Created
November 11, 2014 18:55
-
-
Save erik-megarad/5df43818f1058f380631 to your computer and use it in GitHub Desktop.
This file contains 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 "A long-running process" do | |
before(:context) do # Have to use before(:context) instead of subject() to make the long-running task only execute once | |
@input_one = 1 | |
@input_two = 2 # Can't use let() in before(:context) | |
@my_test_object = MyTestClass.new | |
@my_test_object.thing_that_takes_thirty_minutes(@input_one, @input_two) | |
end | |
# Multiple assertions | |
it 'calculates the output correctly' do | |
@my_test_object.value.should eq 3 | |
end | |
it 'does not set the failed flag' do | |
@my_test_object.failed.should be_nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a little extension that provides something very similar to what you're asking for:
Put that in
spec/spec_helper.rb
(or somewhere that is always loaded) and then tag example groups in which you wantlet
/subject
memoization to have context rather than example scope withmemoization_scope: :context
. Your example would become:...and it should just work.
It's trivial to add this functionality on top of what RSpec already provides. We field enough questions where users get confused when misusing
before(:context)
hooks that I don't want to add more features to RSpec that would encourage their (mis)use, particularly because it's so easy to add this kind of thing on top of the APIs already provided. It could make a great extension gem, though.