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.



236
237
238
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 236

def initialize(content)
  @content = content
end

Instance Method Details

#content_messageObject



263
264
265
266
267
268
269
270
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 263

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

#failure_messageObject

Returns

String

The failure message.



253
254
255
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 253

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

#matches?(element) ⇒ Boolean

Returns:

  • (Boolean)


240
241
242
243
244
245
246
247
248
249
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 240

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.



259
260
261
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 259

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