Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verify partial arguments with RSpec

I need to set expectation on one single argument. How can I access the received arguments from RSpec?

Here is what I want to achieve.

let(:api) { double('API') }

it "should pass :filter in options" do
  api.should_receive(:traverse)
  subject.execute
  args = api.recevied_arguments_for(:traverse) # How to obtain all the arguments?
  args[0].should have_key(:filter)
end

To answer the question, fix the line with the comment.

Thanks.

like image 771
Dmytrii Nagirniak Avatar asked Jan 27 '26 01:01

Dmytrii Nagirniak


1 Answers

Just figured it out. Much better than I thought.

let(:api) { double('API') }
it "should pass :filter in options" do
  api.should_receive(:traverse).with hash_including(:filter)
  # or with the exact value
  #api.should_receive(:traverse).with hash_including(:filter => 'something')
  subject.execute
end
like image 185
Dmytrii Nagirniak Avatar answered Jan 28 '26 17:01

Dmytrii Nagirniak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!