Class: Capybara::Minitest::Assertions::Matcher
- Inherits:
-
Object
- Object
- Capybara::Minitest::Assertions::Matcher
- Includes:
- RSpecMatchers
- Defined in:
- lib/capybara/minitest/assertions/matcher.rb
Overview
Represents one of the Capybara RSpec matchers.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the RSpec matcher, e.g.
Class Method Summary collapse
-
.all ⇒ Object
Returns an array of matchers representing the recognized Capybara RSpec matchers.
-
.recognizes_name?(name) ⇒ Boolean
Determines whether the given RSpec matcher is recognized by this class.
Instance Method Summary collapse
-
#assertions ⇒ Object
Returns a new array of assertions for this matcher.
-
#initialize(name) ⇒ Matcher
constructor
Initializes a new matcher based on the given RSpec matcher name.
-
#matcher(*args) ⇒ Object
Returns a new Capybara RSpec matcher object for the given matcher arguments.
-
#third_person_name ⇒ Object
Returns the matcher’s name in third person.
Constructor Details
#initialize(name) ⇒ Matcher
Initializes a new matcher based on the given RSpec matcher name.
28 29 30 31 32 33 34 |
# File 'lib/capybara/minitest/assertions/matcher.rb', line 28 def initialize(name) unless self.class.recognizes_name?(name) fail ArgumentError, 'Unrecognized matcher name.' end @name = name.to_s end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the RSpec matcher, e.g. have_text.
25 26 27 |
# File 'lib/capybara/minitest/assertions/matcher.rb', line 25 def name @name end |
Class Method Details
.all ⇒ Object
Returns an array of matchers representing the recognized Capybara RSpec matchers.
12 13 14 15 16 |
# File 'lib/capybara/minitest/assertions/matcher.rb', line 12 def self.all Capybara::RSpecMatchers.public_instance_methods.map do |matcher_name| new(matcher_name) if recognizes_name?(matcher_name) end.compact end |
.recognizes_name?(name) ⇒ Boolean
Determines whether the given RSpec matcher is recognized by this class.
20 21 22 |
# File 'lib/capybara/minitest/assertions/matcher.rb', line 20 def self.recognizes_name?(name) name.to_s.match(/^have_/) end |
Instance Method Details
#assertions ⇒ Object
Returns a new array of assertions for this matcher.
53 54 55 |
# File 'lib/capybara/minitest/assertions/matcher.rb', line 53 def assertions [MatcherAssertion.new(self), MatcherRefutation.new(self)] end |
#matcher(*args) ⇒ Object
Returns a new Capybara RSpec matcher object for the given matcher arguments. This is what would be returned by have_text(‘Foo’), for example.
48 49 50 |
# File 'lib/capybara/minitest/assertions/matcher.rb', line 48 def matcher(*args) send(@name, *args) end |
#third_person_name ⇒ Object
Returns the matcher’s name in third person.
matcher.name # => have_text (infinitive form)
matcher.third_person_name # => has_text (third person form)
41 42 43 |
# File 'lib/capybara/minitest/assertions/matcher.rb', line 41 def third_person_name @third_person_name ||= @name.gsub(/^have_/, 'has_') end |