Skip to content

Instantly share code, notes, and snippets.

@coreyhaines
Last active August 29, 2015 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save coreyhaines/db2257c18549b6f87c1e to your computer and use it in GitHub Desktop.
Save coreyhaines/db2257c18549b6f87c1e to your computer and use it in GitHub Desktop.
Using super() in rspec's subject
# Phew! Turns out this was generated by transpec, not by a human!
before do
@admin = User.create(username: "user", password: "password", password_confirmation: "password")
end
subject{ @admin }
describe '#remember_token' do
subject { super().remember_token }
it { is_expected.not_to be_blank }
end
@bppr
Copy link

bppr commented Feb 23, 2015

explicit subject has done nothing but harm the readability of my specs imo

hell, the use of subject at all is just weird and foreign to me.

@mattvanhorn
Copy link

Why not name the subject? Does that not work across context boundaries?

subject(:admin){ @admin }
# ...
subject(:token) { admin.remember_token }

@coreyhaines
Copy link
Author

Okay, turns out that this is a result of running transpec. I'm glad to hear nobody actually wrote this. :)

But, in general, my personal style hasn't evolved to using explicit subject / it. I'm pretty old school. :)

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