Class: RSpec::TagMatchers::MultipleInputMatcher
- Inherits:
-
Object
- Object
- RSpec::TagMatchers::MultipleInputMatcher
- Defined in:
- lib/rspec/tag_matchers/multiple_input_matcher.rb
Overview
A matcher that matches multiple input elements. It is intended to serve as a base class for
building more specific matchers that must match multiple input elements. For example, a matcher
to test for Rails' time_select drop-downs must test that the HTML contains a drop-down for
hours and another drop-down for minutes.
Direct Known Subclasses
Instance Method Summary collapse
-
#failure_message ⇒ String
Returns the failure messages from each failed matcher.
-
#for(*args) ⇒ MultipleInputMatcher
Specifies the inputs' names with more accuracy than the default regular expressions.
-
#initialize(components) ⇒ MultipleInputMatcher
constructor
Initializes a matcher that matches multiple input elements.
-
#matches?(rendered) ⇒ Boolean
Tests whether the matcher matches the
renderedstring. -
#negative_failure_message ⇒ String
Returns the negative failure messages from every matcher.
Constructor Details
#initialize(components) ⇒ MultipleInputMatcher
Initializes a matcher that matches multiple input elements.
29 30 31 32 33 34 |
# File 'lib/rspec/tag_matchers/multiple_input_matcher.rb', line 29 def initialize(components) @components = components @components.each do |key, matcher| matcher.with_attribute(:name => /\(#{key}\)/) end end |
Instance Method Details
#failure_message ⇒ String
Returns the failure messages from each failed matcher.
82 83 84 |
# File 'lib/rspec/tag_matchers/multiple_input_matcher.rb', line 82 def @failures.map(&:failure_message).join(" and ") end |
#for(*args) ⇒ MultipleInputMatcher
Specifies the inputs' names with more accuracy than the default regular expressions. It
delegates to each matcher's for method. But it first appends the matcher's key to the last
component of the input's name.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rspec/tag_matchers/multiple_input_matcher.rb', line 68 def for(*args) @for = args.dup @for.extend(DeepFlattening) @for = @for.deep_flatten @components.each do |index, matcher| delegated_for(index, matcher, @for) end self end |
#matches?(rendered) ⇒ Boolean
Tests whether the matcher matches the rendered string. It delegates matching to its
matchers. It returns true if all of its matchers return true. It returns false if any of its
matchers return false.
44 45 46 47 48 49 50 51 |
# File 'lib/rspec/tag_matchers/multiple_input_matcher.rb', line 44 def matches?(rendered) @rendered = rendered @failures = matchers.reject do |matcher| matcher.matches?(rendered) end @failures.empty? end |
#negative_failure_message ⇒ String
Returns the negative failure messages from every matcher.
89 90 91 |
# File 'lib/rspec/tag_matchers/multiple_input_matcher.rb', line 89 def matchers.map(&:negative_failure_message).join(" and ") end |