Matthijs Langenberg
2007-Sep-22 13:22 UTC
[rspec-users] How to DRY up controller action spec with different params.
I tend to write a fresh description block for every change in the parameters for that specific action, because I hate conditionals in the example describtion, e.g.: describe SomeController, "handling GET /path/with/param/3" do it "should do this" it "should not do this if" it "should still do that in both cases" end Seperate description blocks keep things clean, however, there is a big amount of duplication between the two blocks, I do love clarity over cryptic DRY-ed up code (certainly in the examples), but those long blocks make the controller spec file tedious. Take for instance the code from the following pastie ( http://pastie.caboo.se/99683 ). The only difference between the two examples is that, in the first example a cart is retreived using the cart_id from the session, and in the second a new cart is created. Both then find an item and add this item to the cart. How would you guys rewrite the examples in the provided pastie? (and don''t hesitate to tell me if you have any comments about the way I wrote these examples) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070922/c1684655/attachment.html