On Jan 30, 12:33 am, [email protected] wrote: > Awesome answer. > I have being testing the Given/When/Then framework but the Then prints out > very ugly so I do not think I will use it. > > Your solution is good, I thought that doing several expectations inside an > 'it' was considered bad style. > But I think I understand the general idea, what I really want to check is > the fact that it has only one page and this high level check can be > decomposed on these small checks in this case. > > Thank you very much.
I believe the "one expectation per example" (or "one assertion per test") guideline was born as a reaction to a testing style that would pile up many unrelated assertions/expectations in a single test/ example, which made it hard to understand what behavior was failing when you get failure output. It's useful as an exercise to try to structure things using "one expectation per example", but I think it's an unhelpful guideline as a general rule. betterspecs.org lists this as a "best practice" (along with some other things with which I disagree). I commented on a github issue thread what I would say instead: https://github.com/andreareginato/betterspecs/issues/5#issuecomment-9110114 * In isolated unit specs, you want each example to specify one (and only one) behavior. Multiple expectations in the same example are a signal that you may be specifying multiple behaviors. * In tests that are not isolated (e.g. ones that integrate with a DB, an external webservice, or end-to-end-tests), you take a massive performance hit to do the same setup over and over again, just to set a different expectation in each test. In these sorts of slower tests, I think it's fine to specify more than one isolated behavior. As in all things, software engineering is about tradeoffs, and this is no exception. It's bad to encourage cargo-cult thinking here. -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
