-
-
Save jimweirich/3706244 to your computer and use it in GitHub Desktop.
| # 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 |
I like the idea. I was just curious if there is a reason why you chose not to follow the And/But syntax of cucumber?
I'll second glanotte's thoughts. Using the "And/But" syntax of cucumber and maintaining that consistency would certainly have benefits for those using both. I know I'd be writing "Also" in my cukes, and "And" in my rspec at that point!
I really miss them as a rspec user. +1
yes please and I would also go for the "And" keyword.
I think it woud be a great addition
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.
I think this is a fantastic option. I've done enough
Then { a.should == :a; b.should == :b }to say that having an Also would help clean some of this up.