Class: RspecTagMatchers::HaveTag
- Inherits:
-
Object
- Object
- RspecTagMatchers::HaveTag
- Defined in:
- lib/rspec_tag_matchers/have_tag.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(selector, inner_text_or_options, options, &block) ⇒ HaveTag
constructor
A new instance of HaveTag.
- #matches?(actual, &block) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(selector, inner_text_or_options, options, &block) ⇒ HaveTag
Returns a new instance of HaveTag.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rspec_tag_matchers/have_tag.rb', line 5 def initialize(selector, , , &block) @selector = selector if Hash === @inner_text = nil @options = else @inner_text = @options = end end |
Instance Method Details
#failure_message ⇒ Object
39 40 41 42 |
# File 'lib/rspec_tag_matchers/have_tag.rb', line 39 def explanation = @actual_count ? "but found #{@actual_count}" : "but did not" "expected\n#{@hdoc.to_s}\nto have #{failure_count_phrase} #{failure_selector_phrase}, #{explanation}" end |
#matches?(actual, &block) ⇒ Boolean
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rspec_tag_matchers/have_tag.rb', line 16 def matches?(actual, &block) @actual = actual @hdoc = hdoc_for(@actual) matched_elements = @hdoc.search(@selector) if matched_elements.empty? return @options[:count] == 0 end if @inner_text matched_elements = filter_on_inner_text(matched_elements) end if block matched_elements = filter_on_nested_expectations(matched_elements, block) end @actual_count = matched_elements.length return false if not acceptable_count?(@actual_count) !matched_elements.empty? end |
#negative_failure_message ⇒ Object
44 45 46 47 |
# File 'lib/rspec_tag_matchers/have_tag.rb', line 44 def explanation = @actual_count ? "but found #{@actual_count}" : "but did" "expected\n#{@hdoc.to_s}\nnot to have #{failure_count_phrase} #{failure_selector_phrase}, #{explanation}" end |