Class: Merb::Test::Rspec::ViewMatchers::HasContent

Inherits:
Object
  • Object
show all
Defined in:
lib/merb-core/test/matchers/view_matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ HasContent

Returns a new instance of HasContent.



287
288
289
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 287

def initialize(content)
  @content = content
end

Instance Method Details

#content_messageObject



314
315
316
317
318
319
320
321
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 314

def content_message
  case @content
  when String
    "include \"#{@content}\""
  when Regexp
    "match #{@content.inspect}"
  end
end

#failure_messageObject

Returns

String

The failure message.



304
305
306
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 304

def failure_message
  "expected the following element's content to #{content_message}:\n#{@element.inner_text}"
end

#matches?(element) ⇒ Boolean

Returns:

  • (Boolean)


291
292
293
294
295
296
297
298
299
300
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 291

def matches?(element)
  @element = element
  
  case @content
  when String
    @element.contains?(@content)
  when Regexp
    @element.matches?(@content)
  end
end

#negative_failure_messageObject

Returns

String

The failure message to be displayed in negative matches.



310
311
312
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 310

def negative_failure_message
  "expected the following element's content to not #{content_message}:\n#{@element.inner_text}"
end