Module: RSpec::Matcher
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rspec/matcher.rb,
lib/rspec/matcher/identity.rb
Overview
Provides minimal interface for creating RSpec Matchers.
Register matcher with RSpec via register_as.
Include RSpec::Matchers::Composable to support composable matchers.
Required Methods:
match
Optional Methods:
descriptionfailure_messagefailure_message_when_negateddiffable?supports_block_expectations?
Defined Under Namespace
Modules: ClassMethods, Identity, PrependedMethods
Constant Summary collapse
- UNDEFINED =
To indicate no value was passed to matcher
Object.new.freeze
Instance Method Summary collapse
-
#actual ⇒ any
Value passed to
expect(). -
#description ⇒ String
Describes what this matcher does.
-
#diffable? ⇒ Boolean
Indicates if actual and expected should be diffed on failure.
-
#expected ⇒ any
Value passed to matcher function.
-
#failure_message ⇒ String
Describe failure.
-
#failure_message_when_negated ⇒ String
Describe failure when not_to is used.
-
#initialize ⇒ Object
First argument passed to matcher is placed in expected and removed from arg list.
-
#match(_ = nil) ⇒ Boolean
Determines if there is a match or not.
-
#matches?(actual) ⇒ Boolean
private
Hides RSpec internal api.
-
#reject_expectation ⇒ void
private
Stops evaluation and tells RSpec there wasn't a match.
-
#resolve_expectation ⇒ void
private
Stops evaluation and tells RSpec there was a match.
-
#supports_block_expectations? ⇒ Boolean
Indicates if actual can be a block.
Instance Method Details
#actual ⇒ any
Returns value passed to expect().
|
|
# File 'lib/rspec/matcher.rb', line 110
|
#description ⇒ String
for composable matchers
raises by default
Describes what this matcher does.
137 138 139 |
# File 'lib/rspec/matcher.rb', line 137 def description raise "not implemented" end |
#diffable? ⇒ Boolean
false by default
Indicates if actual and expected should be diffed on failure.
162 163 164 |
# File 'lib/rspec/matcher.rb', line 162 def diffable? false end |
#expected ⇒ any
Returns value passed to matcher function.
|
|
# File 'lib/rspec/matcher.rb', line 114
|
#failure_message ⇒ String
raises by default
Describe failure.
146 147 148 |
# File 'lib/rspec/matcher.rb', line 146 def raise "not implemented" end |
#failure_message_when_negated ⇒ String
raises by default
Describe failure when not_to is used.
155 156 157 |
# File 'lib/rspec/matcher.rb', line 155 def raise "not implemented" end |
#initialize ⇒ Object
First argument passed to matcher is placed in expected and removed from arg list. Every argument beside that including a block is passed to initialize function.
|
|
# File 'lib/rspec/matcher.rb', line 118
|
#match(_ = nil) ⇒ Boolean
Must be implemented.
Determines if there is a match or not.
127 128 129 |
# File 'lib/rspec/matcher.rb', line 127 def match _ = nil raise "not implemented" end |
#matches?(actual) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Hides RSpec internal api
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rspec/matcher.rb', line 98 def matches? actual self.actual = actual catch(:resolution) do if method(:match).arity == 0 match else match actual end end end |
#reject_expectation ⇒ void (private)
This method returns an undefined value.
Stops evaluation and tells RSpec there wasn't a match.
188 189 190 |
# File 'lib/rspec/matcher.rb', line 188 def reject_expectation throw :resolution, false end |
#resolve_expectation ⇒ void (private)
This method returns an undefined value.
Stops evaluation and tells RSpec there was a match.
180 181 182 |
# File 'lib/rspec/matcher.rb', line 180 def resolve_expectation throw :resolution, true end |
#supports_block_expectations? ⇒ Boolean
false by default
Indicates if actual can be a block.
170 171 172 |
# File 'lib/rspec/matcher.rb', line 170 def supports_block_expectations? false end |