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.



152
153
154
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 152

def initialize(content)
  @content = content
end

Instance Method Details

#content_messageObject



180
181
182
183
184
185
186
187
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 180

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

#failure_messageObject

Returns

String

The failure message.



170
171
172
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 170

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

#matches?(element) ⇒ Boolean

Returns:

  • (Boolean)


156
157
158
159
160
161
162
163
164
165
166
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 156

def matches?(element)
  element = element.body.to_s if element.respond_to?(:body)
  @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.



176
177
178
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 176

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