Skip to content

Instantly share code, notes, and snippets.

@stevenharman
Created June 23, 2011 04:17
Show Gist options
  • Save stevenharman/1041894 to your computer and use it in GitHub Desktop.
Save stevenharman/1041894 to your computer and use it in GitHub Desktop.
RSpec shared_context blocks
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