Created
July 26, 2012 10:06
-
-
Save wojtekmach/3181329 to your computer and use it in GitHub Desktop.
Spec inheritance
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 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 |
Author
In plain rspec they wouldn't, context is just an alias for describe, I'm
just experimenting with it. It's pretty easy to make it work with
minitest/spec though, you would have total 6 assertions. Do you have some
experience/examples with contract testing in Ruby? I would love to know
more about this stuff.
26-07-2012 19:37, "J. B. Rainsberger" <
reply@reply.github.com>
napisał(a):
… I didn't think that the 2 specs would run in each context when written
this way.
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/3181329
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
I didn't think that the 2 specs would run in each context when written this way.