Module: RSpec::Mocks::ArgumentMatchers
- Included in:
- ExampleMethods
- Defined in:
- lib/rspec/mocks/argument_matchers.rb
Overview
ArgumentMatchers are placeholders that you can include in message expectations to match arguments against a broader check than simple equality.
With the exception of any_args
and no_args
, they all match against
the arg in same position in the argument list.
Instance Method Summary collapse
-
#any_args ⇒ Object
Acts like an arg splat, matching any number of args at any point in an arg list.
-
#anything ⇒ Object
Matches any argument at all.
-
#array_excluding(*args) ⇒ Object
Matches an array that excludes the specified items.
-
#array_including(*args) ⇒ Object
Matches an array that includes the specified items at least once.
-
#boolean ⇒ Object
Matches a boolean value.
-
#duck_type(*args) ⇒ Object
Matches if the actual argument responds to the specified messages.
-
#hash_excluding(*args) ⇒ Object
(also: #hash_not_including)
Matches a hash that doesn't include the specified key(s) or key/value.
-
#hash_including(*args) ⇒ Object
Matches a hash that includes the specified key(s) or key/value pairs.
-
#instance_of(klass) ⇒ Object
(also: #an_instance_of)
Matches if
arg.instance_of?(klass)
. -
#kind_of(klass) ⇒ Object
(also: #a_kind_of)
Matches if
arg.kind_of?(klass)
. -
#no_args ⇒ Object
Matches no arguments.
Instance Method Details
#any_args ⇒ Object
Acts like an arg splat, matching any number of args at any point in an arg list.
26 27 28 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 26 def any_args AnyArgsMatcher::INSTANCE end |
#anything ⇒ Object
Matches any argument at all.
34 35 36 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 34 def anything AnyArgMatcher::INSTANCE end |
#array_excluding(*args) ⇒ Object
Matches an array that excludes the specified items.
100 101 102 103 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 100 def array_excluding(*args) actually_an_array = Array === args.first && args.count == 1 ? args.first : args ArrayExcludingMatcher.new(actually_an_array) end |
#array_including(*args) ⇒ Object
Matches an array that includes the specified items at least once. Ignores duplicates and additional values
90 91 92 93 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 90 def array_including(*args) actually_an_array = Array === args.first && args.count == 1 ? args.first : args ArrayIncludingMatcher.new(actually_an_array) end |
#boolean ⇒ Object
Matches a boolean value.
59 60 61 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 59 def boolean BooleanMatcher::INSTANCE end |
#duck_type(*args) ⇒ Object
Matches if the actual argument responds to the specified messages.
51 52 53 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 51 def duck_type(*args) DuckTypeMatcher.new(*args) end |
#hash_excluding(*args) ⇒ Object Also known as: hash_not_including
Matches a hash that doesn't include the specified key(s) or key/value.
80 81 82 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 80 def hash_excluding(*args) HashExcludingMatcher.new(ArgumentMatchers.anythingize_lonely_keys(*args)) end |
#hash_including(*args) ⇒ Object
Matches a hash that includes the specified key(s) or key/value pairs. Ignores any additional keys.
70 71 72 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 70 def hash_including(*args) HashIncludingMatcher.new(ArgumentMatchers.anythingize_lonely_keys(*args)) end |
#instance_of(klass) ⇒ Object Also known as: an_instance_of
Matches if arg.instance_of?(klass)
111 112 113 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 111 def instance_of(klass) InstanceOf.new(klass) end |
#kind_of(klass) ⇒ Object Also known as: a_kind_of
Matches if arg.kind_of?(klass)
121 122 123 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 121 def kind_of(klass) KindOf.new(klass) end |
#no_args ⇒ Object
Matches no arguments.
42 43 44 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 42 def no_args NoArgsMatcher::INSTANCE end |