I have been curious about rSpec for a while, so I thought I''d give it a try... I started reading Ron Jeffries'' articles on Sudoku (http://www.xprogramming.com/xpmag/OkSudoku.htm), and noticed he was doing TDD, I thought, this would be fun to do with BDD... Can you comment on the following? (note that I added a method in the Game class called cells which return @cells) to make the first spec work) Thanks! Dominique ---------------------------------------------------------- # Inspired by: # http://www.xprogramming.com/xpmag/OkSudoku.htm # http://rspec.rubyforge.org/ require ''Game'' context "An Empty Board" do setup do @game = Game.test_game end specify "should have 81 cells" do @game.should.have(81).cells end specify "should have 0..80 in the cells" do (0..80).each do | i | @game.cell(i).should.equal i end end specify "check values in row 3" do @game.row(3).should.equal [27, 28, 29, 30, 31, 32, 33, 34, 35] end specify "check values in row 8" do @game.row(8).should.equal [72, 73, 74, 75, 76, 77, 78, 79, 80] end specify "check values in column 3" do @game.column(3).should.equal [3, 12, 21, 30, 39, 48, 57, 66, 75] end specify "check values in square 4 (middle square, counting from 0)" do @game.square(4).should.equal [30, 31, 32, 39, 40, 41, 48, 49, 50] end specify "check values in square 8 (last square, counting from 0)" do @game.square(8).should.equal [60, 61, 62, 69, 70, 71, 78, 79, 80] end end ------------------------------------------------------------- dom.website = http://www.binaryshift.com
This was intended for the whole group. ---------- Forwarded message ---------- From: David Chelimsky <dchelimsky at gmail.com> Date: Jul 29, 2006 7:11 AM Subject: Re: [Rspec-users] comments on my first context To: Dominique Plante <dominique.plante at gmail.com> On 7/29/06, Dominique Plante <dominique.plante at gmail.com> wrote:> I have been curious about rSpec for a while, so I thought I''d give it a try... > > I started reading Ron Jeffries'' articles on Sudoku > (http://www.xprogramming.com/xpmag/OkSudoku.htm), and noticed he was > doing TDD, I thought, this would be fun to do with BDD... > > Can you comment on the following? (note that I added a method in the > Game class called cells which return @cells) to make the first spec > work)Interesting example. BDD is about behaviour, and you''ve picked an example (sudoku) that seems to be inherently about state ("An Empty Board should have 81 squares"). The behavioural aspects (interactions) won''t show up for a while on the path that you''re on. But that''s OK for now. The expectations you''ve written are all fine (i.e. the code in the specs), but the names are a bit confusing. Right now, the output would be this: An Empty Board -should have 81 cells -should have 0..80 in the cells -check values in row 3 -check values in row 8 -check values in column 3 -check values in square 4 (middle square, counting from 0) -check values in square 8 (last square, counting from 0) Think about how that reads and what it conveys. There are a few points of confusion here. The second spec "should have 0..80 in the cells" doesn''t make sense in An Empty Board. It might make sense in A Sample Board, or something like that. Also, "An Empty Board check values in row 3" reads a bit funny. You get the idea. I''d recommend that you play around w/ the names so that the output makes more sense. Part of the idea is to get your head out of the code and think about the communication aspects (i.e. how you would use this output to express the intent of the system), and that doesn''t always become apparent until you look at the output as a whole. Feel free to post back when you''ve made some changes. Have fun! David> > Thanks! > Dominique > > ---------------------------------------------------------- > > # Inspired by: > # http://www.xprogramming.com/xpmag/OkSudoku.htm > # http://rspec.rubyforge.org/ > > require ''Game'' > > context "An Empty Board" do > setup do > @game = Game.test_game > end > > specify "should have 81 cells" do > @game.should.have(81).cells > end > > specify "should have 0..80 in the cells" do > (0..80).each do | i | > @game.cell(i).should.equal i > end > end > > specify "check values in row 3" do > @game.row(3).should.equal [27, 28, 29, 30, 31, 32, 33, 34, 35] > end > > specify "check values in row 8" do > @game.row(8).should.equal [72, 73, 74, 75, 76, 77, 78, 79, 80] > end > > specify "check values in column 3" do > @game.column(3).should.equal [3, 12, 21, 30, 39, 48, 57, 66, 75] > end > > specify "check values in square 4 (middle square, counting from 0)" do > @game.square(4).should.equal [30, 31, 32, 39, 40, 41, 48, 49, 50] > end > > specify "check values in square 8 (last square, counting from 0)" do > @game.square(8).should.equal [60, 61, 62, 69, 70, 71, 78, 79, 80] > end > > end > ------------------------------------------------------------- > dom.website = http://www.binaryshift.com > _______________________________________________ > Rspec-users mailing list > Rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Dear David: Thanks for the feedback! Your feedback makes sense - I will play around with the names, and think about the behavior as I go a little bit further along... I think what''s interesting that you are suggesting is that there are assertions that feel natural in TDD that you wouldn''t want to mimic in BDD... Thanks! Dominique On 7/29/06, David Chelimsky <dchelimsky at gmail.com> wrote:> On 7/29/06, Dominique Plante <dominique.plante at gmail.com> wrote: > > I have been curious about rSpec for a while, so I thought I''d give it a try... > > > > I started reading Ron Jeffries'' articles on Sudoku > > (http://www.xprogramming.com/xpmag/OkSudoku.htm), and noticed he was > > doing TDD, I thought, this would be fun to do with BDD... > > > > Can you comment on the following? (note that I added a method in the > > Game class called cells which return @cells) to make the first spec > > work) > > Interesting example. BDD is about behaviour, and you''ve picked an > example (sudoku) that seems to be inherently about state ("An Empty > Board should have 81 squares"). The behavioural aspects (interactions) > won''t show up for a while on the path that you''re on. But that''s OK > for now. > > The expectations you''ve written are all fine (i.e. the code in the > specs), but the names are a bit confusing. Right now, the output would > be this: > > An Empty Board > -should have 81 cells > -should have 0..80 in the cells > -check values in row 3 > -check values in row 8 > -check values in column 3 > -check values in square 4 (middle square, counting from 0) > -check values in square 8 (last square, counting from 0) > > Think about how that reads and what it conveys. There are a few points > of confusion here. The second spec "should have 0..80 in the cells" > doesn''t make sense in An Empty Board. It might make sense in A Sample > Board, or something like that. Also, "An Empty Board check values in > row 3" reads a bit funny. You get the idea. > > I''d recommend that you play around w/ the names so that the output > makes more sense. Part of the idea is to get your head out of the code > and think about the communication aspects (i.e. how you would use this > output to express the intent of the system), and that doesn''t always > become apparent until you look at the output as a whole. > > Feel free to post back when you''ve made some changes. > > Have fun! > > David > > > > > Thanks! > > Dominique > > > > ---------------------------------------------------------- > > > > # Inspired by: > > # http://www.xprogramming.com/xpmag/OkSudoku.htm > > # http://rspec.rubyforge.org/ > > > > require ''Game'' > > > > context "An Empty Board" do > > setup do > > @game = Game.test_game > > end > > > > specify "should have 81 cells" do > > @game.should.have(81).cells > > end > > > > specify "should have 0..80 in the cells" do > > (0..80).each do | i | > > @game.cell(i).should.equal i > > end > > end > > > > specify "check values in row 3" do > > @game.row(3).should.equal [27, 28, 29, 30, 31, 32, 33, 34, 35] > > end > > > > specify "check values in row 8" do > > @game.row(8).should.equal [72, 73, 74, 75, 76, 77, 78, 79, 80] > > end > > > > specify "check values in column 3" do > > @game.column(3).should.equal [3, 12, 21, 30, 39, 48, 57, 66, 75] > > end > > > > specify "check values in square 4 (middle square, counting from 0)" do > > @game.square(4).should.equal [30, 31, 32, 39, 40, 41, 48, 49, 50] > > end > > > > specify "check values in square 8 (last square, counting from 0)" do > > @game.square(8).should.equal [60, 61, 62, 69, 70, 71, 78, 79, 80] > > end > > > > end > > ------------------------------------------------------------- > > dom.website = http://www.binaryshift.com > > _______________________________________________ > > Rspec-users mailing list > > Rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > >-- ------------------------------------------------------------- dom.website = http://www.binaryshift.com