Created
September 12, 2012 12:17
-
-
Save jimweirich/3706244 to your computer and use it in GitHub Desktop.
Description of the "And" Experimental feature for RSpec/Given (was "Also")
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
# Experimental And Clauses | |
# | |
# I've been thinking about tests where there are multiple Thens | |
# in a single context. All the Givens and before blocks are run | |
# for each Then. Since Then's are idempotent, that seems to be a waste. | |
# | |
# Maybe we can introduce And clauses. They are like Then clauses, but | |
# they reuse the Givens of an existing Then clause. This could make a | |
# difference in spec that have expensive setups. | |
# | |
# Example: | |
context "with one item" do | |
Given(:initial_contents) { [:an_item] } | |
context "when popping" do | |
When(:pop_result) { stack.pop } | |
Then { pop_result.should == :an_item } | |
And { stack.depth.should == 0 } | |
end | |
end | |
# Some Limitations | |
# | |
# (1) And clauses are run after the first Then clause in a context. It | |
# is an error to have an Also clause without a Then. | |
# | |
# (2) And clauses are not independent, a failure in a Then or an early | |
# And clause will cause the remaining And clauses to _not_ be run. | |
# | |
# Limitation 2 is a technical limitation. Essentially the And clauses are running | |
# in the same "spec/test" as the its parent Then. It would be nice if there | |
# was a way to report multiple spec failures in a single spec run. | |
# | |
# RSpec/Given 2.1.0.beta.4 has this experimental feature. Try it with: | |
# | |
# gem install --pre rspec-given |
Definitely a big fan of the addition.
I make the explicit choice to use Also rather than And because I felt the semantics were different from Cucumber's And. After consideration (and weighing all the comments) I don't think the difference will be confusing, so we will go with "And" for the name of the clause.
Thanks for the feedback.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think it woud be a great addition