You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
It would be nice to have a feature/documentation for the ordering of let! and subject! since it can make a difference.
Personally, I'd prefer they were run last; after all before blocks and before the example.
e.g.
Scenario: subjectbangrunsafterallbeforeblocksatlatestGivenafilenamed"subject_bang_last_spec.rb"with:
"""ruby describe "subject! runslast" do subject! { array.count } let(:array) { [] } before { array.push 1 } describe "nestinggroup" do before { array.push 2 } it { should eq(2) } end end """WhenIrun`rspec subject_bang_last_spec.rb`Thentheexamplesshouldallpass
It looks like, however, they are run first.
Ciao!
The text was updated successfully, but these errors were encountered:
subject! and let! are very implicit constructs, that, while occasionally useful, should not be abused, and I think that if you really need things to happen in a particular order you should explicitly write it so that it happens in that order:
it'returns the correct count'doarray=[]array.push1array.push2count=array.countexpect(count).toeq(2)end
There's no ambiguity here, and no room for misinterpretation.
The particular ordering you are asking for (having a subject! defined in a parent context called before a before hook in a child context) doesn't make sense with the semantics of RSpec's before hooks: we've explicitly documented that parent before hooks run before child before hooks, and subject! is simply a subject declaration plus a before hook. Changing it to act like you are requesting would break many users, and would run counter to how most people expect it to work.
It would be nice to have a feature/documentation for the ordering of
let!
andsubject!
since it can make a difference.Personally, I'd prefer they were run last; after all
before
blocks and before the example.e.g.
It looks like, however, they are run first.
Ciao!
The text was updated successfully, but these errors were encountered: