RSpec tips #2

RSpec and state_machine gem

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 =
transition =, User.state_machine, :register, :pending, :registered)
expect(user.received_gift?).to be_truthy

Now go test some transitions!