From: Christian Neukirchen Date: 2007-01-25T04:33:59+09:00 Subject: Re: test/spec -- was Re: I don't get rspec "David Chelimsky" writes: >> > Glad to hear it. Do you have any feeling about which approach to reuse >> > you personally prefer? Nested contexts or included modules? >> >> As said, nesting is purely for organizational and namespacing purposes. >> I use modules. > > Interesting. I thought it was for context state sharing like this: > > context "a User" do > setup do > user = User.new > end > > context "with a valid email address" do > setup do > user.email = "a@b.com" > end > ... > end > > context "with an invalid email address" do > setup do > user.email = "this@is.not.correctly.formatted" > end > ... > end > end > > This leads us quickly down a path in which you have to look up a chain > of several setup methods to understand failures. > > If it's just a matter of namespacing for reporting/organization that's > kind of interesting. I'm not sure how I could implement that (and I wont ;-)). But maybe includable setups would be useful. module UserSetup setup do # ??? @user = User.new end end context "Users" do context "with a valid email address" do include UserSetup setup { @user.email ... } end context "with a valid email address" do include UserSetup setup { @user.email ... } end end That shouldn't be too hard to do... > David -- Christian Neukirchen http://chneukirchen.org