You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 11, 2022. It is now read-only.
I'm using the state_machine gem in conjunction with no-peeping-toms. In the spec that I have written at the bottom, the state_machine callback after_game_ended is never called. I verified that it is called through the development console and places in my environment.
# models/event.rbclassEvent < ActiveRecord::Basestate_machine:initial=>:not_starteddoevent:game_starteddotransition:not_started=>:in_progressendevent:game_endeddotransition:in_progress=>:finalendendend# observers/event_observer.rbclassEventObserver < ActiveRecord::Observerdefafter_game_ended(record,transition)# never reaches hereResolveGamesWorker.perform(record.id)endend# spec/models/event_spec.rbdescribeEventdocontext'when game ends'dosubject{FactoryGirl.build(:event,:in_progress)}it'should queue up event for games resolution worker'doActiveRecord::Observer.with_observers(:event_observer)doResolveGamesWorker.any_instance.should_receive(:perform)subject.game_ended!endendendend
The text was updated successfully, but these errors were encountered:
When you say "it never reaches here" are you saying that because the test fails? If so I think the test is set up incorrectly, or at least it shouldn't pass with this code. ResolveGamesWorker.any_instance.should_receive(:perform) sets an expectation for #perform to be called on an instance of ResolveGamesWorker while after_game_ended calls ResolveGamesWorker.perform - a class method. For that expectation to bet met you'd need to change it to ResolveGamesWorker.should_receive(:perform) OR change the call to ResolveGamesWorker.new.perform(record.id). Does that help?
It fails because it actually never triggers the callback after_game_ended. If I try Rails.logger.info("I made it!") or puts "yea dawg" before the call to ResolveGamesWorker in the event observer, the output never makes it to test.log or the console, respectively.
I've tried other assertions besides ResolveGamesWorker.any_instance.should_receive(:perform) just to make sure that I didn't write a bad test and it always fails.
Honestly Chris I'm not sure from looking at your code, and I'm not familiar enough with state_machine's inner workings to know what might be going on. If you sort this out please send a pull request, for now I'm afraid I can't investigate further.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I'm using the state_machine gem in conjunction with no-peeping-toms. In the spec that I have written at the bottom, the state_machine callback after_game_ended is never called. I verified that it is called through the development console and places in my environment.
The text was updated successfully, but these errors were encountered: