How can RSpec check that an argument object has one value?

时间:2016-02-12 20:03:03

标签: ruby-on-rails ruby rspec

I have a function being called like

car.method({a: 3, b: 6, c: 9})

And in RSpec, I want to assert that b: 6 is called, but not any of the other values.

expect(car).to receive(:method).with({b: 6})

How can I do that without strictly matching the entire object?

1 个答案:

答案 0 :(得分:2)

If I right understand your question, it may write like this (from relishapp.com):

expect(car).to receive(:method).with(hash_including(b: 6))

Anyway, see matching arguments from this source, it can help to resolve your problem.