Hi, I want to be able to get at the described class in my shared behaviour. I''m sure an example will say it better than my words describe "my shared", :shared => true do it "should tell me what the class is its describing" do how_do_i_get_the_user_class_here end end describe User do it_should_behave_like "my shared" #... end So in my shared behaviour, how do I get access to the User class? Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071122/3036e7c6/attachment-0001.html
Did you try self.class ?? Nathan Sutton fowlduck at gmail.com rspec edge revision 2910 rspec_on_rails edge revision 2909 rails edge revision 8175 On Nov 21, 2007, at 3:14 PM, Daniel N wrote:> Hi, > > I want to be able to get at the described class in my shared > behaviour. I''m sure an example will say it better than my words > > describe "my shared", :shared => true do > > it "should tell me what the class is its describing" do > how_do_i_get_the_user_class_here > end > > end > > describe User do > it_should_behave_like "my shared" > > #... > end > > So in my shared behaviour, how do I get access to the User class? > > Cheers > Daniel > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
yep should == User expected: User, got: #<Class:0x25d0ce4> (using ==) On Nov 22, 2007 8:15 AM, Nathan Sutton <nathan.sutton at gmail.com> wrote:> Did you try self.class > > ?? > Nathan Sutton > fowlduck at gmail.com > rspec edge revision 2910 > rspec_on_rails edge revision 2909 > rails edge revision 8175 > > > > On Nov 21, 2007, at 3:14 PM, Daniel N wrote: > > > Hi, > > > > I want to be able to get at the described class in my shared > > behaviour. I''m sure an example will say it better than my words > > > > describe "my shared", :shared => true do > > > > it "should tell me what the class is its describing" do > > how_do_i_get_the_user_class_here > > end > > > > end > > > > describe User do > > it_should_behave_like "my shared" > > > > #... > > end > > > > So in my shared behaviour, how do I get access to the User class? > > > > Cheers > > Daniel > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071122/fbf63a2a/attachment.html
On Nov 21, 2007 3:14 PM, Daniel N <has.sox at gmail.com> wrote:> Hi, > > I want to be able to get at the described class in my shared behaviour. I''m > sure an example will say it better than my words > > describe "my shared", :shared => true do > > it "should tell me what the class is its describing" do > how_do_i_get_the_user_class_here > end > > end > > describe User do > it_should_behave_like "my shared" > > #... > end > > So in my shared behaviour, how do I get access to the User class?There''s no way to do this implicitly. i.e. rspec does not expose the class. You''d have to have a method like described_class or something: describe "my shared", :shared => true do it "should tell me what the class is its describing" do described_class.should do_something_I_care_about end end describe User do def described_class User end ... end> > Cheers > Daniel > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Nov 22, 2007 8:22 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> On Nov 21, 2007 3:14 PM, Daniel N <has.sox at gmail.com> wrote: > > Hi, > > > > I want to be able to get at the described class in my shared behaviour. > I''m > > sure an example will say it better than my words > > > > describe "my shared", :shared => true do > > > > it "should tell me what the class is its describing" do > > how_do_i_get_the_user_class_here > > end > > > > end > > > > describe User do > > it_should_behave_like "my shared" > > > > #... > > end > > > > So in my shared behaviour, how do I get access to the User class? > > There''s no way to do this implicitly. i.e. rspec does not expose the > class. You''d have to have a method like described_class or something: > > describe "my shared", :shared => true do > > it "should tell me what the class is its describing" do > described_class.should do_something_I_care_about > end > > end > > describe User do > def described_class > User > end > ... > end > >> > K thanx David >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071122/df24bb24/attachment.html
David to the rescue! :) Nathan Sutton fowlduck at gmail.com rspec edge revision 2910 rspec_on_rails edge revision 2909 rails edge revision 8175 On Nov 21, 2007, at 3:22 PM, David Chelimsky wrote:> On Nov 21, 2007 3:14 PM, Daniel N <has.sox at gmail.com> wrote: >> Hi, >> >> I want to be able to get at the described class in my shared >> behaviour. I''m >> sure an example will say it better than my words >> >> describe "my shared", :shared => true do >> >> it "should tell me what the class is its describing" do >> how_do_i_get_the_user_class_here >> end >> >> end >> >> describe User do >> it_should_behave_like "my shared" >> >> #... >> end >> >> So in my shared behaviour, how do I get access to the User class? > > There''s no way to do this implicitly. i.e. rspec does not expose the > class. You''d have to have a method like described_class or something: > > describe "my shared", :shared => true do > > it "should tell me what the class is its describing" do > described_class.should do_something_I_care_about > end > > end > > describe User do > def described_class > User > end > ... > end > > > > >> >> Cheers >> Daniel >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On Nov 21, 2007 10:22 PM, David Chelimsky <dchelimsky at gmail.com> wrote:> > On Nov 21, 2007 3:14 PM, Daniel N <has.sox at gmail.com> wrote: > > Hi, > > > > I want to be able to get at the described class in my shared behaviour. I''m > > sure an example will say it better than my words > > > > describe "my shared", :shared => true do > > > > it "should tell me what the class is its describing" do > > how_do_i_get_the_user_class_here > > end > > > > end > > > > describe User do > > it_should_behave_like "my shared" > > > > #... > > end > > > > So in my shared behaviour, how do I get access to the User class? > > There''s no way to do this implicitly. i.e. rspec does not expose the > class. You''d have to have a method like described_class or something: > > describe "my shared", :shared => true do > > it "should tell me what the class is its describing" do > described_class.should do_something_I_care_about > end > > end > > describe User do > def described_class > User > end > ... > end > >However, if you do this: describe MyModule do # MyModule has a #hello method it "should be polite" do hello.should == ''How do you do'' end end Modules are automatically mixed into your examples Aslak> > > > > > > Cheers > > Daniel > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Nov 22, 2007 8:31 AM, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:> On Nov 21, 2007 10:22 PM, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > On Nov 21, 2007 3:14 PM, Daniel N <has.sox at gmail.com> wrote: > > > Hi, > > > > > > I want to be able to get at the described class in my shared > behaviour. I''m > > > sure an example will say it better than my words > > > > > > describe "my shared", :shared => true do > > > > > > it "should tell me what the class is its describing" do > > > how_do_i_get_the_user_class_here > > > end > > > > > > end > > > > > > describe User do > > > it_should_behave_like "my shared" > > > > > > #... > > > end > > > > > > So in my shared behaviour, how do I get access to the User class? > > > > There''s no way to do this implicitly. i.e. rspec does not expose the > > class. You''d have to have a method like described_class or something: > > > > describe "my shared", :shared => true do > > > > it "should tell me what the class is its describing" do > > described_class.should do_something_I_care_about > > end > > > > end > > > > describe User do > > def described_class > > User > > end > > ... > > end > > > > > > However, if you do this: > > describe MyModule do # MyModule has a #hello method > it "should be polite" do > hello.should == ''How do you do'' > end > end > > Modules are automatically mixed into your examples > > Aslak > > > > > > > > > > > > Cheers > > > Daniel > > > <http://rubyforge.org/mailman/listinfo/rspec-users> >Aslak Thanx. I was aware of that behaviour, but this module is being mixed into AR classes and relies on there being methods available to AR models. I really want to implemnet these specs as a shared behaviour on each implementing model. That way I can check to make sure that the model has the correct attributes for the mixin to function properly etc. Thanx again. Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071122/b2b6fe11/attachment.html
Some of this clears up my issues around sharing behaviors that you can pass parameters to. I was doing a hackish solution before by including a module then calling a method it provides, but now I can have shared behaviors and just have them call specific methods which then become a convention to define. It still feels hackish, but not nearly as much. Is there another way? Nathan Sutton fowlduck at gmail.com rspec edge revision 2910 rspec_on_rails edge revision 2909 rails edge revision 8175 On Nov 21, 2007, at 3:31 PM, aslak hellesoy wrote:> On Nov 21, 2007 10:22 PM, David Chelimsky <dchelimsky at gmail.com> > wrote: >> >> On Nov 21, 2007 3:14 PM, Daniel N <has.sox at gmail.com> wrote: >>> Hi, >>> >>> I want to be able to get at the described class in my shared >>> behaviour. I''m >>> sure an example will say it better than my words >>> >>> describe "my shared", :shared => true do >>> >>> it "should tell me what the class is its describing" do >>> how_do_i_get_the_user_class_here >>> end >>> >>> end >>> >>> describe User do >>> it_should_behave_like "my shared" >>> >>> #... >>> end >>> >>> So in my shared behaviour, how do I get access to the User class? >> >> There''s no way to do this implicitly. i.e. rspec does not expose the >> class. You''d have to have a method like described_class or something: >> >> describe "my shared", :shared => true do >> >> it "should tell me what the class is its describing" do >> described_class.should do_something_I_care_about >> end >> >> end >> >> describe User do >> def described_class >> User >> end >> ... >> end >> >> > > However, if you do this: > > describe MyModule do # MyModule has a #hello method > it "should be polite" do > hello.should == ''How do you do'' > end > end > > Modules are automatically mixed into your examples > > Aslak >> >> >> >>> >>> Cheers >>> Daniel >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On Nov 21, 2007, at 4:22 PM, David Chelimsky wrote:> On Nov 21, 2007 3:14 PM, Daniel N <has.sox at gmail.com> wrote: >> Hi, >> >> I want to be able to get at the described class in my shared >> behaviour. I''m >> sure an example will say it better than my words >> >> describe "my shared", :shared => true do >> >> it "should tell me what the class is its describing" do >> how_do_i_get_the_user_class_here >> end >> >> end >> >> describe User do >> it_should_behave_like "my shared" >> >> #... >> end >> >> So in my shared behaviour, how do I get access to the User class? > > There''s no way to do this implicitly. i.e. rspec does not expose the > class. You''d have to have a method like described_class or something: > > describe "my shared", :shared => true do > > it "should tell me what the class is its describing" do > described_class.should do_something_I_care_about > end > > end > > describe User do > def described_class > User > end > ... > endOr you could just set up instance variables in your before :each block: describe "an object which has to_s", :shared => true do it "should work!" do :foo.send(@method).should == "foo" end end describe Symbol do before :each do @method = :to_s end it_should_behave_like "an object which has to_s" end On another note, I''ve been poking around Rubinius'' source, which uses a scaled down version of rspec, and they already have shared examples with parameters: shared :symbol_id2name do |cmd| describe "Symbol\##{cmd}" do it "returns the string corresponding to self" do :rubinius.send(cmd).should == "rubinius" :squash.send(cmd).should == "squash" :[].send(cmd).should == "[]" :@ruby.send(cmd).should == "@ruby" :@@ruby.send(cmd).should == "@@ruby" end end end require File.dirname(__FILE__) + ''/../../spec_helper'' describe "Symbol#to_s" do it_behaves_like(:symbol_id2name, :to_s) end This doesn''t seem that hard to implement. Is there some reason a patch has been created yet? Scott
On Nov 21, 2007 3:53 PM, Scott Taylor <mailing_lists at railsnewbie.com> wrote:> > On Nov 21, 2007, at 4:22 PM, David Chelimsky wrote: > > > > On Nov 21, 2007 3:14 PM, Daniel N <has.sox at gmail.com> wrote: > >> Hi, > >> > >> I want to be able to get at the described class in my shared > >> behaviour. I''m > >> sure an example will say it better than my words > >> > >> describe "my shared", :shared => true do > >> > >> it "should tell me what the class is its describing" do > >> how_do_i_get_the_user_class_here > >> end > >> > >> end > >> > >> describe User do > >> it_should_behave_like "my shared" > >> > >> #... > >> end > >> > >> So in my shared behaviour, how do I get access to the User class? > > > > There''s no way to do this implicitly. i.e. rspec does not expose the > > class. You''d have to have a method like described_class or something: > > > > describe "my shared", :shared => true do > > > > it "should tell me what the class is its describing" do > > described_class.should do_something_I_care_about > > end > > > > end > > > > describe User do > > def described_class > > User > > end > > ... > > end > > Or you could just set up instance variables in your before :each block: > > describe "an object which has to_s", :shared => true do > it "should work!" do > :foo.send(@method).should == "foo" > end > end > > describe Symbol do > before :each do > @method = :to_s > end > > it_should_behave_like "an object which has to_s" > end > > > On another note, I''ve been poking around Rubinius'' source, which uses > a scaled down version of rspec, and they already have shared examples > with parameters: > > shared :symbol_id2name do |cmd| > describe "Symbol\##{cmd}" do > it "returns the string corresponding to self" do > :rubinius.send(cmd).should == "rubinius" > :squash.send(cmd).should == "squash" > :[].send(cmd).should == "[]" > :@ruby.send(cmd).should == "@ruby" > :@@ruby.send(cmd).should == "@@ruby" > end > end > end > > require File.dirname(__FILE__) + ''/../../spec_helper'' > > describe "Symbol#to_s" do > it_behaves_like(:symbol_id2name, :to_s) > end > > > This doesn''t seem that hard to implement. Is there some reason a > patch has been created yet?Yes. You haven''t submitted it.> > Scott > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Ooh, I totally want to do this, I''ll work on it this week along with my other patch i have yet to submit this week, unless Scott is partial to doing it. Do you want it, Scott? Nathan Sutton fowlduck at gmail.com rspec edge revision 2910 rspec_on_rails edge revision 2909 rails edge revision 8175 On Nov 21, 2007, at 4:13 PM, David Chelimsky wrote:> On Nov 21, 2007 3:53 PM, Scott Taylor > <mailing_lists at railsnewbie.com> wrote: >> >> On Nov 21, 2007, at 4:22 PM, David Chelimsky wrote: >> >> >>> On Nov 21, 2007 3:14 PM, Daniel N <has.sox at gmail.com> wrote: >>>> Hi, >>>> >>>> I want to be able to get at the described class in my shared >>>> behaviour. I''m >>>> sure an example will say it better than my words >>>> >>>> describe "my shared", :shared => true do >>>> >>>> it "should tell me what the class is its describing" do >>>> how_do_i_get_the_user_class_here >>>> end >>>> >>>> end >>>> >>>> describe User do >>>> it_should_behave_like "my shared" >>>> >>>> #... >>>> end >>>> >>>> So in my shared behaviour, how do I get access to the User class? >>> >>> There''s no way to do this implicitly. i.e. rspec does not expose the >>> class. You''d have to have a method like described_class or >>> something: >>> >>> describe "my shared", :shared => true do >>> >>> it "should tell me what the class is its describing" do >>> described_class.should do_something_I_care_about >>> end >>> >>> end >>> >>> describe User do >>> def described_class >>> User >>> end >>> ... >>> end >> >> Or you could just set up instance variables in your before :each >> block: >> >> describe "an object which has to_s", :shared => true do >> it "should work!" do >> :foo.send(@method).should == "foo" >> end >> end >> >> describe Symbol do >> before :each do >> @method = :to_s >> end >> >> it_should_behave_like "an object which has to_s" >> end >> >> >> On another note, I''ve been poking around Rubinius'' source, which uses >> a scaled down version of rspec, and they already have shared examples >> with parameters: >> >> shared :symbol_id2name do |cmd| >> describe "Symbol\##{cmd}" do >> it "returns the string corresponding to self" do >> :rubinius.send(cmd).should == "rubinius" >> :squash.send(cmd).should == "squash" >> :[].send(cmd).should == "[]" >> :@ruby.send(cmd).should == "@ruby" >> :@@ruby.send(cmd).should == "@@ruby" >> end >> end >> end >> >> require File.dirname(__FILE__) + ''/../../spec_helper'' >> >> describe "Symbol#to_s" do >> it_behaves_like(:symbol_id2name, :to_s) >> end >> >> >> This doesn''t seem that hard to implement. Is there some reason a >> patch has been created yet? > > Yes. You haven''t submitted it. > >> >> Scott >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On Nov 21, 2007 4:16 PM, Nathan Sutton <nathan.sutton at gmail.com> wrote:> Nathan Sutton > fowlduck at gmail.com > rspec edge revision 2910 > rspec_on_rails edge revision 2909 > rails edge revision 8175Have you added this to your signature????
On Nov 21, 2007, at 5:16 PM, Nathan Sutton wrote:> Ooh, I totally want to do this, I''ll work on it this week along with > my other patch i have yet to submit this week, unless Scott is partial > to doing it. Do you want it, Scott?Go for it. Let me know if you don''t want it. What is the syntax your thinking of? Scott
Yeah, I''m currently doing it manually though, and this email is only for mailing lists. Nathan Sutton fowlduck at gmail.com rspec edge revision 2910 rspec_on_rails edge revision 2909 rails edge revision 8175 On Nov 21, 2007, at 4:31 PM, David Chelimsky wrote:> On Nov 21, 2007 4:16 PM, Nathan Sutton <nathan.sutton at gmail.com> > wrote: >> Nathan Sutton >> fowlduck at gmail.com >> rspec edge revision 2910 >> rspec_on_rails edge revision 2909 >> rails edge revision 8175 > > Have you added this to your signature???? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Oh, and the reason I include this is because it''s always a question when discussing things, and this makes it always available, both to those reading now and those who may read these conversations in the future. Nathan Sutton fowlduck at gmail.com rspec edge revision 2910 rspec_on_rails edge revision 2909 rails edge revision 8175 On Nov 21, 2007, at 4:31 PM, David Chelimsky wrote:> On Nov 21, 2007 4:16 PM, Nathan Sutton <nathan.sutton at gmail.com> > wrote: >> Nathan Sutton >> fowlduck at gmail.com >> rspec edge revision 2910 >> rspec_on_rails edge revision 2909 >> rails edge revision 8175 > > Have you added this to your signature???? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On Nov 21, 2007, at 5:31 PM, David Chelimsky wrote:> On Nov 21, 2007 4:16 PM, Nathan Sutton <nathan.sutton at gmail.com> > wrote: >> Nathan Sutton >> fowlduck at gmail.com >> rspec edge revision 2910 >> rspec_on_rails edge revision 2909 >> rails edge revision 8175 > > Have you added this to your signature????Haha. Probably not a bad option.
Not even sure, what are your thoughts? Nathan Sutton fowlduck at gmail.com rspec edge revision 2910 rspec_on_rails edge revision 2909 rails edge revision 8175 On Nov 21, 2007, at 4:31 PM, Scott Taylor wrote:> > On Nov 21, 2007, at 5:16 PM, Nathan Sutton wrote: > >> Ooh, I totally want to do this, I''ll work on it this week along with >> my other patch i have yet to submit this week, unless Scott is >> partial >> to doing it. Do you want it, Scott? > > Go for it. Let me know if you don''t want it. > > What is the syntax your thinking of? > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On Nov 21, 2007, at 5:42 PM, Nathan Sutton wrote:> Not even sure, what are your thoughts? > > Nathan Sutton > fowlduck at gmail.com > rspec edge revision 2910 > rspec_on_rails edge revision 2909 > rails edge revision 8175 >I''d like to see something like this: it_should_behave_like "a foo", :variables => { :bar => "bar", :baz => "baz", :class => Object } describe "a foo", :shared => true do it "should have the variable bar there, equal to bar" do bar.should == "bar" end end Conceivably, you could do some metaprogramming to define methods "bar" and "baz" in the ExampleGroupClass (or whatever that thing is called now) to return the values give in the hash. Scott> > > On Nov 21, 2007, at 4:31 PM, Scott Taylor wrote: > >> >> On Nov 21, 2007, at 5:16 PM, Nathan Sutton wrote: >> >>> Ooh, I totally want to do this, I''ll work on it this week along with >>> my other patch i have yet to submit this week, unless Scott is >>> partial >>> to doing it. Do you want it, Scott? >> >> Go for it. Let me know if you don''t want it. >> >> What is the syntax your thinking of? >> >> Scott >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Anyone else have any opinions on this? I''d like to get some more input. Thanks, Nathan Sutton fowlduck at gmail.com rspec edge revision 2910 rspec_on_rails edge revision 2909 rails edge revision 8175 On Nov 21, 2007, at 4:58 PM, Scott Taylor wrote:> > On Nov 21, 2007, at 5:42 PM, Nathan Sutton wrote: > >> Not even sure, what are your thoughts? >> >> Nathan Sutton >> fowlduck at gmail.com >> rspec edge revision 2910 >> rspec_on_rails edge revision 2909 >> rails edge revision 8175 >> > > I''d like to see something like this: > > > it_should_behave_like "a foo", :variables => { > :bar => "bar", > :baz => "baz", > :class => Object > } > > > describe "a foo", :shared => true do > > it "should have the variable bar there, equal to bar" do > bar.should == "bar" > end > > end > > Conceivably, you could do some metaprogramming to define methods > "bar" and "baz" in the ExampleGroupClass (or whatever that thing is > called now) to return the values give in the hash. > > Scott > > > > >> >> >> On Nov 21, 2007, at 4:31 PM, Scott Taylor wrote: >> >>> >>> On Nov 21, 2007, at 5:16 PM, Nathan Sutton wrote: >>> >>>> Ooh, I totally want to do this, I''ll work on it this week along >>>> with >>>> my other patch i have yet to submit this week, unless Scott is >>>> partial >>>> to doing it. Do you want it, Scott? >>> >>> Go for it. Let me know if you don''t want it. >>> >>> What is the syntax your thinking of? >>> >>> Scott >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
I like what Scott suggested. it_should_behave_like "a foo", :with => { ... } Might read a little better. But I like the idea of it just taking a hash. -Ben Nathan Sutton wrote:> Anyone else have any opinions on this? I''d like to get some more input. > > Thanks, > > Nathan Sutton > fowlduck at gmail.com > rspec edge revision 2910 > rspec_on_rails edge revision 2909 > rails edge revision 8175 > > > > On Nov 21, 2007, at 4:58 PM, Scott Taylor wrote: > > >> On Nov 21, 2007, at 5:42 PM, Nathan Sutton wrote: >> >> >>> Not even sure, what are your thoughts? >>> >>> Nathan Sutton >>> fowlduck at gmail.com >>> rspec edge revision 2910 >>> rspec_on_rails edge revision 2909 >>> rails edge revision 8175 >>> >>> >> I''d like to see something like this: >> >> >> it_should_behave_like "a foo", :variables => { >> :bar => "bar", >> :baz => "baz", >> :class => Object >> } >> >> >> describe "a foo", :shared => true do >> >> it "should have the variable bar there, equal to bar" do >> bar.should == "bar" >> end >> >> end >> >> Conceivably, you could do some metaprogramming to define methods >> "bar" and "baz" in the ExampleGroupClass (or whatever that thing is >> called now) to return the values give in the hash. >> >> Scott >> >> >> >> >> >>> On Nov 21, 2007, at 4:31 PM, Scott Taylor wrote: >>> >>> >>>> On Nov 21, 2007, at 5:16 PM, Nathan Sutton wrote: >>>> >>>> >>>>> Ooh, I totally want to do this, I''ll work on it this week along >>>>> with >>>>> my other patch i have yet to submit this week, unless Scott is >>>>> partial >>>>> to doing it. Do you want it, Scott? >>>>> >>>> Go for it. Let me know if you don''t want it. >>>> >>>> What is the syntax your thinking of? >>>> >>>> Scott >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Nov 21, 2007, at 11:14 PM, Ben Mabey wrote:> I like what Scott suggested. > > it_should_behave_like "a foo", :with => { ... } > > Might read a little better. But I like the idea of it just taking > a hash. >The obvious problem with this approach is that it will crowd the namespace (declaring methods in the shared example object might lead to some hard to track down bugs). The other suggestion, as proposed in IRC (for those who may not have been in the room). [11:06pm] smtlaissezfaire: So I was thinking of another way to do this - with the shared specs [11:06pm] fowlduck: elaborate [11:06pm] smtlaissezfaire: It could be block/lambda based [11:06pm] fowlduck: that''s actually what I was going to suggest [11:06pm] smtlaissezfaire: So you might say it_should_behave_like "foo", var1, var2 and so on [11:07pm] fowlduck: *args, &proc [11:07pm] fowlduck: or something [11:07pm] smtlaissezfaire: and then describe "a shared example", :shared => true do |var1, var2| I''m interested in other''s opinions (or other suggestions). Scott
Bah, I won''t have time to do this anytime soon, you can feel free, Scott. Nathan Sutton fowlduck at gmail.com rspec edge revision 2944 rspec_on_rails edge revision 2944 rails edge revision 8186 On Nov 21, 2007, at 10:25 PM, Scott Taylor wrote:> > On Nov 21, 2007, at 11:14 PM, Ben Mabey wrote: > >> I like what Scott suggested. >> >> it_should_behave_like "a foo", :with => { ... } >> >> Might read a little better. But I like the idea of it just taking >> a hash. >> > > The obvious problem with this approach is that it will crowd the > namespace (declaring methods in the shared example object might lead > to some hard to track down bugs). > > > The other suggestion, as proposed in IRC (for those who may not have > been in the room). > > [11:06pm] smtlaissezfaire: So I was thinking of another way to do > this - with the shared specs > [11:06pm] fowlduck: elaborate > [11:06pm] smtlaissezfaire: It could be block/lambda based > [11:06pm] fowlduck: that''s actually what I was going to suggest > [11:06pm] smtlaissezfaire: So you might say it_should_behave_like > "foo", var1, var2 and so on > [11:07pm] fowlduck: *args, &proc > [11:07pm] fowlduck: or something > [11:07pm] smtlaissezfaire: and then describe "a shared > example", :shared => true do |var1, var2| > > I''m interested in other''s opinions (or other suggestions). > > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users