Marcelo de Moraes Serpa
2010-Feb-18 19:33 UTC
[rspec-users] Recall a example inside another (just like in Cucumber)
Hello guys, I was spec''ing a model and just tried to do something like this it "should create a payment with period_start & period_end set correctly" do it "should create a new payment for an approved transaction" previous_payment = Payment.find(Payment.last.id-1) just_created_payment = Payment.last #Here, check below for a documentation of how period_start and #period_end should be set as of now: payment.period_start.should == previous_payment.period_end payment.period_end.should == previous_payment.period_end + (@subscription.billing_cycle.months).months end Calling an already defined example, since this one requires all the tests/objects from the "should created a new payment for an approved transaction". I know I could just recreted all objects locally or just use a before block, but I think it would be useful if we could do like this just like Cucumber allows with steps. Cheers, Marcelo. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100218/412edd17/attachment.html>
Matt Wynne
2010-Feb-18 20:11 UTC
[rspec-users] Recall a example inside another (just like in Cucumber)
On 18 Feb 2010, at 19:33, Marcelo de Moraes Serpa wrote:> Hello guys, > > I was spec''ing a model and just tried to do something like this > > it "should create a payment with period_start & period_end set > correctly" do > it "should create a new payment for an approved transaction" > > previous_payment = Payment.find(Payment.last.id-1) > just_created_payment = Payment.last > #Here, check below for a documentation of how period_start and > #period_end should be set as of now: > payment.period_start.should == previous_payment.period_end > payment.period_end.should == previous_payment.period_end + > (@subscription.billing_cycle.months).months > > > end > > Calling an already defined example, since this one requires all the > tests/objects from the "should created a new payment for an approved > transaction". > > I know I could just recreted all objects locally or just use a > before block, but I think it would be useful if we could do like > this just like Cucumber allows with steps.Why not move the code that''s common to the two examples out into a before block?> > Cheers, > > Marcelo. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-userscheers, Matt http://mattwynne.net +447974 430184
Phillip Koebbe
2010-Feb-18 20:20 UTC
[rspec-users] Recall a example inside another (just like in Cucumber)
> On 18 Feb 2010, at 19:33, Marcelo de Moraes Serpa wrote: > >> Hello guys, >> >> I was spec''ing a model and just tried to do something like this >> >> it "should create a payment with period_start & period_end set >> correctly" do >> it "should create a new payment for an approved transaction" >> >> previous_payment = Payment.find(Payment.last.id-1) >> just_created_payment = Payment.last >> #Here, check below for a documentation of how period_start and >> #period_end should be set as of now: >> payment.period_start.should == previous_payment.period_end >> payment.period_end.should == previous_payment.period_end + >> (@subscription.billing_cycle.months).months >> >> >> end >> >> Calling an already defined example, since this one requires all the >> tests/objects from the "should created a new payment for an approved >> transaction". >> >> I know I could just recreted all objects locally or just use a before >> block, but I think it would be useful if we could do like this just >> like Cucumber allows with steps. > > Why not move the code that''s common to the two examples out into a > before block? >Or a shared example? I haven''t used them much, so I''m only guessing that it would work. Peace, Phillip