RSpec tips #2
RSpec and state_machine gem
Published in
1 min readApr 8, 2016
Wanna test some `after_transition` or `before_transition` code from your models on RSpec without super complicated mocks and stubs? Worry no more, here’s the real deal!
# User model
after_transition on: :register, :give_gift# User spec
it ‘gives gift to user after registering’ do
user = User.new
transition = StateMachine::Transition.new(user, User.state_machine, :register, :pending, :registered)
transition.run_callbacksexpect(user.received_gift?).to be_truthy
end
Now go test some transitions!