Created
June 23, 2011 04:17
-
-
Save stevenharman/1041894 to your computer and use it in GitHub Desktop.
RSpec shared_context blocks
This file contains 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
shared_context 'authenticated user' do | |
before(:each) do | |
@user = Factory(:user) | |
sign_in @user | |
end | |
end | |
require 'spec_helper' | |
describe ThingsController do | |
describe "when creating a thing" do | |
describe 'an authenticated user' do | |
include_context 'authenticated user' | |
before(:each) do | |
@attrs = { :username => @user.to_param, | |
:thing => Factory.attributes_for(:thing) } | |
end | |
it 'can create a new thing' do | |
lambda do | |
post :create, @attrs | |
end.should change(Thing, :count).by(1) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment