Class: RSpec::SleepingKingStudios::Matchers::BuiltIn::IncludeMatcher
- Inherits:
-
Matchers::BuiltIn::Include
- Object
- Matchers::BuiltIn::Include
- RSpec::SleepingKingStudios::Matchers::BuiltIn::IncludeMatcher
- Includes:
- Description
- Defined in:
- lib/rspec/sleeping_king_studios/matchers/built_in/include_matcher.rb
Overview
Extensions to the built-in RSpec #include matcher.
Constant Summary
Constants included from Description
Description::DEFAULT_EXPECTED_ITEMS
Instance Method Summary collapse
- #description ⇒ Object
- #does_not_match?(actual) ⇒ Boolean private
-
#failure_message ⇒ Object
Message for when the object does not match, but was expected to.
-
#failure_message_when_negated ⇒ Object
Message for when the object matches, but was expected not to.
-
#initialize(*expected) {|item| ... } ⇒ IncludeMatcher
constructor
A new instance of IncludeMatcher.
- #matches?(actual) ⇒ Boolean private
Constructor Details
#initialize(*expected) {|item| ... } ⇒ IncludeMatcher
Returns a new instance of IncludeMatcher.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rspec/sleeping_king_studios/matchers/built_in/include_matcher.rb', line 19 def initialize *expected, &block if block_given? SleepingKingStudios::Tools::CoreTools .deprecate('IncludeMatcher with a block') expected << block end if expected.empty? && !allow_empty_matcher? raise ArgumentError, 'must specify an item expectation', caller end # if super *expected end |
Instance Method Details
#description ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rspec/sleeping_king_studios/matchers/built_in/include_matcher.rb', line 37 def description desc = super # Format hash expectations. desc = desc.gsub(/(\S)=>(\S)/, '\1 => \2') # Replace processed block expectation stub with proper description. desc = desc.gsub ':__block_comparison__', 'an item matching the block' desc end |
#does_not_match?(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.
61 62 63 64 65 |
# File 'lib/rspec/sleeping_king_studios/matchers/built_in/include_matcher.rb', line 61 def does_not_match?(actual) @actual = actual perform_match(actual) { |v| !v } end |
#failure_message ⇒ Object
Message for when the object does not match, but was expected to. Make sure to always call #matches? first to set up the matcher state.
68 69 70 71 72 73 74 |
# File 'lib/rspec/sleeping_king_studios/matchers/built_in/include_matcher.rb', line 68 def = super.sub ':__block_comparison__', 'an item matching the block' << ", but it does not respond to `include?`" unless actual.respond_to?(:include?) || =~ /does not respond to/ end |
#failure_message_when_negated ⇒ Object
Message for when the object matches, but was expected not to. Make sure to always call #matches? first to set up the matcher state.
77 78 79 80 81 82 83 |
# File 'lib/rspec/sleeping_king_studios/matchers/built_in/include_matcher.rb', line 77 def = super.sub ':__block_comparison__', 'an item matching the block' << ", but it does not respond to `include?`" unless actual.respond_to?(:include?) || =~ /does not respond to/ 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.
52 53 54 55 56 |
# File 'lib/rspec/sleeping_king_studios/matchers/built_in/include_matcher.rb', line 52 def matches?(actual) @actual = actual perform_match(actual) { |v| v } end |