Hey everyone, This is a noob question. I''m not grasping the difference between "describe" and "context" in my spec file. As an example, what''s the difference with this... describe Game do context "starting up" do it "should send a welcome message" do @messenger.should_receive(:puts).with("Welcome to Mastermind!") @game.start(%w[r g y c]) end And this.... describe Game do describe "starting up" do it "should send a welcome message" do @messenger.should_receive(:puts).with("Welcome to Mastermind!") @game.start(%w[r g y c]) end Is this just preference, or are the serious differences?
On Sat, Jul 11, 2009 at 3:29 PM, Chris Sund<chris at silhouettesolutions.net> wrote:> Hey everyone, > > This is a noob question. I''m not grasping the difference between > "describe" and "context" in my spec file. As an example, what''s the > difference with this... > > describe Game do > ? ? context "starting up" do > it "should send a welcome message" do > ? ? ? ?@messenger.should_receive(:puts).with("Welcome to > Mastermind!") > ? ? ? ?@game.start(%w[r g y c]) > ? ? ?end > > > > And this.... > > describe Game do > ? ? describe "starting up" do > it "should send a welcome message" do > ? ? ? ?@messenger.should_receive(:puts).with("Welcome to > Mastermind!") > ? ? ? ?@game.start(%w[r g y c]) > ? ? ?end > > > Is this just preference, or are the serious differences? >There is no technical difference. context is aliased to describe. However, you can use them in combination to write more expressive specs. For example: describe Game do describe "#join_game" do context "when the game has not started"d o it "should allow a player to join" end context "when the game has started" do it "should not allow another player to join" end end end> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Zach Dennis http://www.continuousthinking.com (personal) http://www.mutuallyhuman.com (hire me) http://ideafoundry.info/behavior-driven-development (first rate BDD training) @zachdennis (twitter)
Scott Taylor
2009-Jul-12 19:48 UTC
[rspec-users] explanation of "describe" vs "context"...
Chris Sund wrote:> Hey everyone, > > This is a noob question. I''m not grasping the difference between > "describe" and "context" in my spec file. As an example, what''s the > difference with this... > > describe Game do > context "starting up" do > it "should send a welcome message" do > @messenger.should_receive(:puts).with("Welcome to > Mastermind!") > @game.start(%w[r g y c]) > end > > > > And this.... > > describe Game do > describe "starting up" do > it "should send a welcome message" do > @messenger.should_receive(:puts).with("Welcome to > Mastermind!") > @game.start(%w[r g y c]) > end > > > Is this just preference, or are the serious differences? > > >They are aliased, so there is no functional difference: http://gist.github.com/ded8be0839e77c30afe1 Scott> _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
internetchris
2009-Jul-12 20:51 UTC
[rspec-users] explanation of "describe" vs "context"...
Thanks, that helps me understand better. On Jul 12, 1:48?pm, Scott Taylor <sc... at railsnewbie.com> wrote:> Chris Sund wrote: > > Hey everyone, > > > This is a noob question. I''m not grasping the difference between > > "describe" and "context" in my spec file. As an example, what''s the > > difference with this... > > > describe Game do > > ? ? ?context "starting up" do > > it "should send a welcome message" do > > ? ? ? ? @messenger.should_receive(:puts).with("Welcome to > > Mastermind!") > > ? ? ? ? @game.start(%w[r g y c]) > > ? ? ? end > > > And this.... > > > describe Game do > > ? ? ?describe "starting up" do > > it "should send a welcome message" do > > ? ? ? ? @messenger.should_receive(:puts).with("Welcome to > > Mastermind!") > > ? ? ? ? @game.start(%w[r g y c]) > > ? ? ? end > > > Is this just preference, or are the serious differences? > > They are aliased, so there is no functional difference: > > http://gist.github.com/ded8be0839e77c30afe1 > > Scott > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users