Class: Merb::Test::Rspec::ViewMatchers::MatchTag
- Defined in:
- lib/merb-core/test/matchers/view_matchers.rb
Instance Method Summary collapse
-
#failure_message ⇒ Object
Returns String:: The failure message.
-
#initialize(name, attrs) ⇒ MatchTag
constructor
Parameters name<~to_s>:: The name of the tag to look for.
-
#matches?(target) ⇒ Boolean
Parameters target<String>:: The string to look for the tag in.
-
#negative_failure_message ⇒ Object
Returns String:: The failure message to be displayed in negative matches.
Constructor Details
#initialize(name, attrs) ⇒ MatchTag
Parameters
- name<~to_s>
-
The name of the tag to look for.
- attrs<Hash>
-
Attributes to look for in the tag (see below).
Options (attrs)
- :content<String>
-
Optional content to match.
48 49 50 51 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 48 def initialize(name, attrs) @name, @attrs = name, attrs @content = @attrs.delete(:content) end |
Instance Method Details
#failure_message ⇒ Object
Returns
- String
-
The failure message.
78 79 80 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 78 def @errors[0] end |
#matches?(target) ⇒ Boolean
Parameters
- target<String>
-
The string to look for the tag in.
Returns
- Boolean
-
True if the tag matched.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 58 def matches?(target) @errors = [] unless target.include?("<#{@name}") @errors << "Expected a <#{@name}>, but was #{target}" end @attrs.each do |attr, val| unless target.include?("#{attr}=\"#{val}\"") @errors << "Expected #{attr}=\"#{val}\", but was #{target}" end end if @content unless target.include?(">#{@content}<") @errors << "Expected #{target} to include #{@content}" end end @errors.size == 0 end |
#negative_failure_message ⇒ Object
Returns
- String
-
The failure message to be displayed in negative matches.
84 85 86 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 84 def "Expected not to match against <#{@name} #{@attrs.map{ |a,v| "#{a}=\"#{v}\"" }.join(" ")}> tag, but it matched" end |