Class: RSpec::Matchers::BuiltIn::BaseMatcher Private
- Inherits:
-
Object
- Object
- RSpec::Matchers::BuiltIn::BaseMatcher
- Includes:
- Pretty
- Defined in:
- lib/rspec/matchers/built_in/base_matcher.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Used internally as a base class for matchers that ship with rspec-expectations.
Warning:
This class is for internal use, and subject to change without notice. We strongly recommend that you do not base your custom matchers on this class. If/when this changes, we will announce it and remove this warning.
Direct Known Subclasses
Be, BeAKindOf, BeAnInstanceOf, BeFalse, BeNil, BeTrue, Cover, Eq, Eql, Equal, Exist, Include, Match, MatchArray, StartAndEndWith, YieldControl, YieldWithNoArgs
Instance Attribute Summary collapse
- #actual ⇒ Object readonly private
- #expected ⇒ Object readonly private
- #rescued_exception ⇒ Object readonly private
Instance Method Summary collapse
- #==(other) ⇒ Object private
- #description ⇒ Object private
- #diffable? ⇒ Boolean private
- #failure_message_for_should ⇒ Object private
- #failure_message_for_should_not ⇒ Object private
-
#initialize(expected = nil) ⇒ BaseMatcher
constructor
private
A new instance of BaseMatcher.
- #match_unless_raises(*exceptions) ⇒ Object private
- #matches?(actual) ⇒ Boolean private
Methods included from Pretty
#_pretty_print, #expected_to_sentence, #name, #name_to_sentence, #split_words, #to_sentence, #underscore
Constructor Details
#initialize(expected = nil) ⇒ BaseMatcher
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.
Returns a new instance of BaseMatcher.
19 20 21 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 19 def initialize(expected = nil) @expected = expected end |
Instance Attribute Details
#actual ⇒ Object (readonly)
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.
17 18 19 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 17 def actual @actual end |
#expected ⇒ Object (readonly)
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.
17 18 19 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 17 def expected @expected end |
#rescued_exception ⇒ Object (readonly)
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.
17 18 19 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 17 def rescued_exception @rescued_exception end |
Instance Method Details
#==(other) ⇒ Object
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.
56 57 58 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 56 def ==(other) matches?(other) end |
#description ⇒ Object
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.
48 49 50 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 48 def description expected ? "#{name_to_sentence} #{@expected.inspect}" : name_to_sentence end |
#diffable? ⇒ 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.
52 53 54 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 52 def diffable? false end |
#failure_message_for_should ⇒ Object
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.
38 39 40 41 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 38 def assert_ivars :@actual, :@expected "expected #{@actual.inspect} to #{name_to_sentence}#{expected_to_sentence}" end |
#failure_message_for_should_not ⇒ Object
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.
43 44 45 46 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 43 def assert_ivars :@actual, :@expected "expected #{@actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}" end |
#match_unless_raises(*exceptions) ⇒ Object
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.
28 29 30 31 32 33 34 35 36 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 28 def match_unless_raises(*exceptions) exceptions.unshift Exception if exceptions.empty? begin yield true rescue *exceptions => @rescued_exception false end 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.
23 24 25 26 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 23 def matches?(actual) @actual = actual match(expected, actual) end |