rspec / rspec-mocks

RSpec's 'test double' framework, with support for stubbing and mocking
https://rspec.info
MIT License
1.16k stars 360 forks source link

facing issue with rspec-mocks test cases #1564

Closed raoehtesham03 closed 9 months ago

raoehtesham03 commented 9 months ago

Your environment

Expected behavior

   it { expect(Asset).to receive(:transaction).and_yield.exactly(5).times }
   This test case should pass.

Actual behavior

it { expect(Asset).to receive(:transaction).and_yield.exactly(5).times }
       expected: 5 times with any arguments
       received: 1 time with any arguments
       But I am facing this error again and again
pirj commented 9 months ago

In the same example you should at least call Asset.transaction. Your example must be incomplete if it says that it did indeed yield once.

Are you certain that and_yield works with countable specifiers? http://rspec.info/features/3-12/rspec-mocks/configuring-responses/yielding/ https://github.com/rspec/rspec-mocks/blob/main/spec/rspec/mocks/and_yield_spec.rb

Counts in this case are about how many times the method was called, not how many times it yielded.