Provide RSpec argument matcher for asserting AR object equality.
The purpose of the gem is to reduce casual use of any_instance_of
: which is often used to specify a record used at far scope from an example.
Add this line to your application's Gemfile:
gem 'rspec-mocks-activerecord_argument_matchers'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rspec-mocks-activerecord_argument_matchers
Add include configuration at spec/spec_helper.rb
RSpec.configure do |config|
# ... snip ..
config.include RSpec::Mocks::ActiverecordArgumentMatchers
end
Now you can use same_record_of
argument matcher in an example.
let(:resource) { MyResource.create! }
specify do
expect(SomethingCreator).to receive(:work).with(same_record_of(resource)) { :fine }
post :something, id: resource.id
end
- Fork it ( http://github.com/moro/rspec-mocks-activerecord_argument_matchers/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request