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.
98 99 100 101 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 98 def initialize(name, attrs) @name, @attrs = name, attrs @content = @attrs.delete(:content) end |
Instance Method Details
#failure_message ⇒ Object
Returns
- String
-
The failure message.
128 129 130 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 128 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.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 108 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.
134 135 136 |
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 134 def "Expected not to match against <#{@name} #{@attrs.map{ |a,v| "#{a}=\"#{v}\"" }.join(" ")}> tag, but it matched" end |