method
hash_including
1.1.4 -
Show latest stable
-
1 note -
Class: Spec::Mocks::ArgumentConstraintMatchers
- 1.1.4 (0)
- 1.1.12
- 1.2.0
- 1.2.8
- 1.3.0
- 1.3.1
- What's this?
Register or
log in
to add new notes.
Olly -
August 14, 2008
13 thanks
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')