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.



52
53
54
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 52

def initialize(expected)
  @expected = expected
end

Instance Method Details

#failure_messageObject

Returns

String

The failure message.



75
76
77
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 75

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)


61
62
63
64
65
66
67
68
69
70
71
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 61

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.



81
82
83
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 81

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