From ben at benburkert.com Wed Aug 1 01:13:24 2007 From: ben at benburkert.com (Ben Burkert) Date: Wed, 1 Aug 2007 00:13:24 -0500 Subject: [rspec-users] PaginationHelper load_missing_constant error Message-ID: <91B5F200-7868-4FE7-8319-A379E27B2873@benburkert.com> I just ran into this error after updating rails and the rspec_on_rails plugin (both are on edge): /Users/ben/Work/wizzdl/vendor/rails/activerecord/lib/../../ activesupport/lib/active_support/dependencies.rb:263:in `load_missing_constant': uninitialized constant ActionView::Helpers::PaginationHelper (NameError) from /Users/ben/Work/wizzdl/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:452:in `const_missing' from /Users/ben/Work/wizzdl/vendor/plugins/rspec_on_rails/ lib/spec/rails/dsl/behaviour/helper.rb:33 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:27:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:27:in `require' from /Users/ben/Work/wizzdl/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:495:in `require' from /Users/ben/Work/wizzdl/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in' from /Users/ben/Work/wizzdl/vendor/rails/activerecord/ lib/../../activesupport/lib/active_support/dependencies.rb:495:in `require' from /Users/ben/Work/wizzdl/vendor/plugins/rspec_on_rails/ lib/spec/rails/dsl/behaviour.rb:8 I'm not sure if the problem is with rails or rspec, or even if there is one, so I'll wait until someone confirms it before submitting a bug. If you do run into this problem, commenting out line 33 of rspec_on_rails/lib/spec/rails/dsl/behaviour/helper.rb made the error message disappear, but it could have side effects. -Ben -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070801/1df806bb/attachment.html From aslak.hellesoy at gmail.com Wed Aug 1 01:48:09 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 1 Aug 2007 07:48:09 +0200 Subject: [rspec-users] PaginationHelper load_missing_constant error In-Reply-To: <91B5F200-7868-4FE7-8319-A379E27B2873@benburkert.com> References: <91B5F200-7868-4FE7-8319-A379E27B2873@benburkert.com> Message-ID: <8d961d900707312248x5bc3a66eifd13ecfff6159b1b@mail.gmail.com> This is already in the tracker since a few hours. 2007/8/1, Ben Burkert : > I just ran into this error after updating rails and the > rspec_on_rails plugin (both are on edge): > > /Users/ben/Work/wizzdl/vendor/rails/activerecord/lib/../../ > activesupport/lib/active_support/dependencies.rb:263:in > `load_missing_constant': uninitialized constant > ActionView::Helpers::PaginationHelper (NameError) > from /Users/ben/Work/wizzdl/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:452:in > `const_missing' > from /Users/ben/Work/wizzdl/vendor/plugins/rspec_on_rails/ > lib/spec/rails/dsl/behaviour/helper.rb:33 > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/ > custom_require.rb:27:in `gem_original_require' > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/ > custom_require.rb:27:in `require' > from /Users/ben/Work/wizzdl/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:495:in > `require' > from /Users/ben/Work/wizzdl/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:342:in > `new_constants_in' > from /Users/ben/Work/wizzdl/vendor/rails/activerecord/ > lib/../../activesupport/lib/active_support/dependencies.rb:495:in > `require' > from /Users/ben/Work/wizzdl/vendor/plugins/rspec_on_rails/ > lib/spec/rails/dsl/behaviour.rb:8 > > > I'm not sure if the problem is with rails or rspec, or even if there > is one, so I'll wait until someone confirms it before submitting a bug. > > If you do run into this problem, commenting out line 33 of > rspec_on_rails/lib/spec/rails/dsl/behaviour/helper.rb made the error > message disappear, but it could have side effects. > > -Ben From edward.og at gmail.com Wed Aug 1 14:43:23 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Wed, 01 Aug 2007 14:43:23 -0400 Subject: [rspec-users] :render expects possible? Message-ID: <46B0D44B.5080009@gmail.com> Hi, Is it possible to do the following in a controller spec? @controller.should_receive(:render).with(:layout => false) I've been trying this kind of thing and it looks like RSpec is messing with the render calls, and requires you to use render_template instead. Could we have at least a warning that mentions that parameters passed to :render expectations are going to be thrown away and mention an alternative way of spec-ing this behaviour? Thanks, Edward From dchelimsky at gmail.com Wed Aug 1 16:49:28 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 1 Aug 2007 15:49:28 -0500 Subject: [rspec-users] :render expects possible? In-Reply-To: <46B0D44B.5080009@gmail.com> References: <46B0D44B.5080009@gmail.com> Message-ID: <57c63afe0708011349t54613271j8d73a46cc369c151@mail.gmail.com> On 8/1/07, Edward Ocampo-Gooding wrote: > Hi, > > Is it possible to do the following in a controller spec? > > @controller.should_receive(:render).with(:layout => false) > > I've been trying this kind of thing and it looks like RSpec is messing > with the render calls, and requires you to use render_template instead. > > Could we have at least a warning that mentions that parameters passed to > :render expectations are going to be thrown away and mention an > alternative way of spec-ing this behaviour? In trunk, when you call should_receive(:render) you will get an error saying you should use the new method (also in trunk) controller.expects_render. Cheers, David > Thanks, > Edward > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From smingins at elctech.com Wed Aug 1 18:47:06 2007 From: smingins at elctech.com (Shane Mingins) Date: Thu, 2 Aug 2007 10:47:06 +1200 Subject: [rspec-users] Test Rendering nothing in Rails Message-ID: <5E0791E9-B2D2-464A-BA4B-5BA7C94DC9D3@elctech.com> Hi In a controller I have method that is accessed via an AJAX call and will conditionally do: render :nothing => true to test the condition hitting this line I was hoping to do something like: response.should render_template(:nothing) How should I test this behaviour? Cheers Shane From smingins at elctech.com Wed Aug 1 18:54:16 2007 From: smingins at elctech.com (Shane Mingins) Date: Thu, 2 Aug 2007 10:54:16 +1200 Subject: [rspec-users] Test Rendering nothing in Rails In-Reply-To: <5E0791E9-B2D2-464A-BA4B-5BA7C94DC9D3@elctech.com> References: <5E0791E9-B2D2-464A-BA4B-5BA7C94DC9D3@elctech.com> Message-ID: <27B3993F-4E82-468A-85F9-42844C7EF15D@elctech.com> ok ... went with response.body.should == " " On 2/08/2007, at 10:47 AM, Shane Mingins wrote: > Hi > > In a controller I have method that is accessed via an AJAX call and > will conditionally do: > > render :nothing => true > > to test the condition hitting this line I was hoping to do > something like: > > response.should render_template(:nothing) > > How should I test this behaviour? > > Cheers > Shane > r -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070802/e98cf247/attachment.html From smingins at elctech.com Wed Aug 1 19:00:18 2007 From: smingins at elctech.com (Shane Mingins) Date: Thu, 2 Aug 2007 11:00:18 +1200 Subject: [rspec-users] Test Rendering nothing in Rails In-Reply-To: <27B3993F-4E82-468A-85F9-42844C7EF15D@elctech.com> References: <5E0791E9-B2D2-464A-BA4B-5BA7C94DC9D3@elctech.com> <27B3993F-4E82-468A-85F9-42844C7EF15D@elctech.com> Message-ID: and better: response.body.should be_blank On 2/08/2007, at 10:54 AM, Shane Mingins wrote: > ok ... went with response.body.should == " " > > > On 2/08/2007, at 10:47 AM, Shane Mingins wrote: > >> Hi >> >> In a controller I have method that is accessed via an AJAX call >> and will conditionally do: >> >> render :nothing => true >> >> to test the condition hitting this line I was hoping to do >> something like: >> >> response.should render_template(:nothing) >> >> How should I test this behaviour? >> >> Cheers >> Shane >> > > r Shane Mingins ELC Technologies (TM) PO Box 247 Santa Barbara, CA 93102 Phone: +64 4 568 6684 Mobile: +64 21 435 586 Email: smingins at elctech.com AIM: ShaneMingins Skype: shane.mingins (866) 863-7365 Tel - Santa Barbara Office (866) 893-1902 Fax - Santa Barbara Office +44 020 7504 1346 Tel - London Office +44 020 7504 1347 Fax - London Office http://www.elctech.com -------------------------------------------------------------------- Privacy and Confidentiality Notice: The information contained in this electronic mail message is intended for the named recipient(s) only. It may contain privileged and confidential information. If you are not an intended recipient, you must not copy, forward, distribute or take any action in reliance on it. If you have received this electronic mail message in error, please notify the sender immediately. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070802/f7045ee0/attachment-0001.html From edward.og at gmail.com Thu Aug 2 01:03:30 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Thu, 02 Aug 2007 01:03:30 -0400 Subject: [rspec-users] :render expects possible? In-Reply-To: <57c63afe0708011349t54613271j8d73a46cc369c151@mail.gmail.com> References: <46B0D44B.5080009@gmail.com> <57c63afe0708011349t54613271j8d73a46cc369c151@mail.gmail.com> Message-ID: <46B165A2.2090002@gmail.com> David Chelimsky wrote: > On 8/1/07, Edward Ocampo-Gooding wrote: >> Hi, >> >> Is it possible to do the following in a controller spec? >> >> @controller.should_receive(:render).with(:layout => false) >> >> I've been trying this kind of thing and it looks like RSpec is messing >> with the render calls, and requires you to use render_template instead. >> >> Could we have at least a warning that mentions that parameters passed to >> :render expectations are going to be thrown away and mention an >> alternative way of spec-ing this behaviour? > > In trunk, when you call should_receive(:render) you will get an error > saying you should use the new method (also in trunk) > controller.expects_render. Right on. Thanks for the tip. By the way, is there support for catching methods that haven't been stubbed out on mock objects and throwing appropriate warnings? The last time this happened by accident, I just got a mess of rspec debugging log dumps. From dchelimsky at gmail.com Thu Aug 2 01:06:52 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 2 Aug 2007 00:06:52 -0500 Subject: [rspec-users] :render expects possible? In-Reply-To: <46B165A2.2090002@gmail.com> References: <46B0D44B.5080009@gmail.com> <57c63afe0708011349t54613271j8d73a46cc369c151@mail.gmail.com> <46B165A2.2090002@gmail.com> Message-ID: <57c63afe0708012206t5e013d2ap4d0f2cb9dd39dfca@mail.gmail.com> On 8/2/07, Edward Ocampo-Gooding wrote: > David Chelimsky wrote: > > On 8/1/07, Edward Ocampo-Gooding wrote: > >> Hi, > >> > >> Is it possible to do the following in a controller spec? > >> > >> @controller.should_receive(:render).with(:layout => false) > >> > >> I've been trying this kind of thing and it looks like RSpec is messing > >> with the render calls, and requires you to use render_template instead. > >> > >> Could we have at least a warning that mentions that parameters passed to > >> :render expectations are going to be thrown away and mention an > >> alternative way of spec-ing this behaviour? > > > > In trunk, when you call should_receive(:render) you will get an error > > saying you should use the new method (also in trunk) > > controller.expects_render. > > Right on. Thanks for the tip. > > By the way, is there support for catching methods that haven't been > stubbed out on mock objects and throwing appropriate warnings? Sorry but I don't really understand what you mean? Can you give an example? > The last > time this happened by accident, I just got a mess of rspec debugging log > dumps. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From edward.og at gmail.com Thu Aug 2 09:02:16 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Thu, 02 Aug 2007 09:02:16 -0400 Subject: [rspec-users] Test Rendering nothing in Rails In-Reply-To: References: <5E0791E9-B2D2-464A-BA4B-5BA7C94DC9D3@elctech.com> <27B3993F-4E82-468A-85F9-42844C7EF15D@elctech.com> Message-ID: <46B1D5D8.1010203@gmail.com> Hi Shane, (I'll continue with the top-posting, but I think it should be discouraged.) As David just mentioned to me in the response to a related question, you might want to check out @controller.expects_render which is now available in rspec trunk. While the response.body.should be_empty kind of thing makes sense, it'd be nice to have a render expectation too. Edward Shane Mingins wrote: > and better: response.body.should be_blank > > On 2/08/2007, at 10:54 AM, Shane Mingins wrote: > >> ok ... went with response.body.should == " " >> >> >> On 2/08/2007, at 10:47 AM, Shane Mingins wrote: >> >>> Hi >>> >>> In a controller I have method that is accessed via an AJAX call and >>> will conditionally do: >>> >>> render :nothing => true >>> >>> to test the condition hitting this line I was hoping to do something >>> like: >>> >>> response.should render_template(:nothing) >>> >>> How should I test this behaviour? >>> >>> Cheers >>> Shane >>> >> >> r > > Shane Mingins > ELC Technologies (TM) > PO Box 247 > Santa Barbara, CA 93102 > > Phone: +64 4 568 6684 > Mobile: +64 21 435 586 > Email: smingins at elctech.com > AIM: ShaneMingins > Skype: shane.mingins > > (866) 863-7365 Tel - Santa Barbara Office > (866) 893-1902 Fax - Santa Barbara Office > > +44 020 7504 1346 Tel - London Office > +44 020 7504 1347 Fax - London Office > > http://www.elctech.com > > -------------------------------------------------------------------- > Privacy and Confidentiality Notice: > The information contained in this electronic mail message is > intended for the named recipient(s) only. It may contain privileged > and confidential information. If you are not an intended recipient, you > must not copy, forward, distribute or take any action in reliance on it. > If you have received this electronic mail message in error, please > notify the sender immediately. > > > > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From hussein at morsy.de Thu Aug 2 10:02:27 2007 From: hussein at morsy.de (Hussein Morsy) Date: Thu, 2 Aug 2007 16:02:27 +0200 Subject: [rspec-users] Best practice integration testing In-Reply-To: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> Message-ID: <569E74A7-C0B6-4997-B611-C408F938F0E4@morsy.de> Hello, Are there are any best pracitces for integration-testing is rspec? What about tutorials ? I found only http://wincent.com/knowledge-base/ Using_Watir_with_RSpec_and_Rails Chears Hussein From edward.og at gmail.com Thu Aug 2 10:36:29 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Thu, 02 Aug 2007 10:36:29 -0400 Subject: [rspec-users] :render expects possible? In-Reply-To: <57c63afe0708012206t5e013d2ap4d0f2cb9dd39dfca@mail.gmail.com> References: <46B0D44B.5080009@gmail.com> <57c63afe0708011349t54613271j8d73a46cc369c151@mail.gmail.com> <46B165A2.2090002@gmail.com> <57c63afe0708012206t5e013d2ap4d0f2cb9dd39dfca@mail.gmail.com> Message-ID: <46B1EBED.7000900@gmail.com> >>>> Could we have at least a warning that mentions that parameters passed to >>>> :render expectations are going to be thrown away and mention an >>>> alternative way of spec-ing this behaviour? >>> In trunk, when you call should_receive(:render) you will get an error >>> saying you should use the new method (also in trunk) >>> controller.expects_render. >> Right on. Thanks for the tip. >> >> By the way, is there support for catching methods that haven't been >> stubbed out on mock objects and throwing appropriate warnings? > > Sorry but I don't really understand what you mean? Can you give an example? Frustratingly, no. I tried to reproduce it with what I remember I had yesterday, but the bug that triggered the river of rspec debugging code has yet to resurface. (I think it had something to do with calling to_s on mock objects in a certain way, but I can't seem to remember.) Basically, what I was trying to say was that I was hoping that if you had something like language = mock_model(Language) then later called language.name it would say something along the lines of "you've called a mock object's method that you forgot to stub", but I see that it already does this under normal conditions. I'll let you know if I find the bug again. From lists-rspec at shopwatch.org Thu Aug 2 09:57:40 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Thu, 02 Aug 2007 09:57:40 -0400 Subject: [rspec-users] got/expects causes mental layering violation Message-ID: <46B1E2D4.9010503@shopwatch.org> I was, for the first time, spec'ing a class that redefined ==. And my spec was incorrect, so == was returning false. The result was something like: class C def ==(other) false end end .. C.new.should == other... expected other, got # (using ==) But wait! Why on earth is == returning the class itself instead of true/false? That shouldn't be possible. No, no time for coffee, let me go debug this for a few hours... oh. of course. == IS returning a boolean value, in this case, false; rspec is helpfully showing me C.inspect so I can see why they MIGHT differ, assuming I haven't redefined ==. Which I have. Would it be good, when == is redefined (or eql? or equals?) for the rspec output to indicate somehow what it's doing and why you might be seeing what you're seeing? Maybe something like expected C==other, but C!=other. You have redefined ==. C.inspect shows: # but much prettier and better worded. Or do I just call this a learning experience? Jay From dchelimsky at gmail.com Thu Aug 2 10:44:09 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 2 Aug 2007 09:44:09 -0500 Subject: [rspec-users] Best practice integration testing In-Reply-To: <569E74A7-C0B6-4997-B611-C408F938F0E4@morsy.de> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <569E74A7-C0B6-4997-B611-C408F938F0E4@morsy.de> Message-ID: <57c63afe0708020744h5d8c362bua6ecc0c6ae059fa6@mail.gmail.com> On 8/2/07, Hussein Morsy wrote: > Hello, > > Are there are any best pracitces for integration-testing is rspec? > What about tutorials ? > > I found only http://wincent.com/knowledge-base/ > Using_Watir_with_RSpec_and_Rails We're working on getting the rbehave story runner merged into rspec and able to integrate w/ rails, but that's probably a couple of months away from reality. Right now I just use rails integration testing and spec/ui to drive in-browser tests with Selenium or Watir. > > Chears > > Hussein > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From hussein at morsy.de Thu Aug 2 10:52:30 2007 From: hussein at morsy.de (Hussein Morsy) Date: Thu, 2 Aug 2007 16:52:30 +0200 Subject: [rspec-users] Best practice integration testing In-Reply-To: <57c63afe0708020744h5d8c362bua6ecc0c6ae059fa6@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <569E74A7-C0B6-4997-B611-C408F938F0E4@morsy.de> <57c63afe0708020744h5d8c362bua6ecc0c6ae059fa6@mail.gmail.com> Message-ID: > > We're working on getting the rbehave story runner merged into rspec > and able to integrate w/ rails, but that's probably a couple of months > away from reality. > nice to hear :-) > Right now I just use rails integration testing and spec/ui to drive > in-browser tests with Selenium or Watir. > To you have an example how to use spec/ui ? >> >> Chears >> >> Hussein >> >> >> _______________________________________________ >> 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 > From dchelimsky at gmail.com Thu Aug 2 10:56:00 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 2 Aug 2007 09:56:00 -0500 Subject: [rspec-users] Best practice integration testing In-Reply-To: References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <569E74A7-C0B6-4997-B611-C408F938F0E4@morsy.de> <57c63afe0708020744h5d8c362bua6ecc0c6ae059fa6@mail.gmail.com> Message-ID: <57c63afe0708020756j75659a79kb5c1eea89ae75ee4@mail.gmail.com> On 8/2/07, Hussein Morsy wrote: > > > > We're working on getting the rbehave story runner merged into rspec > > and able to integrate w/ rails, but that's probably a couple of months > > away from reality. > > > > nice to hear :-) > > > > > > Right now I just use rails integration testing and spec/ui to drive > > in-browser tests with Selenium or Watir. > > > > To you have an example how to use spec/ui ? There are examples in the spec/ui directory tree: svn co svn://rubyforge.org/var/svn/rspec/trunk/spec_ui > > > > > >> > >> Chears > >> > >> Hussein > >> > >> > >> _______________________________________________ > >> 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 > From dchelimsky at gmail.com Thu Aug 2 11:01:27 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 2 Aug 2007 10:01:27 -0500 Subject: [rspec-users] got/expects causes mental layering violation In-Reply-To: <46B1E2D4.9010503@shopwatch.org> References: <46B1E2D4.9010503@shopwatch.org> Message-ID: <57c63afe0708020801v46804793t98d10693fefdad22@mail.gmail.com> On 8/2/07, Jay Levitt wrote: > I was, for the first time, spec'ing a class that redefined ==. And my > spec was incorrect, so == was returning false. > > The result was something like: > > class C > def ==(other) > false > end > end > > .. C.new.should == other... > > expected other, got # (using ==) What did it really call other? The output should be evaluating a variable there, not naming it. > But wait! Why on earth is == returning the class itself instead of > true/false? That shouldn't be possible. No, no time for coffee, let me > go debug this for a few hours... oh. of course. == IS returning a > boolean value, in this case, false; rspec is helpfully showing me > C.inspect so I can see why they MIGHT differ, assuming I haven't > redefined ==. Which I have. > > Would it be good, when == is redefined (or eql? or equals?) for the > rspec output to indicate somehow what it's doing and why you might be > seeing what you're seeing? Maybe something like > > expected C==other, but C!=other. You have redefined ==. C.inspect > shows: # > > but much prettier and better worded. > > Or do I just call this a learning experience? I must be missing something. I don't really understand the problem you are experiencing. Any class can redefine == at any time. Many library classes do. That's just part of the language. You defined == to always return false, so the feedback you got seems to be the feedback you would expect. Even if you do explain this differently and I end up seeing it differently, I don't think it's feasible for rspec to be trying to discover what methods get defined, overridden, etc, and when. Cheers, David > > Jay > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From hussein at macnews.de Thu Aug 2 10:51:55 2007 From: hussein at macnews.de (Hussein) Date: Thu, 2 Aug 2007 16:51:55 +0200 Subject: [rspec-users] Best practice integration testing In-Reply-To: <57c63afe0708020744h5d8c362bua6ecc0c6ae059fa6@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <569E74A7-C0B6-4997-B611-C408F938F0E4@morsy.de> <57c63afe0708020744h5d8c362bua6ecc0c6ae059fa6@mail.gmail.com> Message-ID: > > We're working on getting the rbehave story runner merged into rspec > and able to integrate w/ rails, but that's probably a couple of months > away from reality. nice to hear :-) > Right now I just use rails integration testing and spec/ui to drive > in-browser tests with Selenium or Watir. To you have an example how to use spec/ui ? >> >> Chears >> >> Hussein >> >> >> _______________________________________________ >> 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 From lists-rspec at shopwatch.org Thu Aug 2 16:10:48 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Thu, 02 Aug 2007 16:10:48 -0400 Subject: [rspec-users] got/expects causes mental layering violation In-Reply-To: <57c63afe0708020801v46804793t98d10693fefdad22@mail.gmail.com> References: <46B1E2D4.9010503@shopwatch.org> <57c63afe0708020801v46804793t98d10693fefdad22@mail.gmail.com> Message-ID: <46B23A48.7010002@jay.fm> David Chelimsky wrote: > On 8/2/07, Jay Levitt wrote: >> I was, for the first time, spec'ing a class that redefined ==. And my >> spec was incorrect, so == was returning false. >> >> The result was something like: >> >> class C >> def ==(other) >> false >> end >> end >> >> .. C.new.should == other... >> >> expected other, got # (using ==) > > What did it really call other? The output should be evaluating a > variable there, not naming it. Right.. sorry, I over-simplified the example. It's more like: # class class C def initialize(name, value) @name = name @value = value end def ==(other) @value == other end end # spec .. c = C.new("name", 0) c.should == 1 # output expected 1, got # (using ==) And that's confusing at first glance, because it implies that it was trying to compare 1 to the whole object, when obviously the redefined == function would compare it to C.value (which == 0)! In an ideal world, rspec would tell me "expected 1, got 0". But that, of course, is impossible without reverse-engineering an == function to see what it's really doing. I'm not sure there is an actual solution, just throwing it out there to see if my confusion was common... Jay From rspec.user at gmail.com Thu Aug 2 16:15:41 2007 From: rspec.user at gmail.com (sinclair bain) Date: Thu, 2 Aug 2007 16:15:41 -0400 Subject: [rspec-users] Do the :attributes and :content matchers work Message-ID: <2ca660dd0708021315qa701a95h7a13334daa625b89@mail.gmail.com> [Rails plugin 1.0.5] Hi, I am looking for some guidance. When working on a partial which looks like this
I have some examples which should fail - I think - but do not: it ' should fail' do response.should have_tag( 'div.bug', :content => 'There is no content!' ) end it ' should fail since there is no bug attribute with a value of "here"' do response.should have_tag( 'div', :attributes => {:bug => "here"} ) response.should have_tag( 'div', :attributes => {:bug => "here", :another_bug => 'there'} ) end I am calling render :partial => '/bug/div' in the before :each block. As I said I would expect this to fail but it does not. I am trying this because in the /vendor/plugins/rspec_on_rails/spec/rails/dsl/view_spec_spec.rb file there is an example describe "A view that includes a partial using :collection and :spacer_template", :behaviour_type => :view do before(:each) do render "view_spec/partial_collection_including_template" end it "should render the partial w/ spacer_tamplate" do response.should have_tag('div', :content => 'Alice') response.should have_tag('hr', :attributes =>{:id => "spacer"}) response.should have_tag('div', :content => 'Bob') end end which does just this. Can anyone help please ? Cheers! sinclair -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070802/c3ed6209/attachment.html From dchelimsky at gmail.com Thu Aug 2 16:18:26 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 2 Aug 2007 15:18:26 -0500 Subject: [rspec-users] Do the :attributes and :content matchers work In-Reply-To: <2ca660dd0708021315qa701a95h7a13334daa625b89@mail.gmail.com> References: <2ca660dd0708021315qa701a95h7a13334daa625b89@mail.gmail.com> Message-ID: <57c63afe0708021318w60d74d6biecf4170e8f428ce@mail.gmail.com> On 8/2/07, sinclair bain wrote: > [Rails plugin 1.0.5] > > > Hi, > I am looking for some guidance. > When working on a partial which looks like this > >
> > I have some examples which should fail - I think - but do not: > > it ' should fail' do > response.should have_tag( 'div.bug', :content => 'There is no > content!' ) > end have_tag wraps the assert_select API. Basically, your hash (:content => ...) is being ignored. What you want to say is: response.should have_tag('div.bug', 'There is no content!') That should fail. Please report back. Thanks, David > > it ' should fail since there is no bug attribute with a value of > "here"' do > response.should have_tag( 'div', :attributes => {:bug => "here"} ) > response.should have_tag( 'div', :attributes => {:bug => "here", > :another_bug => 'there'} ) > end > > I am calling render :partial => '/bug/div' in the before :each block. > > As I said I would expect this to fail but it does not. > > I am trying this because in the > > > /vendor/plugins/rspec_on_rails/spec/rails/dsl/view_spec_spec.rb > > file there is an example > > describe "A view that includes a partial using :collection and > :spacer_template", :behaviour_type => :view do > > before(:each) do > render > "view_spec/partial_collection_including_template" > end > > it "should render the partial w/ spacer_tamplate" do > response.should have_tag('div', :content => 'Alice') > response.should have_tag('hr', :attributes =>{:id => "spacer"}) > response.should have_tag('div', :content => 'Bob') > end > > end > > which does just this. > > Can anyone help please ? > > Cheers! > sinclair > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Aug 2 16:24:04 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 2 Aug 2007 15:24:04 -0500 Subject: [rspec-users] Do the :attributes and :content matchers work In-Reply-To: <2ca660dd0708021315qa701a95h7a13334daa625b89@mail.gmail.com> References: <2ca660dd0708021315qa701a95h7a13334daa625b89@mail.gmail.com> Message-ID: <57c63afe0708021324hcfc3921p6cdb46df1218ef33@mail.gmail.com> On 8/2/07, sinclair bain wrote: > [Rails plugin 1.0.5] > > > Hi, > I am looking for some guidance. > When working on a partial which looks like this > >
> > I have some examples which should fail - I think - but do not: > > it ' should fail' do > response.should have_tag( 'div.bug', :content => 'There is no > content!' ) > end > > it ' should fail since there is no bug attribute with a value of > "here"' do > response.should have_tag( 'div', :attributes => {:bug => "here"} ) > response.should have_tag( 'div', :attributes => {:bug => "here", > :another_bug => 'there'} ) > end > > I am calling render :partial => '/bug/div' in the before :each block. > > As I said I would expect this to fail but it does not. > > I am trying this because in the > > > /vendor/plugins/rspec_on_rails/spec/rails/dsl/view_spec_spec.rb > > file there is an example > > describe "A view that includes a partial using :collection and > :spacer_template", :behaviour_type => :view do > > before(:each) do > render > "view_spec/partial_collection_including_template" > end > > it "should render the partial w/ spacer_tamplate" do > response.should have_tag('div', :content => 'Alice') > response.should have_tag('hr', :attributes =>{:id => "spacer"}) > response.should have_tag('div', :content => 'Bob') > end Ugh. Those are holdovers from the old API and are only passing because :content and :attributes are being ignored. I'm updating them in rspec trunk to correctly reflect the API. > > end > > which does just this. > > Can anyone help please ? > > Cheers! > sinclair > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From philipp.engel at filzip.com Fri Aug 3 06:29:16 2007 From: philipp.engel at filzip.com (Philipp Engel) Date: Fri, 3 Aug 2007 10:29:16 +0000 (UTC) Subject: [rspec-users] more different predicates (not only should)? Message-ID: Hello, I am using rspec in a project and would like to know if you have thought about adding a feature. RSpec as I know it currently only knows about the predicate 'should'. What I have in mind would look something like this: it :should "have a valid name" now should is not part of the spec text, but a symbol. Then you could think of things like that: it :must "have a valid name" it :shall "have a valid name" so you can define some criticality, and if specs fail, you know what has a higher priority. Also, there could be a predicate that allows you to write down spec for future versions that do not have to work and are not shown when running the test in normal mode it :in_future_version_must "have a valid name" or something like that. Is something like that already planned or, if not, what do you think about a feature like this? From mailing_lists at railsnewbie.com Fri Aug 3 06:49:49 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 3 Aug 2007 06:49:49 -0400 Subject: [rspec-users] more different predicates (not only should)? In-Reply-To: References: Message-ID: <0B045C1F-CEB6-4426-8288-E660D1857D43@railsnewbie.com> On Aug 3, 2007, at 6:29 AM, Philipp Engel wrote: > Hello, > > I am using rspec in a project and would like to know if you have > thought about adding a feature. > RSpec as I know it currently only knows about the predicate 'should'. > What I have in mind would look something like this: > > it :should "have a valid name" > > now should is not part of the spec text, but a symbol. Then you > could think of things like that: > > it :must "have a valid name" > it :shall "have a valid name" > > so you can define some criticality, and if specs fail, you know > what has a higher priority. Also, there could be a predicate What would be the different levels of priority, and how would they be rated? As far as I've been doing it, BDD usually encourages example specification => implementing the spec => refactoring, and then repeating the process until your feature set is where you want it to be. Usually the only time a bunch of specs will fail is when you are doing some major refactoring, and so usually I look to refactor in a different way. From what I understand, there was once a time (long ago, something like pre v. 0.1) when these three names were all being considered as equals. Should won, and must lost. > that allows you to write down spec for future versions that do not > have to work and are not shown when running the test in normal mode > > it :in_future_version_must "have a valid name" > > or something like that. yep. That's the unimplemented spec. Don't provide a block, and the runner will let you know that the feature hasn't been implemented. So your example would be: it "should have a valid name" New on trunk is also the pending() method, which allows you to write the desired behaviour without it being implemented. It considers the spec as an unimplemented spec. Best, Scott From daniel at danielfischer.com Fri Aug 3 15:30:33 2007 From: daniel at danielfischer.com (Fischer, Daniel) Date: Fri, 3 Aug 2007 12:30:33 -0700 Subject: [rspec-users] Plugins 'speced' with rSpec? Message-ID: <7e565b5c0708031230wa0a51t1677136a8b4d571f@mail.gmail.com> Hello, I'm trying to figure out how to setup a spec structure for plugins. I'm getting pretty lost in figuring out how to isolate a plugin enviornment emulating rails, but not actually being reflected upon the current rails project. What I mean is this, let's say I have a comment plugin. This has two things in lib, the comment model (comment.rb) and then the module ruby file for methods. I'm trying to figure out how I would spec this out in the actual plugin directory (vendor/plugins/comment_plugin/spec). What would my spec_helper look like? How would I spec that it works? Why I'm saying this is because I can't use any of the /app/models/ in the rails project because that is specific to a rails project, I'm trying to isolate it into the plugin. How would I fake a model in rspec, especially with the line that "acts_as_comment" which sets up the polymorphic association. If anyone has any advice, or knows of any plugins that are tested with rspec and not rails testing, let me know. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070803/09f9e2af/attachment-0001.html From lists-rspec at shopwatch.org Fri Aug 3 15:42:57 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Fri, 03 Aug 2007 15:42:57 -0400 Subject: [rspec-users] Plugins 'speced' with rSpec? In-Reply-To: <7e565b5c0708031230wa0a51t1677136a8b4d571f@mail.gmail.com> References: <7e565b5c0708031230wa0a51t1677136a8b4d571f@mail.gmail.com> Message-ID: <46B38541.5020603@jay.fm> Fischer, Daniel wrote: > Hello, > > I'm trying to figure out how to setup a spec structure for plugins. I'm > getting pretty lost in figuring out how to isolate a plugin enviornment > emulating rails, but not actually being reflected upon the current rails > project. I just saw an article yesterday about this very topic, though of course it's Test::Unit-focused, not rspec: http://www.pluginaweek.org/2006/11/24/plugin-tip-of-the-week-testing-your-plugins-the-right-way/ From pergesu at gmail.com Fri Aug 3 15:47:05 2007 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 3 Aug 2007 12:47:05 -0700 Subject: [rspec-users] Plugins 'speced' with rSpec? In-Reply-To: <7e565b5c0708031230wa0a51t1677136a8b4d571f@mail.gmail.com> References: <7e565b5c0708031230wa0a51t1677136a8b4d571f@mail.gmail.com> Message-ID: <810a540e0708031247o3c40cb72q67ac84664f9b1b0c@mail.gmail.com> On 8/3/07, Fischer, Daniel wrote: > Hello, > > I'm trying to figure out how to setup a spec structure for plugins. I'm > getting pretty lost in figuring out how to isolate a plugin enviornment > emulating rails, but not actually being reflected upon the current rails > project. > > What I mean is this, let's say I have a comment plugin. This has two things > in lib, the comment model (comment.rb) and then the module ruby file for > methods. > > I'm trying to figure out how I would spec this out in the actual plugin > directory (vendor/plugins/comment_plugin/spec). What would > my spec_helper look like? How would I spec that it works? Why I'm saying > this is because I can't use any of the /app/models/ in the rails project > because that is specific to a rails project, I'm trying to isolate it into > the plugin. How would I fake a model in rspec, especially with the line > that "acts_as_comment" which sets up the polymorphic association. If anyone > has any advice, or knows of any plugins that are tested with rspec and not > rails testing, let me know. > > > Thanks. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Hey Daniel, You might be interested in the rspec_plugin generator. http://agilewebdevelopment.com/plugins/rspec_plugin Pat From justnothing at tiscali.co.uk Sat Aug 4 09:06:24 2007 From: justnothing at tiscali.co.uk (David Green) Date: Sat, 4 Aug 2007 06:06:24 -0700 (PDT) Subject: [rspec-users] reusable specs - almost there Message-ID: <11996399.post@talk.nabble.com> I have a lot of controllers with virtually identical functionality for most actions. I've been using shared behaviours to DRY things up a bit, but I still have to create separate behaviours for each context before I can use the shared behaviours what I have now is a generic file which contains all the behaviours and examples common to all the controllers, and that file gets loaded from an actual controller spec. The generic file knows which controller to test by calling kontroller(), which is defined in the controller spec. here's a very simplified example: http://pastebin.com/m6b47bae9 It works great when I run the specs individually, but when I use rake, specs begin to fail and i think it's because the value of kontroller() is set to whatever it returns the first time it gets called. Here's the rake output from running the specs shown above: FooController .FooController . Finished in 0.041793 seconds 2 examples, 0 failures I would expect it to print FooController and then BarController ... interestingly, if I insert 'puts kontroller.to_s' *outside* of the describe block, then it does output the names of both controllers as expected. does anyone know of a solution? thanks dave -- View this message in context: http://www.nabble.com/reusable-specs---almost-there-tf4216708.html#a11996399 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Sun Aug 5 11:57:38 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 5 Aug 2007 10:57:38 -0500 Subject: [rspec-users] reusable specs - almost there In-Reply-To: <11996399.post@talk.nabble.com> References: <11996399.post@talk.nabble.com> Message-ID: <57c63afe0708050857x61afe07aiedafcea9f4961698@mail.gmail.com> On 8/4/07, David Green wrote: > > I have a lot of controllers with virtually identical functionality for most > actions. I've been using shared behaviours to DRY things up a bit, but I > still have to create separate behaviours for each context before I can use > the shared behaviours > > what I have now is a generic file which contains all the behaviours and > examples common to all the controllers, and that file gets loaded from an > actual controller spec. The generic file knows which controller to test by > calling kontroller(), which is defined in the controller spec. > > here's a very simplified example: > http://pastebin.com/m6b47bae9 > > It works great when I run the specs individually, but when I use rake, specs > begin to fail and i think it's because the value of kontroller() is set to > whatever it returns the first time it gets called. Here's the rake output > from running the specs shown above: > > > FooController > .FooController > . > > Finished in 0.041793 seconds > 2 examples, 0 failures > > I would expect it to print FooController and then BarController ... > interestingly, if I insert 'puts kontroller.to_s' *outside* of the describe > block, then it does output the names of both controllers as expected. > > does anyone know of a solution? > thanks > > dave I'm all for keeping things DRY, but NEVER at the risk of clarity. You've got to balance DRY and readability/clarity. Anybody familiar with rspec can look at this: ========================= describe FooController do it_should_behave_like "All Controllers" end ========================= and understand what that means: A FooController should behave like All Controllers. Perhaps there is a split second of mental mapping: "Oh, there must be some behaviour described for all controllers that the FooController should adopt." Compare that to your example: ========================= def kontroller FooController end load File.dirname(__FILE__) + '/all_controllers.rb' ========================= First of all - how is that any more DRY than the example above? Perhaps you save a few keystrokes, but if you think that makes it more DRY then you don't really understand what DRY is all about. Second of all, what does it actually mean? Where's the story? How is a non-developer going to look at that and have any context for what that means? I'm a developer and I don't know what it means. Sure I can figure it out, but, in my opinion, it's just nowhere near as clear as the example above. FWIW, David From justnothing at tiscali.co.uk Sun Aug 5 15:43:16 2007 From: justnothing at tiscali.co.uk (David Green) Date: Sun, 5 Aug 2007 12:43:16 -0700 (PDT) Subject: [rspec-users] reusable specs - almost there In-Reply-To: <57c63afe0708050857x61afe07aiedafcea9f4961698@mail.gmail.com> References: <11996399.post@talk.nabble.com> <57c63afe0708050857x61afe07aiedafcea9f4961698@mail.gmail.com> Message-ID: <12007548.post@talk.nabble.com> that's a great point, but there are some things about shared behaviours I don't like. for example, I have 14 different contexts I'm testing (and more to come) in 8 controllers. I can do this: describe MyController do it_should_behave_like "context 1" it_should_behave_like "context 2" . . it_should_behave_like "context 14" end but then I lose the context info in the output, it just displays one long list of examples. The alternative is: describe MyController, "context 1" do it_should_behave_like "context 1" end describe MyController, "context 2" do it_should_behave_like "context 2" end . . describe MyController, "context 14" do it_should_behave_like "context 14" end this way the context info is preserved in the output, but it's more work, especially across 8 controllers. another thing is, depending on the model being used, controllers will instantiate variables of different names. e.g. in the "dvd" controller, an instance of the Dvd model would be stored in @dvd, whereas in the "book" controller, it would be in @book . using dynamic specs, I can make my examples more specific depending on the controller being tested e.g. : # obj and var passed in as parameters it "should load a #{obj.class} object into @#{varname}" do get :show assigns[var_name].should == obj end I could put obj and varname into instance variables in the before() method, but they're only available in the example block, not from the example title these are minor complaints really, but as my project grows, they become more of an issue. David Chelimsky-2 wrote: > > On 8/4/07, David Green wrote: >> >> I have a lot of controllers with virtually identical functionality for >> most >> actions. I've been using shared behaviours to DRY things up a bit, but I >> still have to create separate behaviours for each context before I can >> use >> the shared behaviours >> >> what I have now is a generic file which contains all the behaviours and >> examples common to all the controllers, and that file gets loaded from an >> actual controller spec. The generic file knows which controller to test >> by >> calling kontroller(), which is defined in the controller spec. >> >> here's a very simplified example: >> http://pastebin.com/m6b47bae9 >> >> It works great when I run the specs individually, but when I use rake, >> specs >> begin to fail and i think it's because the value of kontroller() is set >> to >> whatever it returns the first time it gets called. Here's the rake output >> from running the specs shown above: >> >> >> FooController >> .FooController >> . >> >> Finished in 0.041793 seconds >> 2 examples, 0 failures >> >> I would expect it to print FooController and then BarController ... >> interestingly, if I insert 'puts kontroller.to_s' *outside* of the >> describe >> block, then it does output the names of both controllers as expected. >> >> does anyone know of a solution? >> thanks >> >> dave > > I'm all for keeping things DRY, but NEVER at the risk of clarity. > You've got to balance DRY and readability/clarity. Anybody familiar > with rspec can look at this: > > ========================= > describe FooController do > it_should_behave_like "All Controllers" > end > ========================= > > and understand what that means: A FooController should behave like All > Controllers. Perhaps there is a split second of mental mapping: "Oh, > there must be some behaviour described for all controllers that the > FooController should adopt." > > Compare that to your example: > > ========================= > def kontroller > FooController > end > > load File.dirname(__FILE__) + '/all_controllers.rb' > ========================= > > First of all - how is that any more DRY than the example above? > Perhaps you save a few keystrokes, but if you think that makes it more > DRY then you don't really understand what DRY is all about. > > Second of all, what does it actually mean? Where's the story? How is a > non-developer going to look at that and have any context for what that > means? I'm a developer and I don't know what it means. Sure I can > figure it out, but, in my opinion, it's just nowhere near as clear as > the example above. > > FWIW, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -- View this message in context: http://www.nabble.com/reusable-specs---almost-there-tf4216708.html#a12007548 Sent from the rspec-users mailing list archive at Nabble.com. From pergesu at gmail.com Sun Aug 5 16:18:15 2007 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 5 Aug 2007 13:18:15 -0700 Subject: [rspec-users] reusable specs - almost there In-Reply-To: <12007548.post@talk.nabble.com> References: <11996399.post@talk.nabble.com> <57c63afe0708050857x61afe07aiedafcea9f4961698@mail.gmail.com> <12007548.post@talk.nabble.com> Message-ID: <810a540e0708051318jaa7d362w2efba62a335a5422@mail.gmail.com> I agree with David, I think this is too much magic. You'll often have more duplication in specs than you will in production code. That's not a bad thing though, because specs need to be explicit about the behavior being performed. Duplication doesn't lead to the same mistakes that it does in production code. You can and should factor out stuff when doing so won't hurt the clarity of the specs. However when you have to think hard to figure out what's going on, you lose one of the main benefits of RSpec. It's all about making your spec code easy to parse. Solving the problem of 14 different shared contexts isn't really hard. %w(admin_context regular_user_context manager_context).each do |con| describe MyController do it_should_be_have_like con end end Pat On 8/5/07, David Green wrote: > > that's a great point, but there are some things about shared behaviours I > don't like. for example, I have 14 different contexts I'm testing (and more > to come) in 8 controllers. > > I can do this: > > describe MyController do > it_should_behave_like "context 1" > it_should_behave_like "context 2" > . > . > it_should_behave_like "context 14" > end > > but then I lose the context info in the output, it just displays one long > list of examples. > The alternative is: > > describe MyController, "context 1" do > it_should_behave_like "context 1" > end > describe MyController, "context 2" do > it_should_behave_like "context 2" > end > . > . > describe MyController, "context 14" do > it_should_behave_like "context 14" > end > > this way the context info is preserved in the output, but it's more work, > especially across 8 controllers. > > another thing is, depending on the model being used, controllers will > instantiate variables of different names. e.g. in the "dvd" controller, an > instance of the Dvd model would be stored in @dvd, whereas in the "book" > controller, it would be in @book . using dynamic specs, I can make my > examples more specific depending on the controller being tested e.g. : > > # obj and var passed in as parameters > it "should load a #{obj.class} object into @#{varname}" do > get :show > assigns[var_name].should == obj > end > > I could put obj and varname into instance variables in the before() method, > but they're only available in the example block, not from the example title > > these are minor complaints really, but as my project grows, they become more > of an issue. > > > > David Chelimsky-2 wrote: > > > > On 8/4/07, David Green wrote: > >> > >> I have a lot of controllers with virtually identical functionality for > >> most > >> actions. I've been using shared behaviours to DRY things up a bit, but I > >> still have to create separate behaviours for each context before I can > >> use > >> the shared behaviours > >> > >> what I have now is a generic file which contains all the behaviours and > >> examples common to all the controllers, and that file gets loaded from an > >> actual controller spec. The generic file knows which controller to test > >> by > >> calling kontroller(), which is defined in the controller spec. > >> > >> here's a very simplified example: > >> http://pastebin.com/m6b47bae9 > >> > >> It works great when I run the specs individually, but when I use rake, > >> specs > >> begin to fail and i think it's because the value of kontroller() is set > >> to > >> whatever it returns the first time it gets called. Here's the rake output > >> from running the specs shown above: > >> > >> > >> FooController > >> .FooController > >> . > >> > >> Finished in 0.041793 seconds > >> 2 examples, 0 failures > >> > >> I would expect it to print FooController and then BarController ... > >> interestingly, if I insert 'puts kontroller.to_s' *outside* of the > >> describe > >> block, then it does output the names of both controllers as expected. > >> > >> does anyone know of a solution? > >> thanks > >> > >> dave > > > > I'm all for keeping things DRY, but NEVER at the risk of clarity. > > You've got to balance DRY and readability/clarity. Anybody familiar > > with rspec can look at this: > > > > ========================= > > describe FooController do > > it_should_behave_like "All Controllers" > > end > > ========================= > > > > and understand what that means: A FooController should behave like All > > Controllers. Perhaps there is a split second of mental mapping: "Oh, > > there must be some behaviour described for all controllers that the > > FooController should adopt." > > > > Compare that to your example: > > > > ========================= > > def kontroller > > FooController > > end > > > > load File.dirname(__FILE__) + '/all_controllers.rb' > > ========================= > > > > First of all - how is that any more DRY than the example above? > > Perhaps you save a few keystrokes, but if you think that makes it more > > DRY then you don't really understand what DRY is all about. > > > > Second of all, what does it actually mean? Where's the story? How is a > > non-developer going to look at that and have any context for what that > > means? I'm a developer and I don't know what it means. Sure I can > > figure it out, but, in my opinion, it's just nowhere near as clear as > > the example above. > > > > FWIW, > > David > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > View this message in context: http://www.nabble.com/reusable-specs---almost-there-tf4216708.html#a12007548 > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Aug 5 17:52:18 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 5 Aug 2007 16:52:18 -0500 Subject: [rspec-users] reusable specs - almost there In-Reply-To: <12007548.post@talk.nabble.com> References: <11996399.post@talk.nabble.com> <57c63afe0708050857x61afe07aiedafcea9f4961698@mail.gmail.com> <12007548.post@talk.nabble.com> Message-ID: <57c63afe0708051452h3a4e4013saae007fd30c2c68a@mail.gmail.com> On 8/5/07, David Green wrote: > > that's a great point, but there are some things about shared behaviours I > don't like. for example, I have 14 different contexts I'm testing (and more > to come) in 8 controllers. > > I can do this: > > describe MyController do > it_should_behave_like "context 1" > it_should_behave_like "context 2" > . > . > it_should_behave_like "context 14" > end > > but then I lose the context info in the output, it just displays one long > list of examples. Interesting. This is kind of backwards from how I envision shared behaviours. To me, a shared behaviour is a behaviour that is shared across objects, not contexts. In other words: describe "any controller", :shared => true do it "should do a when b" { ... } end describe "a specific controller" do it_should_behave_like "any controller" end As opposed to: describe "any controller when the user is logged in", :shared => true do it "should do a when b" { ... } end describe "a specific controller" do it_should_behave_like "any controller when the user is logged in" end Subtle difference, but I'm sure it guides in a different direction. The problem you're experiencing is not new, and I'm definitely interested in discussing solutions for it, but I'm much more interested in ways rspec could improve than ways to work around rspec's deficiencies. > The alternative is: > > describe MyController, "context 1" do > it_should_behave_like "context 1" > end > describe MyController, "context 2" do > it_should_behave_like "context 2" > end > . > . > describe MyController, "context 14" do > it_should_behave_like "context 14" > end > > this way the context info is preserved in the output, but it's more work, > especially across 8 controllers. > > another thing is, depending on the model being used, controllers will > instantiate variables of different names. e.g. in the "dvd" controller, an > instance of the Dvd model would be stored in @dvd, whereas in the "book" > controller, it would be in @book . using dynamic specs, I can make my > examples more specific depending on the controller being tested e.g. : > > # obj and var passed in as parameters > it "should load a #{obj.class} object into @#{varname}" do > get :show > assigns[var_name].should == obj > end > > I could put obj and varname into instance variables in the before() method, > but they're only available in the example block, not from the example title > > these are minor complaints really, but as my project grows, they become more > of an issue. Understood - although, if all of these controllers are behaving exactly the same way with only a variable name or two difference, it seems to me that the duplication problem is in the code, not the specs. Perhaps there is some common code that could be extracted to a module - then you can have specs for that module and specify that the module should be included in each of your controllers. WDYT? > > > > David Chelimsky-2 wrote: > > > > On 8/4/07, David Green wrote: > >> > >> I have a lot of controllers with virtually identical functionality for > >> most > >> actions. I've been using shared behaviours to DRY things up a bit, but I > >> still have to create separate behaviours for each context before I can > >> use > >> the shared behaviours > >> > >> what I have now is a generic file which contains all the behaviours and > >> examples common to all the controllers, and that file gets loaded from an > >> actual controller spec. The generic file knows which controller to test > >> by > >> calling kontroller(), which is defined in the controller spec. > >> > >> here's a very simplified example: > >> http://pastebin.com/m6b47bae9 > >> > >> It works great when I run the specs individually, but when I use rake, > >> specs > >> begin to fail and i think it's because the value of kontroller() is set > >> to > >> whatever it returns the first time it gets called. Here's the rake output > >> from running the specs shown above: > >> > >> > >> FooController > >> .FooController > >> . > >> > >> Finished in 0.041793 seconds > >> 2 examples, 0 failures > >> > >> I would expect it to print FooController and then BarController ... > >> interestingly, if I insert 'puts kontroller.to_s' *outside* of the > >> describe > >> block, then it does output the names of both controllers as expected. > >> > >> does anyone know of a solution? > >> thanks > >> > >> dave > > > > I'm all for keeping things DRY, but NEVER at the risk of clarity. > > You've got to balance DRY and readability/clarity. Anybody familiar > > with rspec can look at this: > > > > ========================= > > describe FooController do > > it_should_behave_like "All Controllers" > > end > > ========================= > > > > and understand what that means: A FooController should behave like All > > Controllers. Perhaps there is a split second of mental mapping: "Oh, > > there must be some behaviour described for all controllers that the > > FooController should adopt." > > > > Compare that to your example: > > > > ========================= > > def kontroller > > FooController > > end > > > > load File.dirname(__FILE__) + '/all_controllers.rb' > > ========================= > > > > First of all - how is that any more DRY than the example above? > > Perhaps you save a few keystrokes, but if you think that makes it more > > DRY then you don't really understand what DRY is all about. > > > > Second of all, what does it actually mean? Where's the story? How is a > > non-developer going to look at that and have any context for what that > > means? I'm a developer and I don't know what it means. Sure I can > > figure it out, but, in my opinion, it's just nowhere near as clear as > > the example above. > > > > FWIW, > > David > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > View this message in context: http://www.nabble.com/reusable-specs---almost-there-tf4216708.html#a12007548 > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Sun Aug 5 22:12:06 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 5 Aug 2007 22:12:06 -0400 Subject: [rspec-users] Stubbing Enumerable#each Message-ID: <97C3CAEE-624F-4D68-9A31-6CA3A2862343@railsnewbie.com> I have a mock of an instance of a class which descends from Array: class ArrayDescendent < Array; end #... in the specs... @descendent = mock ArrayDescendent How would I stub out ArrayDescendent#each, which is inherited from Array, to return multiple values successively? I could use and_yield, but that is raising an arity error (the anonymous function/ block should expect only *one value at a time, but and_yield is yielding both values once). Should I be using a lambda expression here? Tips are welcome...Thanks, Scott From mailing_lists at railsnewbie.com Mon Aug 6 01:13:47 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 6 Aug 2007 01:13:47 -0400 Subject: [rspec-users] pending w/ no string Message-ID: <45BDB9EB-EC87-40AD-8F1C-092AC5352DC4@railsnewbie.com> Is there some reason that pending() *MUST* take an argument? Scott From pergesu at gmail.com Mon Aug 6 02:16:53 2007 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 5 Aug 2007 23:16:53 -0700 Subject: [rspec-users] Stubbing Enumerable#each In-Reply-To: <97C3CAEE-624F-4D68-9A31-6CA3A2862343@railsnewbie.com> References: <97C3CAEE-624F-4D68-9A31-6CA3A2862343@railsnewbie.com> Message-ID: <810a540e0708052316q5f7f5b69y4457a001608675a4@mail.gmail.com> On 8/5/07, Scott Taylor wrote: > > I have a mock of an instance of a class which descends from Array: > > class ArrayDescendent < Array; end > > #... in the specs... > @descendent = mock ArrayDescendent > > How would I stub out ArrayDescendent#each, which is inherited from > Array, to return multiple values successively? I could use > and_yield, but that is raising an arity error (the anonymous function/ > block should expect only *one value at a time, but and_yield is > yielding both values once). Should I be using a lambda expression here? > > Tips are welcome...Thanks, > > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Hey Scott, I'm not sure if there's a way you can currently do that (there may be and I just couldn't figure it out). However I agree it's useful, and I whipped up a quick patch to provide that behavior. http://rubyforge.org/tracker/index.php?func=detail&aid=12841&group_id=797&atid=3151 My example spec is it "should support yielding consecutive values" do yielded_values = [] @obj.stub!(:method_that_yields).and_yield_consecutively("abc", 123, :foobar) @obj.method_that_yields {|val| yielded_values << val } yielded_values.should == [ "abc", 123, :foobar ] @obj.rspec_verify end How's that? Pat From mailing_lists at railsnewbie.com Mon Aug 6 02:53:47 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 6 Aug 2007 02:53:47 -0400 Subject: [rspec-users] using RSpec's trunk in non-rails projects w/ Autotest Message-ID: <3C103E41-DEBC-4389-A0AB-E4F42CDE6338@railsnewbie.com> I believe for rails projects you can put rspec's code repos into vendor/plugins, and autotest will automatically use the rspec binary in that directory, and not the gem installed. Is there an easy way to do this for non-rails projects? There are a few advancements on trunk which I would like to take advantage of. Tips welcome ; ). Scott Taylor From dchelimsky at gmail.com Mon Aug 6 07:19:49 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Aug 2007 06:19:49 -0500 Subject: [rspec-users] pending w/ no string In-Reply-To: <45BDB9EB-EC87-40AD-8F1C-092AC5352DC4@railsnewbie.com> References: <45BDB9EB-EC87-40AD-8F1C-092AC5352DC4@railsnewbie.com> Message-ID: <57c63afe0708060419p7499b4e4k5d4898ebc18bbbef@mail.gmail.com> On 8/6/07, Scott Taylor wrote: > > Is there some reason that pending() *MUST* take an argument? There was no discussion of this when the feature was contributed. Thinking about it now, to allow for no arg would require good default messages - one for when there is a block and one for when there is not. As long as you can come up w/ messages that really make sense in all situations, then a patch would be welcome. > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Mon Aug 6 07:29:52 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 6 Aug 2007 07:29:52 -0400 Subject: [rspec-users] pending w/ no string In-Reply-To: <57c63afe0708060419p7499b4e4k5d4898ebc18bbbef@mail.gmail.com> References: <45BDB9EB-EC87-40AD-8F1C-092AC5352DC4@railsnewbie.com> <57c63afe0708060419p7499b4e4k5d4898ebc18bbbef@mail.gmail.com> Message-ID: On Aug 6, 2007, at 7:19 AM, David Chelimsky wrote: > On 8/6/07, Scott Taylor wrote: >> >> Is there some reason that pending() *MUST* take an argument? > > There was no discussion of this when the feature was contributed. > Thinking about it now, to allow for no arg would require good default > messages - one for when there is a block and one for when there is > not. As long as you can come up w/ messages that really make sense in > all situations, then a patch would be welcome. How about accepting no arguments if no block is given? Scott From dchelimsky at gmail.com Mon Aug 6 07:46:39 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Aug 2007 06:46:39 -0500 Subject: [rspec-users] pending w/ no string In-Reply-To: References: <45BDB9EB-EC87-40AD-8F1C-092AC5352DC4@railsnewbie.com> <57c63afe0708060419p7499b4e4k5d4898ebc18bbbef@mail.gmail.com> Message-ID: <57c63afe0708060446t7ef0c43bie4d640d542455f26@mail.gmail.com> On 8/6/07, Scott Taylor wrote: > > On Aug 6, 2007, at 7:19 AM, David Chelimsky wrote: > > > On 8/6/07, Scott Taylor wrote: > >> > >> Is there some reason that pending() *MUST* take an argument? > > > > There was no discussion of this when the feature was contributed. > > Thinking about it now, to allow for no arg would require good default > > messages - one for when there is a block and one for when there is > > not. As long as you can come up w/ messages that really make sense in > > all situations, then a patch would be welcome. > > How about accepting no arguments if no block is given? I think that would be more confusing - it should work the same way for both situations. > > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists-rspec at shopwatch.org Mon Aug 6 12:20:31 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Mon, 06 Aug 2007 12:20:31 -0400 Subject: [rspec-users] Specifying custom rails FormBuilders Message-ID: <46B74A4F.70705@jay.fm> I want to write a spec for a custom form builder, but I'm not really sure where it should live or how to include the right rspec_on_rails contexts. Ideally, I should be able to write a spec like: describe LabelledBuilder do it "should let me create a text field" do object = mock(object) object.stub!(:attribute).and_return("Test String") render :inline => "<% form_for(@object, :builder => LabelledBuilder) do |f| -%> <%= f.text_field :attribute %> <% end %>" response.should have_tag("label") end end but I'm not having much luck. Can anyone give me an idea where to start? Jay From dchelimsky at gmail.com Mon Aug 6 12:23:06 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Aug 2007 11:23:06 -0500 Subject: [rspec-users] Specifying custom rails FormBuilders In-Reply-To: <46B74A4F.70705@jay.fm> References: <46B74A4F.70705@jay.fm> Message-ID: <57c63afe0708060923s222b5e56s2f30d83b88ef2880@mail.gmail.com> On 8/6/07, Jay Levitt wrote: > I want to write a spec for a custom form builder, but I'm not really > sure where it should live or how to include the right rspec_on_rails > contexts. Ideally, I should be able to write a spec like: > > > describe LabelledBuilder do > > it "should let me create a text field" do > object = mock(object) > object.stub!(:attribute).and_return("Test String") > > render :inline => > "<% form_for(@object, :builder => LabelledBuilder) do |f| -%> > <%= f.text_field :attribute %> > <% end %>" > > response.should have_tag("label") > end > end > > > but I'm not having much luck. How so? What error do you get from that? > Can anyone give me an idea where to start? > > Jay > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists-rspec at shopwatch.org Mon Aug 6 12:42:07 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Mon, 06 Aug 2007 12:42:07 -0400 Subject: [rspec-users] Specifying custom rails FormBuilders In-Reply-To: <57c63afe0708060923s222b5e56s2f30d83b88ef2880@mail.gmail.com> References: <46B74A4F.70705@jay.fm> <57c63afe0708060923s222b5e56s2f30d83b88ef2880@mail.gmail.com> Message-ID: <46B74F5F.2030005@jay.fm> David Chelimsky wrote: > On 8/6/07, Jay Levitt wrote: >> I want to write a spec for a custom form builder, but I'm not really >> sure where it should live or how to include the right rspec_on_rails >> contexts. Ideally, I should be able to write a spec like: >> >> >> describe LabelledBuilder do >> >> it "should let me create a text field" do >> object = mock(object) >> object.stub!(:attribute).and_return("Test String") >> >> render :inline => >> "<% form_for(@object, :builder => LabelledBuilder) do |f| -%> >> <%= f.text_field :attribute %> >> <% end %>" >> >> response.should have_tag("label") >> end >> end >> >> >> but I'm not having much luck. > > How so? What error do you get from that? Well, if I put it in spec/helpers, where I expected it to work, I get: NoMethodError in 'LabelledBuilder should let me create a text field' undefined method `render' for [Dynamically generated class for RSpec example]:# ./spec/helpers/labelled_builder_spec.rb:15: If I instead put it in spec/views, I get: Exception in 'LabelledBuilder should let me create a text field' Unhandled render type in view spec. /Users/jay/Documents/eclipse/mediajoint/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:133:in `subject_of_render' /Users/jay/Documents/eclipse/mediajoint/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:118:in `derived_controller_name' /Users/jay/Documents/eclipse/mediajoint/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:114:in `base_view_path' /Users/jay/Documents/eclipse/mediajoint/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:110:in `set_base_view_path' /Users/jay/Documents/eclipse/mediajoint/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:27:in `render' ./spec/views/labelled_builder_spec.rb:15: which makes sense, since subject_of_render doesn't seem to handle inline rendering... but of course, if I move it out into a file and render it there, I have to make one fake view per test case. Jay From gramos at rectorado.unl.edu.ar Mon Aug 6 13:17:15 2007 From: gramos at rectorado.unl.edu.ar (Gaston Ramos) Date: Mon, 6 Aug 2007 13:17:15 -0400 Subject: [rspec-users] Problems with array mock Message-ID: <20070806171715.GA15788@marlasina> Hi everyone, I'm trying this in my helper spec and it didn't work: @curr_odontogram.should_receive('photos[1]').and_return(@photo) and the error is: SyntaxError in 'PersonHelper Deberia devolverme un link para eliminar una foto' compile error /home/gramos/src/rails/r-dental/config/../vendor/plugins/rspec/lib/spec/mocks/proxy.rb:99: syntax error, unexpected '[', expecting '\n' or ';' def photos[1](*args, &block) does anyone have a good solution for this? the complete code of the helper: http://pastie.caboo.se/85287 the complete code of the spec helper: http://pastie.caboo.se/85289 See you. -- Gast?n Ramos GNU/Linux Counter user #450312 http://gastonramos.wordpress.com/ No a la Matricula Obligatoria http://noalamatricula.wordpress.com/about/ From dchelimsky at gmail.com Mon Aug 6 12:52:28 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Aug 2007 11:52:28 -0500 Subject: [rspec-users] Problems with array mock In-Reply-To: <20070806171715.GA15788@marlasina> References: <20070806171715.GA15788@marlasina> Message-ID: <57c63afe0708060952y7223e442sbc1fb716f45a03e7@mail.gmail.com> On 8/6/07, Gaston Ramos wrote: > > Hi everyone, > > I'm trying this in my helper spec and it didn't work: > > @curr_odontogram.should_receive('photos[1]').and_return(@photo) > > and the error is: > > SyntaxError in 'PersonHelper Deberia devolverme un link para eliminar una foto' > compile error > /home/gramos/src/rails/r-dental/config/../vendor/plugins/rspec/lib/spec/mocks/proxy.rb:99: > syntax error, unexpected '[', expecting '\n' or ';' > def photos[1](*args, &block) > > does anyone have a good solution for this? > > the complete code of the helper: > > http://pastie.caboo.se/85287 > > the complete code of the spec helper: > > http://pastie.caboo.se/85289 This is ruby magic causing confusion. When you call foo.photos[1], you're actually calling foo.photos[](1) (though that won't work) - so I *think* the expectation should read: @curr_odontogram.should_receive(:photos[]).with(1).and_return(@photo) Give that a try. > > > See you. > -- > Gast?n Ramos > > GNU/Linux Counter user #450312 > http://gastonramos.wordpress.com/ > > No a la Matricula Obligatoria > http://noalamatricula.wordpress.com/about/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From gramos at rectorado.unl.edu.ar Mon Aug 6 15:04:47 2007 From: gramos at rectorado.unl.edu.ar (Gaston Ramos) Date: Mon, 6 Aug 2007 15:04:47 -0400 Subject: [rspec-users] Problems with array mock In-Reply-To: <57c63afe0708060952y7223e442sbc1fb716f45a03e7@mail.gmail.com> References: <20070806171715.GA15788@marlasina> <57c63afe0708060952y7223e442sbc1fb716f45a03e7@mail.gmail.com> Message-ID: <20070806190447.GA23845@marlasina> El lun, 06 de ago de 2007, a las 11:52:28 -0500, David Chelimsky dijo: > On 8/6/07, Gaston Ramos wrote: > > > > Hi everyone, > > > > I'm trying this in my helper spec and it didn't work: > > > > @curr_odontogram.should_receive('photos[1]').and_return(@photo) > > > > and the error is: > > > > SyntaxError in 'PersonHelper Deberia devolverme un link para eliminar una foto' > > compile error > > /home/gramos/src/rails/r-dental/config/../vendor/plugins/rspec/lib/spec/mocks/proxy.rb:99: > > syntax error, unexpected '[', expecting '\n' or ';' > > def photos[1](*args, &block) > > > > does anyone have a good solution for this? > > > > the complete code of the helper: > > > > http://pastie.caboo.se/85287 > > > > the complete code of the spec helper: > > > > http://pastie.caboo.se/85289 > > This is ruby magic causing confusion. When you call foo.photos[1], > you're actually calling foo.photos[](1) (though that won't work) - so > I *think* the expectation should read: > > @curr_odontogram.should_receive(:photos[]).with(1).and_return(@photo) > > Give that a try. I tried this: @curr_odontogram.should_receive(:photos[]).with(1).and_return(@photo) and I have this error: NoMethodError in 'PersonHelper Deberia devolverme un link para eliminar una foto' undefined method `[]' for :photos:Symbol > > > > > > > See you. > > -- > > Gast?n Ramos > > > > GNU/Linux Counter user #450312 > > http://gastonramos.wordpress.com/ > > > > No a la Matricula Obligatoria > > http://noalamatricula.wordpress.com/about/ > > _______________________________________________ > > 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 > -- Gast?n Ramos GNU/Linux Counter user #450312 http://gastonramos.wordpress.com/ No a la Matricula Obligatoria http://noalamatricula.wordpress.com/about/ From aslak.hellesoy at gmail.com Mon Aug 6 14:03:53 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 6 Aug 2007 20:03:53 +0200 Subject: [rspec-users] Problems with array mock In-Reply-To: <20070806190447.GA23845@marlasina> References: <20070806171715.GA15788@marlasina> <57c63afe0708060952y7223e442sbc1fb716f45a03e7@mail.gmail.com> <20070806190447.GA23845@marlasina> Message-ID: <8d961d900708061103r30d8364bw1aef998c1bfd5b66@mail.gmail.com> On 8/6/07, Gaston Ramos wrote: > El lun, 06 de ago de 2007, a las 11:52:28 -0500, David Chelimsky dijo: > > On 8/6/07, Gaston Ramos wrote: > > > > > > Hi everyone, > > > > > > I'm trying this in my helper spec and it didn't work: > > > > > > @curr_odontogram.should_receive('photos[1]').and_return(@photo) > > > > > > and the error is: > > > > > > SyntaxError in 'PersonHelper Deberia devolverme un link para eliminar una foto' > > > compile error > > > /home/gramos/src/rails/r-dental/config/../vendor/plugins/rspec/lib/spec/mocks/proxy.rb:99: > > > syntax error, unexpected '[', expecting '\n' or ';' > > > def photos[1](*args, &block) > > > > > > does anyone have a good solution for this? > > > > > > the complete code of the helper: > > > > > > http://pastie.caboo.se/85287 > > > > > > the complete code of the spec helper: > > > > > > http://pastie.caboo.se/85289 > > > > This is ruby magic causing confusion. When you call foo.photos[1], > > you're actually calling foo.photos[](1) (though that won't work) - so > > I *think* the expectation should read: > > > > @curr_odontogram.should_receive(:photos[]).with(1).and_return(@photo) > > @curr_odontogram.photos.should_receive(:[]).with(1).and_return(@photo) Aslak > > Give that a try. > > I tried this: > @curr_odontogram.should_receive(:photos[]).with(1).and_return(@photo) > > and I have this error: > > NoMethodError in 'PersonHelper Deberia devolverme un link para eliminar una > foto' > undefined method `[]' for :photos:Symbol > > > > > > > > > > > > See you. > > > -- > > > Gast?n Ramos > > > > > > GNU/Linux Counter user #450312 > > > http://gastonramos.wordpress.com/ > > > > > > No a la Matricula Obligatoria > > > http://noalamatricula.wordpress.com/about/ > > > _______________________________________________ > > > 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 > > > > -- > Gast?n Ramos > > GNU/Linux Counter user #450312 > http://gastonramos.wordpress.com/ > > No a la Matricula Obligatoria > http://noalamatricula.wordpress.com/about/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Aug 6 14:57:48 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Aug 2007 13:57:48 -0500 Subject: [rspec-users] Problems with array mock In-Reply-To: <8d961d900708061103r30d8364bw1aef998c1bfd5b66@mail.gmail.com> References: <20070806171715.GA15788@marlasina> <57c63afe0708060952y7223e442sbc1fb716f45a03e7@mail.gmail.com> <20070806190447.GA23845@marlasina> <8d961d900708061103r30d8364bw1aef998c1bfd5b66@mail.gmail.com> Message-ID: <57c63afe0708061157hfffd3cct50f980e98566ea5f@mail.gmail.com> On 8/6/07, aslak hellesoy wrote: > @curr_odontogram.photos.should_receive(:[]).with(1).and_return(@photo) > > Aslak D'oh! Of course - that should do it. From ben at benburkert.com Mon Aug 6 17:25:55 2007 From: ben at benburkert.com (ben at benburkert.com) Date: Mon, 6 Aug 2007 16:25:55 -0500 (CDT) Subject: [rspec-users] used the described Class in a shared behavior Message-ID: <60190.64.129.167.114.1186435555.squirrel@webmail.benburkert.com> Is it possible to access the described class in a shared behavior? I'm trying to do something like this: describe "Siberian feline", :shared => true do described_class_instance_as :feline, :name => "fluffy", :breed => "Siberian" # or maybe before(:all) do @feline = described_class.new(:name => "fluffy", :breed => "Siberian") end it "should have long hair" do @feline.should be_long_haired end end describe SiberianCat, "(a subclass of, say, Cat)" do it_should_behave_like "Siberian feline" it "should purr" do @feline.sound.should == "purr" end end describe SiberianTiger, "(a subclass of BigCat)" do it_should_behave_like "Siberian feline" it "should roar" do @feline.sound.should == "roar" end end I'm looking for something more elegant than my current way, which is like so: describe "Siberian felines", :shared => true do before(:all) do @feline = @klass.new(:name => "fluffy", :breed => "Siberian") end it "should have long hair" do @feline.should be_long_haired end end describe SiberianCat, "(a subclass of, say, Cat)" do it_should_behave_like "Siberian felines" before(:all) do @klass = SiberianCat end it "should purr" do @feline.sound.should == "purr" end end describe SiberianTiger, "(a subclass of BigCat)" do it_should_behave_like "Siberian felines" before(:all) do @klass = SiberanTiger end it "should roar" do @feline.sound.should == "roar" end end Then again, i have a gut feeling that if i took better advantage of modules it wouldn't be an issue... -Ben From dchelimsky at gmail.com Mon Aug 6 20:47:46 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Aug 2007 19:47:46 -0500 Subject: [rspec-users] used the described Class in a shared behavior In-Reply-To: <60190.64.129.167.114.1186435555.squirrel@webmail.benburkert.com> References: <60190.64.129.167.114.1186435555.squirrel@webmail.benburkert.com> Message-ID: <57c63afe0708061747o543d8947k37f3a8c123aee3e2@mail.gmail.com> On 8/6/07, ben at benburkert.com wrote: > Is it possible to access the described class in a shared behavior? I'm > trying to do something like this: > > describe "Siberian feline", :shared => true do > described_class_instance_as :feline, :name => "fluffy", :breed => > "Siberian" > > # or maybe > > before(:all) do > @feline = described_class.new(:name => "fluffy", :breed => "Siberian") > end > > it "should have long hair" do > @feline.should be_long_haired > end > end > > describe SiberianCat, "(a subclass of, say, Cat)" do > it_should_behave_like "Siberian feline" > > it "should purr" do > @feline.sound.should == "purr" > end > end > > describe SiberianTiger, "(a subclass of BigCat)" do > it_should_behave_like "Siberian feline" > > it "should roar" do > @feline.sound.should == "roar" > end > end > > > > I'm looking for something more elegant than my current way, which is like so: > > describe "Siberian felines", :shared => true do > before(:all) do > @feline = @klass.new(:name => "fluffy", :breed => "Siberian") > end > > it "should have long hair" do > @feline.should be_long_haired > end > end > > describe SiberianCat, "(a subclass of, say, Cat)" do > it_should_behave_like "Siberian felines" > > before(:all) do > @klass = SiberianCat > end > > it "should purr" do > @feline.sound.should == "purr" > end > end > > describe SiberianTiger, "(a subclass of BigCat)" do > it_should_behave_like "Siberian felines" > > before(:all) do > @klass = SiberanTiger > end > > it "should roar" do > @feline.sound.should == "roar" > end > end > The way you're approaching it means that if something changes about the initializer for the SiberianTiger that doesn't change for the initializer of the SiberianCat, you're kinda screwed. I'd do it like this: http://pastie.caboo.se/85444 This keeps the shared behaviour very simple (all it needs is an instance variable) and puts control of the object you're dealing with in the spec. WDYT? > > > > Then again, i have a gut feeling that if i took better advantage of > modules it wouldn't be an issue... > > -Ben > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Aug 6 20:51:17 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Aug 2007 19:51:17 -0500 Subject: [rspec-users] used the described Class in a shared behavior In-Reply-To: <57c63afe0708061747o543d8947k37f3a8c123aee3e2@mail.gmail.com> References: <60190.64.129.167.114.1186435555.squirrel@webmail.benburkert.com> <57c63afe0708061747o543d8947k37f3a8c123aee3e2@mail.gmail.com> Message-ID: <57c63afe0708061751g214690a7h815f1a79ecc6098d@mail.gmail.com> On 8/6/07, David Chelimsky wrote: > On 8/6/07, ben at benburkert.com wrote: > > Is it possible to access the described class in a shared behavior? I'm > > trying to do something like this: > > > > describe "Siberian feline", :shared => true do > > described_class_instance_as :feline, :name => "fluffy", :breed => > > "Siberian" > > > > # or maybe > > > > before(:all) do > > @feline = described_class.new(:name => "fluffy", :breed => "Siberian") > > end > > > > it "should have long hair" do > > @feline.should be_long_haired > > end > > end > > > > describe SiberianCat, "(a subclass of, say, Cat)" do > > it_should_behave_like "Siberian feline" > > > > it "should purr" do > > @feline.sound.should == "purr" > > end > > end > > > > describe SiberianTiger, "(a subclass of BigCat)" do > > it_should_behave_like "Siberian feline" > > > > it "should roar" do > > @feline.sound.should == "roar" > > end > > end > > > > > > > > I'm looking for something more elegant than my current way, which is like so: > > > > describe "Siberian felines", :shared => true do > > before(:all) do > > @feline = @klass.new(:name => "fluffy", :breed => "Siberian") > > end > > > > it "should have long hair" do > > @feline.should be_long_haired > > end > > end > > > > describe SiberianCat, "(a subclass of, say, Cat)" do > > it_should_behave_like "Siberian felines" > > > > before(:all) do > > @klass = SiberianCat > > end > > > > it "should purr" do > > @feline.sound.should == "purr" > > end > > end > > > > describe SiberianTiger, "(a subclass of BigCat)" do > > it_should_behave_like "Siberian felines" > > > > before(:all) do > > @klass = SiberanTiger > > end > > > > it "should roar" do > > @feline.sound.should == "roar" > > end > > end > > > > The way you're approaching it means that if something changes about > the initializer for the SiberianTiger that doesn't change for the > initializer of the SiberianCat, you're kinda screwed. I'd do it like > this: http://pastie.caboo.se/85444 > > This keeps the shared behaviour very simple (all it needs is an > instance variable) and puts control of the object you're dealing with > in the spec. > > WDYT? Also - side note - before(:each) is preferred over before(:all) because it's better to be sure that each example starts with a clean slate. If one should change the state of the object you're describing, you could end up with unexpected results and hair-pulling debugging sessions. > > > > > > > > > > Then again, i have a gut feeling that if i took better advantage of > > modules it wouldn't be an issue... > > > > -Ben > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From mailing_lists at railsnewbie.com Mon Aug 6 21:36:04 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 6 Aug 2007 21:36:04 -0400 Subject: [rspec-users] Object equality with a DSL Message-ID: <3FEE2799-F858-4152-84C8-7DE10DE3721C@railsnewbie.com> How would you spec a DSL which descends from Jim Weirich's Blank Slate? I'm asking this question because I have written a DSL, and would like to have the DSL class descend from BlankSlate so that methods like == are not available in the DSL itself (in production), but only while Testing. Does any one have any insight on this? I can provide code samples if anyone would like me to be more specific. Scott Taylor From don at donpetersen.net Mon Aug 6 14:08:55 2007 From: don at donpetersen.net (Don Petersen) Date: Mon, 6 Aug 2007 13:08:55 -0500 Subject: [rspec-users] Problems with array mock In-Reply-To: <20070806190447.GA23845@marlasina> References: <20070806171715.GA15788@marlasina> <57c63afe0708060952y7223e442sbc1fb716f45a03e7@mail.gmail.com> <20070806190447.GA23845@marlasina> Message-ID: Have a look at this: http://pastie.textmate.org/85317 That should work out. Don On Aug 6, 2007, at 2:04 PM, Gaston Ramos wrote: > El lun, 06 de ago de 2007, a las 11:52:28 -0500, David Chelimsky dijo: >> On 8/6/07, Gaston Ramos wrote: >>> >>> Hi everyone, >>> >>> I'm trying this in my helper spec and it didn't work: >>> >>> @curr_odontogram.should_receive('photos[1]').and_return(@photo) >>> >>> and the error is: >>> >>> SyntaxError in 'PersonHelper Deberia devolverme un link para >>> eliminar una foto' >>> compile error >>> /home/gramos/src/rails/r-dental/config/../vendor/plugins/rspec/ >>> lib/spec/mocks/proxy.rb:99: >>> syntax error, unexpected '[', expecting '\n' or ';' >>> def photos[1](*args, &block) >>> >>> does anyone have a good solution for this? >>> >>> the complete code of the helper: >>> >>> http://pastie.caboo.se/85287 >>> >>> the complete code of the spec helper: >>> >>> http://pastie.caboo.se/85289 >> >> This is ruby magic causing confusion. When you call foo.photos[1], >> you're actually calling foo.photos[](1) (though that won't work) - so >> I *think* the expectation should read: >> >> @curr_odontogram.should_receive(:photos[]).with(1).and_return(@photo) >> >> Give that a try. > > I tried this: > @curr_odontogram.should_receive(:photos[]).with(1).and_return(@photo) > > and I have this error: > > NoMethodError in 'PersonHelper Deberia devolverme un link para > eliminar una > foto' > undefined method `[]' for :photos:Symbol > >> >>> >>> >>> See you. >>> -- >>> Gast?n Ramos >>> >>> GNU/Linux Counter user #450312 >>> http://gastonramos.wordpress.com/ >>> >>> No a la Matricula Obligatoria >>> http://noalamatricula.wordpress.com/about/ >>> _______________________________________________ >>> 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 >> > > -- > Gast?n Ramos > > GNU/Linux Counter user #450312 > http://gastonramos.wordpress.com/ > > No a la Matricula Obligatoria > http://noalamatricula.wordpress.com/about/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From flyeminent at hotmail.com Tue Aug 7 05:21:28 2007 From: flyeminent at hotmail.com (Shaker) Date: Tue, 7 Aug 2007 02:21:28 -0700 (PDT) Subject: [rspec-users] Rspec controller test Message-ID: <12030820.post@talk.nabble.com> Great Hi to everybody! I am currently working on a project which tests the controllers using rspec. I came across some methods in the controller which do not generate any actions at all. However, they still need testing! Some of these methods do require parameters. I am wondering how I can pass the test cases as the parameters to these targeted methods in the controller spec?? Below is a simple example for illustration: in the controller: def method_for_test(parameter_1, parameter_2) #do some coding #no action end in the controller_spec: it "should test the method_for_test" do parameter_1 parameter_2 ??how to pass them to method_for_test end Thank you all in advance. -- View this message in context: http://www.nabble.com/Rspec-controller-test-tf4229016.html#a12030820 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Tue Aug 7 10:43:05 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Aug 2007 09:43:05 -0500 Subject: [rspec-users] Rspec controller test In-Reply-To: <12030820.post@talk.nabble.com> References: <12030820.post@talk.nabble.com> Message-ID: <57c63afe0708070743q42bb008fyf502787cbad607db@mail.gmail.com> On 8/7/07, Shaker wrote: > > Great Hi to everybody! > I am currently working on a project which tests the controllers using rspec. > I came across some methods in the controller which do not generate any > actions at all. However, they still need testing! Some of these methods do > require parameters. I am wondering how I can pass the test cases as the > parameters to these targeted methods in the controller spec?? Below is a > simple example for illustration: > in the controller: > def method_for_test(parameter_1, parameter_2) > #do some coding > #no action > end > > in the controller_spec: > it "should test the method_for_test" do > parameter_1 > parameter_2 > ??how to pass them to method_for_test > end controller.method_for_test(arg1, arg2) > > Thank you all in advance. > -- > View this message in context: http://www.nabble.com/Rspec-controller-test-tf4229016.html#a12030820 > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Aug 7 10:51:59 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 7 Aug 2007 10:51:59 -0400 Subject: [rspec-users] stubs which yield and return Message-ID: <7267A2FC-D7F9-4851-970E-867F7DA9AF0D@railsnewbie.com> Is there any reason why a stub couldn't both yield and return? I'm looking for a way to mock out a class I've made named "AnonymousClass": class AnonymousClass def initialize(&blk) @klass = Class.new @klass.instance_eval(&blk) if block_given? end def new @klass.new end def evaluate(&blk) @klass.instance_eval(&blk) end attr_reader :klass alias_method :class, :klass end One of the behaviours of the AnonymousClass is that new can take a block, and eval the block in the anonymous class, represented by the @klass instance_variable: ac = AnonymousClass.new do include Enumerable end So is there a way to stub AnonymousClass.new such that it yield an AnonymousClass mock, as well as yielding to the block given? What are the technical challenges involved in implementing this in the mocking framework? Or is it a matter of clean syntax? Regards, Scott From dchelimsky at gmail.com Tue Aug 7 12:54:45 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Aug 2007 11:54:45 -0500 Subject: [rspec-users] stubs which yield and return In-Reply-To: <7267A2FC-D7F9-4851-970E-867F7DA9AF0D@railsnewbie.com> References: <7267A2FC-D7F9-4851-970E-867F7DA9AF0D@railsnewbie.com> Message-ID: <57c63afe0708070954ke9c3a71m64ac38611d53cd27@mail.gmail.com> On 8/7/07, Scott Taylor wrote: > > Is there any reason why a stub couldn't both yield and return? Yes. Nobody ever asked for it :) > I'm > looking for a way to mock out a class I've made named "AnonymousClass": > > class AnonymousClass > > def initialize(&blk) > @klass = Class.new > @klass.instance_eval(&blk) if block_given? > end > > def new > @klass.new > end > > def evaluate(&blk) > @klass.instance_eval(&blk) > end > > attr_reader :klass > alias_method :class, :klass > end > > One of the behaviours of the AnonymousClass is that new can take a > block, and eval the block in the anonymous class, represented by the > @klass instance_variable: > > ac = AnonymousClass.new do > include Enumerable > end > > So is there a way to stub AnonymousClass.new such that it yield an > AnonymousClass mock, as well as yielding to the block given? What > are the technical challenges involved in implementing this in the > mocking framework? Or is it a matter of clean syntax? Again - this simply hasn't come up. Please add an RFE and feel free to submit a patch. Cheers, David > > Regards, > > Scott > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Aug 7 18:52:12 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 7 Aug 2007 18:52:12 -0400 Subject: [rspec-users] stubs which yield and return In-Reply-To: <57c63afe0708070954ke9c3a71m64ac38611d53cd27@mail.gmail.com> References: <7267A2FC-D7F9-4851-970E-867F7DA9AF0D@railsnewbie.com> <57c63afe0708070954ke9c3a71m64ac38611d53cd27@mail.gmail.com> Message-ID: <45130EC8-5479-4056-A24B-59473F6FE43D@railsnewbie.com> On Aug 7, 2007, at 12:54 PM, David Chelimsky wrote: > On 8/7/07, Scott Taylor wrote: >> >> Is there any reason why a stub couldn't both yield and return? > > Yes. Nobody ever asked for it :) > > Again - this simply hasn't come up. Please add an RFE and feel free to > submit a patch. > Will do. I think for now I'm going to override the stub in the individual spec to yield. More importantly, I'm going to get autotest to work w/ rspec's native development before I do anymore rspec work. The time to run the full test suite is absolutely unbearable on my Mac G4. Scott From eivindu at ifi.uio.no Tue Aug 7 19:55:50 2007 From: eivindu at ifi.uio.no (Eivind Uggedal) Date: Wed, 8 Aug 2007 01:55:50 +0200 Subject: [rspec-users] Problems with raising errors on a mocked object Message-ID: <824b51d00708071655n6c943a34j320f754e04636d87@mail.gmail.com> I'm trying to mock a object to raise a certain error. By doing so I get a ArgumentError on ActiveRecord's save! method: http://pastie.caboo.se/85628 I've tried to debug it but just can't seem to find what I'm doing wrong. Any help is greatly appreciated. Cheers, Eivind Uggedal From mailing_lists at railsnewbie.com Tue Aug 7 21:14:48 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 7 Aug 2007 21:14:48 -0400 Subject: [rspec-users] and_yield + instance_eval(&block) Message-ID: <46C54C9D-1BF3-436A-93A7-466B6B3BD51D@railsnewbie.com> I have the following code, which yields instance eval's the block given: class Foo def bar(&blk) instance_eval &blk end def baz yield end end The effect of this is that self is reassigned: Foo.new.bar do # here, self is the instance of Foo # created by new end But normally self is the object in which Foo.new.bar {...} occurs. Foo.new.baz do # self is the execution context # in which Foo.new was called, # since a block is a closure end The second case is easy; it is covered by and_yield (with no arguments). Is there some way to spec the first case? Do I smell the need for a patch? Scott From mailing_lists at railsnewbie.com Tue Aug 7 21:34:48 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 7 Aug 2007 21:34:48 -0400 Subject: [rspec-users] and_yield + instance_eval(&block) In-Reply-To: <46C54C9D-1BF3-436A-93A7-466B6B3BD51D@railsnewbie.com> References: <46C54C9D-1BF3-436A-93A7-466B6B3BD51D@railsnewbie.com> Message-ID: <43942287-CA4B-4334-AB15-31C20931EE9B@railsnewbie.com> Duh. I should be using and_return(), not and_yield(), since I am actually returning the value of the instance eval. The method in question takes one parameter, a proc obj (as block). But how can I get a handle on that object (since it is anonymous)? Scott On Aug 7, 2007, at 9:14 PM, Scott Taylor wrote: > > I have the following code, which yields instance eval's the block > given: > > class Foo > > def bar(&blk) > instance_eval &blk > end > > def baz > yield > end > > end > > The effect of this is that self is reassigned: > > Foo.new.bar do > # here, self is the instance of Foo > # created by new > end > > But normally self is the object in which > Foo.new.bar {...} occurs. > > Foo.new.baz do > > # self is the execution context > # in which Foo.new was called, > # since a block is a closure > > end > > > The second case is easy; it is covered by and_yield (with no > arguments). > > Is there some way to spec the first case? Do I smell the need for a > patch? > > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Aug 7 23:30:37 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Aug 2007 22:30:37 -0500 Subject: [rspec-users] Problems with raising errors on a mocked object In-Reply-To: <824b51d00708071655n6c943a34j320f754e04636d87@mail.gmail.com> References: <824b51d00708071655n6c943a34j320f754e04636d87@mail.gmail.com> Message-ID: <57c63afe0708072030o423fcbbfk423ac89ed7dc31a4@mail.gmail.com> On 8/7/07, Eivind Uggedal wrote: > I'm trying to mock a object to raise a certain error. By doing so I > get a ArgumentError on ActiveRecord's save! method: > > http://pastie.caboo.se/85628 > > I've tried to debug it but just can't seem to find what I'm doing > wrong. Any help is greatly appreciated. Please run this: ruby script/spec ./spec/controllers/users_controller_spec.rb -b That will give the complete backtrace for the failure, which I'd ask you to pastie as well. > > Cheers, > Eivind Uggedal > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From flyeminent at hotmail.com Tue Aug 7 20:32:38 2007 From: flyeminent at hotmail.com (Shaker) Date: Tue, 7 Aug 2007 17:32:38 -0700 (PDT) Subject: [rspec-users] Failed to pass arguments to controller method Message-ID: <12045114.post@talk.nabble.com> Good morning to everyone: So weird!! I got a method called apply_settings(arg1, arg2) in the controller to be tested. In the controller spec, I of course called the method. In the controller: def apply_settings(arg1, arg2) #where arg1 is a hash, and arg2 is an array of object #do some coding end In the controller spec: before(:each) do @controller = Controller.new end it "should test the apply_settings" do @controller.apply_settings(Hash.new, array_of_object) #where the arguments are exactly some format #as required end However, it yielded "wrong number of arguments(0 for 1)" error after I ran the spec. It there anything wrong in my spec? Cheers! -- View this message in context: http://www.nabble.com/Failed-to-pass-arguments-to-controller-method-tf4233633.html#a12045114 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Wed Aug 8 00:03:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Aug 2007 23:03:01 -0500 Subject: [rspec-users] Failed to pass arguments to controller method In-Reply-To: <12045114.post@talk.nabble.com> References: <12045114.post@talk.nabble.com> Message-ID: <57c63afe0708072103s724324f8ncf9b8431183f837d@mail.gmail.com> On 8/7/07, Shaker wrote: > > Good morning to everyone: > So weird!! > I got a method called apply_settings(arg1, arg2) in the controller to be > tested. In the controller spec, I of course called the method. > In the controller: > def apply_settings(arg1, arg2) #where arg1 is a hash, and arg2 is an > array of object > #do some coding > end > In the controller spec: > before(:each) do > @controller = Controller.new > end > > it "should test the apply_settings" do > @controller.apply_settings(Hash.new, array_of_object) #where the > arguments are exactly some format > > #as required > end > > However, it yielded "wrong number of arguments(0 for 1)" error after I ran > the spec. It there anything wrong in my spec? Difficult to say with the little bit of code you're posting. It would be a lot easier to help if you posted the full code of the spec'd method, the spec, and the resulting backtrace. From eivindu at ifi.uio.no Wed Aug 8 01:44:15 2007 From: eivindu at ifi.uio.no (Eivind Uggedal) Date: Wed, 8 Aug 2007 07:44:15 +0200 Subject: [rspec-users] Problems with raising errors on a mocked object In-Reply-To: <57c63afe0708072030o423fcbbfk423ac89ed7dc31a4@mail.gmail.com> References: <824b51d00708071655n6c943a34j320f754e04636d87@mail.gmail.com> <57c63afe0708072030o423fcbbfk423ac89ed7dc31a4@mail.gmail.com> Message-ID: <824b51d00708072244t1659a75k4e7da81af7a617a1@mail.gmail.com> Here you go: http://pastie.caboo.se/85876 Eivind On 8/8/07, David Chelimsky wrote: > On 8/7/07, Eivind Uggedal wrote: > > I'm trying to mock a object to raise a certain error. By doing so I > > get a ArgumentError on ActiveRecord's save! method: > > > > http://pastie.caboo.se/85628 > > > > I've tried to debug it but just can't seem to find what I'm doing > > wrong. Any help is greatly appreciated. > > Please run this: > > ruby script/spec ./spec/controllers/users_controller_spec.rb -b > > That will give the complete backtrace for the failure, which I'd ask > you to pastie as well. > > > > > Cheers, > > Eivind Uggedal > > _______________________________________________ > > 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 > From dchelimsky at gmail.com Wed Aug 8 02:39:21 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Aug 2007 01:39:21 -0500 Subject: [rspec-users] Problems with raising errors on a mocked object In-Reply-To: <824b51d00708072244t1659a75k4e7da81af7a617a1@mail.gmail.com> References: <824b51d00708071655n6c943a34j320f754e04636d87@mail.gmail.com> <57c63afe0708072030o423fcbbfk423ac89ed7dc31a4@mail.gmail.com> <824b51d00708072244t1659a75k4e7da81af7a617a1@mail.gmail.com> Message-ID: <57c63afe0708072339w51c2027dvf9b375dc4e62b745@mail.gmail.com> On 8/8/07, Eivind Uggedal wrote: > Here you go: http://pastie.caboo.se/85876 OK - that helped. The and_raise method can take an exception class or object. If you pass it the class, it will try to create an instance of it using Klass.new. This is the source of the problem. In your example we see: @user.should_receive(:save!).and_raise(ActiveRecord::RecordInvalid) Rspec tries to call ActiveRecord::RecordInvalid.new, but that requires an argument, which is why you get an error saying it got 0 for 1 arguments. Because and_raise can also take an exception object, the solution to this problem is: @user.should_receive(:save!).and_raise(ActiveRecord::RecordInvalid.new(@user)) I guess the root of the problem is poor docs - I'm updating the rdoc now and it will be published with the next release. Cheers, David > > Eivind > > On 8/8/07, David Chelimsky wrote: > > On 8/7/07, Eivind Uggedal wrote: > > > I'm trying to mock a object to raise a certain error. By doing so I > > > get a ArgumentError on ActiveRecord's save! method: > > > > > > http://pastie.caboo.se/85628 > > > > > > I've tried to debug it but just can't seem to find what I'm doing > > > wrong. Any help is greatly appreciated. > > > > Please run this: > > > > ruby script/spec ./spec/controllers/users_controller_spec.rb -b > > > > That will give the complete backtrace for the failure, which I'd ask > > you to pastie as well. > > > > > > > > Cheers, > > > Eivind Uggedal > > > _______________________________________________ > > > 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 > From eivindu at ifi.uio.no Wed Aug 8 03:26:52 2007 From: eivindu at ifi.uio.no (Eivind Uggedal) Date: Wed, 8 Aug 2007 09:26:52 +0200 Subject: [rspec-users] Problems with raising errors on a mocked object In-Reply-To: <57c63afe0708072339w51c2027dvf9b375dc4e62b745@mail.gmail.com> References: <824b51d00708071655n6c943a34j320f754e04636d87@mail.gmail.com> <57c63afe0708072030o423fcbbfk423ac89ed7dc31a4@mail.gmail.com> <824b51d00708072244t1659a75k4e7da81af7a617a1@mail.gmail.com> <57c63afe0708072339w51c2027dvf9b375dc4e62b745@mail.gmail.com> Message-ID: <824b51d00708080026n44f1dcacu278ece8978dd94fe@mail.gmail.com> Thanks, that worked great after I had mocked out the ActiveRecord::Errors::full_messages: http://pastie.caboo.se/85887 Cheers, Eivind Uggedal On 8/8/07, David Chelimsky wrote: > On 8/8/07, Eivind Uggedal wrote: > > Here you go: http://pastie.caboo.se/85876 > > OK - that helped. > > The and_raise method can take an exception class or object. If you > pass it the class, it will try to create an instance of it using > Klass.new. This is the source of the problem. In your example we see: > > @user.should_receive(:save!).and_raise(ActiveRecord::RecordInvalid) > > Rspec tries to call ActiveRecord::RecordInvalid.new, but that requires > an argument, which is why you get an error saying it got 0 for 1 > arguments. > > Because and_raise can also take an exception object, the solution to > this problem is: > > @user.should_receive(:save!).and_raise(ActiveRecord::RecordInvalid.new(@user)) > > I guess the root of the problem is poor docs - I'm updating the rdoc > now and it will be published with the next release. > > Cheers, > David > > > > > > Eivind > > > > On 8/8/07, David Chelimsky wrote: > > > On 8/7/07, Eivind Uggedal wrote: > > > > I'm trying to mock a object to raise a certain error. By doing so I > > > > get a ArgumentError on ActiveRecord's save! method: > > > > > > > > http://pastie.caboo.se/85628 > > > > > > > > I've tried to debug it but just can't seem to find what I'm doing > > > > wrong. Any help is greatly appreciated. > > > > > > Please run this: > > > > > > ruby script/spec ./spec/controllers/users_controller_spec.rb -b > > > > > > That will give the complete backtrace for the failure, which I'd ask > > > you to pastie as well. > > > > > > > > > > > Cheers, > > > > Eivind Uggedal > > > > _______________________________________________ > > > > 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 > From work at ashleymoran.me.uk Wed Aug 8 05:53:19 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 8 Aug 2007 10:53:19 +0100 Subject: [rspec-users] RSpec book? Message-ID: <0ECB23AC-0DAF-41E6-B1C0-5F81D002AA58@ashleymoran.me.uk> Came across this as a stub page browsing Amazon UK. This is good news! I'm surprised it hasn't been discussed on the list before. Was Chad keeping it a secret? I hope it will have plenty of BDD theory. I'm still waiting for that magic book I can give to someone and say "here - read this, it tells you how to build software". Ashley From lancecarlson at gmail.com Wed Aug 8 10:26:21 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Wed, 8 Aug 2007 10:26:21 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers Message-ID: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> I am using helper the RESTfully generated helper methods in my views. My routes are nested so the helpers appear to need arguments passed to them, but it works without arguments. Say for example I have pages and comments. If I do page_comments_path without parameters, it works. However, when I run the rspec test, it fails and tells me i'm missing parameters. I tried to pass params[:page_id], but it still says it needs parameters. I did fill in the parameters like it asked and the test passed, but I think my views look cleaner without the arguments being passed everywhere. Do I have to stub these methods to get my views to pass, or is there some other way? TIA, Lance From kevwil at gmail.com Wed Aug 8 10:33:45 2007 From: kevwil at gmail.com (Kevin Williams) Date: Wed, 8 Aug 2007 08:33:45 -0600 Subject: [rspec-users] RSpec book? In-Reply-To: <0ECB23AC-0DAF-41E6-B1C0-5F81D002AA58@ashleymoran.me.uk> References: <0ECB23AC-0DAF-41E6-B1C0-5F81D002AA58@ashleymoran.me.uk> Message-ID: <683a886f0708080733w1aeca603le2e7a6c11ad08b54@mail.gmail.com> I can't wait to read this. If IronRuby ever supports RSpec, I'll give a copy of this book to all my .NET cronies and say just what Ashley said. :) On 8/8/07, Ashley Moran wrote: > > > Came across this as a stub page browsing Amazon UK. This is good > news! I'm surprised it hasn't been discussed on the list before. > Was Chad keeping it a secret? > > I hope it will have plenty of BDD theory. I'm still waiting for that > magic book I can give to someone and say "here - read this, it tells > you how to build software". > > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Cheers, Kevin Williams http://www.almostserio.us/ http://kevwil.tumblr.com/ http://kevwil.jaiku.com/ From dchelimsky at gmail.com Wed Aug 8 11:07:42 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Aug 2007 10:07:42 -0500 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> Message-ID: <57c63afe0708080807k6a8f13ecu435b97c24bd73207@mail.gmail.com> On 8/8/07, Lance Carlson wrote: > I am using helper the RESTfully generated helper methods in my views. > My routes are nested so the helpers appear to need arguments passed to > them, but it works without arguments. Say for example I have pages and > comments. If I do page_comments_path without parameters, it works. > However, when I run the rspec test, it fails and tells me i'm missing > parameters. I tried to pass params[:page_id], but it still says it > needs parameters. I did fill in the parameters like it asked and the > test passed, but I think my views look cleaner without the arguments > being passed everywhere. Do I have to stub these methods to get my > views to pass, or is there some other way? It would be much easier to answer your question if you posted the actual spec and code. > > TIA, > Lance > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lancecarlson at gmail.com Wed Aug 8 11:56:56 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Wed, 8 Aug 2007 11:56:56 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <57c63afe0708080807k6a8f13ecu435b97c24bd73207@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708080807k6a8f13ecu435b97c24bd73207@mail.gmail.com> Message-ID: <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> ActionView::TemplateError in 'Edit Artist Page should render the edit artist form' label_artist_url failed to generate from {:controller=>"artists", :action=>"show"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["labels", :label_id, "artists", :id] - are they all satisfied? On line #3 of app/views/artists/edit.rhtml 1:

