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.
Defined Under Namespace
Classes: AnyArgMatcher, AnyArgsMatcher, BooleanMatcher, DuckTypeMatcher, EqualityProxy, HashExcludingMatcher, HashIncludingMatcher, InstanceOf, KindOf, MatcherMatcher, NoArgsMatcher, RegexpMatcher
Instance Method Summary (collapse)
-
- (Object) any_args
Matches any args at all.
-
- (Object) anything
Matches any argument at all.
-
- (Object) boolean
Matches a boolean value.
-
- (Object) duck_type(*args)
Matches if the actual argument responds to the specified messages.
-
- (Object) hash_excluding(*args)
(also: #hash_not_including)
Matches a hash that doesn't include the specified key(s) or key/value.
-
- (Object) hash_including(*args)
Matches a hash that includes the specified key(s) or key/value pairs.
-
- (Object) instance_of(klass)
(also: #an_instance_of)
Matches if
arg.instance_of?(klass)
. -
- (Object) kind_of(klass)
(also: #a_kind_of)
Matches if
arg.kind_of?(klass)
. -
- (Object) no_args
Matches no arguments.
Instance Method Details
- (Object) any_args
Matches any args at all. Supports a more explicit variation of
object.should_receive(:message)
154 155 156 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 154 def any_args AnyArgsMatcher.new end |
- (Object) anything
Matches any argument at all.
163 164 165 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 163 def anything AnyArgMatcher.new(nil) end |
- (Object) boolean
Matches a boolean value.
191 192 193 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 191 def boolean BooleanMatcher.new(nil) end |
- (Object) duck_type(*args)
Matches if the actual argument responds to the specified messages.
182 183 184 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 182 def duck_type(*args) DuckTypeMatcher.new(*args) end |
- (Object) hash_excluding(*args) Also known as: hash_not_including
Matches a hash that doesn't include the specified key(s) or key/value.
214 215 216 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 214 def hash_excluding(*args) HashExcludingMatcher.new(anythingize_lonely_keys(*args)) end |
- (Object) hash_including(*args)
Matches a hash that includes the specified key(s) or key/value pairs. Ignores any additional keys.
203 204 205 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 203 def hash_including(*args) HashIncludingMatcher.new(anythingize_lonely_keys(*args)) end |
- (Object) instance_of(klass) Also known as: an_instance_of
Matches if arg.instance_of?(klass)
225 226 227 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 225 def instance_of(klass) InstanceOf.new(klass) end |
- (Object) kind_of(klass) Also known as: a_kind_of
Matches if arg.kind_of?(klass)
235 236 237 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 235 def kind_of(klass) KindOf.new(klass) end |
- (Object) no_args
Matches no arguments.
172 173 174 |
# File 'lib/rspec/mocks/argument_matchers.rb', line 172 def no_args NoArgsMatcher.new end |