ruby on rails - Setting a variable when a stubbed method is called in RSpec -


in 1 of tests want perform before :all action, , need want test method not called in before :all action. there way this?

e.g. want able to:

before :all   @bar_called = false   # set @bar_called true if bar called on instance of class foo   do_other_stuff end 

and then, in 1 of specs later on, expect @bar_called == false

you implement mock block, set @bar_called.

expect(obj).to receive(:my_method) { @bar_called = true }

now, may want consider setting expectation on mock/stub instead

expect(obj).to receive(:my_method).exactly(0).times

see rspec-mocks documentation on receive counts.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -