Class: Merb::Test::Rspec::ViewMatchers::HaveSelector

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

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ HaveSelector

Parameters

expected<String>

The string to look for.



6
7
8
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 6

def initialize(expected)
  @expected = expected
end

Instance Method Details

#failure_messageObject

Returns

String

The failure message.



29
30
31
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 29

def failure_message
  "expected following text to match selector #{@expected}:\n#{@document}"
end

#matches?(stringlike) ⇒ Boolean

Parameters

stringlike<Hpricot::Elem, StringIO, String>

The thing to search in.

Returns

Boolean

True if there was at least one match.

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 15

def matches?(stringlike)
  @document = case stringlike
  when Hpricot::Elem
    stringlike
  when StringIO
    Hpricot.parse(stringlike.string)
  else
    Hpricot.parse(stringlike)
  end
  !@document.search(@expected).empty?
end

#negative_failure_messageObject

Returns

String

The failure message to be displayed in negative matches.



35
36
37
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 35

def negative_failure_message
  "expected following text to not match selector #{@expected}:\n#{@document}"
end