rspec/rspec-core — pull request #760 by zubin (2012-12-30 04:17:07+00:00)
Title: Added `subject!` method for invoking subject in a before block like `let!`

I've gone to use the imaginary `subject!` method a few times and each time was mildly surprised that it wasn't already there. Writing `before { subject }` seems wrong, when there's already a `let!` method for avoiding this.

Consider this contrived example, which registers user activity via an after-save callback:

describe '#update_attributes!' do
subject { FactoryGirl.create(:user) }
it "stores activity" do
expect do
subject.update_attributes!(attrs)
end.to change(Activity, :count).by(1)
end
end

The test will fail since the `register_activity` method will be called twice within the expect block: once on create, then on update). Using `subject!` corrects this.