Last active
December 18, 2015 12:59
-
-
Save sevenseacat/5787196 to your computer and use it in GitHub Desktop.
Inconsistencies in using rspec's `expect` syntax. Does it take an argument or a block? In which circumstances does it take each? Why can't we all just get along!?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe SeriesController do | |
| describe 'GET "create"' do | |
| subject { post :create, series: params } | |
| context 'valid parameters provided' do | |
| let(:params) { FactoryGirl.attributes_for :series } | |
| # Using expect(subject) here leads to an error: | |
| # NoMethodError: undefined method `call' for #<ActionController::TestResponse:0x007f03c4c3d470> | |
| specify { expect { subject }.to change(Series, :count).by(1) } | |
| # Using expect { subject } here leads to an error: | |
| # Expected response to be a <redirect>, but was <200> | |
| specify { expect(subject).to redirect_to series_path(assigns(:series)) } | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
my chunk of code that works (maybe it will help you?)