Editing artist

2: 3: <% form_tag label_artist_path, :method => :put do %> 4: <%= render :partial => 'form' %> 5: <%= submit_tag 'Save' %> 6: <% end %> My spec looks like: require File.dirname(__FILE__) + '/../../spec_helper' describe 'Edit Artist Page' do before do @label = mock_model(Label) @artist = mock_model(Artist) assigns[:label] = @label assigns[:artist] = @artist end def render_edit render :template => 'artists/edit' end it "should render the edit artist form" do render_edit end end On 8/8/07, David Chelimsky wrote: > On 8/8/07, Lance Carlson wrote: > > I am using helper the RESTfully generated helper methods in my views. > > My routes are nested so the helpers appear to need arguments passed to > > them, but it works without arguments. Say for example I have pages and > > comments. If I do page_comments_path without parameters, it works. > > However, when I run the rspec test, it fails and tells me i'm missing > > parameters. I tried to pass params[:page_id], but it still says it > > needs parameters. I did fill in the parameters like it asked and the > > test passed, but I think my views look cleaner without the arguments > > being passed everywhere. Do I have to stub these methods to get my > > views to pass, or is there some other way? > > It would be much easier to answer your question if you posted the > actual spec and code. > > > > > TIA, > > Lance > > _______________________________________________ > > 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 > From mailing_lists at railsnewbie.com Wed Aug 8 13:34:05 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 8 Aug 2007 13:34:05 -0400 Subject: [rspec-users] RSpec book? In-Reply-To: <0ECB23AC-0DAF-41E6-B1C0-5F81D002AA58@ashleymoran.me.uk> References: <0ECB23AC-0DAF-41E6-B1C0-5F81D002AA58@ashleymoran.me.uk> Message-ID: <14755201-36B3-42F6-9D64-FE1BEE3B43B2@railsnewbie.com> Speaking of a BDD book, does anyone recommend Dave Astels book? Or should I assume I doing "testing well" if I'm using rspec? Scott On Aug 8, 2007, at 5:53 AM, Ashley Moran wrote: > > > Came across this as a stub page browsing Amazon UK. This is good > news! I'm surprised it hasn't been discussed on the list before. > Was Chad keeping it a secret? > > I hope it will have plenty of BDD theory. I'm still waiting for that > magic book I can give to someone and say "here - read this, it tells > you how to build software". > > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rails at content-space.de Wed Aug 8 13:41:12 2007 From: rails at content-space.de (Michael Hamann) Date: Wed, 08 Aug 2007 19:41:12 +0200 Subject: [rspec-users] Transactional fixtures not working as expected Message-ID: <46BA0038.10807@content-space.de> Hi! I am quite new to BDD and I just wrote my first tests. Suddenly I received unexpected results because in a model test I load only users-fixtures but when the views-fixtures in which I load the posts-fixtures, are run before this model-test, the posts-fixtures are loaded too. I test for example if there is one record in the posts-table after creating one post. But when there are fixtures loaded, this does not work of course. A similar issue was discussed here already in October 2006, but there was no real result: http://rubyforge.org/pipermail/rspec-users/2006-October/000088.html I am using edge rails with the current RSpec and RSpec on Rails - plugins. I first used sqlite3, then mysql to verify that it is no sqlite3 bug, but the errors occur also when I am using Mysql. Transactional fixtures are enabled, instantiated fixtures are disabled. My question is now: Is this behavior really desired? Because now my model-tests alone pass, and all the other tests too, but when the view-tests are run before the model-tests, they don't pass. So the passing of the tests becomes unpredictable. And I think I will have additional fixtures for models I don't use fixtures at the moment and this will make other tests fail, too. So should I really write tests that work with any fixtures loaded? And why is there a possibility to load fixtures in one description also this loads the fixtures actually globally? What can I do against this behavior? Is this a bug? Greetings Michael Hamann From lancecarlson at gmail.com Wed Aug 8 13:50:42 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Wed, 8 Aug 2007 13:50:42 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708080807k6a8f13ecu435b97c24bd73207@mail.gmail.com> <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> Message-ID: <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> I just passed label_artist_path(@label.id, @artist.id) into the view and it worked.. but I really don't want to have to pass those parameters in all my views. It looks ugly. Does anyone know a way around this without stubbing? It seems useless to test this view without allowing those methods to act out their real behavior. -TIA On 8/8/07, Lance Carlson wrote: > ActionView::TemplateError in 'Edit Artist Page should render the edit > artist form' > label_artist_url failed to generate from {:controller=>"artists", > :action=>"show"} - you may have ambiguous routes, or you may need to > supply additional parameters for this route. content_url has the > following required parameters: ["labels", :label_id, "artists", :id] - > are they all satisfied? > On line #3 of app/views/artists/edit.rhtml > > 1:

Editing artist

> 2: > 3: <% form_tag label_artist_path, :method => :put do %> > 4: <%= render :partial => 'form' %> > 5: <%= submit_tag 'Save' %> > 6: <% end %> > > > My spec looks like: > > require File.dirname(__FILE__) + '/../../spec_helper' > > describe 'Edit Artist Page' do > before do > @label = mock_model(Label) > @artist = mock_model(Artist) > > assigns[:label] = @label > assigns[:artist] = @artist > end > > def render_edit > render :template => 'artists/edit' > end > > it "should render the edit artist form" do > render_edit > end > end > > On 8/8/07, David Chelimsky wrote: > > On 8/8/07, Lance Carlson wrote: > > > I am using helper the RESTfully generated helper methods in my views. > > > My routes are nested so the helpers appear to need arguments passed to > > > them, but it works without arguments. Say for example I have page