Hussein Morsy
2007-Mar-25 20:04 UTC
[rspec-users] New Style: describe-it instead of context-specify
Hello, in the tunk, i found a new style for spec: describe Foo do it "should do bar" do ... end end instead of context "Foo" context "should do bar" ... end end The Rails-Textmate-bundle in trunk use only the new "describe-it" style, What are the reasons for the new style ? Shall i use the new style from now on ? Hussein
aslak hellesoy
2007-Mar-25 20:46 UTC
[rspec-users] New Style: describe-it instead of context-specify
On 3/25/07, Hussein Morsy <hussein at morsy.de> wrote:> Hello, > > in the tunk, i found a new style for spec: > > describe Foo do > it "should do bar" do > ... > end > end > > instead of > > context "Foo" > context "should do bar" > ... > end > end > > The Rails-Textmate-bundle in trunk use only the new "describe-it" > style, > > What are the reasons for the new style ?We believe it will lead spec writers to subconsciously write more behavioural specs.> Shall i use the new style from now on ? >Yes, but we will still support the old style for a good while. Aslak> > > Hussein > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Bryan Helmkamp
2007-Mar-25 21:20 UTC
[rspec-users] New Style: describe-it instead of context-specify
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" end 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 ... end WDYT? -Bryan
David Chelimsky
2007-Mar-25 21:33 UTC
[rspec-users] New Style: describe-it instead of context-specify
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" > end > > 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" doYES!!!! 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. David> ... > end > > WDYT? > > -Bryan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >