Skip to content

Instantly share code, notes, and snippets.

@sevenseacat
Last active December 16, 2015 08:09
Show Gist options
  • Save sevenseacat/5404252 to your computer and use it in GitHub Desktop.
Save sevenseacat/5404252 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe GamesController do
describe 'POST "create"' do
subject(:response) { post :create, params }
context 'valid parameters provided' do
let(:params) { { game: FactoryGirl.attributes_for(:game) } }
specify { expect { subject }.to change(Game, :count).by 1 }
# This fails - assigns(:game) is nil so the route comes out like /games//score
it { should redirect_to score_game_path(assigns(:game)) }
# This passes - subject evaluated first?
it { subject.should redirect_to score_game_path(assigns(:game)) }
# This passes - named subject gets evaluated first too
it 'redirects to the newly created game' do
response.should redirect_to score_game_path(assigns(:game))
end
it { should set_flash :notice }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment