[rspec-users] New Style: describe-it instead of context-specify
dchelimsky at gmail.com
Sun Mar 25 17:33:01 EDT 2007
On 3/25/07, Bryan Helmkamp <bhelmkamp at gmail.com> wrote:
> I'm a bit uncomfortable with the new describe/it syntax, and I'm
> hoping someone can help me put aside my reservations...
> Basically, using the context/specify syntax, there is room to include
> additional information about the context of the set specs without
> duplicating it in each spec. For example, the context would be "An
> invalid credit card", and the specify blocks would be "should be
> reject by the payment processor", etc. In the describe/it syntax, it
> seems like I'd have to do:
> describe CreditCard
> it "should be rejected by the payment processor when invalid"
> it "should not be chargeable when invalid"
> it "should contain validation errors when invalid"
> I'm concerned about the duplication of "when invalid" in the "it"
> blocks. I totally understand the argument of clarity over DRY in
> specs, but the new syntax seems like it requires spec writers to take
> this too far to the extreme.
> Does the describe syntax take an extra string param? That would
> provide a solution as follows:
> describe CreditCard, "when invalid" do
YES!!!! It does. The signature now looks like this:
def describe(type_or_description, additional_description=nil, &block)
(actually, it still says "def context" and describe is an alias" in
trunk - need to reverse that)
This will be completely backwards compatible, and context/specify will
live indefinitely as aliases to describe/it.
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users