Hi, Not sure if this is the right place for general questions on BDD style, but here goes... I have a class which behaves almost like a big function - you always instantiate it with a bunch of args, and call one of a couple of methods to get the results back. BDD style seems to like a separate describe block for each instantiation of the class under test. In this case that would mean a ton of describe blocks, each with just one it "..." do block (terminology??). That seems rather verbose. What would the recommended style be? And the meta question - where should I go to educate myself on this stuff? Thanks Tom
On 6/21/07, Tom Locke <tom at hobocentral.net> wrote:> Hi, > > Not sure if this is the right place for general questions on BDD > style, but here goes... > > I have a class which behaves almost like a big function - you always > instantiate it with a bunch of args, and call one of a couple of > methods to get the results back. > > BDD style seems to like a separate describe block for each > instantiation of the class under test.Only when you''re describing that object in different starting states. If there''s only one starting state, you can create one of them before(:each) example: before(:each) { @thing = Thing.new }> In this case that would mean a > ton of describe blocks, each with just one it "..." do block > (terminology??). That seems rather verbose. What would the > recommended style be?If you need the object in different starting states, you''ve got a few options. You could go w/ the context approach you described above in which you have a different description for each starting state. You could also make a helper method (or a couple of them) in a module: module ExampleHelpers def create_thing ... end end describe "Stuff" do include ExampleHelpers before(:each) { @thing = create_thing } ... end Another is to use a shared behaviour: describe "All Things", :shared => true do before(:each) { @thing = Thing.new(with, a, bunch, of, args) } end describe "One Thing" do it_should_behave_like "All Things" # now you can access @thing in each example end> And the meta question - where should I go to educate myself on this > stuff?This is a good place. Here are some blogs: http://blog.davidchelimsky.net http://blog.daveastels.com/ http://blog.aslakhellesoy.com/ http://dannorth.net/ Another list is testdrivendevelopment at yahoogroups.com. BDD started off as TDD with more focus on behaviour, but serious TDD''ers (who live on that list) know better (they were already focusing on behaviour). Cheers, David> > Thanks > > Tom > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Thanks David, I''m not sure this covers my situation though - I''ll give a bit more detail The class I''m specing is the DRYML compiler -- yep I''m doing retroactive specing I''m afraid, which is maybe why things don''t fit too neatly. You instantiate the class, passing the DRYML source, and then call process_src which converts the DRYML to regular ERB, and returns that as a string. At the moment I''m doing stuff like this: describe Template do it "should compile tag calls to method calls" do compile_dryml("<foo/>").should == "<%= foo() %>" end it "should compile attributes as keyword parameters" do compile_dryml("<foo a=''1''/>").should == ''<%= foo({:a => "1"}) %>'' end end Those compile_dryml calls each instantiate a template with a different state. I really don''t want to have a separate describe block for each example - there could be hundreds. Is this bad form? Tom
On 6/21/07, Tom Locke <tom at hobocentral.net> wrote:> Thanks David, > > I''m not sure this covers my situation though - I''ll give a bit more > detail > > The class I''m specing is the DRYML compiler -- yep I''m doing > retroactive specing I''m afraid, which is maybe why things don''t fit > too neatly. > > You instantiate the class, passing the DRYML source, and then call > process_src which converts the DRYML to regular ERB, and returns that > as a string. > > At the moment I''m doing stuff like this: > > describe Template do > > it "should compile tag calls to method calls" do > compile_dryml("<foo/>").should == "<%= foo() %>" > end > > it "should compile attributes as keyword parameters" do > compile_dryml("<foo a=''1''/>").should == ''<%= foo({:a => "1"}) %>'' > end > > end > > Those compile_dryml calls each instantiate a template with a > different state. I really don''t want to have a separate describe > block for each example - there could be hundreds. Is this bad form?Not at all. Perfectly sane.> > Tom > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >