Class: Capybara::Minitest::Assertions::MatcherAssertion
- Inherits:
-
Object
- Object
- Capybara::Minitest::Assertions::MatcherAssertion
- Defined in:
- lib/capybara/minitest/assertions/matcher.rb
Overview
Represents an assertion based on a Capybara RSpec matcher.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#matcher ⇒ Object
readonly
The matcher this assertion is based on.
Class Method Summary collapse
-
.matcher_failure_message_method ⇒ Object
The failure message method called on the RSpec matcher for this kind of assertion.
-
.matcher_test_method ⇒ Object
The test method called on the RSpec matcher for this kind of assertion.
-
.name_prefix ⇒ Object
The prefix for method names of this kind of assertion.
Instance Method Summary collapse
-
#initialize(matcher) ⇒ MatcherAssertion
constructor
Initializes a new assertion with the given matcher.
-
#name ⇒ Object
The name of the assertion.
-
#test(subject, *args) ⇒ Object
Executes the assertion by testing it against the matcher on the given test subject and with the provided arguments.
Constructor Details
#initialize(matcher) ⇒ MatcherAssertion
Initializes a new assertion with the given matcher.
64 65 66 |
# File 'lib/capybara/minitest/assertions/matcher.rb', line 64 def initialize(matcher) @matcher = matcher end |
Instance Attribute Details
#matcher ⇒ Object (readonly)
The matcher this assertion is based on.
61 62 63 |
# File 'lib/capybara/minitest/assertions/matcher.rb', line 61 def matcher @matcher end |
Class Method Details
.matcher_failure_message_method ⇒ Object
The failure message method called on the RSpec matcher for this kind of assertion.
104 105 106 |
# File 'lib/capybara/minitest/assertions/matcher.rb', line 104 def self. :failure_message end |
.matcher_test_method ⇒ Object
The test method called on the RSpec matcher for this kind of assertion.
98 99 100 |
# File 'lib/capybara/minitest/assertions/matcher.rb', line 98 def self.matcher_test_method :matches? end |
.name_prefix ⇒ Object
The prefix for method names of this kind of assertion.
92 93 94 |
# File 'lib/capybara/minitest/assertions/matcher.rb', line 92 def self.name_prefix 'assert' end |
Instance Method Details
#name ⇒ Object
The name of the assertion.
assertion.matcher.name # => have_text
assertion.name # => assert_has_text
73 74 75 |
# File 'lib/capybara/minitest/assertions/matcher.rb', line 73 def name "#{self.class.name_prefix}_#{@matcher.third_person_name}" end |
#test(subject, *args) ⇒ Object
Executes the assertion by testing it against the matcher on the given test subject and with the provided arguments. Returns an array with the test result (as a boolean) and the failure message.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/capybara/minitest/assertions/matcher.rb', line 80 def test(subject, *args) # Create an RSpec matcher object. matcher = @matcher.matcher(*args) # Perform the match. test_result = matcher.send(self.class.matcher_test_method, subject) # Get the failure message, which has to be done after the matching. = matcher.send(self.class.) [test_result, ] end |