method
hash_including
rspec latest stable - Class:
Spec::Mocks::ArgumentConstraintMatchers
hash_including(expected={})public
No documentation available.
# File lib/spec/mocks/argument_constraint_matchers.rb, line 22
def hash_including(expected={})
HashIncludingConstraint.new(expected)
end 1Note
Testing an options hash receives certain parameters
This method is very useful for testing methods that use the ruby idiom of accepting a hash with configurable options.
class Example
def self.find(options = {})
...
end
end
We can use hash_including to ensure that certain options are passed in when mocking it.
Example.should_receive(:find).with(hash_including(:conditions => 'some conditions'))
Example.find(:conditions => 'some_conditions', :order => 1)
# => Passes expectation
Example.find(:order => 1)
# => Fails expectation
This can also be used to great effect with the anything matcher. For example: hash_including(:key => anything)
hash_including(anything => 'value')