Skip to content

Instantly share code, notes, and snippets.

@wojtekmach
Created July 26, 2012 10:06
Show Gist options
  • Select an option

  • Save wojtekmach/3181329 to your computer and use it in GitHub Desktop.

Select an option

Save wojtekmach/3181329 to your computer and use it in GitHub Desktop.
Spec inheritance
describe UsersController do
describe '#show' do
before { get :show, id: user.id }
it { should respond_with :success }
it { should assign_to(:user).with(user) }
context 'with public user' do
let(:user) { Factory(:public_user) }
end
context 'with protected, but friended user' do
let(:user) { Factory(:protected_user, friends: [current_user]) }
end
end
end
@jbrains
Copy link

jbrains commented Jul 26, 2012

I didn't think that the 2 specs would run in each context when written this way.

@wojtekmach
Copy link
Author

wojtekmach commented Jul 26, 2012 via email

@jbrains
Copy link

jbrains commented Jul 27, 2012

Good, then I wasn't completely crazy. I didn't think it would work.

Sadly, I don't have examples of doing this in Ruby with RSpec. I'd just do it with shared examples. I don't have enough practice with it to know the problems with shared examples in RSpec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment