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 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 pergesu at gmail.com Wed Aug 8 14:07:23 2007 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 8 Aug 2007 11:07:23 -0700 Subject: [rspec-users] RSpec book? In-Reply-To: <14755201-36B3-42F6-9D64-FE1BEE3B43B2@railsnewbie.com> References: <0ECB23AC-0DAF-41E6-B1C0-5F81D002AA58@ashleymoran.me.uk> <14755201-36B3-42F6-9D64-FE1BEE3B43B2@railsnewbie.com> Message-ID: <810a540e0708081107l6c021336l38f327da63b9d259@mail.gmail.com> It's dated, as far as the Java side goes. A lot of the examples don't work anymore. This wouldn't be a problem if it were just writing classes and text-based programs (because then it's cake to do it in Ruby ;), but in his example he creates a full-blown GUI app. So it's kind of hard to follow along, and I think a book about testing is of limited use when you can't really test the code ;) However it's still good from a conceptual standpoint, it drives home the point that TDD is about design, not testing. I really like Kent Beck's book, although it's more about testing techniques than using TDD as a design tool. This is an area where there's certainly a void, I think. All the people who've really mastered TDD/BDD are probably too busy working to write a book. I'm definitely looking forward to this. Pat On 8/8/07, Scott Taylor wrote: > > 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 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Aug 8 14:30:49 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Aug 2007 13:30:49 -0500 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708080807k6a8f13ecu435b97c24bd73207@mail.gmail.com> <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> Message-ID: <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> On 8/8/07, Lance Carlson wrote: > 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. Can you point me to docs that say you're supposed to be able to just call label_artist_path without any args? I've not see such docs and I can't get it to work in any of my views - and I'm talking about just rendering the views at all, not getting specs to work. > > -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 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 > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lancecarlson at gmail.com Wed Aug 8 14:38:47 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Wed, 8 Aug 2007 14:38:47 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708080807k6a8f13ecu435b97c24bd73207@mail.gmail.com> <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> Message-ID: <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> All I'm doing is passing the instance variables @label and @artist in the controller to the view using this code: @label = current_user.labels.find(params[:label_id]) @artist = params[:id].nil? ? Artist.new : @label.artists.find(params[:id]) By sending these two instance variables to the view, I don't need to specify these arguments and the view just works. Can you get it to work when you specify these instance variables in your controller? -L On 8/8/07, David Chelimsky wrote: > On 8/8/07, Lance Carlson wrote: > > 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. > > Can you point me to docs that say you're supposed to be able to just > call label_artist_path without any args? I've not see such docs and I > can't get it to work in any of my views - and I'm talking about just > rendering the views at all, not getting specs to work. > > > > > -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 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 > > > > > > > > > _______________________________________________ > > 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 14:41:31 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Aug 2007 13:41:31 -0500 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708080807k6a8f13ecu435b97c24bd73207@mail.gmail.com> <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> Message-ID: <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> On 8/8/07, Lance Carlson wrote: > All I'm doing is passing the instance variables @label and @artist in > the controller to the view using this code: > > @label = current_user.labels.find(params[:label_id]) > @artist = params[:id].nil? ? Artist.new : @label.artists.find(params[:id]) > > By sending these two instance variables to the view, I don't need to > specify these arguments and the view just works. Can you get it to > work when you specify these instance variables in your controller? No. That's what I'm saying. I get the same ambigous URL error you cited in the first email in this thread, but in the browser. Using edge rails, edge rspec. > > -L > > On 8/8/07, David Chelimsky wrote: > > On 8/8/07, Lance Carlson wrote: > > > 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. > > > > Can you point me to docs that say you're supposed to be able to just > > call label_artist_path without any args? I've not see such docs and I > > can't get it to work in any of my views - and I'm talking about just > > rendering the views at all, not getting specs to work. > > > > > > > > -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 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 > > > > > > > > > > > > _______________________________________________ > > > 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 lancecarlson at gmail.com Wed Aug 8 14:46:59 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Wed, 8 Aug 2007 14:46:59 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708080807k6a8f13ecu435b97c24bd73207@mail.gmail.com> <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> Message-ID: <49f64a900708081146w6564983dhed18d215ef91d727@mail.gmail.com> I just visited the action in my browser and i don't get any errors. I am also running on edge rails as the application relies on ActiveResource. Can you show me the code you created? On 8/8/07, David Chelimsky wrote: > On 8/8/07, Lance Carlson wrote: > > All I'm doing is passing the instance variables @label and @artist in > > the controller to the view using this code: > > > > @label = current_user.labels.find(params[:label_id]) > > @artist = params[:id].nil? ? Artist.new : @label.artists.find(params[:id]) > > > > By sending these two instance variables to the view, I don't need to > > specify these arguments and the view just works. Can you get it to > > work when you specify these instance variables in your controller? > > No. That's what I'm saying. I get the same ambigous URL error you > cited in the first email in this thread, but in the browser. Using > edge rails, edge rspec. > > > > > -L > > > > On 8/8/07, David Chelimsky wrote: > > > On 8/8/07, Lance Carlson wrote: > > > > 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. > > > > > > Can you point me to docs that say you're supposed to be able to just > > > call label_artist_path without any args? I've not see such docs and I > > > can't get it to work in any of my views - and I'm talking about just > > > rendering the views at all, not getting specs to work. > > > > > > > > > > > -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 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 > > > > > > > > > > > > > > > _______________________________________________ > > > > 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 nicksieger at gmail.com Wed Aug 8 16:17:31 2007 From: nicksieger at gmail.com (Nick Sieger) Date: Wed, 8 Aug 2007 15:17:31 -0500 Subject: [rspec-users] using RSpec's trunk in non-rails projects w/ Autotest In-Reply-To: <3C103E41-DEBC-4389-A0AB-E4F42CDE6338@railsnewbie.com> References: <3C103E41-DEBC-4389-A0AB-E4F42CDE6338@railsnewbie.com> Message-ID: On 8/6/07, Scott Taylor wrote: > > > 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 ; ). Check out the trunk somewhere and set RUBYLIB=/path/to/rspec/trunk? Emulate the Rails vendor structure somewhat and have a bootstrap script that adds RSpec in that location to the load path? /Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070808/1c660c73/attachment.html From mailing_lists at railsnewbie.com Wed Aug 8 16:27:50 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 8 Aug 2007 16:27:50 -0400 Subject: [rspec-users] using RSpec's trunk in non-rails projects w/ Autotest In-Reply-To: References: <3C103E41-DEBC-4389-A0AB-E4F42CDE6338@railsnewbie.com> Message-ID: <46A856C5-0A29-4434-9CDC-0BC9EE207F4B@railsnewbie.com> Hey Nick, Good to hear from you (as the original developer of the autotest compatibility issue). I was working on the same issue David was (to fix autotest to work for RSpec's trunk), only to find that David had modified it. I have refactored the autotest plugin to use vendor/plugin/rspec/bin if that exists, and have spec'ed out most of the Autotest. This means that a non-rails project could use vendor/plugins w/ rspec checked out, and autotest should work out of the box. Right now spec coverage is at 99.7%, so I'm working on finishing up the specs for RSpec's autotest. (David, I assume this would be welcome?) Scott On Aug 8, 2007, at 4:17 PM, Nick Sieger wrote: > On 8/6/07, Scott Taylor wrote: > > 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 ; ). > > Check out the trunk somewhere and set RUBYLIB=/path/to/rspec/trunk? > > Emulate the Rails vendor structure somewhat and have a bootstrap > script that adds RSpec in that location to the load path? > > /Nick > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Aug 8 16:30:45 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Aug 2007 15:30:45 -0500 Subject: [rspec-users] using RSpec's trunk in non-rails projects w/ Autotest In-Reply-To: <46A856C5-0A29-4434-9CDC-0BC9EE207F4B@railsnewbie.com> References: <3C103E41-DEBC-4389-A0AB-E4F42CDE6338@railsnewbie.com> <46A856C5-0A29-4434-9CDC-0BC9EE207F4B@railsnewbie.com> Message-ID: <57c63afe0708081330tfc8a1p6854b30da76380f9@mail.gmail.com> On 8/8/07, Scott Taylor wrote: > I was working on the same issue David was (to fix autotest to work > for RSpec's trunk), only to find that David had modified it. Sorry - I saw the RFE and was taking a look at solutions and it was too easy to not just do. > I have refactored the autotest plugin to use vendor/plugin/rspec/bin > if that exists, and have spec'ed out most of the Autotest. This > means that a non-rails project could use vendor/plugins w/ rspec > checked out, and autotest should work out of the box. > > Right now spec coverage is at 99.7%, so I'm working on finishing up > the specs for RSpec's autotest. (David, I assume this would be > welcome?) Absolutely!!!! I'll stay out of your way on this one :) Cheers, David From mailing_lists at railsnewbie.com Wed Aug 8 16:36:36 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 8 Aug 2007 16:36:36 -0400 Subject: [rspec-users] using RSpec's trunk in non-rails projects w/ Autotest In-Reply-To: <57c63afe0708081330tfc8a1p6854b30da76380f9@mail.gmail.com> References: <3C103E41-DEBC-4389-A0AB-E4F42CDE6338@railsnewbie.com> <46A856C5-0A29-4434-9CDC-0BC9EE207F4B@railsnewbie.com> <57c63afe0708081330tfc8a1p6854b30da76380f9@mail.gmail.com> Message-ID: On Aug 8, 2007, at 4:30 PM, David Chelimsky wrote: > On 8/8/07, Scott Taylor wrote: >> I was working on the same issue David was (to fix autotest to work >> for RSpec's trunk), only to find that David had modified it. > > Sorry - I saw the RFE and was taking a look at solutions and it was > too easy to not just do. > >> I have refactored the autotest plugin to use vendor/plugin/rspec/bin >> if that exists, and have spec'ed out most of the Autotest. This >> means that a non-rails project could use vendor/plugins w/ rspec >> checked out, and autotest should work out of the box. >> >> Right now spec coverage is at 99.7%, so I'm working on finishing up >> the specs for RSpec's autotest. (David, I assume this would be >> welcome?) > > Absolutely!!!! I'll stay out of your way on this one :) Unfortunately, the specs (for the rest of our Autotest plugin) are coupled with the original refactoring that I made. I hope that's alright (I've had this problem with multiple patch dependencies in the past). If that's not OK, then I'll submit them, and write some throw away specs for the version that is currently on trunk. Scott From dchelimsky at gmail.com Wed Aug 8 16:40:20 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Aug 2007 15:40:20 -0500 Subject: [rspec-users] using RSpec's trunk in non-rails projects w/ Autotest In-Reply-To: References: <3C103E41-DEBC-4389-A0AB-E4F42CDE6338@railsnewbie.com> <46A856C5-0A29-4434-9CDC-0BC9EE207F4B@railsnewbie.com> <57c63afe0708081330tfc8a1p6854b30da76380f9@mail.gmail.com> Message-ID: <57c63afe0708081340w1b899c97u44a9a4101abb4d7b@mail.gmail.com> On 8/8/07, Scott Taylor wrote: > > On Aug 8, 2007, at 4:30 PM, David Chelimsky wrote: > > > On 8/8/07, Scott Taylor wrote: > >> I was working on the same issue David was (to fix autotest to work > >> for RSpec's trunk), only to find that David had modified it. > > > > Sorry - I saw the RFE and was taking a look at solutions and it was > > too easy to not just do. > > > >> I have refactored the autotest plugin to use vendor/plugin/rspec/bin > >> if that exists, and have spec'ed out most of the Autotest. This > >> means that a non-rails project could use vendor/plugins w/ rspec > >> checked out, and autotest should work out of the box. > >> > >> Right now spec coverage is at 99.7%, so I'm working on finishing up > >> the specs for RSpec's autotest. (David, I assume this would be > >> welcome?) > > > > Absolutely!!!! I'll stay out of your way on this one :) > > Unfortunately, the specs (for the rest of our Autotest plugin) are > coupled with the original refactoring that I made. I hope that's > alright (I've had this problem with multiple patch dependencies in > the past). > > If that's not OK, then I'll submit them, and write some throw away > specs for the version that is currently on trunk. I'm less worried about the implementation than I am about being able to easily apply your patch to the current trunk. As long as I can do that, it's fine. > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lancecarlson at gmail.com Wed Aug 8 16:41:39 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Wed, 8 Aug 2007 16:41:39 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <49f64a900708081146w6564983dhed18d215ef91d727@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708080807k6a8f13ecu435b97c24bd73207@mail.gmail.com> <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> <49f64a900708081146w6564983dhed18d215ef91d727@mail.gmail.com> Message-ID: <49f64a900708081341o6282f6a2y371ca8c9ad764756@mail.gmail.com> David, I know for a fact that these helpers do not require arguments to be sent to them. Does anyone have any idea why rspec is forcing this to happen? On 8/8/07, Lance Carlson wrote: > I just visited the action in my browser and i don't get any errors. I > am also running on edge rails as the application relies on > ActiveResource. Can you show me the code you created? > > On 8/8/07, David Chelimsky wrote: > > On 8/8/07, Lance Carlson wrote: > > > All I'm doing is passing the instance variables @label and @artist in > > > the controller to the view using this code: > > > > > > @label = current_user.labels.find(params[:label_id]) > > > @artist = params[:id].nil? ? Artist.new : @label.artists.find(params[:id]) > > > > > > By sending these two instance variables to the view, I don't need to > > > specify these arguments and the view just works. Can you get it to > > > work when you specify these instance variables in your controller? > > > > No. That's what I'm saying. I get the same ambigous URL error you > > cited in the first email in this thread, but in the browser. Using > > edge rails, edge rspec. > > > > > > > > -L > > > > > > On 8/8/07, David Chelimsky wrote: > > > > On 8/8/07, Lance Carlson wrote: > > > > > 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. > > > > > > > > Can you point me to docs that say you're supposed to be able to just > > > > call label_artist_path without any args? I've not see such docs and I > > > > can't get it to work in any of my views - and I'm talking about just > > > > rendering the views at all, not getting specs to work. > > > > > > > > > > > > > > -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 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 > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > 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 lists-rspec at shopwatch.org Wed Aug 8 16:46:12 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Wed, 08 Aug 2007 16:46:12 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708080807k6a8f13ecu435b97c24bd73207@mail.gmail.com> <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> Message-ID: <46BA2B94.4020006@jay.fm> David Chelimsky wrote: > On 8/8/07, Lance Carlson wrote: >> All I'm doing is passing the instance variables @label and @artist in >> the controller to the view using this code: >> >> @label = current_user.labels.find(params[:label_id]) >> @artist = params[:id].nil? ? Artist.new : @label.artists.find(params[:id]) >> >> By sending these two instance variables to the view, I don't need to >> specify these arguments and the view just works. Can you get it to >> work when you specify these instance variables in your controller? > > No. That's what I'm saying. I get the same ambigous URL error you > cited in the first email in this thread, but in the browser. Using > edge rails, edge rspec. Dumb question, but do you have the resource mapped in your routes.rb file? Something like map.resources :artists Jay > >> -L >> >> On 8/8/07, David Chelimsky wrote: >>> On 8/8/07, Lance Carlson wrote: >>>> 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. >>> Can you point me to docs that say you're supposed to be able to just >>> call label_artist_path without any args? I've not see such docs and I >>> can't get it to work in any of my views - and I'm talking about just >>> rendering the views at all, not getting specs to work. >>> >>>> -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 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 >>>>>> >>>> _______________________________________________ >>>> 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 lancecarlson at gmail.com Wed Aug 8 16:48:10 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Wed, 8 Aug 2007 16:48:10 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <46BA2B94.4020006@jay.fm> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708080807k6a8f13ecu435b97c24bd73207@mail.gmail.com> <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> <46BA2B94.4020006@jay.fm> Message-ID: <49f64a900708081348m49c427bfi3e727ebfa784e1cb@mail.gmail.com> Yes, map.resources :labels do |label| label.resources :artists end On 8/8/07, Jay Levitt wrote: > David Chelimsky wrote: > > On 8/8/07, Lance Carlson wrote: > >> All I'm doing is passing the instance variables @label and @artist in > >> the controller to the view using this code: > >> > >> @label = current_user.labels.find(params[:label_id]) > >> @artist = params[:id].nil? ? Artist.new : @label.artists.find(params[:id]) > >> > >> By sending these two instance variables to the view, I don't need to > >> specify these arguments and the view just works. Can you get it to > >> work when you specify these instance variables in your controller? > > > > No. That's what I'm saying. I get the same ambigous URL error you > > cited in the first email in this thread, but in the browser. Using > > edge rails, edge rspec. > > Dumb question, but do you have the resource mapped in your routes.rb > file? Something like > > map.resources :artists > > Jay > > > > >> -L > >> > >> On 8/8/07, David Chelimsky wrote: > >>> On 8/8/07, Lance Carlson wrote: > >>>> 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. > >>> Can you point me to docs that say you're supposed to be able to just > >>> call label_artist_path without any args? I've not see such docs and I > >>> can't get it to work in any of my views - and I'm talking about just > >>> rendering the views at all, not getting specs to work. > >>> > >>>> -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 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 > >>>>>> > >>>> _______________________________________________ > >>>> 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 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From daniel at danielfischer.com Wed Aug 8 17:08:24 2007 From: daniel at danielfischer.com (Fischer, Daniel) Date: Wed, 8 Aug 2007 14:08:24 -0700 Subject: [rspec-users] Can't seem to spec a ActiveRecord::RecordInvalid exception properly... Message-ID: <7e565b5c0708081408q474ac9e9m729143cc86ddaab7@mail.gmail.com> 1 def create 2 @user = User.new(params[:user]) 3 @user.save! 4 self.current_user = @user 5 redirect_to user_path(@user) 6 flash[:notice] = "Thanks for signing up!" 7 rescue ActiveRecord::RecordInvalid 8 render :action => 'new' 9 end I can't seem to properly spec this out. I am trying numerous things, the latest one is this, which makes sense but it still fails... it "should re-render new on an invalid record exception" do post :create, :user => {:login => nil} response.should render_template(:new) end should re-render new on an invalid record exception expected "new", got nil Any help would be great, thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070808/9cb7bada/attachment.html From lancecarlson at gmail.com Wed Aug 8 17:14:03 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Wed, 8 Aug 2007 17:14:03 -0400 Subject: [rspec-users] Can't seem to spec a ActiveRecord::RecordInvalid exception properly... In-Reply-To: <7e565b5c0708081408q474ac9e9m729143cc86ddaab7@mail.gmail.com> References: <7e565b5c0708081408q474ac9e9m729143cc86ddaab7@mail.gmail.com> Message-ID: <49f64a900708081414o26bdc9bax949115dee2a67d87@mail.gmail.com> Does it redirect instead? On 8/8/07, Fischer, Daniel wrote: > 1 def create > 2 @user = User.new(params[:user]) > 3 @user.save! > 4 self.current_user = @user > 5 redirect_to user_path(@user) > 6 flash[:notice] = "Thanks for signing up!" > 7 rescue ActiveRecord::RecordInvalid > 8 render :action => 'new' > 9 end > > I can't seem to properly spec this out. I am trying numerous things, the > latest one is this, which makes sense but it still fails... > > > it "should re-render new on an invalid record exception" do > post :create, :user => {:login => nil} > response.should render_template(:new) > end > > should re-render new on an invalid record exception > expected "new", got nil > > Any help would be great, thanks! > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From daniel at danielfischer.com Wed Aug 8 17:22:15 2007 From: daniel at danielfischer.com (Fischer, Daniel) Date: Wed, 8 Aug 2007 14:22:15 -0700 Subject: [rspec-users] Can't seem to spec a ActiveRecord::RecordInvalid exception properly... In-Reply-To: <49f64a900708081414o26bdc9bax949115dee2a67d87@mail.gmail.com> References: <7e565b5c0708081408q474ac9e9m729143cc86ddaab7@mail.gmail.com> <49f64a900708081414o26bdc9bax949115dee2a67d87@mail.gmail.com> Message-ID: <7e565b5c0708081422i5cbe77d7h22a9de9c892e2ad3@mail.gmail.com> It's redirecting to /users/1 so it's not causing a fail on the exception, which I don't know why. My question is how to properly do this in rSpec? On 8/8/07, Lance Carlson wrote: > > Does it redirect instead? > > On 8/8/07, Fischer, Daniel wrote: > > 1 def create > > 2 @user = User.new(params[:user]) > > 3 @user.save! > > 4 self.current_user = @user > > 5 redirect_to user_path(@user) > > 6 flash[:notice] = "Thanks for signing up!" > > 7 rescue ActiveRecord::RecordInvalid > > 8 render :action => 'new' > > 9 end > > > > I can't seem to properly spec this out. I am trying numerous things, the > > latest one is this, which makes sense but it still fails... > > > > > > it "should re-render new on an invalid record exception" do > > post :create, :user => {:login => nil} > > response.should render_template(:new) > > end > > > > should re-render new on an invalid record exception > > expected "new", got nil > > > > Any help would be great, thanks! > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070808/5817f2a6/attachment.html From nemo7467 at gmail.com Wed Aug 8 17:25:56 2007 From: nemo7467 at gmail.com (David Parker) Date: Wed, 8 Aug 2007 16:25:56 -0500 Subject: [rspec-users] rspec with autotest on a windows machine Message-ID: <9a07e4a80708081425q515be2b1m6bd4183b452bde59@mail.gmail.com> Hello all, I'm new to rSpec but after reading a couple of tutorials I've become enamored. Anyway, I am at minute 42 of the rSpec basics screencast ( peepcode.com) and I'm having the following error running autotest w/rSpec: D:\ruby\projects\forecaster>autotest loading autotest/rails_rspec c:\ruby\bin\ruby -rrubygems -e "require 'redgreen'" -S script/spec -O spec/spec.opts spec/models/weather_spec.rb spec/views/weathers/show.rhtml_spec.rb spec/controllers/weathers_controller_spec.rb spec/views/weathers/new.rhtml_spec.rb spec/views/weathers/edit.rhtml_spec.rb spec/helpers/weathers_helper_spec.rb spec/views/weathers/index.rhtml_spec.rb invalid option: -O Test::Unit automatic runner. I also have the TDD screencast and I am able to run autotest with no problems: D:\ruby\projects\journal_app>autotest loading autotest/rails c:\ruby\bin\ruby -rrubygems -e "require 'redgreen'" -I.;lib;test -rtest/unit -e "%w[test/functional/journals_controller_test.rb test/integration/journal_stories_test.rb test/unit/journal_test.rb].each { |f| require f }" | unit_diff -u Loaded suite -e Started ................ Finished in 1.265 seconds. 16 tests, 33 assertions, 0 failures, 0 errors Note: I am running Rails 1.2.3 and ZenTest v 3.6.1 on a Windows machine (sad, I know, but we've discussed that already). When I run 'ruby script/spec -v' it says: RSpec-1.0.5 (r2081) - BDD for Ruby I've also tried installing the newest version of the rSpec plugins and running "ruby script/generate rspec" so the proper files are copied to the script folder. as a "hack" fix, I did this: 1) I removed my .autotest file completely (so no fun red/green/etc) 2) I modified plugins>rspec>lib>autotest> rspec.rb and removed "#{add_options_if_present}" from line 50 Anyone know of what my problem may be? Windows perhaps? It would sure be nice to be able to keep my .autotest file... Thanks for any help you can provide! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070808/a24d9cf4/attachment.html From lancecarlson at gmail.com Wed Aug 8 17:35:19 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Wed, 8 Aug 2007 17:35:19 -0400 Subject: [rspec-users] Can't seem to spec a ActiveRecord::RecordInvalid exception properly... In-Reply-To: <7e565b5c0708081422i5cbe77d7h22a9de9c892e2ad3@mail.gmail.com> References: <7e565b5c0708081408q474ac9e9m729143cc86ddaab7@mail.gmail.com> <49f64a900708081414o26bdc9bax949115dee2a67d87@mail.gmail.com> <7e565b5c0708081422i5cbe77d7h22a9de9c892e2ad3@mail.gmail.com> Message-ID: <49f64a900708081435pfa7319bqaf156ff6fe52ad8c@mail.gmail.com> Is it redirecting or is it rendering new? On 8/8/07, Fischer, Daniel wrote: > It's redirecting to /users/1 so it's not causing a fail on the exception, > which I don't know why. My question is how to properly do this in rSpec? > > > On 8/8/07, Lance Carlson wrote: > > Does it redirect instead? > > > > On 8/8/07, Fischer, Daniel wrote: > > > 1 def create > > > 2 @user = User.new(params[:user]) > > > 3 @ user.save! > > > 4 self.current_user = @user > > > 5 redirect_to user_path(@user) > > > 6 flash[:notice] = "Thanks for signing up!" > > > 7 rescue ActiveRecord::RecordInvalid > > > 8 render :action => 'new' > > > 9 end > > > > > > I can't seem to properly spec this out. I am trying numerous things, the > > > latest one is this, which makes sense but it still fails... > > > > > > > > > it "should re-render new on an invalid record exception" do > > > post :create, :user => {:login => nil} > > > response.should render_template(:new) > > > end > > > > > > should re-render new on an invalid record exception > > > expected "new", got nil > > > > > > Any help would be great, thanks! > > > > > > _______________________________________________ > > > 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 mailing_lists at railsnewbie.com Wed Aug 8 17:45:23 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 8 Aug 2007 17:45:23 -0400 Subject: [rspec-users] rspec with autotest on a windows machine In-Reply-To: <9a07e4a80708081425q515be2b1m6bd4183b452bde59@mail.gmail.com> References: <9a07e4a80708081425q515be2b1m6bd4183b452bde59@mail.gmail.com> Message-ID: Do you have spec/spec.opts? Scott On Aug 8, 2007, at 5:25 PM, David Parker wrote: > Hello all, > I'm new to rSpec but after reading a couple of tutorials I've > become enamored. Anyway, I am at minute 42 of the rSpec basics > screencast ( peepcode.com) and I'm having the following error > running autotest w/rSpec: > D:\ruby\projects\forecaster > >autotest > loading autotest/rails_rspec > c:\ruby\bin\ruby -rrubygems -e "require 'redgreen'" -S script/spec > -O spec/spec.opts spec/models/weather_spec.rb spec/views/weathers/ > show.rhtml_spec.rb spec/controllers/weathers_controller_spec.rb > spec/views/weathers/new.rhtml_spec.rb spec/views/weathers/ > edit.rhtml_spec.rb spec/helpers/weathers_helper_spec.rb spec/views/ > weathers/index.rhtml_spec.rb > invalid option: -O > Test::Unit automatic runner. > > I also have the TDD screencast and I am able to run autotest with > no problems: > D:\ruby\projects\journal_app>autotest > loading autotest/rails > c:\ruby\bin\ruby -rrubygems -e "require 'redgreen'" -I.;lib;test - > rtest/unit -e "%w[test/functional/journals_controller_test.rb test/ > integration/journal_stories_test.rb test/unit/journal_test.rb].each > { |f| require f }" | unit_diff -u > Loaded suite -e > Started > ................ > Finished in 1.265 seconds. > 16 tests, 33 assertions, 0 failures, 0 errors > > Note: I am running Rails 1.2.3 and ZenTest v 3.6.1 on a Windows > machine (sad, I know, but we've discussed that already). > > When I run 'ruby script/spec -v' it says: > RSpec-1.0.5 (r2081) - BDD for Ruby > > I've also tried installing the newest version of the rSpec plugins > and running "ruby script/generate rspec" so the proper files are > copied to the script folder. > > as a "hack" fix, I did this: > 1) I removed my .autotest file completely (so no fun red/green/etc) > 2) I modified plugins>rspec >lib>autotest> rspec.rb and removed "# > {add_options_if_present}" from line 50 > > Anyone know of what my problem may be? Windows perhaps? It would > sure be nice to be able to keep my .autotest file... > Thanks for any help you can provide! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Aug 8 18:10:19 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Aug 2007 17:10:19 -0500 Subject: [rspec-users] Can't seem to spec a ActiveRecord::RecordInvalid exception properly... In-Reply-To: <7e565b5c0708081408q474ac9e9m729143cc86ddaab7@mail.gmail.com> References: <7e565b5c0708081408q474ac9e9m729143cc86ddaab7@mail.gmail.com> Message-ID: <57c63afe0708081510n53f725edu9aac14b9457a403a@mail.gmail.com> On 8/8/07, Fischer, Daniel wrote: > 1 def create > 2 @user = User.new(params[:user]) > 3 @user.save! > 4 self.current_user = @user > 5 redirect_to user_path(@user) > 6 flash[:notice] = "Thanks for signing up!" > 7 rescue ActiveRecord::RecordInvalid > 8 render :action => 'new' > 9 end Try this: describe "/users/create" do before(:each) do User.stub!(:new).and_return(@user = mock_model(User)) end it "should redirect to show on successful save" do @user.should_receive(:save!) post :create response.should redirect_to(user_path(@user)) end it "should re-render new on failed save" do @user.should_receive(:save!).and_raise(ActiveRecord::RecordInvalid.new(@user)) post :create response.should render_template('new') end end Cheers, David > > I can't seem to properly spec this out. I am trying numerous things, the > latest one is this, which makes sense but it still fails... > > > it "should re-render new on an invalid record exception" do > post :create, :user => {:login => nil} > response.should render_template(:new) > end > > should re-render new on an invalid record exception > expected "new", got nil > > Any help would be great, thanks! > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Aug 8 18:53:16 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Aug 2007 17:53:16 -0500 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <49f64a900708081146w6564983dhed18d215ef91d727@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708080807k6a8f13ecu435b97c24bd73207@mail.gmail.com> <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> <49f64a900708081146w6564983dhed18d215ef91d727@mail.gmail.com> Message-ID: <57c63afe0708081553w73a5d5afme2d851a3179fe343@mail.gmail.com> On 8/8/07, Lance Carlson wrote: > I just visited the action in my browser and i don't get any errors. I > am also running on edge rails as the application relies on > ActiveResource. Can you show me the code you created? OK - I've created a small project and am able to reproduce the behaviour you're describing. I'll follow up when learn something. David From lancecarlson at gmail.com Wed Aug 8 18:56:43 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Wed, 8 Aug 2007 18:56:43 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <57c63afe0708081553w73a5d5afme2d851a3179fe343@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708080807k6a8f13ecu435b97c24bd73207@mail.gmail.com> <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> <49f64a900708081146w6564983dhed18d215ef91d727@mail.gmail.com> <57c63afe0708081553w73a5d5afme2d851a3179fe343@mail.gmail.com> Message-ID: <49f64a900708081556s1454a8aey3feb2d937092083e@mail.gmail.com> Awesome! Thank you! :) On 8/8/07, David Chelimsky wrote: > On 8/8/07, Lance Carlson wrote: > > I just visited the action in my browser and i don't get any errors. I > > am also running on edge rails as the application relies on > > ActiveResource. Can you show me the code you created? > > OK - I've created a small project and am able to reproduce the > behaviour you're describing. I'll follow up when learn something. > > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nemo7467 at gmail.com Wed Aug 8 19:12:32 2007 From: nemo7467 at gmail.com (David Parker) Date: Wed, 8 Aug 2007 18:12:32 -0500 Subject: [rspec-users] rspec with autotest on a windows machine Message-ID: <9a07e4a80708081612s56ae814ax43e9caaa92eb59fb@mail.gmail.com> Scott, Yes, my spec.opts file contains the following: --colour --format progress --loadby mtime --reverse Thoughts? If this seems like too much of a hassle, or unknown, I should say that I plan on "upgrading" my windows machine to Ubuntu Linux in the next week or two... Thanks, David Parker >Do you have spec/spec.opts? > >Scott On Aug 8, 2007, at 5:25 PM, David Parker wrote: > Hello all, > I'm new to rSpec but after reading a couple of tutorials I've > become enamored. Anyway, I am at minute 42 of the rSpec basics > screencast ( peepcode.com) and I'm having the following error > running autotest w/rSpec: > D:\ruby\projects\forecaster > >autotest > loading autotest/rails_rspec > c:\ruby\bin\ruby -rrubygems -e "require 'redgreen'" -S script/spec > -O spec/spec.opts spec/models/weather_spec.rb spec/views/weathers/ > show.rhtml_spec.rb spec/controllers/weathers_controller_spec.rb > spec/views/weathers/new.rhtml_spec.rb spec/views/weathers/ > edit.rhtml_spec.rb spec/helpers/weathers_helper_spec.rb spec/views/ > weathers/index.rhtml_spec.rb > invalid option: -O > Test::Unit automatic runner. > > I also have the TDD screencast and I am able to run autotest with > no problems: > D:\ruby\projects\journal_app>autotest > loading autotest/rails > c:\ruby\bin\ruby -rrubygems -e "require 'redgreen'" -I.;lib;test - > rtest/unit -e "%w[test/functional/journals_controller_test.rb test/ > integration/journal_stories_test.rb test/unit/journal_test.rb].each > { |f| require f }" | unit_diff -u > Loaded suite -e > Started > ................ > Finished in 1.265 seconds. > 16 tests, 33 assertions, 0 failures, 0 errors > > Note: I am running Rails 1.2.3 and ZenTest v 3.6.1 on a Windows > machine (sad, I know, but we've discussed that already). > > When I run 'ruby script/spec -v' it says: > RSpec-1.0.5 (r2081) - BDD for Ruby > > I've also tried installing the newest version of the rSpec plugins > and running "ruby script/generate rspec" so the proper files are > copied to the script folder. > > as a "hack" fix, I did this: > 1) I removed my .autotest file completely (so no fun red/green/etc) > 2) I modified plugins>rspec >lib>autotest> rspec.rb and removed "# > {add_options_if_present}" from line 50 > > Anyone know of what my problem may be? Windows perhaps? It would > sure be nice to be able to keep my .autotest file... > Thanks for any help you can provide! -- dp -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070808/962a6026/attachment.html From dchelimsky at gmail.com Wed Aug 8 22:35:34 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Aug 2007 21:35:34 -0500 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <49f64a900708081556s1454a8aey3feb2d937092083e@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708080807k6a8f13ecu435b97c24bd73207@mail.gmail.com> <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> <49f64a900708081146w6564983dhed18d215ef91d727@mail.gmail.com> <57c63afe0708081553w73a5d5afme2d851a3179fe343@mail.gmail.com> <49f64a900708081556s1454a8aey3feb2d937092083e@mail.gmail.com> Message-ID: <57c63afe0708081935x21e68a7ey74335c0129149325@mail.gmail.com> On 8/8/07, Lance Carlson wrote: > Awesome! Thank you! :) Don't thank me yet. I've spent some time trying to track this down and I've found my way into some methods in routing.rb that are dynamically generated (and so you can't )(*&)(*& read them to debug them quite so easily) that call the methods (in your case) label_id_value and id_value (being the artist id). I have no idea yet where those two methods get generated. Once I do, then we can stub them. Unfortunately I can't really spend any more time on this right now (though I'd love to solve it). In the mean time, you'll just have to use the parameters if you want the specs to work with the same code with which your app works. > > On 8/8/07, David Chelimsky wrote: > > On 8/8/07, Lance Carlson wrote: > > > I just visited the action in my browser and i don't get any errors. I > > > am also running on edge rails as the application relies on > > > ActiveResource. Can you show me the code you created? > > > > OK - I've created a small project and am able to reproduce the > > behaviour you're describing. I'll follow up when learn something. > > > > David > > _______________________________________________ > > 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 22:48:43 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Aug 2007 21:48:43 -0500 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: <57c63afe0708081948k6d5f8019p27ffcb055f18d0c4@mail.gmail.com> 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". I don't think this will be the one and only book to solve that problem, but you should know that Aslak and I are working on an RSpec/BDD book as well. There are still some things being worked out, which is why I haven't really been spouting about it yet, but you can expect to be hearing quite a bit about it within the next few weeks. From dchelimsky at gmail.com Wed Aug 8 22:52:00 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Aug 2007 21:52:00 -0500 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: <57c63afe0708081952o51db239em66152a01823268a8@mail.gmail.com> On 8/8/07, Ashley Moran wrote: > 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". Have you read this one? http://www.amazon.com/Software-Development-Principles-Patterns-Practices/dp/0135974445/ref=pd_bbs_sr_1/002-7438072-0005646?ie=UTF8&s=books&qid=1186627780&sr=8-1 It pre-dates the BDD discussion, but is packed with very relevant material. From kevwil at gmail.com Wed Aug 8 22:52:52 2007 From: kevwil at gmail.com (Kevin Williams) Date: Wed, 8 Aug 2007 20:52:52 -0600 Subject: [rspec-users] RSpec book? In-Reply-To: <57c63afe0708081948k6d5f8019p27ffcb055f18d0c4@mail.gmail.com> References: <0ECB23AC-0DAF-41E6-B1C0-5F81D002AA58@ashleymoran.me.uk> <57c63afe0708081948k6d5f8019p27ffcb055f18d0c4@mail.gmail.com> Message-ID: <683a886f0708081952o53a31e71m4fcd79eaf3529b1c@mail.gmail.com> Cool. The more exposure we can give BDD/RSpec, the better. I'll probably read both. :) On 8/8/07, David Chelimsky wrote: > 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". > > I don't think this will be the one and only book to solve that > problem, but you should know that Aslak and I are working on an > RSpec/BDD book as well. There are still some things being worked out, > which is why I haven't really been spouting about it yet, but you can > expect to be hearing quite a bit about it within the next few weeks. > _______________________________________________ > 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 znmeb at cesmail.net Thu Aug 9 00:00:58 2007 From: znmeb at cesmail.net (M. Edward (Ed) Borasky) Date: Wed, 08 Aug 2007 21:00:58 -0700 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: <46BA917A.6090503@cesmail.net> Ashley Moran wrote: > 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". I have two copies, but as far as I know it's still in print. If you can't find it, let me know -- I'll trade you for your copy of the magic book that tells you how to make money giving programming expertise away. :) From obiefernandez at gmail.com Thu Aug 9 01:09:13 2007 From: obiefernandez at gmail.com (Obie Fernandez) Date: Thu, 9 Aug 2007 01:09:13 -0400 Subject: [rspec-users] RSpec book? In-Reply-To: <46BA917A.6090503@cesmail.net> References: <0ECB23AC-0DAF-41E6-B1C0-5F81D002AA58@ashleymoran.me.uk> <46BA917A.6090503@cesmail.net> Message-ID: <8bf510930708082209w65b186ebl67e44155efc6e9e2@mail.gmail.com> I'm including a chapter about RSpec and its Rails plugin in my book, The Rails Way. It'll be out in October. I'm also rallying for an RSpec book to be added to our Professional Ruby Series at Addison-Wesley. Stay tuned for more on that. -- Obie Fernandez http://jroller.com/obie/ Pre-order my book The Rails Way today! http://www.amazon.com/dp/0321445619 From smingins at elctech.com Thu Aug 9 01:14:18 2007 From: smingins at elctech.com (Shane Mingins) Date: Thu, 9 Aug 2007 17:14:18 +1200 Subject: [rspec-users] RSpec book? In-Reply-To: <8bf510930708082209w65b186ebl67e44155efc6e9e2@mail.gmail.com> References: <0ECB23AC-0DAF-41E6-B1C0-5F81D002AA58@ashleymoran.me.uk> <46BA917A.6090503@cesmail.net> <8bf510930708082209w65b186ebl67e44155efc6e9e2@mail.gmail.com> Message-ID: Hi Obie I am patiently waiting for October as I am really look forward to this book! Cheers Shane On 9/08/2007, at 5:09 PM, Obie Fernandez wrote: > I'm including a chapter about RSpec and its Rails plugin in my book, > The Rails Way. It'll be out in October. I'm also rallying for an RSpec > book to be added to our Professional Ruby Series at Addison-Wesley. > Stay tuned for more on that. > > -- > Obie Fernandez > http://jroller.com/obie/ > > Pre-order my book The Rails Way today! > http://www.amazon.com/dp/0321445619 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070809/ee57b554/attachment-0001.html From obiefernandez at gmail.com Thu Aug 9 01:35:21 2007 From: obiefernandez at gmail.com (Obie Fernandez) Date: Thu, 9 Aug 2007 01:35:21 -0400 Subject: [rspec-users] Any liberally-licensed open source projects out there that make good use of RSpec? In-Reply-To: References: <8bf510930707301948r36e2fbb7t7062175829eed85e@mail.gmail.com> Message-ID: <8bf510930708082235r2d521deg7dc35ee324a06915@mail.gmail.com> Thanks, Scott. Checking it out now. On 7/31/07, Scott Taylor wrote: > > I've just started DatedBackup (an rsnapshot-like utility), which has > about 500 LOC at the moment. It is licensed under the GPL, and has > 190 example specs. If you are interested, download the trunk from > Rubyforge: > > svn checkout svn://rubyforge.org/var/svn/datedbackup/trunk/ > svn checkout http://datedbackup.rubyforge.org/svn/trunk/ > > It has a DSL baked in, which I know is up your alley. > > Of course, Rspec itself would probably be the model if you needed to > look at specs. > > Best Regards, > > > Scott > > On Jul 30, 2007, at 10:48 PM, Obie Fernandez wrote: > > > I'm trolling for example RSpec code. Any pointers appreciated. > > > > Cheers, > > Obie > > _______________________________________________ > > 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 > -- Obie Fernandez http://jroller.com/obie/ Pre-order my book The Rails Way today! http://www.amazon.com/dp/0321445619 From obiefernandez at gmail.com Thu Aug 9 01:39:01 2007 From: obiefernandez at gmail.com (Obie Fernandez) Date: Thu, 9 Aug 2007 01:39:01 -0400 Subject: [rspec-users] Any liberally-licensed open source projects out there that make good use of RSpec? In-Reply-To: References: <8bf510930707301948r36e2fbb7t7062175829eed85e@mail.gmail.com> Message-ID: <8bf510930708082239h4636fb24idc3f0a25d93da02c@mail.gmail.com> Any idea if it's kosher to include snippets of GPL'd code in a commercial publication? MIT license is no problem, but the GPL makes me nervous about that. On 7/31/07, Scott Taylor wrote: > > I've just started DatedBackup (an rsnapshot-like utility), which has > about 500 LOC at the moment. It is licensed under the GPL, and has > 190 example specs. If you are interested, download the trunk from > Rubyforge: > > svn checkout svn://rubyforge.org/var/svn/datedbackup/trunk/ > svn checkout http://datedbackup.rubyforge.org/svn/trunk/ > > It has a DSL baked in, which I know is up your alley. > > Of course, Rspec itself would probably be the model if you needed to > look at specs. > > Best Regards, > > > Scott > > On Jul 30, 2007, at 10:48 PM, Obie Fernandez wrote: > > > I'm trolling for example RSpec code. Any pointers appreciated. > > > > Cheers, > > Obie > > _______________________________________________ > > 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 > -- Obie Fernandez http://jroller.com/obie/ Pre-order my book The Rails Way today! http://www.amazon.com/dp/0321445619 From has.sox at gmail.com Thu Aug 9 01:39:43 2007 From: has.sox at gmail.com (Daniel N) Date: Thu, 9 Aug 2007 15:39:43 +1000 Subject: [rspec-users] Any liberally-licensed open source projects out there that make good use of RSpec? In-Reply-To: <8bf510930708082235r2d521deg7dc35ee324a06915@mail.gmail.com> References: <8bf510930707301948r36e2fbb7t7062175829eed85e@mail.gmail.com> <8bf510930708082235r2d521deg7dc35ee324a06915@mail.gmail.com> Message-ID: <2fff50390708082239v7fb99e52kb694aa938b887992@mail.gmail.com> On 8/9/07, Obie Fernandez wrote: > > Thanks, Scott. Checking it out now. > > On 7/31/07, Scott Taylor wrote: > > > > I've just started DatedBackup (an rsnapshot-like utility), which has > > about 500 LOC at the moment. It is licensed under the GPL, and has > > 190 example specs. If you are interested, download the trunk from > > Rubyforge: > > > > svn checkout svn://rubyforge.org/var/svn/datedbackup/trunk/ > > svn checkout http://datedbackup.rubyforge.org/svn/trunk/ > > > > It has a DSL baked in, which I know is up your alley. > > > > Of course, Rspec itself would probably be the model if you needed to > > look at specs. > > > > Best Regards, > > > > > > Scott > > > > On Jul 30, 2007, at 10:48 PM, Obie Fernandez wrote: > > > > > I'm trolling for example RSpec code. Any pointers appreciated. > > > > > > Cheers, > > > Obie > > > _______________________________________________ > > > 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 > > > > > -- > Obie Fernandez > http://jroller.com/obie/ Merb writes it's spec in rspec. merb.devjavu.com I don't know that they're best practice but there are a few different styles amongst the specs HTH Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070809/2c4da0cd/attachment.html From mailing_lists at railsnewbie.com Thu Aug 9 03:55:01 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 9 Aug 2007 03:55:01 -0400 Subject: [rspec-users] rspec with autotest on a windows machine In-Reply-To: <9a07e4a80708081612s56ae814ax43e9caaa92eb59fb@mail.gmail.com> References: <9a07e4a80708081612s56ae814ax43e9caaa92eb59fb@mail.gmail.com> Message-ID: Well, I can tell you that you *won't* need the --loadby, and -- reverse switches if using autotest. Does the command generated by autotest run ok on your DOS command line? Scott On Aug 8, 2007, at 7:12 PM, David Parker wrote: > Scott, > > Yes, my spec.opts file contains the following: > --colour > --format > progress > --loadby > mtime > --reverse > > Thoughts? If this seems like too much of a hassle, or unknown, I > should say that I plan on "upgrading" my windows machine to Ubuntu > Linux in the next week or two... > > Thanks, > > David Parker > > > >Do you have spec/spec.opts? > > > >Scott > > > On Aug 8, 2007, at 5:25 PM, David Parker wrote: > > > Hello all, > > I'm new to rSpec but after reading a couple of tutorials I've > > become enamored. Anyway, I am at minute 42 of the rSpec basics > > screencast ( peepcode.com) and I'm having the following error > > running autotest w/rSpec: > > D:\ruby\projects\forecaster > > >autotest > > loading autotest/rails_rspec > > c:\ruby\bin\ruby -rrubygems -e "require 'redgreen'" -S script/spec > > -O spec/spec.opts spec/models/weather_spec.rb spec/views/weathers/ > > show.rhtml_spec.rb spec/controllers/weathers > _controller_spec.rb > > spec/views/weathers/new.rhtml_spec.rb spec/views/weathers/ > > edit.rhtml_spec.rb spec/helpers/weathers_helper_spec.rb spec/views/ > > weathers/index.rhtml_spec.rb > > invalid option: -O > > Test::Unit automatic runner. > > > > I also have the TDD screencast and I am able to run autotest with > > no problems: > > D:\ruby\projects\journal_app>autotest > > loading autotest/rails > > c:\ruby\bin\ruby -rrubygems -e "require 'redgreen'" -I.;lib;test - > > rtest/unit -e "%w[test/functional/journals_controller_test.rb test/ > > integration/journal_stories_test.rb test/unit/journal_test.rb].each > > { |f| require f }" | unit_diff -u > > Loaded suite -e > > Started > > ................ > > Finished in 1.265 seconds. > > 16 tests, 33 assertions, 0 failures, 0 errors > > > > Note: I am running Rails 1.2.3 and ZenTest v 3.6.1 on a Windows > > machine (sad, I know, but we've discussed that already). > > > > When I run 'ruby script/spec -v' it says: > > RSpec-1.0.5 (r2081) - BDD for Ruby > > > > I've also tried installing the newest version of the rSpec plugins > > and running "ruby script/generate rspec" so the proper files are > > copied to the script folder. > > > > as a "hack" fix, I did this: > > 1) I removed my .autotest file completely (so no fun red/green/etc) > > 2) I modified plugins>rspec >lib>autotest> rspec.rb and removed "# > > {add_options_if_present}" from line 50 > > > > Anyone know of what my problem may be? Windows perhaps? It would > > sure be nice to be able to keep my .autotest file... > > Thanks for any help you can provide! > > > -- > > dp > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Thu Aug 9 05:33:58 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 9 Aug 2007 11:33:58 +0200 Subject: [rspec-users] Any liberally-licensed open source projects out there that make good use of RSpec? In-Reply-To: <8bf510930708082239h4636fb24idc3f0a25d93da02c@mail.gmail.com> References: <8bf510930707301948r36e2fbb7t7062175829eed85e@mail.gmail.com> <8bf510930708082239h4636fb24idc3f0a25d93da02c@mail.gmail.com> Message-ID: <8d961d900708090233o510d00dah574ec305f582beb5@mail.gmail.com> Hi Obie! Check out Rubinius and Gecode/R (and RSpec hehe) On 8/9/07, Obie Fernandez wrote: > Any idea if it's kosher to include snippets of GPL'd code in a > commercial publication? MIT license is no problem, but the GPL makes > me nervous about that. > I, personally, wouldn't want to put a virus in my book, but IANAL. Aslak > On 7/31/07, Scott Taylor wrote: > > > > I've just started DatedBackup (an rsnapshot-like utility), which has > > about 500 LOC at the moment. It is licensed under the GPL, and has > > 190 example specs. If you are interested, download the trunk from > > Rubyforge: > > > > svn checkout svn://rubyforge.org/var/svn/datedbackup/trunk/ > > svn checkout http://datedbackup.rubyforge.org/svn/trunk/ > > > > It has a DSL baked in, which I know is up your alley. > > > > Of course, Rspec itself would probably be the model if you needed to > > look at specs. > > > > Best Regards, > > > > > > Scott > > > > On Jul 30, 2007, at 10:48 PM, Obie Fernandez wrote: > > > > > I'm trolling for example RSpec code. Any pointers appreciated. > > > > > > Cheers, > > > Obie > > > _______________________________________________ > > > 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 > > > > > -- > Obie Fernandez > http://jroller.com/obie/ > > Pre-order my book The Rails Way today! > http://www.amazon.com/dp/0321445619 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Thu Aug 9 06:36:37 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 9 Aug 2007 06:36:37 -0400 Subject: [rspec-users] Any liberally-licensed open source projects out there that make good use of RSpec? In-Reply-To: <8d961d900708090233o510d00dah574ec305f582beb5@mail.gmail.com> References: <8bf510930707301948r36e2fbb7t7062175829eed85e@mail.gmail.com> <8bf510930708082239h4636fb24idc3f0a25d93da02c@mail.gmail.com> <8d961d900708090233o510d00dah574ec305f582beb5@mail.gmail.com> Message-ID: <520E60AC-35CA-4B46-8E9B-16BFE33E5260@railsnewbie.com> On Aug 9, 2007, at 5:33 AM, aslak hellesoy wrote: > Hi Obie! > > Check out Rubinius and Gecode/R (and RSpec hehe) > I would second Rubinius, because it would considerably lessen the learning curve for some one new to RSpec. > On 8/9/07, Obie Fernandez wrote: >> Any idea if it's kosher to include snippets of GPL'd code in a >> commercial publication? MIT license is no problem, but the GPL makes >> me nervous about that. >> > > I, personally, wouldn't want to put a virus in my book, but IANAL. A virus? Strong words, Aslak. On another note, this book aside: Why is *all* the Ruby code out there licensed under MIT, and not GPL'ed or dual licensed? Scott From justnothing at tiscali.co.uk Thu Aug 9 07:07:31 2007 From: justnothing at tiscali.co.uk (David Green) Date: Thu, 9 Aug 2007 04:07:31 -0700 (PDT) Subject: [rspec-users] reusable specs - almost there In-Reply-To: <57c63afe0708051452h3a4e4013saae007fd30c2c68a@mail.gmail.com> References: <11996399.post@talk.nabble.com> <57c63afe0708050857x61afe07aiedafcea9f4961698@mail.gmail.com> <12007548.post@talk.nabble.com> <57c63afe0708051452h3a4e4013saae007fd30c2c68a@mail.gmail.com> Message-ID: <12070479.post@talk.nabble.com> David Chelimsky-2 wrote: > > 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? > > I spent some time refactoring and I'm at happy with the stage I'm at now. as per your suggestion, I extracted common code and now only test it in one controller. In situations where it isn't practical to extract code, I'm still using shared behaviour but setting instance variables in before() to customize the specs slightly. I've pretty much given up on dynamically generating specs. as for improving rspec, I think it would be a great feature if shared behaviours could accept parameters, which are available both inside and outside examples. Then you could do things like: describe "a standard create action", :shared => true do it "should instantiate a new #{target_class} object called #{target_name}" do get :create assigns[target_name].should be_instance_of(target_class) end end I can accomplish the same by setting @target_name and @target_class instance variables, but it would be nice if the example titles could include those values too. thanks for all your help dave -- View this message in context: http://www.nabble.com/reusable-specs---almost-there-tf4216708.html#a12070479 Sent from the rspec-users mailing list archive at Nabble.com. From mailing_lists at railsnewbie.com Thu Aug 9 07:57:00 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 9 Aug 2007 07:57:00 -0400 Subject: [rspec-users] Any liberally-licensed open source projects out there that make good use of RSpec? In-Reply-To: <8d961d900708090233o510d00dah574ec305f582beb5@mail.gmail.com> References: <8bf510930707301948r36e2fbb7t7062175829eed85e@mail.gmail.com> <8bf510930708082239h4636fb24idc3f0a25d93da02c@mail.gmail.com> <8d961d900708090233o510d00dah574ec305f582beb5@mail.gmail.com> Message-ID: On Aug 9, 2007, at 5:33 AM, aslak hellesoy wrote: > Hi Obie! > > Check out Rubinius and Gecode/R (and RSpec hehe) > > On 8/9/07, Obie Fernandez wrote: >> Any idea if it's kosher to include snippets of GPL'd code in a >> commercial publication? MIT license is no problem, but the GPL makes >> me nervous about that. >> > > I, personally, wouldn't want to put a virus in my book, but IANAL. This seems to cover it (at least in the US): http://www.gnu.org/licenses/gpl-faq.html#SourceCodeInDocumentation http://en.wikipedia.org/wiki/Fair_Use Scott From rspec.user at gmail.com Thu Aug 9 19:44:10 2007 From: rspec.user at gmail.com (sinclair bain) Date: Thu, 9 Aug 2007 19:44:10 -0400 Subject: [rspec-users] AutoTest plugin and rspec for rails Message-ID: <2ca660dd0708091644v27397e2bpaa8187ca36381276@mail.gmail.com> (WinXP) Hi, I have the autotest rails plugin running - detecting changes and running the examples. However the rspec color output (of which I am a fan) ... has stopped happening Anybody got a spare moment to point me in the right direction, please ? Cheers! sinclair -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070809/2331a41a/attachment.html From dchelimsky at gmail.com Thu Aug 9 19:47:56 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Aug 2007 18:47:56 -0500 Subject: [rspec-users] AutoTest plugin and rspec for rails In-Reply-To: <2ca660dd0708091644v27397e2bpaa8187ca36381276@mail.gmail.com> References: <2ca660dd0708091644v27397e2bpaa8187ca36381276@mail.gmail.com> Message-ID: <57c63afe0708091647w1fb65279k4c164638e795480b@mail.gmail.com> On 8/9/07, sinclair bain wrote: > (WinXP) > Hi, > > I have the autotest rails plugin running - detecting changes and running the > examples. > > However the rspec color output (of which I am a fan) ... has stopped > happening > > Anybody got a spare moment to point me in the right direction, please ? You need a spec/spec.opts file with the following: --colour Is that in place? Also, what versions of everything are you using? > > Cheers! > sinclair > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lancecarlson at gmail.com Thu Aug 9 20:11:49 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Thu, 9 Aug 2007 20:11:49 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <57c63afe0708081935x21e68a7ey74335c0129149325@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> <49f64a900708081146w6564983dhed18d215ef91d727@mail.gmail.com> <57c63afe0708081553w73a5d5afme2d851a3179fe343@mail.gmail.com> <49f64a900708081556s1454a8aey3feb2d937092083e@mail.gmail.com> <57c63afe0708081935x21e68a7ey74335c0129149325@mail.gmail.com> Message-ID: <49f64a900708091711m5d4c4b62s811b50e957bbe092@mail.gmail.com> Were you able to come up with any solutions? On 8/8/07, David Chelimsky wrote: > On 8/8/07, Lance Carlson wrote: > > Awesome! Thank you! :) > > Don't thank me yet. I've spent some time trying to track this down and > I've found my way into some methods in routing.rb that are dynamically > generated (and so you can't )(*&)(*& read them to debug them quite so > easily) that call the methods (in your case) label_id_value and > id_value (being the artist id). I have no idea yet where those two > methods get generated. Once I do, then we can stub them. Unfortunately > I can't really spend any more time on this right now (though I'd love > to solve it). > > In the mean time, you'll just have to use the parameters if you want > the specs to work with the same code with which your app works. > > > > > > On 8/8/07, David Chelimsky wrote: > > > On 8/8/07, Lance Carlson wrote: > > > > I just visited the action in my browser and i don't get any errors. I > > > > am also running on edge rails as the application relies on > > > > ActiveResource. Can you show me the code you created? > > > > > > OK - I've created a small project and am able to reproduce the > > > behaviour you're describing. I'll follow up when learn something. > > > > > > David > > > _______________________________________________ > > > 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 9 20:16:34 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Aug 2007 19:16:34 -0500 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <49f64a900708091711m5d4c4b62s811b50e957bbe092@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> <49f64a900708081146w6564983dhed18d215ef91d727@mail.gmail.com> <57c63afe0708081553w73a5d5afme2d851a3179fe343@mail.gmail.com> <49f64a900708081556s1454a8aey3feb2d937092083e@mail.gmail.com> <57c63afe0708081935x21e68a7ey74335c0129149325@mail.gmail.com> <49f64a900708091711m5d4c4b62s811b50e957bbe092@mail.gmail.com> Message-ID: <57c63afe0708091716u70a2f998j43fed817f6fe0f27@mail.gmail.com> On 8/9/07, Lance Carlson wrote: > Were you able to come up with any solutions? Nope. Anyone else? > > On 8/8/07, David Chelimsky wrote: > > On 8/8/07, Lance Carlson wrote: > > > Awesome! Thank you! :) > > > > Don't thank me yet. I've spent some time trying to track this down and > > I've found my way into some methods in routing.rb that are dynamically > > generated (and so you can't )(*&)(*& read them to debug them quite so > > easily) that call the methods (in your case) label_id_value and > > id_value (being the artist id). I have no idea yet where those two > > methods get generated. Once I do, then we can stub them. Unfortunately > > I can't really spend any more time on this right now (though I'd love > > to solve it). > > > > In the mean time, you'll just have to use the parameters if you want > > the specs to work with the same code with which your app works. > > > > > > > > > > On 8/8/07, David Chelimsky wrote: > > > > On 8/8/07, Lance Carlson wrote: > > > > > I just visited the action in my browser and i don't get any errors. I > > > > > am also running on edge rails as the application relies on > > > > > ActiveResource. Can you show me the code you created? > > > > > > > > OK - I've created a small project and am able to reproduce the > > > > behaviour you're describing. I'll follow up when learn something. > > > > > > > > David > > > > _______________________________________________ > > > > 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 lancecarlson at gmail.com Thu Aug 9 20:21:05 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Thu, 9 Aug 2007 20:21:05 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <57c63afe0708091716u70a2f998j43fed817f6fe0f27@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> <49f64a900708081146w6564983dhed18d215ef91d727@mail.gmail.com> <57c63afe0708081553w73a5d5afme2d851a3179fe343@mail.gmail.com> <49f64a900708081556s1454a8aey3feb2d937092083e@mail.gmail.com> <57c63afe0708081935x21e68a7ey74335c0129149325@mail.gmail.com> <49f64a900708091711m5d4c4b62s811b50e957bbe092@mail.gmail.com> <57c63afe0708091716u70a2f998j43fed817f6fe0f27@mail.gmail.com> Message-ID: <49f64a900708091721x4c7e0beeqf6febb40a7845192@mail.gmail.com> Is it possible that rspec is not pulling the instance variables into the method because this method is being defined before instance variables in parameters are assigned to that method? I'm trying to hone down where the problem is popping up exactly. Any insight? On 8/9/07, David Chelimsky wrote: > On 8/9/07, Lance Carlson wrote: > > Were you able to come up with any solutions? > > Nope. Anyone else? > > > > > On 8/8/07, David Chelimsky wrote: > > > On 8/8/07, Lance Carlson wrote: > > > > Awesome! Thank you! :) > > > > > > Don't thank me yet. I've spent some time trying to track this down and > > > I've found my way into some methods in routing.rb that are dynamically > > > generated (and so you can't )(*&)(*& read them to debug them quite so > > > easily) that call the methods (in your case) label_id_value and > > > id_value (being the artist id). I have no idea yet where those two > > > methods get generated. Once I do, then we can stub them. Unfortunately > > > I can't really spend any more time on this right now (though I'd love > > > to solve it). > > > > > > In the mean time, you'll just have to use the parameters if you want > > > the specs to work with the same code with which your app works. > > > > > > > > > > > > > > On 8/8/07, David Chelimsky wrote: > > > > > On 8/8/07, Lance Carlson wrote: > > > > > > I just visited the action in my browser and i don't get any errors. I > > > > > > am also running on edge rails as the application relies on > > > > > > ActiveResource. Can you show me the code you created? > > > > > > > > > > OK - I've created a small project and am able to reproduce the > > > > > behaviour you're describing. I'll follow up when learn something. > > > > > > > > > > David > > > > > _______________________________________________ > > > > > 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 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Aug 9 20:31:14 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Aug 2007 19:31:14 -0500 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <49f64a900708091721x4c7e0beeqf6febb40a7845192@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> <49f64a900708081146w6564983dhed18d215ef91d727@mail.gmail.com> <57c63afe0708081553w73a5d5afme2d851a3179fe343@mail.gmail.com> <49f64a900708081556s1454a8aey3feb2d937092083e@mail.gmail.com> <57c63afe0708081935x21e68a7ey74335c0129149325@mail.gmail.com> <49f64a900708091711m5d4c4b62s811b50e957bbe092@mail.gmail.com> <57c63afe0708091716u70a2f998j43fed817f6fe0f27@mail.gmail.com> <49f64a900708091721x4c7e0beeqf6febb40a7845192@mail.gmail.com> Message-ID: <57c63afe0708091731h37fc80a7qa5f1cff16bbd7549@mail.gmail.com> On 8/9/07, Lance Carlson wrote: > Is it possible that rspec is not pulling the instance variables into > the method because this method is being defined before instance > variables in parameters are assigned to that method? I'm trying to > hone down where the problem is popping up exactly. Any insight? Not really more than what I said earlier in this thread. > On 8/9/07, David Chelimsky wrote: > > On 8/9/07, Lance Carlson wrote: > > > Were you able to come up with any solutions? > > > > Nope. Anyone else? > > > > > > > > On 8/8/07, David Chelimsky wrote: > > > > On 8/8/07, Lance Carlson wrote: > > > > > Awesome! Thank you! :) > > > > > > > > Don't thank me yet. I've spent some time trying to track this down and > > > > I've found my way into some methods in routing.rb that are dynamically > > > > generated (and so you can't )(*&)(*& read them to debug them quite so > > > > easily) that call the methods (in your case) label_id_value and > > > > id_value (being the artist id). I have no idea yet where those two > > > > methods get generated. Once I do, then we can stub them. Unfortunately > > > > I can't really spend any more time on this right now (though I'd love > > > > to solve it). > > > > > > > > In the mean time, you'll just have to use the parameters if you want > > > > the specs to work with the same code with which your app works. > > > > > > > > > > > > > > > > > > On 8/8/07, David Chelimsky wrote: > > > > > > On 8/8/07, Lance Carlson wrote: > > > > > > > I just visited the action in my browser and i don't get any errors. I > > > > > > > am also running on edge rails as the application relies on > > > > > > > ActiveResource. Can you show me the code you created? > > > > > > > > > > > > OK - I've created a small project and am able to reproduce the > > > > > > behaviour you're describing. I'll follow up when learn something. > > > > > > > > > > > > David > > > > > > _______________________________________________ > > > > > > 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 > > > > > _______________________________________________ > > 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 lancecarlson at gmail.com Thu Aug 9 20:36:12 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Thu, 9 Aug 2007 20:36:12 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <57c63afe0708091731h37fc80a7qa5f1cff16bbd7549@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> <49f64a900708081146w6564983dhed18d215ef91d727@mail.gmail.com> <57c63afe0708081553w73a5d5afme2d851a3179fe343@mail.gmail.com> <49f64a900708081556s1454a8aey3feb2d937092083e@mail.gmail.com> <57c63afe0708081935x21e68a7ey74335c0129149325@mail.gmail.com> <49f64a900708091711m5d4c4b62s811b50e957bbe092@mail.gmail.com> <57c63afe0708091716u70a2f998j43fed817f6fe0f27@mail.gmail.com> <49f64a900708091721x4c7e0beeqf6febb40a7845192@mail.gmail.com> <57c63afe0708091731h37fc80a7qa5f1cff16bbd7549@mail.gmail.com> Message-ID: <49f64a900708091736x4b71f847je4dd001081b145e3@mail.gmail.com> About these methods requiring arguments? I thought you were able to reproduce the problems I was having and was also able to reproduce a working application with no arguments. By default these methods should not require arguments to be passed as it is unnecessary noise in the code. Perhaps we can continue this discussion on IRC? #rspec? What is your s/n? On 8/9/07, David Chelimsky wrote: > On 8/9/07, Lance Carlson wrote: > > Is it possible that rspec is not pulling the instance variables into > > the method because this method is being defined before instance > > variables in parameters are assigned to that method? I'm trying to > > hone down where the problem is popping up exactly. Any insight? > > Not really more than what I said earlier in this thread. > > > On 8/9/07, David Chelimsky wrote: > > > On 8/9/07, Lance Carlson wrote: > > > > Were you able to come up with any solutions? > > > > > > Nope. Anyone else? > > > > > > > > > > > On 8/8/07, David Chelimsky wrote: > > > > > On 8/8/07, Lance Carlson wrote: > > > > > > Awesome! Thank you! :) > > > > > > > > > > Don't thank me yet. I've spent some time trying to track this down and > > > > > I've found my way into some methods in routing.rb that are dynamically > > > > > generated (and so you can't )(*&)(*& read them to debug them quite so > > > > > easily) that call the methods (in your case) label_id_value and > > > > > id_value (being the artist id). I have no idea yet where those two > > > > > methods get generated. Once I do, then we can stub them. Unfortunately > > > > > I can't really spend any more time on this right now (though I'd love > > > > > to solve it). > > > > > > > > > > In the mean time, you'll just have to use the parameters if you want > > > > > the specs to work with the same code with which your app works. > > > > > > > > > > > > > > > > > > > > > > On 8/8/07, David Chelimsky wrote: > > > > > > > On 8/8/07, Lance Carlson wrote: > > > > > > > > I just visited the action in my browser and i don't get any errors. I > > > > > > > > am also running on edge rails as the application relies on > > > > > > > > ActiveResource. Can you show me the code you created? > > > > > > > > > > > > > > OK - I've created a small project and am able to reproduce the > > > > > > > behaviour you're describing. I'll follow up when learn something. > > > > > > > > > > > > > > David > > > > > > > _______________________________________________ > > > > > > > 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 > > > > > > > _______________________________________________ > > > 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 barjunk at attglobal.net Thu Aug 9 20:57:41 2007 From: barjunk at attglobal.net (barsalou) Date: Thu, 09 Aug 2007 16:57:41 -0800 Subject: [rspec-users] Using rcov and ouput to screen Message-ID: <20070809165741.haskmtz628sgg88w@lcgalaska.com> I'd like to output my rcov data to the screen in ascii instead of html...is that possible using the rake spec:rcov command? Also, is there somewhere that will allow me to search the mail archives...I'm pretty sure someone else has asked similar questions. Thanks for the help. Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From mailing_lists at railsnewbie.com Thu Aug 9 22:16:07 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 9 Aug 2007 22:16:07 -0400 Subject: [rspec-users] AutoTest plugin and rspec for rails In-Reply-To: <57c63afe0708091647w1fb65279k4c164638e795480b@mail.gmail.com> References: <2ca660dd0708091644v27397e2bpaa8187ca36381276@mail.gmail.com> <57c63afe0708091647w1fb65279k4c164638e795480b@mail.gmail.com> Message-ID: On Aug 9, 2007, at 7:47 PM, David Chelimsky wrote: > On 8/9/07, sinclair bain wrote: >> (WinXP) >> Hi, >> >> I have the autotest rails plugin running - detecting changes and >> running the >> examples. >> >> However the rspec color output (of which I am a fan) ... has stopped >> happening >> >> Anybody got a spare moment to point me in the right direction, >> please ? > > You need a spec/spec.opts file with the following: > > --colour > > Is that in place? Also, what versions of everything are you using? Also try running it would the --drb flag, if you are already using it. Scott From mailing_lists at railsnewbie.com Thu Aug 9 22:20:37 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 9 Aug 2007 22:20:37 -0400 Subject: [rspec-users] Using rcov and ouput to screen In-Reply-To: <20070809165741.haskmtz628sgg88w@lcgalaska.com> References: <20070809165741.haskmtz628sgg88w@lcgalaska.com> Message-ID: <82882AA6-F729-4431-AFCA-7FFEEA71CFF3@railsnewbie.com> On Aug 9, 2007, at 8:57 PM, barsalou wrote: > I'd like to output my rcov data to the screen in ascii instead of > html...is that possible using the rake spec:rcov command? Look at the RSpec gem's rdoc. I believe it is something like Rake::RcovTask. An option can be provided to give rcov options. Run rcov --help. > > Also, is there somewhere that will allow me to search the mail > archives...I'm pretty sure someone else has asked similar questions. > Google is your friend. Rubyforge also has the mailing lists, although they aren't searchable. Scott From rspec.user at gmail.com Thu Aug 9 22:33:12 2007 From: rspec.user at gmail.com (sinclair bain) Date: Thu, 9 Aug 2007 22:33:12 -0400 Subject: [rspec-users] AutoTest plugin and rspec for rails In-Reply-To: <57c63afe0708091647w1fb65279k4c164638e795480b@mail.gmail.com> References: <2ca660dd0708091644v27397e2bpaa8187ca36381276@mail.gmail.com> <57c63afe0708091647w1fb65279k4c164638e795480b@mail.gmail.com> Message-ID: <2ca660dd0708091933g6d0e9215p85c466a591835fb7@mail.gmail.com> Dave, Got that ... --colour --format progress ... The latest ... all installed today ... except rspec 4 rails it is 1.0. This was all going ok before I installed autotest (red, green and yellow). On 8/9/07, David Chelimsky wrote: > > On 8/9/07, sinclair bain wrote: > > (WinXP) > > Hi, > > > > I have the autotest rails plugin running - detecting changes and running > the > > examples. > > > > However the rspec color output (of which I am a fan) ... has stopped > > happening > > > > Anybody got a spare moment to point me in the right direction, please ? > > You need a spec/spec.opts file with the following: > > --colour > > Is that in place? Also, what versions of everything are you using? > > > > > > Cheers! > > sinclair > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070809/11ac6c99/attachment.html From jonathan at parkerhill.com Thu Aug 9 23:58:26 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Thu, 9 Aug 2007 23:58:26 -0400 Subject: [rspec-users] rspec and active_scaffold Message-ID: <71BA1C74-FFA3-4CBD-85D7-06E3511BE577@parkerhill.com> Hi, Anyone here have a link or tips for a complete spec for a dead simple active_scaffold controller, including its internal calls stubbed out which we could use as a starting point? thanks. linoj From ingo at ingoweiss.com Fri Aug 10 02:13:10 2007 From: ingo at ingoweiss.com (Ingo Weiss) Date: Fri, 10 Aug 2007 08:13:10 +0200 Subject: [rspec-users] fixture scenario builder In-Reply-To: <49f64a900708091711m5d4c4b62s811b50e957bbe092@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <49f64a900708080856n774a3da5m7c146c7fea1cf3cc@mail.gmail.com> <49f64a900708081050q5d926152k8eaaba820d9abee5@mail.gmail.com> <57c63afe0708081130x286c71eap17055ae66f3020f2@mail.gmail.com> <49f64a900708081138k6eff867dyf87199ca73df9591@mail.gmail.com> <57c63afe0708081141w4a309bd5kfae806dd4bd74d06@mail.gmail.com> <49f64a900708081146w6564983dhed18d215ef91d727@mail.gmail.com> <57c63afe0708081553w73a5d5afme2d851a3179fe343@mail.gmail.com> <49f64a900708081556s1454a8aey3feb2d937092083e@mail.gmail.com> <57c63afe0708081935x21e68a7ey74335c0129149325@mail.gmail.com> <49f64a900708091711m5d4c4b62s811b50e957bbe092@mail.gmail.com> Message-ID: <06791B70-D34E-4421-832A-9B816540817D@ingoweiss.com> Hi all, did anybody get 'fixture scenario builder' (http://errtheblog.com/post/ 7708) to work with rspec? I am getting the following error: ..../plugins/fixture_scenarios_builder/lib/scenario_builder.rb:8:in `scenario': undefined method `scenario' for main (NoMethodError) Ingo From win at wincent.com Fri Aug 10 05:18:55 2007 From: win at wincent.com (Wincent Colaiuta) Date: Fri, 10 Aug 2007 11:18:55 +0200 Subject: [rspec-users] FixtureScenarios Message-ID: <98472412-6026-4A7F-9EC3-15204ED84FB8@wincent.com> This may have turned up in the RSS feeds of many of you already, but for those who haven't seen it yet, looks intersting: > The main problem with fixtures, for me, has always been how unfun > they are. They literally suck the fun out of anything they?re > around. You throw them in your test/ directory, then suddenly > testing is, like, work. But it?s not work, dammit. This is Ruby, > dammit. > Cheers, Wincent From dchelimsky at gmail.com Fri Aug 10 08:04:15 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 10 Aug 2007 07:04:15 -0500 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <49f64a900708091736x4b71f847je4dd001081b145e3@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <49f64a900708081146w6564983dhed18d215ef91d727@mail.gmail.com> <57c63afe0708081553w73a5d5afme2d851a3179fe343@mail.gmail.com> <49f64a900708081556s1454a8aey3feb2d937092083e@mail.gmail.com> <57c63afe0708081935x21e68a7ey74335c0129149325@mail.gmail.com> <49f64a900708091711m5d4c4b62s811b50e957bbe092@mail.gmail.com> <57c63afe0708091716u70a2f998j43fed817f6fe0f27@mail.gmail.com> <49f64a900708091721x4c7e0beeqf6febb40a7845192@mail.gmail.com> <57c63afe0708091731h37fc80a7qa5f1cff16bbd7549@mail.gmail.com> <49f64a900708091736x4b71f847je4dd001081b145e3@mail.gmail.com> Message-ID: <57c63afe0708100504o78effbfeu6aed0f2aee09af2f@mail.gmail.com> On 8/9/07, Lance Carlson wrote: > About these methods requiring arguments? I thought you were able to > reproduce the problems I was having and was also able to reproduce a > working application with no arguments. That is correct. > By default these methods should > not require arguments to be passed as it is unnecessary noise in the > code. I understand that, but that was news to me as of this thread. I spent a couple of hours banging my head against this and found the generated code I mentioned earlier in the thread. That's the only insight I have to offer at this point. > Perhaps we can continue this discussion on IRC? #rspec? I'll pop in at one point this morning but I really don't have much in the way of cycles to spend on this right now. I'm happy to help point you in the right direction, but it's not very high on my priority list. In the mean time, now that we know this is a bug, would you kindly report it in the tracker? http://rubyforge.org/tracker/?atid=3149&group_id=797&func=browse > What is your s/n? > > On 8/9/07, David Chelimsky wrote: > > On 8/9/07, Lance Carlson wrote: > > > Is it possible that rspec is not pulling the instance variables into > > > the method because this method is being defined before instance > > > variables in parameters are assigned to that method? I'm trying to > > > hone down where the problem is popping up exactly. Any insight? > > > > Not really more than what I said earlier in this thread. > > > > > On 8/9/07, David Chelimsky wrote: > > > > On 8/9/07, Lance Carlson wrote: > > > > > Were you able to come up with any solutions? > > > > > > > > Nope. Anyone else? > > > > > > > > > > > > > > On 8/8/07, David Chelimsky wrote: > > > > > > On 8/8/07, Lance Carlson wrote: > > > > > > > Awesome! Thank you! :) > > > > > > > > > > > > Don't thank me yet. I've spent some time trying to track this down and > > > > > > I've found my way into some methods in routing.rb that are dynamically > > > > > > generated (and so you can't )(*&)(*& read them to debug them quite so > > > > > > easily) that call the methods (in your case) label_id_value and > > > > > > id_value (being the artist id). I have no idea yet where those two > > > > > > methods get generated. Once I do, then we can stub them. Unfortunately > > > > > > I can't really spend any more time on this right now (though I'd love > > > > > > to solve it). > > > > > > > > > > > > In the mean time, you'll just have to use the parameters if you want > > > > > > the specs to work with the same code with which your app works. > > > > > > > > > > > > > > > > > > > > > > > > > > On 8/8/07, David Chelimsky wrote: > > > > > > > > On 8/8/07, Lance Carlson wrote: > > > > > > > > > I just visited the action in my browser and i don't get any errors. I > > > > > > > > > am also running on edge rails as the application relies on > > > > > > > > > ActiveResource. Can you show me the code you created? > > > > > > > > > > > > > > > > OK - I've created a small project and am able to reproduce the > > > > > > > > behaviour you're describing. I'll follow up when learn something. > > > > > > > > > > > > > > > > David > > > > > > > > _______________________________________________ > > > > > > > > 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 > > > > > > > > > _______________________________________________ > > > > 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 lancecarlson at gmail.com Fri Aug 10 09:52:09 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Fri, 10 Aug 2007 09:52:09 -0400 Subject: [rspec-users] FixtureScenarios In-Reply-To: <98472412-6026-4A7F-9EC3-15204ED84FB8@wincent.com> References: <98472412-6026-4A7F-9EC3-15204ED84FB8@wincent.com> Message-ID: <49f64a900708100652l7fcfc08n85aafbabfd57ae77@mail.gmail.com> Thusfar, my experience with stubbing and mocking has not been a walk in the park either. Hopefully this will change when rspec's mocking and stubbing matures some more. Fixtures have always been a source of anger for many railers because they slow down tests, rely on the database and are hard to maintain. On 8/10/07, Wincent Colaiuta wrote: > This may have turned up in the RSS feeds of many of you already, but > for those who haven't seen it yet, looks intersting: > > > > > The main problem with fixtures, for me, has always been how unfun > > they are. They literally suck the fun out of anything they're > > around. You throw them in your test/ directory, then suddenly > > testing is, like, work. But it's not work, dammit. This is Ruby, > > dammit. > > > > Cheers, > Wincent > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Aug 10 10:01:07 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 10 Aug 2007 09:01:07 -0500 Subject: [rspec-users] FixtureScenarios In-Reply-To: <49f64a900708100652l7fcfc08n85aafbabfd57ae77@mail.gmail.com> References: <98472412-6026-4A7F-9EC3-15204ED84FB8@wincent.com> <49f64a900708100652l7fcfc08n85aafbabfd57ae77@mail.gmail.com> Message-ID: <57c63afe0708100701v4d37f169gc2c75cdfc750a8a5@mail.gmail.com> On 8/10/07, Lance Carlson wrote: > Thusfar, my experience with stubbing and mocking has not been a walk > in the park either. Hopefully this will change when rspec's mocking > and stubbing matures some more. Please elaborate. What new features are you expecting rspec's mocking framework to adopt? From lancecarlson at gmail.com Fri Aug 10 10:04:00 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Fri, 10 Aug 2007 10:04:00 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <57c63afe0708100504o78effbfeu6aed0f2aee09af2f@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <57c63afe0708081553w73a5d5afme2d851a3179fe343@mail.gmail.com> <49f64a900708081556s1454a8aey3feb2d937092083e@mail.gmail.com> <57c63afe0708081935x21e68a7ey74335c0129149325@mail.gmail.com> <49f64a900708091711m5d4c4b62s811b50e957bbe092@mail.gmail.com> <57c63afe0708091716u70a2f998j43fed817f6fe0f27@mail.gmail.com> <49f64a900708091721x4c7e0beeqf6febb40a7845192@mail.gmail.com> <57c63afe0708091731h37fc80a7qa5f1cff16bbd7549@mail.gmail.com> <49f64a900708091736x4b71f847je4dd001081b145e3@mail.gmail.com> <57c63afe0708100504o78effbfeu6aed0f2aee09af2f@mail.gmail.com> Message-ID: <49f64a900708100704pdf441een1cdf1dd8b49e007e@mail.gmail.com> Thanks for your patience trying to resolve this issue. I posted a bug report here: http://rubyforge.org/tracker/index.php?func=detail&aid=12963&group_id=797&atid=3149 On 8/10/07, David Chelimsky wrote: > On 8/9/07, Lance Carlson wrote: > > About these methods requiring arguments? I thought you were able to > > reproduce the problems I was having and was also able to reproduce a > > working application with no arguments. > > That is correct. > > > By default these methods should > > not require arguments to be passed as it is unnecessary noise in the > > code. > > I understand that, but that was news to me as of this thread. I spent > a couple of hours banging my head against this and found the generated > code I mentioned earlier in the thread. That's the only insight I have > to offer at this point. > > > Perhaps we can continue this discussion on IRC? #rspec? > > I'll pop in at one point this morning but I really don't have much in > the way of cycles to spend on this right now. I'm happy to help point > you in the right direction, but it's not very high on my priority > list. In the mean time, now that we know this is a bug, would you > kindly report it in the tracker? > > http://rubyforge.org/tracker/?atid=3149&group_id=797&func=browse > > > What is your s/n? > > > > On 8/9/07, David Chelimsky wrote: > > > On 8/9/07, Lance Carlson wrote: > > > > Is it possible that rspec is not pulling the instance variables into > > > > the method because this method is being defined before instance > > > > variables in parameters are assigned to that method? I'm trying to > > > > hone down where the problem is popping up exactly. Any insight? > > > > > > Not really more than what I said earlier in this thread. > > > > > > > On 8/9/07, David Chelimsky wrote: > > > > > On 8/9/07, Lance Carlson wrote: > > > > > > Were you able to come up with any solutions? > > > > > > > > > > Nope. Anyone else? > > > > > > > > > > > > > > > > > On 8/8/07, David Chelimsky wrote: > > > > > > > On 8/8/07, Lance Carlson wrote: > > > > > > > > Awesome! Thank you! :) > > > > > > > > > > > > > > Don't thank me yet. I've spent some time trying to track this down and > > > > > > > I've found my way into some methods in routing.rb that are dynamically > > > > > > > generated (and so you can't )(*&)(*& read them to debug them quite so > > > > > > > easily) that call the methods (in your case) label_id_value and > > > > > > > id_value (being the artist id). I have no idea yet where those two > > > > > > > methods get generated. Once I do, then we can stub them. Unfortunately > > > > > > > I can't really spend any more time on this right now (though I'd love > > > > > > > to solve it). > > > > > > > > > > > > > > In the mean time, you'll just have to use the parameters if you want > > > > > > > the specs to work with the same code with which your app works. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On 8/8/07, David Chelimsky wrote: > > > > > > > > > On 8/8/07, Lance Carlson wrote: > > > > > > > > > > I just visited the action in my browser and i don't get any errors. I > > > > > > > > > > am also running on edge rails as the application relies on > > > > > > > > > > ActiveResource. Can you show me the code you created? > > > > > > > > > > > > > > > > > > OK - I've created a small project and am able to reproduce the > > > > > > > > > behaviour you're describing. I'll follow up when learn something. > > > > > > > > > > > > > > > > > > David > > > > > > > > > _______________________________________________ > > > > > > > > > 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 > > > > > > > > > > > _______________________________________________ > > > > > 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 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Aug 10 10:05:48 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 10 Aug 2007 09:05:48 -0500 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <49f64a900708100704pdf441een1cdf1dd8b49e007e@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <49f64a900708081556s1454a8aey3feb2d937092083e@mail.gmail.com> <57c63afe0708081935x21e68a7ey74335c0129149325@mail.gmail.com> <49f64a900708091711m5d4c4b62s811b50e957bbe092@mail.gmail.com> <57c63afe0708091716u70a2f998j43fed817f6fe0f27@mail.gmail.com> <49f64a900708091721x4c7e0beeqf6febb40a7845192@mail.gmail.com> <57c63afe0708091731h37fc80a7qa5f1cff16bbd7549@mail.gmail.com> <49f64a900708091736x4b71f847je4dd001081b145e3@mail.gmail.com> <57c63afe0708100504o78effbfeu6aed0f2aee09af2f@mail.gmail.com> <49f64a900708100704pdf441een1cdf1dd8b49e007e@mail.gmail.com> Message-ID: <57c63afe0708100705s2cf1d71bue50d3916f37fad93@mail.gmail.com> On 8/10/07, Lance Carlson wrote: > Thanks for your patience trying to resolve this issue. I posted a bug > report here: > > http://rubyforge.org/tracker/index.php?func=detail&aid=12963&group_id=797&atid=3149 I see it - thanks. If you have time now, Lance, pls join the #rspec IRC chat. > > On 8/10/07, David Chelimsky wrote: > > On 8/9/07, Lance Carlson wrote: > > > About these methods requiring arguments? I thought you were able to > > > reproduce the problems I was having and was also able to reproduce a > > > working application with no arguments. > > > > That is correct. > > > > > By default these methods should > > > not require arguments to be passed as it is unnecessary noise in the > > > code. > > > > I understand that, but that was news to me as of this thread. I spent > > a couple of hours banging my head against this and found the generated > > code I mentioned earlier in the thread. That's the only insight I have > > to offer at this point. > > > > > Perhaps we can continue this discussion on IRC? #rspec? > > > > I'll pop in at one point this morning but I really don't have much in > > the way of cycles to spend on this right now. I'm happy to help point > > you in the right direction, but it's not very high on my priority > > list. In the mean time, now that we know this is a bug, would you > > kindly report it in the tracker? > > > > http://rubyforge.org/tracker/?atid=3149&group_id=797&func=browse > > > > > What is your s/n? > > > > > > On 8/9/07, David Chelimsky wrote: > > > > On 8/9/07, Lance Carlson wrote: > > > > > Is it possible that rspec is not pulling the instance variables into > > > > > the method because this method is being defined before instance > > > > > variables in parameters are assigned to that method? I'm trying to > > > > > hone down where the problem is popping up exactly. Any insight? > > > > > > > > Not really more than what I said earlier in this thread. > > > > > > > > > On 8/9/07, David Chelimsky wrote: > > > > > > On 8/9/07, Lance Carlson wrote: > > > > > > > Were you able to come up with any solutions? > > > > > > > > > > > > Nope. Anyone else? > > > > > > > > > > > > > > > > > > > > On 8/8/07, David Chelimsky wrote: > > > > > > > > On 8/8/07, Lance Carlson wrote: > > > > > > > > > Awesome! Thank you! :) > > > > > > > > > > > > > > > > Don't thank me yet. I've spent some time trying to track this down and > > > > > > > > I've found my way into some methods in routing.rb that are dynamically > > > > > > > > generated (and so you can't )(*&)(*& read them to debug them quite so > > > > > > > > easily) that call the methods (in your case) label_id_value and > > > > > > > > id_value (being the artist id). I have no idea yet where those two > > > > > > > > methods get generated. Once I do, then we can stub them. Unfortunately > > > > > > > > I can't really spend any more time on this right now (though I'd love > > > > > > > > to solve it). > > > > > > > > > > > > > > > > In the mean time, you'll just have to use the parameters if you want > > > > > > > > the specs to work with the same code with which your app works. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On 8/8/07, David Chelimsky wrote: > > > > > > > > > > On 8/8/07, Lance Carlson wrote: > > > > > > > > > > > I just visited the action in my browser and i don't get any errors. I > > > > > > > > > > > am also running on edge rails as the application relies on > > > > > > > > > > > ActiveResource. Can you show me the code you created? > > > > > > > > > > > > > > > > > > > > OK - I've created a small project and am able to reproduce the > > > > > > > > > > behaviour you're describing. I'll follow up when learn something. > > > > > > > > > > > > > > > > > > > > David > > > > > > > > > > _______________________________________________ > > > > > > > > > > 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 > > > > > > > > > > > > > _______________________________________________ > > > > > > 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 > > > > > _______________________________________________ > > 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 steve.tooke at gmail.com Fri Aug 10 10:29:47 2007 From: steve.tooke at gmail.com (Steve Tooke) Date: Fri, 10 Aug 2007 15:29:47 +0100 Subject: [rspec-users] ActiveRecordAssociationMatcher Message-ID: <78d462040708100729r6f4c3f2bm8179e82a7554da4a@mail.gmail.com> I've started to put together a custom expectation matcher for specifying AR associations. Its not quite complete and I really need to put some specs together for it, but I'd appreciate any comments. It lets you spec your associations like this: describe Record do include ActiveRecordAssociationMatchers it "should belong to artist and use a counter cache" do Record.should belong_to(:artist).with_options(:counter_cache => true) end it "should have_many tracks" do Record.should have_many(:tracks).with_class_name("Song).and_options(:include => :writers) end end Please see my blog entry or the pastie for more details. http://stevetooke.karmatrading.co.uk/2007/8/10/simple-rails-association-matching-with-rspec http://pastie.caboo.se/86604 From mailing_lists at railsnewbie.com Fri Aug 10 15:22:58 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 10 Aug 2007 15:22:58 -0400 Subject: [rspec-users] FixtureScenarios In-Reply-To: <57c63afe0708100701v4d37f169gc2c75cdfc750a8a5@mail.gmail.com> References: <98472412-6026-4A7F-9EC3-15204ED84FB8@wincent.com> <49f64a900708100652l7fcfc08n85aafbabfd57ae77@mail.gmail.com> <57c63afe0708100701v4d37f169gc2c75cdfc750a8a5@mail.gmail.com> Message-ID: On Aug 10, 2007, at 10:01 AM, David Chelimsky wrote: > On 8/10/07, Lance Carlson wrote: >> Thusfar, my experience with stubbing and mocking has not been a walk >> in the park either. Hopefully this will change when rspec's mocking >> and stubbing matures some more. > > Please elaborate. What new features are you expecting rspec's mocking > framework to adopt? I would really like to see better support for anonymous functions + and what they execute. I've posted several emails now about spec'ing anonymous functions and have gotten no replies. I think the fixture problem has been the mutability of data while doing TDD/BDD. When you change a field name, do you end up changing 6 fixture records field names? What about if you change the data that a model should have? This is the real advantage to generating the fixture data in ruby - it allows more rapid BDD. Scott From dchelimsky at gmail.com Fri Aug 10 15:43:54 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 10 Aug 2007 14:43:54 -0500 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: <57c63afe0708101243x23ab5bfr8af83d87d151c089@mail.gmail.com> On 8/7/07, 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 Why not just do this, which is already a language construct? Foo.new.instance_eval { ... } > > 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 Fri Aug 10 15:45:25 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 10 Aug 2007 14:45:25 -0500 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: <57c63afe0708101245h1421103eq3a8b73d7283a665f@mail.gmail.com> On 8/7/07, 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? I'm not sure what you're trying to accomplish here - what would this spec look like? > > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From eivindu at ifi.uio.no Fri Aug 10 16:04:41 2007 From: eivindu at ifi.uio.no (Eivind Uggedal) Date: Fri, 10 Aug 2007 22:04:41 +0200 Subject: [rspec-users] Can't seem to spec a ActiveRecord::RecordInvalid exception properly... In-Reply-To: <57c63afe0708081510n53f725edu9aac14b9457a403a@mail.gmail.com> References: <7e565b5c0708081408q474ac9e9m729143cc86ddaab7@mail.gmail.com> <57c63afe0708081510n53f725edu9aac14b9457a403a@mail.gmail.com> Message-ID: <824b51d00708101304i15fcaa64y5881587c26126740@mail.gmail.com> I asked exactly this question on this list 2 days ago... See http://pastie.caboo.se/85887 for a working example. One has to mock out ActiveRecord::Errors::full_messages for it to work under Rails. Cheers, Eivind Uggedal On 8/9/07, David Chelimsky wrote: > On 8/8/07, Fischer, Daniel wrote: > > 1 def create > > 2 @user = User.new(params[:user]) > > 3 @user.save! > > 4 self.current_user = @user > > 5 redirect_to user_path(@user) > > 6 flash[:notice] = "Thanks for signing up!" > > 7 rescue ActiveRecord::RecordInvalid > > 8 render :action => 'new' > > 9 end > > Try this: > > describe "/users/create" do > before(:each) do > User.stub!(:new).and_return(@user = mock_model(User)) > end > > it "should redirect to show on successful save" do > @user.should_receive(:save!) > post :create > response.should redirect_to(user_path(@user)) > end > > it "should re-render new on failed save" do > @user.should_receive(:save!).and_raise(ActiveRecord::RecordInvalid.new(@user)) > post :create > response.should render_template('new') > end > end > > Cheers, > David > > > > > I can't seem to properly spec this out. I am trying numerous things, the > > latest one is this, which makes sense but it still fails... > > > > > > it "should re-render new on an invalid record exception" do > > post :create, :user => {:login => nil} > > response.should render_template(:new) > > end > > > > should re-render new on an invalid record exception > > expected "new", got nil > > > > Any help would be great, thanks! > > > > _______________________________________________ > > 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 tils-rspec at tils.net Fri Aug 10 11:15:49 2007 From: tils-rspec at tils.net (Tilmann Singer) Date: Fri, 10 Aug 2007 17:15:49 +0200 Subject: [rspec-users] Transactional fixtures not working as expected In-Reply-To: <46BA0038.10807@content-space.de> References: <46BA0038.10807@content-space.de> Message-ID: <20070810151549.GH6662@tils.net> * Michael Hamann [20070808 19:46]: > 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 A fixture declaration in a context only guarantees that the explicitely declared fixtures are loaded and correspond to their fixture data in the .yml file - it does not guarantee that the non-declared fixtures are not loaded, nor does the absence of a fixture declaration guarantee that no fixtures are loaded. If a specific context depends on empty tables that may contain fixture data from previous runs the only way I can think of to guarantee that state is to add something like this in the context: before(:each) do Post.delete_all end This is certainly not ideal, but maybe a necessary workaround for you as long as fixtures work the way they do now. greetings, Til From mailing_lists at railsnewbie.com Fri Aug 10 16:31:18 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 10 Aug 2007 16:31:18 -0400 Subject: [rspec-users] and_yield + instance_eval(&block) In-Reply-To: <57c63afe0708101243x23ab5bfr8af83d87d151c089@mail.gmail.com> References: <46C54C9D-1BF3-436A-93A7-466B6B3BD51D@railsnewbie.com> <57c63afe0708101243x23ab5bfr8af83d87d151c089@mail.gmail.com> Message-ID: <27C7A435-E6EA-46B1-BE63-BE12F315DAF2@railsnewbie.com> On Aug 10, 2007, at 3:43 PM, David Chelimsky wrote: > On 8/7/07, 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 > > Why not just do this, which is already a language construct? > > Foo.new.instance_eval { ... } Maybe a better example would be in place. Consider the following from the Autotest plugin: Autotest.add_discovery do "rspec" if File.exist?('spec') end How would you go about testing this? It's easy enough to test that Autotest receives the method add_discovery. But how would you deal with the block? Scott From dchelimsky at gmail.com Fri Aug 10 16:36:15 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 10 Aug 2007 15:36:15 -0500 Subject: [rspec-users] and_yield + instance_eval(&block) In-Reply-To: <27C7A435-E6EA-46B1-BE63-BE12F315DAF2@railsnewbie.com> References: <46C54C9D-1BF3-436A-93A7-466B6B3BD51D@railsnewbie.com> <57c63afe0708101243x23ab5bfr8af83d87d151c089@mail.gmail.com> <27C7A435-E6EA-46B1-BE63-BE12F315DAF2@railsnewbie.com> Message-ID: <57c63afe0708101336r42ddc85dtc6154bc52cbe68b9@mail.gmail.com> On 8/10/07, Scott Taylor wrote: > > On Aug 10, 2007, at 3:43 PM, David Chelimsky wrote: > > > On 8/7/07, 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 > > > > Why not just do this, which is already a language construct? > > > > Foo.new.instance_eval { ... } > > Maybe a better example would be in place. Consider the following > from the Autotest plugin: > > Autotest.add_discovery do > "rspec" if File.exist?('spec') > end > > How would you go about testing this? > > It's easy enough to test that Autotest receives the method > add_discovery. But how would you deal with the block? OK - now I'm starting to see. Concrete examples are always helpful. I guess there's no mocking framework right now that would solve that for you. What spec do you *wish* you could write? From barjunk at attglobal.net Fri Aug 10 18:33:18 2007 From: barjunk at attglobal.net (barsalou) Date: Fri, 10 Aug 2007 14:33:18 -0800 Subject: [rspec-users] (no subject) Message-ID: <20070810143318.r4tlbzho0o4ss0c0@lcgalaska.com> Scott said: >> I'd like to output my rcov data to the screen in ascii instead of >> html...is that possible using the rake spec:rcov command? > Look at the RSpec gem's rdoc. I believe it is something like > Rake::RcovTask. An option can be provided to give rcov options. Run > rcov --help. This told me I needed the -T option to get what I wanted. Just to give a little more detail, I had to modify this file: vendor/plugins/rspec_on_rails/tasks/rspec.rake and in this section of code: desc "Run all specs in spec directory with RCov (excluding plugin specs)" Spec::Rake::SpecTask.new(:rcov) do |t| t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] t.spec_files = FileList['spec/**/*_spec.rb'] t.rcov = true t.rcov_opts = ['--exclude', 'spec', '--rails'] end Change this: t.rcov_opts = ['--exclude', 'spec', '--rails'] to this: t.rcov_opts = ['--exclude', 'spec', '--rails', '-T'] Any way to do this by passing a command line arg? like: rake spec:rcov -T <- This DOESN'T work. If it bugs me enough, maybe I'll submit a patch that allows an rcov.opts file like the spec.opts file. :) > > Also, is there somewhere that will allow me to search the mail > archives...I'm pretty sure someone else has asked similar questions. > > Google is your friend. Rubyforge also has the mailing lists, > although they aren't searchable. Google is such a great resource...with abundant responses! Sometimes this hinders my progress. :) Thanks for the hints. > Scott Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From barjunk at attglobal.net Fri Aug 10 18:35:49 2007 From: barjunk at attglobal.net (barsalou) Date: Fri, 10 Aug 2007 14:35:49 -0800 Subject: [rspec-users] Using rcov and ouput to screen Message-ID: <20070810143549.puoh3jebdw00kk84@lcgalaska.com> Sorry I left off the subject by accident...hopefully this will connect to the thread. Mike B. ----- Forwarded message from barjunk at attglobal.net ----- Date: Fri, 10 Aug 2007 14:33:18 -0800 From: barsalou Reply-To: barsalou To: rspec-users at rubyforge.org Scott said: >> I'd like to output my rcov data to the screen in ascii instead of >> html...is that possible using the rake spec:rcov command? > Look at the RSpec gem's rdoc. I believe it is something like > Rake::RcovTask. An option can be provided to give rcov options. Run > rcov --help. This told me I needed the -T option to get what I wanted. Just to give a little more detail, I had to modify this file: vendor/plugins/rspec_on_rails/tasks/rspec.rake and in this section of code: desc "Run all specs in spec directory with RCov (excluding plugin specs)" Spec::Rake::SpecTask.new(:rcov) do |t| t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] t.spec_files = FileList['spec/**/*_spec.rb'] t.rcov = true t.rcov_opts = ['--exclude', 'spec', '--rails'] end Change this: t.rcov_opts = ['--exclude', 'spec', '--rails'] to this: t.rcov_opts = ['--exclude', 'spec', '--rails', '-T'] Any way to do this by passing a command line arg? like: rake spec:rcov -T <- This DOESN'T work. If it bugs me enough, maybe I'll submit a patch that allows an rcov.opts file like the spec.opts file. :) > > Also, is there somewhere that will allow me to search the mail > archives...I'm pretty sure someone else has asked similar questions. > > Google is your friend. Rubyforge also has the mailing lists, > although they aren't searchable. Google is such a great resource...with abundant responses! Sometimes this hinders my progress. :) Thanks for the hints. > Scott Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. ----- End forwarded message ----- ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From nemo7467 at gmail.com Fri Aug 10 19:18:34 2007 From: nemo7467 at gmail.com (David Parker) Date: Fri, 10 Aug 2007 18:18:34 -0500 Subject: [rspec-users] How to spec a model method Message-ID: <9a07e4a80708101618k6fd3ed54l8b8cc5eb216f8ce0@mail.gmail.com> Still new to Specs... How do I create a spec to test a model method? Specifically, here is my spec: #testing model describe User do it "should have many user roles" do User.reflect_on_association(:user_roles).should_not be_nil end it "should have many roles though user roles" do User.reflect_on_association(:roles).should_not be_nil end it "should know what role it has" do #User.should end end The last spec is incomplete... basically, I will want the code to be something like this: class User < ActiveRecord::Base has_many :user_roles has_many :roles, :through => :user_roles def has_role?(role) self.roles.count(:conditions => ['name = ?', role]) > 0 end end How would I spec the last method? Thanks -- dp -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070810/f4587f0e/attachment.html From dchelimsky at gmail.com Fri Aug 10 19:32:37 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 10 Aug 2007 18:32:37 -0500 Subject: [rspec-users] How to spec a model method In-Reply-To: <9a07e4a80708101618k6fd3ed54l8b8cc5eb216f8ce0@mail.gmail.com> References: <9a07e4a80708101618k6fd3ed54l8b8cc5eb216f8ce0@mail.gmail.com> Message-ID: <57c63afe0708101632n5452e3fj15a90b893b8af700@mail.gmail.com> On 8/10/07, David Parker wrote: > Still new to Specs... > How do I create a spec to test a model method? Specifically, here is my > spec: > #testing model > describe User do > it "should have many user roles" do > User.reflect_on_association (:user_roles).should_not be_nil > end > > it "should have many roles though user roles" do > User.reflect_on_association(:roles).should_not be_nil > end > > it "should know what role it has" do > #User.should > end > end > > The last spec is incomplete... basically, I will want the code to be > something like this: > class User < ActiveRecord::Base > has_many :user_roles > has_many :roles, :through => :user_roles > > def has_role?(role) > self.roles.count(:conditions => ['name = ?', role] ) > 0 > end > end > > How would I spec the last method? If you change has_role? to in_role?, you can say this: role = Role.create(:name => 'foo') user.roles.add(role) user.should be_in_role('foo') > Thanks > -- > dp > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sbellware at hotmail.com Fri Aug 10 19:56:30 2007 From: sbellware at hotmail.com (sbellware) Date: Fri, 10 Aug 2007 16:56:30 -0700 (PDT) Subject: [rspec-users] Can't get should redirect_to match to work Message-ID: <12101072.post@talk.nabble.com> Folks, I've posted to the simple example I'm working with as well as the spec code and results here: http://pastie.caboo.se/86750 I can't seem to get this to work. Any ideas? Thanks, Scott -- View this message in context: http://www.nabble.com/Can%27t-get-should-redirect_to-match-to-work-tf4251891.html#a12101072 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Fri Aug 10 23:51:52 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 10 Aug 2007 22:51:52 -0500 Subject: [rspec-users] Can't get should redirect_to match to work In-Reply-To: <12101072.post@talk.nabble.com> References: <12101072.post@talk.nabble.com> Message-ID: <57c63afe0708102051v3494d7abjf352f0b56af3b5e5@mail.gmail.com> On 8/10/07, sbellware wrote: > > Folks, > > I've posted to the simple example I'm working with as well as the spec code > and results here: > http://pastie.caboo.se/86750 > > I can't seem to get this to work. Any ideas? As of some time ago, response.should redirect_to should come after the action. So: it "get foo" do get 'foo' response.should redirect_to(:action => 'bar') end > > Thanks, > Scott > -- > View this message in context: http://www.nabble.com/Can%27t-get-should-redirect_to-match-to-work-tf4251891.html#a12101072 > 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 jonathan at parkerhill.com Sat Aug 11 06:11:19 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Sat, 11 Aug 2007 06:11:19 -0400 Subject: [rspec-users] template.expect_render In-Reply-To: <57c63afe0706262231o31ffe07bv36d51b1fde376e15@mail.gmail.com> References: <57c63afe0706262231o31ffe07bv36d51b1fde376e15@mail.gmail.com> Message-ID: <3F0A0AF4-E210-45E2-B95E-207E282831EC@parkerhill.com> Hi, I'd like to stub out a partial call but not sure how. I tried something like this it "should render partial foo" do template.stub_render("bar/foo") render "/layouts/bar.html.erb" response.should render("bar/foo") end but the partial is still getting called On Jun 27, 2007, at 1:31 AM, David Chelimsky wrote: > Trunksters, > > I just added a couple of methods to ActionView::Base in Spec::Rails > (as of r2136) that lets you do this in view examples: > > describe '/things/index.html.erb' do > it "should render _thing with a collection of things" do > assigns[:things] = things = [Object.new] > template.expect_render(:partial => 'thing', :collection => things) > render '/things/index.html.erb' > end > end > > This solves two big problems - mocking nested partials and mocking > :object and :collection in partials. > > template.expect_render wraps part of 'spec/mocks', but not the whole > framework - so we get the expectation matching benefit w/o conflicting > with other mock frameworks that ppl might choose to use. > > There is also template.stub_render(opts) in case you just want to stub > the render w/o verification. > > I would LOVE it if some of you would try this method out and provide > feedback before we release it. Please feel to ask any questions about > this on this list. > > Thanks, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jonathan at parkerhill.com Sat Aug 11 08:00:01 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Sat, 11 Aug 2007 08:00:01 -0400 Subject: [rspec-users] template.expect_render In-Reply-To: <3F0A0AF4-E210-45E2-B95E-207E282831EC@parkerhill.com> References: <57c63afe0706262231o31ffe07bv36d51b1fde376e15@mail.gmail.com> <3F0A0AF4-E210-45E2-B95E-207E282831EC@parkerhill.com> Message-ID: <171B08D8-1DA8-413D-9A86-452D5E8E6DE0@parkerhill.com> oops, my bad this works (asserts pass, and partial not called) template.expect_render(:partial => 'bar/foo') render "/layouts/bar.html.erb" so does this: template.stub_render(:partial => 'bar/foo') render "/layouts/bar.html.erb" neither case seems to try to render the partial On Aug 11, 2007, at 6:11 AM, Jonathan Linowes wrote: > > Hi, I'd like to stub out a partial call but not sure how. > > I tried something like this > > it "should render partial foo" do > template.stub_render("bar/foo") > render "/layouts/bar.html.erb" > response.should render("bar/foo") > end > > but the partial is still getting called > > > On Jun 27, 2007, at 1:31 AM, David Chelimsky wrote: > >> Trunksters, >> >> I just added a couple of methods to ActionView::Base in Spec::Rails >> (as of r2136) that lets you do this in view examples: >> >> describe '/things/index.html.erb' do >> it "should render _thing with a collection of things" do >> assigns[:things] = things = [Object.new] >> template.expect_render(:partial => 'thing', :collection => >> things) >> render '/things/index.html.erb' >> end >> end >> >> This solves two big problems - mocking nested partials and mocking >> :object and :collection in partials. >> >> template.expect_render wraps part of 'spec/mocks', but not the whole >> framework - so we get the expectation matching benefit w/o >> conflicting >> with other mock frameworks that ppl might choose to use. >> >> There is also template.stub_render(opts) in case you just want to >> stub >> the render w/o verification. >> >> I would LOVE it if some of you would try this method out and provide >> feedback before we release it. Please feel to ask any questions about >> this on this list. >> >> Thanks, >> David >> _______________________________________________ >> 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 jonathan at parkerhill.com Sat Aug 11 08:52:36 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Sat, 11 Aug 2007 08:52:36 -0400 Subject: [rspec-users] nested layouts Message-ID: hi, I'm using a helper like in nested-layouts plugin as follows def inside_layout(layout, &block) layout = layout.include?('/') ? layout : "layouts/#{layout}" @template.instance_variable_set('@content_for_layout', capture (&block)) concat( @template.render( :file => layout, :user_full_path => true ), block.binding ) end used like this: views/layouts/bar.html.erb: <% inside_layout 'foo' do -%> ...stuff... <% end %> This basically works in my view spec although it brings in all the nested (outer) layouts Can you suggest a way to isolate the bar.html.erb template? thanks From dchelimsky at gmail.com Sat Aug 11 09:00:35 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 11 Aug 2007 08:00:35 -0500 Subject: [rspec-users] template.expect_render In-Reply-To: <171B08D8-1DA8-413D-9A86-452D5E8E6DE0@parkerhill.com> References: <57c63afe0706262231o31ffe07bv36d51b1fde376e15@mail.gmail.com> <3F0A0AF4-E210-45E2-B95E-207E282831EC@parkerhill.com> <171B08D8-1DA8-413D-9A86-452D5E8E6DE0@parkerhill.com> Message-ID: <57c63afe0708110600o6d22e5f5p4d93d654ceac1d97@mail.gmail.com> On 8/11/07, Jonathan Linowes wrote: > oops, my bad > > this works (asserts pass, and partial not called) > > template.expect_render(:partial => 'bar/foo') > render "/layouts/bar.html.erb" > > so does this: > > template.stub_render(:partial => 'bar/foo') > render "/layouts/bar.html.erb" > > neither case seems to try to render the partial Right - the difference is that stub_render won't complain if the partial is not rendered, so if what you mean to do is specify that it should be rendered, then you should use expects_render. > > > > On Aug 11, 2007, at 6:11 AM, Jonathan Linowes wrote: > > > > > Hi, I'd like to stub out a partial call but not sure how. > > > > I tried something like this > > > > it "should render partial foo" do > > template.stub_render("bar/foo") > > render "/layouts/bar.html.erb" > > response.should render("bar/foo") > > end > > > > but the partial is still getting called > > > > > > On Jun 27, 2007, at 1:31 AM, David Chelimsky wrote: > > > >> Trunksters, > >> > >> I just added a couple of methods to ActionView::Base in Spec::Rails > >> (as of r2136) that lets you do this in view examples: > >> > >> describe '/things/index.html.erb' do > >> it "should render _thing with a collection of things" do > >> assigns[:things] = things = [Object.new] > >> template.expect_render(:partial => 'thing', :collection => > >> things) > >> render '/things/index.html.erb' > >> end > >> end > >> > >> This solves two big problems - mocking nested partials and mocking > >> :object and :collection in partials. > >> > >> template.expect_render wraps part of 'spec/mocks', but not the whole > >> framework - so we get the expectation matching benefit w/o > >> conflicting > >> with other mock frameworks that ppl might choose to use. > >> > >> There is also template.stub_render(opts) in case you just want to > >> stub > >> the render w/o verification. > >> > >> I would LOVE it if some of you would try this method out and provide > >> feedback before we release it. Please feel to ask any questions about > >> this on this list. > >> > >> Thanks, > >> David > >> _______________________________________________ > >> 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 franck.dagostini at gmail.com Sat Aug 11 12:34:42 2007 From: franck.dagostini at gmail.com (Franck D'agostini) Date: Sat, 11 Aug 2007 09:34:42 -0700 (PDT) Subject: [rspec-users] Rspec and acl_system2 plugin Message-ID: <12106932.post@talk.nabble.com> Hello, I'm trying to spec a Rails application using the couple restful_authentication/acl_system2 plugins. In my admin layout, I put the following code : <% restrict_to "admin" do -%>
  • /users Users management
<% end -%> Then in my spec file 'spec/views/layout/admin.rhtml_spec.rb' : describe "Layout Admin if admin user" do include UserMockViewHelper it "should display the admin tabs" do login_as :admin render 'layouts/admin' response.should have_tag("ul#admin-tabs") end end the UserMockViewHelper module handle the mocking of the current user : module UserMockViewHelper def login_as(user) @current_user = mock_model(User) @role = mock_model(Role) case user when :admin @role.stub!(:map).and_return(["admin", "cms"]) when :cms_admin @role.stub!(:map).and_return(["cms", "cms_admin"]) when :cms @role.stub!(:map).and_return(["cms"]) else @role.stub!(:map).and_return([]) end @current_user.stub!(:roles).and_return(@role) @current_user.stub!(:login).and_return(user) User.should_receive(:find_by_id).any_number_of_times.and_return(@current_user) request.session[:user] = @current_user @controller.template.should_receive(:current_user).and_return(@current_user) end end When I run 'ruby script/spec spec/views/layouts/admin.rhtml_spec.rb', I've got the following error message : ActionView::TemplateError in 'Layout Admin if admin user should display the admin tabs' undefined local variable or method `current_user' for # On line #28 of app/views/layouts/admin.rhtml 25:
    26:
  • /articles Publications
  • 27:
28: <% restrict_to "admin" do -%> 29:
    30:
  • /users Utilisateurs
  • 31:
#{RAILS_ROOT}/vendor/plugins/acl_system2/lib/caboose/access_control.rb:75:in `restrict_to' (eval):2:in `send' (eval):2:in `restrict_to' #{RAILS_ROOT}/app/views/layouts/admin.rhtml:28:in `_run_rhtml_47app47views47layouts47admin46rhtml' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:326:in `send' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:326:in `compile_and_render_template' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:301:in `render_template' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:260:in `render_file' In the acl_system2 plugin, we have the following code : # restrict_to "admin | moderator" do # link_to "foo" # end def restrict_to(logicstring, context = {}) return false if current_user.nil? result = '' if permit?(logicstring, context) result = yield if block_given? end result end I'm just starting with rspec and I believe I'm missing something ... Did someone run into this error before ? -- View this message in context: http://www.nabble.com/Rspec-and-acl_system2-plugin-tf4254003.html#a12106932 Sent from the rspec-users mailing list archive at Nabble.com. From aslak.hellesoy at gmail.com Sat Aug 11 13:01:32 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 11 Aug 2007 19:01:32 +0200 Subject: [rspec-users] Using rcov and ouput to screen In-Reply-To: <20070810143549.puoh3jebdw00kk84@lcgalaska.com> References: <20070810143549.puoh3jebdw00kk84@lcgalaska.com> Message-ID: <8d961d900708111001g5fe852fejb0c24925e88e79c0@mail.gmail.com> On 8/11/07, barsalou wrote: > > Sorry I left off the subject by accident...hopefully this will connect > to the thread. > > Mike B. > ----- Forwarded message from barjunk at attglobal.net ----- > Date: Fri, 10 Aug 2007 14:33:18 -0800 > From: barsalou > Reply-To: barsalou > To: rspec-users at rubyforge.org > > > Scott said: > > >> I'd like to output my rcov data to the screen in ascii instead of > >> html...is that possible using the rake spec:rcov command? > > > Look at the RSpec gem's rdoc. I believe it is something like > > Rake::RcovTask. An option can be provided to give rcov options. Run > > rcov --help. > > This told me I needed the -T option to get what I wanted. > > Just to give a little more detail, I had to modify this file: > > > vendor/plugins/rspec_on_rails/tasks/rspec.rake > > and in this section of code: > > desc "Run all specs in spec directory with RCov (excluding plugin specs)" > Spec::Rake::SpecTask.new(:rcov) do |t| > t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] > t.spec_files = FileList['spec/**/*_spec.rb'] > t.rcov = true > t.rcov_opts = ['--exclude', 'spec', '--rails'] > end > > Change this: > > t.rcov_opts = ['--exclude', 'spec', '--rails'] > > to this: > > t.rcov_opts = ['--exclude', 'spec', '--rails', '-T'] > > > Any way to do this by passing a command line arg? like: > > rake spec:rcov -T <- This DOESN'T work. > >From Spec::Rake::SpecTask's RDoc (on trunk) A Rake task that runs a set of RSpec contexts. Example: Spec::Rake::SpecTask.new do |t| t.warning = true t.rcov = true end This will create a task that can be run with: rake spec If rake is invoked with a "SPEC=filename" command line option, then the list of spec files will be overridden to include only the filename specified on the command line. This provides an easy way to run just one spec. If rake is invoked with a "SPEC_OPTS=options" command line option, then the given options will override the value of the spec_opts attribute. If rake is invoked with a "RCOV_OPTS=options" command line option, then the given options will override the value of the rcov_opts attribute. Examples: rake spec # run specs normally rake spec SPEC=just_one_file.rb # run just one spec file. rake spec SPEC_OPTS="--diff" # enable diffing rake spec RCOV_OPTS="--aggregate myfile.txt" # see rcov --help for details Each attribute of this task may be a proc. This allows for lazy evaluation, which is sometimes handy if you want to defer the evaluation of an attribute value until the task is run (as opposed to when it is defined). > > > If it bugs me enough, maybe I'll submit a patch that allows an > rcov.opts file like the spec.opts file. :) > > > > > > Also, is there somewhere that will allow me to search the mail > > archives...I'm pretty sure someone else has asked similar questions. > > > > > Google is your friend. Rubyforge also has the mailing lists, > > although they aren't searchable. > > Google is such a great resource...with abundant responses! Sometimes > this hinders my progress. :) > > Thanks for the hints. > > > Scott > > > Mike B. > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > > > ----- End forwarded message ----- > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From court3nay at gmail.com Sat Aug 11 14:08:21 2007 From: court3nay at gmail.com (Courtenay) Date: Sat, 11 Aug 2007 11:08:21 -0700 Subject: [rspec-users] Rspec and acl_system2 plugin In-Reply-To: <12106932.post@talk.nabble.com> References: <12106932.post@talk.nabble.com> Message-ID: <4b430c8f0708111108l7eef6dd5l53e217b0101011e1@mail.gmail.com> On 8/11/07, Franck D'agostini wrote: > > I'm trying to spec a Rails application using the couple > restful_authentication/acl_system2 plugins. > > In my admin layout, I put the following code : > > <% restrict_to "admin" do -%> >
    >
  • /users Users management
  • >
> <% end -%> > Remember, rSpec is Behavioural. The code behind "restrict_to" doesn't matter; it's the behaviour that matters. As such, your view-spec should only know about the code in that view. So for example, there's no mention of a "user" or "role" model there, only a "restrict_to" method. Spec out the "restrict_to" code, rather than setting up a complex chain of fragile model interactions. This means that you can change the whole ACL system, but as long as it conforms to the same interface, restrict_to("rolename"), your specs will suceed. You can also change the associations or the name of your models, or add some fancy caching, anything, and this particular spec won't die. > User.should_receive(:find_by_id).any_number_of_times.and_return(@current_user) > request.session[:user] = @current_user The fact that you're stubbing "find" calls in the *view* spec indicates that you're probably testing things that are out of the scope of that spec. The actual ACL system should be tested on its own, not in the context of a view. Courtenay From franck.dagostini at gmail.com Sat Aug 11 12:54:42 2007 From: franck.dagostini at gmail.com (Franck D'agostini) Date: Sat, 11 Aug 2007 09:54:42 -0700 (PDT) Subject: [rspec-users] Rspec and acl_system2 plugin In-Reply-To: <12106932.post@talk.nabble.com> References: <12106932.post@talk.nabble.com> Message-ID: <12107096.post@talk.nabble.com> Sorry, I've just seen that this question has already been raised in this mailing list. I should have double checked first. My bad :sleep: -- View this message in context: http://www.nabble.com/Rspec-and-acl_system2-plugin-tf4254003.html#a12107096 Sent from the rspec-users mailing list archive at Nabble.com. From rupert_apsc at rupespad.com Sun Aug 12 06:34:28 2007 From: rupert_apsc at rupespad.com (rupert) Date: Sun, 12 Aug 2007 11:34:28 +0100 Subject: [rspec-users] stubbing a method that yeilds sequential results Message-ID: <3F7BD489-E648-4A40-8E6C-0BA5B313691A@rupespad.com> I've just found myself stuck trying to rspec something so am hoping someone more knowledgable can help. I have a Connector class which has a class method 'results' that yields results it get from a network service based on a set of attributes that I pass to it. I am wanting to yield these results from my Intermediate class up to the next 'level' so the basic no frills set up would be this: class Intermediate def self.results(attributes) Connector.each_result(attributes) do |result| yield result end end end I've worked out how to stub things for the case where the Connector. each_result method yields a result once #setup @result = mock("result") Connector.stub!(:each_result).and_yield(@result) @attributes = {} @results = [] @block = Proc.new { |r| @results << r } #action Intermediate.search_results(@attributes, &@block) # expectation @results.should == [@search_result] However, what I actually need to do is check each result that is yielded by the Connector.each_result method and compare it to the previous one. If they are sufficiently similar I need to merge them (and same again if the next result is sufficiently similar). I only want to yeild merged results and results that are not similar to their preceeding result(s) - I'd imagined he code to do this would be something along the lines of: class Intermediate def self.results(attributes) @saved_result = nil Connector.each_result(attributes) do |result| if results_match(result, @saved_result) @saved_result.merge!(result) else yield @saved_result unless @saved_result.nil? @saved_result = result end end yield @saved_result unless @saved_result.nil? end def results_match(this, last) return false if last.nil? .... end end I can't for the life of me see how I should spec this though, as trying: Connector.stub!(:results).and_yield(@result1, @result2) is expecting the two results to be yielded at the same time and not sequentially. I can't see how to stub a method to yield sequential results so I can spec the behavior for different scenarios of similarities between subsequent results. Is it possible to do this? Any help would be much appreciated Cheers Rupert From dchelimsky at gmail.com Sun Aug 12 09:38:36 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 12 Aug 2007 09:38:36 -0400 Subject: [rspec-users] stubbing a method that yeilds sequential results In-Reply-To: <3F7BD489-E648-4A40-8E6C-0BA5B313691A@rupespad.com> References: <3F7BD489-E648-4A40-8E6C-0BA5B313691A@rupespad.com> Message-ID: <57c63afe0708120638j626da921y13d414cf2879fe9@mail.gmail.com> On 8/12/07, rupert wrote: > I've just found myself stuck trying to rspec something so am hoping > someone more knowledgable can help. > > I have a Connector class which has a class method 'results' that > yields results it get from a network service based on a set of > attributes that I pass to it. I am wanting to yield these results > from my Intermediate class up to the next 'level' so the basic no > frills set up would be this: > > class Intermediate > def self.results(attributes) > Connector.each_result(attributes) do |result| > yield result > end > end > end > > I've worked out how to stub things for the case where the Connector. > each_result method yields a result once > > #setup > @result = mock("result") > Connector.stub!(:each_result).and_yield(@result) > > @attributes = {} > @results = [] > @block = Proc.new { |r| @results << r } > > #action > Intermediate.search_results(@attributes, &@block) > > # expectation > @results.should == [@search_result] > > > However, what I actually need to do is check each result that is > yielded by the Connector.each_result method and compare it to the > previous one. If they are sufficiently similar I need to merge them > (and same again if the next result is sufficiently similar). I only > want to yeild merged results and results that are not similar to > their preceeding result(s) - I'd imagined he code to do this would be > something along the lines of: > > class Intermediate > def self.results(attributes) > @saved_result = nil > > Connector.each_result(attributes) do |result| > if results_match(result, @saved_result) > @saved_result.merge!(result) > else > yield @saved_result unless @saved_result.nil? > @saved_result = result > end > end > yield @saved_result unless @saved_result.nil? > end > > def results_match(this, last) > return false if last.nil? > .... > end > end > > I can't for the life of me see how I should spec this though, as trying: > > Connector.stub!(:results).and_yield(@result1, @result2) > > is expecting the two results to be yielded at the same time and not > sequentially. I'm pretty sure you can get what you want by using should_receive instead of stub and doing this: Connector.should_receive(:results).and_yield(@result1) Connector.should_receive(:results).and_yield(@result2) > I can't see how to stub a method to yield sequential > results so I can spec the behavior for different scenarios of > similarities between subsequent results. Is it possible to do this? > > Any help would be much appreciated > > Cheers > > Rupert > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rupert_apsc at rupespad.com Sun Aug 12 10:23:42 2007 From: rupert_apsc at rupespad.com (rupert) Date: Sun, 12 Aug 2007 15:23:42 +0100 Subject: [rspec-users] stubbing a method that yeilds sequential results In-Reply-To: <57c63afe0708120638j626da921y13d414cf2879fe9@mail.gmail.com> References: <3F7BD489-E648-4A40-8E6C-0BA5B313691A@rupespad.com> <57c63afe0708120638j626da921y13d414cf2879fe9@mail.gmail.com> Message-ID: <5ECC2B3D-BC8B-4EBE-8136-A65F6ABD8388@rupespad.com> On 12 Aug 2007, at 14:38, David Chelimsky wrote: > On 8/12/07, rupert wrote: >> I've just found myself stuck trying to rspec something so am hoping >> someone more knowledgable can help. >> >> I have a Connector class which has a class method 'results' that >> yields results it get from a network service based on a set of >> attributes that I pass to it. I am wanting to yield these results >> from my Intermediate class up to the next 'level' so the basic no >> frills set up would be this: >> >> class Intermediate >> def self.results(attributes) >> Connector.each_result(attributes) do |result| >> yield result >> end >> end >> end >> >> I've worked out how to stub things for the case where the Connector. >> each_result method yields a result once >> >> #setup >> @result = mock("result") >> Connector.stub!(:each_result).and_yield(@result) >> >> @attributes = {} >> @results = [] >> @block = Proc.new { |r| @results << r } >> >> #action >> Intermediate.search_results(@attributes, &@block) >> >> # expectation >> @results.should == [@search_result] >> >> >> However, what I actually need to do is check each result that is >> yielded by the Connector.each_result method and compare it to the >> previous one. If they are sufficiently similar I need to merge them >> (and same again if the next result is sufficiently similar). I only >> want to yeild merged results and results that are not similar to >> their preceeding result(s) - I'd imagined he code to do this would be >> something along the lines of: >> >> class Intermediate >> def self.results(attributes) >> @saved_result = nil >> >> Connector.each_result(attributes) do |result| >> if results_match(result, @saved_result) >> @saved_result.merge!(result) >> else >> yield @saved_result unless @saved_result.nil? >> @saved_result = result >> end >> end >> yield @saved_result unless @saved_result.nil? >> end >> >> def results_match(this, last) >> return false if last.nil? >> .... >> end >> end >> >> I can't for the life of me see how I should spec this though, as >> trying: >> >> Connector.stub!(:results).and_yield(@result1, @result2) >> >> is expecting the two results to be yielded at the same time and not >> sequentially. > > I'm pretty sure you can get what you want by using should_receive > instead of stub and doing this: > > Connector.should_receive(:results).and_yield(@result1) > Connector.should_receive(:results).and_yield(@result2) Thanks for getting back so quickly - on a Sunday too!! Unfortunately this doesn't seem to work - it's failing the second Conector.should_receive spec. This seems to be because the Connector is only receiving the results (sorry for the confusion - it should be each_result) method call once. So what's happening is that @result1 is being yielded then the second should_receive fails as the method isn't called a 2nd time. So what I need to be able to say is: Connector.should_receive(:each_result).once.and_yield(@result1 followed_by @result2 followed_by @result3) so one call to a method can yield a set of results in turn. Hope this makes sense (and it's not just that I'm missing the obvious or doing something stupid!) Cheers Rupert From dchelimsky at gmail.com Sun Aug 12 11:03:41 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 12 Aug 2007 11:03:41 -0400 Subject: [rspec-users] 1.0.6 gotcha Message-ID: <57c63afe0708120803w46fa1761ibf28b6ca3b2d3c2c@mail.gmail.com> Hi All - I released 1.0.6 this morning, but there is apparently a bug related to rspec and autotest. I'll be fixing this today (but not until tonight) so you have two options: Wait until 1.0.7 (tonight) Upgrade now to 1.0.6 but make sure you install the rspec gem. Thanks, David From port001 at gmail.com Sun Aug 12 12:07:23 2007 From: port001 at gmail.com (Ian Leitch) Date: Sun, 12 Aug 2007 17:07:23 +0100 Subject: [rspec-users] 1.0.6 gotcha In-Reply-To: <57c63afe0708120803w46fa1761ibf28b6ca3b2d3c2c@mail.gmail.com> References: <57c63afe0708120803w46fa1761ibf28b6ca3b2d3c2c@mail.gmail.com> Message-ID: Cheers David, I've been waiting patiently for this release :) I think I might wait for a rainy day until I upgrade though (I'm not using autotest btw).. 1469 examples, 62 failures It's good to see you (and the rest of the team) give credit where credit is due. I was half expecting the contributors list to stay the same with this release. I'm glad to see that it didn't, I only wish more projects accepted contributions so graciously. Cheers Ian On 12/08/07, David Chelimsky wrote: > > Hi All - I released 1.0.6 this morning, but there is apparently a bug > related to rspec and autotest. I'll be fixing this today (but not > until tonight) so you have two options: > > Wait until 1.0.7 (tonight) > > Upgrade now to 1.0.6 but make sure you install the rspec gem. > > Thanks, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070812/c12e7cc7/attachment.html From nemo7467 at gmail.com Sun Aug 12 16:53:24 2007 From: nemo7467 at gmail.com (David Parker) Date: Sun, 12 Aug 2007 15:53:24 -0500 Subject: [rspec-users] Scope and specing models Message-ID: <9a07e4a80708121353v6a9de792k2d72cb4d2642f02b@mail.gmail.com> Hello all, I'm currently having an issue with some specs, specifically scope issues (probably more of a scope issue than a spec issue at this point)... Here's the error: ActiveRecord::AssociationTypeMismatch in 'A new User should know what role it has' Role expected, got NilClass D:/ruby/projects/restful_authentication_test/config/../app/models/role.rb:5:in `add' ./spec/models/user_spec.rb:62: script/spec:4: Here's the user.rb http://pastie.caboo.se/87029 role.rb http://pastie.caboo.se/87030 user_spec.rb http://pastie.caboo.se/87032 The code is based off of RESTful authentication + Ben Curtis' user roles in Rails Application: http://www.bencurtis.com/archives/2007/06/user-roles-in-rails-applications/ Thanks for your help! -- dp -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070812/38430919/attachment.html From lists-rspec at shopwatch.org Sun Aug 12 18:26:29 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Sun, 12 Aug 2007 18:26:29 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <57c63afe0708100705s2cf1d71bue50d3916f37fad93@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <49f64a900708081556s1454a8aey3feb2d937092083e@mail.gmail.com> <57c63afe0708081935x21e68a7ey74335c0129149325@mail.gmail.com> <49f64a900708091711m5d4c4b62s811b50e957bbe092@mail.gmail.com> <57c63afe0708091716u70a2f998j43fed817f6fe0f27@mail.gmail.com> <49f64a900708091721x4c7e0beeqf6febb40a7845192@mail.gmail.com> <57c63afe0708091731h37fc80a7qa5f1cff16bbd7549@mail.gmail.com> <49f64a900708091736x4b71f847je4dd001081b145e3@mail.gmail.com> <57c63afe0708100504o78effbfeu6aed0f2aee09af2f@mail.gmail.com> <49f64a900708100704pdf441een1cdf1dd8b49e007e@mail.gmail.com> <57c63afe0708100705s2cf1d71bue50d3916f37fad93@mail.gmail.com> Message-ID: <46BF8915.5040109@jay.fm> David Chelimsky wrote: > On 8/10/07, Lance Carlson wrote: >> Thanks for your patience trying to resolve this issue. I posted a bug >> report here: >> >> http://rubyforge.org/tracker/index.php?func=detail&aid=12963&group_id=797&atid=3149 > > I see it - thanks. If you have time now, Lance, pls join the #rspec IRC chat. How did this chat go, if it went? I'm about to dive into this problem but don't want to duplicate efforts. Jay From lancecarlson at gmail.com Sun Aug 12 18:33:47 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Sun, 12 Aug 2007 18:33:47 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <46BF8915.5040109@jay.fm> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <49f64a900708091711m5d4c4b62s811b50e957bbe092@mail.gmail.com> <57c63afe0708091716u70a2f998j43fed817f6fe0f27@mail.gmail.com> <49f64a900708091721x4c7e0beeqf6febb40a7845192@mail.gmail.com> <57c63afe0708091731h37fc80a7qa5f1cff16bbd7549@mail.gmail.com> <49f64a900708091736x4b71f847je4dd001081b145e3@mail.gmail.com> <57c63afe0708100504o78effbfeu6aed0f2aee09af2f@mail.gmail.com> <49f64a900708100704pdf441een1cdf1dd8b49e007e@mail.gmail.com> <57c63afe0708100705s2cf1d71bue50d3916f37fad93@mail.gmail.com> <46BF8915.5040109@jay.fm> Message-ID: <49f64a900708121533x630b6310je1b371eee99130e8@mail.gmail.com> It was never resolved.. the only resolution was to mock out the methods at this point or provide the views with the instance variables. On 8/12/07, Jay Levitt wrote: > David Chelimsky wrote: > > On 8/10/07, Lance Carlson wrote: > >> Thanks for your patience trying to resolve this issue. I posted a bug > >> report here: > >> > >> http://rubyforge.org/tracker/index.php?func=detail&aid=12963&group_id=797&atid=3149 > > > > I see it - thanks. If you have time now, Lance, pls join the #rspec IRC chat. > > How did this chat go, if it went? I'm about to dive into this problem > but don't want to duplicate efforts. > > Jay > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From davidjrice at gmail.com Sun Aug 12 18:50:42 2007 From: davidjrice at gmail.com (David Rice) Date: Sun, 12 Aug 2007 23:50:42 +0100 Subject: [rspec-users] Test::Unit to RSpec Converter Message-ID: <85797B99-B2CD-4A33-A229-0ABEFAAFD89E@gmail.com> Hey, just posting in case this is of interest. I just recently wrote a Rails plugin to convert Rails Test::Unit cases to RSpec. http://www.davidjrice.co.uk/articles/2007/8/12/ruby-on-rails-plugin- test-unit-to-rspec-converter it's not going to work 100% in every case, but it's really helped me convert old tests to the lovely RSpec :) Best, Dave --- David Rice http://www.davidjrice.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070812/b809a804/attachment-0001.html From lists-rspec at shopwatch.org Sun Aug 12 20:28:39 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Sun, 12 Aug 2007 20:28:39 -0400 Subject: [rspec-users] Problems with RESTfully generated helpers In-Reply-To: <49f64a900708121533x630b6310je1b371eee99130e8@mail.gmail.com> References: <49f64a900708080726s52d972ak9b488bdd0fff3ddd@mail.gmail.com> <49f64a900708091711m5d4c4b62s811b50e957bbe092@mail.gmail.com> <57c63afe0708091716u70a2f998j43fed817f6fe0f27@mail.gmail.com> <49f64a900708091721x4c7e0beeqf6febb40a7845192@mail.gmail.com> <57c63afe0708091731h37fc80a7qa5f1cff16bbd7549@mail.gmail.com> <49f64a900708091736x4b71f847je4dd001081b145e3@mail.gmail.com> <57c63afe0708100504o78effbfeu6aed0f2aee09af2f@mail.gmail.com> <49f64a900708100704pdf441een1cdf1dd8b49e007e@mail.gmail.com> <57c63afe0708100705s2cf1d71bue50d3916f37fad93@mail.gmail.com> <46BF8915.5040109@jay.fm> <49f64a900708121533x630b6310je1b371eee99130e8@mail.gmail.com> Message-ID: <46BFA5B7.30909@jay.fm> Lance Carlson wrote: > It was never resolved.. the only resolution was to mock out the > methods at this point or provide the views with the instance > variables. Well, I didn't get anywhere tonight - but I did discover that script/console has the same problem. Given routes.rb: map.resources :users, :member => {:edit_business_card => :get, :update_business_card => :put } and: >> app.update_business_card_user_url I get: ActionController::RoutingError: update_business_card_user_url failed to generate from {:controller=>"users", :action=>"update_business_card"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["users", :id, "update_business_card"] - are they all satisfied? Yet using update_business_card_user_url from a view works fine. Since I can duplicate it without rspec, I'll post a message to rubyonrails-talk and see if anyone has some ideas. Jay From dchelimsky at gmail.com Mon Aug 13 01:39:05 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 13 Aug 2007 01:39:05 -0400 Subject: [rspec-users] Scope and specing models In-Reply-To: <9a07e4a80708121353v6a9de792k2d72cb4d2642f02b@mail.gmail.com> References: <9a07e4a80708121353v6a9de792k2d72cb4d2642f02b@mail.gmail.com> Message-ID: <57c63afe0708122239x56fe61fay766331e24e5b56f7@mail.gmail.com> On 8/12/07, David Parker wrote: > Hello all, I'm currently having an issue with some specs, specifically scope > issues (probably more of a scope issue than a spec issue at this point)... > Here's the error: > ActiveRecord::AssociationTypeMismatch in 'A new User should > know what role it has' > Role expected, got NilClass > D:/ruby/projects/restful_authentication_test/config/../app/models/role.rb:5:in > `add' > ./spec/models/user_spec.rb:62: > script/spec:4: > > Here's the user.rb > http://pastie.caboo.se/87029 > > role.rb > http://pastie.caboo.se/87030 > > user_spec.rb > http://pastie.caboo.se/87032 > > The code is based off of RESTful authentication + > Ben Curtis' user roles in Rails Application: > http://www.bencurtis.com/archives/2007/06/user-roles-in-rails-applications/ users.roles is an AssociationProxy, not the Role class, where you have defined the method add(user, role). You should be able to eliminate that method in the Role class and just pass the role on line 62 of your spec: users.roles.add(role) > > Thanks for your help! > -- > dp > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From flyeminent at hotmail.com Sun Aug 12 20:43:03 2007 From: flyeminent at hotmail.com (Shaker) Date: Sun, 12 Aug 2007 17:43:03 -0700 (PDT) Subject: [rspec-users] Problem of using fixture in Rspec Message-ID: <12119520.post@talk.nabble.com> Dear Fellows: I was using fixtures in the model tests using Rspec. I found that the test data specified in the fixtures was stored in the test database once I ran the spec and won't be removed anyway. Is my observation correct? There might be another problem regarding the fixtures. When I ran the specs one by one, it was working. However, it failed when I tried to run all the specs in one command. It seemed that the test data which was modified by one spec caused the other spec which accessed that particular data to fail. In other words, the data is actually kind of public to all specs, so the specs shares one copy of test data. If my observation is correct, are there any ways to overcome these problems? Is it possible that each single spec owns its test data so that the modifications on the data will not affect other specs? Cheers! -- View this message in context: http://www.nabble.com/Problem-of-using-fixture-in-Rspec-tf4258669.html#a12119520 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Mon Aug 13 01:58:42 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 13 Aug 2007 01:58:42 -0400 Subject: [rspec-users] [ANN] RSpec-1.0.8 Message-ID: <57c63afe0708122258r6ae4494cld9353dc135c00c94@mail.gmail.com> The RSpec Development Team is pleased to announce the release of RSpec-1.0.8. RSpec 1.0.6 is the "holy cow, batman, it's been a long time since we released and there are a ton of bug fixes, patches and even new features" release. RSpec 1.0.7 and 1.0.8 deal with a regression introduced in 1.0.6 and a hiccup in releasing 1.0.7, respectively. == RSpec RSpec is a Behaviour Driven Development framework which plays the same role that a unit testing framework would play in Test Driven Development, but does so using words and structures that better support BDD. http://rspec.rubyforge.org == rspec_on_rails rspec_on_rails is a Ruby on Rails plugin that supports a BDD approach to developing the various layers of objects within a Rails application. See http://rspec.rubyforge.org/documentation/rails/index.html == Installation http://rspec.rubyforge.org/download.html http://rspec.rubyforge.org/documentation/rails/install.html From flyeminent at hotmail.com Mon Aug 13 03:21:52 2007 From: flyeminent at hotmail.com (Shaker) Date: Mon, 13 Aug 2007 00:21:52 -0700 (PDT) Subject: [rspec-users] How to use expect_render? Message-ID: <12121894.post@talk.nabble.com> Hi: I am a rspec beginner. I have scratched my head for the whole afternoon, trying to figure out a way of writing render expectation in controller spec. However, I failed. It kept telling me that the 'expect_render' was an undefined method. I have installed rspec 1.0.8 and rspec_on_rails as well. Below is the controller to be tested. Controller def index pre = Array.new render :partial=>'index', :layout=>false, :locals=>{:pre=>pre} end My controller spec before do @controller = MyController.new end it "should render the index partial" do @controller.expect_render(:partial=>'index', :layout=>false) #I don't know how to expect the :locals end As I mentioned, the spec failed , saying that "Undefined method 'expect_render' ". There might be some mistakes in my "before" block. Do I need to mock the controller or something else? Anyway, do any one know how to fix the problem? It will be even better if you guys could show me a piece of example code. Thanks!! -- View this message in context: http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12121894 Sent from the rspec-users mailing list archive at Nabble.com. From aslak.hellesoy at gmail.com Mon Aug 13 03:51:05 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 13 Aug 2007 09:51:05 +0200 Subject: [rspec-users] Test::Unit to RSpec Converter In-Reply-To: <85797B99-B2CD-4A33-A229-0ABEFAAFD89E@gmail.com> References: <85797B99-B2CD-4A33-A229-0ABEFAAFD89E@gmail.com> Message-ID: <8d961d900708130051l2acf88e8x46794cb3c2cc0ff8@mail.gmail.com> On 8/13/07, David Rice wrote: > Hey, just posting in case this is of interest. > > I just recently wrote a Rails plugin to convert Rails Test::Unit cases to > RSpec. > > http://www.davidjrice.co.uk/articles/2007/8/12/ruby-on-rails-plugin-test-unit-to-rspec-converter > > it's not going to work 100% in every case, but it's really helped me convert > old tests to the lovely RSpec :) > Thanks David, We used to have one of those too. The first one was similar to yours, then I wrote one based on ParseTree and Ruby2Ruby which did the transformation on the syntax tree level. We ditched it because it was too much work to maintain (it's still part of older releases - around 0.7 IIRC). In many cases, simple is better :-) Aslak > Best, > Dave > > > --- > David Rice > http://www.davidjrice.co.uk > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Mon Aug 13 04:01:12 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 13 Aug 2007 10:01:12 +0200 Subject: [rspec-users] How to use expect_render? In-Reply-To: <12121894.post@talk.nabble.com> References: <12121894.post@talk.nabble.com> Message-ID: <8d961d900708130101h4a4bceeelb2e26e61bbd65639@mail.gmail.com> On 8/13/07, Shaker wrote: > > Hi: > I am a rspec beginner. I have scratched my head for the whole afternoon, > trying to figure out a way of writing render expectation in controller spec. > However, I failed. It kept telling me that the 'expect_render' was an > undefined method. I have installed rspec 1.0.8 and rspec_on_rails as well. > Below is the controller to be tested. > > Controller > def index > pre = Array.new > render :partial=>'index', :layout=>false, :locals=>{:pre=>pre} > end > > My controller spec > before do > @controller = MyController.new > end > it "should render the index partial" do > @controller.expect_render(:partial=>'index', :layout=>false) #I don't > know how to expect the :locals > end > > As I mentioned, the spec failed , saying that "Undefined method > 'expect_render' ". There might be some mistakes in my "before" block. Do I > need to mock the controller or something else? Anyway, do any one know how > to fix the problem? It will be even better if you guys could show me a piece > of example code. > Thanks!! Have you looked here? http://rspec.rubyforge.org/documentation/rails/writing/views.html (you must use template.expect_render) Or perhaps you're looking for response.should render_template("path/to/template/for/action") HTH, Aslak > -- > View this message in context: http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12121894 > 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 aslak.hellesoy at gmail.com Mon Aug 13 04:07:00 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 13 Aug 2007 10:07:00 +0200 Subject: [rspec-users] Problem of using fixture in Rspec In-Reply-To: <12119520.post@talk.nabble.com> References: <12119520.post@talk.nabble.com> Message-ID: <8d961d900708130107k130d91d1pd22ecd841719464f@mail.gmail.com> On 8/13/07, Shaker wrote: > > Dear Fellows: > I was using fixtures in the model tests using Rspec. I found that the > test data specified in the fixtures was stored in the test database once I > ran the spec and won't be removed anyway. Is my observation correct? Yes, this is how Rails does it. > There might be another problem regarding the fixtures. When I ran the > specs one by one, it was working. However, it failed when I tried to run all > the specs in one command. It seemed that the test data which was modified by > one spec caused the other spec which accessed that particular data to fail. > In other words, the data is actually kind of public to all specs, so the > specs shares one copy of test data. > If my observation is correct, are there any ways to overcome these > problems? Is it possible that each single spec owns its test data so that > the modifications on the data will not affect other specs? My hunch is that you'll get the same behaviour with Test::Unit (try it). You probably need to tell your spec that it must use more fixture tables, to clean up before each example (it block). Aslak > Cheers! > -- > View this message in context: http://www.nabble.com/Problem-of-using-fixture-in-Rspec-tf4258669.html#a12119520 > 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 flyeminent at hotmail.com Mon Aug 13 04:15:46 2007 From: flyeminent at hotmail.com (Shaker) Date: Mon, 13 Aug 2007 01:15:46 -0700 (PDT) Subject: [rspec-users] How to use expect_render? In-Reply-To: <8d961d900708130101h4a4bceeelb2e26e61bbd65639@mail.gmail.com> References: <12121894.post@talk.nabble.com> <8d961d900708130101h4a4bceeelb2e26e61bbd65639@mail.gmail.com> Message-ID: <12122511.post@talk.nabble.com> Hello, Aslak: I know we could do template.expect_render somehow, although I haven't tried that out. But the rspec developer said that we could now actually use controller.expect_render in controller specs, which caused me confused. You may want to have a look at this: http://rspec.rubyforge.org/documentation/rails/writing/controllers.html writing controller spec Thanks, regards. aslak hellesoy wrote: > > On 8/13/07, Shaker wrote: >> >> Hi: >> I am a rspec beginner. I have scratched my head for the whole >> afternoon, >> trying to figure out a way of writing render expectation in controller >> spec. >> However, I failed. It kept telling me that the 'expect_render' was an >> undefined method. I have installed rspec 1.0.8 and rspec_on_rails as >> well. >> Below is the controller to be tested. >> >> Controller >> def index >> pre = Array.new >> render :partial=>'index', :layout=>false, :locals=>{:pre=>pre} >> end >> >> My controller spec >> before do >> @controller = MyController.new >> end >> it "should render the index partial" do >> @controller.expect_render(:partial=>'index', :layout=>false) #I >> don't >> know how to expect the :locals >> end >> >> As I mentioned, the spec failed , saying that "Undefined method >> 'expect_render' ". There might be some mistakes in my "before" block. Do >> I >> need to mock the controller or something else? Anyway, do any one know >> how >> to fix the problem? It will be even better if you guys could show me a >> piece >> of example code. >> Thanks!! > > Have you looked here? > > http://rspec.rubyforge.org/documentation/rails/writing/views.html > > (you must use template.expect_render) > Or perhaps you're looking for response.should > render_template("path/to/template/for/action") > > HTH, > Aslak > >> -- >> View this message in context: >> http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12121894 >> 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 >> > _______________________________________________ > 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/How-to-use-expect_render--tf4259590.html#a12122511 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Mon Aug 13 04:41:47 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 13 Aug 2007 04:41:47 -0400 Subject: [rspec-users] How to use expect_render? In-Reply-To: <12122511.post@talk.nabble.com> References: <12121894.post@talk.nabble.com> <8d961d900708130101h4a4bceeelb2e26e61bbd65639@mail.gmail.com> <12122511.post@talk.nabble.com> Message-ID: <57c63afe0708130141g6d906ab0kd0699d48668abb0c@mail.gmail.com> On 8/13/07, Shaker wrote: > > Hello, Aslak: > I know we could do template.expect_render somehow, although I haven't > tried that out. But the rspec developer Aslak is one of the rspec developers. :) > said that we could now actually use > controller.expect_render in controller specs, which caused me confused. You > may want to have a look at this: > http://rspec.rubyforge.org/documentation/rails/writing/controllers.html > writing controller spec > Thanks, regards. > > aslak hellesoy wrote: > > > > On 8/13/07, Shaker wrote: > >> > >> Hi: > >> I am a rspec beginner. I have scratched my head for the whole > >> afternoon, > >> trying to figure out a way of writing render expectation in controller > >> spec. > >> However, I failed. It kept telling me that the 'expect_render' was an > >> undefined method. I have installed rspec 1.0.8 and rspec_on_rails as > >> well. > >> Below is the controller to be tested. > >> > >> Controller > >> def index > >> pre = Array.new > >> render :partial=>'index', :layout=>false, :locals=>{:pre=>pre} > >> end > >> > >> My controller spec > >> before do > >> @controller = MyController.new > >> end > >> it "should render the index partial" do > >> @controller.expect_render(:partial=>'index', :layout=>false) #I > >> don't > >> know how to expect the :locals > >> end Don't create an instance of the controller directly. Use either: describe MyController do ... or describe "MyController" do controller_name :my ... RSpec mixes some methods into the controller in these cases (including expect_render) but does not in the case you describe because it initializes the controller directly. Cheers, David > >> > >> As I mentioned, the spec failed , saying that "Undefined method > >> 'expect_render' ". There might be some mistakes in my "before" block. Do > >> I > >> need to mock the controller or something else? Anyway, do any one know > >> how > >> to fix the problem? It will be even better if you guys could show me a > >> piece > >> of example code. > >> Thanks!! > > > > Have you looked here? > > > > http://rspec.rubyforge.org/documentation/rails/writing/views.html > > > > (you must use template.expect_render) > > Or perhaps you're looking for response.should > > render_template("path/to/template/for/action") > > > > HTH, > > Aslak > > > >> -- > >> View this message in context: > >> http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12121894 > >> 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 > >> > > _______________________________________________ > > 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/How-to-use-expect_render--tf4259590.html#a12122511 > 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 aslak.hellesoy at gmail.com Mon Aug 13 04:48:51 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 13 Aug 2007 10:48:51 +0200 Subject: [rspec-users] How to use expect_render? In-Reply-To: <57c63afe0708130141g6d906ab0kd0699d48668abb0c@mail.gmail.com> References: <12121894.post@talk.nabble.com> <8d961d900708130101h4a4bceeelb2e26e61bbd65639@mail.gmail.com> <12122511.post@talk.nabble.com> <57c63afe0708130141g6d906ab0kd0699d48668abb0c@mail.gmail.com> Message-ID: <8d961d900708130148w69d6d2d8nf1ed2d417615535a@mail.gmail.com> On 8/13/07, David Chelimsky wrote: > On 8/13/07, Shaker wrote: > > > > Hello, Aslak: > > I know we could do template.expect_render somehow, although I haven't > > tried that out. But the rspec developer > > Aslak is one of the rspec developers. :) > > > said that we could now actually use > > controller.expect_render in controller specs, which caused me confused. You > > may want to have a look at this: > > http://rspec.rubyforge.org/documentation/rails/writing/controllers.html > > writing controller spec > > Thanks, regards. > > > > aslak hellesoy wrote: > > > > > > On 8/13/07, Shaker wrote: > > >> > > >> Hi: > > >> I am a rspec beginner. I have scratched my head for the whole > > >> afternoon, > > >> trying to figure out a way of writing render expectation in controller > > >> spec. > > >> However, I failed. It kept telling me that the 'expect_render' was an > > >> undefined method. I have installed rspec 1.0.8 and rspec_on_rails as > > >> well. > > >> Below is the controller to be tested. > > >> > > >> Controller > > >> def index > > >> pre = Array.new > > >> render :partial=>'index', :layout=>false, :locals=>{:pre=>pre} > > >> end > > >> > > >> My controller spec > > >> before do > > >> @controller = MyController.new > > >> end > > >> it "should render the index partial" do > > >> @controller.expect_render(:partial=>'index', :layout=>false) #I > > >> don't > > >> know how to expect the :locals > > >> end > > Don't create an instance of the controller directly. Use either: > > describe MyController do > ... > > or > > describe "MyController" do > controller_name :my > ... > Doh, I missed that. > RSpec mixes some methods into the controller in these cases (including > expect_render) but does not in the case you describe because it > initializes the controller directly. > I wonder if this is a common mistake among newcomers to RSpec (since Rails/Test::Unit does it that way). I don't think we should build in any warning mechanisms, but I'll update the page mentioning this. Aslak > Cheers, > David > > > > >> > > >> As I mentioned, the spec failed , saying that "Undefined method > > >> 'expect_render' ". There might be some mistakes in my "before" block. Do > > >> I > > >> need to mock the controller or something else? Anyway, do any one know > > >> how > > >> to fix the problem? It will be even better if you guys could show me a > > >> piece > > >> of example code. > > >> Thanks!! > > > > > > Have you looked here? > > > > > > http://rspec.rubyforge.org/documentation/rails/writing/views.html > > > > > > (you must use template.expect_render) > > > Or perhaps you're looking for response.should > > > render_template("path/to/template/for/action") > > > > > > HTH, > > > Aslak > > > > > >> -- > > >> View this message in context: > > >> http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12121894 > > >> 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 > > >> > > > _______________________________________________ > > > 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/How-to-use-expect_render--tf4259590.html#a12122511 > > 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 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From flyeminent at hotmail.com Mon Aug 13 05:21:01 2007 From: flyeminent at hotmail.com (Shaker) Date: Mon, 13 Aug 2007 02:21:01 -0700 (PDT) Subject: [rspec-users] How to use expect_render? In-Reply-To: <12121894.post@talk.nabble.com> References: <12121894.post@talk.nabble.com> Message-ID: <12123224.post@talk.nabble.com> Dear Aslak and David: I have tried two possible ways to get expect_render work. However, they all failed. My combinations are: my controller spec describe MyController do before do #do nothing end it "should render the index partial" do controller.expect_render(:partial=>'index') #1st way MyController.expect_render(:partial=>'index') #2nd way end end The 1st way gave me an error: Mock 'expect_render_mock_proxy' expected :render with ({:partial=>'index'}) once, but received it 0 times The 2nd way gave me an error: undefined method 'expect_render' Do I need to mock the controller or there are some mistakes I have made in my spec? Shaker wrote: > > Hi: > I am a rspec beginner. I have scratched my head for the whole > afternoon, trying to figure out a way of writing render expectation in > controller spec. However, I failed. It kept telling me that the > 'expect_render' was an undefined method. I have installed rspec 1.0.8 and > rspec_on_rails as well. Below is the controller to be tested. > > Controller > def index > pre = Array.new > render :partial=>'index', :layout=>false, :locals=>{:pre=>pre} > end > > My controller spec > before do > @controller = MyController.new > end > it "should render the index partial" do > @controller.expect_render(:partial=>'index', :layout=>false) #I > don't know how to expect the :locals > end > > As I mentioned, the spec failed , saying that "Undefined method > 'expect_render' ". There might be some mistakes in my "before" block. Do I > need to mock the controller or something else? Anyway, do any one know how > to fix the problem? It will be even better if you guys could show me a > piece of example code. > Thanks!! > -- View this message in context: http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12123224 Sent from the rspec-users mailing list archive at Nabble.com. From aslak.hellesoy at gmail.com Mon Aug 13 05:43:36 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 13 Aug 2007 11:43:36 +0200 Subject: [rspec-users] How to use expect_render? In-Reply-To: <12123224.post@talk.nabble.com> References: <12121894.post@talk.nabble.com> <12123224.post@talk.nabble.com> Message-ID: <8d961d900708130243w28985a2dmf7ae9ebda7397c92@mail.gmail.com> On 8/13/07, Shaker wrote: > > Dear Aslak and David: > I have tried two possible ways to get expect_render work. However, they > all failed. My combinations are: > my controller spec > describe MyController do > before do > #do nothing > end > it "should render the index partial" do > controller.expect_render(:partial=>'index') #1st way That's the way to go > MyController.expect_render(:partial=>'index') #2nd way > end > end > > The 1st way gave me an error: Mock 'expect_render_mock_proxy' expected > :render with ({:partial=>'index'}) once, but received it 0 times You've forgotten to run the action. RSpec doesn't magically guess what action is supposed to render your index partial. it "should render the index partial" do controller.expect_render(:partial=>'index') get 'index' end > The 2nd way gave me an error: undefined method 'expect_render' > Do I need to mock the controller or there are some mistakes I have made in > my spec? > > Shaker wrote: > > > > Hi: > > I am a rspec beginner. I have scratched my head for the whole > > afternoon, trying to figure out a way of writing render expectation in > > controller spec. However, I failed. It kept telling me that the > > 'expect_render' was an undefined method. I have installed rspec 1.0.8 and > > rspec_on_rails as well. Below is the controller to be tested. > > > > Controller > > def index > > pre = Array.new > > render :partial=>'index', :layout=>false, :locals=>{:pre=>pre} > > end > > > > My controller spec > > before do > > @controller = MyController.new > > end > > it "should render the index partial" do > > @controller.expect_render(:partial=>'index', :layout=>false) #I > > don't know how to expect the :locals > > end > > > > As I mentioned, the spec failed , saying that "Undefined method > > 'expect_render' ". There might be some mistakes in my "before" block. Do I > > need to mock the controller or something else? Anyway, do any one know how > > to fix the problem? It will be even better if you guys could show me a > > piece of example code. > > Thanks!! > > > > -- > View this message in context: http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12123224 > 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 nemo7467 at gmail.com Mon Aug 13 06:51:01 2007 From: nemo7467 at gmail.com (David Parker) Date: Mon, 13 Aug 2007 05:51:01 -0500 Subject: [rspec-users] Scope and specing models Message-ID: <9a07e4a80708130351la69792fjef4bc2dcdbd7e74a@mail.gmail.com> On 8/12/07, David Parker wrote: > Hello all, I'm currently having an issue with some specs, specifically scope > issues (probably more of a scope issue than a spec issue at this point)... > Here's the error: > ActiveRecord::AssociationTypeMismatch in 'A new User should > know what role it has' > Role expected, got NilClass > D:/ruby/projects/restful_authentication_test/config/../app/models/role.rb:5:in > `add' > ./spec/models/user_spec.rb:62: > script/spec:4: > > Here's the user.rb > http://pastie.caboo.se/87029 > > role.rb > http://pastie.caboo.se/87030 > > user_spec.rb > http://pastie.caboo.se/87032 > > The code is based off of RESTful authentication + > Ben Curtis' user roles in Rails Application: > http://www.bencurtis.com/archives/2007/06/user-roles -in-rails-applications/ > users.roles is an AssociationProxy, not the Role class, where you have defined the method add(user, role). You should be able to eliminate that method in the Role class and just pass the role on line 62 of your spec: users.roles.add(role) ____________ I went ahead an eliminated the add method in the role class, and now, with the same spec as above these are the results I get, depending on what I have for line 62... Users.roles.add(role): NameError in 'A new User should know what role it has' uninitialized constant Users User.roles.add(role): NoMethodError in 'A new User should know what role it has' undefined method `roles' for User:Class user.roles.add(role): NoMethodError in 'A new User should know what role it has' undefined method `add' for Role:Class users.roles.add(role): NameError in 'A new User should know what role it has' undefined local variable or method `users' If I go ahead and do something like: users = User.find(:all) before doing users.roles.add(role), then I get: NoMethodError in 'A new User should know what role it has' undefined method `roles' are my associations somehow not registering? > > Thanks for your help! > -- > dp > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- dp -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070813/954f6dcb/attachment.html From aslak.hellesoy at gmail.com Mon Aug 13 07:20:13 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 13 Aug 2007 13:20:13 +0200 Subject: [rspec-users] Scope and specing models In-Reply-To: <9a07e4a80708130351la69792fjef4bc2dcdbd7e74a@mail.gmail.com> References: <9a07e4a80708130351la69792fjef4bc2dcdbd7e74a@mail.gmail.com> Message-ID: <8d961d900708130420o3b9738d5le4e9fbd04df30a05@mail.gmail.com> On 8/13/07, David Parker wrote: > On 8/12/07, David Parker wrote: > > Hello all, I'm currently having an issue with some specs, specifically > scope > > issues (probably more of a scope issue than a spec issue at this point)... > > Here's the error: > > ActiveRecord::AssociationTypeM > ismatch in 'A new User should > > know what role it has' > > Role expected, got NilClass > > > D:/ruby/projects/restful_authentication_test/config/../app/models/role.rb:5:in > > `add' > > ./spec/models/user_spec.rb:62: > > script/spec:4: > > > > Here's the user.rb > > http://pastie.caboo.se/87029 > > > > role.rb > > http://pastie.caboo.se/87030 > > > > user_spec.rb > > http://pastie.caboo.se/87032 > > > > The code is based off of RESTful authentication + > > Ben Curtis' user roles in Rails Application: > > > http://www.bencurtis.com/archives/2007/06/user-roles-in-rails-applications/ > > > users.roles is an AssociationProxy, not the Role class, where you have > defined the method add(user, role). You should be able to eliminate > that method in the Role class and just pass the role on line 62 of > your spec: > > users.roles.add(role) > ____________ > I went ahead an eliminated the add method in the role class, and now, with > the same spec as above these are the results I get, depending on what I have > for line 62... > It looks like all of your questions are Ruby or Rails specific, not RSpec specific. There are other more suitable forums for that. > Users.roles.add(role): > NameError in 'A new User should know what role it has' > uninitialized constant Users > This is Ruby telling you that there is no class named Users. > User.roles.add(role): > NoMethodError in 'A new User should know what role it has' > undefined method `roles' for User:Class > Only ActiveRecord instances (not classes) have associations. You can find out more by reading up on ActiveRecord associations. > user.roles.add(role): > NoMethodError in 'A new User should know what role it has' > undefined method `add' for Role:Class > I don't think Rails has_many associations have an #add method. Use #<< or #build or #create http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M000642 > users.roles.add(role): > NameError in 'A new User should know what role it has' > undefined local variable or method `users' > This is Ruby telling you that you don't have a users variable (or method) in the current scope. > If I go ahead and do something like: > users = User.find(:all) > before doing users.roles.add(role), then I get: > NoMethodError in 'A new User should know what role it has' > undefined method `roles' > I think you're trying to add a role to *one* user, not all of them. A collection of User (which is what your users variable is) doesn't have a roles method, but each of the User *instances* in that collection do. Try this: user = User.find(:first) user.should_not have_role('master') user.add_role('master') user.should have_role('master') > are my associations somehow not registering? > No, they're registering fine, but I think you need to study Ruby and Rails/ActiveRecord more. You're not using ActiveRecord properly. HTH, Aslak > > > > Thanks for your help! > > -- > > dp > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > -- > > dp > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jonathan at parkerhill.com Mon Aug 13 09:00:08 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Mon, 13 Aug 2007 09:00:08 -0400 Subject: [rspec-users] expect_render not? Message-ID: <8D3ADA32-F6F0-4BBC-BBAC-6C2C9E7B896B@parkerhill.com> hi, I have a template that conditionally renders a partial. Is there a way to test that a partial is NOT rendered? :) From dchelimsky at gmail.com Mon Aug 13 09:06:25 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 13 Aug 2007 09:06:25 -0400 Subject: [rspec-users] expect_render not? In-Reply-To: <8D3ADA32-F6F0-4BBC-BBAC-6C2C9E7B896B@parkerhill.com> References: <8D3ADA32-F6F0-4BBC-BBAC-6C2C9E7B896B@parkerhill.com> Message-ID: <57c63afe0708130606m71ef6d7al5eccc1aaadd615f6@mail.gmail.com> On 8/13/07, Jonathan Linowes wrote: > hi, I have a template that conditionally renders a partial. Is there > a way to test that a partial is NOT rendered? > :) template.should_render(:partial => '/partial/that/should/not/get/rendered').never > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists-rspec at shopwatch.org Mon Aug 13 17:41:27 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Mon, 13 Aug 2007 17:41:27 -0400 Subject: [rspec-users] Backtrace tweaker - broken or me? Message-ID: <46C0D007.3090406@jay.fm> Using 1.0.8, I just realized that I've been scrolling through pages of backtraces when rspec is supposed to clean them up for me. This is a new development machine, so I'm not sure if older versions worked or not. I'm running Ruby 1.8.6, Rails edge, Mac OS X 10.4.10. I've verified that the QuietBacktraceTweaker is the one that's running. However, error.backtrace seems to have only one big element in it (with multiple lines separated by \n), that whole line gets ignored because it matches, and then the whole backtrace gets printed out anyway somehow. I'm heading home and don't have time to dig into it right now, but has anyone else seen this? Jay Levitt From flyeminent at hotmail.com Mon Aug 13 20:58:45 2007 From: flyeminent at hotmail.com (Shaker) Date: Mon, 13 Aug 2007 17:58:45 -0700 (PDT) Subject: [rspec-users] How to use expect_render? In-Reply-To: <8d961d900708130243w28985a2dmf7ae9ebda7397c92@mail.gmail.com> References: <12121894.post@talk.nabble.com> <12123224.post@talk.nabble.com> <8d961d900708130243w28985a2dmf7ae9ebda7397c92@mail.gmail.com> Message-ID: <12136984.post@talk.nabble.com> Dear Aslak: Sorry to bother you over and over again. I did follow your instruction to write the controller spec, but...the thing is not getting better.:-( I'd like to post my code again, hopefully you would figure it out. My Controller class MyController def index pre = Array.new render :partial=>'index', layout=>false, locals=>{:pre=>pre} end end ------------------------------------------------------------ My Controller spec describe MyController do it "should render the index partial" do controller.expect_render(:partial=>'index', :layout=>false) get 'index' end end ------------------------------------------------------------ By the way, I am using JRuby rather than ruby. Hence my command to run the spec above is jruby --command spec spec/controllers/my_controller_spec.rb --format specdoc It always gave me an error:Mock 'expect_render_mock_proxy' expected :render with ({:partial=>"index"}) once, but received it 0 times. Is it because "expect_render" is not compatible with JRuby or I forgot to mock something? Thanks a lot. Regards. aslak hellesoy wrote: > > On 8/13/07, Shaker wrote: >> >> Dear Aslak and David: >> I have tried two possible ways to get expect_render work. However, >> they >> all failed. My combinations are: >> my controller spec >> describe MyController do >> before do >> #do nothing >> end >> it "should render the index partial" do >> controller.expect_render(:partial=>'index') #1st way > > That's the way to go > >> MyController.expect_render(:partial=>'index') #2nd way >> end >> end >> >> The 1st way gave me an error: Mock 'expect_render_mock_proxy' expected >> :render with ({:partial=>'index'}) once, but received it 0 times > > You've forgotten to run the action. RSpec doesn't magically guess what > action is supposed to render your index partial. > > it "should render the index partial" do > controller.expect_render(:partial=>'index') > get 'index' > end > > >> The 2nd way gave me an error: undefined method 'expect_render' >> Do I need to mock the controller or there are some mistakes I have made >> in >> my spec? >> >> Shaker wrote: >> > >> > Hi: >> > I am a rspec beginner. I have scratched my head for the whole >> > afternoon, trying to figure out a way of writing render expectation in >> > controller spec. However, I failed. It kept telling me that the >> > 'expect_render' was an undefined method. I have installed rspec 1.0.8 >> and >> > rspec_on_rails as well. Below is the controller to be tested. >> > >> > Controller >> > def index >> > pre = Array.new >> > render :partial=>'index', :layout=>false, :locals=>{:pre=>pre} >> > end >> > >> > My controller spec >> > before do >> > @controller = MyController.new >> > end >> > it "should render the index partial" do >> > @controller.expect_render(:partial=>'index', :layout=>false) #I >> > don't know how to expect the :locals >> > end >> > >> > As I mentioned, the spec failed , saying that "Undefined method >> > 'expect_render' ". There might be some mistakes in my "before" block. >> Do I >> > need to mock the controller or something else? Anyway, do any one know >> how >> > to fix the problem? It will be even better if you guys could show me a >> > piece of example code. >> > Thanks!! >> > >> >> -- >> View this message in context: >> http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12123224 >> 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 >> > _______________________________________________ > 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/How-to-use-expect_render--tf4259590.html#a12136984 Sent from the rspec-users mailing list archive at Nabble.com. From zach.dennis at gmail.com Tue Aug 14 00:45:08 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 14 Aug 2007 00:45:08 -0400 Subject: [rspec-users] How to use expect_render? In-Reply-To: <12136984.post@talk.nabble.com> References: <12121894.post@talk.nabble.com> <12123224.post@talk.nabble.com> <8d961d900708130243w28985a2dmf7ae9ebda7397c92@mail.gmail.com> <12136984.post@talk.nabble.com> Message-ID: <85d99afe0708132145x7644d635wd90ad5116bd46c28@mail.gmail.com> On 8/13/07, Shaker wrote: > > Dear Aslak: > Sorry to bother you over and over again. I did follow your instruction to > write the controller spec, but...the thing is not getting better.:-( > I'd like to post my code again, hopefully you would figure it out. > My Controller > class MyController > def index > pre = Array.new > render :partial=>'index', layout=>false, locals=>{:pre=>pre} > end > end > ------------------------------------------------------------ > My Controller spec > describe MyController do > it "should render the index partial" do > controller.expect_render(:partial=>'index', :layout=>false) > get 'index' > end > end > ------------------------------------------------------------ > By the way, I am using JRuby rather than ruby. Hence my command to run the > spec above is > jruby --command spec spec/controllers/my_controller_spec.rb --format specdoc > It always gave me an error:Mock 'expect_render_mock_proxy' expected :render > with > ({:partial=>"index"}) once, but received it 0 times. > Is it because "expect_render" is not compatible with JRuby or I forgot to > mock something? > Thanks a lot. > Regards. > Your failing test case seems to indicate a correct failure. You are expecting: controller.expect_render(:partial=>'index', :layout=>false) but you are passing in: render :partial=>'index', layout=>false, locals=>{:pre=>pre} Try updating your test to expect the :locals or try removing them from your call to render, whichever is correct for what you are doing, Zach From zach.dennis at gmail.com Tue Aug 14 00:58:58 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 14 Aug 2007 00:58:58 -0400 Subject: [rspec-users] expect_render, why does there need to be a warning Message-ID: <85d99afe0708132158ua34f8beq61bd3f3a03c3eb14@mail.gmail.com> There is a warning on the web site about expect_render and stub_render: "WARNING: expect_render and stub_render, while very useful, act differently from standard Message Expectations (a.k.a. mock expectations), which would never pass calls through to the real object. This can be very confusing when there are failures if you're not aware of this fact, because some calls will be passed through while others will not. This is especially confusing when you use stub_render because, as with all Method Stubs, you will get very little feedback about what is going on." My questions: Is this a sign that expect_render is doing to much? Is there a benefit from having expect_render and stub_render sometimes pass the render call to the underlying template object? Why not force all partials to be tested individually? Testing partials individually seems like a cleaner, more consistent and less confusing route to go, especially when you consider the nesting of paritals which render other partials. Zach From zach.dennis at gmail.com Tue Aug 14 01:01:37 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 14 Aug 2007 01:01:37 -0400 Subject: [rspec-users] [ANN] RSpec-1.0.8 In-Reply-To: <57c63afe0708122258r6ae4494cld9353dc135c00c94@mail.gmail.com> References: <57c63afe0708122258r6ae4494cld9353dc135c00c94@mail.gmail.com> Message-ID: <85d99afe0708132201s7b3edba2lf1fc14adc4f8a399@mail.gmail.com> I've been waiting for this since June so I can have expect_render "officially" . Thanks for the hard work! Zach On 8/13/07, David Chelimsky wrote: > The RSpec Development Team is pleased to announce the release of RSpec-1.0.8. > > RSpec 1.0.6 is the "holy cow, batman, it's been a long time since we > released and there are a ton of bug fixes, patches and even new > features" release. RSpec 1.0.7 and 1.0.8 deal with a regression > introduced in 1.0.6 and a hiccup in releasing 1.0.7, respectively. > > == RSpec > > RSpec is a Behaviour Driven Development framework which plays the same > role that a unit testing framework would play in Test Driven > Development, but does so using words and structures that better > support BDD. > > http://rspec.rubyforge.org > > == rspec_on_rails > > rspec_on_rails is a Ruby on Rails plugin that supports a BDD approach > to developing the various layers of objects within a Rails > application. > > See http://rspec.rubyforge.org/documentation/rails/index.html > > == Installation > > http://rspec.rubyforge.org/download.html > http://rspec.rubyforge.org/documentation/rails/install.html > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Tue Aug 14 01:15:59 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 14 Aug 2007 01:15:59 -0400 Subject: [rspec-users] [ANN] RSpec-1.0.8 In-Reply-To: <85d99afe0708132201s7b3edba2lf1fc14adc4f8a399@mail.gmail.com> References: <57c63afe0708122258r6ae4494cld9353dc135c00c94@mail.gmail.com> <85d99afe0708132201s7b3edba2lf1fc14adc4f8a399@mail.gmail.com> Message-ID: <85d99afe0708132215l2d040d5by8ffa5bb3ea151e43@mail.gmail.com> It looks like officially was in 1.0.6, but I don't recall seeing an announcement on 1.0.6 or 1.0.7 ... perhaps I just missed it, Zach On 8/14/07, Zach Dennis wrote: > I've been waiting for this since June so I can have expect_render > "officially" . > > Thanks for the hard work! > > Zach > > On 8/13/07, David Chelimsky wrote: > > The RSpec Development Team is pleased to announce the release of RSpec-1.0.8. > > > > RSpec 1.0.6 is the "holy cow, batman, it's been a long time since we > > released and there are a ton of bug fixes, patches and even new > > features" release. RSpec 1.0.7 and 1.0.8 deal with a regression > > introduced in 1.0.6 and a hiccup in releasing 1.0.7, respectively. > > > > == RSpec > > > > RSpec is a Behaviour Driven Development framework which plays the same > > role that a unit testing framework would play in Test Driven > > Development, but does so using words and structures that better > > support BDD. > > > > http://rspec.rubyforge.org > > > > == rspec_on_rails > > > > rspec_on_rails is a Ruby on Rails plugin that supports a BDD approach > > to developing the various layers of objects within a Rails > > application. > > > > See http://rspec.rubyforge.org/documentation/rails/index.html > > > > == Installation > > > > http://rspec.rubyforge.org/download.html > > http://rspec.rubyforge.org/documentation/rails/install.html > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From aslak.hellesoy at gmail.com Tue Aug 14 01:28:41 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 14 Aug 2007 07:28:41 +0200 Subject: [rspec-users] Backtrace tweaker - broken or me? In-Reply-To: <46C0D007.3090406@jay.fm> References: <46C0D007.3090406@jay.fm> Message-ID: <8d961d900708132228k698b12fdo9919367bfba48d29@mail.gmail.com> On 8/13/07, Jay Levitt wrote: > Using 1.0.8, I just realized that I've been scrolling through pages of > backtraces when rspec is supposed to clean them up for me. This is a > new development machine, so I'm not sure if older versions worked or > not. I'm running Ruby 1.8.6, Rails edge, Mac OS X 10.4.10. > > I've verified that the QuietBacktraceTweaker is the one that's running. > However, error.backtrace seems to have only one big element in it > (with multiple lines separated by \n), that whole line gets ignored > because it matches, and then the whole backtrace gets printed out anyway > somehow. I'm heading home and don't have time to dig into it right now, > but has anyone else seen this? > How can we reproduce it? Aslak > Jay Levitt > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Aug 14 01:38:52 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 14 Aug 2007 01:38:52 -0400 Subject: [rspec-users] [ANN] RSpec-1.0.8 In-Reply-To: <85d99afe0708132215l2d040d5by8ffa5bb3ea151e43@mail.gmail.com> References: <57c63afe0708122258r6ae4494cld9353dc135c00c94@mail.gmail.com> <85d99afe0708132201s7b3edba2lf1fc14adc4f8a399@mail.gmail.com> <85d99afe0708132215l2d040d5by8ffa5bb3ea151e43@mail.gmail.com> Message-ID: <58BFE93D-49BA-4D65-8513-A018B79C017F@railsnewbie.com> On Aug 14, 2007, at 1:15 AM, Zach Dennis wrote: > It looks like officially was in 1.0.6, but I don't recall seeing an > announcement on 1.0.6 or 1.0.7 ... perhaps I just missed it, They were tiny releases (mostly, if not all, bug fixes) Scott From flyeminent at hotmail.com Tue Aug 14 01:44:01 2007 From: flyeminent at hotmail.com (Shaker) Date: Mon, 13 Aug 2007 22:44:01 -0700 (PDT) Subject: [rspec-users] How to use expect_render? In-Reply-To: <8d961d900708130243w28985a2dmf7ae9ebda7397c92@mail.gmail.com> References: <12121894.post@talk.nabble.com> <12123224.post@talk.nabble.com> <8d961d900708130243w28985a2dmf7ae9ebda7397c92@mail.gmail.com> Message-ID: <12136984.post@talk.nabble.com> Dear Fellows: Sorry to bother you over and over again. I did follow your instruction to write the controller spec, but...the thing is not getting better.:-( I'd like to post my code again, hopefully you would figure it out. My Controller class MyController def index pre = Array.new render :partial=>'index', :layout=>false, :locals=>{:pre=>pre} end end Notes: sorry, I just missed the colons for layout and locals, but I am afraid that the spec still failed even I added in the colons. ------------------------------------------------------------ My Controller spec describe MyController do it "should render the index partial" do controller.expect_render(:partial=>'index', :layout=>false) get 'index' end end ------------------------------------------------------------ By the way, I am using JRuby rather than ruby. Hence my command to run the spec above is jruby --command spec spec/controllers/my_controller_spec.rb --format specdoc It always gave me an error:Mock 'expect_render_mock_proxy' expected :render with ({:partial=>"index"}) once, but received it 0 times. Is it because "expect_render" is not compatible with JRuby or I forgot to mock something? Thanks a lot. Regards. aslak hellesoy wrote: > > On 8/13/07, Shaker wrote: >> >> Dear Aslak and David: >> I have tried two possible ways to get expect_render work. However, >> they >> all failed. My combinations are: >> my controller spec >> describe MyController do >> before do >> #do nothing >> end >> it "should render the index partial" do >> controller.expect_render(:partial=>'index') #1st way > > That's the way to go > >> MyController.expect_render(:partial=>'index') #2nd way >> end >> end >> >> The 1st way gave me an error: Mock 'expect_render_mock_proxy' expected >> :render with ({:partial=>'index'}) once, but received it 0 times > > You've forgotten to run the action. RSpec doesn't magically guess what > action is supposed to render your index partial. > > it "should render the index partial" do > controller.expect_render(:partial=>'index') > get 'index' > end > > >> The 2nd way gave me an error: undefined method 'expect_render' >> Do I need to mock the controller or there are some mistakes I have made >> in >> my spec? >> >> Shaker wrote: >> > >> > Hi: >> > I am a rspec beginner. I have scratched my head for the whole >> > afternoon, trying to figure out a way of writing render expectation in >> > controller spec. However, I failed. It kept telling me that the >> > 'expect_render' was an undefined method. I have installed rspec 1.0.8 >> and >> > rspec_on_rails as well. Below is the controller to be tested. >> > >> > Controller >> > def index >> > pre = Array.new >> > render :partial=>'index', :layout=>false, :locals=>{:pre=>pre} >> > end >> > >> > My controller spec >> > before do >> > @controller = MyController.new >> > end >> > it "should render the index partial" do >> > @controller.expect_render(:partial=>'index', :layout=>false) #I >> > don't know how to expect the :locals >> > end >> > >> > As I mentioned, the spec failed , saying that "Undefined method >> > 'expect_render' ". There might be some mistakes in my "before" block. >> Do I >> > need to mock the controller or something else? Anyway, do any one know >> how >> > to fix the problem? It will be even better if you guys could show me a >> > piece of example code. >> > Thanks!! >> > >> >> -- >> View this message in context: >> http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12123224 >> 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 >> > _______________________________________________ > 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/How-to-use-expect_render--tf4259590.html#a12136984 Sent from the rspec-users mailing list archive at Nabble.com. From aslak.hellesoy at gmail.com Tue Aug 14 01:50:55 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 14 Aug 2007 07:50:55 +0200 Subject: [rspec-users] Backtrace tweaker - broken or me? In-Reply-To: <8d961d900708132228k698b12fdo9919367bfba48d29@mail.gmail.com> References: <46C0D007.3090406@jay.fm> <8d961d900708132228k698b12fdo9919367bfba48d29@mail.gmail.com> Message-ID: <8d961d900708132250o3204fab9sb30bc2111748a1f3@mail.gmail.com> On 8/14/07, aslak hellesoy wrote: > On 8/13/07, Jay Levitt wrote: > > Using 1.0.8, I just realized that I've been scrolling through pages of > > backtraces when rspec is supposed to clean them up for me. This is a > > new development machine, so I'm not sure if older versions worked or > > not. I'm running Ruby 1.8.6, Rails edge, Mac OS X 10.4.10. > > > > I've verified that the QuietBacktraceTweaker is the one that's running. > > However, error.backtrace seems to have only one big element in it > > (with multiple lines separated by \n), that whole line gets ignored > > because it matches, and then the whole backtrace gets printed out anyway > > somehow. I'm heading home and don't have time to dig into it right now, > > but has anyone else seen this? > > > > How can we reproduce it? > Never mind, I saw the tracker issue. > Aslak > > > Jay Levitt > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From dchelimsky at gmail.com Tue Aug 14 02:16:05 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 14 Aug 2007 02:16:05 -0400 Subject: [rspec-users] expect_render, why does there need to be a warning In-Reply-To: <85d99afe0708132158ua34f8beq61bd3f3a03c3eb14@mail.gmail.com> References: <85d99afe0708132158ua34f8beq61bd3f3a03c3eb14@mail.gmail.com> Message-ID: <57c63afe0708132316m467f4af7y6fc019096bff2d98@mail.gmail.com> On 8/14/07, Zach Dennis wrote: > There is a warning on the web site about expect_render and stub_render: > > "WARNING: expect_render and stub_render, while very useful, act > differently from standard Message Expectations (a.k.a. mock > expectations), which would never pass calls through to the real > object. This can be very confusing when there are failures if you're > not aware of this fact, because some calls will be passed through > while others will not. This is especially confusing when you use > stub_render because, as with all Method Stubs, you will get very > little feedback about what is going on." > > My questions: > > Is this a sign that expect_render is doing to much? > Is there a benefit from having expect_render and stub_render sometimes > pass the render call to the underlying template object? > Why not force all partials to be tested individually? > > Testing partials individually seems like a cleaner, more consistent > and less confusing route to go, especially when you consider the > nesting of paritals which render other partials. That's the whole reason for the existence of expect_render. If you're spec'ing '_outer_partial' and you want to specify that it renders '_inner_partial', but you don't want to actually render '_inner_partial', there is no way to do that with traditional mocking frameworks because they are not designed to pay attention to one call to a method: render(:partial => '_inner_partial') while letting another call to the same method: render(:partial => '_outer_partial') through to the object. Agreed that expect_partial is doing to much, but what alternatives do we have? Cheers, David From dchelimsky at gmail.com Tue Aug 14 02:26:44 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 14 Aug 2007 02:26:44 -0400 Subject: [rspec-users] expect_render, why does there need to be a warning In-Reply-To: <57c63afe0708132316m467f4af7y6fc019096bff2d98@mail.gmail.com> References: <85d99afe0708132158ua34f8beq61bd3f3a03c3eb14@mail.gmail.com> <57c63afe0708132316m467f4af7y6fc019096bff2d98@mail.gmail.com> Message-ID: <57c63afe0708132326k51b28a31q1a7ef5ce298b963@mail.gmail.com> On 8/14/07, David Chelimsky wrote: > On 8/14/07, Zach Dennis wrote: > > Is this a sign that expect_render is doing to much? > Agreed that expect_partial is doing to much, Oy vey - we BOTH used the wrong "to". Shame on both of us :) From zach.dennis at gmail.com Tue Aug 14 10:01:49 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 14 Aug 2007 10:01:49 -0400 Subject: [rspec-users] expect_render, why does there need to be a warning In-Reply-To: <57c63afe0708132316m467f4af7y6fc019096bff2d98@mail.gmail.com> References: <85d99afe0708132158ua34f8beq61bd3f3a03c3eb14@mail.gmail.com> <57c63afe0708132316m467f4af7y6fc019096bff2d98@mail.gmail.com> Message-ID: <85d99afe0708140701w4fadd922i5868c962bacfb0fc@mail.gmail.com> On 8/14/07, David Chelimsky wrote: > On 8/14/07, Zach Dennis wrote: > > There is a warning on the web site about expect_render and stub_render: > > > > "WARNING: expect_render and stub_render, while very useful, act > > differently from standard Message Expectations (a.k.a. mock > > expectations), which would never pass calls through to the real > > object. This can be very confusing when there are failures if you're > > not aware of this fact, because some calls will be passed through > > while others will not. This is especially confusing when you use > > stub_render because, as with all Method Stubs, you will get very > > little feedback about what is going on." > > > > My questions: > > > > Is this a sign that expect_render is doing to much? > > Is there a benefit from having expect_render and stub_render sometimes > > pass the render call to the underlying template object? > > Why not force all partials to be tested individually? > > > > Testing partials individually seems like a cleaner, more consistent > > and less confusing route to go, especially when you consider the > > nesting of paritals which render other partials. > > That's the whole reason for the existence of expect_render. If you're > spec'ing '_outer_partial' and you want to specify that it renders > '_inner_partial', but you don't want to actually render > '_inner_partial', there is no way to do that with traditional mocking > frameworks because they are not designed to pay attention to one call > to a method: > > render(:partial => '_inner_partial') > > while letting another call to the same method: > > render(:partial => '_outer_partial') > > through to the object. Agreed that expect_partial is doing to much, > but what alternatives do we have? When testing views the first call to render is going to be the one that should be passed to the underlying template, since this is from the test. Every subsequent call to render will be done from within the template, so RSpec can look for a matching expectation. It seems that expect_render is in charge of setting those up. If this is done then a simple convention will be enforced, every inline "render :partial" call will have to be expected in a view spec, and every view template (or partial) will have to have it's own view test. This gets rid of issues of nesting, confusion and poorly written specs where someone is asserting contents of a partial rendered multiple levels deep in the render chain. Granted you end up with more view tests, but they are cleaner, shorter and easier to read. More importantly they are easier to maintain and update because they will be easy to find an existing spec for to start test driving changes, rather then having to find the view which renders your partial and the spec that renders that view (and heaven forbid your partial is used in several views, and each view tests the contents of that partial). Zach From edward.og at gmail.com Tue Aug 14 14:44:23 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Tue, 14 Aug 2007 14:44:23 -0400 Subject: [rspec-users] AssociationTypeMismatch with RSpec 1.0.8, autotest running with drb Message-ID: <46C1F807.5070504@gmail.com> Before I chalk this up as a bug and report it, I just want to make sure I'm not doing something silly. Running ZenTest's autotest on OS 10.4.10 with RSpec 1.0.8, drb, produces the following failed test: ActiveRecord::AssociationTypeMismatch in 'User should create an avatar with uploaded_data' Avatar expected, got Avatar This only happens with that exact configuration; turning off drb will fix it, as will running 'rake spec' instead. I saw something like this in Brian's post here [http://rubyforge.org/pipermail/rspec-devel/2007-June/003032.html] but it's a little strange that it only gets triggered in this exact setup. Any ideas why? Edward From aslak.hellesoy at gmail.com Tue Aug 14 15:20:36 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 14 Aug 2007 21:20:36 +0200 Subject: [rspec-users] AssociationTypeMismatch with RSpec 1.0.8, autotest running with drb In-Reply-To: <46C1F807.5070504@gmail.com> References: <46C1F807.5070504@gmail.com> Message-ID: <8d961d900708141220r52eccf40l7a6f5bf9be137465@mail.gmail.com> On 8/14/07, Edward Ocampo-Gooding wrote: > Before I chalk this up as a bug and report it, I just want to make sure I'm not > doing something silly. > > Running ZenTest's autotest on OS 10.4.10 with RSpec 1.0.8, drb, produces the > following failed test: > > ActiveRecord::AssociationTypeMismatch in 'User should create an avatar with > uploaded_data' > Avatar expected, got Avatar > > This only happens with that exact configuration; turning off drb will fix it, as > will running 'rake spec' instead. > What if you run with drb *without* autotest? Does it pass the first time and fail the second time? If that's the case, it could have something to do with the reloading of AR classes. Have you tried with different versions of Rails? Aslak > I saw something like this in Brian's post here > [http://rubyforge.org/pipermail/rspec-devel/2007-June/003032.html] but it's a > little strange that it only gets triggered in this exact setup. > > Any ideas why? > > Edward > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Aug 14 16:15:32 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 14 Aug 2007 16:15:32 -0400 Subject: [rspec-users] To mock or not mock base classes Message-ID: <5CC942B4-60A1-4146-9A52-1BFD0B7D9DB4@railsnewbie.com> Just a general opinion question on idioms/common usage. Is it better to mock Ruby's base classes, or to use real instances of those base classes? @string = mock String @string.stub!(:to_s).and_return "hello" # or: @string = "hello" I was wondering which is generally favored, and if so, for what reasons? Or is it highly dependent on the type of spec which is being written? Regards, Scott From mailing_lists at railsnewbie.com Tue Aug 14 16:24:19 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 14 Aug 2007 16:24:19 -0400 Subject: [rspec-users] Using rspec in a non-rails project w/ autotest Message-ID: Not sure if anyone needs this, but I have successfully been running rspec/trunk with autotest for a few days now on a non-rails project. The process is pretty simple: 1. Put rspec into vendor/plugins/rspec (on externals, or simply frozen) 2. Add autotest/discover.rb: Autotest.add_discovery do "myproj" end 3. Add autotest/myproj.rb: require File.dirname(__FILE__) + "/../vendor/plugins/rspec/rspec/lib/ autotest/rspec" class Autotest::Myproj < Autotest::Rspec alias :old_spec_commands :spec_commands def spec_commands [File.dirname(__FILE__) + "/../vendor/plugins/rspec/rspec/bin/ spec"] + old_spec_commands end end Autotest should now run fine with trunk rspec (it also means you don't need the rspec gem installed). Happy hacking, Scott From mailing_lists at railsnewbie.com Tue Aug 14 16:30:09 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 14 Aug 2007 16:30:09 -0400 Subject: [rspec-users] (no subject) Message-ID: How would you spec out something like the following: def a_method x = Class.new do include Enumerable end # do something here with x end describe "The Anonymous Class" do before :each do @anonymous_class = mock Class Class.stub!(:new).and_return @anonymous_class end it "should create a new anonymous class" do Class.should_receive(:new) a_method end it "should include Enumerable" do #... what goes here? end end One thought I've had on this is that we should be able to do something like this: it "should include Enumerable" do Class.should_receive(:new).with(&lambda { include Enumerable }).and_return true end The serious problem with implementing this is that in Ruby 1.8.6 proc equality occurs at the syntax/parser tree level, so this spec would fail: describe "Two procs" do it "should be equal with the same bodies" do @proc1 = lambda { do_something } @proc2 = lambda { do_something } @proc1.should == @proc2 end end Any good thoughts on how to get around this? Scott From rupert_apsc at rupespad.com Tue Aug 14 16:46:58 2007 From: rupert_apsc at rupespad.com (rupert) Date: Tue, 14 Aug 2007 21:46:58 +0100 Subject: [rspec-users] (no subject) In-Reply-To: References: Message-ID: On 14/8/07 21:30, "Scott Taylor" wrote: > How would you spec out something like the following: > > def a_method > x = Class.new do > include Enumerable > end > > # do something here with x > end > > > describe "The Anonymous Class" do > > before :each do > @anonymous_class = mock Class > Class.stub!(:new).and_return @anonymous_class > end > > it "should create a new anonymous class" do > Class.should_receive(:new) > a_method > end > > it "should include Enumerable" do > #... what goes here? > end > > end Not being an expert, so apply the relevant pinches of salt! ...but if you're including enumerable, then it must be so that you can enumerate the class, so would the behavior driven approach be that you would test the enumerable behavior you wish the class to exhibit rather than the implementation of enabling this behavior by including the enumerable module. Cheers Rupert -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070814/0379a970/attachment-0001.html From aslak.hellesoy at gmail.com Tue Aug 14 17:17:19 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 14 Aug 2007 23:17:19 +0200 Subject: [rspec-users] (no subject) In-Reply-To: References: Message-ID: <8d961d900708141417x70179b26sa0c28fb76cc7cc25@mail.gmail.com> On 8/14/07, Scott Taylor wrote: > > How would you spec out something like the following: > You're starting with the code, trying to tape on the spec afterwards. This is always a difficult task and is exactly what BDD and RSpec is trying to get you away from. Have you tried writing the RSpec examples first? I'd help you with an example if I knew what you're trying to achieve from a functional (not code) standpoint. Aslak > def a_method > x = Class.new do > include Enumerable > end > > # do something here with x > end > > > describe "The Anonymous Class" do > > before :each do > @anonymous_class = mock Class > Class.stub!(:new).and_return @anonymous_class > end > > it "should create a new anonymous class" do > Class.should_receive(:new) > a_method > end > > it "should include Enumerable" do > #... what goes here? > end > > end > > One thought I've had on this is that we should be able to do > something like this: > > it "should include Enumerable" do > Class.should_receive(:new).with(&lambda { > include Enumerable > }).and_return true > end > > The serious problem with implementing this is that in Ruby 1.8.6 proc > equality occurs at the syntax/parser tree level, so this spec would > fail: > > describe "Two procs" do > it "should be equal with the same bodies" do > @proc1 = lambda { do_something } > @proc2 = lambda { do_something } > > @proc1.should == @proc2 > end > end > > Any good thoughts on how to get around this? > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From luislavena at gmail.com Tue Aug 14 17:33:56 2007 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 14 Aug 2007 18:33:56 -0300 Subject: [rspec-users] Upgrade to 1.0.8 broke Rake Message-ID: <71166b3b0708141433x6c875c51l9e3ca0bf28da62f4@mail.gmail.com> Hello Guys. I'm upgrading a project from 0.9.8 to 1.0.8, following this procedure: * Removed vendor/plugins/rspec* completely. * installed rspec and rspec_on_rails from svn://rubyforge.org/var/svn/rspec/tags/REL_1_0_8 * Run script/generate rspec to update spec_helper and spec.opts Now, when running rake, get the following error: superclass mismatch for class Annotation The following pastie shows the backtrace from rake (--trace) http://pastie.caboo.se/87713 According to the last line evaluated by Ruby, class Annotation is defined in another place, with another signature... http://pastie.caboo.se/87714 Which worked flawlessly prior the update. This only brakes Rake (which actually is very helpful). using script/spec and spec as gem to fire spec "testing" works almost without problems (some issues with ActionController::DoubleRenderError, nothing that couldn't be fixed) Any idea or suggestion? or I should stay at 0.9.8? :-) Thanks -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi From mailing_lists at railsnewbie.com Tue Aug 14 17:53:56 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 14 Aug 2007 17:53:56 -0400 Subject: [rspec-users] (no subject) In-Reply-To: <8d961d900708141417x70179b26sa0c28fb76cc7cc25@mail.gmail.com> References: <8d961d900708141417x70179b26sa0c28fb76cc7cc25@mail.gmail.com> Message-ID: <2CEB9406-202C-4B0E-A2F4-BECC367FFDEC@railsnewbie.com> On Aug 14, 2007, at 5:17 PM, aslak hellesoy wrote: > On 8/14/07, Scott Taylor wrote: >> >> How would you spec out something like the following: >> > > You're starting with the code, trying to tape on the spec afterwards. > This is always a difficult task and is exactly what BDD and RSpec is > trying to get you away from. > > Have you tried writing the RSpec examples first? I'd help you with an > example if I knew what you're trying to achieve from a functional (not > code) standpoint. Sounds fair. The only reason I included the code first and presented it in that way was for simplicity. I'll now go for the complexity: I already have developed test first, and running specs. I'd now like to refactor, but my specs are preventing me. The code is here: http://pastie.caboo.se/87722 Here is the code I'd like to refactor: def anonymous_class_with_loaded_modules(*mods) klass = Class.new mods.each do |mod| klass.send(:include, mod) end return klass end I'd like to change it to this, which is functionally equivalent: def anonymous_class_with_loaded_modules(*mods) klass = Class.new do mods.each do |mod| include, mod end end return klass end Sorry for the long code samples, but I'm not exactly sure how to simplify them. I can also give you a high level over-view of what this code is doing and what it's purpose is. Let me know if that would better help you help me. Thanks for listening, Scott From luislavena at gmail.com Tue Aug 14 17:51:48 2007 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 14 Aug 2007 18:51:48 -0300 Subject: [rspec-users] Upgrade to 1.0.8 broke Rake In-Reply-To: <71166b3b0708141433x6c875c51l9e3ca0bf28da62f4@mail.gmail.com> References: <71166b3b0708141433x6c875c51l9e3ca0bf28da62f4@mail.gmail.com> Message-ID: <71166b3b0708141451q2b28ed22y2defb14ee495919f@mail.gmail.com> A follow up... On 8/14/07, Luis Lavena wrote: > Hello Guys. > > I'm upgrading a project from 0.9.8 to 1.0.8, following this procedure: > First, is 0.9.4 :-) > > Now, when running rake, get the following error: superclass mismatch > for class Annotation > > The following pastie shows the backtrace from rake (--trace) > > http://pastie.caboo.se/87713 > > It seems is that I missed rspec installed 'as gem' even I have in the vendor/plugins for this application (and use the script/spec to run). Doing "gem install rspec -v '1.0.8'" solves the problem... Which shouldn't happen in the first place :P -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi From mailing_lists at railsnewbie.com Tue Aug 14 18:35:33 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 14 Aug 2007 18:35:33 -0400 Subject: [rspec-users] (no subject) In-Reply-To: <2CEB9406-202C-4B0E-A2F4-BECC367FFDEC@railsnewbie.com> References: <8d961d900708141417x70179b26sa0c28fb76cc7cc25@mail.gmail.com> <2CEB9406-202C-4B0E-A2F4-BECC367FFDEC@railsnewbie.com> Message-ID: <8F19E839-F815-4C0E-A9F0-E4CEADCEC45E@railsnewbie.com> On Aug 14, 2007, at 5:53 PM, Scott Taylor wrote: > > On Aug 14, 2007, at 5:17 PM, aslak hellesoy wrote: > >> On 8/14/07, Scott Taylor wrote: >>> >>> How would you spec out something like the following: >>> >> >> You're starting with the code, trying to tape on the spec afterwards. >> This is always a difficult task and is exactly what BDD and RSpec is >> trying to get you away from. >> >> Have you tried writing the RSpec examples first? I'd help you with an >> example if I knew what you're trying to achieve from a functional >> (not >> code) standpoint. > > > Sounds fair. The only reason I included the code first and presented > it in that way was for simplicity. I'll now go for the complexity: > > I already have developed test first, and running specs. I'd now like > to refactor, but my specs are preventing me. The code is here: > > http://pastie.caboo.se/87722 > > Here is the code I'd like to refactor: > > def anonymous_class_with_loaded_modules(*mods) > klass = Class.new > mods.each do |mod| > klass.send(:include, mod) > end > return klass > end > > I'd like to change it to this, which is functionally equivalent: > > def anonymous_class_with_loaded_modules(*mods) > klass = Class.new do > mods.each do |mod| > include, mod > end > end > return klass > end Aslak, Maybe dependency injection would be the way to solve this problem. Let me know your thoughts - I'd like to clean up this code. Scott From mailing_lists at railsnewbie.com Tue Aug 14 18:55:25 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 14 Aug 2007 18:55:25 -0400 Subject: [rspec-users] Stubbing all methods Message-ID: <98ECC771-E86C-4978-8E18-7F371FC845D0@railsnewbie.com> Mocha's mock/stub framework has the ability to stub all methods on a mock given. Does RSpec's mocking framework have this ability? And if not, is there some reason it shouldn't be implemeneted? Regards, Scott From aslak.hellesoy at gmail.com Tue Aug 14 18:59:48 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 15 Aug 2007 00:59:48 +0200 Subject: [rspec-users] Stubbing all methods In-Reply-To: <98ECC771-E86C-4978-8E18-7F371FC845D0@railsnewbie.com> References: <98ECC771-E86C-4978-8E18-7F371FC845D0@railsnewbie.com> Message-ID: <8d961d900708141559o32705ecar62f781e4f45a390b@mail.gmail.com> On 8/15/07, Scott Taylor wrote: > > Mocha's mock/stub framework has the ability to stub all methods on a > mock given. Does RSpec's mocking framework have this ability? No > And > if not, is there some reason it shouldn't be implemeneted? > Not that I can think of. Aslak > Regards, > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Tue Aug 14 19:03:13 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 15 Aug 2007 01:03:13 +0200 Subject: [rspec-users] Stubbing all methods In-Reply-To: <8d961d900708141559o32705ecar62f781e4f45a390b@mail.gmail.com> References: <98ECC771-E86C-4978-8E18-7F371FC845D0@railsnewbie.com> <8d961d900708141559o32705ecar62f781e4f45a390b@mail.gmail.com> Message-ID: <8d961d900708141603x413f2643hfc4aa4b43be50d42@mail.gmail.com> On 8/15/07, aslak hellesoy wrote: > On 8/15/07, Scott Taylor wrote: > > > > Mocha's mock/stub framework has the ability to stub all methods on a > > mock given. Does RSpec's mocking framework have this ability? > > No Err, actually it is possible. (I first thought about "stub methods on all instances of a class" which mocha does, but RSpec doesn't). mock("person", :null_object => true) Is this what you're after? See RDoc for details. Aslak > > > And > > if not, is there some reason it shouldn't be implemeneted? > > > > Not that I can think of. > > Aslak > > > Regards, > > > > Scott > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From court3nay at gmail.com Tue Aug 14 19:09:53 2007 From: court3nay at gmail.com (Courtenay) Date: Tue, 14 Aug 2007 16:09:53 -0700 Subject: [rspec-users] Stubbing all methods In-Reply-To: <8d961d900708141559o32705ecar62f781e4f45a390b@mail.gmail.com> References: <98ECC771-E86C-4978-8E18-7F371FC845D0@railsnewbie.com> <8d961d900708141559o32705ecar62f781e4f45a390b@mail.gmail.com> Message-ID: <4b430c8f0708141609k2a3303f7w326cba18ca74e7b1@mail.gmail.com> On 8/14/07, aslak hellesoy wrote: > On 8/15/07, Scott Taylor wrote: > > > > Mocha's mock/stub framework has the ability to stub all methods on a > > mock given. Does RSpec's mocking framework have this ability? > You mean like :null_object => true ?? ============ http://rspec.rubyforge.org/documentation/mocks/mocks.html "As above, but allows you to specific options to tweak the mock's behaviour. The options argument is a hash. Currently the only supported option is :null_object. Setting this to true instructs the mock to ignore (quietly consume) any messages it hasn't been told to expect ? and return itself. i.e. my_mock = mock("blah", :null_object => true) From edward.og at gmail.com Tue Aug 14 21:52:29 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Tue, 14 Aug 2007 21:52:29 -0400 Subject: [rspec-users] AssociationTypeMismatch with RSpec 1.0.8, autotest running with drb In-Reply-To: <8d961d900708141220r52eccf40l7a6f5bf9be137465@mail.gmail.com> References: <46C1F807.5070504@gmail.com> <8d961d900708141220r52eccf40l7a6f5bf9be137465@mail.gmail.com> Message-ID: <46C25C5D.3060203@gmail.com> aslak hellesoy wrote: > On 8/14/07, Edward Ocampo-Gooding wrote: >> Before I chalk this up as a bug and report it, I just want to make sure I'm not >> doing something silly. >> >> Running ZenTest's autotest on OS 10.4.10 with RSpec 1.0.8, drb, produces the >> following failed test: >> >> ActiveRecord::AssociationTypeMismatch in 'User should create an avatar with >> uploaded_data' >> Avatar expected, got Avatar >> >> This only happens with that exact configuration; turning off drb will fix it, as >> will running 'rake spec' instead. >> > > What if you run with drb *without* autotest? Does it pass the first > time and fail the second time? > If that's the case, it could have something to do with the reloading > of AR classes. Have you tried with different versions of Rails? After getting home and trying it out again on the same laptop, it looks like when drb is enabled, now both 'rake spec' and autotest hang for about 60 seconds and then finally run. (Running rake spec --trace shows that it's hanging on "Execute spec" for a really long time.) Is there some drb debugging flag I can turn on, or blow away some drb-related cache? Oh, and yes, you're right; 'rake spec' looks like it's having problems with reloading the class, as it works fine the first time, but on subsequent runs, it fails with an ActiveRecord::AssociationTypeMismatch. This is all on Rails 1.2.3 Thanks, Edward From mailing_lists at railsnewbie.com Tue Aug 14 22:40:43 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 14 Aug 2007 22:40:43 -0400 Subject: [rspec-users] Stubbing all methods In-Reply-To: <4b430c8f0708141609k2a3303f7w326cba18ca74e7b1@mail.gmail.com> References: <98ECC771-E86C-4978-8E18-7F371FC845D0@railsnewbie.com> <8d961d900708141559o32705ecar62f781e4f45a390b@mail.gmail.com> <4b430c8f0708141609k2a3303f7w326cba18ca74e7b1@mail.gmail.com> Message-ID: <4CE93F76-47E3-4215-8FC7-0DDD6E8848A0@railsnewbie.com> On Aug 14, 2007, at 7:09 PM, Courtenay wrote: > On 8/14/07, aslak hellesoy wrote: >> On 8/15/07, Scott Taylor wrote: >>> >>> Mocha's mock/stub framework has the ability to stub all methods on a >>> mock given. Does RSpec's mocking framework have this ability? >> > > You mean like :null_object => true ?? Yes, actually that works well. Aslak - were you understanding me to ask for Mocha's any_instance stub ? Thanks, Scott > > ============ > > http://rspec.rubyforge.org/documentation/mocks/mocks.html > > "As above, but allows you to specific options to tweak the mock's > behaviour. The options argument is a hash. Currently the only > supported option is :null_object. Setting this to true instructs the > mock to ignore (quietly consume) any messages it hasn't been told to > expect ? and return itself. i.e. > > my_mock = mock("blah", :null_object => true) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Tue Aug 14 23:36:54 2007 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 14 Aug 2007 20:36:54 -0700 Subject: [rspec-users] To mock or not mock base classes In-Reply-To: <5CC942B4-60A1-4146-9A52-1BFD0B7D9DB4@railsnewbie.com> References: <5CC942B4-60A1-4146-9A52-1BFD0B7D9DB4@railsnewbie.com> Message-ID: <810a540e0708142036i262734aaya8aaed19e1e68a0c@mail.gmail.com> On 8/14/07, Scott Taylor wrote: > > Just a general opinion question on idioms/common usage. Is it better > to mock Ruby's base classes, or to use real instances of those base > classes? > > @string = mock String > @string.stub!(:to_s).and_return "hello" > > # or: > > @string = "hello" > > I was wondering which is generally favored, and if so, for what > reasons? Or is it highly dependent on the type of spec which is > being written? > > Regards, > > Scott > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I would say the second way is pretty clearly the favorite :) However there might be usages where the first way could be appropriate, but it's surely not that example. Perhaps you could show the actual spec you're trying to write? Pat From dchelimsky at gmail.com Tue Aug 14 23:41:37 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 14 Aug 2007 23:41:37 -0400 Subject: [rspec-users] expect_render, why does there need to be a warning In-Reply-To: <85d99afe0708140701w4fadd922i5868c962bacfb0fc@mail.gmail.com> References: <85d99afe0708132158ua34f8beq61bd3f3a03c3eb14@mail.gmail.com> <57c63afe0708132316m467f4af7y6fc019096bff2d98@mail.gmail.com> <85d99afe0708140701w4fadd922i5868c962bacfb0fc@mail.gmail.com> Message-ID: <57c63afe0708142041y55efc047m7230f01cd0a26e3e@mail.gmail.com> On 8/14/07, Zach Dennis wrote: > On 8/14/07, David Chelimsky wrote: > > On 8/14/07, Zach Dennis wrote: > > > There is a warning on the web site about expect_render and stub_render: > > > > > > "WARNING: expect_render and stub_render, while very useful, act > > > differently from standard Message Expectations (a.k.a. mock > > > expectations), which would never pass calls through to the real > > > object. This can be very confusing when there are failures if you're > > > not aware of this fact, because some calls will be passed through > > > while others will not. This is especially confusing when you use > > > stub_render because, as with all Method Stubs, you will get very > > > little feedback about what is going on." > > > > > > My questions: > > > > > > Is this a sign that expect_render is doing to much? > > > Is there a benefit from having expect_render and stub_render sometimes > > > pass the render call to the underlying template object? > > > Why not force all partials to be tested individually? > > > > > > Testing partials individually seems like a cleaner, more consistent > > > and less confusing route to go, especially when you consider the > > > nesting of paritals which render other partials. > > > > That's the whole reason for the existence of expect_render. If you're > > spec'ing '_outer_partial' and you want to specify that it renders > > '_inner_partial', but you don't want to actually render > > '_inner_partial', there is no way to do that with traditional mocking > > frameworks because they are not designed to pay attention to one call > > to a method: > > > > render(:partial => '_inner_partial') > > > > while letting another call to the same method: > > > > render(:partial => '_outer_partial') > > > > through to the object. Agreed that expect_partial is doing to much, > > but what alternatives do we have? > > When testing views the first call to render is going to be the one > that should be passed to the underlying template, since this is from > the test. > > Every subsequent call to render will be done from within the template, > so RSpec can look for a matching expectation. It seems that > expect_render is in charge of setting those up. > > If this is done then a simple convention will be enforced, every > inline "render :partial" call will have to be expected in a view spec, > and every view template (or partial) will have to have it's own view > test. > > This gets rid of issues of nesting, confusion and poorly written specs > where someone is asserting contents of a partial rendered multiple > levels deep in the render chain. > > Granted you end up with more view tests, but they are cleaner, shorter > and easier to read. More importantly they are easier to maintain and > update because they will be easy to find an existing spec for to start > test driving changes, rather then having to find the view which > renders your partial and the spec that renders that view (and heaven > forbid your partial is used in several views, and each view tests the > contents of that partial). I think you are describing a good convention, but I don't think rspec should force it on everybody. The goal here is to provide tools that ALLOW you to do things in certain ways but not force you to. For example, rspec_on_rails supports isolated views, but you can do rails-style functional tests (using controller specs with integrated views) if you want. From jonathan at parkerhill.com Wed Aug 15 03:40:38 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Wed, 15 Aug 2007 03:40:38 -0400 Subject: [rspec-users] active_scaffold partials In-Reply-To: <85d99afe0708140701w4fadd922i5868c962bacfb0fc@mail.gmail.com> References: <85d99afe0708132158ua34f8beq61bd3f3a03c3eb14@mail.gmail.com> <57c63afe0708132316m467f4af7y6fc019096bff2d98@mail.gmail.com> <85d99afe0708140701w4fadd922i5868c962bacfb0fc@mail.gmail.com> Message-ID: <905E3694-C9B6-4FC1-9204-8135C10A4E9A@parkerhill.com> An issue I've run into is with a controller using the active_scaffold plugin, which injects a method that modifies the search path for partial files. When I try to run a spec on a a_s partial it reports the file cannot be found. I think this is the a_s code that does it but I'm not sure where to go from there to get rspec to handle it. Any suggestions would be appreciated. file: plugins/active_scaffold/lib/extensions/action_view.rb module ActionView #:nodoc: class Base ... def render_partial_with_active_scaffold(partial_path, local_assigns = nil, deprecated_local_assigns = nil) #:nodoc: if self.controller.class.respond_to?(:uses_active_scaffold?) and self.controller.class.uses_active_scaffold? partial_path = rewrite_partial_path_for_active_scaffold (partial_path) end render_partial_without_active_scaffold(partial_path, local_assigns, deprecated_local_assigns) end alias_method :render_partial_without_active_scaffold, :render_partial alias_method :render_partial, :render_partial_with_active_scaffold private def rewrite_partial_path_for_active_scaffold(partial_path) path, partial_name = partial_pieces(partial_path) # test for the actual file return partial_path if file_exists? File.join(path, "_# {partial_name}") # check the ActiveScaffold-specific directories ActiveScaffold::Config::Core.template_search_path.each do | template_path| return File.join(template_path, partial_name) if file_exists? File.join(template_path, "_#{partial_name}") end return partial_path end end end From mailing_lists at railsnewbie.com Wed Aug 15 07:51:33 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 15 Aug 2007 07:51:33 -0400 Subject: [rspec-users] Extra Options to Heckle Message-ID: I've tried running Heckle with rspec on some of my classes, but keep getting (what I believe to be) an infinite recursion. Is there some way to supply extra options to heckle via. rspec? Scott From steve.tooke at gmail.com Wed Aug 15 07:52:20 2007 From: steve.tooke at gmail.com (Steve Tooke) Date: Wed, 15 Aug 2007 12:52:20 +0100 Subject: [rspec-users] ActsAsList specs Message-ID: <78d462040708150452m747ae9d0k10aef7ba208af6db@mail.gmail.com> Hi, How are people specifying models which act_as_list? I'm thinking that it would be possible to check that acts_as_list instance methods have been added to a class using something like this: describe Page, "acts_as_list" do it "should act as a list" do Page.ancestors.should be_include(ActiveRecord::Acts::List::InstanceMethods) end it "should use page_index as position_column" do Page.new.position_column.should == "page_index" end it "should have scope of book_id" do Page.new.scope_condition.should == "book_id IS NULL" end end it at least lets you drive adding acts_as_list? Any thoughts on how I can improve this? How anyone else has done this? Cheers, Steve From aslak.hellesoy at gmail.com Wed Aug 15 07:57:03 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 15 Aug 2007 13:57:03 +0200 Subject: [rspec-users] Extra Options to Heckle In-Reply-To: References: Message-ID: <8d961d900708150457w6a001d99t8b2ed18a55f0821b@mail.gmail.com> On 8/15/07, Scott Taylor wrote: > > I've tried running Heckle with rspec on some of my classes, but keep > getting (what I believe to be) an infinite recursion. Is there some > way to supply extra options to heckle via. rspec? > Currently not. What options do you want to supply? Aslak > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Wed Aug 15 08:11:00 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 15 Aug 2007 08:11:00 -0400 Subject: [rspec-users] Extra Options to Heckle In-Reply-To: <8d961d900708150457w6a001d99t8b2ed18a55f0821b@mail.gmail.com> References: <8d961d900708150457w6a001d99t8b2ed18a55f0821b@mail.gmail.com> Message-ID: <5A1E2341-F3CF-40FC-91D9-9F47EBC9CC1F@railsnewbie.com> On Aug 15, 2007, at 7:57 AM, aslak hellesoy wrote: > On 8/15/07, Scott Taylor wrote: >> >> I've tried running Heckle with rspec on some of my classes, but keep >> getting (what I believe to be) an infinite recursion. Is there some >> way to supply extra options to heckle via. rspec? >> > > Currently not. What options do you want to supply? Well right now the only one I care about is --verbose, but depending on the output of --verbose, I may want other options (probably -- assignments and --branches). Thanks, Scott From mailing_lists at railsnewbie.com Wed Aug 15 08:16:48 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 15 Aug 2007 08:16:48 -0400 Subject: [rspec-users] Extra Options to Heckle In-Reply-To: <5A1E2341-F3CF-40FC-91D9-9F47EBC9CC1F@railsnewbie.com> References: <8d961d900708150457w6a001d99t8b2ed18a55f0821b@mail.gmail.com> <5A1E2341-F3CF-40FC-91D9-9F47EBC9CC1F@railsnewbie.com> Message-ID: <38C5AD61-85C8-4C34-A401-0119BDF8E179@railsnewbie.com> On Aug 15, 2007, at 8:11 AM, Scott Taylor wrote: > > On Aug 15, 2007, at 7:57 AM, aslak hellesoy wrote: > >> On 8/15/07, Scott Taylor wrote: >>> >>> I've tried running Heckle with rspec on some of my classes, but keep >>> getting (what I believe to be) an infinite recursion. Is there some >>> way to supply extra options to heckle via. rspec? >>> >> >> Currently not. What options do you want to supply? > > Well right now the only one I care about is --verbose, but depending > on the output of --verbose, I may want other options (probably -- > assignments and --branches). > I can probably work up a patch for this one. Thanks for the info, Aslak. Scott From dchelimsky at gmail.com Wed Aug 15 10:28:12 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 15 Aug 2007 10:28:12 -0400 Subject: [rspec-users] expect_render, why does there need to be a warning In-Reply-To: <85d99afe0708150722x31a5b3fev117546f1c60617eb@mail.gmail.com> References: <85d99afe0708132158ua34f8beq61bd3f3a03c3eb14@mail.gmail.com> <57c63afe0708132316m467f4af7y6fc019096bff2d98@mail.gmail.com> <85d99afe0708140701w4fadd922i5868c962bacfb0fc@mail.gmail.com> <57c63afe0708142041y55efc047m7230f01cd0a26e3e@mail.gmail.com> <85d99afe0708150722x31a5b3fev117546f1c60617eb@mail.gmail.com> Message-ID: <57c63afe0708150728p633fcda1k7401ce89a5429de7@mail.gmail.com> On 8/15/07, Zach Dennis wrote: > On 8/14/07, David Chelimsky wrote: > > On 8/14/07, Zach Dennis wrote: > > > On 8/14/07, David Chelimsky wrote: > > > > On 8/14/07, Zach Dennis wrote: > > > > > There is a warning on the web site about expect_render and stub_render: > > > > > > > > > > "WARNING: expect_render and stub_render, while very useful, act > > > > > differently from standard Message Expectations (a.k.a. mock > > > > > expectations), which would never pass calls through to the real > > > > > object. This can be very confusing when there are failures if you're > > > > > not aware of this fact, because some calls will be passed through > > > > > while others will not. This is especially confusing when you use > > > > > stub_render because, as with all Method Stubs, you will get very > > > > > little feedback about what is going on." > > > > > > > > > > My questions: > > > > > > > > > > Is this a sign that expect_render is doing to much? > > > > > Is there a benefit from having expect_render and stub_render sometimes > > > > > pass the render call to the underlying template object? > > > > > Why not force all partials to be tested individually? > > > > > > > > > > Testing partials individually seems like a cleaner, more consistent > > > > > and less confusing route to go, especially when you consider the > > > > > nesting of paritals which render other partials. > > > > > > > > That's the whole reason for the existence of expect_render. If you're > > > > spec'ing '_outer_partial' and you want to specify that it renders > > > > '_inner_partial', but you don't want to actually render > > > > '_inner_partial', there is no way to do that with traditional mocking > > > > frameworks because they are not designed to pay attention to one call > > > > to a method: > > > > > > > > render(:partial => '_inner_partial') > > > > > > > > while letting another call to the same method: > > > > > > > > render(:partial => '_outer_partial') > > > > > > > > through to the object. Agreed that expect_partial is doing to much, > > > > but what alternatives do we have? > > > > > > When testing views the first call to render is going to be the one > > > that should be passed to the underlying template, since this is from > > > the test. > > > > > > Every subsequent call to render will be done from within the template, > > > so RSpec can look for a matching expectation. It seems that > > > expect_render is in charge of setting those up. > > > > > > If this is done then a simple convention will be enforced, every > > > inline "render :partial" call will have to be expected in a view spec, > > > and every view template (or partial) will have to have it's own view > > > test. > > > > > > This gets rid of issues of nesting, confusion and poorly written specs > > > where someone is asserting contents of a partial rendered multiple > > > levels deep in the render chain. > > > > > > Granted you end up with more view tests, but they are cleaner, shorter > > > and easier to read. More importantly they are easier to maintain and > > > update because they will be easy to find an existing spec for to start > > > test driving changes, rather then having to find the view which > > > renders your partial and the spec that renders that view (and heaven > > > forbid your partial is used in several views, and each view tests the > > > contents of that partial). > > > > I think you are describing a good convention, but I don't think rspec > > should force it on everybody. The goal here is to provide tools that > > ALLOW you to do things in certain ways but not force you to. > > > > For example, rspec_on_rails supports isolated views, but you can do > > rails-style functional tests (using controller specs with integrated > > views) if you want. > > How about a "integrate_inline_renders" similar to "integrate_views"? Just don't use expect_render and it'll do that. Magic! > > Zach > From zach.dennis at gmail.com Wed Aug 15 10:22:13 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 15 Aug 2007 10:22:13 -0400 Subject: [rspec-users] expect_render, why does there need to be a warning In-Reply-To: <57c63afe0708142041y55efc047m7230f01cd0a26e3e@mail.gmail.com> References: <85d99afe0708132158ua34f8beq61bd3f3a03c3eb14@mail.gmail.com> <57c63afe0708132316m467f4af7y6fc019096bff2d98@mail.gmail.com> <85d99afe0708140701w4fadd922i5868c962bacfb0fc@mail.gmail.com> <57c63afe0708142041y55efc047m7230f01cd0a26e3e@mail.gmail.com> Message-ID: <85d99afe0708150722x31a5b3fev117546f1c60617eb@mail.gmail.com> On 8/14/07, David Chelimsky wrote: > On 8/14/07, Zach Dennis wrote: > > On 8/14/07, David Chelimsky wrote: > > > On 8/14/07, Zach Dennis wrote: > > > > There is a warning on the web site about expect_render and stub_render: > > > > > > > > "WARNING: expect_render and stub_render, while very useful, act > > > > differently from standard Message Expectations (a.k.a. mock > > > > expectations), which would never pass calls through to the real > > > > object. This can be very confusing when there are failures if you're > > > > not aware of this fact, because some calls will be passed through > > > > while others will not. This is especially confusing when you use > > > > stub_render because, as with all Method Stubs, you will get very > > > > little feedback about what is going on." > > > > > > > > My questions: > > > > > > > > Is this a sign that expect_render is doing to much? > > > > Is there a benefit from having expect_render and stub_render sometimes > > > > pass the render call to the underlying template object? > > > > Why not force all partials to be tested individually? > > > > > > > > Testing partials individually seems like a cleaner, more consistent > > > > and less confusing route to go, especially when you consider the > > > > nesting of paritals which render other partials. > > > > > > That's the whole reason for the existence of expect_render. If you're > > > spec'ing '_outer_partial' and you want to specify that it renders > > > '_inner_partial', but you don't want to actually render > > > '_inner_partial', there is no way to do that with traditional mocking > > > frameworks because they are not designed to pay attention to one call > > > to a method: > > > > > > render(:partial => '_inner_partial') > > > > > > while letting another call to the same method: > > > > > > render(:partial => '_outer_partial') > > > > > > through to the object. Agreed that expect_partial is doing to much, > > > but what alternatives do we have? > > > > When testing views the first call to render is going to be the one > > that should be passed to the underlying template, since this is from > > the test. > > > > Every subsequent call to render will be done from within the template, > > so RSpec can look for a matching expectation. It seems that > > expect_render is in charge of setting those up. > > > > If this is done then a simple convention will be enforced, every > > inline "render :partial" call will have to be expected in a view spec, > > and every view template (or partial) will have to have it's own view > > test. > > > > This gets rid of issues of nesting, confusion and poorly written specs > > where someone is asserting contents of a partial rendered multiple > > levels deep in the render chain. > > > > Granted you end up with more view tests, but they are cleaner, shorter > > and easier to read. More importantly they are easier to maintain and > > update because they will be easy to find an existing spec for to start > > test driving changes, rather then having to find the view which > > renders your partial and the spec that renders that view (and heaven > > forbid your partial is used in several views, and each view tests the > > contents of that partial). > > I think you are describing a good convention, but I don't think rspec > should force it on everybody. The goal here is to provide tools that > ALLOW you to do things in certain ways but not force you to. > > For example, rspec_on_rails supports isolated views, but you can do > rails-style functional tests (using controller specs with integrated > views) if you want. How about a "integrate_inline_renders" similar to "integrate_views"? Zach From zach.dennis at gmail.com Wed Aug 15 13:09:11 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 15 Aug 2007 13:09:11 -0400 Subject: [rspec-users] expect_render, why does there need to be a warning In-Reply-To: <57c63afe0708150728p633fcda1k7401ce89a5429de7@mail.gmail.com> References: <85d99afe0708132158ua34f8beq61bd3f3a03c3eb14@mail.gmail.com> <57c63afe0708132316m467f4af7y6fc019096bff2d98@mail.gmail.com> <85d99afe0708140701w4fadd922i5868c962bacfb0fc@mail.gmail.com> <57c63afe0708142041y55efc047m7230f01cd0a26e3e@mail.gmail.com> <85d99afe0708150722x31a5b3fev117546f1c60617eb@mail.gmail.com> <57c63afe0708150728p633fcda1k7401ce89a5429de7@mail.gmail.com> Message-ID: <85d99afe0708151009oef2bde8jc289dc721dcb6812@mail.gmail.com> On 8/15/07, David Chelimsky wrote: > On 8/15/07, Zach Dennis wrote: > > On 8/14/07, David Chelimsky wrote: > > > On 8/14/07, Zach Dennis wrote: > > > > On 8/14/07, David Chelimsky wrote: > > > > > On 8/14/07, Zach Dennis wrote: > > > > > > There is a warning on the web site about expect_render and stub_render: > > > > > > > > > > > > "WARNING: expect_render and stub_render, while very useful, act > > > > > > differently from standard Message Expectations (a.k.a. mock > > > > > > expectations), which would never pass calls through to the real > > > > > > object. This can be very confusing when there are failures if you're > > > > > > not aware of this fact, because some calls will be passed through > > > > > > while others will not. This is especially confusing when you use > > > > > > stub_render because, as with all Method Stubs, you will get very > > > > > > little feedback about what is going on." > > > > > > > > > > > > My questions: > > > > > > > > > > > > Is this a sign that expect_render is doing to much? > > > > > > Is there a benefit from having expect_render and stub_render sometimes > > > > > > pass the render call to the underlying template object? > > > > > > Why not force all partials to be tested individually? > > > > > > > > > > > > Testing partials individually seems like a cleaner, more consistent > > > > > > and less confusing route to go, especially when you consider the > > > > > > nesting of paritals which render other partials. > > > > > > > > > > That's the whole reason for the existence of expect_render. If you're > > > > > spec'ing '_outer_partial' and you want to specify that it renders > > > > > '_inner_partial', but you don't want to actually render > > > > > '_inner_partial', there is no way to do that with traditional mocking > > > > > frameworks because they are not designed to pay attention to one call > > > > > to a method: > > > > > > > > > > render(:partial => '_inner_partial') > > > > > > > > > > while letting another call to the same method: > > > > > > > > > > render(:partial => '_outer_partial') > > > > > > > > > > through to the object. Agreed that expect_partial is doing to much, > > > > > but what alternatives do we have? > > > > > > > > When testing views the first call to render is going to be the one > > > > that should be passed to the underlying template, since this is from > > > > the test. > > > > > > > > Every subsequent call to render will be done from within the template, > > > > so RSpec can look for a matching expectation. It seems that > > > > expect_render is in charge of setting those up. > > > > > > > > If this is done then a simple convention will be enforced, every > > > > inline "render :partial" call will have to be expected in a view spec, > > > > and every view template (or partial) will have to have it's own view > > > > test. > > > > > > > > This gets rid of issues of nesting, confusion and poorly written specs > > > > where someone is asserting contents of a partial rendered multiple > > > > levels deep in the render chain. > > > > > > > > Granted you end up with more view tests, but they are cleaner, shorter > > > > and easier to read. More importantly they are easier to maintain and > > > > update because they will be easy to find an existing spec for to start > > > > test driving changes, rather then having to find the view which > > > > renders your partial and the spec that renders that view (and heaven > > > > forbid your partial is used in several views, and each view tests the > > > > contents of that partial). > > > > > > I think you are describing a good convention, but I don't think rspec > > > should force it on everybody. The goal here is to provide tools that > > > ALLOW you to do things in certain ways but not force you to. > > > > > > For example, rspec_on_rails supports isolated views, but you can do > > > rails-style functional tests (using controller specs with integrated > > > views) if you want. > > > > How about a "integrate_inline_renders" similar to "integrate_views"? > > Just don't use expect_render and it'll do that. Magic! > I'm on the opposite view point. I don't want to pass through renders, I want to force all inline renders to be enforced. If i have a view that calls "render :partial => 'foo'" and I don't use expect_render I want it to yell at me saying an unexpected call was made on the template. Zach From dchelimsky at gmail.com Wed Aug 15 14:18:38 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 15 Aug 2007 14:18:38 -0400 Subject: [rspec-users] expect_render, why does there need to be a warning In-Reply-To: <85d99afe0708151009oef2bde8jc289dc721dcb6812@mail.gmail.com> References: <85d99afe0708132158ua34f8beq61bd3f3a03c3eb14@mail.gmail.com> <57c63afe0708132316m467f4af7y6fc019096bff2d98@mail.gmail.com> <85d99afe0708140701w4fadd922i5868c962bacfb0fc@mail.gmail.com> <57c63afe0708142041y55efc047m7230f01cd0a26e3e@mail.gmail.com> <85d99afe0708150722x31a5b3fev117546f1c60617eb@mail.gmail.com> <57c63afe0708150728p633fcda1k7401ce89a5429de7@mail.gmail.com> <85d99afe0708151009oef2bde8jc289dc721dcb6812@mail.gmail.com> Message-ID: <57c63afe0708151118i36a45934m1b891f67d5dac5ed@mail.gmail.com> On 8/15/07, Zach Dennis wrote: > On 8/15/07, David Chelimsky wrote: > > On 8/15/07, Zach Dennis wrote: > > > On 8/14/07, David Chelimsky wrote: > > > > On 8/14/07, Zach Dennis wrote: > > > > > On 8/14/07, David Chelimsky wrote: > > > > > > On 8/14/07, Zach Dennis wrote: > > > > > > > There is a warning on the web site about expect_render and stub_render: > > > > > > > > > > > > > > "WARNING: expect_render and stub_render, while very useful, act > > > > > > > differently from standard Message Expectations (a.k.a. mock > > > > > > > expectations), which would never pass calls through to the real > > > > > > > object. This can be very confusing when there are failures if you're > > > > > > > not aware of this fact, because some calls will be passed through > > > > > > > while others will not. This is especially confusing when you use > > > > > > > stub_render because, as with all Method Stubs, you will get very > > > > > > > little feedback about what is going on." > > > > > > > > > > > > > > My questions: > > > > > > > > > > > > > > Is this a sign that expect_render is doing to much? > > > > > > > Is there a benefit from having expect_render and stub_render sometimes > > > > > > > pass the render call to the underlying template object? > > > > > > > Why not force all partials to be tested individually? > > > > > > > > > > > > > > Testing partials individually seems like a cleaner, more consistent > > > > > > > and less confusing route to go, especially when you consider the > > > > > > > nesting of paritals which render other partials. > > > > > > > > > > > > That's the whole reason for the existence of expect_render. If you're > > > > > > spec'ing '_outer_partial' and you want to specify that it renders > > > > > > '_inner_partial', but you don't want to actually render > > > > > > '_inner_partial', there is no way to do that with traditional mocking > > > > > > frameworks because they are not designed to pay attention to one call > > > > > > to a method: > > > > > > > > > > > > render(:partial => '_inner_partial') > > > > > > > > > > > > while letting another call to the same method: > > > > > > > > > > > > render(:partial => '_outer_partial') > > > > > > > > > > > > through to the object. Agreed that expect_partial is doing to much, > > > > > > but what alternatives do we have? > > > > > > > > > > When testing views the first call to render is going to be the one > > > > > that should be passed to the underlying template, since this is from > > > > > the test. > > > > > > > > > > Every subsequent call to render will be done from within the template, > > > > > so RSpec can look for a matching expectation. It seems that > > > > > expect_render is in charge of setting those up. > > > > > > > > > > If this is done then a simple convention will be enforced, every > > > > > inline "render :partial" call will have to be expected in a view spec, > > > > > and every view template (or partial) will have to have it's own view > > > > > test. > > > > > > > > > > This gets rid of issues of nesting, confusion and poorly written specs > > > > > where someone is asserting contents of a partial rendered multiple > > > > > levels deep in the render chain. > > > > > > > > > > Granted you end up with more view tests, but they are cleaner, shorter > > > > > and easier to read. More importantly they are easier to maintain and > > > > > update because they will be easy to find an existing spec for to start > > > > > test driving changes, rather then having to find the view which > > > > > renders your partial and the spec that renders that view (and heaven > > > > > forbid your partial is used in several views, and each view tests the > > > > > contents of that partial). > > > > > > > > I think you are describing a good convention, but I don't think rspec > > > > should force it on everybody. The goal here is to provide tools that > > > > ALLOW you to do things in certain ways but not force you to. > > > > > > > > For example, rspec_on_rails supports isolated views, but you can do > > > > rails-style functional tests (using controller specs with integrated > > > > views) if you want. > > > > > > How about a "integrate_inline_renders" similar to "integrate_views"? > > > > Just don't use expect_render and it'll do that. Magic! > > > > I'm on the opposite view point. I don't want to pass through renders, > I want to force all inline renders to be enforced. > > If i have a view that calls "render :partial => 'foo'" and I don't use > expect_render I want it to yell at me saying an unexpected call was > made on the template. There's nothing else in rspec_on_rails that yells at you because you don't like to organize your specs the way rspec thinks they should be organized, so I definitely wouldn't support this being default behaviour. I could see, maybe, the possibility of having a command like disallow_unexpected_renders or something like that, but I honestly don't see that much value in it in return for the additional complexity (didn't you start by saying this was too complex already?). I understand that you DO see value in this, and I'd encourage you to write a plugin that makes this work the way you want and feel free to publish it. Cheers, David From court3nay at gmail.com Wed Aug 15 14:22:47 2007 From: court3nay at gmail.com (Courtenay) Date: Wed, 15 Aug 2007 11:22:47 -0700 Subject: [rspec-users] ActsAsList specs In-Reply-To: <78d462040708150452m747ae9d0k10aef7ba208af6db@mail.gmail.com> References: <78d462040708150452m747ae9d0k10aef7ba208af6db@mail.gmail.com> Message-ID: <4b430c8f0708151122y50a361c8y5f23cf1c6d838e72@mail.gmail.com> On 8/15/07, Steve Tooke wrote: > Hi, > > How are people specifying models which act_as_list? > > I'm thinking that it would be possible to check that acts_as_list > instance methods have been added to a class using something like this: You're specing the code not the behavior. This will make double-work if you want to change anything. From priit.tamboom at gmail.com Wed Aug 15 15:14:18 2007 From: priit.tamboom at gmail.com (Priit Tamboom) Date: Thu, 16 Aug 2007 03:14:18 +0800 Subject: [rspec-users] nuby: how spec redirect_to at ApplicationController Message-ID: Good morning rspec people! Still rspec nuby: I must do something wrong obviously. How can I spec about redirect_to at ApplicationController describe ApplicationController do it "method login_required should redirect to home path without login" do pending "I tried to use controller.login_required.should be_redirected and got NoMethodError with nil object didn't expect error." end end class ApplicationController < ActionController::Base # using it with before_filter def login_required # I took out everything except redirecting to make the point simple redirect_to home_path # tried also redirect_to "/" end end However the code does work manually testing with browser. Thanks for any help, Priit -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070816/9f4d994e/attachment.html From jonathan at parkerhill.com Wed Aug 15 16:02:31 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Wed, 15 Aug 2007 16:02:31 -0400 Subject: [rspec-users] restful named routes In-Reply-To: <70EE6770-3ABB-46F4-9195-AE566AD21A12@railsnewbie.com> References: <70EE6770-3ABB-46F4-9195-AE566AD21A12@railsnewbie.com> Message-ID: Hi, revisiting this issue, I feel I'm getting closer: describe CommentsController, "named routes" do before do @post = mock_model(Post, :id => 22) end it "should generate post_comments_path" do controller.post_comments_path(@post).should == "/posts/22/comments" end end results in: NoMethodError in 'CommentsController named routes should generate post_comments_path' protected method `post_comments_path' called for # Is there a way around this? Or how are other testing named routes? thanks linoj On May 29, 2007, at 7:52 AM, Scott Taylor wrote: > > On May 29, 2007, at 4:54 AM, Jonathan Linowes wrote: > >> >> - Is there a way to test named routes? > > I don't think there is a very clean & direct way (hopefully the > others on the list can correct me). The rspec rest generator > generates some code to check the routes, so you could use something > like that. > > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From court3nay at gmail.com Wed Aug 15 16:30:04 2007 From: court3nay at gmail.com (Courtenay) Date: Wed, 15 Aug 2007 13:30:04 -0700 Subject: [rspec-users] nuby: how spec redirect_to at ApplicationController In-Reply-To: References: Message-ID: <4b430c8f0708151330n54b669f5hbf547eeac0e1b84a@mail.gmail.com> On 8/15/07, Priit Tamboom wrote: > Good morning rspec people! > > Still rspec nuby: I must do something wrong obviously. > > How can I spec about redirect_to at ApplicationController > > describe ApplicationController do > it "method login_required should redirect to home path without login" do heh. "it" is so out of place here :) > pending "I tried to use > controller.login_required.should be_redirected > and got NoMethodError with nil object didn't expect error." > end > end > like controller.should_receive(:redirect_to) controller.send :login_required ?? or controller.should_receive(:current_user).and_return(nil) get :foo response.should redirect_to(...) > class ApplicationController < ActionController::Base > # using it with before_filter > def login_required > # I took out everything except redirecting to make the point simple > redirect_to home_path # tried also redirect_to "/" > end > end > > However the code does work manually testing with browser. > > Thanks for any help, > Priit > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Aug 15 16:48:09 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 15 Aug 2007 16:48:09 -0400 Subject: [rspec-users] nuby: how spec redirect_to at ApplicationController In-Reply-To: <4b430c8f0708151330n54b669f5hbf547eeac0e1b84a@mail.gmail.com> References: <4b430c8f0708151330n54b669f5hbf547eeac0e1b84a@mail.gmail.com> Message-ID: <57c63afe0708151348j6dfa6cf6nb14ccf4d055d3d30@mail.gmail.com> On 8/15/07, Courtenay wrote: > On 8/15/07, Priit Tamboom wrote: > > describe ApplicationController do > > it "method login_required should redirect to home path without login" do > > heh. "it" is so out of place here :) I agree. The goal is to describe behaviours of objects, not methods. So, I'd write: it "should redirect anonymous user to home path" Cheers, David From joevandyk at gmail.com Thu Aug 16 02:08:35 2007 From: joevandyk at gmail.com (Joe Van Dyk) Date: Wed, 15 Aug 2007 23:08:35 -0700 Subject: [rspec-users] Mocking a non-existent method Message-ID: I don't like this: i = mock(Integer) i.should_receive(:asdfasdf).and_return('foo') puts i.asdfasdf Shouldn't rspec check to see that :asdfasdf is a valid message to be sending Integer? Joe From steve.tooke at gmail.com Thu Aug 16 07:57:40 2007 From: steve.tooke at gmail.com (Steve Tooke) Date: Thu, 16 Aug 2007 12:57:40 +0100 Subject: [rspec-users] ActsAsList specs In-Reply-To: <4b430c8f0708151122y50a361c8y5f23cf1c6d838e72@mail.gmail.com> References: <78d462040708150452m747ae9d0k10aef7ba208af6db@mail.gmail.com> <4b430c8f0708151122y50a361c8y5f23cf1c6d838e72@mail.gmail.com> Message-ID: <78d462040708160457g65d4a87flf875215e70cb40ff@mail.gmail.com> Hmm that's true. If the acts_as_list implementation changed, or is removed then this isn't going to work. But you don't really want to go down the rabbit warren of checking that the whole of the acts_as_list implementation works as expected, as presumably that's already tested. Perhaps I'm just being over complicated, and you could just mock the call to acts_as_list? Of course that still wouldn't guard against the acts_as_list behaviour changing to something that doesn't match what you were trying to achieve. Thanks, more to think about! On 8/15/07, Courtenay wrote: > On 8/15/07, Steve Tooke wrote: > > Hi, > > > > How are people specifying models which act_as_list? > > > > I'm thinking that it would be possible to check that acts_as_list > > instance methods have been added to a class using something like this: > > You're specing the code not the behavior. > This will make double-work if you want to change anything. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Thu Aug 16 10:11:47 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 16 Aug 2007 10:11:47 -0400 Subject: [rspec-users] expect_render, why does there need to be a warning In-Reply-To: <57c63afe0708151118i36a45934m1b891f67d5dac5ed@mail.gmail.com> References: <85d99afe0708132158ua34f8beq61bd3f3a03c3eb14@mail.gmail.com> <57c63afe0708132316m467f4af7y6fc019096bff2d98@mail.gmail.com> <85d99afe0708140701w4fadd922i5868c962bacfb0fc@mail.gmail.com> <57c63afe0708142041y55efc047m7230f01cd0a26e3e@mail.gmail.com> <85d99afe0708150722x31a5b3fev117546f1c60617eb@mail.gmail.com> <57c63afe0708150728p633fcda1k7401ce89a5429de7@mail.gmail.com> <85d99afe0708151009oef2bde8jc289dc721dcb6812@mail.gmail.com> <57c63afe0708151118i36a45934m1b891f67d5dac5ed@mail.gmail.com> Message-ID: <85d99afe0708160711x62348ea9ocafc1f39b3d8e26@mail.gmail.com> > > > > If i have a view that calls "render :partial => 'foo'" and I don't use > > expect_render I want it to yell at me saying an unexpected call was > > made on the template. > > There's nothing else in rspec_on_rails that yells at you because you > don't like to organize your specs the way rspec thinks they should be > organized, so I definitely wouldn't support this being default > behaviour. It was worth a shot. > > I could see, maybe, the possibility of having a command like > disallow_unexpected_renders or something like that, but I honestly > don't see that much value in it in return for the additional > complexity (didn't you start by saying this was too complex already?). To summarize for anyone else reading this or possibly picking it up in an archive down the road. I was wanting to have a one to one, view to spec. If I had a template called "show.html.erb" I want a "show.html.erb_spec.rb". If "show" had an inline call to render the partial "foo" I want to have a "_foo.html.erb_spec.rb" to test that partial. The one way I see how this can work is to have rspec_on_rails treat all inline render calls as expectations. This would result in a "unexpected call to render :partial => 'foo'" when I ran my "show" spec if I didn't have an "expect_render :partial => 'foo'" line. I do not want to be able to test the contents of the partial "foo" inside of my "show" spec. The reasons I do not want: - possibly multiple view specs testing the same partial - possibly multiple places for each partial to be tested, I'd rather make it easy to know where to go when updating a view and its spec - to add time for a developer having to search for what view a partial is being rendered in and then checking to see if that view's spec is testing the contents of the partial I do want: - consistency, expect_render is an expectation, let it be consistent with how expectations work, I should not get a passing test by potentially rendering the wrong thing - ease of maintainability and readability (which I see a single location is easier to maintain and read then potentially multiple spots) I see the convention of one view to one spec adding more value then it takes away. I may be a little to hardcore though, I also think that "integrate_views" in controller specs should just go away. > > I understand that you DO see value in this, and I'd encourage you to > write a plugin that makes this work the way you want and feel free to > publish it. > I think I'll have to give that a try. Thanks David, Zach From zach.dennis at gmail.com Thu Aug 16 10:17:30 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 16 Aug 2007 10:17:30 -0400 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# Message-ID: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> I am getting: undefined method `mock_model' for [RSpec example]:# with my view specs after upgrading to 1.0.8. Is anyone else seeing this? To isolate the message I did the following setup: - create new rails project (with edge) - installed rspec and rspec_on_rails - ran rake spec - ran script/generate rspec_scaffold products - tried to run a builtin view spec Zach From dchelimsky at gmail.com Thu Aug 16 10:32:02 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 16 Aug 2007 10:32:02 -0400 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> Message-ID: <57c63afe0708160732s365df56bwfbbdca70dc5bafde@mail.gmail.com> On 8/16/07, Zach Dennis wrote: > I am getting: > undefined method `mock_model' for [RSpec example]:# The fact that it says [RSpec example] means that it's not the right class for a view spec. The plugin knows how to create the right class based on one of two things: If the file is below /spec/views/ or describe "...", :behaviour_type => :view do ... If the spec you're running satisfies either of these, you shouldn't be seeing this. > > with my view specs after upgrading to 1.0.8. Is anyone else seeing this? > > To isolate the message I did the following setup: > > - create new rails project (with edge) > - installed rspec and rspec_on_rails > - ran rake spec > - ran script/generate rspec_scaffold products > - tried to run a builtin view spec When you say "builtin view spec," do you mean one that was generated by running the rspec_scaffold generator? > > Zach > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Aug 16 11:08:37 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 16 Aug 2007 11:08:37 -0400 Subject: [rspec-users] expect_render, why does there need to be a warning In-Reply-To: <85d99afe0708160711x62348ea9ocafc1f39b3d8e26@mail.gmail.com> References: <85d99afe0708132158ua34f8beq61bd3f3a03c3eb14@mail.gmail.com> <57c63afe0708132316m467f4af7y6fc019096bff2d98@mail.gmail.com> <85d99afe0708140701w4fadd922i5868c962bacfb0fc@mail.gmail.com> <57c63afe0708142041y55efc047m7230f01cd0a26e3e@mail.gmail.com> <85d99afe0708150722x31a5b3fev117546f1c60617eb@mail.gmail.com> <57c63afe0708150728p633fcda1k7401ce89a5429de7@mail.gmail.com> <85d99afe0708151009oef2bde8jc289dc721dcb6812@mail.gmail.com> <57c63afe0708151118i36a45934m1b891f67d5dac5ed@mail.gmail.com> <85d99afe0708160711x62348ea9ocafc1f39b3d8e26@mail.gmail.com> Message-ID: <57c63afe0708160808i266891a3me7c8d24da022b5cd@mail.gmail.com> On 8/16/07, Zach Dennis wrote: > > > > > > If i have a view that calls "render :partial => 'foo'" and I don't use > > > expect_render I want it to yell at me saying an unexpected call was > > > made on the template. > > > > There's nothing else in rspec_on_rails that yells at you because you > > don't like to organize your specs the way rspec thinks they should be > > organized, so I definitely wouldn't support this being default > > behaviour. > > It was worth a shot. > > > > > I could see, maybe, the possibility of having a command like > > disallow_unexpected_renders or something like that, but I honestly > > don't see that much value in it in return for the additional > > complexity (didn't you start by saying this was too complex already?). > > To summarize for anyone else reading this or possibly picking it up in > an archive down the road. > > I was wanting to have a one to one, view to spec. You can have that. But you don't have to. It's your choice. > If I had a template > called "show.html.erb" I want > a "show.html.erb_spec.rb". If "show" had an inline call to render the > partial "foo" I want to have > a "_foo.html.erb_spec.rb" to test that partial. There is nothing stopping you from doing this. > The one way I see how > this can work is to have > rspec_on_rails treat all inline render calls as expectations. Again, there's nothing stopping you from doing this. There's nothing forcing you to either. That's an important point. >This > would result in a > "unexpected call to render :partial => 'foo'" when I ran my "show" > spec if I didn't have an "expect_render :partial => 'foo'" > line. > > I do not want to be able to test the contents of the partial "foo" > inside of my "show" spec. If you're actually driving your design with the specs, which is what rspec is designed to encourage, the way you do it is this: Spec-drive a view. At the end of several red/green/refactor cycles you'll likely have one spec and one view. Spec-drive another view. Recognize that both views display some of the same stuff. Extract the common stuff into a partial. This last step is refactoring: changing the design without changing the behaviour. Refactoring, ideally, should not require changing any specs. The way things are currently, after you extract the partial, you can run the specs and they pass. With rspec forcing things to work the way you seem to want it to, you couldn't change the design without causing failing specs. After you've refactored the design, extracting the partial, perhaps you want to restructure the specs so that there is only one spec for the partial. At this point, you create a new spec for the partial, moving the examples from one of the two view specs to the partial spec, and then remove the duplicate examples from the other. BDD is a process, not a result. The tools should support the process. What you're asking for would stand in the way of this process. > The reasons > I do not want: > - possibly multiple view specs testing the same partial > - possibly multiple places for each partial to be tested, I'd rather > make it easy to know where to go when updating a view and its spec > - to add time for a developer having to search for what view a > partial is being rendered in and then checking to see if that view's > spec is testing the contents of the partial > > I do want: > - consistency, expect_render is an expectation, let it be consistent > with how expectations work, I should not get a passing test by > potentially rendering the wrong thing How can this happen if you're writing the specs first? > - ease of maintainability and readability (which I see a single > location is easier to maintain and read then potentially multiple > spots) Again, there's nothing stopping you from getting to this. > I see the convention of one view to one spec adding more value then it > takes away. There's a difference between convention and handcuffs. What you are proposing is handcuffs. There is absolutely nothing stopping you from following this convention. > I may be a little to hardcore though, I also think that > "integrate_views" in controller specs should just go away. Again, while RSpec is opinionated in some ways, it also needs to be flexible. Obviously there are boundaries to this, but you and I seem to have these boundaries in different places. The fact that the default is to not integrate views guides you in the direction of strict isolation. But with strict isolation comes a cost, which is that you can get all your component specs working and the app doesn't run because you never had any integration tests. For some, using integrate_views takes the place of having integration tests. Although this is not the approach that I like to take, it is a perfectly reasonable approach and I think it would be wrong for rspec to disallow this. > > I understand that you DO see value in this, and I'd encourage you to > > write a plugin that makes this work the way you want and feel free to > > publish it. > > > > I think I'll have to give that a try. Thanks David, > > Zach > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Thu Aug 16 13:01:06 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 16 Aug 2007 13:01:06 -0400 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <57c63afe0708160732s365df56bwfbbdca70dc5bafde@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <57c63afe0708160732s365df56bwfbbdca70dc5bafde@mail.gmail.com> Message-ID: <85d99afe0708161001w371a6effsea9f7827943eaf39@mail.gmail.com> On 8/16/07, David Chelimsky wrote: > On 8/16/07, Zach Dennis wrote: > > I am getting: > > undefined method `mock_model' for [RSpec example]:# > > The fact that it says [RSpec example] means that it's not the right > class for a view spec. The plugin knows how to create the right class > based on one of two things: > > If the file is below /spec/views/ > > or > > describe "...", :behaviour_type => :view do > ... > > If the spec you're running satisfies either of these, you shouldn't be > seeing this. > > > > > with my view specs after upgrading to 1.0.8. Is anyone else seeing this? > > > > To isolate the message I did the following setup: > > > > - create new rails project (with edge) > > - installed rspec and rspec_on_rails > > - ran rake spec > > - ran script/generate rspec_scaffold products > > - tried to run a builtin view spec > > When you say "builtin view spec," do you mean one that was generated > by running the rspec_scaffold generator? > One that was generated by the rspec_scaffold generator, Zach From jerry.west at ntlworld.com Thu Aug 16 13:04:35 2007 From: jerry.west at ntlworld.com (Jerry West) Date: Thu, 16 Aug 2007 18:04:35 +0100 Subject: [rspec-users] restful named routes In-Reply-To: References: <70EE6770-3ABB-46F4-9195-AE566AD21A12@railsnewbie.com> Message-ID: <003001c7e027$8ff4f410$370aa8c0@CherithSimmons.local> try this: controller.send(:post_comments_path, @post).should == "/posts/22/comments" Rgds, Jerry -----Original Message----- From: rspec-users-bounces at rubyforge.org [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of Jonathan Linowes Sent: 15 August 2007 21:03 To: rspec-users Subject: [rspec-users] restful named routes Hi, revisiting this issue, I feel I'm getting closer: describe CommentsController, "named routes" do before do @post = mock_model(Post, :id => 22) end it "should generate post_comments_path" do controller.post_comments_path(@post).should == "/posts/22/comments" end end results in: NoMethodError in 'CommentsController named routes should generate post_comments_path' protected method `post_comments_path' called for # Is there a way around this? Or how are other testing named routes? thanks linoj On May 29, 2007, at 7:52 AM, Scott Taylor wrote: > > On May 29, 2007, at 4:54 AM, Jonathan Linowes wrote: > >> >> - Is there a way to test named routes? > > I don't think there is a very clean & direct way (hopefully the others > on the list can correct me). The rspec rest generator generates some > code to check the routes, so you could use something like that. > > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Aug 16 13:31:13 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 16 Aug 2007 13:31:13 -0400 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <85d99afe0708161001w371a6effsea9f7827943eaf39@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <57c63afe0708160732s365df56bwfbbdca70dc5bafde@mail.gmail.com> <85d99afe0708161001w371a6effsea9f7827943eaf39@mail.gmail.com> Message-ID: <57c63afe0708161031i426e5edeo1f19058baf2fc028@mail.gmail.com> On 8/16/07, Zach Dennis wrote: > On 8/16/07, David Chelimsky wrote: > > On 8/16/07, Zach Dennis wrote: > > > I am getting: > > > undefined method `mock_model' for [RSpec example]:# > > > > The fact that it says [RSpec example] means that it's not the right > > class for a view spec. The plugin knows how to create the right class > > based on one of two things: > > > > If the file is below /spec/views/ > > > > or > > > > describe "...", :behaviour_type => :view do > > ... > > > > If the spec you're running satisfies either of these, you shouldn't be > > seeing this. > > > > > > > > with my view specs after upgrading to 1.0.8. Is anyone else seeing this? > > > > > > To isolate the message I did the following setup: > > > > > > - create new rails project (with edge) > > > - installed rspec and rspec_on_rails > > > - ran rake spec > > > - ran script/generate rspec_scaffold products > > > - tried to run a builtin view spec > > > > When you say "builtin view spec," do you mean one that was generated > > by running the rspec_scaffold generator? > > > > One that was generated by the rspec_scaffold generator, Sorry man, it should be working fine. I'm not having that experience personally - is anybody else? Zach - what platform are you on? > > Zach > From zach.dennis at gmail.com Thu Aug 16 14:01:06 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 16 Aug 2007 14:01:06 -0400 Subject: [rspec-users] expect_render, why does there need to be a warning In-Reply-To: <57c63afe0708160808i266891a3me7c8d24da022b5cd@mail.gmail.com> References: <85d99afe0708132158ua34f8beq61bd3f3a03c3eb14@mail.gmail.com> <57c63afe0708132316m467f4af7y6fc019096bff2d98@mail.gmail.com> <85d99afe0708140701w4fadd922i5868c962bacfb0fc@mail.gmail.com> <57c63afe0708142041y55efc047m7230f01cd0a26e3e@mail.gmail.com> <85d99afe0708150722x31a5b3fev117546f1c60617eb@mail.gmail.com> <57c63afe0708150728p633fcda1k7401ce89a5429de7@mail.gmail.com> <85d99afe0708151009oef2bde8jc289dc721dcb6812@mail.gmail.com> <57c63afe0708151118i36a45934m1b891f67d5dac5ed@mail.gmail.com> <85d99afe0708160711x62348ea9ocafc1f39b3d8e26@mail.gmail.com> <57c63afe0708160808i266891a3me7c8d24da022b5cd@mail.gmail.com> Message-ID: <85d99afe0708161101r46bba2e4wde5fd03131114b68@mail.gmail.com> > BDD is a process, not a result. The tools should support the process. > What you're asking for would stand in the way of this process. If there is a "disallow_unexpected_renders" that does not stand in the way of the process. It gives people a choice, much like integrate_views gives people a choice. Although I see people using integrate_views are disabling themselves, because they are probably writing horrible specs. Using controller specs to double as view specs to make up for not having integration specs is a big problem in itself. And I see disallow_unexpected_renders enabling themselves to not test the same partials in more then one spot. I get your point though, it's not getting in. Thats ok, Zach From mailing_lists at railsnewbie.com Thu Aug 16 15:13:31 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 16 Aug 2007 15:13:31 -0400 Subject: [rspec-users] Extra Options to Heckle In-Reply-To: <8d961d900708150457w6a001d99t8b2ed18a55f0821b@mail.gmail.com> References: <8d961d900708150457w6a001d99t8b2ed18a55f0821b@mail.gmail.com> Message-ID: <22B3939A-EE9E-496C-AEF8-E6BB259B4B96@railsnewbie.com> On Aug 15, 2007, at 7:57 AM, aslak hellesoy wrote: > On 8/15/07, Scott Taylor wrote: >> >> I've tried running Heckle with rspec on some of my classes, but keep >> getting (what I believe to be) an infinite recursion. Is there some >> way to supply extra options to heckle via. rspec? >> > > Currently not. What options do you want to supply? > > Aslak Aslak, What would be the best format for heckle options (through OptionParser) via the spec-command? Scott From dchelimsky at gmail.com Fri Aug 17 02:59:27 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 17 Aug 2007 02:59:27 -0400 Subject: [rspec-users] Mocking a non-existent method In-Reply-To: References: Message-ID: <57c63afe0708162359p7fe41269ne359a2c7e0dfc669@mail.gmail.com> On 8/16/07, Joe Van Dyk wrote: > I don't like this: > > i = mock(Integer) > i.should_receive(:asdfasdf).and_return('foo') > puts i.asdfasdf > > > Shouldn't rspec check to see that :asdfasdf is a valid message to be > sending Integer? Put simply: no. That's what integration testing is for. > > Joe > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Aug 17 03:03:25 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 17 Aug 2007 03:03:25 -0400 Subject: [rspec-users] ActsAsList specs In-Reply-To: <78d462040708160457g65d4a87flf875215e70cb40ff@mail.gmail.com> References: <78d462040708150452m747ae9d0k10aef7ba208af6db@mail.gmail.com> <4b430c8f0708151122y50a361c8y5f23cf1c6d838e72@mail.gmail.com> <78d462040708160457g65d4a87flf875215e70cb40ff@mail.gmail.com> Message-ID: <57c63afe0708170003s61e68d2u6db0b6bef7d007e6@mail.gmail.com> On 8/16/07, Steve Tooke wrote: > Hmm that's true. > > If the acts_as_list implementation changed, or is removed then this > isn't going to work. But you don't really want to go down the rabbit > warren of checking that the whole of the acts_as_list implementation > works as expected, as presumably that's already tested. > > Perhaps I'm just being over complicated, and you could just mock the > call to acts_as_list? > > Of course that still wouldn't guard against the acts_as_list behaviour > changing to something that doesn't match what you were trying to > achieve. Exactly! You should spec the specific behaviour that YOUR application needs. acts_as_list likely provides more than you are using. If you focus your specs on that which your application needs, then you are safe when you update rails, plugins, etc, because if something changes that breaks what your application relies on, then you'll be alerted by failing specs. If whatever changes appear don't affect what your application cares about, then no problem. > > Thanks, more to think about! > > On 8/15/07, Courtenay wrote: > > On 8/15/07, Steve Tooke wrote: > > > Hi, > > > > > > How are people specifying models which act_as_list? > > > > > > I'm thinking that it would be possible to check that acts_as_list > > > instance methods have been added to a class using something like this: > > > > You're specing the code not the behavior. > > This will make double-work if you want to change anything. > > _______________________________________________ > > 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 Fri Aug 17 04:46:18 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 17 Aug 2007 04:46:18 -0400 Subject: [rspec-users] Mocking a non-existent method In-Reply-To: <57c63afe0708162359p7fe41269ne359a2c7e0dfc669@mail.gmail.com> References: <57c63afe0708162359p7fe41269ne359a2c7e0dfc669@mail.gmail.com> Message-ID: <3EA3375E-72FD-4A10-BD0F-C748B7465E69@railsnewbie.com> On Aug 17, 2007, at 2:59 AM, David Chelimsky wrote: > On 8/16/07, Joe Van Dyk wrote: >> I don't like this: >> >> i = mock(Integer) >> i.should_receive(:asdfasdf).and_return('foo') >> puts i.asdfasdf >> >> >> Shouldn't rspec check to see that :asdfasdf is a valid message to be >> sending Integer? > > Put simply: no. That's what integration testing is for. Speaking of which, how is the rbehave integration going? Or are you done with it? Scott From dchelimsky at gmail.com Fri Aug 17 07:56:51 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 17 Aug 2007 07:56:51 -0400 Subject: [rspec-users] Mocking a non-existent method In-Reply-To: <3EA3375E-72FD-4A10-BD0F-C748B7465E69@railsnewbie.com> References: <57c63afe0708162359p7fe41269ne359a2c7e0dfc669@mail.gmail.com> <3EA3375E-72FD-4A10-BD0F-C748B7465E69@railsnewbie.com> Message-ID: <57c63afe0708170456k19f960f3r76fa9a8dcc208996@mail.gmail.com> On 8/17/07, Scott Taylor wrote: > > On Aug 17, 2007, at 2:59 AM, David Chelimsky wrote: > > > On 8/16/07, Joe Van Dyk wrote: > >> I don't like this: > >> > >> i = mock(Integer) > >> i.should_receive(:asdfasdf).and_return('foo') > >> puts i.asdfasdf > >> > >> > >> Shouldn't rspec check to see that :asdfasdf is a valid message to be > >> sending Integer? > > > > Put simply: no. That's what integration testing is for. > > Speaking of which, how is the rbehave integration going? Or are you > done with it? The import-rbehave branch is now fully functional (passing rake pre_commit). Just waiting to coordinate w/ Dan to merge it into trunk. Coming soon. > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jrich013 at gmail.com Fri Aug 17 14:45:03 2007 From: jrich013 at gmail.com (Justin Rich) Date: Fri, 17 Aug 2007 14:45:03 -0400 Subject: [rspec-users] map.with_options :path_prefix => ' Message-ID: Hello, I am getting a 'No route matches' error in rspec with routes that have a path_prefix composed by map.with_options. Rails recognizes the routes just fine and the site works, but I can't get the specs to pass unless I put the prefix in each individual route. Any help is appreciated. My foo model has a polymorphic owner which is what I want the path_prefix to represent, so my routes.rb has something like... map.with_options :controller => 'foos', :path_prefix => ':owner_type/:owner_id' do |foos| foos.new_foo '/foos/new', :action => 'new' foos.create_foo '/foos', :action => 'create', :conditions => {:method => :post} end And in the foos_controller_spec.rb file is something like... describe FoosController, 'on a GET to new' do it "should make a baby foo" do # some stuff get 'new', :owner_type => 'client', :owner_id => '1' # shoulda's woulda's and coulda's end end Thanks, Justin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070817/971ba700/attachment.html From omen.king at gmail.com Fri Aug 17 15:14:39 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Fri, 17 Aug 2007 15:14:39 -0400 Subject: [rspec-users] [rspec] looking for a simple refresher Message-ID: I've been off the rspec for a few months and I'm trying to get back on it. 1) Spec::Mocks::MockExpectationError in 'TicketsController handling POST /tickets should create a new ticket' Mock 'Ticket_1001' expected :new with ({}) once, but received it 0 times ./spec/controllers/tickets_controller_spec.rb:16: script/spec:4: class TicketsController < ApplicationController def new Ticket.new end end describe TicketsController, "handling POST /tickets" do before do @ticket = mock_model(Ticket, :to_param => '1', :save => true) Ticket.stub!(:new).and_return(@ticket) @params = {} end def do_post post :create, :ticket => @params end it "should create a new ticket" do @ticket.should_receive(:new).with(@params).and_return(@ticket) do_post end end Would someone provide with an explanation what I have to do to make this spec pass? Peepcode hasn't released their screen cast on rspecing controllers yet ='( -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070817/61e34fc1/attachment.html From dchelimsky at gmail.com Fri Aug 17 15:17:29 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 17 Aug 2007 15:17:29 -0400 Subject: [rspec-users] [rspec] looking for a simple refresher In-Reply-To: References: Message-ID: <57c63afe0708171217w1414f170ra4de1784e688b40b@mail.gmail.com> On 8/17/07, Andrew WC Brown wrote: > I've been off the rspec for a few months and I'm trying to get back on it. > > 1) > Spec::Mocks::MockExpectationError in 'TicketsController > handling POST /tickets should create a new ticket' > Mock 'Ticket_1001' expected :new with ({}) once, but received it 0 times > ./spec/controllers/tickets_controller_spec.rb:16: > script/spec:4: > > class TicketsController < ApplicationController > > def new > Ticket.new > end > > end > > describe TicketsController, "handling POST /tickets" do > > before do > @ticket = mock_model(Ticket, :to_param => '1', :save => true) > Ticket.stub!(:new).and_return(@ticket) > @params = {} > end > > def do_post > post :create, :ticket => @params > end > > it "should create a new ticket" do > > @ticket.should_receive(:new).with(@params).and_return(@ticket) This is telling the ticket object to expect new, but it's the Ticket class that will receive it: Ticket.should_receive(:new).with(@params).and_return(@ticket) That should do it. > do_post > end > > end > > Would someone provide with an explanation what I have to do to make this > spec pass? > Peepcode hasn't released their screen cast on rspecing controllers yet ='( > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cody at skidmore.us Fri Aug 17 15:23:58 2007 From: cody at skidmore.us (Cody P. Skidmore) Date: Fri, 17 Aug 2007 12:23:58 -0700 (PDT) Subject: [rspec-users] test Message-ID: <1937.216.167.174.73.1187378638.squirrel@webmail.skidmore.us> This is a test. I sent an email to the list earlier but it looks like no one received it... From cody at skidmore.us Fri Aug 17 10:09:34 2007 From: cody at skidmore.us (Cody P. Skidmore) Date: Fri, 17 Aug 2007 07:09:34 -0700 (PDT) Subject: [rspec-users] RSpec --format --html:/path/to/file.html Message-ID: <3756.216.167.174.73.1187359774.squirrel@webmail.skidmore.us> Greetings everyone. I'm learning RSpec and am pretty fresh to Ruby/Rails, but am so excited I can't help jumping in. I'm running before I can walk here. :-) Yesterday I tried outputting test results to HTML instead of colorized plain text. It looked like there were some entries in the change log for the 1.0.5 release allowing RSpec to do what I wanted. I tried adding a setting to spec.opts but it didn't work to say the least. Here's the change log entry: * The --out option is gone. Use --format html:path/to/my.html instead (or similar). 1. Does this do what I think it should? 2. where can I find documentation on using spec.opts? The command line help doesn't mention a "--format" option. It looks like CI::Reporter [could] output XML format but can it be used independently? I'm mining the documentation for related information but didn't find it so far. Thank you for your help in advance. From court3nay at gmail.com Fri Aug 17 17:31:43 2007 From: court3nay at gmail.com (Courtenay) Date: Fri, 17 Aug 2007 14:31:43 -0700 Subject: [rspec-users] should_receive, used in the wrong place? Message-ID: <4b430c8f0708171431y477d82a9s2a06356541470443@mail.gmail.com> What do you guys think of this: if someone calls should_receive outside of an "it" block, it warns you. before(:each) do @foo = Foo.new @foo.should_receive(:monkeys) end would warn you that you're setting an expectation in the wrong place, and that "stub" is correct when setting up objects. Opinions? courtenay From lancecarlson at gmail.com Fri Aug 17 17:34:09 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Fri, 17 Aug 2007 17:34:09 -0400 Subject: [rspec-users] should_receive, used in the wrong place? In-Reply-To: <4b430c8f0708171431y477d82a9s2a06356541470443@mail.gmail.com> References: <4b430c8f0708171431y477d82a9s2a06356541470443@mail.gmail.com> Message-ID: <49f64a900708171434s51cfadd7gaddb7570625bdf5c@mail.gmail.com> what about template.should_receive(:current_user)? I don't know if that's a bad idea to do that in the before(:each) but it's more convenient.. On 8/17/07, Courtenay wrote: > What do you guys think of this: if someone calls should_receive > outside of an "it" block, it warns you. > > before(:each) do > @foo = Foo.new > @foo.should_receive(:monkeys) > end > > would warn you that you're setting an expectation in the wrong place, > and that "stub" is correct when setting up objects. > > Opinions? > > > courtenay > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From court3nay at gmail.com Fri Aug 17 17:47:09 2007 From: court3nay at gmail.com (Courtenay) Date: Fri, 17 Aug 2007 14:47:09 -0700 Subject: [rspec-users] should_receive, used in the wrong place? In-Reply-To: <49f64a900708171434s51cfadd7gaddb7570625bdf5c@mail.gmail.com> References: <4b430c8f0708171431y477d82a9s2a06356541470443@mail.gmail.com> <49f64a900708171434s51cfadd7gaddb7570625bdf5c@mail.gmail.com> Message-ID: <4b430c8f0708171447g72fa1ddbvff6515c2169aabad@mail.gmail.com> That's exactly my point; enforcing the difference between should_receive vs stub! On 8/17/07, Lance Carlson wrote: > what about template.should_receive(:current_user)? > > I don't know if that's a bad idea to do that in the before(:each) but > it's more convenient.. > > On 8/17/07, Courtenay wrote: > > What do you guys think of this: if someone calls should_receive > > outside of an "it" block, it warns you. > > > > before(:each) do > > @foo = Foo.new > > @foo.should_receive(:monkeys) > > end > > > > would warn you that you're setting an expectation in the wrong place, > > and that "stub" is correct when setting up objects. > > > > Opinions? > > > > > > courtenay > > _______________________________________________ > > 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 lancecarlson at gmail.com Fri Aug 17 17:48:02 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Fri, 17 Aug 2007 17:48:02 -0400 Subject: [rspec-users] should_receive, used in the wrong place? In-Reply-To: <4b430c8f0708171447g72fa1ddbvff6515c2169aabad@mail.gmail.com> References: <4b430c8f0708171431y477d82a9s2a06356541470443@mail.gmail.com> <49f64a900708171434s51cfadd7gaddb7570625bdf5c@mail.gmail.com> <4b430c8f0708171447g72fa1ddbvff6515c2169aabad@mail.gmail.com> Message-ID: <49f64a900708171448x50b2fefdkfe46b22e288a0938@mail.gmail.com> I agree :) On 8/17/07, Courtenay wrote: > That's exactly my point; enforcing the difference between > should_receive vs stub! > > On 8/17/07, Lance Carlson wrote: > > what about template.should_receive(:current_user)? > > > > I don't know if that's a bad idea to do that in the before(:each) but > > it's more convenient.. > > > > On 8/17/07, Courtenay wrote: > > > What do you guys think of this: if someone calls should_receive > > > outside of an "it" block, it warns you. > > > > > > before(:each) do > > > @foo = Foo.new > > > @foo.should_receive(:monkeys) > > > end > > > > > > would warn you that you're setting an expectation in the wrong place, > > > and that "stub" is correct when setting up objects. > > > > > > Opinions? > > > > > > > > > courtenay > > > _______________________________________________ > > > 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 omen.king at gmail.com Fri Aug 17 19:11:33 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Fri, 17 Aug 2007 19:11:33 -0400 Subject: [rspec-users] [rspec] looking for a simple refresher In-Reply-To: <57c63afe0708171217w1414f170ra4de1784e688b40b@mail.gmail.com> References: <57c63afe0708171217w1414f170ra4de1784e688b40b@mail.gmail.com> Message-ID: I replaced: @ticket.should_receive(:new).with(@params).and_return(@ticket) with Ticket.should_receive(:new).with(@params).and_return(@ticket) Similar Error 1) Spec::Mocks::MockExpectationError in 'TicketsController handling POST /tickets should create a new ticket' Mock 'Class' expected :new with ({}) once, but received it 0 times ./spec/controllers/tickets_controller_spec.rb:16: If I omit @params = {} then I get the error as following 1) Spec::Mocks::MockExpectationError in 'TicketsController handling POST /tickets should create a new ticket' Mock 'Class' expected :new with (any args) once, but received it 0 times ./spec/controllers/tickets_controller_spec.rb:16: So its not receiving the new method at all even though I clearly called it. Could it be possible that the issue is with the actual Ticket model itself? On 8/17/07, David Chelimsky wrote: > > On 8/17/07, Andrew WC Brown wrote: > > I've been off the rspec for a few months and I'm trying to get back on > it. > > > > 1) > > Spec::Mocks::MockExpectationError in 'TicketsController > > handling POST /tickets should create a new ticket' > > Mock 'Ticket_1001' expected :new with ({}) once, but received it 0 > times > > ./spec/controllers/tickets_controller_spec.rb:16: > > script/spec:4: > > > > class TicketsController < ApplicationController > > > > def new > > Ticket.new > > end > > > > end > > > > describe TicketsController, "handling POST /tickets" do > > > > before do > > @ticket = mock_model(Ticket, :to_param => '1', :save => true) > > Ticket.stub!(:new).and_return(@ticket) > > @params = {} > > end > > > > def do_post > > post :create, :ticket => @params > > end > > > > it "should create a new ticket" do > > > > @ticket.should_receive(:new).with(@params).and_return(@ticket) > > This is telling the ticket object to expect new, but it's the Ticket > class that will receive it: > > Ticket.should_receive(:new).with(@params).and_return(@ticket) > > That should do it. > > > do_post > > end > > > > end > > > > Would someone provide with an explanation what I have to do to make this > > spec pass? > > Peepcode hasn't released their screen cast on rspecing controllers yet > ='( > > > > > > > > > > > > _______________________________________________ > > 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 > -- Monsterbox Productions putting small businesses on-line 1319 Victoria Avenue East Thunder Bay, Ontario P7C 1C3 Canada Andrew WC Brown web-developer and owner andrew at monsterboxpro.com P: 807-626-9009 F: 807-624-2705 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070817/61e06183/attachment.html From dchelimsky at gmail.com Fri Aug 17 19:23:24 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 17 Aug 2007 19:23:24 -0400 Subject: [rspec-users] [rspec] looking for a simple refresher In-Reply-To: References: <57c63afe0708171217w1414f170ra4de1784e688b40b@mail.gmail.com> Message-ID: <57c63afe0708171623v58a29315gfff6dbafd6b3bdbe@mail.gmail.com> Sorry - totally missed the controller code in your first example. You're posting to create, not new: de create Ticket.new end That should do the trick. On 8/17/07, Andrew WC Brown wrote: > I replaced: > > @ticket.should_receive(:new).with(@params).and_return(@ticket) > > with > > Ticket.should_receive(:new).with(@params).and_return(@ticket) > > Similar Error > > 1) > Spec::Mocks::MockExpectationError in 'TicketsController > handling POST /tickets should create a new ticket' > Mock 'Class' expected :new with ({}) once, but received it 0 times > ./spec/controllers/tickets_controller_spec.rb:16: > > If I omit @params = {} then I get the error as following > > 1) > Spec::Mocks::MockExpectationError in 'TicketsController > handling POST /tickets should create a new ticket' > Mock 'Class' expected :new with (any args) once, but received it 0 times > ./spec/controllers/tickets_controller_spec.rb:16: > > So its not receiving the new method at all even though I clearly called it. > Could it be possible that the issue is with the actual Ticket model itself? > > > On 8/17/07, David Chelimsky wrote: > > On 8/17/07, Andrew WC Brown wrote: > > > I've been off the rspec for a few months and I'm trying to get back on > it. > > > > > > 1) > > > Spec::Mocks::MockExpectationError in > 'TicketsController > > > handling POST /tickets should create a new ticket' > > > Mock 'Ticket_1001' expected :new with ({}) once, but received it 0 > times > > > ./spec/controllers/tickets_controller_spec.rb:16: > > > script/spec:4: > > > > > > class TicketsController < ApplicationController > > > > > > def new > > > Ticket.new > > > end > > > > > > end > > > > > > describe TicketsController, "handling POST /tickets" do > > > > > > before do > > > @ticket = mock_model(Ticket, :to_param => '1', :save => true) > > > Ticket.stub!(:new).and_return(@ticket) > > > @params = {} > > > end > > > > > > def do_post > > > post :create, :ticket => @params > > > end > > > > > > it "should create a new ticket" do > > > > > > > @ticket.should_receive(:new).with(@params).and_return(@ticket) > > > > This is telling the ticket object to expect new, but it's the Ticket > > class that will receive it: > > > > > Ticket.should_receive(:new).with(@params).and_return(@ticket) > > > > That should do it. > > > > > do_post > > > end > > > > > > end > > > > > > Would someone provide with an explanation what I have to do to make this > > > spec pass? > > > Peepcode hasn't released their screen cast on rspecing controllers yet > ='( > > > > > > > > > > > > > > > > > > _______________________________________________ > > > 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 > > > > > > -- > Monsterbox Productions > putting small businesses on-line > > 1319 Victoria Avenue East > Thunder Bay, Ontario P7C 1C3 > Canada > > Andrew WC Brown > web-developer and owner > andrew at monsterboxpro.com > P: 807-626-9009 > F: 807-624-2705 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Aug 17 19:24:41 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 17 Aug 2007 19:24:41 -0400 Subject: [rspec-users] [rspec] looking for a simple refresher In-Reply-To: <57c63afe0708171623v58a29315gfff6dbafd6b3bdbe@mail.gmail.com> References: <57c63afe0708171217w1414f170ra4de1784e688b40b@mail.gmail.com> <57c63afe0708171623v58a29315gfff6dbafd6b3bdbe@mail.gmail.com> Message-ID: <57c63afe0708171624t4ba0cc77of38c7c8c3980a777@mail.gmail.com> def create (not de create) On 8/17/07, David Chelimsky wrote: > Sorry - totally missed the controller code in your first example. > You're posting to create, not new: > de create > Ticket.new > end > > That should do the trick. > > > On 8/17/07, Andrew WC Brown wrote: > > I replaced: > > > > @ticket.should_receive(:new).with(@params).and_return(@ticket) > > > > with > > > > Ticket.should_receive(:new).with(@params).and_return(@ticket) > > > > Similar Error > > > > 1) > > Spec::Mocks::MockExpectationError in 'TicketsController > > handling POST /tickets should create a new ticket' > > Mock 'Class' expected :new with ({}) once, but received it 0 times > > ./spec/controllers/tickets_controller_spec.rb:16: > > > > If I omit @params = {} then I get the error as following > > > > 1) > > Spec::Mocks::MockExpectationError in 'TicketsController > > handling POST /tickets should create a new ticket' > > Mock 'Class' expected :new with (any args) once, but received it 0 times > > ./spec/controllers/tickets_controller_spec.rb:16: > > > > So its not receiving the new method at all even though I clearly called it. > > Could it be possible that the issue is with the actual Ticket model itself? > > > > > > On 8/17/07, David Chelimsky wrote: > > > On 8/17/07, Andrew WC Brown wrote: > > > > I've been off the rspec for a few months and I'm trying to get back on > > it. > > > > > > > > 1) > > > > Spec::Mocks::MockExpectationError in > > 'TicketsController > > > > handling POST /tickets should create a new ticket' > > > > Mock 'Ticket_1001' expected :new with ({}) once, but received it 0 > > times > > > > ./spec/controllers/tickets_controller_spec.rb:16: > > > > script/spec:4: > > > > > > > > class TicketsController < ApplicationController > > > > > > > > def new > > > > Ticket.new > > > > end > > > > > > > > end > > > > > > > > describe TicketsController, "handling POST /tickets" do > > > > > > > > before do > > > > @ticket = mock_model(Ticket, :to_param => '1', :save => true) > > > > Ticket.stub!(:new).and_return(@ticket) > > > > @params = {} > > > > end > > > > > > > > def do_post > > > > post :create, :ticket => @params > > > > end > > > > > > > > it "should create a new ticket" do > > > > > > > > > > @ticket.should_receive(:new).with(@params).and_return(@ticket) > > > > > > This is telling the ticket object to expect new, but it's the Ticket > > > class that will receive it: > > > > > > > > Ticket.should_receive(:new).with(@params).and_return(@ticket) > > > > > > That should do it. > > > > > > > do_post > > > > end > > > > > > > > end > > > > > > > > Would someone provide with an explanation what I have to do to make this > > > > spec pass? > > > > Peepcode hasn't released their screen cast on rspecing controllers yet > > ='( > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > 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 > > > > > > > > > > > -- > > Monsterbox Productions > > putting small businesses on-line > > > > 1319 Victoria Avenue East > > Thunder Bay, Ontario P7C 1C3 > > Canada > > > > Andrew WC Brown > > web-developer and owner > > andrew at monsterboxpro.com > > P: 807-626-9009 > > F: 807-624-2705 > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From rupert_apsc at rupespad.com Fri Aug 17 19:25:16 2007 From: rupert_apsc at rupespad.com (rupert) Date: Sat, 18 Aug 2007 00:25:16 +0100 Subject: [rspec-users] [rspec] looking for a simple refresher In-Reply-To: References: <57c63afe0708171217w1414f170ra4de1784e688b40b@mail.gmail.com> Message-ID: what's in the create method of the controller?? you've only given the contents of the new method - and without knowing what you want it to do it's hard to know what will work. Assuming it's the normal def create @ticket = Ticket.new(params(:ticket]) if @ticket.save ....etc etc end then something like the following should work: describe TicketsController, "handling POST /tickets" do before do @ticket = mock_model(Ticket, :save => true) Ticket.stub!(:new).and_return(@ticket) @params = {} end def do_post post :create, :ticket => @params end it "should create a new ticket" do ticket.should_receive(:new).with(@params).and_return(@ticket) do_post end it "should assign the ticket for the view" do do_post assigns[:ticket].should equal(@ticket) end it "should save the new ticket" do @ticket.should_receive(:save).with().and_return(true) do_post end end On 18 Aug 2007, at 00:11, Andrew WC Brown wrote: > I replaced: > > @ticket.should_receive(:new).with(@params).and_return(@ticket) > > with > > Ticket.should_receive(:new).with(@params).and_return(@ticket) > > Similar Error > > 1) > Spec::Mocks::MockExpectationError in 'TicketsController handling > POST /tickets should create a new ticket' > Mock 'Class' expected :new with ({}) once, but received it 0 times > ./spec/controllers/tickets_controller_spec.rb:16: > > If I omit @params = {} then I get the error as following > > 1) > Spec::Mocks::MockExpectationError in 'TicketsController handling > POST /tickets should create a new ticket' > Mock 'Class' expected :new with (any args) once, but received it 0 > times > ./spec/controllers/tickets_controller_spec.rb:16: > > So its not receiving the new method at all even though I clearly > called it. > Could it be possible that the issue is with the actual Ticket model > itself? > > On 8/17/07, David Chelimsky wrote: > On 8/17/07, Andrew WC Brown wrote: > > I've been off the rspec for a few months and I'm trying to get > back on it. > > > > 1) > > Spec::Mocks::MockExpectationError in 'TicketsController > > handling POST /tickets should create a new ticket' > > Mock 'Ticket_1001' expected :new with ({}) once, but received it > 0 times > > ./spec/controllers/tickets_controller_spec.rb:16: > > script/spec:4: > > > > class TicketsController < ApplicationController > > > > def new > > Ticket.new > > end > > > > end > > > > describe TicketsController, "handling POST /tickets" do > > > > before do > > @ticket = mock_model(Ticket, :to_param => '1', :save => true) > > Ticket.stub!(:new).and_return(@ticket) > > @params = {} > > end > > > > def do_post > > post :create, :ticket => @params > > end > > > > it "should create a new ticket" do > > > > @ticket.should_receive(:new).with(@params).and_return(@ticket) > > This is telling the ticket object to expect new, but it's the Ticket > class that will receive it: > > Ticket.should_receive(:new).with(@params).and_return(@ticket) > > That should do it. > > > do_post > > end > > > > end > > > > Would someone provide with an explanation what I have to do to > make this > > spec pass? > > Peepcode hasn't released their screen cast on rspecing > controllers yet ='( > > > > > > > > > > > > _______________________________________________ > > 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 > > > > -- > Monsterbox Productions > putting small businesses on-line > > 1319 Victoria Avenue East > Thunder Bay, Ontario P7C 1C3 > Canada > > Andrew WC Brown > web-developer and owner > andrew at monsterboxpro.com > P: 807-626-9009 > F: 807-624-2705 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070818/204c9f2c/attachment.html From omen.king at gmail.com Fri Aug 17 19:36:00 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Fri, 17 Aug 2007 19:36:00 -0400 Subject: [rspec-users] [rspec] looking for a simple refresher In-Reply-To: References: <57c63afe0708171217w1414f170ra4de1784e688b40b@mail.gmail.com> Message-ID: That makes a-lot of sense. That 'new' word threw me off. My create method is slightly more complex and I'm not sure how to spec it. def create @user = User.find(params[:user_id]) @ticket = @user.tickets.build(params[:ticket]) if @ticket.save redirect_to tickets_path else render new_usr_ticket_path(params[:user_id]) end end Would I need two mock_models? On 8/17/07, rupert wrote: > > what's in the create method of the controller?? you've only given the > contents of the new method - and without knowing what you want it to do it's > hard to know what will work. > Assuming it's the normal > > def create > @ticket = Ticket.new(params(:ticket]) > if @ticket.save > ....etc etc > end > > then something like the following should work: > > describe TicketsController, "handling POST /tickets" do > before do > @ticket = mock_model(Ticket, :save => true) > Ticket.stub!(:new).and_return(@ticket) > @params = {} > end > > def do_post > post :create, :ticket => @params > end > > it "should create a new ticket" do > ticket.should_receive(:new).with(@params).and_return(@ticket) > do_post > end > > it "should assign the ticket for the view" do > do_post > assigns[:ticket].should equal(@ticket) > end > > it "should save the new ticket" do > @ticket.should_receive(:save).with().and_return(true) > do_post > end > end > > On 18 Aug 2007, at 00:11, Andrew WC Brown wrote: > > I replaced: > > @ticket.should_receive(:new).with(@params).and_return(@ticket) > > with > > Ticket.should_receive(:new).with(@params).and_return(@ticket) > > Similar Error > > 1) > Spec::Mocks::MockExpectationError in 'TicketsController handling POST > /tickets should create a new ticket' > Mock 'Class' expected :new with ({}) once, but received it 0 times > ./spec/controllers/tickets_controller_spec.rb:16: > > If I omit @params = {} then I get the error as following > > 1) > Spec::Mocks::MockExpectationError in 'TicketsController handling POST > /tickets should create a new ticket' > Mock 'Class' expected :new with (any args) once, but received it 0 times > ./spec/controllers/tickets_controller_spec.rb:16: > > So its not receiving the new method at all even though I clearly called > it. > Could it be possible that the issue is with the actual Ticket model > itself? > > On 8/17/07, David Chelimsky wrote: > > > > On 8/17/07, Andrew WC Brown wrote: > > > I've been off the rspec for a few months and I'm trying to get back on > > it. > > > > > > 1) > > > Spec::Mocks::MockExpectationError in 'TicketsController > > > handling POST /tickets should create a new ticket' > > > Mock 'Ticket_1001' expected :new with ({}) once, but received it 0 > > times > > > ./spec/controllers/tickets_controller_spec.rb:16: > > > script/spec:4: > > > > > > class TicketsController < ApplicationController > > > > > > def new > > > Ticket.new > > > end > > > > > > end > > > > > > describe TicketsController, "handling POST /tickets" do > > > > > > before do > > > @ticket = mock_model(Ticket, :to_param => '1', :save => true) > > > Ticket.stub!(:new).and_return(@ticket) > > > @params = {} > > > end > > > > > > def do_post > > > post :create, :ticket => @params > > > end > > > > > > it "should create a new ticket" do > > > > > > @ticket.should_receive(:new).with(@params).and_return(@ticket) > > > > This is telling the ticket object to expect new, but it's the Ticket > > class that will receive it: > > > > Ticket.should_receive(:new).with(@params).and_return(@ticket) > > > > That should do it. > > > > > do_post > > > end > > > > > > end > > > > > > Would someone provide with an explanation what I have to do to make > > this > > > spec pass? > > > Peepcode hasn't released their screen cast on rspecing controllers yet > > ='( > > > > > > > > > > > > > > > > > > _______________________________________________ > > > 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 > > > > > > -- > Monsterbox Productions > putting small businesses on-line > > 1319 Victoria Avenue East > Thunder Bay, Ontario P7C 1C3 > Canada > > Andrew WC Brown > web-developer and owner > andrew at monsterboxpro.com > P: 807-626-9009 > F: 807-624-2705_______________________________________________ > 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 > -- Monsterbox Productions putting small businesses on-line 1319 Victoria Avenue East Thunder Bay, Ontario P7C 1C3 Canada Andrew WC Brown web-developer and owner andrew at monsterboxpro.com P: 807-626-9009 F: 807-624-2705 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070817/2dad90e6/attachment.html From rupert_apsc at rupespad.com Fri Aug 17 19:54:51 2007 From: rupert_apsc at rupespad.com (rupert) Date: Sat, 18 Aug 2007 00:54:51 +0100 Subject: [rspec-users] [rspec] looking for a simple refresher In-Reply-To: References: <57c63afe0708171217w1414f170ra4de1784e688b40b@mail.gmail.com> Message-ID: Not entirely sure how to go about mocking the association, but it's going to be something along these lines (totally untested!).... describe TicketsController, "handling POST /tickets" do before do @ticket = mock_model(Ticket, :save => true) @user_tickets_association = mock("accociation") @user_tickets_association.stub!(:build).and_return(@ticket) @user = mock_model(User) @user.stub!(:tickets).and_return(@user_tickets_association) @ticket_params = {} end def do_post post :create, :ticket => @params, :user_id => "user_id" end it "should find the user" do User.should_receive(:find).with("user_id").and_return(@user) do_post end it "should assign the user for the view" do do_post assigns[:user].should equal(@user) end it "should build a new ticket on the user" do @user_tickets_association.should_receive(:build).with (@params).and_return(@ticket) do_post end it "should assign the ticket for the view" do do_post assigns[:ticket].should equal(@ticket) end it "should save the new ticket" do @ticket.should_receive(:save).with().and_return(true) do_post end it "should save the new ticket" do @ticket.should_receive(:save).with().and_return(true) do_post end it "should redirect to the ticket path if successful" do do_post response.should redirect_to('/tickets') end it "should render the new page if create fails" do @ticket.stub!(:save).and_return(false) do_post response.should render_template('new') end end On 18 Aug 2007, at 00:36, Andrew WC Brown wrote: > That makes a-lot of sense. That 'new' word threw me off. > > My create method is slightly more complex and I'm not sure how to > spec it. > > def create > @user = User.find(params[:user_id]) > @ticket = @ user.tickets.build(params[:ticket]) > if @ticket.save > redirect_to tickets_path > else > render new_usr_ticket_path(params[:user_id]) > end > end > > > Would I need two mock_models? > > On 8/17/07, rupert wrote: > what's in the create method of the controller?? you've only given > the contents of the new method - and without knowing what you want > it to do it's hard to know what will work. > > Assuming it's the normal > > def create > @ticket = Ticket.new(params(:ticket]) > if @ticket.save > ....etc etc > end > > then something like the following should work: > > describe TicketsController, "handling POST /tickets" do > before do > @ticket = mock_model(Ticket, :save => true) > Ticket.stub!(:new).and_return(@ticket) > @params = {} > end > > def do_post > post :create, :ticket => @params > end > > it "should create a new ticket" do > ticket.should_receive(:new).with(@params).and_return(@ticket) > do_post > end > > it "should assign the ticket for the view" do > do_post > assigns[:ticket].should equal(@ticket) > end > > it "should save the new ticket" do > @ticket.should_receive(:save).with().and_return(true) > do_post > end > end > > > On 18 Aug 2007, at 00:11, Andrew WC Brown wrote: > >> I replaced: >> >> @ticket.should_receive (:new).with(@params).and_return(@ticket) >> >> with >> >> Ticket.should_receive(:new).with(@params).and_return(@ticket) >> >> Similar Error >> >> 1) >> Spec::Mocks::MockExpectationError in 'TicketsController handling >> POST /tickets should create a new ticket' >> Mock 'Class' expected :new with ({}) once, but received it 0 times >> ./spec/controllers/tickets_controller_spec.rb:16: >> >> If I omit @params = {} then I get the error as following >> >> 1) >> Spec::Mocks::MockExpectationError in 'TicketsController handling >> POST /tickets should create a new ticket' >> Mock 'Class' expected :new with (any args) once, but received it 0 >> times >> ./spec/controllers/tickets_controller_spec.rb:16: >> >> So its not receiving the new method at all even though I clearly >> called it. >> Could it be possible that the issue is with the actual Ticket >> model itself? >> >> On 8/17/07, David Chelimsky < dchelimsky at gmail.com > wrote: >> On 8/17/07, Andrew WC Brown < omen.king at gmail.com > wrote: >> > I've been off the rspec for a few months and I'm trying to get >> back on it. >> > >> > 1) >> > Spec::Mocks::MockExpectationError in 'TicketsController >> > handling POST /tickets should create a new ticket' >> > Mock 'Ticket_1001' expected :new with ({}) once, but received >> it 0 times >> > ./spec/controllers/tickets_controller_spec.rb:16: >> > script/spec:4: >> > >> > class TicketsController < ApplicationController >> > >> > def new >> > Ticket.new >> > end >> > >> > end >> > >> > describe TicketsController, "handling POST /tickets" do >> > >> > before do >> > @ticket = mock_model(Ticket, :to_param => '1', :save => true) >> > Ticket.stub!(:new).and_return(@ticket) >> > @params = {} >> > end >> > >> > def do_post >> > post :create, :ticket => @params >> > end >> > >> > it "should create a new ticket" do >> > >> > @ticket.should_receive(:new).with(@params).and_return(@ticket) >> >> This is telling the ticket object to expect new, but it's the Ticket >> class that will receive it: >> >> Ticket.should_receive(:new).with(@params).and_return(@ticket) >> >> That should do it. >> >> > do_post >> > end >> > >> > end >> > >> > Would someone provide with an explanation what I have to do to >> make this >> > spec pass? >> > Peepcode hasn't released their screen cast on rspecing >> controllers yet ='( >> > >> > >> > >> > >> > >> > _______________________________________________ >> > 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 >> >> >> >> -- >> Monsterbox Productions >> putting small businesses on-line >> >> 1319 Victoria Avenue East >> Thunder Bay, Ontario P7C 1C3 >> Canada >> >> Andrew WC Brown >> web-developer and owner >> andrew at monsterboxpro.com >> P: 807-626-9009 >> F: 807-624-2705 >> _______________________________________________ >> 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 > > > > -- > Monsterbox Productions > putting small businesses on-line > > 1319 Victoria Avenue East > Thunder Bay, Ontario P7C 1C3 > Canada > > Andrew WC Brown > web-developer and owner > andrew at monsterboxpro.com > P: 807-626-9009 > F: 807-624-2705 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070818/ba347153/attachment-0001.html From omen.king at gmail.com Fri Aug 17 20:03:15 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Fri, 17 Aug 2007 20:03:15 -0400 Subject: [rspec-users] [rspec] looking for a simple refresher In-Reply-To: References: <57c63afe0708171217w1414f170ra4de1784e688b40b@mail.gmail.com> Message-ID: thats pretty much what I thought, I'll give it a push around and e-mail back the results On 8/17/07, rupert wrote: > > Not entirely sure how to go about mocking the association, but it's going > to be something along these lines (totally untested!).... > > describe TicketsController, "handling POST /tickets" do > before do > @ticket = mock_model(Ticket, :save => true) > > @user_tickets_association = mock("accociation") > @user_tickets_association.stub!(:build).and_return(@ticket) > > @user = mock_model(User) > @user.stub!(:tickets).and_return(@user_tickets_association) > > @ticket_params = {} > end > def do_post > post :create, :ticket => @params, :user_id => "user_id" > end > > it "should find the user" do > User.should_receive(:find).with("user_id").and_return(@user) > do_post > end > it "should assign the user for the view" do > do_post > assigns[:user].should equal(@user) > end > it "should build a new ticket on the user" do > > @user_tickets_association.should_receive(:build).with(@params).and_return(@ticket) > do_post > end > it "should assign the ticket for the view" do > do_post > assigns[:ticket].should equal(@ticket) > end > it "should save the new ticket" do > @ticket.should_receive(:save).with().and_return(true) > do_post > end > > it "should save the new ticket" do > @ticket.should_receive(:save).with().and_return(true) > do_post > end > > it "should redirect to the ticket path if successful" do > do_post > response.should redirect_to('/tickets') > end > > it "should render the new page if create fails" do > @ticket.stub!(:save).and_return(false) > do_post > response.should render_template('new') > end > end > > > > On 18 Aug 2007, at 00:36, Andrew WC Brown wrote: > > That makes a-lot of sense. That 'new' word threw me off. > > My create method is slightly more complex and I'm not sure how to spec it. > > def create > @user = User.find(params[:user_id]) > @ticket = @ user.tickets.build(params[:ticket]) > if @ticket.save > redirect_to tickets_path > else > render new_usr_ticket_path(params[:user_id]) > end > end > > > Would I need two mock_models? > > On 8/17/07, rupert wrote: > > > > what's in the create method of the controller?? you've only given the > > contents of the new method - and without knowing what you want it to do it's > > hard to know what will work. > > Assuming it's the normal > > > > def create > > @ticket = Ticket.new(params(:ticket]) > > if @ticket.save > > ....etc etc > > end > > > > then something like the following should work: > > > > describe TicketsController, "handling POST /tickets" do > > before do > > @ticket = mock_model(Ticket, :save => true) > > Ticket.stub!(:new).and_return(@ticket) > > @params = {} > > end > > > > def do_post > > post :create, :ticket => @params > > end > > > > it "should create a new ticket" do > > ticket.should_receive(:new).with(@params).and_return(@ticket) > > do_post > > end > > > > it "should assign the ticket for the view" do > > do_post > > assigns[:ticket].should equal(@ticket) > > end > > > > it "should save the new ticket" do > > @ticket.should_receive(:save).with().and_return(true) > > do_post > > end > > end > > > > On 18 Aug 2007, at 00:11, Andrew WC Brown wrote: > > > > I replaced: > > > > @ticket.should_receive (:new).with(@params).and_return(@ticket) > > > > with > > > > Ticket.should_receive(:new).with(@params).and_return(@ticket) > > > > Similar Error > > > > 1) > > Spec::Mocks::MockExpectationError in 'TicketsController handling POST > > /tickets should create a new ticket' > > Mock 'Class' expected :new with ({}) once, but received it 0 times > > ./spec/controllers/tickets_controller_spec.rb:16: > > > > If I omit @params = {} then I get the error as following > > > > 1) > > Spec::Mocks::MockExpectationError in 'TicketsController handling POST > > /tickets should create a new ticket' > > Mock 'Class' expected :new with (any args) once, but received it 0 times > > ./spec/controllers/tickets_controller_spec.rb:16: > > > > So its not receiving the new method at all even though I clearly called > > it. > > Could it be possible that the issue is with the actual Ticket model > > itself? > > > > On 8/17/07, David Chelimsky < dchelimsky at gmail.com > wrote: > > > > > > On 8/17/07, Andrew WC Brown < omen.king at gmail.com > wrote: > > > > I've been off the rspec for a few months and I'm trying to get back > > > on it. > > > > > > > > 1) > > > > Spec::Mocks::MockExpectationError in 'TicketsController > > > > handling POST /tickets should create a new ticket' > > > > Mock 'Ticket_1001' expected :new with ({}) once, but received it 0 > > > times > > > > ./spec/controllers/tickets_controller_spec.rb:16: > > > > script/spec:4: > > > > > > > > class TicketsController < ApplicationController > > > > > > > > def new > > > > Ticket.new > > > > end > > > > > > > > end > > > > > > > > describe TicketsController, "handling POST /tickets" do > > > > > > > > before do > > > > @ticket = mock_model(Ticket, :to_param => '1', :save => true) > > > > Ticket.stub!(:new).and_return(@ticket) > > > > @params = {} > > > > end > > > > > > > > def do_post > > > > post :create, :ticket => @params > > > > end > > > > > > > > it "should create a new ticket" do > > > > > > > > @ticket.should_receive(:new).with(@params).and_return(@ticket) > > > > > > This is telling the ticket object to expect new, but it's the Ticket > > > class that will receive it: > > > > > > Ticket.should_receive(:new).with(@params).and_return(@ticket) > > > > > > That should do it. > > > > > > > do_post > > > > end > > > > > > > > end > > > > > > > > Would someone provide with an explanation what I have to do to make > > > this > > > > spec pass? > > > > Peepcode hasn't released their screen cast on rspecing controllers > > > yet ='( > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > 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 > > > > > > > > > > > -- > > Monsterbox Productions > > putting small businesses on-line > > > > 1319 Victoria Avenue East > > Thunder Bay, Ontario P7C 1C3 > > Canada > > > > Andrew WC Brown > > web-developer and owner > > andrew at monsterboxpro.com > > P: 807-626-9009 > > F: 807-624-2705_______________________________________________ > > 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 > > > > > > -- > Monsterbox Productions > putting small businesses on-line > > 1319 Victoria Avenue East > Thunder Bay, Ontario P7C 1C3 > Canada > > Andrew WC Brown > web-developer and owner > andrew at monsterboxpro.com > P: 807-626-9009 > F: 807-624-2705_______________________________________________ > 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 > -- Monsterbox Productions putting small businesses on-line 1319 Victoria Avenue East Thunder Bay, Ontario P7C 1C3 Canada Andrew WC Brown web-developer and owner andrew at monsterboxpro.com P: 807-626-9009 F: 807-624-2705 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070817/9cba7847/attachment.html From rupespad1 at mac.com Fri Aug 17 20:08:45 2007 From: rupespad1 at mac.com (Rupert Voelcker) Date: Sat, 18 Aug 2007 01:08:45 +0100 Subject: [rspec-users] [rspec] looking for a simple refresher In-Reply-To: References: <57c63afe0708171217w1414f170ra4de1784e688b40b@mail.gmail.com> Message-ID: > thats pretty much what I thought, I'll give it a push around and e- > mail back the results cool - good luck ...I'm off to bed as it's 1am here in the UK but I'm sure one of the useful chaps round here 'll help you out with any probs btw, I just noticed I've put @ticket_params = {} in the before declaration and it needs to be @params = {} Cheers From cody at skidmore.us Fri Aug 17 23:22:01 2007 From: cody at skidmore.us (Cody P. Skidmore) Date: Fri, 17 Aug 2007 22:22:01 -0500 Subject: [rspec-users] Formatting runner output as HTML Message-ID: <000901c7e146$f1f31af0$0202a8c0@cody> I found documentation on Runner & calling Spec on the command line. I'm able to run it on multiple models or a single one and format the output as HTML now. Previously I used the Rake task expecting it to behave the same way passing --format html:path/to/file.html or setting it somehow in spec.opts. But I'm not quite there yet. Should the Rake task work the same way or is everyone just calling Spec instead? With Sincere Regards, Cody P. Skidmore -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070817/d982fc7a/attachment-0001.html From willyrubbit at yahoo.co.uk Sat Aug 18 00:19:13 2007 From: willyrubbit at yahoo.co.uk (AR) Date: Sat, 18 Aug 2007 05:19:13 +0100 Subject: [rspec-users] Tests for render when changing view_paths Message-ID: Hi there, I've been getting into RSpec recently and I must say what a fantastic product I think it is. But, I've hit a bit of a problem. In my ApplicationHelper I have a method which changes the view_paths in a controller so a partial can be rendered from a different base directory. It simply takes an array of view_paths that a partial could be in, updates the view_paths for the controller doing the initial rendering, does the rendering, then removes the paths at the end. Here's the code: module ApplicationHelper def render_partial_with_alternate_view_paths(view_paths, options = {}) view_path_removes = view_paths.inject([]){ |rp, path| self.view_paths.include?(path) ? rp : rp.push(path) } self.view_paths = self.view_paths + view_path_removes returning render( options ) do self.view_paths = self.view_paths - view_path_removes end end end I've tried writing specifications for this in the helper, the view and the controller parts, but get different errors each time. the closest I've managed to get so far is: it "should render a partial from a path in the supplied view_paths and leave view_paths the same afterwards" do options = {:partial => 'application/pod', :locals => {:the_value => "sent value"}, :layout => 'application/layout' } original_paths = ["/path/to/rails_app/app/views"] extra_paths = ["/path/to/rails_app/spec/views"] all_paths = original_paths + extra_paths self.should_receive(:view_paths).and_return(original_paths, original_paths, all_paths) self.should_receive(:view_paths=).with(all_paths).once.ordered self.should_receive(:view_paths=).with(original_paths).once.ordered self.should_receive(:render) render_partial_with_alternate_view_paths(extra_paths, options) end I've put this code in a helper spec, but I can't check what the partial has rendered. I'm really confused and can't work out where the spec should go and what bits should be mocked out and how. Any help would be gratefully appreciated. Thanks, Ant From dchelimsky at gmail.com Sat Aug 18 01:59:15 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 18 Aug 2007 01:59:15 -0400 Subject: [rspec-users] RSpec --format --html:/path/to/file.html In-Reply-To: <3756.216.167.174.73.1187359774.squirrel@webmail.skidmore.us> References: <3756.216.167.174.73.1187359774.squirrel@webmail.skidmore.us> Message-ID: <57c63afe0708172259s46844894l1a3c5d6beccd9974@mail.gmail.com> On 8/17/07, Cody P. Skidmore wrote: > Greetings everyone. I'm learning RSpec and am pretty fresh to Ruby/Rails, > but am so excited I can't help jumping in. I'm running before I can walk > here. :-) > > Yesterday I tried outputting test results to HTML instead of colorized > plain text. It looked like there were some entries in the change log for > the 1.0.5 release allowing RSpec to do what I wanted. > > I tried adding a setting to spec.opts but it didn't work to say the least. > Here's the change log entry: > > * The --out option is gone. Use --format html:path/to/my.html instead (or > similar). > > 1. Does this do what I think it should? In spec.opts, each line represents one command line arg, so you'd have to do this (on two separate lines): --format html:/path/to/my.html Then on the command line: spec spec -O path/to/spec.opts > 2. where can I find documentation on using spec.opts? The command line > help doesn't mention a "--format" option. Look at http://rspec.rubyforge.org/documentation/tools/spec.html. If you scroll down you'll see the output from the spec command. It definitely mentions the --format option. > It looks like CI::Reporter [could] output XML format but can it be used > independently? > > I'm mining the documentation for related information but didn't find it so > far. > > Thank you for your help in advance. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Aug 18 02:02:04 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 18 Aug 2007 02:02:04 -0400 Subject: [rspec-users] should_receive, used in the wrong place? In-Reply-To: <4b430c8f0708171447g72fa1ddbvff6515c2169aabad@mail.gmail.com> References: <4b430c8f0708171431y477d82a9s2a06356541470443@mail.gmail.com> <49f64a900708171434s51cfadd7gaddb7570625bdf5c@mail.gmail.com> <4b430c8f0708171447g72fa1ddbvff6515c2169aabad@mail.gmail.com> Message-ID: <57c63afe0708172302w2465448bgc431109bd5393a51@mail.gmail.com> On 8/17/07, Courtenay wrote: > That's exactly my point; enforcing the difference between > should_receive vs stub! Great convention, but I think making the tool enforce it is a bit restrictive. > On 8/17/07, Lance Carlson wrote: > > what about template.should_receive(:current_user)? > > > > I don't know if that's a bad idea to do that in the before(:each) but > > it's more convenient.. > > > > On 8/17/07, Courtenay wrote: > > > What do you guys think of this: if someone calls should_receive > > > outside of an "it" block, it warns you. > > > > > > before(:each) do > > > @foo = Foo.new > > > @foo.should_receive(:monkeys) > > > end > > > > > > would warn you that you're setting an expectation in the wrong place, > > > and that "stub" is correct when setting up objects. > > > > > > Opinions? > > > > > > > > > courtenay > > > _______________________________________________ > > > 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 Sat Aug 18 02:03:32 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 18 Aug 2007 02:03:32 -0400 Subject: [rspec-users] Formatting runner output as HTML In-Reply-To: <000901c7e146$f1f31af0$0202a8c0@cody> References: <000901c7e146$f1f31af0$0202a8c0@cody> Message-ID: <57c63afe0708172303p774ceecdi21857aaac8d557da@mail.gmail.com> On 8/17/07, Cody P. Skidmore wrote: > > I found documentation on Runner & calling Spec on the command line. I'm > able to run it on multiple models or a single one and format the output as > HTML now. Previously I used the Rake task expecting it to behave the same > way passing ?-format html:path/to/file.html or setting it somehow in > spec.opts. But I'm not quite there yet. Should the Rake task work the same > way or is everyone just calling Spec instead? As per my response to another thread, each command line argument must be on its own line in spec.opts. So: --format html:/path/to/my.html > > > > > With Sincere Regards, > > > > Cody P. Skidmore > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Sat Aug 18 04:38:02 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 18 Aug 2007 04:38:02 -0400 Subject: [rspec-users] Test::Unit to RSpec Message-ID: <992B8A68-0B0B-4440-8A9D-9C5E2B492A6D@railsnewbie.com> So I've just started working on a rails project which currently has something like 7500 LOC. All of the tests are written in Test::Unit, although the test coverage is pretty poor: rcov says that 25% of the code is covered, while rake stats shows the code to test ratio as 1:0.1 (800 lines of test code). I guess I'm wondering what would generally be advisable here. Is it worth it to work on (or use) a test:unit => spec translator? Should I just start using rspec when I need to start writing code, and perform regressions when need be? Or is the project too big to even consider using rspec? Thanks in advance for any experienced advice, Scott Taylor From davidjrice at gmail.com Sat Aug 18 15:22:08 2007 From: davidjrice at gmail.com (David Rice) Date: Sat, 18 Aug 2007 20:22:08 +0100 Subject: [rspec-users] RSpec and acts_as_attachment Message-ID: <8620F4A8-EE68-439F-93F6-BFDEDF65167E@gmail.com> Hey guys, I'm getting a weird error when trying to test something like the following. It's a model that is using acts_as_attachment but the weird thing is the equivalent Test::Unit case passes. Does anyone have any ideas? Best, Dave # it was a Test::Unit case first def test_should_be_invalid_without_file UserFile.any_instance.expects(:with_image).never assert_no_difference UserFile, :count do user_file = create_user_file :uploaded_data => nil assert user_file.errors.on(:filename) assert user_file.errors.on(:size) assert user_file.errors.on(:content_type) end end # Converting the above to the following spec it 'should be invalid without file' do @user_file = create_user_file :uploaded_data => nil @user_file.should have(1).error_on(:filename) @user_file.should have(1).error_on(:size) @user_file.should have(1).error_on(:content_type) end # The spec fails with the following error # ============ should be invalid without file wrong number of arguments (0 for 1) vendor/plugins/acts_as_attachment/lib/technoweenie/acts_as_attachment/ instance_methods.rb:154 :in `content_type' vendor/plugins/acts_as_attachment/lib/technoweenie/acts_as_attachment/ instance_methods.rb:154 :in `send' vendor/plugins/acts_as_attachment/lib/technoweenie/acts_as_attachment/ instance_methods.rb:154 :in `attachment_attributes_valid?' vendor/plugins/acts_as_attachment/lib/technoweenie/acts_as_attachment/ instance_methods.rb:152 :in `each' vendor/plugins/acts_as_attachment/lib/technoweenie/acts_as_attachment/ instance_methods.rb:152 :in `attachment_attributes_valid?' ./spec/models/../spec_helper.rb:635 :in `create_user_file' ./spec/models/user_file_spec.rb:11 152 [:size, :content_type].each do |attr_name| 153 enum = attachment_options[attr_name] 154 errors.add attr_name, ActiveRecord::Errors.default_error_messages[:inclusion] unless enum.nil? || enum.include?(send(attr_name)) 155 end 156 end --- David Rice http://www.davidjrice.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070818/72cee8c1/attachment.html From robert.feldt at bth.se Sun Aug 19 02:05:18 2007 From: robert.feldt at bth.se (Robert Feldt) Date: Sun, 19 Aug 2007 08:05:18 +0200 Subject: [rspec-users] Extra Options to Heckle In-Reply-To: <22B3939A-EE9E-496C-AEF8-E6BB259B4B96@railsnewbie.com> References: <8d961d900708150457w6a001d99t8b2ed18a55f0821b@mail.gmail.com> <22B3939A-EE9E-496C-AEF8-E6BB259B4B96@railsnewbie.com> Message-ID: <87a13e220708182305p7e50c95dv4e21ba5afc8ee9db@mail.gmail.com> What would be the best format for heckle options (through > OptionParser) via the spec-command? When we discussed this a few months back I proposed something like: One alternative I thought of is to have a standard way to "promote" options to other tools that spec invokes. Along the lines of: spec --heckle --options-heckle "--verbose --branches MyModule::MyClass#my_method" ... and the argument to --options-heckle (or --options-rcov etc) would simply be passed along in the call to heckle. This would cover more situations with a single solution. /Robert Feldt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070819/bd8b80da/attachment-0001.html From mailing_lists at railsnewbie.com Sun Aug 19 02:35:06 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 19 Aug 2007 02:35:06 -0400 Subject: [rspec-users] Extra Options to Heckle In-Reply-To: <87a13e220708182305p7e50c95dv4e21ba5afc8ee9db@mail.gmail.com> References: <8d961d900708150457w6a001d99t8b2ed18a55f0821b@mail.gmail.com> <22B3939A-EE9E-496C-AEF8-E6BB259B4B96@railsnewbie.com> <87a13e220708182305p7e50c95dv4e21ba5afc8ee9db@mail.gmail.com> Message-ID: On Aug 19, 2007, at 2:05 AM, Robert Feldt wrote: > > > What would be the best format for heckle options (through > OptionParser) via the spec-command? > > When we discussed this a few months back I proposed something like: > > > One alternative I thought of is to have a standard way to "promote" > options to other tools that spec invokes. Along the lines of: > > spec --heckle --options-heckle "--verbose --branches > MyModule::MyClass#my_method" ... > > and the argument to --options-heckle (or --options-rcov etc) would > simply be passed along in the call to heckle. This would cover more > situations with a single solution. > I've cooked up a patch for a tiny-little recursive parser in the command line parsing to deal with the promotion of options, so that you could do something like this: spec --heckle "MyClass --verbose --timeout 10" So far only the --verbose and --timeout options are used (and I'm not sure that they are even working yet, since I haven't used heckle on anything but an rspec project). I haven't worked more on the patch because I figured it would get rejected for the added complexity in command line parsing of arguments. Robert: Maybe if you would like to take a look at my changes, I could email you what I have so far, and we could divide up work on the rest of the heckle options. So far I have two, and there are only 8 or so, and at this point most of them look pretty trivial to implement. Scott From robert.feldt at bth.se Sun Aug 19 02:52:01 2007 From: robert.feldt at bth.se (Robert Feldt) Date: Sun, 19 Aug 2007 08:52:01 +0200 Subject: [rspec-users] Extra Options to Heckle In-Reply-To: References: <8d961d900708150457w6a001d99t8b2ed18a55f0821b@mail.gmail.com> <22B3939A-EE9E-496C-AEF8-E6BB259B4B96@railsnewbie.com> <87a13e220708182305p7e50c95dv4e21ba5afc8ee9db@mail.gmail.com> Message-ID: <87a13e220708182352k343f751cu4da0d7cd9c274e72@mail.gmail.com> > > One alternative I thought of is to have a standard way to "promote" > > options to other tools that spec invokes. Along the lines of: > > > > spec --heckle --options-heckle "--verbose --branches > > MyModule::MyClass#my_method" ... > > > > and the argument to --options-heckle (or --options-rcov etc) would > > simply be passed along in the call to heckle. This would cover more > > situations with a single solution. > > > > I've cooked up a patch for a tiny-little recursive parser in the > command line parsing to deal with the promotion of options, so that > you could do something like this: > > spec --heckle "MyClass --verbose --timeout 10" > > So far only the --verbose and --timeout options are used (and I'm not > sure that they are even working yet, since I haven't used heckle on > anything but an rspec project). > > I haven't worked more on the patch because I figured it would get > rejected for the added complexity in command line parsing of arguments. > > Robert: Maybe if you would like to take a look at my changes, I could > email you what I have so far, and we could divide up work on the rest > of the heckle options. So far I have two, and there are only 8 or > so, and at this point most of them look pretty trivial to implement. But why do you need to parse the contents of the string with the options that should be passed onto heckle? The idea is that it should simply be passed on. I'm probably missing something... ;) /Robert Scott > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Best regards, /Robert Feldt -- PhD, Assistant Professor in Software Engineering Blekinge Institute of Technology School of Engineering (APS) SE-372 25 Ronneby Sweden Phone: +46 (0) 457 385 887 Mobile: +46 (0) 733 580 580 Web pages: Research group: http://www.bth.se/tek/serl/ Research project: http://www.bth.se/besq/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070819/5ad76b88/attachment.html From mailing_lists at railsnewbie.com Sun Aug 19 04:25:21 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 19 Aug 2007 04:25:21 -0400 Subject: [rspec-users] Extra Options to Heckle In-Reply-To: <87a13e220708182352k343f751cu4da0d7cd9c274e72@mail.gmail.com> References: <8d961d900708150457w6a001d99t8b2ed18a55f0821b@mail.gmail.com> <22B3939A-EE9E-496C-AEF8-E6BB259B4B96@railsnewbie.com> <87a13e220708182305p7e50c95dv4e21ba5afc8ee9db@mail.gmail.com> <87a13e220708182352k343f751cu4da0d7cd9c274e72@mail.gmail.com> Message-ID: <2D4AE521-AB30-403A-A71E-BA053148B17F@railsnewbie.com> On Aug 19, 2007, at 2:52 AM, Robert Feldt wrote: > > > One alternative I thought of is to have a standard way to "promote" > > options to other tools that spec invokes. Along the lines of: > > > > spec --heckle --options-heckle "--verbose --branches > > MyModule::MyClass#my_method" ... > > > > and the argument to --options-heckle (or --options-rcov etc) would > > simply be passed along in the call to heckle. This would cover more > > situations with a single solution. > > > > I've cooked up a patch for a tiny-little recursive parser in the > command line parsing to deal with the promotion of options, so that > you could do something like this: > > spec --heckle "MyClass --verbose --timeout 10" > > So far only the --verbose and --timeout options are used (and I'm not > sure that they are even working yet, since I haven't used heckle on > anything but an rspec project). > > I haven't worked more on the patch because I figured it would get > rejected for the added complexity in command line parsing of > arguments. > > Robert: Maybe if you would like to take a look at my changes, I could > email you what I have so far, and we could divide up work on the rest > of the heckle options. So far I have two, and there are only 8 or > so, and at this point most of them look pretty trivial to implement. > > But why do you need to parse the contents of the string with the > options that should be passed onto heckle? The idea is that it > should simply be passed on. I'm probably missing something... ;) Well - parsing in two regards: 1. On the command line, so that Ruby's OptionParser doesn't think that a "--verbose" is a command to rspec. This alone isn't really an issue until you factor in spec.opts, which is read in as a string (so some detection of escaping must occur). 2. So that it can be used by the RSpec wrapper to Heckle. Heckle has a base Heckle class, as well as a TestUnitHeckler class, which descends from the Heckle class. All Hecker's (the command you run, not the class) option parser does is set some default class variables in the two classes (Heckle & TestUnitHeckler), so some of those class level setters would need to be changed, anyway. This would probably be clearer just by looking at the code for heckle + the relevant code in rspec. Scott From zach.dennis at gmail.com Sun Aug 19 12:01:30 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Sun, 19 Aug 2007 12:01:30 -0400 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <57c63afe0708161031i426e5edeo1f19058baf2fc028@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <57c63afe0708160732s365df56bwfbbdca70dc5bafde@mail.gmail.com> <85d99afe0708161001w371a6effsea9f7827943eaf39@mail.gmail.com> <57c63afe0708161031i426e5edeo1f19058baf2fc028@mail.gmail.com> Message-ID: <85d99afe0708190901o71d0b022v464638bf3a7c5ce1@mail.gmail.com> On 8/16/07, David Chelimsky wrote: > On 8/16/07, Zach Dennis wrote: > > On 8/16/07, David Chelimsky wrote: > > > On 8/16/07, Zach Dennis wrote: > > > > I am getting: > > > > undefined method `mock_model' for [RSpec example]:# > > > > > > The fact that it says [RSpec example] means that it's not the right > > > class for a view spec. The plugin knows how to create the right class > > > based on one of two things: > > > > > > If the file is below /spec/views/ > > > > > > or > > > > > > describe "...", :behaviour_type => :view do > > > ... > > > > > > If the spec you're running satisfies either of these, you shouldn't be > > > seeing this. > > > > > > > > > > > with my view specs after upgrading to 1.0.8. Is anyone else seeing this? > > > > > > > > To isolate the message I did the following setup: > > > > > > > > - create new rails project (with edge) > > > > - installed rspec and rspec_on_rails > > > > - ran rake spec > > > > - ran script/generate rspec_scaffold products > > > > - tried to run a builtin view spec > > > > > > When you say "builtin view spec," do you mean one that was generated > > > by running the rspec_scaffold generator? > > > > > > > One that was generated by the rspec_scaffold generator, > > Sorry man, it should be working fine. I'm not having that experience > personally - is anybody else? > > Zach - what platform are you on? > I tried on OSX and also Kubuntu Feisty. I think the rspec scaffold generators need to be updated to include ", :behaviour_type => :view". Zach From dchelimsky at gmail.com Sun Aug 19 12:38:59 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 19 Aug 2007 12:38:59 -0400 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <85d99afe0708190901o71d0b022v464638bf3a7c5ce1@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <57c63afe0708160732s365df56bwfbbdca70dc5bafde@mail.gmail.com> <85d99afe0708161001w371a6effsea9f7827943eaf39@mail.gmail.com> <57c63afe0708161031i426e5edeo1f19058baf2fc028@mail.gmail.com> <85d99afe0708190901o71d0b022v464638bf3a7c5ce1@mail.gmail.com> Message-ID: <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> On 8/19/07, Zach Dennis wrote: > On 8/16/07, David Chelimsky wrote: > > On 8/16/07, Zach Dennis wrote: > > > On 8/16/07, David Chelimsky wrote: > > > > On 8/16/07, Zach Dennis wrote: > > > > > I am getting: > > > > > undefined method `mock_model' for [RSpec example]:# > > > > > > > > The fact that it says [RSpec example] means that it's not the right > > > > class for a view spec. The plugin knows how to create the right class > > > > based on one of two things: > > > > > > > > If the file is below /spec/views/ > > > > > > > > or > > > > > > > > describe "...", :behaviour_type => :view do > > > > ... > > > > > > > > If the spec you're running satisfies either of these, you shouldn't be > > > > seeing this. > > > > > > > > > > > > > > with my view specs after upgrading to 1.0.8. Is anyone else seeing this? > > > > > > > > > > To isolate the message I did the following setup: > > > > > > > > > > - create new rails project (with edge) > > > > > - installed rspec and rspec_on_rails > > > > > - ran rake spec > > > > > - ran script/generate rspec_scaffold products > > > > > - tried to run a builtin view spec > > > > > > > > When you say "builtin view spec," do you mean one that was generated > > > > by running the rspec_scaffold generator? > > > > > > > > > > One that was generated by the rspec_scaffold generator, > > > > Sorry man, it should be working fine. I'm not having that experience > > personally - is anybody else? > > > > Zach - what platform are you on? > > > > I tried on OSX and also Kubuntu Feisty. I think the rspec scaffold > generators need to be updated to include ", :behaviour_type => > :view". I'd like to avoid that because it would be extra noise and it shouldn't be necessary. The generated specs work absolutely perfectly for me as/is (I'm on OS X). There have been a couple of bugs related to regexps and windows paths over time, but they've either been resolved or await more feedback from users in the tracker. I'm thinking about other ways to be explicit about this (besides the verbose ":behaviour_type => :view". What if we added methods like: describe_model describe_view describe_controller describe_helper Or support the first argument being a Symbol: describe :model, "Thing" do I'm not sure I like those, but I kind of dislike :behaviour_type => :foo as a default. WDYT? David > > Zach > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From edward.og at gmail.com Sun Aug 19 16:33:35 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Sun, 19 Aug 2007 16:33:35 -0400 Subject: [rspec-users] describing a mock_model as being an instance Message-ID: <46C8A91F.6070208@gmail.com> Is there a built-in way of describing a mock_model as being an instance, beyond stubbing the eval("Object.methods - Object.new.methods") methods to throw NoMethodErrors? Edward From dchelimsky at gmail.com Sun Aug 19 20:00:13 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 19 Aug 2007 20:00:13 -0400 Subject: [rspec-users] describing a mock_model as being an instance In-Reply-To: <46C8A91F.6070208@gmail.com> References: <46C8A91F.6070208@gmail.com> Message-ID: <57c63afe0708191700s44505f80g8529343dc3ef10bb@mail.gmail.com> On 8/19/07, Edward Ocampo-Gooding wrote: > Is there a built-in way of describing a mock_model as being an instance, beyond > stubbing the eval("Object.methods - Object.new.methods") methods to throw > NoMethodErrors? Huh? Can you give an example of what you are trying to achieve? > > Edward > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From edward.og at gmail.com Sun Aug 19 21:22:58 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Sun, 19 Aug 2007 21:22:58 -0400 Subject: [rspec-users] describing a mock_model as being an instance In-Reply-To: <57c63afe0708191700s44505f80g8529343dc3ef10bb@mail.gmail.com> References: <46C8A91F.6070208@gmail.com> <57c63afe0708191700s44505f80g8529343dc3ef10bb@mail.gmail.com> Message-ID: <46C8ECF2.1010502@gmail.com> David Chelimsky wrote: > On 8/19/07, Edward Ocampo-Gooding wrote: >> Is there a built-in way of describing a mock_model as being an instance, beyond >> stubbing the eval("Object.methods - Object.new.methods") methods to throw >> NoMethodErrors? > > Huh? Can you give an example of what you are trying to achieve? I'm writing a method that involves deciding if an object is a class or an instance of a class. Right now I'm creating a mock_model and setting up an expectation on respond_to? :new but I've got a feeling that this isn't the way to go. The current mock_model returns an object that looks more like a class based on the methods it has (I should actually go look now and check if it's got the typical instantiated Object methods too...), and I'm wondering if there's a clean way of creating a mock_model instance that has typical instantiated Object methods and no Object class methods. Edward From court3nay at gmail.com Mon Aug 20 01:00:08 2007 From: court3nay at gmail.com (Courtenay) Date: Sun, 19 Aug 2007 22:00:08 -0700 Subject: [rspec-users] describing a mock_model as being an instance In-Reply-To: <46C8ECF2.1010502@gmail.com> References: <46C8A91F.6070208@gmail.com> <57c63afe0708191700s44505f80g8529343dc3ef10bb@mail.gmail.com> <46C8ECF2.1010502@gmail.com> Message-ID: <4b430c8f0708192200j514acc5x78e52bbccb7d19a8@mail.gmail.com> On 8/19/07, Edward Ocampo-Gooding wrote: > David Chelimsky wrote: > > On 8/19/07, Edward Ocampo-Gooding wrote: > >> Is there a built-in way of describing a mock_model as being an instance, beyond > >> stubbing the eval("Object.methods - Object.new.methods") methods to throw > >> NoMethodErrors? > > > > Huh? Can you give an example of what you are trying to achieve? > > I'm writing a method that involves deciding if an object is a class or an > instance of a class. Right now I'm creating a mock_model and setting up an > expectation on respond_to? :new but I've got a feeling that this isn't the way > to go. > > The current mock_model returns an object that looks more like a class based on > the methods it has (I should actually go look now and check if it's got the > typical instantiated Object methods too...), and I'm wondering if there's a > clean way of creating a mock_model instance that has typical instantiated Object > methods and no Object class methods. > > Edward > > Is there a reason it needs to be more complicated than this? class Foo end Foo.is_a?(Class) => true Foo.new.is_a?(Class) => false From mailing_lists at railsnewbie.com Mon Aug 20 01:17:14 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 20 Aug 2007 01:17:14 -0400 Subject: [rspec-users] RSpec --format --html:/path/to/file.html In-Reply-To: <57c63afe0708172259s46844894l1a3c5d6beccd9974@mail.gmail.com> References: <3756.216.167.174.73.1187359774.squirrel@webmail.skidmore.us> <57c63afe0708172259s46844894l1a3c5d6beccd9974@mail.gmail.com> Message-ID: On Aug 18, 2007, at 1:59 AM, David Chelimsky wrote: > On 8/17/07, Cody P. Skidmore wrote: >> Greetings everyone. I'm learning RSpec and am pretty fresh to >> Ruby/Rails, >> but am so excited I can't help jumping in. I'm running before I >> can walk >> here. :-) >> >> Yesterday I tried outputting test results to HTML instead of >> colorized >> plain text. It looked like there were some entries in the change >> log for >> the 1.0.5 release allowing RSpec to do what I wanted. >> >> I tried adding a setting to spec.opts but it didn't work to say >> the least. >> Here's the change log entry: >> >> * The --out option is gone. Use --format html:path/to/my.html >> instead (or >> similar). >> >> 1. Does this do what I think it should? > > > In spec.opts, each line represents one command line arg, so you'd have > to do this (on two separate lines): > Actually you can combine then in any way you choose. This would work as well: --format html:/foo/bar > --format > html:/path/to/my.html > > Then on the command line: > > spec spec -O path/to/spec.opts > >> 2. where can I find documentation on using spec.opts? The >> command line >> help doesn't mention a "--format" option. > > Look at http://rspec.rubyforge.org/documentation/tools/spec.html. If > you scroll down you'll see the output from the spec command. It > definitely mentions the --format option. > > >> It looks like CI::Reporter [could] output XML format but can it be >> used >> independently? >> >> I'm mining the documentation for related information but didn't >> find it so >> far. If you really wanted to dump to XML, I'm sure you could build your own formatter. Check out the different defaults ones which come with rspec, under trunk/rspec/lib/spec/runner/formatter/ Scott From mailing_lists at railsnewbie.com Mon Aug 20 01:17:14 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 20 Aug 2007 01:17:14 -0400 Subject: [rspec-users] RSpec --format --html:/path/to/file.html In-Reply-To: <57c63afe0708172259s46844894l1a3c5d6beccd9974@mail.gmail.com> References: <3756.216.167.174.73.1187359774.squirrel@webmail.skidmore.us> <57c63afe0708172259s46844894l1a3c5d6beccd9974@mail.gmail.com> Message-ID: On Aug 18, 2007, at 1:59 AM, David Chelimsky wrote: > On 8/17/07, Cody P. Skidmore wrote: >> Greetings everyone. I'm learning RSpec and am pretty fresh to >> Ruby/Rails, >> but am so excited I can't help jumping in. I'm running before I >> can walk >> here. :-) >> >> Yesterday I tried outputting test results to HTML instead of >> colorized >> plain text. It looked like there were some entries in the change >> log for >> the 1.0.5 release allowing RSpec to do what I wanted. >> >> I tried adding a setting to spec.opts but it didn't work to say >> the least. >> Here's the change log entry: >> >> * The --out option is gone. Use --format html:path/to/my.html >> instead (or >> similar). >> >> 1. Does this do what I think it should? > > > In spec.opts, each line represents one command line arg, so you'd have > to do this (on two separate lines): > Actually you can combine then in any way you choose. This would work as well: --format html:/foo/bar > --format > html:/path/to/my.html > > Then on the command line: > > spec spec -O path/to/spec.opts > >> 2. where can I find documentation on using spec.opts? The >> command line >> help doesn't mention a "--format" option. > > Look at http://rspec.rubyforge.org/documentation/tools/spec.html. If > you scroll down you'll see the output from the spec command. It > definitely mentions the --format option. > > >> It looks like CI::Reporter [could] output XML format but can it be >> used >> independently? >> >> I'm mining the documentation for related information but didn't >> find it so >> far. If you really wanted to dump to XML, I'm sure you could build your own formatter. Check out the different defaults ones which come with rspec, under trunk/rspec/lib/spec/runner/formatter/ Scott From mailing_lists at railsnewbie.com Mon Aug 20 01:17:14 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 20 Aug 2007 01:17:14 -0400 Subject: [rspec-users] RSpec --format --html:/path/to/file.html In-Reply-To: <57c63afe0708172259s46844894l1a3c5d6beccd9974@mail.gmail.com> References: <3756.216.167.174.73.1187359774.squirrel@webmail.skidmore.us> <57c63afe0708172259s46844894l1a3c5d6beccd9974@mail.gmail.com> Message-ID: On Aug 18, 2007, at 1:59 AM, David Chelimsky wrote: > On 8/17/07, Cody P. Skidmore wrote: >> Greetings everyone. I'm learning RSpec and am pretty fresh to >> Ruby/Rails, >> but am so excited I can't help jumping in. I'm running before I >> can walk >> here. :-) >> >> Yesterday I tried outputting test results to HTML instead of >> colorized >> plain text. It looked like there were some entries in the change >> log for >> the 1.0.5 release allowing RSpec to do what I wanted. >> >> I tried adding a setting to spec.opts but it didn't work to say >> the least. >> Here's the change log entry: >> >> * The --out option is gone. Use --format html:path/to/my.html >> instead (or >> similar). >> >> 1. Does this do what I think it should? > > > In spec.opts, each line represents one command line arg, so you'd have > to do this (on two separate lines): > Actually you can combine then in any way you choose. This would work as well: --format html:/foo/bar > --format > html:/path/to/my.html > > Then on the command line: > > spec spec -O path/to/spec.opts > >> 2. where can I find documentation on using spec.opts? The >> command line >> help doesn't mention a "--format" option. > > Look at http://rspec.rubyforge.org/documentation/tools/spec.html. If > you scroll down you'll see the output from the spec command. It > definitely mentions the --format option. > > >> It looks like CI::Reporter [could] output XML format but can it be >> used >> independently? >> >> I'm mining the documentation for related information but didn't >> find it so >> far. If you really wanted to dump to XML, I'm sure you could build your own formatter. Check out the different defaults ones which come with rspec, under trunk/rspec/lib/spec/runner/formatter/ Scott From aslak.hellesoy at gmail.com Mon Aug 20 04:35:58 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 20 Aug 2007 10:35:58 +0200 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <57c63afe0708160732s365df56bwfbbdca70dc5bafde@mail.gmail.com> <85d99afe0708161001w371a6effsea9f7827943eaf39@mail.gmail.com> <57c63afe0708161031i426e5edeo1f19058baf2fc028@mail.gmail.com> <85d99afe0708190901o71d0b022v464638bf3a7c5ce1@mail.gmail.com> <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> Message-ID: <8d961d900708200135s43c83c81nb8461b36fd0ae2b2@mail.gmail.com> On 8/19/07, David Chelimsky wrote: > On 8/19/07, Zach Dennis wrote: > > On 8/16/07, David Chelimsky wrote: > > > On 8/16/07, Zach Dennis wrote: > > > > On 8/16/07, David Chelimsky wrote: > > > > > On 8/16/07, Zach Dennis wrote: > > > > > > I am getting: > > > > > > undefined method `mock_model' for [RSpec example]:# > > > > > > > > > > The fact that it says [RSpec example] means that it's not the right > > > > > class for a view spec. The plugin knows how to create the right class > > > > > based on one of two things: > > > > > > > > > > If the file is below /spec/views/ > > > > > > > > > > or > > > > > > > > > > describe "...", :behaviour_type => :view do > > > > > ... > > > > > > > > > > If the spec you're running satisfies either of these, you shouldn't be > > > > > seeing this. > > > > > > > > > > > > > > > > > with my view specs after upgrading to 1.0.8. Is anyone else seeing this? > > > > > > > > > > > > To isolate the message I did the following setup: > > > > > > > > > > > > - create new rails project (with edge) > > > > > > - installed rspec and rspec_on_rails > > > > > > - ran rake spec > > > > > > - ran script/generate rspec_scaffold products > > > > > > - tried to run a builtin view spec > > > > > > > > > > When you say "builtin view spec," do you mean one that was generated > > > > > by running the rspec_scaffold generator? > > > > > > > > > > > > > One that was generated by the rspec_scaffold generator, > > > > > > Sorry man, it should be working fine. I'm not having that experience > > > personally - is anybody else? > > > > > > Zach - what platform are you on? > > > > > > > I tried on OSX and also Kubuntu Feisty. I think the rspec scaffold > > generators need to be updated to include ", :behaviour_type => > > :view". > > I'd like to avoid that because it would be extra noise and it > shouldn't be necessary. The generated specs work absolutely perfectly > for me as/is (I'm on OS X). There have been a couple of bugs related > to regexps and windows paths over time, but they've either been > resolved or await more feedback from users in the tracker. > > I'm thinking about other ways to be explicit about this (besides the > verbose ":behaviour_type => :view". What if we added methods like: > > describe_model > describe_view > describe_controller > describe_helper > I like these. They are explicit. > Or support the first argument being a Symbol: > > describe :model, "Thing" do > > I'm not sure I like those, but I kind of dislike :behaviour_type => > :foo as a default. > > WDYT? > > David > > > > > > Zach > > _______________________________________________ > > 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 michael.s.klishin at gmail.com Mon Aug 20 06:09:03 2007 From: michael.s.klishin at gmail.com (Michael Klishin) Date: Mon, 20 Aug 2007 14:09:03 +0400 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <57c63afe0708160732s365df56bwfbbdca70dc5bafde@mail.gmail.com> <85d99afe0708161001w371a6effsea9f7827943eaf39@mail.gmail.com> <57c63afe0708161031i426e5edeo1f19058baf2fc028@mail.gmail.com> <85d99afe0708190901o71d0b022v464638bf3a7c5ce1@mail.gmail.com> <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> Message-ID: <709de1d10708200309s6fd9aa73kf595f136cc1f5f40@mail.gmail.com> +1 for those On 19/08/07, David Chelimsky wrote: > I'm thinking about other ways to be explicit about this (besides the > verbose ":behaviour_type => :view". What if we added methods like: > > describe_model > describe_view > describe_controller > describe_helper -- MK From lists-rspec at shopwatch.org Mon Aug 20 07:52:21 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Mon, 20 Aug 2007 07:52:21 -0400 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <57c63afe0708160732s365df56bwfbbdca70dc5bafde@mail.gmail.com> <85d99afe0708161001w371a6effsea9f7827943eaf39@mail.gmail.com> <57c63afe0708161031i426e5edeo1f19058baf2fc028@mail.gmail.com> <85d99afe0708190901o71d0b022v464638bf3a7c5ce1@mail.gmail.com> <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> Message-ID: <46C98075.5090807@jay.fm> > I'd like to avoid that because it would be extra noise and it > shouldn't be necessary. The generated specs work absolutely perfectly > for me as/is (I'm on OS X). There have been a couple of bugs related > to regexps and windows paths over time, but they've either been > resolved or await more feedback from users in the tracker. > > I'm thinking about other ways to be explicit about this (besides the > verbose ":behaviour_type => :view". What if we added methods like: > > describe_model > describe_view > describe_controller > describe_helper > > Or support the first argument being a Symbol: > > describe :model, "Thing" do I'm not clear why we need any new syntax at all - isn't this just a bug related to some configurations, if it works for David but not for Zach (both on OS X)? Jay > > I'm not sure I like those, but I kind of dislike :behaviour_type => > :foo as a default. > > WDYT? > > David > > >> Zach >> _______________________________________________ >> 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 aslak.hellesoy at gmail.com Mon Aug 20 08:20:54 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 20 Aug 2007 14:20:54 +0200 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <46C98075.5090807@jay.fm> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <57c63afe0708160732s365df56bwfbbdca70dc5bafde@mail.gmail.com> <85d99afe0708161001w371a6effsea9f7827943eaf39@mail.gmail.com> <57c63afe0708161031i426e5edeo1f19058baf2fc028@mail.gmail.com> <85d99afe0708190901o71d0b022v464638bf3a7c5ce1@mail.gmail.com> <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> <46C98075.5090807@jay.fm> Message-ID: <8d961d900708200520p38970129yb1c9571b2a67685@mail.gmail.com> On 8/20/07, Jay Levitt wrote: > > I'd like to avoid that because it would be extra noise and it > > shouldn't be necessary. The generated specs work absolutely perfectly > > for me as/is (I'm on OS X). There have been a couple of bugs related > > to regexps and windows paths over time, but they've either been > > resolved or await more feedback from users in the tracker. > > > > I'm thinking about other ways to be explicit about this (besides the > > verbose ":behaviour_type => :view". What if we added methods like: > > > > describe_model > > describe_view > > describe_controller > > describe_helper > > > > Or support the first argument being a Symbol: > > > > describe :model, "Thing" do > > I'm not clear why we need any new syntax at all - isn't this just a bug > related to some configurations, if it works for David but not for Zach > (both on OS X)? > Good point. Let's figure out why it doesn't work for Zach first. Zach: What's the relative path of the spec? Did you move it after it was created? Aslak > Jay > > > > I'm not sure I like those, but I kind of dislike :behaviour_type => > > :foo as a default. > > > > WDYT? > > > > David > > > > > >> Zach > >> _______________________________________________ > >> 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 lists-rspec at shopwatch.org Mon Aug 20 08:45:38 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Mon, 20 Aug 2007 08:45:38 -0400 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <8d961d900708200520p38970129yb1c9571b2a67685@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <57c63afe0708160732s365df56bwfbbdca70dc5bafde@mail.gmail.com> <85d99afe0708161001w371a6effsea9f7827943eaf39@mail.gmail.com> <57c63afe0708161031i426e5edeo1f19058baf2fc028@mail.gmail.com> <85d99afe0708190901o71d0b022v464638bf3a7c5ce1@mail.gmail.com> <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> <46C98075.5090807@jay.fm> <8d961d900708200520p38970129yb1c9571b2a67685@mail.gmail.com> Message-ID: <46C98CF2.1060107@jay.fm> On 8/20/2007 8:20 AM, aslak hellesoy wrote: > On 8/20/07, Jay Levitt wrote: >>> I'd like to avoid that because it would be extra noise and it >>> shouldn't be necessary. The generated specs work absolutely perfectly >>> for me as/is (I'm on OS X). There have been a couple of bugs related >>> to regexps and windows paths over time, but they've either been >>> resolved or await more feedback from users in the tracker. >>> >>> I'm thinking about other ways to be explicit about this (besides the >>> verbose ":behaviour_type => :view". What if we added methods like: >>> >>> describe_model >>> describe_view >>> describe_controller >>> describe_helper >>> >>> Or support the first argument being a Symbol: >>> >>> describe :model, "Thing" do >> I'm not clear why we need any new syntax at all - isn't this just a bug >> related to some configurations, if it works for David but not for Zach >> (both on OS X)? >> > > Good point. Let's figure out why it doesn't work for Zach first. > > Zach: What's the relative path of the spec? Did you move it after it > was created? If Zach could create a screencast or precise step-by-step, I can attempt to reproduce it tonight on OS X, Windows XP, Cygwin, and/or Ubuntu 6.06. Jay From lists-rspec at shopwatch.org Mon Aug 20 09:38:27 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Mon, 20 Aug 2007 09:38:27 -0400 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <8d961d900708200520p38970129yb1c9571b2a67685@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <57c63afe0708160732s365df56bwfbbdca70dc5bafde@mail.gmail.com> <85d99afe0708161001w371a6effsea9f7827943eaf39@mail.gmail.com> <57c63afe0708161031i426e5edeo1f19058baf2fc028@mail.gmail.com> <85d99afe0708190901o71d0b022v464638bf3a7c5ce1@mail.gmail.com> <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> <46C98075.5090807@jay.fm> <8d961d900708200520p38970129yb1c9571b2a67685@mail.gmail.com> Message-ID: <46C99953.50800@jay.fm> aslak hellesoy wrote: > On 8/20/07, Jay Levitt wrote: >>> I'd like to avoid that because it would be extra noise and it >>> shouldn't be necessary. The generated specs work absolutely perfectly >>> for me as/is (I'm on OS X). There have been a couple of bugs related >>> to regexps and windows paths over time, but they've either been >>> resolved or await more feedback from users in the tracker. >>> >>> I'm thinking about other ways to be explicit about this (besides the >>> verbose ":behaviour_type => :view". What if we added methods like: >>> >>> describe_model >>> describe_view >>> describe_controller >>> describe_helper >>> >>> Or support the first argument being a Symbol: >>> >>> describe :model, "Thing" do >> I'm not clear why we need any new syntax at all - isn't this just a bug >> related to some configurations, if it works for David but not for Zach >> (both on OS X)? >> > > Good point. Let's figure out why it doesn't work for Zach first. > > Zach: What's the relative path of the spec? Did you move it after it > was created? If Zach could create a screencast or precise step-by-step, I can attempt to reproduce it tonight on OS X, Windows XP, Cygwin, and/or Ubuntu 6.06. Jay From dchelimsky at gmail.com Mon Aug 20 09:47:18 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 20 Aug 2007 08:47:18 -0500 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <46C99953.50800@jay.fm> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <57c63afe0708160732s365df56bwfbbdca70dc5bafde@mail.gmail.com> <85d99afe0708161001w371a6effsea9f7827943eaf39@mail.gmail.com> <57c63afe0708161031i426e5edeo1f19058baf2fc028@mail.gmail.com> <85d99afe0708190901o71d0b022v464638bf3a7c5ce1@mail.gmail.com> <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> <46C98075.5090807@jay.fm> <8d961d900708200520p38970129yb1c9571b2a67685@mail.gmail.com> <46C99953.50800@jay.fm> Message-ID: <57c63afe0708200647i7d64379j1bd21630b2905d21@mail.gmail.com> On 8/20/07, Jay Levitt wrote: > aslak hellesoy wrote: > > On 8/20/07, Jay Levitt wrote: > >>> I'd like to avoid that because it would be extra noise and it > >>> shouldn't be necessary. The generated specs work absolutely perfectly > >>> for me as/is (I'm on OS X). There have been a couple of bugs related > >>> to regexps and windows paths over time, but they've either been > >>> resolved or await more feedback from users in the tracker. > >>> > >>> I'm thinking about other ways to be explicit about this (besides the > >>> verbose ":behaviour_type => :view". What if we added methods like: > >>> > >>> describe_model > >>> describe_view > >>> describe_controller > >>> describe_helper > >>> > >>> Or support the first argument being a Symbol: > >>> > >>> describe :model, "Thing" do > >> I'm not clear why we need any new syntax at all - isn't this just a bug > >> related to some configurations, if it works for David but not for Zach > >> (both on OS X)? > >> > > > > Good point. Let's figure out why it doesn't work for Zach first. > > > > Zach: What's the relative path of the spec? Did you move it after it > > was created? > > If Zach could create a screencast or precise step-by-step, I can attempt > to reproduce it tonight on OS X, Windows XP, Cygwin, and/or Ubuntu 6.06. Thanks for offering to do this Jay - that's great. > > Jay > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cody at skidmore.us Mon Aug 20 11:04:49 2007 From: cody at skidmore.us (Cody P. Skidmore) Date: Mon, 20 Aug 2007 08:04:49 -0700 (PDT) Subject: [rspec-users] RSpec --format --html:/path/to/file.html Message-ID: <2635.216.167.174.73.1187622289.squirrel@webmail.skidmore.us> Scott Taylor wrote: > Actually you can combine then in any way you choose. This would work > as well: > > --format html:/foo/bar > >> --format >> html:/path/to/my.html >> >> Then on the command line: >> >> spec spec -O path/to/spec.opts I was hesitant to bring this up again, but I couldn't run it as you described. I'm running on Windows XP Pro instead of Linux or OSX, BTW. When I shell out and execute it like this for example: spec spec -O spec\spec.opts OR rake spec It crashes and dumps a callstack out. However, if it is run like this: spec spec --format html:c:\temp\testing.html the tests run just fine outputting the results as expected. If you'd like, I can run it using --trace and post the callstack for you to look at along with my spec.opts file. It seems straight-forward to use RSpec as described. I haven't had much success running specs using spec.opts though. The same error occurs using the Rake task or passing the options. With Regards, Cody From aslak.hellesoy at gmail.com Mon Aug 20 12:25:32 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 20 Aug 2007 18:25:32 +0200 Subject: [rspec-users] RSpec --format --html:/path/to/file.html In-Reply-To: <2635.216.167.174.73.1187622289.squirrel@webmail.skidmore.us> References: <2635.216.167.174.73.1187622289.squirrel@webmail.skidmore.us> Message-ID: <8d961d900708200925n2c527caah7ff0eaf34024e6cc@mail.gmail.com> On 8/20/07, Cody P. Skidmore wrote: > Scott Taylor wrote: > > Actually you can combine then in any way you choose. This would work > > as well: > > > > --format html:/foo/bar > > > >> --format > >> html:/path/to/my.html > >> > >> Then on the command line: > >> > >> spec spec -O path/to/spec.opts > > > I was hesitant to bring this up again, but I couldn't run it as you > described. I'm running on Windows XP Pro instead of Linux or OSX, BTW. > > When I shell out and execute it like this for example: > > spec spec -O spec\spec.opts > > OR > > rake spec > > It crashes and dumps a callstack out. Can we see that call stack? > However, if it is run like this: > > spec spec --format html:c:\temp\testing.html > > the tests run just fine outputting the results as expected. If you'd > like, I can run it using --trace and post the callstack for you to look at Please do. Aslak > along with my spec.opts file. It seems straight-forward to use RSpec as > described. I haven't had much success running specs using spec.opts > though. The same error occurs using the Rake task or passing the options. > > With Regards, > > Cody > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From omen.king at gmail.com Mon Aug 20 13:17:45 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Mon, 20 Aug 2007 13:17:45 -0400 Subject: [rspec-users] [rspec] looking for a simple refresher In-Reply-To: References: <57c63afe0708171217w1414f170ra4de1784e688b40b@mail.gmail.com> Message-ID: Still having trouble ='( def create @user = User.find(params[:user_id]) @ticket = @user.tickets.build(params[:ticket]) if @ticket.save redirect_to tickets_path else render new_usr_ticket_path(params[:user_id]) end end describe TicketsController, "handling POST /tickets" do before do @ticket = mock_model(Ticket, :save => true) @user = mock_model(User) @user.stub!(:tickets).and_return(@user_tickets_association) @params = {} end def do_post post :create, :ticket => @params, :user_id => "user_id" end it "should find the user" do User.should_receive(:find).with("user_id").and_return(@user) do_post end 8) Spec::Mocks::MockExpectationError in 'TicketsController handling POST /tickets should find the user' Mock 'Class' expected :find with ("user_id") once, but received it 0 times ./spec/controllers/tickets_controller_spec.rb:19: script/spec:4: That really looks like it should pass. On 8/17/07, Rupert Voelcker wrote: > > > thats pretty much what I thought, I'll give it a push around and e- > > mail back the results > > cool - good luck ...I'm off to bed as it's 1am here in the UK but I'm > sure one of the useful chaps round here 'll help you out with any probs > > btw, I just noticed I've put @ticket_params = {} in the before > declaration and it needs to be @params = {} > > Cheers > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070820/7d32e6cf/attachment.html From omen.king at gmail.com Mon Aug 20 13:42:37 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Mon, 20 Aug 2007 13:42:37 -0400 Subject: [rspec-users] [rspec] looking for a simple refresher In-Reply-To: References: <57c63afe0708171217w1414f170ra4de1784e688b40b@mail.gmail.com> Message-ID: I solved my problem. def create @ticket = Ticket.new(params[:ticket]) @ticket.user = current_user if @ticket.save redirect_to tickets_path else render new_ticket_path(params[:user_id]) end end Like my mom would nag: "If you rspec'd from the start you wouldn't have to clean up this mess" On 8/20/07, Andrew WC Brown wrote: > > Still having trouble ='( > > > def create > @user = User.find(params[:user_id]) > @ticket = @user.tickets.build(params[:ticket]) > if @ticket.save > redirect_to tickets_path > else > render new_usr_ticket_path(params[:user_id]) > end > end > > describe TicketsController, "handling POST /tickets" do > before do > @ticket = mock_model(Ticket, :save => true) > @user = mock_model(User) > @user.stub!(:tickets).and_return(@user_tickets_association) > @params = {} > end > def do_post > post :create, :ticket => @params, :user_id => "user_id" > end > it "should find the user" do > User.should_receive(:find).with("user_id").and_return(@user) > do_post > end > > 8) > Spec::Mocks::MockExpectationError in 'TicketsController handling POST > /tickets should find the user' > Mock 'Class' expected :find with ("user_id") once, but received it 0 times > ./spec/controllers/tickets_controller_spec.rb:19: > script/spec:4: > > > That really looks like it should pass. > > > On 8/17/07, Rupert Voelcker wrote: > > > > > thats pretty much what I thought, I'll give it a push around and e- > > > mail back the results > > > > cool - good luck ...I'm off to bed as it's 1am here in the UK but I'm > > sure one of the useful chaps round here 'll help you out with any probs > > > > btw, I just noticed I've put @ticket_params = {} in the before > > declaration and it needs to be @params = {} > > > > Cheers > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070820/b6c699e4/attachment.html From mailing_lists at railsnewbie.com Mon Aug 20 01:17:14 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 20 Aug 2007 01:17:14 -0400 Subject: [rspec-users] RSpec --format --html:/path/to/file.html In-Reply-To: <57c63afe0708172259s46844894l1a3c5d6beccd9974@mail.gmail.com> References: <3756.216.167.174.73.1187359774.squirrel@webmail.skidmore.us> <57c63afe0708172259s46844894l1a3c5d6beccd9974@mail.gmail.com> Message-ID: On Aug 18, 2007, at 1:59 AM, David Chelimsky wrote: > On 8/17/07, Cody P. Skidmore wrote: >> Greetings everyone. I'm learning RSpec and am pretty fresh to >> Ruby/Rails, >> but am so excited I can't help jumping in. I'm running before I >> can walk >> here. :-) >> >> Yesterday I tried outputting test results to HTML instead of >> colorized >> plain text. It looked like there were some entries in the change >> log for >> the 1.0.5 release allowing RSpec to do what I wanted. >> >> I tried adding a setting to spec.opts but it didn't work to say >> the least. >> Here's the change log entry: >> >> * The --out option is gone. Use --format html:path/to/my.html >> instead (or >> similar). >> >> 1. Does this do what I think it should? > > > In spec.opts, each line represents one command line arg, so you'd have > to do this (on two separate lines): > Actually you can combine then in any way you choose. This would work as well: --format html:/foo/bar > --format > html:/path/to/my.html > > Then on the command line: > > spec spec -O path/to/spec.opts > >> 2. where can I find documentation on using spec.opts? The >> command line >> help doesn't mention a "--format" option. > > Look at http://rspec.rubyforge.org/documentation/tools/spec.html. If > you scroll down you'll see the output from the spec command. It > definitely mentions the --format option. > > >> It looks like CI::Reporter [could] output XML format but can it be >> used >> independently? >> >> I'm mining the documentation for related information but didn't >> find it so >> far. If you really wanted to dump to XML, I'm sure you could build your own formatter. Check out the different defaults ones which come with rspec, under trunk/rspec/lib/spec/runner/formatter/ Scott From zach.dennis at gmail.com Mon Aug 20 19:25:04 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 20 Aug 2007 19:25:04 -0400 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <57c63afe0708200647i7d64379j1bd21630b2905d21@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <57c63afe0708160732s365df56bwfbbdca70dc5bafde@mail.gmail.com> <85d99afe0708161001w371a6effsea9f7827943eaf39@mail.gmail.com> <57c63afe0708161031i426e5edeo1f19058baf2fc028@mail.gmail.com> <85d99afe0708190901o71d0b022v464638bf3a7c5ce1@mail.gmail.com> <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> <46C98075.5090807@jay.fm> <8d961d900708200520p38970129yb1c9571b2a67685@mail.gmail.com> <46C99953.50800@jay.fm> <57c63afe0708200647i7d64379j1bd21630b2905d21@mail.gmail.com> Message-ID: <85d99afe0708201625o404109c3v87f85e08ef6dd22c@mail.gmail.com> Here is a link to the .mov: http://www.continuousthinking.com/movies/RSpec_mockModelError.mov In doing this I realized something. I only get the error when I try to run an individual spec within the spec/views// directory. Thanks for the suggestion Jay, Zach On 8/20/07, David Chelimsky wrote: > On 8/20/07, Jay Levitt wrote: > > aslak hellesoy wrote: > > > On 8/20/07, Jay Levitt wrote: > > >>> I'd like to avoid that because it would be extra noise and it > > >>> shouldn't be necessary. The generated specs work absolutely perfectly > > >>> for me as/is (I'm on OS X). There have been a couple of bugs related > > >>> to regexps and windows paths over time, but they've either been > > >>> resolved or await more feedback from users in the tracker. > > >>> > > >>> I'm thinking about other ways to be explicit about this (besides the > > >>> verbose ":behaviour_type => :view". What if we added methods like: > > >>> > > >>> describe_model > > >>> describe_view > > >>> describe_controller > > >>> describe_helper > > >>> > > >>> Or support the first argument being a Symbol: > > >>> > > >>> describe :model, "Thing" do > > >> I'm not clear why we need any new syntax at all - isn't this just a bug > > >> related to some configurations, if it works for David but not for Zach > > >> (both on OS X)? > > >> > > > > > > Good point. Let's figure out why it doesn't work for Zach first. > > > > > > Zach: What's the relative path of the spec? Did you move it after it > > > was created? > > > > If Zach could create a screencast or precise step-by-step, I can attempt > > to reproduce it tonight on OS X, Windows XP, Cygwin, and/or Ubuntu 6.06. > > Thanks for offering to do this Jay - that's great. > > > > > Jay > > > > > > _______________________________________________ > > 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 aslak.hellesoy at gmail.com Mon Aug 20 20:19:46 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 21 Aug 2007 02:19:46 +0200 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <85d99afe0708201625o404109c3v87f85e08ef6dd22c@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <85d99afe0708161001w371a6effsea9f7827943eaf39@mail.gmail.com> <57c63afe0708161031i426e5edeo1f19058baf2fc028@mail.gmail.com> <85d99afe0708190901o71d0b022v464638bf3a7c5ce1@mail.gmail.com> <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> <46C98075.5090807@jay.fm> <8d961d900708200520p38970129yb1c9571b2a67685@mail.gmail.com> <46C99953.50800@jay.fm> <57c63afe0708200647i7d64379j1bd21630b2905d21@mail.gmail.com> <85d99afe0708201625o404109c3v87f85e08ef6dd22c@mail.gmail.com> Message-ID: <8d961d900708201719l5bf4c926m4b6588ccedb60315@mail.gmail.com> Several problems here: First, rspec_scaffold must be given a *singularised* name, in your case 'product'. (This is Rails being finicky, not RSpec). Second, after running rspec_scaffold you must run rake db:migrate Third, before you can run specs with ruby or spec, you must create the test database. This can be done with rake spec or rake db:test:prepare HTH, Aslak On 8/21/07, Zach Dennis wrote: > Here is a link to the .mov: > > http://www.continuousthinking.com/movies/RSpec_mockModelError.mov > > In doing this I realized something. I only get the error when I try to > run an individual spec within the spec/views// directory. > Thanks for the suggestion Jay, > > Zach > > > > On 8/20/07, David Chelimsky wrote: > > On 8/20/07, Jay Levitt wrote: > > > aslak hellesoy wrote: > > > > On 8/20/07, Jay Levitt wrote: > > > >>> I'd like to avoid that because it would be extra noise and it > > > >>> shouldn't be necessary. The generated specs work absolutely perfectly > > > >>> for me as/is (I'm on OS X). There have been a couple of bugs related > > > >>> to regexps and windows paths over time, but they've either been > > > >>> resolved or await more feedback from users in the tracker. > > > >>> > > > >>> I'm thinking about other ways to be explicit about this (besides the > > > >>> verbose ":behaviour_type => :view". What if we added methods like: > > > >>> > > > >>> describe_model > > > >>> describe_view > > > >>> describe_controller > > > >>> describe_helper > > > >>> > > > >>> Or support the first argument being a Symbol: > > > >>> > > > >>> describe :model, "Thing" do > > > >> I'm not clear why we need any new syntax at all - isn't this just a bug > > > >> related to some configurations, if it works for David but not for Zach > > > >> (both on OS X)? > > > >> > > > > > > > > Good point. Let's figure out why it doesn't work for Zach first. > > > > > > > > Zach: What's the relative path of the spec? Did you move it after it > > > > was created? > > > > > > If Zach could create a screencast or precise step-by-step, I can attempt > > > to reproduce it tonight on OS X, Windows XP, Cygwin, and/or Ubuntu 6.06. > > > > Thanks for offering to do this Jay - that's great. > > > > > > > > Jay > > > > > > > > > _______________________________________________ > > > 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 zach.dennis at gmail.com Mon Aug 20 21:55:58 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 20 Aug 2007 21:55:58 -0400 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <8d961d900708201719l5bf4c926m4b6588ccedb60315@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <57c63afe0708161031i426e5edeo1f19058baf2fc028@mail.gmail.com> <85d99afe0708190901o71d0b022v464638bf3a7c5ce1@mail.gmail.com> <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> <46C98075.5090807@jay.fm> <8d961d900708200520p38970129yb1c9571b2a67685@mail.gmail.com> <46C99953.50800@jay.fm> <57c63afe0708200647i7d64379j1bd21630b2905d21@mail.gmail.com> <85d99afe0708201625o404109c3v87f85e08ef6dd22c@mail.gmail.com> <8d961d900708201719l5bf4c926m4b6588ccedb60315@mail.gmail.com> Message-ID: <85d99afe0708201855n2773ebb4t47924437ac31c15@mail.gmail.com> On 8/20/07, aslak hellesoy wrote: > Several problems here: > > First, rspec_scaffold must be given a *singularised* name, in your > case 'product'. (This is Rails being finicky, not RSpec). ok > Second, after running rspec_scaffold you must run rake db:migrate This I didn't do, but doing this makes no difference on the mock model error. This does fix the issue if I run the spec from RAILS_ROOT, but not if I run the spec from within the spec/views/products directory. > Third, before you can run specs with ruby or spec, you must create the > test database. This can be done with rake spec or rake db:test:prepare The database was already in existence, so I left that part omitted in the video If I run specs from RAILS_ROOT then everything works, but not if I'm not in RAILS_ROOT. This is less of an issue I originally thought, but the directory thing is a minor irritation, although I can make sure to run specs from the RAILS_ROOT. thx, Zach From dchelimsky at gmail.com Mon Aug 20 22:01:14 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 20 Aug 2007 21:01:14 -0500 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <85d99afe0708201855n2773ebb4t47924437ac31c15@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <85d99afe0708190901o71d0b022v464638bf3a7c5ce1@mail.gmail.com> <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> <46C98075.5090807@jay.fm> <8d961d900708200520p38970129yb1c9571b2a67685@mail.gmail.com> <46C99953.50800@jay.fm> <57c63afe0708200647i7d64379j1bd21630b2905d21@mail.gmail.com> <85d99afe0708201625o404109c3v87f85e08ef6dd22c@mail.gmail.com> <8d961d900708201719l5bf4c926m4b6588ccedb60315@mail.gmail.com> <85d99afe0708201855n2773ebb4t47924437ac31c15@mail.gmail.com> Message-ID: <57c63afe0708201901v7783b514wa2dbca82c2a841d8@mail.gmail.com> On 8/20/07, Zach Dennis wrote: > On 8/20/07, aslak hellesoy wrote: > > Several problems here: > > > > First, rspec_scaffold must be given a *singularised* name, in your > > case 'product'. (This is Rails being finicky, not RSpec). > > ok > > > Second, after running rspec_scaffold you must run rake db:migrate > > This I didn't do, but doing this makes no difference on the mock model > error. This does fix the issue if I run the spec from RAILS_ROOT, but > not if I run the spec from within the spec/views/products directory. Ah - now THAT makes sense. This won't work on any system at all. RSpec looks for /spec/views/ in the path to know that it's a view spec. If you're in the view spec directory, it doesn't get the information it needs. Make sense? > > Third, before you can run specs with ruby or spec, you must create the > > test database. This can be done with rake spec or rake db:test:prepare > > The database was already in existence, so I left that part omitted in the video > > If I run specs from RAILS_ROOT then everything works, but not if I'm > not in RAILS_ROOT. This is less of an issue I originally thought, but > the directory thing is a minor irritation, although I can make sure to > run specs from the RAILS_ROOT. We'd have to change how rspec figures out what behaviour_type to use to reduce the irritation. Any suggestions? > > thx, > > Zach > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From omen.king at gmail.com Tue Aug 21 01:32:52 2007 From: omen.king at gmail.com (Andrew WC Brown) Date: Tue, 21 Aug 2007 01:32:52 -0400 Subject: [rspec-users] using restful_authentication current_user inside controller specs Message-ID: I'm using restful_authentication in my app and I have the before filters in my application rhtml: before_filter :login_required around_filter :set_timezone around_filter :catch_errors Currently I have them commented out while rspec'in but I'll need to add them in my specs. def create @ticket = Ticket.new(params[:ticket]) @ticket.user = current_user if @ticket.save redirect_to tickets_path else render new_ticket_path(params[:user_id]) end end describe TicketsController, "handling POST /tickets" do before do @ticket = mock_model(Ticket, :save => true) @current_user = mock_model(User) @params = {} end def do_post post :create, :ticket => @params end it "should create a new ticket and assign current user as ticket's user" do @ticket.should_receive(:new).with(@params).and_return(@ticket) assigns[:ticket].user.should equal(@current_user) do_post end end 1) NoMethodError in 'TicketsController handling POST /tickets should create a new ticket and assign current user as ticket's user' You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.include? /Volumes/EXTERNAL/web/yellowticket/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/assigns_hash_proxy.rb:10:in `[]' ./spec/controllers/tickets_controller_spec.rb:14: My guess is that I'm not allow to do this: assigns[:ticket].user How do I apple the assignment with current_user? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070821/e6e65469/attachment.html From aslak.hellesoy at gmail.com Tue Aug 21 03:01:20 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 21 Aug 2007 09:01:20 +0200 Subject: [rspec-users] using restful_authentication current_user inside controller specs In-Reply-To: References: Message-ID: <8d961d900708210001g36ff8e56n1157c49d0c6e1942@mail.gmail.com> @ticket.should_receive(:new).with(@params).and_return(@ticket) is like saying: @ticket = @ticket.new(params) And that, of course, doesn't make much sense. I'll give you a chance to find the solution yourself ;-) Aslak On 8/21/07, Andrew WC Brown wrote: > I'm using restful_authentication in my app and I have the before filters in > my application rhtml: > > before_filter :login_required > around_filter :set_timezone > around_filter :catch_errors > > Currently I have them commented out while rspec'in but I'll need to add them > in my specs. > > > def create > @ticket = Ticket.new(params[:ticket]) > @ticket.user = current_user > if @ticket.save > redirect_to tickets_path > else > render new_ticket_path(params[:user_id]) > end > end > > describe TicketsController, "handling POST /tickets" do > before do > @ticket = mock_model(Ticket, :save => true) > @current_user = mock_model(User) > @params = {} > end > def do_post > post :create, :ticket => @params > end > it "should create a new ticket and assign current user as ticket's user" > do > > @ticket.should_receive(:new).with(@params).and_return(@ticket) > assigns[:ticket].user.should equal(@current_user) > do_post > end > end > > 1) > NoMethodError in 'TicketsController handling POST /tickets should create a > new ticket and assign current user as ticket's user' > You have a nil object when you didn't expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.include? > /Volumes/EXTERNAL/web/yellowticket/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/assigns_hash_proxy.rb:10:in > `[]' > ./spec/controllers/tickets_controller_spec.rb:14: > > > My guess is that I'm not allow to do this: assigns[:ticket].user > How do I apple the assignment with current_user? > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From court3nay at gmail.com Tue Aug 21 03:10:48 2007 From: court3nay at gmail.com (court3nay) Date: Tue, 21 Aug 2007 00:10:48 -0700 Subject: [rspec-users] using restful_authentication current_user inside controller specs In-Reply-To: References: Message-ID: <440DD9FE-53A8-4ACB-8E65-420329B7DA18@gmail.com> controller.stub!:(current_user).and_return(@user) ------- Courtenay On Aug 20, 2007, at 10:32 PM, "Andrew WC Brown" wrote: > I'm using restful_authentication in my app and I have the before > filters in my application rhtml: > > before_filter :login_required > around_filter :set_timezone > around_filter :catch_errors > > Currently I have them commented out while rspec'in but I'll need to > add them in my specs. > > > def create > @ticket = Ticket.new(params[:ticket]) > @ticket.user = current_user > if @ticket.save > redirect_to tickets_path > else > render new_ticket_path(params[:user_id]) > end > end > > describe TicketsController, "handling POST /tickets" do > before do > @ticket = mock_model(Ticket, :save => true) > @current_user = mock_model(User) > @params = {} > end > def do_post > post :create, :ticket => @params > end > it "should create a new ticket and assign current user as > ticket's user" do > @ticket.should_receive(:new).with(@params).and_return(@ticket) > assigns[:ticket].user.should equal(@current_user) > do_post > end > end > > 1) > NoMethodError in 'TicketsController handling POST /tickets should > create a new ticket and assign current user as ticket's user' > You have a nil object when you didn't expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.include? > /Volumes/EXTERNAL/web/yellowticket/vendor/plugins/rspec_on_rails/lib/ > spec/rails/dsl/assigns_hash_proxy.rb:10:in `[]' > ./spec/controllers/tickets_controller_spec.rb:14: > > > My guess is that I'm not allow to do this: assigns[:ticket].user > How do I apple the assignment with current_user? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From work at ashleymoran.me.uk Tue Aug 21 05:07:28 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 21 Aug 2007 10:07:28 +0100 Subject: [rspec-users] Render template not matching absolute path Message-ID: Hi I have a simple controller method like this: class StylesheetsController < ApplicationController layout nil session :off def gap site = Site.find_by_hostname(request.host) @colours = site.colours respond_to do |accepts| accepts.css { render :file => "#{RAILS_ROOT}/app/views/ stylesheets/gap.rcss" } end end end And I want to test that it renders the gap.rcss file, but my spec, it "should render the gap.rcss template" do do_get response.should render_template("gap.rcss") end fails with this error: Expected "gap.rcss", got "/Users/ashleymoran/Documents/Development/ YourMoney/trunk/src/config/../app/views/stylesheets/gap.rcss" I don't remember this failing in 1.0.5, but it's been a while since I worked on this project so might be just be my bad memory. Am I doing something wrong or can you not spec "render :file" with render_template? Thanks Ashley From dchelimsky at gmail.com Tue Aug 21 09:26:39 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 21 Aug 2007 08:26:39 -0500 Subject: [rspec-users] Render template not matching absolute path In-Reply-To: References: Message-ID: <57c63afe0708210626g664b69e4kbb6072e9304aa6e3@mail.gmail.com> On 8/21/07, Ashley Moran wrote: > Hi > > I have a simple controller method like this: > > class StylesheetsController < ApplicationController > layout nil > session :off > > def gap > site = Site.find_by_hostname(request.host) > @colours = site.colours > respond_to do |accepts| > accepts.css { render :file => "#{RAILS_ROOT}/app/views/ > stylesheets/gap.rcss" } > end > end > end > > And I want to test that it renders the gap.rcss file, but my spec, > > it "should render the gap.rcss template" do > do_get > response.should render_template("gap.rcss") > end > > fails with this error: > > Expected "gap.rcss", got "/Users/ashleymoran/Documents/Development/ > YourMoney/trunk/src/config/../app/views/stylesheets/gap.rcss" > > I don't remember this failing in 1.0.5, but it's been a while since I > worked on this project so might be just be my bad memory. Am I doing > something wrong or can you not spec "render :file" with render_template? This changed in 1.0.0, but not since. Take a look at render_template.rb. render_template supports either a file name, in which case it prepends the controller-based path (i.e. if the controller is 'foo' and you say 'bar', it will match 'foo/bar'), or a path. In either case it matches against response.rendered_file - it does not do any real path resolution - it's just matching strings. HTH, David > > Thanks > Ashley > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From edward.og at gmail.com Tue Aug 21 12:54:24 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Tue, 21 Aug 2007 12:54:24 -0400 Subject: [rspec-users] describing a mock_model as being an instance In-Reply-To: <4b430c8f0708192200j514acc5x78e52bbccb7d19a8@mail.gmail.com> References: <46C8A91F.6070208@gmail.com> <57c63afe0708191700s44505f80g8529343dc3ef10bb@mail.gmail.com> <46C8ECF2.1010502@gmail.com> <4b430c8f0708192200j514acc5x78e52bbccb7d19a8@mail.gmail.com> Message-ID: <46CB18C0.1030503@gmail.com> Courtenay wrote: > Is there a reason it needs to be more complicated than this? > > class Foo > end > > Foo.is_a?(Class) > => true > > Foo.new.is_a?(Class) > => false You can do that? Whoaaaaa... That totally makes sense. I also found out about Object#instance_of? yesterday. Thanks for the tip! Edward From flyeminent at hotmail.com Tue Aug 21 23:44:40 2007 From: flyeminent at hotmail.com (Shaker) Date: Tue, 21 Aug 2007 20:44:40 -0700 (PDT) Subject: [rspec-users] Can Rspec do module spec? What if module uses test data? Message-ID: <12267615.post@talk.nabble.com> Dear fellows: I am currently working on writing specs on some ruby modules(e.g. myModule). At first I try to use script/generate to generate rspec_module, but it failed. :-( Later I manually created a file (e.g. named myModule_spec.rb) and put the 'require ....spec_helper.rb' as the first line of code followed by 'describe' block. Luckily, it seemed to be working. But it was not likely to be a logical way to generate module specs. Question 1:Is there any better way of creating module spec??:confused: Anyway, I started to write method specs in these manually created module specs, and I found another problem. Module specs do not support 'fixtures'. This means that if you test some methods which modify test data in your module specs, that data won't be restored after you finish running each spec. In other words, all the modules specs actually share a copy of test data. This will cause some module specs to fail if other modules do modified the shared data beforehand. Question 2:What should I do to resolve this problem, making module specs access test data independently? :confused: -- View this message in context: http://www.nabble.com/Can-Rspec-do-module-spec--What-if-module-uses-test-data--tf4309226.html#a12267615 Sent from the rspec-users mailing list archive at Nabble.com. From aslak.hellesoy at gmail.com Wed Aug 22 03:54:07 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 22 Aug 2007 09:54:07 +0200 Subject: [rspec-users] Can Rspec do module spec? What if module uses test data? In-Reply-To: <12267615.post@talk.nabble.com> References: <12267615.post@talk.nabble.com> Message-ID: <8d961d900708220054t1315c331td3c4a9997fc3f29b@mail.gmail.com> Here is an example from RSpec's own specs: describe Enumerable do def each(&block) ["4", "2", "1"].each(&block) end it "should be included in examples because it is a module" do map{|e| e.to_i}.should == [4,2,1] end end If you pass the module to describe it will automatically be included in each of your it blocks, so you're right at home! HTH, Aslak On 8/22/07, Shaker wrote: > > Dear fellows: > I am currently working on writing specs on some ruby modules(e.g. > myModule). At first I try to use script/generate to generate rspec_module, > but it failed. :-( > Later I manually created a file (e.g. named myModule_spec.rb) and put > the 'require ....spec_helper.rb' as the first line of code followed by > 'describe' block. Luckily, it seemed to be working. But it was not likely to > be a logical way to generate module specs. > Question 1:Is there any better way of creating module spec??:confused: > Anyway, I started to write method specs in these manually created module > specs, and I found another problem. Module specs do not support 'fixtures'. > This means that if you test some methods which modify test data in your > module specs, that data won't be restored after you finish running each > spec. In other words, all the modules specs actually share a copy of test > data. This will cause some module specs to fail if other modules do modified > the shared data beforehand. > Question 2:What should I do to resolve this problem, making module specs > access test data independently? :confused: > -- > View this message in context: http://www.nabble.com/Can-Rspec-do-module-spec--What-if-module-uses-test-data--tf4309226.html#a12267615 > 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 mlins at webinforem.com Wed Aug 22 12:23:48 2007 From: mlins at webinforem.com (Matt Lins) Date: Wed, 22 Aug 2007 11:23:48 -0500 Subject: [rspec-users] How to spec an attachment_fu model Message-ID: <46CC6314.20908@webinforem.com> First off, I'm not trying to spec attachment_fu, I know it's been tested. But, I added some code to that model that I do need to test. Basically, I need to somehow fulfill the "uploaded_data" property so I can actually run my tests(otherwise they fail because of validations). The "uploaded_data" field is what would grab the multipart data from form. Here it is: # This method handles the uploaded file object. If you set the field name to uploaded_data, you don't need # any special code in your controller. # # <% form_for :attachment, :html => { :multipart => true } do |f| -%> #

<%= f.file_field :uploaded_data %>

#

<%= submit_tag :Save %> # <% end -%> # # @attachment = Attachment.create! params[:attachment] # # TODO: Allow it to work with Merb tempfiles too. def uploaded_data=(file_data) return nil if file_data.nil? || file_data.size == 0 self.content_type = file_data.content_type self.filename = file_data.original_filename if respond_to?(:filename) if file_data.is_a?(StringIO) file_data.rewind self.temp_data = file_data.read else self.temp_path = file_data.path end end While I was digging I found out that "file_data" is a ruby Tempfile object. So, I tried to create a dummy file and pass it, but it failed. I found out in the CGI library, it actually extends the Tempfile object and adds some methods/properties. It started to get messy, so I thought I'd ask for advice. How can I create a valid attachment_fu model spec(so I can start tweaking it to test my other validations)? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070822/c286d77d/attachment.html From aslak.hellesoy at gmail.com Wed Aug 22 12:41:15 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 22 Aug 2007 18:41:15 +0200 Subject: [rspec-users] How to spec an attachment_fu model In-Reply-To: <46CC6314.20908@webinforem.com> References: <46CC6314.20908@webinforem.com> Message-ID: <8d961d900708220941ice5f7a5k4de1bb01a0f2ee1f@mail.gmail.com> On 8/22/07, Matt Lins wrote: > > First off, I'm not trying to spec attachment_fu, I know it's been tested. > > But, I added some code to that model that I do need to test. Basically, I > need to somehow fulfill the "uploaded_data" property so I can actually run > my tests(otherwise they fail because of validations). The "uploaded_data" > field is what would grab the multipart data from form. Here it is: > > # This method handles the uploaded file object. If you set the field > name to uploaded_data, you don't need > # any special code in your controller. > # > # <% form_for :attachment, :html => { :multipart => true } do |f| > -%> > #

<%= f.file_field :uploaded_data %>

> #

<%= submit_tag :Save %> > # <% end -%> > # > # @attachment = Attachment.create! params[:attachment] > # > # TODO: Allow it to work with Merb tempfiles too. > def uploaded_data=(file_data) > return nil if file_data.nil? || file_data.size == 0 > self.content_type = file_data.content_type > self.filename = file_data.original_filename if > respond_to?(:filename) > if file_data.is_a?(StringIO) > file_data.rewind > self.temp_data = file_data.read > else > self.temp_path = file_data.path > end > end > I'm not familiar with attachment_fu - is this code from attachment_fu that you have modified? Or is it your code entirely? Attachment_fu's entirely? Where does this code come from? Aslak > While I was digging I found out that "file_data" is a ruby Tempfile object. > So, I tried to create a dummy file and pass it, but it failed. I found out > in the CGI library, it actually extends the Tempfile object and adds some > methods/properties. It started to get messy, so I thought I'd ask for > advice. > > How can I create a valid attachment_fu model spec(so I can start tweaking > it to test my other validations)? > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mlins at webinforem.com Wed Aug 22 12:46:02 2007 From: mlins at webinforem.com (Matt Lins) Date: Wed, 22 Aug 2007 11:46:02 -0500 Subject: [rspec-users] How to spec an attachment_fu model In-Reply-To: <8d961d900708220941ice5f7a5k4de1bb01a0f2ee1f@mail.gmail.com> References: <46CC6314.20908@webinforem.com> <8d961d900708220941ice5f7a5k4de1bb01a0f2ee1f@mail.gmail.com> Message-ID: <46CC684A.7030404@webinforem.com> Sorry, attachment_fu is a plugin for handling binary data. It handles storing the file in the file system and storing some helpful data in the database about the file. The previous code is from the attachment_fu plugin(no, I didn't modify it). This property needs to be satisfied in order for the model to validate. So I need to get my model to validate in the spec so I can actually test other parts of my model. Here is my model: class Picture < ActiveRecord::Base has_and_belongs_to_many :products has_attachment :content_type => 'image/jpeg', :storage => :file_system, :max_size => 3.megabytes, :resize_to => '400x400>', :thumbnails => {:medium => '200x200>', :small => '100x100>'}, :path_prefix => 'images/products' validates_as_attachment validates_uniqueness_of :filename validates_presence_of :filename def before_update self.thumbnails.each do |t| t.filename= thumbnail_name_for(t.thumbnail) t.save end end def full_filename(thumbnail = nil) file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s File.join(RAILS_ROOT, 'public/external', file_system_path, thumbnail_name_for(thumbnail) + '.jpg') end def public_image self.public_filename end end aslak hellesoy wrote: > On 8/22/07, Matt Lins wrote: > >> First off, I'm not trying to spec attachment_fu, I know it's been tested. >> >> But, I added some code to that model that I do need to test. Basically, I >> need to somehow fulfill the "uploaded_data" property so I can actually run >> my tests(otherwise they fail because of validations). The "uploaded_data" >> field is what would grab the multipart data from form. Here it is: >> >> # This method handles the uploaded file object. If you set the field >> name to uploaded_data, you don't need >> # any special code in your controller. >> # >> # <% form_for :attachment, :html => { :multipart => true } do |f| >> -%> >> #

<%= f.file_field :uploaded_data %>

>> #

<%= submit_tag :Save %> >> # <% end -%> >> # >> # @attachment = Attachment.create! params[:attachment] >> # >> # TODO: Allow it to work with Merb tempfiles too. >> def uploaded_data=(file_data) >> return nil if file_data.nil? || file_data.size == 0 >> self.content_type = file_data.content_type >> self.filename = file_data.original_filename if >> respond_to?(:filename) >> if file_data.is_a?(StringIO) >> file_data.rewind >> self.temp_data = file_data.read >> else >> self.temp_path = file_data.path >> end >> end >> >> > > I'm not familiar with attachment_fu - is this code from attachment_fu > that you have modified? Or is it your code entirely? Attachment_fu's > entirely? Where does this code come from? > > Aslak > > >> While I was digging I found out that "file_data" is a ruby Tempfile object. >> So, I tried to create a dummy file and pass it, but it failed. I found out >> in the CGI library, it actually extends the Tempfile object and adds some >> methods/properties. It started to get messy, so I thought I'd ask for >> advice. >> >> How can I create a valid attachment_fu model spec(so I can start tweaking >> it to test my other validations)? >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070822/0a557459/attachment-0001.html From justinwr at gmail.com Wed Aug 22 12:55:11 2007 From: justinwr at gmail.com (Justin W. Reagor) Date: Wed, 22 Aug 2007 12:55:11 -0400 Subject: [rspec-users] How to spec an attachment_fu model In-Reply-To: <46CC684A.7030404@webinforem.com> References: <46CC6314.20908@webinforem.com> <8d961d900708220941ice5f7a5k4de1bb01a0f2ee1f@mail.gmail.com> <46CC684A.7030404@webinforem.com> Message-ID: <404DA4C0-A91C-4430-B030-EF1E58B181BE@gmail.com> I just got finished working with attachment_fu, and ended up modeling a plugin for my company since attachment_fu was slight over kill for our needs. Have you opened up attachment_fu's source? upload_data is just a method (so is upload_data=) which is inserted into a model that calls has_attachment. I have yet to spec my plugin so I'm interested to see what your results are. Thanks, :: Justin Reagor :: justinwr at gmail.com On Aug 22, 2007, at 12:46 PM, Matt Lins wrote: > Sorry, attachment_fu is a plugin for handling binary data. It > handles storing the file in the file system and storing some > helpful data in the database about the file. > > The previous code is from the attachment_fu plugin(no, I didn't > modify it). This property needs to be satisfied in order for the > model to validate. So I need to get my model to validate in the > spec so I can actually test other parts of my model. Here is my model: > > class Picture < ActiveRecord::Base > > has_and_belongs_to_many :products > > has_attachment :content_type => 'image/jpeg', > :storage => :file_system, > :max_size => 3.megabytes, > :resize_to => '400x400>', > :thumbnails => {:medium => '200x200>', :small => > '100x100>'}, > :path_prefix => 'images/products' > > validates_as_attachment > > validates_uniqueness_of :filename > validates_presence_of :filename > > def before_update > self.thumbnails.each do |t| > t.filename= thumbnail_name_for(t.thumbnail) > t.save > end > end > > def full_filename(thumbnail = nil) > file_system_path = (thumbnail ? thumbnail_class : > self).attachment_options[:path_prefix].to_s > File.join(RAILS_ROOT, 'public/external', file_system_path, > thumbnail_name_for(thumbnail) + '.jpg') > end > > def public_image > self.public_filename > end > > end > > aslak hellesoy wrote: >> On 8/22/07, Matt Lins wrote: >> >>> First off, I'm not trying to spec attachment_fu, I know it's >>> been tested. >>> >>> But, I added some code to that model that I do need to test. >>> Basically, I >>> need to somehow fulfill the "uploaded_data" property so I can >>> actually run >>> my tests(otherwise they fail because of validations). The >>> "uploaded_data" >>> field is what would grab the multipart data from form. Here it is: >>> >>> # This method handles the uploaded file object. If you >>> set the field >>> name to uploaded_data, you don't need >>> # any special code in your controller. >>> # >>> # <% form_for :attachment, :html => { :multipart => >>> true } do |f| >>> -%> >>> #

<%= f.file_field :uploaded_data %>

>>> #

<%= submit_tag :Save %> >>> # <% end -%> >>> # >>> # @attachment = Attachment.create! params[:attachment] >>> # >>> # TODO: Allow it to work with Merb tempfiles too. >>> def uploaded_data=(file_data) >>> return nil if file_data.nil? || file_data.size == 0 >>> self.content_type = file_data.content_type >>> self.filename = file_data.original_filename if >>> respond_to?(:filename) >>> if file_data.is_a?(StringIO) >>> file_data.rewind >>> self.temp_data = file_data.read >>> else >>> self.temp_path = file_data.path >>> end >>> end >>> >>> >> I'm not familiar with attachment_fu - is this code from attachment_fu >> that you have modified? Or is it your code entirely? Attachment_fu's >> entirely? Where does this code come from? >> >> Aslak >> >> >>> While I was digging I found out that "file_data" is a ruby >>> Tempfile object. >>> So, I tried to create a dummy file and pass it, but it failed. I >>> found out >>> in the CGI library, it actually extends the Tempfile object and >>> adds some >>> methods/properties. It started to get messy, so I thought I'd ask >>> for >>> advice. >>> >>> How can I create a valid attachment_fu model spec(so I can start >>> tweaking >>> it to test my other validations)? >>> >>> _______________________________________________ >>> 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070822/6ddf27a6/attachment.html From aslak.hellesoy at gmail.com Wed Aug 22 12:52:57 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 22 Aug 2007 18:52:57 +0200 Subject: [rspec-users] How to spec an attachment_fu model In-Reply-To: <46CC684A.7030404@webinforem.com> References: <46CC6314.20908@webinforem.com> <8d961d900708220941ice5f7a5k4de1bb01a0f2ee1f@mail.gmail.com> <46CC684A.7030404@webinforem.com> Message-ID: <8d961d900708220952p5073a5d0l7b088e71f98f243a@mail.gmail.com> On 8/22/07, Matt Lins wrote: > > Sorry, attachment_fu is a plugin for handling binary data. It handles > storing the file in the file system and storing some helpful data in the > database about the file. > > The previous code is from the attachment_fu plugin(no, I didn't modify > it). This property What property? The :filename property? > needs to be satisfied in order for the model to validate. > So I need to get my model to validate in the spec so I can actually test > other parts of my model. Here is my model: > Can't you just set the filename property directly from your spec without going through attachment kung fu? Aslak > class Picture < ActiveRecord::Base > > has_and_belongs_to_many :products > > has_attachment :content_type => 'image/jpeg', > :storage => :file_system, > :max_size => 3.megabytes, > :resize_to => '400x400>', > :thumbnails => {:medium => '200x200>', :small => > '100x100>'}, > :path_prefix => 'images/products' > > validates_as_attachment > > validates_uniqueness_of :filename > validates_presence_of :filename > > def before_update > self.thumbnails.each do |t| > t.filename= thumbnail_name_for(t.thumbnail) > t.save > end > end > > def full_filename(thumbnail = nil) > file_system_path = (thumbnail ? thumbnail_class : > self).attachment_options[:path_prefix].to_s > File.join(RAILS_ROOT, 'public/external', file_system_path, > thumbnail_name_for(thumbnail) + '.jpg') > end > > def public_image > self.public_filename > end > > end > > > aslak hellesoy wrote: > On 8/22/07, Matt Lins wrote: > > > First off, I'm not trying to spec attachment_fu, I know it's been tested. > > But, I added some code to that model that I do need to test. Basically, I > need to somehow fulfill the "uploaded_data" property so I can actually run > my tests(otherwise they fail because of validations). The "uploaded_data" > field is what would grab the multipart data from form. Here it is: > > # This method handles the uploaded file object. If you set the field > name to uploaded_data, you don't need > # any special code in your controller. > # > # <% form_for :attachment, :html => { :multipart => true } do |f| > -%> > #

<%= f.file_field :uploaded_data %>

> #

<%= submit_tag :Save %> > # <% end -%> > # > # @attachment = Attachment.create! params[:attachment] > # > # TODO: Allow it to work with Merb tempfiles too. > def uploaded_data=(file_data) > return nil if file_data.nil? || file_data.size == 0 > self.content_type = file_data.content_type > self.filename = file_data.original_filename if > respond_to?(:filename) > if file_data.is_a?(StringIO) > file_data.rewind > self.temp_data = file_data.read > else > self.temp_path = file_data.path > end > end > > > I'm not familiar with attachment_fu - is this code from attachment_fu > that you have modified? Or is it your code entirely? Attachment_fu's > entirely? Where does this code come from? > > Aslak > > > > While I was digging I found out that "file_data" is a ruby Tempfile object. > So, I tried to create a dummy file and pass it, but it failed. I found out > in the CGI library, it actually extends the Tempfile object and adds some > methods/properties. It started to get messy, so I thought I'd ask for > advice. > > How can I create a valid attachment_fu model spec(so I can start tweaking > it to test my other validations)? > > _______________________________________________ > 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 justnothing at tiscali.co.uk Wed Aug 22 13:09:39 2007 From: justnothing at tiscali.co.uk (David Green) Date: Wed, 22 Aug 2007 10:09:39 -0700 (PDT) Subject: [rspec-users] stubbing network calls Message-ID: <12279004.post@talk.nabble.com> I have a couple of methods which make networks calls. Where's the best place to stub them so they are stubbed for every description automatically? I tried in spec_helper.rb but they are no longer stubbed when a spec runs. at the moment, I'm checking for the test environment in the methods themselves, and returning a dummy value, but I'm sure there's a better way. -- View this message in context: http://www.nabble.com/stubbing-network-calls-tf4312869.html#a12279004 Sent from the rspec-users mailing list archive at Nabble.com. From justinwr at gmail.com Wed Aug 22 12:58:12 2007 From: justinwr at gmail.com (Justin W. Reagor) Date: Wed, 22 Aug 2007 12:58:12 -0400 Subject: [rspec-users] How to spec an attachment_fu model In-Reply-To: <46CC6314.20908@webinforem.com> References: <46CC6314.20908@webinforem.com> Message-ID: > # TODO: Allow it to work with Merb tempfiles too. > def uploaded_data=(file_data) > return nil if file_data.nil? || file_data.size == 0 > self.content_type = file_data.content_type Durh... stupid me, didn't see this post! :) :: Justin Reagor :: justinwr at gmail.com :: Justin Reagor :: justinwr at gmail.com On Aug 22, 2007, at 12:23 PM, Matt Lins wrote: > First off, I'm not trying to spec attachment_fu, I know it's been > tested. > > But, I added some code to that model that I do need to test. > Basically, I need to somehow fulfill the "uploaded_data" property > so I can actually run my tests(otherwise they fail because of > validations). The "uploaded_data" field is what would grab the > multipart data from form. Here it is: > > # This method handles the uploaded file object. If you set > the field name to uploaded_data, you don't need > # any special code in your controller. > # > # <% form_for :attachment, :html => { :multipart => true } > do |f| -%> > #

<%= f.file_field :uploaded_data %>

> #

<%= submit_tag :Save %> > # <% end -%> > # > # @attachment = Attachment.create! params[:attachment] > # > # TODO: Allow it to work with Merb tempfiles too. > def uploaded_data=(file_data) > return nil if file_data.nil? || file_data.size == 0 > self.content_type = file_data.content_type > self.filename = file_data.original_filename if > respond_to?(:filename) > if file_data.is_a?(StringIO) > file_data.rewind > self.temp_data = file_data.read > else > self.temp_path = file_data.path > end > end > > While I was digging I found out that "file_data" is a ruby Tempfile > object. So, I tried to create a dummy file and pass it, but it > failed. I found out in the CGI library, it actually extends the > Tempfile object and adds some methods/properties. It started to get > messy, so I thought I'd ask for advice. > > How can I create a valid attachment_fu model spec(so I can start > tweaking it to test my other validations)? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070822/d55178a9/attachment-0001.html From aslak.hellesoy at gmail.com Wed Aug 22 13:35:20 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 22 Aug 2007 19:35:20 +0200 Subject: [rspec-users] stubbing network calls In-Reply-To: <12279004.post@talk.nabble.com> References: <12279004.post@talk.nabble.com> Message-ID: <8d961d900708221035v34dd71delae0bb9ed9ebdbc73@mail.gmail.com> On 8/22/07, David Green wrote: > > I have a couple of methods which make networks calls. Where's the best place > to stub them so they are stubbed for every description automatically? I > tried in spec_helper.rb but they are no longer stubbed when a spec runs. > > at the moment, I'm checking for the test environment in the methods > themselves, and returning a dummy value, but I'm sure there's a better way. > Instead of stubbing methods on Socket (or whatever network class you're using) I would design the client of the "network" class in such a way that you can pass in whatever. The dependency injection technique. Then you just pass it a mock. Aslak > > -- > View this message in context: http://www.nabble.com/stubbing-network-calls-tf4312869.html#a12279004 > 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 mlins at webinforem.com Wed Aug 22 13:51:12 2007 From: mlins at webinforem.com (Matt Lins) Date: Wed, 22 Aug 2007 12:51:12 -0500 Subject: [rspec-users] How to spec an attachment_fu model In-Reply-To: <8d961d900708220952p5073a5d0l7b088e71f98f243a@mail.gmail.com> References: <46CC6314.20908@webinforem.com> <8d961d900708220941ice5f7a5k4de1bb01a0f2ee1f@mail.gmail.com> <46CC684A.7030404@webinforem.com> <8d961d900708220952p5073a5d0l7b088e71f98f243a@mail.gmail.com> Message-ID: <46CC7790.90002@webinforem.com> No, as mentioned in my first post, the property that needs to be fulfilled is uploaded_data. I posted the accessor in my first post as well. aslak hellesoy wrote: > On 8/22/07, Matt Lins wrote: > >> Sorry, attachment_fu is a plugin for handling binary data. It handles >> storing the file in the file system and storing some helpful data in the >> database about the file. >> >> The previous code is from the attachment_fu plugin(no, I didn't modify >> it). This property >> > > What property? The :filename property? > > >> needs to be satisfied in order for the model to validate. >> So I need to get my model to validate in the spec so I can actually test >> other parts of my model. Here is my model: >> >> > > Can't you just set the filename property directly from your spec > without going through attachment kung fu? > > Aslak > > >> class Picture < ActiveRecord::Base >> >> has_and_belongs_to_many :products >> >> has_attachment :content_type => 'image/jpeg', >> :storage => :file_system, >> :max_size => 3.megabytes, >> :resize_to => '400x400>', >> :thumbnails => {:medium => '200x200>', :small => >> '100x100>'}, >> :path_prefix => 'images/products' >> >> validates_as_attachment >> >> validates_uniqueness_of :filename >> validates_presence_of :filename >> >> def before_update >> self.thumbnails.each do |t| >> t.filename= thumbnail_name_for(t.thumbnail) >> t.save >> end >> end >> >> def full_filename(thumbnail = nil) >> file_system_path = (thumbnail ? thumbnail_class : >> self).attachment_options[:path_prefix].to_s >> File.join(RAILS_ROOT, 'public/external', file_system_path, >> thumbnail_name_for(thumbnail) + '.jpg') >> end >> >> def public_image >> self.public_filename >> end >> >> end >> >> >> aslak hellesoy wrote: >> On 8/22/07, Matt Lins wrote: >> >> >> First off, I'm not trying to spec attachment_fu, I know it's been tested. >> >> But, I added some code to that model that I do need to test. Basically, I >> need to somehow fulfill the "uploaded_data" property so I can actually run >> my tests(otherwise they fail because of validations). The "uploaded_data" >> field is what would grab the multipart data from form. Here it is: >> >> # This method handles the uploaded file object. If you set the field >> name to uploaded_data, you don't need >> # any special code in your controller. >> # >> # <% form_for :attachment, :html => { :multipart => true } do |f| >> -%> >> #

<%= f.file_field :uploaded_data %>

>> #

<%= submit_tag :Save %> >> # <% end -%> >> # >> # @attachment = Attachment.create! params[:attachment] >> # >> # TODO: Allow it to work with Merb tempfiles too. >> def uploaded_data=(file_data) >> return nil if file_data.nil? || file_data.size == 0 >> self.content_type = file_data.content_type >> self.filename = file_data.original_filename if >> respond_to?(:filename) >> if file_data.is_a?(StringIO) >> file_data.rewind >> self.temp_data = file_data.read >> else >> self.temp_path = file_data.path >> end >> end >> >> >> I'm not familiar with attachment_fu - is this code from attachment_fu >> that you have modified? Or is it your code entirely? Attachment_fu's >> entirely? Where does this code come from? >> >> Aslak >> >> >> >> While I was digging I found out that "file_data" is a ruby Tempfile object. >> So, I tried to create a dummy file and pass it, but it failed. I found out >> in the CGI library, it actually extends the Tempfile object and adds some >> methods/properties. It started to get messy, so I thought I'd ask for >> advice. >> >> How can I create a valid attachment_fu model spec(so I can start tweaking >> it to test my other validations)? >> >> _______________________________________________ >> 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070822/59e27f77/attachment.html From aslak.hellesoy at gmail.com Wed Aug 22 13:58:21 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 22 Aug 2007 19:58:21 +0200 Subject: [rspec-users] How to spec an attachment_fu model In-Reply-To: <46CC7790.90002@webinforem.com> References: <46CC6314.20908@webinforem.com> <8d961d900708220941ice5f7a5k4de1bb01a0f2ee1f@mail.gmail.com> <46CC684A.7030404@webinforem.com> <8d961d900708220952p5073a5d0l7b088e71f98f243a@mail.gmail.com> <46CC7790.90002@webinforem.com> Message-ID: <8d961d900708221058q37435435x34cc78f08c567aea@mail.gmail.com> On 8/22/07, Matt Lins wrote: > > No, as mentioned in my first post, the property that needs to be fulfilled > is uploaded_data. I posted the accessor in my first post as well. > Which part of my answer are you answering no to? Can you inline your answers so I can follow? > > aslak hellesoy wrote: > On 8/22/07, Matt Lins wrote: > > > Sorry, attachment_fu is a plugin for handling binary data. It handles > storing the file in the file system and storing some helpful data in the > database about the file. > > The previous code is from the attachment_fu plugin(no, I didn't modify > it). This property > > What property? The :filename property? > > > > needs to be satisfied in order for the model to validate. > So I need to get my model to validate in the spec so I can actually test > other parts of my model. Here is my model: > > > Can't you just set the filename property directly from your spec > without going through attachment kung fu? > > Aslak > > > > class Picture < ActiveRecord::Base > > has_and_belongs_to_many :products > > has_attachment :content_type => 'image/jpeg', > :storage => :file_system, > :max_size => 3.megabytes, > :resize_to => '400x400>', > :thumbnails => {:medium => '200x200>', :small => > '100x100>'}, > :path_prefix => 'images/products' > > validates_as_attachment > > validates_uniqueness_of :filename > validates_presence_of :filename > > def before_update > self.thumbnails.each do |t| > t.filename= thumbnail_name_for(t.thumbnail) > t.save > end > end > > def full_filename(thumbnail = nil) > file_system_path = (thumbnail ? thumbnail_class : > self).attachment_options[:path_prefix].to_s > File.join(RAILS_ROOT, 'public/external', file_system_path, > thumbnail_name_for(thumbnail) + '.jpg') > end > > def public_image > self.public_filename > end > > end > > > aslak hellesoy wrote: > On 8/22/07, Matt Lins wrote: > > > First off, I'm not trying to spec attachment_fu, I know it's been tested. > > But, I added some code to that model that I do need to test. Basically, I > need to somehow fulfill the "uploaded_data" property so I can actually run > my tests(otherwise they fail because of validations). The "uploaded_data" > field is what would grab the multipart data from form. Here it is: > > # This method handles the uploaded file object. If you set the field > name to uploaded_data, you don't need > # any special code in your controller. > # > # <% form_for :attachment, :html => { :multipart => true } do |f| > -%> > #

<%= f.file_field :uploaded_data %>

> #

<%= submit_tag :Save %> > # <% end -%> > # > # @attachment = Attachment.create! params[:attachment] > # > # TODO: Allow it to work with Merb tempfiles too. > def uploaded_data=(file_data) > return nil if file_data.nil? || file_data.size == 0 > self.content_type = file_data.content_type > self.filename = file_data.original_filename if > respond_to?(:filename) > if file_data.is_a?(StringIO) > file_data.rewind > self.temp_data = file_data.read > else > self.temp_path = file_data.path > end > end > > > I'm not familiar with attachment_fu - is this code from attachment_fu > that you have modified? Or is it your code entirely? Attachment_fu's > entirely? Where does this code come from? > > Aslak > > > > While I was digging I found out that "file_data" is a ruby Tempfile object. > So, I tried to create a dummy file and pass it, but it failed. I found out > in the CGI library, it actually extends the Tempfile object and adds some > methods/properties. It started to get messy, so I thought I'd ask for > advice. > > How can I create a valid attachment_fu model spec(so I can start tweaking > it to test my other validations)? > > _______________________________________________ > 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 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From justnothing at tiscali.co.uk Wed Aug 22 14:22:24 2007 From: justnothing at tiscali.co.uk (David Green) Date: Wed, 22 Aug 2007 11:22:24 -0700 (PDT) Subject: [rspec-users] stubbing network calls In-Reply-To: <8d961d900708221035v34dd71delae0bb9ed9ebdbc73@mail.gmail.com> References: <12279004.post@talk.nabble.com> <8d961d900708221035v34dd71delae0bb9ed9ebdbc73@mail.gmail.com> Message-ID: <12280131.post@talk.nabble.com> On 8/22/07, David Green wrote: > > I have a couple of methods which make networks calls. Where's the best > place > to stub them so they are stubbed for every description automatically? I > tried in spec_helper.rb but they are no longer stubbed when a spec runs. > > at the moment, I'm checking for the test environment in the methods > themselves, and returning a dummy value, but I'm sure there's a better > way. > Instead of stubbing methods on Socket (or whatever network class you're using) I would design the client of the "network" class in such a way that you can pass in whatever. The dependency injection technique. Then you just pass it a mock. Aslak thanks for the suggestion. I'd still need to do this every place there's a call to a network method right? My problem is the methods are used extensively. One is a before_filter so it's easy to stub. The other is in a general purpose class which various models and controllers use, i was hoping there would be one central place where I could stub that out -- View this message in context: http://www.nabble.com/stubbing-network-calls-tf4312869.html#a12280131 Sent from the rspec-users mailing list archive at Nabble.com. From jerry.west at ntlworld.com Wed Aug 22 14:20:26 2007 From: jerry.west at ntlworld.com (Jerry West) Date: Wed, 22 Aug 2007 19:20:26 +0100 Subject: [rspec-users] How to spec an attachment_fu model In-Reply-To: References: <46CC6314.20908@webinforem.com> Message-ID: <46CC7E6A.1090900@ntlworld.com> I think you need to clarify what you mean by 'spec an attachment_fu model'. Do you want the validates_as_attachment to succeed with your test data, for instance? If so, simply stub the call: Picture.should_receive(:validates_as_attachment) so that you can be confident the model does the right thing (ensuring it is validated in real life) but the real validation code is never called and so never added to the validation chain, so your test models will save without hassle. I think that's the gist of your problem - you can't get test model instances to validate and so cannot write meaningful tests? Alternatively you may have to include your failing specs so we can understand your situation more clearly. Best wishes, Jerry From flyeminent at hotmail.com Wed Aug 22 20:31:58 2007 From: flyeminent at hotmail.com (Shaker) Date: Wed, 22 Aug 2007 17:31:58 -0700 (PDT) Subject: [rspec-users] Can module spec use fixtures? Message-ID: <12285512.post@talk.nabble.com> Good morning, dear fellows: I'd like to recall one question I posted yesterday. I am writing specs for ruby modules. Some of the modules do some data process in the test database. Because 'fixtures' is undefined (Am I correct?) in module specs, spec of certain module (e.g. delete data form database) will affect other specs of other modules (e.g. try to access the deleted data). My observation is all the modules specs share only a copy of test data. If I am correct, are there any way of avoiding this, and providing a copy of initial test data (like fixtures do) for each module spec? Thanks Regards. -- View this message in context: http://www.nabble.com/Can-module-spec-use-fixtures--tf4314808.html#a12285512 Sent from the rspec-users mailing list archive at Nabble.com. From luislavena at gmail.com Wed Aug 22 20:37:00 2007 From: luislavena at gmail.com (Luis Lavena) Date: Wed, 22 Aug 2007 21:37:00 -0300 Subject: [rspec-users] Can module spec use fixtures? In-Reply-To: <12285512.post@talk.nabble.com> References: <12285512.post@talk.nabble.com> Message-ID: <71166b3b0708221737j565a7d66tdb461afe145a1ff9@mail.gmail.com> On 8/22/07, Shaker wrote: > > Good morning, dear fellows: > I'd like to recall one question I posted yesterday. I am writing specs > for ruby modules. Some of the modules do some data process in the test > database. Because 'fixtures' is undefined (Am I correct?) in module specs, > spec of certain module (e.g. delete data form database) will affect other > specs of other modules (e.g. try to access the deleted data). My observation > is all the modules specs share only a copy of test data. > If I am correct, are there any way of avoiding this, and providing a > copy of initial test data (like fixtures do) for each module spec? I'll like to ask you if the "feature" you have implemented inside those modules is related to a model (I guess). So, shouldn't be better describe the specs for your model in that specified context, make it shared and later do it_should_behave_like '...' ? As previous discussed inthe list, creating specs for especific functionality (like the acts_as_list thread) will make your specs brittle. Expecting results (which the aim of BDD) is more helpful. Or maybe I'm wrong (as usual) and don't get the picture ;-) -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi From davidjrice at gmail.com Thu Aug 23 12:18:20 2007 From: davidjrice at gmail.com (David Rice) Date: Thu, 23 Aug 2007 17:18:20 +0100 Subject: [rspec-users] Test::Unit to RSpec In-Reply-To: <992B8A68-0B0B-4440-8A9D-9C5E2B492A6D@railsnewbie.com> References: <992B8A68-0B0B-4440-8A9D-9C5E2B492A6D@railsnewbie.com> Message-ID: Scott, There was a thread about this earlier... You might be interested in this plugin I wrote. Kinda basic but worked for me. http://www.davidjrice.co.uk/articles/2007/8/12/ruby-on-rails-plugin- test-unit-to-rspec-converter Best, Dave On 18 Aug 2007, at 09:38, Scott Taylor wrote: > > So I've just started working on a rails project which currently has > something like 7500 LOC. All of the tests are written in Test::Unit, > although the test coverage is pretty poor: rcov says that 25% of the > code is covered, while rake stats shows the code to test ratio as > 1:0.1 (800 lines of test code). > > I guess I'm wondering what would generally be advisable here. Is it > worth it to work on (or use) a test:unit => spec translator? Should > I just start using rspec when I need to start writing code, and > perform regressions when need be? Or is the project too big to even > consider using rspec? > > Thanks in advance for any experienced advice, > > Scott Taylor > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users --- David Rice http://www.davidjrice.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070823/62b7c90e/attachment.html From cwdinfo at gmail.com Thu Aug 23 13:57:06 2007 From: cwdinfo at gmail.com (s.ross) Date: Thu, 23 Aug 2007 10:57:06 -0700 Subject: [rspec-users] controller spec with model that validates_uniqueness Message-ID: <8379025F-5318-4BB1-B52A-DBE7AEA69688@gmail.com> I want to use mocks and stubs to test the controller, but am having trouble getting my validation not to trigger. Here's the code: # spec: Image.stub!(:find).and_return(@image) @image.should_receive(:save!).once.with(:any_args) put :update, :id => @image.id, :category_id => @category.id, :image => {:name => 'test', :image_number => 13554} #model validates_presence_of :name validates_uniqueness_of :name, :allow_nil => true # rspec output ActiveRecord::RecordInvalid in 'ImagesController should update a database record when it receives a PUT' Validation failed: Name has already been taken, Image number has already been taken It seems AR is not detecting that this is an edit/update that will not cause a uniqueness conflict. I believe the code in the model needs to remain in place because I don't want a user creating a name conflict by editing an existing name into one that already exists in the database. Any thoughts on how better to spec this? Thanks From mailing_lists at railsnewbie.com Thu Aug 23 15:23:39 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 23 Aug 2007 15:23:39 -0400 Subject: [rspec-users] Test::Unit to RSpec In-Reply-To: References: <992B8A68-0B0B-4440-8A9D-9C5E2B492A6D@railsnewbie.com> Message-ID: <3B0F9038-60BF-4565-8879-159358B73E1F@railsnewbie.com> On Aug 23, 2007, at 12:18 PM, David Rice wrote: > Scott, > > There was a thread about this earlier... You might be interested in > this plugin I wrote. Kinda basic but worked for me. > > http://www.davidjrice.co.uk/articles/2007/8/12/ruby-on-rails-plugin- > test-unit-to-rspec-converter Yeah - actually I saw it, and tried it out. Although I can't lie - it didn't work well. I can't imagine any translator really working well. How would you add mocks + stubs + clear specifications + 1 test-per-spec in a translator, and do it intelligently? But, for what it's worth - it did what I expected it to do, and would be a good, but crude way, to translate a lot test::unit code to rspec. Thanks for the tool (and have you looked into the old rspec one - test2spec, I believe it was called)? Scott > > Best, > Dave > > > On 18 Aug 2007, at 09:38, Scott Taylor wrote: > >> >> So I've just started working on a rails project which currently has >> something like 7500 LOC. All of the tests are written in Test::Unit, >> although the test coverage is pretty poor: rcov says that 25% of the >> code is covered, while rake stats shows the code to test ratio as >> 1:0.1 (800 lines of test code). >> >> I guess I'm wondering what would generally be advisable here. Is it >> worth it to work on (or use) a test:unit => spec translator? Should >> I just start using rspec when I need to start writing code, and >> perform regressions when need be? Or is the project too big to even >> consider using rspec? >> >> Thanks in advance for any experienced advice, >> >> Scott Taylor >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > --- > David Rice > http://www.davidjrice.co.uk > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From davidjrice at gmail.com Thu Aug 23 15:58:32 2007 From: davidjrice at gmail.com (David Rice) Date: Thu, 23 Aug 2007 20:58:32 +0100 Subject: [rspec-users] Test::Unit to RSpec In-Reply-To: <3B0F9038-60BF-4565-8879-159358B73E1F@railsnewbie.com> References: <992B8A68-0B0B-4440-8A9D-9C5E2B492A6D@railsnewbie.com> <3B0F9038-60BF-4565-8879-159358B73E1F@railsnewbie.com> Message-ID: <26295C8C-8AD7-4C74-8191-9E10DE220904@gmail.com> On 23 Aug 2007, at 20:23, Scott Taylor wrote: > > On Aug 23, 2007, at 12:18 PM, David Rice wrote: > >> Scott, >> >> There was a thread about this earlier... You might be interested in >> this plugin I wrote. Kinda basic but worked for me. >> >> http://www.davidjrice.co.uk/articles/2007/8/12/ruby-on-rails-plugin- >> test-unit-to-rspec-converter > > Yeah - actually I saw it, and tried it out. Although I can't lie - > it didn't work well. I can't imagine any translator really working > well. How would you add mocks + stubs + clear specifications + 1 > test-per-spec in a translator, and do it intelligently? > Totally :) Yeah there's so many different syntax variants that it becomes hard across testing styles. Especially now that all of my test suites are converted over to RSpec... I really don't think the complexity is worth it because for the people that use the tool it instantly becomes useless after they are "converted". > But, for what it's worth - it did what I expected it to do, and would > be a good, but crude way, to translate a lot test::unit code to rspec. > > Thanks for the tool (and have you looked into the old rspec one - > test2spec, I believe it was called)? > No problem! Yeah the original was very interesting to look at once I realised it did exist and wasn't a dream ( I went on a fruitless hunt before rolling my own ). > Scott > > >> >> Best, >> Dave >> >> >> On 18 Aug 2007, at 09:38, Scott Taylor wrote: >> >>> >>> So I've just started working on a rails project which currently has >>> something like 7500 LOC. All of the tests are written in >>> Test::Unit, >>> although the test coverage is pretty poor: rcov says that 25% of the >>> code is covered, while rake stats shows the code to test ratio as >>> 1:0.1 (800 lines of test code). >>> >>> I guess I'm wondering what would generally be advisable here. Is it >>> worth it to work on (or use) a test:unit => spec translator? Should >>> I just start using rspec when I need to start writing code, and >>> perform regressions when need be? Or is the project too big to even >>> consider using rspec? >>> >>> Thanks in advance for any experienced advice, >>> >>> Scott Taylor >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> --- >> David Rice >> http://www.davidjrice.co.uk >> >> >> >> >> _______________________________________________ >> 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 --- David Rice +44 (0)78 708 12996 http://www.davidjrice.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070823/f907eef5/attachment-0001.html From ben at benmabey.com Thu Aug 23 12:41:55 2007 From: ben at benmabey.com (Ben Mabey) Date: Thu, 23 Aug 2007 10:41:55 -0600 Subject: [rspec-users] Keeping unit tests from hitting the DB In-Reply-To: References: <992B8A68-0B0B-4440-8A9D-9C5E2B492A6D@railsnewbie.com> Message-ID: <46CDB8D3.2030906@benmabey.com> Hey all, I think I saw a thread about this earlier (maybe it was on the devlopers list) but I am wondering if anyone has stubbed out AR so that the unit test do not hit the database. The reason I am curious is because there was a lightning talk given at the Ruby Hoedown (watch it here: http://rubyhoedown2007.confreaks.com/session06.html) about separating unit tests from the DB entirely and making it a lot faster. I'm not just talking about not using fixtures but this would not even query the DB for columns or do any inserts or updates either. Dan Manges was the presenter and he talks about it on his blog and his newly released gem: http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database I haven't experimented with the gem yet but I'm sure it could be changed to work with rspec. I'm curious about people's opinions about this practice and see if anyone has done something similar with rspec already. I think the speed is very attractive but if you were to do this you would need to to have another type of test that would actually hit the DB. Has anyone done this with rspec that could shed a little more light on the advantages/disadvantages? Thanks, Ben From dchelimsky at gmail.com Thu Aug 23 17:43:44 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 23 Aug 2007 16:43:44 -0500 Subject: [rspec-users] Keeping unit tests from hitting the DB In-Reply-To: <46CDB8D3.2030906@benmabey.com> References: <992B8A68-0B0B-4440-8A9D-9C5E2B492A6D@railsnewbie.com> <46CDB8D3.2030906@benmabey.com> Message-ID: <57c63afe0708231443g2bdba02fsed2ed82d609edb43@mail.gmail.com> On 8/23/07, Ben Mabey wrote: > Hey all, > I think I saw a thread about this earlier (maybe it was on the devlopers > list) but I am wondering if anyone has stubbed out AR so that the unit > test do not hit the database. The reason I am curious is because there > was a lightning talk given at the Ruby Hoedown (watch it here: > http://rubyhoedown2007.confreaks.com/session06.html) about separating > unit tests from the DB entirely and making it a lot faster. I'm not > just talking about not using fixtures but this would not even query the > DB for columns or do any inserts or updates either. Dan Manges was the > presenter and he talks about it on his blog and his newly released gem: > http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database > > I haven't experimented with the gem yet but I'm sure it could be changed > to work with rspec. I'm curious about people's opinions about this > practice and see if anyone has done something similar with rspec > already. I've heard of ppl experimenting w/ this but haven't seen it in action. I would LOVE to see this capability but I'd like to be able to control it from behaviour to behaviour. For example, I tend to mock all models in view, controller and helper specs, but not in model specs, where I tend to let them interact w/ the DB. I'm not recommending that approach over mocking models in model specs, just saying that it's my personal preference. There are very good arguments to do it differently. That said, I'd want to be able to do this in spec_helper.rb: Spec::Runner.configure do |config| config.deny_db_access :view, :controller, :helper end or _something_ like that. Then if a controller spec tries to hit the db you should get an error. Feel like contributing that? > I think the speed is very attractive but if you were to do > this you would need to to have another type of test that would actually > hit the DB. Has anyone done this with rspec that could shed a little > more light on the advantages/disadvantages? > > Thanks, > Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From court3nay at gmail.com Thu Aug 23 20:11:17 2007 From: court3nay at gmail.com (Courtenay) Date: Thu, 23 Aug 2007 17:11:17 -0700 Subject: [rspec-users] controller spec with model that validates_uniqueness In-Reply-To: <8379025F-5318-4BB1-B52A-DBE7AEA69688@gmail.com> References: <8379025F-5318-4BB1-B52A-DBE7AEA69688@gmail.com> Message-ID: <4b430c8f0708231711x26a5c04cof48129f0bb9a27b7@mail.gmail.com> Does this work? Image.stub!(:validates_uniqueness_of).and_return(true) On 8/23/07, s.ross wrote: > I want to use mocks and stubs to test the controller, but am having > trouble getting my validation not to trigger. Here's the code: > > # spec: > > Image.stub!(:find).and_return(@image) > @image.should_receive(:save!).once.with(:any_args) > put :update, :id => @image.id, :category_id => > @category.id, :image => {:name => 'test', :image_number => 13554} > > #model > > validates_presence_of :name > validates_uniqueness_of :name, :allow_nil => true > > # rspec output > > ActiveRecord::RecordInvalid in 'ImagesController should update a > database record when it receives a PUT' > Validation failed: Name has already been taken, Image number has > already been taken > > > It seems AR is not detecting that this is an edit/update that will > not cause a uniqueness conflict. I believe the code in the model > needs to remain in place because I don't want a user creating a name > conflict by editing an existing name into one that already exists in > the database. Any thoughts on how better to spec this? > > Thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben at benmabey.com Thu Aug 23 21:43:30 2007 From: ben at benmabey.com (Ben Mabey) Date: Thu, 23 Aug 2007 19:43:30 -0600 Subject: [rspec-users] Keeping unit tests from hitting the DB In-Reply-To: <57c63afe0708231443g2bdba02fsed2ed82d609edb43@mail.gmail.com> References: <992B8A68-0B0B-4440-8A9D-9C5E2B492A6D@railsnewbie.com> <46CDB8D3.2030906@benmabey.com> <57c63afe0708231443g2bdba02fsed2ed82d609edb43@mail.gmail.com> Message-ID: <46CE37C2.2060707@benmabey.com> David Chelimsky wrote: > On 8/23/07, Ben Mabey wrote: > >> Hey all, >> I think I saw a thread about this earlier (maybe it was on the devlopers >> list) but I am wondering if anyone has stubbed out AR so that the unit >> test do not hit the database. The reason I am curious is because there >> was a lightning talk given at the Ruby Hoedown (watch it here: >> http://rubyhoedown2007.confreaks.com/session06.html) about separating >> unit tests from the DB entirely and making it a lot faster. I'm not >> just talking about not using fixtures but this would not even query the >> DB for columns or do any inserts or updates either. Dan Manges was the >> presenter and he talks about it on his blog and his newly released gem: >> http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database >> >> I haven't experimented with the gem yet but I'm sure it could be changed >> to work with rspec. I'm curious about people's opinions about this >> practice and see if anyone has done something similar with rspec >> already. >> > > I've heard of ppl experimenting w/ this but haven't seen it in action. > I would LOVE to see this capability but I'd like to be able to control > it from behaviour to behaviour. For example, I tend to mock all models > in view, controller and helper specs, but not in model specs, where I > tend to let them interact w/ the DB. I'm not recommending that > approach over mocking models in model specs, just saying that it's my > personal preference. There are very good arguments to do it > differently. > > That said, I'd want to be able to do this in spec_helper.rb: > > Spec::Runner.configure do |config| > config.deny_db_access :view, :controller, :helper > end > > or _something_ like that. Then if a controller spec tries to hit the > db you should get an error. > > Feel like contributing that? > > So would the "config.deny_db_access :view, :controller, :helper" line just throw an exception upon any DB access thereby acting as an alert saying that your using the DB instead of mocking appropriately? Is that right? Or should that line automatically stub the AR methods like new, save, create, etc to prevent any DB activity but give the illusion of talking to the DB? The latter is is what I was thinking for the model specs, although the alert exception would also be a good idea- especially for the controllers, views, and helpers. I have yet to dive into the rspec internals but I would definitely like to contribute. Let me know if the alert idea is what you meant. Thanks, Ben From has.sox at gmail.com Thu Aug 23 21:53:56 2007 From: has.sox at gmail.com (Daniel N) Date: Fri, 24 Aug 2007 11:53:56 +1000 Subject: [rspec-users] controller spec with model that validates_uniqueness In-Reply-To: <4b430c8f0708231711x26a5c04cof48129f0bb9a27b7@mail.gmail.com> References: <8379025F-5318-4BB1-B52A-DBE7AEA69688@gmail.com> <4b430c8f0708231711x26a5c04cof48129f0bb9a27b7@mail.gmail.com> Message-ID: <2fff50390708231853k77cc8ecfm826c97ace408ee7e@mail.gmail.com> On 8/24/07, Courtenay wrote: > > Does this work? > > Image.stub!(:validates_uniqueness_of).and_return(true) > > > On 8/23/07, s.ross wrote: > > I want to use mocks and stubs to test the controller, but am having > > trouble getting my validation not to trigger. Here's the code: > > > > # spec: > > > > Image.stub!(:find).and_return(@image) > > @image.should_receive(:save!).once.with(:any_args) > > put :update, :id => @image.id, :category_id => > > @category.id, :image => {:name => 'test', :image_number => 13554} > > > > #model > > > > validates_presence_of :name > > validates_uniqueness_of :name, :allow_nil => true > > > > # rspec output > > > > ActiveRecord::RecordInvalid in 'ImagesController should update a > > database record when it receives a PUT' > > Validation failed: Name has already been taken, Image number has > > already been taken > > > > > > It seems AR is not detecting that this is an edit/update that will > > not cause a uniqueness conflict. I believe the code in the model > > needs to remain in place because I don't want a user creating a name > > conflict by editing an existing name into one that already exists in > > the database. Any thoughts on how better to spec this? > > > > Thanks > > _______________________________________________ Why use a real image at all? I usually use mock_model on these and then stub/mock the specific calls in the controller method. This way your not testing the model at all. Just the controller. Of course, they can get pretty complex with all the stubbing etc. Image.stub!(:find).and_return(@image) @image.should_receive(:save!).once.with(:any_args) put :update, :id => @image.id, :category_id => @category.id, :image => {:name => 'test', :image_number => 13554} could become. @category = mock_model( Category, :id => 1 ) # Not sure where this one is used other than the call to put @image = mock_model( Image, :id => 2 ) @image.should_receive( :save! ).once.with( :any_args ).and_return( true ) Image.stub!( :find ).and_return( @image ) put :update, :id => @image.id, :category_id => @category.id, :image => {:name => 'test', :image_number => 13554} This way you're not reaching into the model to check your controller. HTH Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070824/7a761815/attachment.html From zach.dennis at gmail.com Thu Aug 23 22:49:30 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 23 Aug 2007 22:49:30 -0400 Subject: [rspec-users] controller spec with model that validates_uniqueness In-Reply-To: <2fff50390708231853k77cc8ecfm826c97ace408ee7e@mail.gmail.com> References: <8379025F-5318-4BB1-B52A-DBE7AEA69688@gmail.com> <4b430c8f0708231711x26a5c04cof48129f0bb9a27b7@mail.gmail.com> <2fff50390708231853k77cc8ecfm826c97ace408ee7e@mail.gmail.com> Message-ID: <85d99afe0708231949x6246f9a6g3273307c723099e2@mail.gmail.com> On 8/23/07, Daniel N wrote: > > > > On 8/24/07, Courtenay wrote: > > Does this work? > > > > Image.stub!(:validates_uniqueness_of).and_return(true) > > > > > > On 8/23/07, s.ross wrote: > > > I want to use mocks and stubs to test the controller, but am having > > > trouble getting my validation not to trigger. Here's the code: > > > > > > # spec: > > > > > > Image.stub!(:find).and_return(@image) > > > @image.should_receive(:save!).once.with(:any_args) > > > put :update, :id => @image.id, :category_id => > > > @category.id, :image => {:name => 'test', :image_number => 13554} > > > > > > #model > > > > > > validates_presence_of :name > > > validates_uniqueness_of :name, :allow_nil => true > > > > > > # rspec output > > > > > > ActiveRecord::RecordInvalid in 'ImagesController should update a > > > database record when it receives a PUT' > > > Validation failed: Name has already been taken, Image number has > > > already been taken > > > > > > > > > It seems AR is not detecting that this is an edit/update that will > > > not cause a uniqueness conflict. I believe the code in the model > > > needs to remain in place because I don't want a user creating a name > > > conflict by editing an existing name into one that already exists in > > > the database. Any thoughts on how better to spec this? > > > > > > Thanks > > > _______________________________________________ > > Why use a real image at all? I usually use mock_model on these and then > stub/mock the specific calls in the controller method. This way your not > testing the model at all. Just the controller. Of course, they can get > pretty complex with all the stubbing etc. > > Image.stub!(:find).and_return(@image) > @image.should_receive(:save!).once.with(:any_args) > put :update, :id => @image.id, :category_id => > @category.id, :image => {:name => 'test', :image_number => 13554} > > could become. > > @category = mock_model( Category, :id => 1 ) # Not sure where this one is > used other than the call to put > @image = mock_model( Image, :id => 2 ) > @image.should_receive( :save! ).once.with( :any_args ).and_return( true ) > Image.stub!( :find ).and_return( @image ) > > put :update, :id => @image.id, :category_id => > @category.id, :image => {:name => 'test', :image_number => 13554} > > This way you're not reaching into the model to check your controller. You can even go as far as removing all of that ActiveRecord interaction from your controller. @image = mock("image") Image.should_receive(:update_image).with(@image) put :update, :id => 1, :category_id => 2, :image => @image You would also want to test a failure case I'm sure (if you redirected...): Image.stub!(:update_image).and_raise(ActiveRecord::ActiveRecordError) put :update, :id => 1, :category_id => 2, :image => @image response.should be_redirect response.should redirect_to(:action => "other_action") This keeps your controller a little cleaner and pushes down the interaction of working with ActiveRecord models to a minimum. Now you can put the code that actually handles an update in your model class and your controller doesn't have to worry about how it is saved, it either works or raises an exception, Zach From pergesu at gmail.com Thu Aug 23 22:55:45 2007 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 23 Aug 2007 19:55:45 -0700 Subject: [rspec-users] controller spec with model that validates_uniqueness In-Reply-To: <8379025F-5318-4BB1-B52A-DBE7AEA69688@gmail.com> References: <8379025F-5318-4BB1-B52A-DBE7AEA69688@gmail.com> Message-ID: <810a540e0708231955q7f76188bq853c28b9726e8a5b@mail.gmail.com> On 8/23/07, s.ross wrote: > I want to use mocks and stubs to test the controller, but am having > trouble getting my validation not to trigger. Here's the code: > > # spec: > > Image.stub!(:find).and_return(@image) > @image.should_receive(:save!).once.with(:any_args) > put :update, :id => @image.id, :category_id => > @category.id, :image => {:name => 'test', :image_number => 13554} > > #model > > validates_presence_of :name > validates_uniqueness_of :name, :allow_nil => true > > # rspec output > > ActiveRecord::RecordInvalid in 'ImagesController should update a > database record when it receives a PUT' > Validation failed: Name has already been taken, Image number has > already been taken > > > It seems AR is not detecting that this is an edit/update that will > not cause a uniqueness conflict. I believe the code in the model > needs to remain in place because I don't want a user creating a name > conflict by editing an existing name into one that already exists in > the database. Any thoughts on how better to spec this? > > Thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > As others have said, return a mock object instead of an actual AR object. You don't really care what the underlying implementation is, only that particular methods get called. Pat From zach.dennis at gmail.com Thu Aug 23 22:57:52 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 23 Aug 2007 22:57:52 -0400 Subject: [rspec-users] controller spec with model that validates_uniqueness In-Reply-To: <85d99afe0708231949x6246f9a6g3273307c723099e2@mail.gmail.com> References: <8379025F-5318-4BB1-B52A-DBE7AEA69688@gmail.com> <4b430c8f0708231711x26a5c04cof48129f0bb9a27b7@mail.gmail.com> <2fff50390708231853k77cc8ecfm826c97ace408ee7e@mail.gmail.com> <85d99afe0708231949x6246f9a6g3273307c723099e2@mail.gmail.com> Message-ID: <85d99afe0708231957u281ed4c8hdda46c6b7613355c@mail.gmail.com> Actually better then an exception On 8/23/07, Zach Dennis wrote: > On 8/23/07, Daniel N wrote: > > > > > > > > On 8/24/07, Courtenay wrote: > > > Does this work? > > > > > > Image.stub!(:validates_uniqueness_of).and_return(true) > > > > > > > > > On 8/23/07, s.ross wrote: > > > > I want to use mocks and stubs to test the controller, but am having > > > > trouble getting my validation not to trigger. Here's the code: > > > > > > > > # spec: > > > > > > > > Image.stub!(:find).and_return(@image) > > > > @image.should_receive(:save!).once.with(:any_args) > > > > put :update, :id => @image.id, :category_id => > > > > @category.id, :image => {:name => 'test', :image_number => 13554} > > > > > > > > #model > > > > > > > > validates_presence_of :name > > > > validates_uniqueness_of :name, :allow_nil => true > > > > > > > > # rspec output > > > > > > > > ActiveRecord::RecordInvalid in 'ImagesController should update a > > > > database record when it receives a PUT' > > > > Validation failed: Name has already been taken, Image number has > > > > already been taken > > > > > > > > > > > > It seems AR is not detecting that this is an edit/update that will > > > > not cause a uniqueness conflict. I believe the code in the model > > > > needs to remain in place because I don't want a user creating a name > > > > conflict by editing an existing name into one that already exists in > > > > the database. Any thoughts on how better to spec this? > > > > > > > > Thanks > > > > _______________________________________________ > > > > Why use a real image at all? I usually use mock_model on these and then > > stub/mock the specific calls in the controller method. This way your not > > testing the model at all. Just the controller. Of course, they can get > > pretty complex with all the stubbing etc. > > > > Image.stub!(:find).and_return(@image) > > @image.should_receive(:save!).once.with(:any_args) > > put :update, :id => @image.id, :category_id => > > @category.id, :image => {:name => 'test', :image_number => 13554} > > > > could become. > > > > @category = mock_model( Category, :id => 1 ) # Not sure where this one is > > used other than the call to put > > @image = mock_model( Image, :id => 2 ) > > @image.should_receive( :save! ).once.with( :any_args ).and_return( true ) > > Image.stub!( :find ).and_return( @image ) > > > > put :update, :id => @image.id, :category_id => > > @category.id, :image => {:name => 'test', :image_number => 13554} > > > > This way you're not reaching into the model to check your controller. > > You can even go as far as removing all of that ActiveRecord > interaction from your controller. > > @image = mock("image") > Image.should_receive(:update_image).with(@image) > put :update, :id => 1, :category_id => 2, :image => @image > > You would also want to test a failure case I'm sure (if you redirected...): > > Image.stub!(:update_image).and_raise(ActiveRecord::ActiveRecordError) > put :update, :id => 1, :category_id => 2, :image => @image > response.should be_redirect > response.should redirect_to(:action => "other_action") > > This keeps your controller a little cleaner and pushes down the > interaction of working with ActiveRecord models to a minimum. Now you > can put the code that actually handles an update in your model class > and your controller doesn't have to worry about how it is saved, it > either works or raises an exception, If you are only using Category in the test then go with Daniel's first suggestion. If you only need a numeric id which represents a Category don't create a dummy mock that will only be used in your test. If your controller has to find a Category and an Image to update an image in your controller then I think my approach (minus the exception, use true/false return values instead on update_image) makes sense. Zach From pergesu at gmail.com Thu Aug 23 23:00:01 2007 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 23 Aug 2007 20:00:01 -0700 Subject: [rspec-users] Keeping unit tests from hitting the DB In-Reply-To: <46CE37C2.2060707@benmabey.com> References: <992B8A68-0B0B-4440-8A9D-9C5E2B492A6D@railsnewbie.com> <46CDB8D3.2030906@benmabey.com> <57c63afe0708231443g2bdba02fsed2ed82d609edb43@mail.gmail.com> <46CE37C2.2060707@benmabey.com> Message-ID: <810a540e0708232000wad14492q2c1c8cfb33d5208c@mail.gmail.com> On 8/23/07, Ben Mabey wrote: > David Chelimsky wrote: > > On 8/23/07, Ben Mabey wrote: > > > >> Hey all, > >> I think I saw a thread about this earlier (maybe it was on the devlopers > >> list) but I am wondering if anyone has stubbed out AR so that the unit > >> test do not hit the database. The reason I am curious is because there > >> was a lightning talk given at the Ruby Hoedown (watch it here: > >> http://rubyhoedown2007.confreaks.com/session06.html) about separating > >> unit tests from the DB entirely and making it a lot faster. I'm not > >> just talking about not using fixtures but this would not even query the > >> DB for columns or do any inserts or updates either. Dan Manges was the > >> presenter and he talks about it on his blog and his newly released gem: > >> http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database > >> > >> I haven't experimented with the gem yet but I'm sure it could be changed > >> to work with rspec. I'm curious about people's opinions about this > >> practice and see if anyone has done something similar with rspec > >> already. > >> > > > > I've heard of ppl experimenting w/ this but haven't seen it in action. > > I would LOVE to see this capability but I'd like to be able to control > > it from behaviour to behaviour. For example, I tend to mock all models > > in view, controller and helper specs, but not in model specs, where I > > tend to let them interact w/ the DB. I'm not recommending that > > approach over mocking models in model specs, just saying that it's my > > personal preference. There are very good arguments to do it > > differently. > > > > That said, I'd want to be able to do this in spec_helper.rb: > > > > Spec::Runner.configure do |config| > > config.deny_db_access :view, :controller, :helper > > end > > > > or _something_ like that. Then if a controller spec tries to hit the > > db you should get an error. > > > > Feel like contributing that? > > > > > So would the "config.deny_db_access :view, :controller, :helper" line just throw an exception upon any DB access thereby acting as an alert saying that your using the DB instead of mocking appropriately? Is that right? Or should that line automatically stub the AR methods like new, save, create, etc to prevent any DB activity but give the illusion of talking to the DB? The latter is is what I was thinking for the model specs, although the alert exception would also be a good idea- especially for the controllers, views, and helpers. I have yet to dive into the rspec internals but I would definitely like to contribute. Let me know if the alert idea is what you meant. Thanks, > Ben > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > It should, imo, throw an exception when the DB is touched. Jay Fields posted about something like this a while ago: http://blog.jayfields.com/2006/06/ruby-on-rails-unit-tests.html As far as model specs go...I've been toying with the idea of splitting up non-db-reliant behavior specs from the specs that do require the database. When you want to specify behavior you can just stub out the columns (because AR does try to hit the db to find the column info). Obviously for things where you need to hit the db, such as custom finders and such, you should use a real db. Kent Beck proposed writing a mock db interface that expects SQL queries but I thoroughly hate that idea. Pat From cwdinfo at gmail.com Thu Aug 23 23:13:08 2007 From: cwdinfo at gmail.com (s.ross) Date: Thu, 23 Aug 2007 20:13:08 -0700 Subject: [rspec-users] controller spec with model that validates_uniqueness In-Reply-To: <85d99afe0708231957u281ed4c8hdda46c6b7613355c@mail.gmail.com> References: <8379025F-5318-4BB1-B52A-DBE7AEA69688@gmail.com> <4b430c8f0708231711x26a5c04cof48129f0bb9a27b7@mail.gmail.com> <2fff50390708231853k77cc8ecfm826c97ace408ee7e@mail.gmail.com> <85d99afe0708231949x6246f9a6g3273307c723099e2@mail.gmail.com> <85d99afe0708231957u281ed4c8hdda46c6b7613355c@mail.gmail.com> Message-ID: <1ED42ADB-AEC8-42D7-A33B-DE18002717E4@gmail.com> I left out a key piece of my spec code in the original question: before(:each) do @category = mock_model(Category) Category.should_receive(:find).any_number_of_times.and_return (@category) @image = mock_model(Image) @image_category = mock_model(ImageCategory) end For this simple controller (and they are *all* supposed to be simple, right?), I think taking AR out completely might work. It's all working now... Thanks for all responses. BTW: Courtenay, great that you're using rSpec on the Caboose Sample App. On Aug 23, 2007, at 7:57 PM, Zach Dennis wrote: > Actually better then an exception > > On 8/23/07, Zach Dennis wrote: >> On 8/23/07, Daniel N wrote: >>> >>> >>> >>> On 8/24/07, Courtenay wrote: >>>> Does this work? >>>> >>>> Image.stub!(:validates_uniqueness_of).and_return(true) >>>> >>>> >>>> On 8/23/07, s.ross wrote: >>>>> I want to use mocks and stubs to test the controller, but am >>>>> having >>>>> trouble getting my validation not to trigger. Here's the code: >>>>> >>>>> # spec: >>>>> >>>>> Image.stub!(:find).and_return(@image) >>>>> @image.should_receive(:save!).once.with(:any_args) >>>>> put :update, :id => @image.id, :category_id => >>>>> @category.id, :image => {:name => 'test', :image_number => 13554} >>>>> >>>>> #model >>>>> >>>>> validates_presence_of :name >>>>> validates_uniqueness_of :name, :allow_nil => true >>>>> >>>>> # rspec output >>>>> >>>>> ActiveRecord::RecordInvalid in 'ImagesController should update a >>>>> database record when it receives a PUT' >>>>> Validation failed: Name has already been taken, Image number has >>>>> already been taken >>>>> >>>>> >>>>> It seems AR is not detecting that this is an edit/update that will >>>>> not cause a uniqueness conflict. I believe the code in the model >>>>> needs to remain in place because I don't want a user creating a >>>>> name >>>>> conflict by editing an existing name into one that already >>>>> exists in >>>>> the database. Any thoughts on how better to spec this? >>>>> >>>>> Thanks >>>>> _______________________________________________ >>> >>> Why use a real image at all? I usually use mock_model on these >>> and then >>> stub/mock the specific calls in the controller method. This way >>> your not >>> testing the model at all. Just the controller. Of course, they >>> can get >>> pretty complex with all the stubbing etc. >>> >>> Image.stub!(:find).and_return(@image) >>> @image.should_receive(:save!).once.with(:any_args) >>> put :update, :id => @image.id, :category_id => >>> @category.id, :image => {:name => 'test', :image_number => 13554} >>> >>> could become. >>> >>> @category = mock_model( Category, :id => 1 ) # Not sure where >>> this one is >>> used other than the call to put >>> @image = mock_model( Image, :id => 2 ) >>> @image.should_receive( :save! ).once.with( :any_args ).and_return >>> ( true ) >>> Image.stub!( :find ).and_return( @image ) >>> >>> put :update, :id => @image.id, :category_id => >>> @category.id, :image => {:name => 'test', :image_number => 13554} >>> >>> This way you're not reaching into the model to check your >>> controller. >> >> You can even go as far as removing all of that ActiveRecord >> interaction from your controller. >> >> @image = mock("image") >> Image.should_receive(:update_image).with(@image) >> put :update, :id => 1, :category_id => 2, :image => @image >> >> You would also want to test a failure case I'm sure (if you >> redirected...): >> >> Image.stub!(:update_image).and_raise >> (ActiveRecord::ActiveRecordError) >> put :update, :id => 1, :category_id => 2, :image => @image >> response.should be_redirect >> response.should redirect_to(:action => "other_action") >> >> This keeps your controller a little cleaner and pushes down the >> interaction of working with ActiveRecord models to a minimum. Now you >> can put the code that actually handles an update in your model class >> and your controller doesn't have to worry about how it is saved, it >> either works or raises an exception, > > If you are only using Category in the test then go with Daniel's first > suggestion. If you only need a numeric id which represents a Category > don't create a dummy mock that will only be used in your test. > > If your controller has to find a Category and an Image to update an > image in your controller then I think my approach (minus the > exception, use true/false return values instead on update_image) makes > sense. > > Zach > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From james.deville at gmail.com Fri Aug 24 00:33:42 2007 From: james.deville at gmail.com (Jim Deville) Date: Thu, 23 Aug 2007 21:33:42 -0700 Subject: [rspec-users] Keeping unit tests from hitting the DB In-Reply-To: <810a540e0708232000wad14492q2c1c8cfb33d5208c@mail.gmail.com> References: <992B8A68-0B0B-4440-8A9D-9C5E2B492A6D@railsnewbie.com> <46CDB8D3.2030906@benmabey.com> <57c63afe0708231443g2bdba02fsed2ed82d609edb43@mail.gmail.com> <46CE37C2.2060707@benmabey.com> <810a540e0708232000wad14492q2c1c8cfb33d5208c@mail.gmail.com> Message-ID: <0D56536A-1EF1-47D9-A9F8-90E9AFD29CEC@gmail.com> >>>> > As far as model specs go...I've been toying with the idea of splitting > up non-db-reliant behavior specs from the specs that do require the > database. When you want to specify behavior you can just stub out the > columns (because AR does try to hit the db to find the column info). > Obviously for things where you need to hit the db, such as custom > finders and such, you should use a real db. Kent Beck proposed > writing a mock db interface that expects SQL queries but I thoroughly > hate that idea. > I'm wondering why custom finders need to hit the database? Mocking out the columns method (as suggested by the articles) should work just as well for custom finders as it would for AR finders. Am I missing something? Jim > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Fri Aug 24 00:48:22 2007 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 23 Aug 2007 21:48:22 -0700 Subject: [rspec-users] Keeping unit tests from hitting the DB In-Reply-To: <0D56536A-1EF1-47D9-A9F8-90E9AFD29CEC@gmail.com> References: <992B8A68-0B0B-4440-8A9D-9C5E2B492A6D@railsnewbie.com> <46CDB8D3.2030906@benmabey.com> <57c63afe0708231443g2bdba02fsed2ed82d609edb43@mail.gmail.com> <46CE37C2.2060707@benmabey.com> <810a540e0708232000wad14492q2c1c8cfb33d5208c@mail.gmail.com> <0D56536A-1EF1-47D9-A9F8-90E9AFD29CEC@gmail.com> Message-ID: <810a540e0708232148t78f32a4ft210183af0b53031a@mail.gmail.com> On 8/23/07, Jim Deville wrote: > >>>> > > As far as model specs go...I've been toying with the idea of splitting > > up non-db-reliant behavior specs from the specs that do require the > > database. When you want to specify behavior you can just stub out the > > columns (because AR does try to hit the db to find the column info). > > Obviously for things where you need to hit the db, such as custom > > finders and such, you should use a real db. Kent Beck proposed > > writing a mock db interface that expects SQL queries but I thoroughly > > hate that idea. > > > > I'm wondering why custom finders need to hit the database? Mocking > out the columns method (as suggested by the articles) should work > just as well for custom finders as it would for AR finders. Am I > missing something? > > Jim If I've got something like def find_recent(limit = 5) find :all, :order => "created_at DESC", :limit => limit end I think it's better to just create 6 records and make sure it returns the proper 5. Then write another spec that only gets 3. I suppose you could use a mock db that ensures that the SQL is valid...but that seems brittle. Also at some point you have to ensure that the generated SQL actually works (by running it). Might as well do that in the spec itself. Also that's a better way because the behavior you want in this case is for it to find the proper records, not to generate some particular SQL string. Pat From justnothing at tiscali.co.uk Fri Aug 24 05:42:17 2007 From: justnothing at tiscali.co.uk (David Green) Date: Fri, 24 Aug 2007 02:42:17 -0700 (PDT) Subject: [rspec-users] testing behaviour or testing code? Message-ID: <12309322.post@talk.nabble.com> hypothetical question for all you BDD experts: I want to make sure that a :list action always returns widgets in alphabetical order. There's at least 2 ways of doing this: it "should fetch items in alphabetical order" do Widget.should_receive(:find).with(:order => "name ASC") get :list end it "should fetch items in alphabetical order" do [:red, :green, :blue].each {|x| Widget.create(:name => x) } get :list assigns[:widgets].first.name.should == 'blue' assigns[:widgets].last.name.should == 'red' end with the first method, I get to mock the important calls and stub the rest, but the example is very closely tied to the implementation. If I change from Widget.find to Widget.find_alphabetically then the example breaks (assuming find_alphabetically() doesn't use AR::Base.find) with the second method, I'm testing the behaviour more than how it's implemented. I don't care what the action does as long as it gives me an array of widgets sorted alphabetically, but I spend more time setting things up and worrying about model validations. In addition, the specs are tied to a db. so which is the better method, and is there another way i havn't considered that gives me the best of both worlds? -- View this message in context: http://www.nabble.com/testing-behaviour-or-testing-code--tf4322619.html#a12309322 Sent from the rspec-users mailing list archive at Nabble.com. From priit.tamboom at eesti.ee Fri Aug 24 05:57:26 2007 From: priit.tamboom at eesti.ee (Priit Tamboom) Date: Fri, 24 Aug 2007 17:57:26 +0800 Subject: [rspec-users] nuby: how spec redirect_to at ApplicationController In-Reply-To: <57c63afe0708151348j6dfa6cf6nb14ccf4d055d3d30@mail.gmail.com> References: <4b430c8f0708151330n54b669f5hbf547eeac0e1b84a@mail.gmail.com> <57c63afe0708151348j6dfa6cf6nb14ccf4d055d3d30@mail.gmail.com> Message-ID: On 8/16/07, David Chelimsky wrote: > > On 8/15/07, Courtenay wrote: > > On 8/15/07, Priit Tamboom wrote: > > > > describe ApplicationController do > > > it "method login_required should redirect to home path without > login" do > > > > heh. "it" is so out of place here :) > > I agree. The goal is to describe behaviours of objects, not methods. > So, I'd write: > > it "should redirect anonymous user to home path" > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Thanks for great answers! By the way, David, your blog post was good additional help about what to do with application methods: http://blog.davidchelimsky.net/articles/2007/06/03/oxymoron-testing-behaviour-of-abstractions I wonder how far you go just testing "concrete" controllers. For example, if I move login methods from application controller to module under lib directory then do you change your style (write separate spec for module) or just keep testing concrete controllers as usually you do. Oki, Priit -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070824/8f3dbf9f/attachment-0001.html From dchelimsky at gmail.com Fri Aug 24 09:59:25 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 24 Aug 2007 08:59:25 -0500 Subject: [rspec-users] testing behaviour or testing code? In-Reply-To: <12309322.post@talk.nabble.com> References: <12309322.post@talk.nabble.com> Message-ID: <57c63afe0708240659y1ea3668qc2065333f199a7bb@mail.gmail.com> On 8/24/07, David Green wrote: > > hypothetical question for all you BDD experts: > > I want to make sure that a :list action always returns widgets in > alphabetical order. There's at least 2 ways of doing this: > > it "should fetch items in alphabetical order" do > Widget.should_receive(:find).with(:order => "name ASC") > get :list > end > > it "should fetch items in alphabetical order" do > [:red, :green, :blue].each {|x| Widget.create(:name => x) } > get :list > assigns[:widgets].first.name.should == 'blue' > assigns[:widgets].last.name.should == 'red' > end > > with the first method, I get to mock the important calls and stub the rest, > but the example is very closely tied to the implementation. If I change from > Widget.find to Widget.find_alphabetically then the example breaks (assuming > find_alphabetically() doesn't use AR::Base.find) > > with the second method, I'm testing the behaviour more than how it's > implemented. I don't care what the action does as long as it gives me an > array of widgets sorted alphabetically, but I spend more time setting things > up and worrying about model validations. In addition, the specs are tied to > a db. > > so which is the better method, and is there another way i havn't considered > that gives me the best of both worlds? It depends on how high you have your magnifying glass set. Really! Here's how I'd get there: In an integration test, which I use as ... well ... integration tests (i.e. pretty close to end to end - just no browser, so the javascript can't get tested), I'd have something akin to the second example, except that the creates would be done through a controller. This would be in place before I ever started working on individual objects. Then I'd develop the view, followed by the controller, followed by the model. Typically, in my experience, that would result in something like (not executing these so please pardon any potential bugs): describe "/widgets/index" do it "should display a list of widgets" do assigns[:widgets] = [ mock_model(Widget, :name => 'foo'), mock_model(Widget, :name => 'bar') ] render '/widgets/index' response.should have_tag('ul') do with_tag('li', 'foo') with_tag('li', 'bar') end end end describe WidgetController, 'responding to GET /widgets' do it "should assign a list of widgets" do Widget.should_receive(:find_alphabetically).and_return(list = []) get :index assigns[:widgets].should == [] end end describe Widget, "class" do it "should provide a list of widgets sorted alphabetically" do Widget.should_receive(:find).with(:order => "name ASC") Widget.find_alphabetically end end You're correct that the refactoring requires you to change the object-level examples, and that is something that would be nice to avoid. But also keep in mind that in java and C# people refactor things like that all the time without batting an eye, because the tools make it a one-step activity. Refactoring is changing the design of your *system* without changing its behaviour. That doesn't really fly all the way down to the object level 100% of the time. WDYT? David > > -- > View this message in context: http://www.nabble.com/testing-behaviour-or-testing-code--tf4322619.html#a12309322 > 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 Fri Aug 24 10:05:46 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 24 Aug 2007 09:05:46 -0500 Subject: [rspec-users] nuby: how spec redirect_to at ApplicationController In-Reply-To: References: <4b430c8f0708151330n54b669f5hbf547eeac0e1b84a@mail.gmail.com> <57c63afe0708151348j6dfa6cf6nb14ccf4d055d3d30@mail.gmail.com> Message-ID: <57c63afe0708240705k6d47ea0akcdd16f94e041b2ad@mail.gmail.com> On 8/24/07, Priit Tamboom wrote: > On 8/16/07, David Chelimsky wrote: > > > > On 8/15/07, Courtenay wrote: > > > On 8/15/07, Priit Tamboom wrote: > > > > > > describe ApplicationController do > > > > it "method login_required should redirect to home path without > login" do > > > > > > heh. "it" is so out of place here :) > > > > I agree. The goal is to describe behaviours of objects, not methods. > > So, I'd write: > > > > it "should redirect anonymous user to home path" > > > > Cheers, > > David > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > Thanks for great answers! > > By the way, David, your blog post was good additional help about what to do > with application methods: > http://blog.davidchelimsky.net/articles/2007/06/03/oxymoron-testing-behaviour-of-abstractions > > I wonder how far you go just testing "concrete" controllers. For example, if > I move login methods from application controller to module under lib > directory then do you change your style (write separate spec for module) or > just keep testing concrete controllers as usually you do. Typically I'd only move something up to Application when I find that I need it in two controllers. But I start by implementing it (spec-first) in both. Then I've got duplicated specs and duplicated code. Then I'd extract a shared behaviour, followed by moving the method up to Application. Which extraction happens first is not important - what IS important is that they are separate activities and you don't start the second extraction until you have a green bar. Cheers, David > > Oki, > Priit > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Fri Aug 24 10:08:16 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 24 Aug 2007 10:08:16 -0400 Subject: [rspec-users] testing behaviour or testing code? In-Reply-To: <12309322.post@talk.nabble.com> References: <12309322.post@talk.nabble.com> Message-ID: <85d99afe0708240708j33187665o8cf6cdcf784c9f95@mail.gmail.com> On 8/24/07, David Green wrote: > > hypothetical question for all you BDD experts: > > I want to make sure that a :list action always returns widgets in > alphabetical order. There's at least 2 ways of doing this: > > > it "should fetch items in alphabetical order" do > Widget.should_receive(:find).with(:order => "name ASC") > get :list > end > > it "should fetch items in alphabetical order" do > [:red, :green, :blue].each {|x| Widget.create(:name => x) } > get :list > assigns[:widgets].first.name.should == 'blue' > assigns[:widgets].last.name.should == 'red' > end > > with the first method, I get to mock the important calls and stub the rest, > but the example is very closely tied to the implementation. If I change from > Widget.find to Widget.find_alphabetically then the example breaks (assuming > find_alphabetically() doesn't use AR::Base.find) > > with the second method, I'm testing the behaviour more than how it's > implemented. I don't care what the action does as long as it gives me an > array of widgets sorted alphabetically, but I spend more time setting things > up and worrying about model validations. In addition, the specs are tied to > a db. > > so which is the better method, and is there another way i havn't considered > that gives me the best of both worlds? In your controller have something like: @widgets = mock("widgets") Widget.should_receive(:find_alphabetically).and_return(@widgets) get :index You don't care in your controller test what actually gets returned, just that it's calling the right method on the model. Now in your "Widget" spec have one that looks like: describe Widget, "#find_alphabetically) do before do Widget.destroy_all # create some widgets for your test, say widgets C, A, B in that order @results = Widget.find_alphabetically end it "has widget A as the first widget" do # ... end it "has widget B as the second widget" do # ... end it "has widget C as the third widget" do # ... end end HTH, Zach From zach.dennis at gmail.com Fri Aug 24 10:53:17 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 24 Aug 2007 10:53:17 -0400 Subject: [rspec-users] undefined method `mock_model' for [RSpec example]:# In-Reply-To: <57c63afe0708201901v7783b514wa2dbca82c2a841d8@mail.gmail.com> References: <85d99afe0708160717w33a9ee7eybe57a55fcbd72455@mail.gmail.com> <57c63afe0708190938u5e59f32fyb611e46bb7da49d4@mail.gmail.com> <46C98075.5090807@jay.fm> <8d961d900708200520p38970129yb1c9571b2a67685@mail.gmail.com> <46C99953.50800@jay.fm> <57c63afe0708200647i7d64379j1bd21630b2905d21@mail.gmail.com> <85d99afe0708201625o404109c3v87f85e08ef6dd22c@mail.gmail.com> <8d961d900708201719l5bf4c926m4b6588ccedb60315@mail.gmail.com> <85d99afe0708201855n2773ebb4t47924437ac31c15@mail.gmail.com> <57c63afe0708201901v7783b514wa2dbca82c2a841d8@mail.gmail.com> Message-ID: <85d99afe0708240753le65ae1em84d3f8d10e3e81e2@mail.gmail.com> On 8/20/07, David Chelimsky wrote: > On 8/20/07, Zach Dennis wrote: > > On 8/20/07, aslak hellesoy wrote: > > > Several problems here: > > > > > > First, rspec_scaffold must be given a *singularised* name, in your > > > case 'product'. (This is Rails being finicky, not RSpec). > > > > ok > > > > > Second, after running rspec_scaffold you must run rake db:migrate > > > > This I didn't do, but doing this makes no difference on the mock model > > error. This does fix the issue if I run the spec from RAILS_ROOT, but > > not if I run the spec from within the spec/views/products directory. > > Ah - now THAT makes sense. This won't work on any system at all. RSpec > looks for /spec/views/ in the path to know that it's a view spec. If > you're in the view spec directory, it doesn't get the information it > needs. Make sense? > > > > Third, before you can run specs with ruby or spec, you must create the > > > test database. This can be done with rake spec or rake db:test:prepare > > > > The database was already in existence, so I left that part omitted in the video > > > > If I run specs from RAILS_ROOT then everything works, but not if I'm > > not in RAILS_ROOT. This is less of an issue I originally thought, but > > the directory thing is a minor irritation, although I can make sure to > > run specs from the RAILS_ROOT. > > We'd have to change how rspec figures out what behaviour_type to use > to reduce the irritation. Any suggestions? Use expand_path on the current file and see if it is in RAILS_ROOT/specs/views ? Zach From james.deville at gmail.com Fri Aug 24 12:48:25 2007 From: james.deville at gmail.com (Jim Deville) Date: Fri, 24 Aug 2007 09:48:25 -0700 Subject: [rspec-users] Keeping unit tests from hitting the DB In-Reply-To: <810a540e0708232148t78f32a4ft210183af0b53031a@mail.gmail.com> References: <992B8A68-0B0B-4440-8A9D-9C5E2B492A6D@railsnewbie.com> <46CDB8D3.2030906@benmabey.com> <57c63afe0708231443g2bdba02fsed2ed82d609edb43@mail.gmail.com> <46CE37C2.2060707@benmabey.com> <810a540e0708232000wad14492q2c1c8cfb33d5208c@mail.gmail.com> <0D56536A-1EF1-47D9-A9F8-90E9AFD29CEC@gmail.com> <810a540e0708232148t78f32a4ft210183af0b53031a@mail.gmail.com> Message-ID: <41FEBADC-416E-4B96-9FD2-3EBDB28D4C67@gmail.com> On Aug 23, 2007, at 9:48 PM, Pat Maddox wrote: > On 8/23/07, Jim Deville wrote: >>>>>> >>> As far as model specs go...I've been toying with the idea of >>> splitting >>> up non-db-reliant behavior specs from the specs that do require the >>> database. When you want to specify behavior you can just stub >>> out the >>> columns (because AR does try to hit the db to find the column info). >>> Obviously for things where you need to hit the db, such as custom >>> finders and such, you should use a real db. Kent Beck proposed >>> writing a mock db interface that expects SQL queries but I >>> thoroughly >>> hate that idea. >>> >> >> I'm wondering why custom finders need to hit the database? Mocking >> out the columns method (as suggested by the articles) should work >> just as well for custom finders as it would for AR finders. Am I >> missing something? >> >> Jim > > If I've got something like > > def find_recent(limit = 5) > find :all, :order => "created_at DESC", :limit => limit > end > > I think it's better to just create 6 records and make sure it returns > the proper 5. Then write another spec that only gets 3. > I understand this, but overriding the Columns method, as suggested by Fields and Manges, should take care of this without hitting the DB. It's not checking the validity of the SQL, its using the columns method to return your result from fixtures without hitting the DB. > I suppose you could use a mock db that ensures that the SQL is > valid...but that seems brittle. Also at some point you have to ensure > that the generated SQL actually works (by running it). Might as well > do that in the spec itself. Also that's a better way because the Agreed, in some cases. In this case, testing the proper SQL feels like testing AR's implementation. If this was a find_by_sql method, I would completely agree with you here. > behavior you want in this case is for it to find the proper records, > not to generate some particular SQL string. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Jim From dchelimsky at gmail.com Fri Aug 24 12:58:36 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 24 Aug 2007 11:58:36 -0500 Subject: [rspec-users] Keeping unit tests from hitting the DB In-Reply-To: <41FEBADC-416E-4B96-9FD2-3EBDB28D4C67@gmail.com> References: <992B8A68-0B0B-4440-8A9D-9C5E2B492A6D@railsnewbie.com> <46CDB8D3.2030906@benmabey.com> <57c63afe0708231443g2bdba02fsed2ed82d609edb43@mail.gmail.com> <46CE37C2.2060707@benmabey.com> <810a540e0708232000wad14492q2c1c8cfb33d5208c@mail.gmail.com> <0D56536A-1EF1-47D9-A9F8-90E9AFD29CEC@gmail.com> <810a540e0708232148t78f32a4ft210183af0b53031a@mail.gmail.com> <41FEBADC-416E-4B96-9FD2-3EBDB28D4C67@gmail.com> Message-ID: <57c63afe0708240958s734b8f37xb916d332909568db@mail.gmail.com> On 8/24/07, Jim Deville wrote: > > On Aug 23, 2007, at 9:48 PM, Pat Maddox wrote: > > > On 8/23/07, Jim Deville wrote: > >>>>>> > >>> As far as model specs go...I've been toying with the idea of > >>> splitting > >>> up non-db-reliant behavior specs from the specs that do require the > >>> database. When you want to specify behavior you can just stub > >>> out the > >>> columns (because AR does try to hit the db to find the column info). > >>> Obviously for things where you need to hit the db, such as custom > >>> finders and such, you should use a real db. Kent Beck proposed > >>> writing a mock db interface that expects SQL queries but I > >>> thoroughly > >>> hate that idea. > >>> > >> > >> I'm wondering why custom finders need to hit the database? Mocking > >> out the columns method (as suggested by the articles) should work > >> just as well for custom finders as it would for AR finders. Am I > >> missing something? > >> > >> Jim > > > > If I've got something like > > > > def find_recent(limit = 5) > > find :all, :order => "created_at DESC", :limit => limit > > end > > > > I think it's better to just create 6 records and make sure it returns > > the proper 5. Then write another spec that only gets 3. > > > > I understand this, but overriding the Columns method, as suggested by > Fields and Manges, should take care of this without hitting the DB. > It's not checking the validity of the SQL, its using the columns > method to return your result from fixtures without hitting the DB. > > > > I suppose you could use a mock db that ensures that the SQL is > > valid...but that seems brittle. Also at some point you have to ensure > > that the generated SQL actually works (by running it). Might as well > > do that in the spec itself. Also that's a better way because the > > Agreed, in some cases. In this case, testing the proper SQL feels > like testing AR's implementation. If this was a find_by_sql method, I > would completely agree with you here. > > > behavior you want in this case is for it to find the proper records, > > not to generate some particular SQL string. Well - there are two schools of thought on this. At a system test level, there is no argument. However, at the object level, since this object is interacting with the database, that's its behaviour. If you accept that, then generating the correct SQL string is no different than any other mock expectation. FYI - I tried using the unit_record gem and there are some changes required in rspec to make it work, but they are trivial and it works great. The only trick is that the prevention of DB access is global per process, so you'd have to separate examples that hit the DB from those that don't into two separate suites. I'll explore this possibility and follow up. Cheers, David > > > > Pat > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > Jim > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Fri Aug 24 13:06:11 2007 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 24 Aug 2007 10:06:11 -0700 Subject: [rspec-users] testing behaviour or testing code? In-Reply-To: <57c63afe0708240659y1ea3668qc2065333f199a7bb@mail.gmail.com> References: <12309322.post@talk.nabble.com> <57c63afe0708240659y1ea3668qc2065333f199a7bb@mail.gmail.com> Message-ID: <810a540e0708241006m23118ed7k9248705c13c2678a@mail.gmail.com> On 8/24/07, David Chelimsky wrote: > describe Widget, "class" do > it "should provide a list of widgets sorted alphabetically" do > Widget.should_receive(:find).with(:order => "name ASC") > Widget.find_alphabetically > end > end > > You're correct that the refactoring requires you to change the > object-level examples, and that is something that would be nice to > avoid. But also keep in mind that in java and C# people refactor > things like that all the time without batting an eye, because the > tools make it a one-step activity. Refactoring is changing the design > of your *system* without changing its behaviour. That doesn't really > fly all the way down to the object level 100% of the time. > > WDYT? I think that example is fine up until the model spec. The find_alphabetically example should hit the db, imo. With the current spec there's no way to know whether find_alphabetically actually works or not. You're relying on knowledge of ActiveRecord here, trusting that the arguments to find are correct. What I've found when I write specs is that I discover new layers of services until eventually I get to a layer that actually does something. When I get there, it's important to have specs that describe what it does, not how it does it. In the case of find_alphabetically we care that it returns the items in alphabetical order. Not that it makes a certain call to the db. Pat From pergesu at gmail.com Fri Aug 24 13:11:01 2007 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 24 Aug 2007 10:11:01 -0700 Subject: [rspec-users] Keeping unit tests from hitting the DB In-Reply-To: <41FEBADC-416E-4B96-9FD2-3EBDB28D4C67@gmail.com> References: <992B8A68-0B0B-4440-8A9D-9C5E2B492A6D@railsnewbie.com> <46CDB8D3.2030906@benmabey.com> <57c63afe0708231443g2bdba02fsed2ed82d609edb43@mail.gmail.com> <46CE37C2.2060707@benmabey.com> <810a540e0708232000wad14492q2c1c8cfb33d5208c@mail.gmail.com> <0D56536A-1EF1-47D9-A9F8-90E9AFD29CEC@gmail.com> <810a540e0708232148t78f32a4ft210183af0b53031a@mail.gmail.com> <41FEBADC-416E-4B96-9FD2-3EBDB28D4C67@gmail.com> Message-ID: <810a540e0708241011m9c47680o32a5f86e7ac0d2@mail.gmail.com> On 8/24/07, Jim Deville wrote: > > On Aug 23, 2007, at 9:48 PM, Pat Maddox wrote: > > > On 8/23/07, Jim Deville wrote: > >>>>>> > >>> As far as model specs go...I've been toying with the idea of > >>> splitting > >>> up non-db-reliant behavior specs from the specs that do require the > >>> database. When you want to specify behavior you can just stub > >>> out the > >>> columns (because AR does try to hit the db to find the column info). > >>> Obviously for things where you need to hit the db, such as custom > >>> finders and such, you should use a real db. Kent Beck proposed > >>> writing a mock db interface that expects SQL queries but I > >>> thoroughly > >>> hate that idea. > >>> > >> > >> I'm wondering why custom finders need to hit the database? Mocking > >> out the columns method (as suggested by the articles) should work > >> just as well for custom finders as it would for AR finders. Am I > >> missing something? > >> > >> Jim > > > > If I've got something like > > > > def find_recent(limit = 5) > > find :all, :order => "created_at DESC", :limit => limit > > end > > > > I think it's better to just create 6 records and make sure it returns > > the proper 5. Then write another spec that only gets 3. > > > > I understand this, but overriding the Columns method, as suggested by > Fields and Manges, should take care of this without hitting the DB. > It's not checking the validity of the SQL, its using the columns > method to return your result from fixtures without hitting the DB. I don't follow. How does it (and I'm not sure what it is, tbh) know how to return the proper fixtures in the proper order? You need an SQL engine to make it happen. Pat From dchelimsky at gmail.com Fri Aug 24 13:12:51 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 24 Aug 2007 12:12:51 -0500 Subject: [rspec-users] testing behaviour or testing code? In-Reply-To: <810a540e0708241006m23118ed7k9248705c13c2678a@mail.gmail.com> References: <12309322.post@talk.nabble.com> <57c63afe0708240659y1ea3668qc2065333f199a7bb@mail.gmail.com> <810a540e0708241006m23118ed7k9248705c13c2678a@mail.gmail.com> Message-ID: <57c63afe0708241012o6c5bf76bib536656bf69ee323@mail.gmail.com> On 8/24/07, Pat Maddox wrote: > On 8/24/07, David Chelimsky wrote: > > describe Widget, "class" do > > it "should provide a list of widgets sorted alphabetically" do > > Widget.should_receive(:find).with(:order => "name ASC") > > Widget.find_alphabetically > > end > > end > > > > You're correct that the refactoring requires you to change the > > object-level examples, and that is something that would be nice to > > avoid. But also keep in mind that in java and C# people refactor > > things like that all the time without batting an eye, because the > > tools make it a one-step activity. Refactoring is changing the design > > of your *system* without changing its behaviour. That doesn't really > > fly all the way down to the object level 100% of the time. > > > > WDYT? > > I think that example is fine up until the model spec. The > find_alphabetically example should hit the db, imo. With the current > spec there's no way to know whether find_alphabetically actually works > or not. You're relying on knowledge of ActiveRecord here, trusting > that the arguments to find are correct. Au contrare! This all starts with an Integration Test. I didn't post the code but I did mention it. > What I've found when I write specs is that I discover new layers of > services until eventually I get to a layer that actually does > something. When I get there, it's important to have specs that > describe what it does, not how it does it. In the case of > find_alphabetically we care that it returns the items in alphabetical > order. Not that it makes a certain call to the db. I play this both ways and haven't come to a preference, but I'm leaning towards blocking database access from the rspec examples and only allowing it my end to end tests (using Rails Integration Tests or - soon - RSpec's new Story Runner). > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Fri Aug 24 14:20:15 2007 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 24 Aug 2007 11:20:15 -0700 Subject: [rspec-users] testing behaviour or testing code? In-Reply-To: <57c63afe0708241012o6c5bf76bib536656bf69ee323@mail.gmail.com> References: <12309322.post@talk.nabble.com> <57c63afe0708240659y1ea3668qc2065333f199a7bb@mail.gmail.com> <810a540e0708241006m23118ed7k9248705c13c2678a@mail.gmail.com> <57c63afe0708241012o6c5bf76bib536656bf69ee323@mail.gmail.com> Message-ID: <810a540e0708241120k76d896a5k350503f80ac42414@mail.gmail.com> On 8/24/07, David Chelimsky wrote: > On 8/24/07, Pat Maddox wrote: > > On 8/24/07, David Chelimsky wrote: > > > describe Widget, "class" do > > > it "should provide a list of widgets sorted alphabetically" do > > > Widget.should_receive(:find).with(:order => "name ASC") > > > Widget.find_alphabetically > > > end > > > end > > > > > > You're correct that the refactoring requires you to change the > > > object-level examples, and that is something that would be nice to > > > avoid. But also keep in mind that in java and C# people refactor > > > things like that all the time without batting an eye, because the > > > tools make it a one-step activity. Refactoring is changing the design > > > of your *system* without changing its behaviour. That doesn't really > > > fly all the way down to the object level 100% of the time. > > > > > > WDYT? > > > > I think that example is fine up until the model spec. The > > find_alphabetically example should hit the db, imo. With the current > > spec there's no way to know whether find_alphabetically actually works > > or not. You're relying on knowledge of ActiveRecord here, trusting > > that the arguments to find are correct. > > Au contrare! This all starts with an Integration Test. I didn't post > the code but I did mention it. You're absolutely right, there should be an integration or acceptance test that exercises the behavior. I would question then whether or not the example for find_alphabetically is (a) pulling its weight or (b) too brittle. (a) What value does the example provide? It doesn't serve to document how find_alphabetically is used (usage doco is provided by good naming, and secondarily by the controller specs). It doesn't give you any information that you couldn't get by looking at the implementation, because it duplicates the implementation exactly. So the only real benefits of it is that you can see it when you visually scan the specs, and it shows up in the output when you generate spec docs. Those are real benefits, of course, which leads me to believe that the spec is just a bit brittle. Knowing what exact arguments are passed to Widget.find doesn't add any value. It makes the test more cluttered and brittle. All we really care about is that a find is performed. In that case, perhaps the example should be simply it "should provide a list of widgets sorted alphabetically" do Widget.should_receive(:find) Widget.find_alphabetically end WDYT? > I play this both ways and haven't come to a preference, but I'm > leaning towards blocking database access from the rspec examples and > only allowing it my end to end tests (using Rails Integration Tests or > - soon - RSpec's new Story Runner). Will Story Runner give us all the same abilities as Rails ITs, obviating the need for test::unit altogether? Pat From dchelimsky at gmail.com Fri Aug 24 17:00:06 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 24 Aug 2007 16:00:06 -0500 Subject: [rspec-users] testing behaviour or testing code? In-Reply-To: <810a540e0708241120k76d896a5k350503f80ac42414@mail.gmail.com> References: <12309322.post@talk.nabble.com> <57c63afe0708240659y1ea3668qc2065333f199a7bb@mail.gmail.com> <810a540e0708241006m23118ed7k9248705c13c2678a@mail.gmail.com> <57c63afe0708241012o6c5bf76bib536656bf69ee323@mail.gmail.com> <810a540e0708241120k76d896a5k350503f80ac42414@mail.gmail.com> Message-ID: <57c63afe0708241400k4a12413v70a230fd349b7a8f@mail.gmail.com> On 8/24/07, Pat Maddox wrote: > On 8/24/07, David Chelimsky wrote: > > On 8/24/07, Pat Maddox wrote: > > > On 8/24/07, David Chelimsky wrote: > > > > describe Widget, "class" do > > > > it "should provide a list of widgets sorted alphabetically" do > > > > Widget.should_receive(:find).with(:order => "name ASC") > > > > Widget.find_alphabetically > > > > end > > > > end > > > > > > > > You're correct that the refactoring requires you to change the > > > > object-level examples, and that is something that would be nice to > > > > avoid. But also keep in mind that in java and C# people refactor > > > > things like that all the time without batting an eye, because the > > > > tools make it a one-step activity. Refactoring is changing the design > > > > of your *system* without changing its behaviour. That doesn't really > > > > fly all the way down to the object level 100% of the time. > > > > > > > > WDYT? > > > > > > I think that example is fine up until the model spec. The > > > find_alphabetically example should hit the db, imo. With the current > > > spec there's no way to know whether find_alphabetically actually works > > > or not. You're relying on knowledge of ActiveRecord here, trusting > > > that the arguments to find are correct. > > > > Au contrare! This all starts with an Integration Test. I didn't post > > the code but I did mention it. > > You're absolutely right, there should be an integration or acceptance > test that exercises the behavior. I would question then whether or > not the example for find_alphabetically is (a) pulling its weight or > (b) too brittle. > > (a) What value does the example provide? It doesn't serve to document > how find_alphabetically is used (usage doco is provided by good > naming, and secondarily by the controller specs). It doesn't give you > any information that you couldn't get by looking at the > implementation, because it duplicates the implementation exactly. So > the only real benefits of it is that you can see it when you visually > scan the specs, and it shows up in the output when you generate spec > docs. > > Those are real benefits, of course, which leads me to believe that the > spec is just a bit brittle. Knowing what exact arguments are passed > to Widget.find doesn't add any value. It makes the test more > cluttered and brittle. All we really care about is that a find is > performed. In that case, perhaps the example should be simply > > it "should provide a list of widgets sorted alphabetically" do > Widget.should_receive(:find) > Widget.find_alphabetically > end > > WDYT? The problem w/ that, for me, is that if I change that method for any reason I won't know if I broke anything until I run the integration tests. I'll trade off a bit of brittleness for rapid feedback. Not always - but usually. > > > I play this both ways and haven't come to a preference, but I'm > > leaning towards blocking database access from the rspec examples and > > only allowing it my end to end tests (using Rails Integration Tests or > > - soon - RSpec's new Story Runner). > > Will Story Runner give us all the same abilities as Rails ITs, > obviating the need for test::unit altogether? Yes. Just need to figure out how to wrap IT w/ Story Runner. Cheers, David > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From justnothing at tiscali.co.uk Sat Aug 25 03:01:11 2007 From: justnothing at tiscali.co.uk (David Green) Date: Sat, 25 Aug 2007 00:01:11 -0700 (PDT) Subject: [rspec-users] testing behaviour or testing code? In-Reply-To: <57c63afe0708240659y1ea3668qc2065333f199a7bb@mail.gmail.com> References: <12309322.post@talk.nabble.com> <57c63afe0708240659y1ea3668qc2065333f199a7bb@mail.gmail.com> Message-ID: <12323713.post@talk.nabble.com> David Chelimsky-2 wrote: > > > It depends on how high you have your magnifying glass set. Really! > > Here's how I'd get there: > > In an integration test, which I use as ... well ... integration tests > (i.e. pretty close to end to end - just no browser, so the javascript > can't get tested), I'd have something akin to the second example, > except that the creates would be done through a controller. This would > be in place before I ever started working on individual objects. > > Then I'd develop the view, followed by the controller, followed by the > model. Typically, in my experience, that would result in something > like (not executing these so please pardon any potential bugs): > > describe "/widgets/index" do > it "should display a list of widgets" do > assigns[:widgets] = [ > mock_model(Widget, :name => 'foo'), > mock_model(Widget, :name => 'bar') > ] > render '/widgets/index' > response.should have_tag('ul') do > with_tag('li', 'foo') > with_tag('li', 'bar') > end > end > end > > describe WidgetController, 'responding to GET /widgets' do > it "should assign a list of widgets" do > Widget.should_receive(:find_alphabetically).and_return(list = []) > get :index > assigns[:widgets].should == [] > end > end > > describe Widget, "class" do > it "should provide a list of widgets sorted alphabetically" do > Widget.should_receive(:find).with(:order => "name ASC") > Widget.find_alphabetically > end > end > > You're correct that the refactoring requires you to change the > object-level examples, and that is something that would be nice to > avoid. But also keep in mind that in java and C# people refactor > things like that all the time without batting an eye, because the > tools make it a one-step activity. Refactoring is changing the design > of your *system* without changing its behaviour. That doesn't really > fly all the way down to the object level 100% of the time. > > WDYT? > > David > after reading your post yesterday, I dug out some old specs that were doing some really complex setup using real objects, and rewrote them to exclusively use mocks and stubs. The specs run around 20% quicker, but more importantly, the code is much less complex and much easier to work with! it's a relief not having to worry about model behaviour in controller specs. so much so that I ended up adding around 50% more examples and catching some bugs which I'd missed. I wasn't testing my views at all, instead relying on integrate_views to catch any problems. This time round I wrote view specs, which is a little more work but testing only one MVC aspect in isolation really makes things simpler. I realise now that the old way, I was using controller specs to test integration rather than controllers. I'm relatively new to programming, and it's all self taught so I can't speak with authority, but the more I use BDD, the more I like it. It just makes sense. thanks for your help p.s. when is the book coming? :) -- View this message in context: http://www.nabble.com/testing-behaviour-or-testing-code--tf4322619.html#a12323713 Sent from the rspec-users mailing list archive at Nabble.com. From hans at degraaff.org Sat Aug 25 06:06:39 2007 From: hans at degraaff.org (Hans de Graaff) Date: Sat, 25 Aug 2007 10:06:39 +0000 Subject: [rspec-users] testing behaviour or testing code? In-Reply-To: <12323713.post@talk.nabble.com> References: <12309322.post@talk.nabble.com> <57c63afe0708240659y1ea3668qc2065333f199a7bb@mail.gmail.com> <12323713.post@talk.nabble.com> Message-ID: <1188036399.29465.13.camel@ip6-localhost> On Sat, 2007-08-25 at 00:01 -0700, David Green wrote: > I wasn't testing my views at all, instead relying on integrate_views to > catch any problems. This time round I wrote view specs, which is a little > more work but testing only one MVC aspect in isolation really makes things > simpler. I realise now that the old way, I was using controller specs to > test integration rather than controllers. I'm actually doing a bit of both. I write all my controller specs without integrate_views, with separate specs for the views. On top of that I'm also including very simple specs for each action in the controller including views and relying on fixtures, mostly like this: it 'should be a valid page' do get :index response.should be_xhtml end Even though all the behaviour is tested without views and fixtures, this additional check helps to find problems in the interaction between views, controller, and model, and it is the only way I know to validate the pages as XHTML. Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/rspec-users/attachments/20070825/d46a0002/attachment.bin From stefano.crocco at alice.it Sat Aug 25 09:50:19 2007 From: stefano.crocco at alice.it (Stefano Crocco) Date: Sat, 25 Aug 2007 15:50:19 +0200 Subject: [rspec-users] rspec hangs when used with QtRuby Message-ID: <200708251550.19451.stefano.crocco@alice.it> Hello to everyone I'm having trouble using RSpec to test code which uses QtRuby (both version 3 and 4). I noticed that, after upgrading from RSpec 1.0.5 to RSpec 1.0.8, some of my specs which used QtRuby caused spec (or rake, when used from a Rakefile) to hang indefinitly. After a bit of investigation, I found that the problem arose in the following situation: * requiring Qt4 / Qt3 * creating a stub which stubs a method called :type What I found particulary strange is that this happens even if I don't actually use Qt in the spec (directly or not). The following is the simplest example I could write which reproduces the problem: require 'Qt4' describe 'something' do it 'should work passing the :type parameter' do s = stub('x', :type => 'anything') end end If I remove the first line, spec exits correctly with the message "1 example, 0 failures". With the first line, instead, it hangs, and I have to press Ctrl+C to make it go on (of course, in this case it says: "1 example, 1 failure"). If I use another mock framework (I tried with flexmock), then everythings works. If I replace :type with anything else in the call to stub, then everything works. I tried searching google, this mailing list's archives and QtRuby forum, but I found nothing about this. Am I doing something wrong or is it a RSpec or QtRuby problem? I'm asking here because I think it's caused by RSpec (or by my wrong use of it), since it happened when I upgraded RSpec. If the issue is related more to QtRuby than to RSpec, please let me know and I'll ask in the QtRuby forum. Thanks in advance Stefano From mailing_lists at railsnewbie.com Sat Aug 25 16:17:13 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 25 Aug 2007 16:17:13 -0400 Subject: [rspec-users] rspec hangs when used with QtRuby In-Reply-To: <200708251550.19451.stefano.crocco@alice.it> References: <200708251550.19451.stefano.crocco@alice.it> Message-ID: On Aug 25, 2007, at 9:50 AM, Stefano Crocco wrote: > Hello to everyone > > I'm having trouble using RSpec to test code which uses QtRuby (both > version 3 > and 4). > > I noticed that, after upgrading from RSpec 1.0.5 to RSpec 1.0.8, > some of my > specs which used QtRuby caused spec (or rake, when used from a > Rakefile) to > hang indefinitly. After a bit of investigation, I found that the > problem > arose in the following situation: > > * requiring Qt4 / Qt3 > * creating a stub which stubs a method called :type > > What I found particulary strange is that this happens even if I > don't actually > use Qt in the spec (directly or not). The following is the simplest > example I > could write which reproduces the problem: > > require 'Qt4' > > describe 'something' do > > it 'should work passing the :type parameter' do > s = stub('x', :type => 'anything') > end > > end > > If I remove the first line, spec exits correctly with the message > "1 example, > 0 failures". With the first line, instead, it hangs, and I have to > press > Ctrl+C to make it go on (of course, in this case it says: "1 > example, 1 > failure"). If I use another mock framework (I tried with flexmock), > then > everythings works. If I replace :type with anything else in the > call to stub, > then everything works. I'm not sure which stubbing framework you are using when you aren't using flexmock, but I believe that if you are using RSpec's default mock/stubbing framework, the standard stubbing method is "stub!", not "stub", although this should still raise an error. I would suggest adding relevant version numbers (of Ruby, Qt, RSpec (gem or trunk), platform, OS), and submitting a bug report on Rubyforge's database if no one gets back to you on this one. Scott From priit.tamboom at eesti.ee Sun Aug 26 05:57:38 2007 From: priit.tamboom at eesti.ee (Priit Tamboom) Date: Sun, 26 Aug 2007 17:57:38 +0800 Subject: [rspec-users] ror app with advanced rspec? Message-ID: Hi! Can anybody link to some ror based project what is using rspec, so nuby as me can learn from it. So it should have updated and practising advanced rspec. After reading last threat about "testing behaviour or testing code?", I just realised that I would definitely learn something from app like that. Some casual googling didn't help me this time. Thanks! Priit at still.nuby.rspecter From michael.s.klishin.lists at gmail.com Sun Aug 26 06:24:38 2007 From: michael.s.klishin.lists at gmail.com (Michael Klishin) Date: Sun, 26 Aug 2007 14:24:38 +0400 Subject: [rspec-users] ror app with advanced rspec? In-Reply-To: References: Message-ID: <46D154E6.10606@gmail.com> RSpec itself is a nice example of pretty large open source project that uses RSpec for testing ;) It's a general problem in TDD/BDD worlds: what to test and how to keep it maintainable. I'd recommend reading mockobjects.com. Priit Tamboom wrote: > Hi! > > Can anybody link to some ror based project what is using rspec, so > nuby as me can learn from it. So it should have updated and practising > advanced rspec. -- MK From rupert_apsc at rupespad.com Sun Aug 26 09:22:39 2007 From: rupert_apsc at rupespad.com (rupert) Date: Sun, 26 Aug 2007 14:22:39 +0100 Subject: [rspec-users] ror app with advanced rspec? In-Reply-To: <46D154E6.10606@gmail.com> References: <46D154E6.10606@gmail.com> Message-ID: <0EA117C5-702D-41B2-940B-369FCA1ED871@rupespad.com> plus for a rails app that uses rspec, there's the caboose sample app: http://blog.caboo.se/pages/sample-rails-application On 26 Aug 2007, at 11:24, Michael Klishin wrote: > RSpec itself is a nice example of pretty large open source project > that > uses RSpec for testing ;) > > It's a general problem in TDD/BDD worlds: what to test and how to keep > it maintainable. I'd recommend reading mockobjects.com. > > Priit Tamboom wrote: >> Hi! >> >> Can anybody link to some ror based project what is using rspec, so >> nuby as me can learn from it. So it should have updated and >> practising >> advanced rspec. > > > -- > MK > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Sun Aug 26 18:43:14 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 26 Aug 2007 18:43:14 -0400 Subject: [rspec-users] howto regressions on environment.rb in Rails projects Message-ID: <8BD595A9-7EDF-44E2-946F-F91388A073D2@railsnewbie.com> How would one write a spec on environment.rb in a rails app? I was requiring a gem in environment.rb, but received a "MissingSourceError". Generally, ruby raises a LoadError when it can't find a gem, but rails overrides this to raise a MissingSourceError (since rails is expecting a required file to be in lib/...). How would I write a spec to override this behavior, such that a more friendly error message would be raised (such as: LoadError, "you must install the xyz gem!") ? Regards, Scott From michael.s.klishin.lists at gmail.com Sun Aug 26 19:22:22 2007 From: michael.s.klishin.lists at gmail.com (Michael Klishin) Date: Mon, 27 Aug 2007 03:22:22 +0400 Subject: [rspec-users] howto regressions on environment.rb in Rails projects In-Reply-To: <8BD595A9-7EDF-44E2-946F-F91388A073D2@railsnewbie.com> References: <8BD595A9-7EDF-44E2-946F-F91388A073D2@railsnewbie.com> Message-ID: <46D20B2E.1080709@gmail.com> Seems that the assertion itself is just obvious lambda { ... }.should_not raise_error ... But given the fact environment.rb is loaded well before examples are run, is it worth the effort it may take to spec out Rails bootstrap process? Sorry if I do not get your question. Scott Taylor wrote: > How would one write a spec on environment.rb in a rails app? > > I was requiring a gem in environment.rb, but received a > "MissingSourceError". Generally, ruby raises a LoadError when it > can't find a gem, but rails overrides this to raise a > MissingSourceError (since rails is expecting a required file to be in > lib/...). How would I write a spec to override this behavior, such > that a more friendly error message would be raised (such as: > LoadError, "you must install the xyz gem!") ? -- MK From mailing_lists at railsnewbie.com Sun Aug 26 19:29:33 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 26 Aug 2007 19:29:33 -0400 Subject: [rspec-users] howto regressions on environment.rb in Rails projects In-Reply-To: <46D20B2E.1080709@gmail.com> References: <8BD595A9-7EDF-44E2-946F-F91388A073D2@railsnewbie.com> <46D20B2E.1080709@gmail.com> Message-ID: <2F961EE0-1FEE-4D4E-B799-AFD4D87A2316@railsnewbie.com> On Aug 26, 2007, at 7:22 PM, Michael Klishin wrote: > Seems that the assertion itself is just obvious > > lambda { ... }.should_not raise_error ... > > But given the fact environment.rb is loaded well before examples are > run, is it worth the effort it may take to spec out Rails bootstrap > process? No, it probably isn't. I just like to do everything test-first : ) Scott From lists-rspec at shopwatch.org Sun Aug 26 21:51:27 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Sun, 26 Aug 2007 21:51:27 -0400 Subject: [rspec-users] Foreign key constraints, fixtures, and rake task Message-ID: <46D22E1F.1050508@jay.fm> I've got a spec that loads a fixture in the "before" block. This works fine running scripts/spec, but when I run rake spec instead, I get: ActiveRecord::StatementInvalid in 'User in fixture :quentin with an IM service but no IM name should be invalid' Mysql::Error: Cannot delete or update a parent row: a foreign key constraint fails (`mediajoint_development/accounts`, CONSTRAINT `accounts_opener_id_fk` FOREIGN KEY (`opener_id`) REFERENCES `users` (`id`)): DELETE FROM users /Users/jay/Documents/eclipse/mediajoint/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/model.rb:12:in `before_eval' I've even manually run the entire "ruby -I" command that rake generates, and it works fine. I can't see that the rake task's doing anything different other than db:test:prepare, which I can do manually with no problem. What's rake doing differently? Jay Levitt From ben at benmabey.com Sun Aug 26 23:25:57 2007 From: ben at benmabey.com (Ben Mabey) Date: Sun, 26 Aug 2007 21:25:57 -0600 Subject: [rspec-users] Testing c code with rspec? Message-ID: <46D24445.60106@benmabey.com> Hey all, Has any one ever tested or try to test c code with rspec? I am using system calls to my compiled c program and testing against the standard output but I would like to get a lot more granular than this. I have experimented with using RubyInline to test individual functions and that works on functions that are not calling other c functions. I have some other ideas on how to do this but they all seem around about ways... I have never used RubyInline before nor have I integrated c or c++ with Ruby before so I'm guessing there is a much better way to go about this. Any ideas/suggestions on how to best test c code with rSpec? Thanks, Ben From ben at benmabey.com Sun Aug 26 23:45:24 2007 From: ben at benmabey.com (Ben Mabey) Date: Sun, 26 Aug 2007 21:45:24 -0600 Subject: [rspec-users] Testing c code with rspec? In-Reply-To: <46D24445.60106@benmabey.com> References: <46D24445.60106@benmabey.com> Message-ID: <46D248D4.6090606@benmabey.com> Ben Mabey wrote: > Hey all, > Has any one ever tested or try to test c code with rspec? I am using > system calls to my compiled c program and testing against the standard > output but I would like to get a lot more granular than this. I have > experimented with using RubyInline to test individual functions and that > works on functions that are not calling other c functions. I have some > other ideas on how to do this but they all seem around about ways... I > have never used RubyInline before nor have I integrated c or c++ with > Ruby before so I'm guessing there is a much better way to go about > this. Any ideas/suggestions on how to best test c code with rSpec? > Thanks, > Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Hmm.. I'm looking into SWIG right now and it is looking promising.... From what I am reading it doesn't look like it would be too hard to test c with rspec via SWIG. I'd still be curious about any suggestions everyone else might have. Thanks, Ben From srbaker at pobox.com Mon Aug 27 00:00:33 2007 From: srbaker at pobox.com (Steven R. Baker) Date: Mon, 27 Aug 2007 00:00:33 -0400 Subject: [rspec-users] Testing c code with rspec? In-Reply-To: <46D24445.60106@benmabey.com> References: <46D24445.60106@benmabey.com> Message-ID: <46D24C61.6070006@pobox.com> Ben Mabey wrote: > Hey all, > Has any one ever tested or try to test c code with rspec? I am using > system calls to my compiled c program and testing against the standard > output but I would like to get a lot more granular than this. I have > I've specified Ruby C extensions using RSpec, but not just regular C applications. My suggestion is to write Ruby C wrappers, if you *really* want to use RSpec to specify your C. I might be interested in helping you with this if you want to hit me via email off-list. -Steven From win at wincent.com Mon Aug 27 03:34:37 2007 From: win at wincent.com (Wincent Colaiuta) Date: Mon, 27 Aug 2007 09:34:37 +0200 Subject: [rspec-users] Testing c code with rspec? In-Reply-To: <46D24C61.6070006@pobox.com> References: <46D24445.60106@benmabey.com> <46D24C61.6070006@pobox.com> Message-ID: <294282D6-EF8D-4A4D-8EF3-C205EE759E78@wincent.com> El 27/8/2007, a las 6:00, Steven R. Baker escribi?: > Ben Mabey wrote: >> Hey all, >> Has any one ever tested or try to test c code with rspec? I am using >> system calls to my compiled c program and testing against the >> standard >> output but I would like to get a lot more granular than this. I have >> > I've specified Ruby C extensions using RSpec, but not just regular C > applications. My suggestion is to write Ruby C wrappers, if you > *really* want to use RSpec to specify your C. That's what I've done in the past as well and have been very happy with the results. Cheers, Wincent From tils-rspec at tils.net Mon Aug 27 04:54:28 2007 From: tils-rspec at tils.net (Tilmann Singer) Date: Mon, 27 Aug 2007 10:54:28 +0200 Subject: [rspec-users] Foreign key constraints, fixtures, and rake task In-Reply-To: <46D22E1F.1050508@jay.fm> References: <46D22E1F.1050508@jay.fm> Message-ID: <20070827085428.GA32463@tils.net> * Jay Levitt [20070827 03:51]: > I've got a spec that loads a fixture in the "before" block. This works > fine running scripts/spec, but when I run rake spec instead, I get: > > ActiveRecord::StatementInvalid in 'User in fixture :quentin with an IM > service but no IM name should be invalid' > Mysql::Error: Cannot delete or update a parent row: a foreign key > constraint fails (`mediajoint_development/accounts`, CONSTRAINT > `accounts_opener_id_fk` FOREIGN KEY (`opener_id`) REFERENCES `users` > (`id`)): DELETE FROM users > /Users/jay/Documents/eclipse/mediajoint/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/model.rb:12:in > `before_eval' > > I've even manually run the entire "ruby -I" command that rake generates, > and it works fine. > > I can't see that the rake task's doing anything different other than > db:test:prepare, which I can do manually with no problem. > > What's rake doing differently? rake spec isn't doing anything fundamentally different, but the order the specs are run is propably randomly different from when you run them with spec so they happen to pass in one case and fail in the other. Using fixtures when there are foreign key constraints in the db can be a pain - if the speed is acceptable it's propably best to do fixtures :all whenever you need any of the fixtures, or leave the fixtures declaration out if a describe block doesn't need any. I guess the error you are seeing is because a fixtures declaration is encountered that references users fixtures, but not accounts. When preparing the fixtures for a describe block, ActiveRecord deletes all rows in all declared tables and then fills them with the fixtures data. In your case it wants to delete all from users but doesn't do anything with accounts where there are still rows from a spec that ran previously, and those rows reference users. You could also try to add :accounts to that particular failing spec to get rid of this one error. Til From lists-rspec at shopwatch.org Mon Aug 27 10:51:16 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Mon, 27 Aug 2007 10:51:16 -0400 Subject: [rspec-users] Foreign key constraints, fixtures, and rake task In-Reply-To: <20070827085428.GA32463@tils.net> References: <46D22E1F.1050508@jay.fm> <20070827085428.GA32463@tils.net> Message-ID: <46D2E4E4.2040709@jay.fm> Tilmann Singer wrote: > * Jay Levitt [20070827 03:51]: >> What's rake doing differently? > > rake spec isn't doing anything fundamentally different, but the order > the specs are run is propably randomly different from when you run > them with spec so they happen to pass in one case and fail in the > other. Nope, it's definitely not random - script/spec works every time, rake fails every time. I'm not actually using :accounts at all in my specs; it's only referenced in the database constraints. (It's tested in Test::Unit at the moment.) So the order wouldn't matter. I'm sure I can work around it by loading all the fixtures in some order that makes the database happy; I'm more curious as to why it happens with "rake spec", and not with (what seems to be) the equivalent script/spec command. Unfortunately, test.log doesn't show me anything that happens during the failed rake run. I'll have to see if there's a way to turn up logging on MySQL itself to see what's different, or maybe switch to a TCP socket and use Wireshark (nee Ethereal). Jay From dchelimsky at gmail.com Mon Aug 27 11:08:00 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 27 Aug 2007 10:08:00 -0500 Subject: [rspec-users] Foreign key constraints, fixtures, and rake task In-Reply-To: <46D2E4E4.2040709@jay.fm> References: <46D22E1F.1050508@jay.fm> <20070827085428.GA32463@tils.net> <46D2E4E4.2040709@jay.fm> Message-ID: <57c63afe0708270808p52e2574eq17dfd7f785dab88@mail.gmail.com> On 8/27/07, Jay Levitt wrote: > Tilmann Singer wrote: > > * Jay Levitt [20070827 03:51]: > >> What's rake doing differently? > > > > rake spec isn't doing anything fundamentally different, but the order > > the specs are run is propably randomly different from when you run > > them with spec so they happen to pass in one case and fail in the > > other. > > Nope, it's definitely not random - script/spec works every time, rake > fails every time. By default, the spec.opts file, which is loaded w/ the rake task, but not implicitly with the script/spec command, uses --reverse, so the files are run in reverse order. That would support Tilmann's theory combined with your observation that they consistently pass one way and fail the other. This information should shed some light on your questions below as well. Cheers, David > > I'm not actually using :accounts at all in my specs; it's only > referenced in the database constraints. (It's tested in Test::Unit at > the moment.) So the order wouldn't matter. > > I'm sure I can work around it by loading all the fixtures in some order > that makes the database happy; I'm more curious as to why it happens > with "rake spec", and not with (what seems to be) the equivalent > script/spec command. > > Unfortunately, test.log doesn't show me anything that happens during the > failed rake run. I'll have to see if there's a way to turn up logging > on MySQL itself to see what's different, or maybe switch to a TCP socket > and use Wireshark (nee Ethereal). > > Jay > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From james.deville at gmail.com Mon Aug 27 11:34:44 2007 From: james.deville at gmail.com (Jim Deville) Date: Mon, 27 Aug 2007 08:34:44 -0700 Subject: [rspec-users] Foreign key constraints, fixtures, and rake task In-Reply-To: <57c63afe0708270808p52e2574eq17dfd7f785dab88@mail.gmail.com> References: <46D22E1F.1050508@jay.fm> <20070827085428.GA32463@tils.net> <46D2E4E4.2040709@jay.fm> <57c63afe0708270808p52e2574eq17dfd7f785dab88@mail.gmail.com> Message-ID: On Aug 27, 2007, at 8:08 AM, David Chelimsky wrote: > On 8/27/07, Jay Levitt wrote: >> Tilmann Singer wrote: >>> * Jay Levitt [20070827 03:51]: >>>> What's rake doing differently? >>> >>> rake spec isn't doing anything fundamentally different, but the >>> order >>> the specs are run is propably randomly different from when you run >>> them with spec so they happen to pass in one case and fail in the >>> other. >> >> Nope, it's definitely not random - script/spec works every time, rake >> fails every time. > > By default, the spec.opts file, which is loaded w/ the rake task, but > not implicitly with the script/spec command, uses --reverse, so the > files are run in reverse order. That would support Tilmann's theory > combined with your observation that they consistently pass one way and > fail the other. > > This information should shed some light on your questions below as > well. > > Cheers, > David > Just wondering about your usage of constraints. We ran into this issue recently and came to the conclusion that unless profiling shows an issue, use AR to enforce referential integrity. You might be able to get by using :dependent => :destroy, or one of the other options. As for the indexing, you can set it up on your own using add_index in the migration. That helps save us the headaches of migrations and fixture issues. Just an idea. Jim >> >> I'm not actually using :accounts at all in my specs; it's only >> referenced in the database constraints. (It's tested in >> Test::Unit at >> the moment.) So the order wouldn't matter. >> >> I'm sure I can work around it by loading all the fixtures in some >> order >> that makes the database happy; I'm more curious as to why it happens >> with "rake spec", and not with (what seems to be) the equivalent >> script/spec command. >> >> Unfortunately, test.log doesn't show me anything that happens >> during the >> failed rake run. I'll have to see if there's a way to turn up >> logging >> on MySQL itself to see what's different, or maybe switch to a TCP >> socket >> and use Wireshark (nee Ethereal). >> >> Jay >> >> >> >> _______________________________________________ >> 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 ben at benmabey.com Mon Aug 27 11:56:03 2007 From: ben at benmabey.com (Ben Mabey) Date: Mon, 27 Aug 2007 09:56:03 -0600 Subject: [rspec-users] Foreign key constraints, fixtures, and rake task In-Reply-To: References: <46D22E1F.1050508@jay.fm> <20070827085428.GA32463@tils.net> <46D2E4E4.2040709@jay.fm> <57c63afe0708270808p52e2574eq17dfd7f785dab88@mail.gmail.com> Message-ID: <46D2F413.6010308@benmabey.com> As people have pointed out, using DB foreign key constraints within rails can be a nightmare when it comes to fixtures. In the past when I have used DB constraints I have always disabled the constraints when loading the fixtures so it wouldn't be an issue. The way I did it was the following: class Fixtures alias :original_delete_existing_fixtures :delete_existing_fixtures alias :original_insert_fixtures :insert_fixtures def delete_existing_fixtures @connection.update "SET FOREIGN_KEY_CHECKS = 0", 'Fixtures deactivate foreign key checks.'; original_delete_existing_fixtures @connection.update "SET FOREIGN_KEY_CHECKS = 1", 'Fixtures activate foreign key checks.'; end def insert_fixtures @connection.update "SET FOREIGN_KEY_CHECKS = 0", 'Fixtures deactivate foreign key checks.'; original_insert_fixtures @connection.update "SET FOREIGN_KEY_CHECKS = 1", 'Fixtures activate foreign key checks.'; end end Note, that this is MySQL specific and I would place this is my test_helper.rb (this was pre-rSpec.) I have not used this code with rpsec but since rspec uses rails Fixtures class (right?) you should be able to use this as well. -Ben Jim Deville wrote: > On Aug 27, 2007, at 8:08 AM, David Chelimsky wrote: > > >> On 8/27/07, Jay Levitt wrote: >> >>> Tilmann Singer wrote: >>> >>>> * Jay Levitt [20070827 03:51]: >>>> >>>>> What's rake doing differently? >>>>> >>>> rake spec isn't doing anything fundamentally different, but the >>>> order >>>> the specs are run is propably randomly different from when you run >>>> them with spec so they happen to pass in one case and fail in the >>>> other. >>>> >>> Nope, it's definitely not random - script/spec works every time, rake >>> fails every time. >>> >> By default, the spec.opts file, which is loaded w/ the rake task, but >> not implicitly with the script/spec command, uses --reverse, so the >> files are run in reverse order. That would support Tilmann's theory >> combined with your observation that they consistently pass one way and >> fail the other. >> >> This information should shed some light on your questions below as >> well. >> >> Cheers, >> David >> >> > > Just wondering about your usage of constraints. We ran into this > issue recently and came to the conclusion that unless profiling shows > an issue, use AR to enforce referential integrity. You might be able > to get by using :dependent => :destroy, or one of the other options. > As for the indexing, you can set it up on your own using add_index in > the migration. That helps save us the headaches of migrations and > fixture issues. > > Just an idea. > > Jim > > >>> I'm not actually using :accounts at all in my specs; it's only >>> referenced in the database constraints. (It's tested in >>> Test::Unit at >>> the moment.) So the order wouldn't matter. >>> >>> I'm sure I can work around it by loading all the fixtures in some >>> order >>> that makes the database happy; I'm more curious as to why it happens >>> with "rake spec", and not with (what seems to be) the equivalent >>> script/spec command. >>> >>> Unfortunately, test.log doesn't show me anything that happens >>> during the >>> failed rake run. I'll have to see if there's a way to turn up >>> logging >>> on MySQL itself to see what's different, or maybe switch to a TCP >>> socket >>> and use Wireshark (nee Ethereal). >>> >>> Jay >>> >>> >>> >>> _______________________________________________ >>> 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 lists-rspec at shopwatch.org Mon Aug 27 12:11:24 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Mon, 27 Aug 2007 12:11:24 -0400 Subject: [rspec-users] Foreign key constraints, fixtures, and rake task In-Reply-To: <57c63afe0708270808p52e2574eq17dfd7f785dab88@mail.gmail.com> References: <46D22E1F.1050508@jay.fm> <20070827085428.GA32463@tils.net> <46D2E4E4.2040709@jay.fm> <57c63afe0708270808p52e2574eq17dfd7f785dab88@mail.gmail.com> Message-ID: <46D2F7AC.7030209@jay.fm> David Chelimsky wrote: > On 8/27/07, Jay Levitt wrote: >> Tilmann Singer wrote: >>> * Jay Levitt [20070827 03:51]: >>>> What's rake doing differently? >>> rake spec isn't doing anything fundamentally different, but the order >>> the specs are run is propably randomly different from when you run >>> them with spec so they happen to pass in one case and fail in the >>> other. >> Nope, it's definitely not random - script/spec works every time, rake >> fails every time. > > By default, the spec.opts file, which is loaded w/ the rake task, but > not implicitly with the script/spec command, uses --reverse, so the > files are run in reverse order. That would support Tilmann's theory > combined with your observation that they consistently pass one way and > fail the other. Nope: # lib/tasks/jaytest.rake rspec_base = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec/lib') $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base) require 'spec/rake/spectask' require 'spec/translator' desc "Run my bad spec" Spec::Rake::SpecTask.new(:jaytest) do |t| t.spec_files = FileList['spec/models/jaytest_spec.rb'] end # spec/models/jaytest_spec.rb require File.dirname(__FILE__) + '/../spec_helper' describe User, "in fixture :quentin" do fixtures :users it "should" do @user = users(:quentin) end end # mysql>show create table accounts .. CONSTRAINT `accounts_opener_id_fk` FOREIGN KEY (`opener_id`) REFERENCES `users` (`id`) .. # 'rake jaytest' output F 1) ActiveRecord::StatementInvalid in 'User in fixture :quentin should' Mysql::Error: Cannot delete or update a parent row: a foreign key constraint fails (`mediajoint_development/accounts`, CONSTRAINT `accounts_opener_id_fk` FOREIGN KEY (`opener_id`) REFERENCES `users` (`id`)): DELETE FROM users /Users/jay/Documents/eclipse/mediajoint/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/model.rb:12:in `before_eval' Finished in 0.031189 seconds 1 example, 1 failure rake aborted! Command ruby -I"/Users/jay/Documents/eclipse/mediajoint/vendor/plugins/rspec/lib" "/Users/jay/Documents/eclipse/mediajoint/vendor/plugins/rspec/bin/spec" "spec/models/jaytest_spec.rb" failed # ruby -I"/Users/jay/Documents/eclipse/mediajoint/vendor/plugins/rspec/lib" "/Users/jay/Documents/eclipse/mediajoint/vendor/plugins/rspec/bin/spec" "spec/models/jaytest_spec.rb" output From papipo at gmail.com Mon Aug 27 13:54:03 2007 From: papipo at gmail.com (=?ISO-8859-1?Q?Rodrigo_Alvarez_Fern=E1ndez?=) Date: Mon, 27 Aug 2007 19:54:03 +0200 Subject: [rspec-users] Testing arbitrary SQL Message-ID: <6d2bdda0708271054o73971676s75dc2b96230a78d5@mail.gmail.com> Hi, I would like to know how would you test a method in a model that uses complex a SQL query that joins several tables in order to make a calculation. I suppose that I need fixtures, although my approach with rspec is to avoid fixtures and isolate model specs, but none of both seems possible in this case. Is there another way than fixtures? Thanks. From court3nay at gmail.com Mon Aug 27 14:48:23 2007 From: court3nay at gmail.com (Courtenay) Date: Mon, 27 Aug 2007 11:48:23 -0700 Subject: [rspec-users] Testing arbitrary SQL In-Reply-To: <6d2bdda0708271054o73971676s75dc2b96230a78d5@mail.gmail.com> References: <6d2bdda0708271054o73971676s75dc2b96230a78d5@mail.gmail.com> Message-ID: <4b430c8f0708271148g7bb53b79q3c90a11c2c99c9c1@mail.gmail.com> You create the records. @bah = Bah.create! [1, 5, 22, 16].each { |amount| Foo.create! :amount => amount, :bah => @bah } @bah.foos.should == 44 On 8/27/07, Rodrigo Alvarez Fern?ndez wrote: > Hi, > > I would like to know how would you test a method in a model that uses > complex a SQL query that joins several tables in order to make a > calculation. > > I suppose that I need fixtures, although my approach with rspec is to > avoid fixtures and isolate model specs, but none of both seems > possible in this case. Is there another way than fixtures? > > Thanks. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From papipo at gmail.com Mon Aug 27 15:34:56 2007 From: papipo at gmail.com (=?ISO-8859-1?Q?Rodrigo_Alvarez_Fern=E1ndez?=) Date: Mon, 27 Aug 2007 21:34:56 +0200 Subject: [rspec-users] Testing arbitrary SQL In-Reply-To: <4b430c8f0708271148g7bb53b79q3c90a11c2c99c9c1@mail.gmail.com> References: <6d2bdda0708271054o73971676s75dc2b96230a78d5@mail.gmail.com> <4b430c8f0708271148g7bb53b79q3c90a11c2c99c9c1@mail.gmail.com> Message-ID: <6d2bdda0708271234k1d538a9by54a464ec1c3444ce@mail.gmail.com> On 8/27/07, Courtenay wrote: > You create the records. I guess that I need to hit the database to really test if the method is working at all. In fact what I must test is the SQL query itself. Thanks. > > @bah = Bah.create! > [1, 5, 22, 16].each { |amount| Foo.create! :amount => amount, :bah => @bah } > > @bah.foos.should == 44 > > > On 8/27/07, Rodrigo Alvarez Fern?ndez wrote: > > Hi, > > > > I would like to know how would you test a method in a model that uses > > complex a SQL query that joins several tables in order to make a > > calculation. > > > > I suppose that I need fixtures, although my approach with rspec is to > > avoid fixtures and isolate model specs, but none of both seems > > possible in this case. Is there another way than fixtures? > > > > Thanks. > > _______________________________________________ > > 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 Mon Aug 27 15:45:11 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Mon, 27 Aug 2007 15:45:11 -0400 Subject: [rspec-users] Foreign key constraints, fixtures, and rake task In-Reply-To: References: <46D22E1F.1050508@jay.fm> <20070827085428.GA32463@tils.net> <46D2E4E4.2040709@jay.fm> <57c63afe0708270808p52e2574eq17dfd7f785dab88@mail.gmail.com> Message-ID: <46D329C7.1040201@jay.fm> Jim Deville wrote: >> > > Just wondering about your usage of constraints. We ran into this > issue recently and came to the conclusion that unless profiling shows > an issue, use AR to enforce referential integrity. You might be able > to get by using :dependent => :destroy, or one of the other options. > As for the indexing, you can set it up on your own using add_index in > the migration. That helps save us the headaches of migrations and > fixture issues. Just the usual debate of "single layer of cleverness" vs. "defense in depth" against bugs. It's not a performance thing; we're not at that level yet. Jay From jd at buttondowndesign.com Mon Aug 27 15:52:17 2007 From: jd at buttondowndesign.com (J.D. Hollis) Date: Mon, 27 Aug 2007 15:52:17 -0400 Subject: [rspec-users] issue with edge rails and urls Message-ID: <09AE7D5B-EEEF-4C4A-9706-AD582C9E9D9F@buttondowndesign.com> I just switched our project over to Edge Rails, and I'm running into this problem with all of my helper methods that call _url methods: NoMethodError in 'ApplicationHelper home_link should generate a valid home link when User.current and Profile.current is not set' You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.<< ./spec/helpers/application_helper_spec.rb:17 Here's the relevant spec: describe ApplicationHelper, "home_link" do before(:each) do User.current = nil Profile.current = nil end it "should generate a valid home link when User.current and Profile.current is not set" do home_link.should =~ /#{new_profile_url}/ end it "should generate a valid home link when User.current is set" do User.current = mock_model(User) home_link.should =~ /#{dashboard_url}/ end it "should generate a valid home link when Profile.current is set" do Profile.current = mock_model(Profile) home_link.should =~ /#{profile_url(Profile.current)}/ end end And the method in ApplicationHelper: def home_link if User.current.blank? if Profile.current.blank? link_to 'Get Started', new_profile_url else link_to 'My Profile', profile_url(Profile.current) end else link_to 'Dashboard', dashboard_url end end I'm using RSpec 1.0.8 and Rails revision 7360. Any ideas where to start looking for a fix or workaround? Regards, J.D. From lists-rspec at shopwatch.org Mon Aug 27 16:02:32 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Mon, 27 Aug 2007 16:02:32 -0400 Subject: [rspec-users] issue with edge rails and urls In-Reply-To: <09AE7D5B-EEEF-4C4A-9706-AD582C9E9D9F@buttondowndesign.com> References: <09AE7D5B-EEEF-4C4A-9706-AD582C9E9D9F@buttondowndesign.com> Message-ID: <46D32DD8.9050904@jay.fm> J.D. Hollis wrote: > I just switched our project over to Edge Rails, and I'm running into > this problem with all of my helper methods that call _url methods: Check out the patch at: http://rubyforge.org/tracker/index.php?func=detail&aid=13186&group_id=797&atid=3151 Jay From james.deville at gmail.com Mon Aug 27 19:43:16 2007 From: james.deville at gmail.com (Jim Deville) Date: Mon, 27 Aug 2007 16:43:16 -0700 Subject: [rspec-users] issue with edge rails and urls In-Reply-To: <09AE7D5B-EEEF-4C4A-9706-AD582C9E9D9F@buttondowndesign.com> References: <09AE7D5B-EEEF-4C4A-9706-AD582C9E9D9F@buttondowndesign.com> Message-ID: <93D94641-D0E8-4292-A89F-C339D2D5E067@gmail.com> On Aug 27, 2007, at 12:52 PM, J.D. Hollis wrote: > I just switched our project over to Edge Rails, and I'm running into > this problem with all of my helper methods that call _url methods: > > NoMethodError in 'ApplicationHelper home_link should generate a valid > home link when User.current and Profile.current is not set' > You have a nil object when you didn't expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.<< > ./spec/helpers/application_helper_spec.rb:17 > > Here's the relevant spec: > > describe ApplicationHelper, "home_link" do > before(:each) do > User.current = nil > Profile.current = nil > end > > it "should generate a valid home link when User.current and > Profile.current is not set" do > home_link.should =~ /#{new_profile_url}/ > end > > it "should generate a valid home link when User.current is set" do > User.current = mock_model(User) > home_link.should =~ /#{dashboard_url}/ > end > > it "should generate a valid home link when Profile.current is set" do > Profile.current = mock_model(Profile) > home_link.should =~ /#{profile_url(Profile.current)}/ > end > end > > And the method in ApplicationHelper: > > def home_link > if User.current.blank? > if Profile.current.blank? > link_to 'Get Started', new_profile_url > else > link_to 'My Profile', profile_url(Profile.current) > end > else > link_to 'Dashboard', dashboard_url > end > end > > I'm using RSpec 1.0.8 and Rails revision 7360. Any ideas where to > start looking for a fix or workaround? > > Regards, > J.D. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users This is fixed in Rspec edge. Jim From sbellware at hotmail.com Tue Aug 14 19:36:53 2007 From: sbellware at hotmail.com (sbellware) Date: Tue, 14 Aug 2007 16:36:53 -0700 (PDT) Subject: [rspec-users] Spec'ing ApplicationController Message-ID: <12154175.post@talk.nabble.com> Folks, I'd like to spec the behaviors that I'm adding to ApplicationController. Specifically, I'm adding: def authenticated? session[:username] != nil end I described ApplicationController, but couldn't figure out how to call the authenticated method. I'm probably going about this quite wrongly and would appreciate any hints? Thanks, Scott -- View this message in context: http://www.nabble.com/Spec%27ing-ApplicationController-tf4270301.html#a12154175 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Mon Aug 27 23:33:45 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 27 Aug 2007 22:33:45 -0500 Subject: [rspec-users] Spec'ing ApplicationController In-Reply-To: <12154175.post@talk.nabble.com> References: <12154175.post@talk.nabble.com> Message-ID: <57c63afe0708272033y2bc0c19es5785ed51d8dacb2e@mail.gmail.com> On 8/14/07, sbellware wrote: > > Folks, > > I'd like to spec the behaviors that I'm adding to ApplicationController. > Specifically, I'm adding: > > def authenticated? > session[:username] != nil > end > > I described ApplicationController, but couldn't figure out how to call the > authenticated method. I'm probably going about this quite wrongly and would > appreciate any hints? The way I handle this is with a shared behaviour that includes specs for behaviours inherited from ApplicationController, but I run them against the real controllers. > > Thanks, > Scott > -- > View this message in context: http://www.nabble.com/Spec%27ing-ApplicationController-tf4270301.html#a12154175 > 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 priit.tamboom at eesti.ee Tue Aug 28 00:32:39 2007 From: priit.tamboom at eesti.ee (Priit Tamboom) Date: Tue, 28 Aug 2007 12:32:39 +0800 Subject: [rspec-users] Spec'ing ApplicationController In-Reply-To: <57c63afe0708272033y2bc0c19es5785ed51d8dacb2e@mail.gmail.com> References: <12154175.post@talk.nabble.com> <57c63afe0708272033y2bc0c19es5785ed51d8dacb2e@mail.gmail.com> Message-ID: On 8/28/07, David Chelimsky wrote: > On 8/14/07, sbellware wrote: > > > > Folks, > > > > I'd like to spec the behaviors that I'm adding to ApplicationController. > > Specifically, I'm adding: > > > > def authenticated? > > session[:username] != nil > > end > > > > I described ApplicationController, but couldn't figure out how to call the > > authenticated method. I'm probably going about this quite wrongly and would > > appreciate any hints? > > The way I handle this is with a shared behaviour that includes specs > for behaviours inherited from ApplicationController, but I run them > against the real controllers. > > > > > > Thanks, > > Scott > > -- > > View this message in context: http://www.nabble.com/Spec%27ing-ApplicationController-tf4270301.html#a12154175 > > 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 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I had same question recently, take a look: http://rubyforge.org/pipermail/rspec-users/2007-August/002760.html If you want discuss it further, I'm happy to share my nuby knowledge :-) Oki, Priit From priit.tamboom at eesti.ee Tue Aug 28 05:00:20 2007 From: priit.tamboom at eesti.ee (Priit Tamboom) Date: Tue, 28 Aug 2007 17:00:20 +0800 Subject: [rspec-users] How do you keep mocks updated without pain? Message-ID: Hi! I know you must be answering a lot of basic questions, sorry about that :-) However I have not get it, how do you keep mocks updated without pain? I reached to the point where mocking things for view. I spec model-controller-view using "correct doc" way mocking-stubbing (plus I should run integration test to be sure that everything really works together). Now, when I want to change something in model then basically I have to change mocks so many places, haven't I? It really feels a little too messy for me as nuby rspecer. Or it's just my worry and you have to be so good that you don't have to change things too much after specing them? If so then I know that I should think much more when mocking(== designing) things. When I googled about this topic I have found similar worries out there and I got two solutions, where David [1] suggest to write integration tests (what should indicate that mocks are outdated) and Ryan [2] suggest to fall bact to fixtures. I feel I will fall back to fixtures, so no more designing fun with mocks but things feels more lightweight and practical :-) Or perhaps it's more up to project size and conditions... I don't know yet. Oki, Priit at typical.nuby.reaction.to.mock.things [1] http://blog.davidchelimsky.net/articles/2006/11/06/view-spec-tutorial "Now the risk here is that you could build a model that doesn't have a title field in it and your app will blow up! Admittedly, if you only write isolated, granular specs like this that risk is real. So you should be doing this in conjunction with integration testing." [2] http://railsforum.com/viewtopic.php?id=6528 "I took the past few hours and removed nearly all mocks from my specs. I also merged the controller and view specs into one using "integrate_views" in the controller spec. I am also loading all fixtures for each controller spec so there's some test data to fill the views. The end result? My specs are shorter, simpler, more consistent, less rigid, and they test the entire stack together (model, view, controller) so no bugs can slip through the cracks. I'm not saying this is the "right" way for everyone. If your project requires a very strict spec case then it may not be for you, but in my case this is worlds better than what I had before using mocks. I still think stubbing is a good solution in a few spots so I'm still doing that." From papipo at gmail.com Tue Aug 28 08:21:55 2007 From: papipo at gmail.com (=?ISO-8859-1?Q?Rodrigo_Alvarez_Fern=E1ndez?=) Date: Tue, 28 Aug 2007 14:21:55 +0200 Subject: [rspec-users] How do you keep mocks updated without pain? In-Reply-To: References: Message-ID: <6d2bdda0708280521i52aafaa7qcba3b1876ccf6b3a@mail.gmail.com> On 8/28/07, Priit Tamboom wrote: > Hi! > > I know you must be answering a lot of basic questions, sorry about that :-) > > However I have not get it, how do you keep mocks updated without pain? > > I reached to the point where mocking things for view. I spec > model-controller-view using "correct doc" way mocking-stubbing (plus I > should run integration test to be sure that everything really works > together). > > Now, when I want to change something in model then basically I have to > change mocks so many places, haven't I? It really feels a little too > messy for me as nuby rspecer. Or it's just my worry and you have to be > so good that you don't have to change things too much after specing > them? If so then I know that I should think much more when mocking(== > designing) things. > > When I googled about this topic I have found similar worries out there > and I got two solutions, where David [1] suggest to write integration > tests (what should indicate that mocks are outdated) and Ryan [2] > suggest to fall bact to fixtures. I guess that each approach has its cons and pros. The integration test way is the way to go, surely. Fixtures are really a pain to maintain, and a lot of times you have records in there that exist just because you need them to one spec. From tom at experthuman.com Wed Aug 29 07:06:12 2007 From: tom at experthuman.com (Tom Stuart) Date: Wed, 29 Aug 2007 12:06:12 +0100 Subject: [rspec-users] DRY specs for RESTful controllers Message-ID: Hi, I'm developing a RESTful Rails application whose code and specs are becoming increasingly repetitive: every controller does pretty much the same set of things (give or take the occasional twiddle), for example, and so every controller spec is almost identical modulo some names, constants and strings. The make_resourceful plugin, which autogenerates the boilerplate REST actions, has gone a long way towards DRYing out the controller side of things, but I haven't seen any examples of nice patterns for doing something similar on the spec side. I'm starting small here: I don't even know what the authorised idiom is for sharing behaviours between specs, since I've only used shared behaviours within a single spec. (Stick something -- a behaviour? some kind of helper? -- in a module? What to call the module file?; where to put it?) Furthermore it's obvious that I don't want just to "inherit" a single static spec across multiple controllers, but rather to instantiate a parameterised spec so that it talks about the right classes, the right routes, the right instance variable. *Furthermore* furthermore, controllers occasionally deviate from the standard RESTful template in a variety of ways, so it'd be nice to be able to "override" the appropriate bits after declaring that it_should_behave_like "ARestfulController" (or whatever). I fear the solution to my requirements is ultimately on par with implementing some kind of make_resourceful-for-specs plugin, which is way beyond what I've got time to do at the moment, but I still feel there's plenty of room for gentle incremental improvement on my current position without going crazy with speculative generality. Any advice much appreciated! Cheers, -Tom From dchelimsky at gmail.com Wed Aug 29 09:44:31 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 29 Aug 2007 08:44:31 -0500 Subject: [rspec-users] DRY specs for RESTful controllers In-Reply-To: References: Message-ID: <57c63afe0708290644w371804ebvc74480f3dc1b37f1@mail.gmail.com> On 8/29/07, Tom Stuart wrote: > Hi, > > I'm developing a RESTful Rails application whose code and specs are > becoming increasingly repetitive: every controller does pretty much > the same set of things (give or take the occasional twiddle), for > example, and so every controller spec is almost identical modulo some > names, constants and strings. > > The make_resourceful plugin, which autogenerates the boilerplate REST > actions, has gone a long way towards DRYing out the controller side > of things, but I haven't seen any examples of nice patterns for doing > something similar on the spec side. > > I'm starting small here: I don't even know what the authorised idiom > is for sharing behaviours between specs, since I've only used shared > behaviours within a single spec. (Stick something -- a behaviour? > some kind of helper? -- in a module? What to call the module file?; > where to put it?) Furthermore it's obvious that I don't want just to > "inherit" a single static spec across multiple controllers, but > rather to instantiate a parameterised spec so that it talks about the > right classes, the right routes, the right instance variable. There has been discussion of parameterized shared behaviours, but the current implementation doesn't do that. I just added a feature request for this outlining my thoughts on how it should work: http://rubyforge.org/tracker/index.php?func=detail&aid=13487&group_id=797&atid=3152. Please feel free to add comments to that item in the tracker. You can add them here, but they'll likely get lost if you do. Adding them to the tracker ensures that when we go to implement something your comments are considered. Cheers, David > *Furthermore* furthermore, controllers occasionally deviate from the > standard RESTful template in a variety of ways, so it'd be nice to be > able to "override" the appropriate bits after declaring that > it_should_behave_like "ARestfulController" (or whatever). > > I fear the solution to my requirements is ultimately on par with > implementing some kind of make_resourceful-for-specs plugin, which is > way beyond what I've got time to do at the moment, but I still feel > there's plenty of room for gentle incremental improvement on my > current position without going crazy with speculative generality. Any > advice much appreciated! > > Cheers, > -Tom > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tom at experthuman.com Wed Aug 29 09:50:57 2007 From: tom at experthuman.com (Tom Stuart) Date: Wed, 29 Aug 2007 14:50:57 +0100 Subject: [rspec-users] DRY specs for RESTful controllers In-Reply-To: <57c63afe0708290644w371804ebvc74480f3dc1b37f1@mail.gmail.com> References: <57c63afe0708290644w371804ebvc74480f3dc1b37f1@mail.gmail.com> Message-ID: <968372FB-5E8C-43DD-8BA7-9AA3916D1F3F@experthuman.com> On 29 Aug 2007, at 14:44, David Chelimsky wrote: > I just added a feature request for this outlining my thoughts on > how it should work: > Please feel free to add comments to that item in the tracker. Thanks a lot, David, I'll read and respond to that. In the meantime, assuming one is restricted to using shared behaviours as they stand, what's the tidiest way to share a shared behaviour (IYSWIM) among several specs? Cheers, -Tom From mathias at globalinn.com Wed Aug 29 08:35:03 2007 From: mathias at globalinn.com (=?ISO-8859-1?Q?Mathias_Stjernstr=F6m?=) Date: Wed, 29 Aug 2007 14:35:03 +0200 Subject: [rspec-users] assign local variable instead of instance variable. Message-ID: Hello, I have a view that generates a list of adverts with <%= render :partial => 'advert', :collection => @adverts %> I have the render call described with @controller.template.should_receive(:render).with(:partial => 'advert', :collection => @adverts) Bu when i was about to describe my partial i got stuck. My partial _advert.rhtml:

And to describe that: http://pastie.textmate.org/91995 The problem is that (assigns[:advert] = advert) creates an instance variable and :collection => @adverts creates a local variable called advert. Is there a way of assigning a local variables in a view/template from my description/spec? Cheers! Mathias Stjernstrom From hans at degraaff.org Wed Aug 29 10:32:53 2007 From: hans at degraaff.org (Hans de Graaff) Date: Wed, 29 Aug 2007 16:32:53 +0200 Subject: [rspec-users] assign local variable instead of instance variable. In-Reply-To: References: Message-ID: <1188397973.32283.1.camel@ip6-localhost> On Wed, 2007-08-29 at 14:35 +0200, Mathias Stjernstr?m wrote: > And to describe that: http://pastie.textmate.org/91995 > > The problem is that (assigns[:advert] = advert) creates an instance > variable and :collection => @adverts creates a local variable called > advert. > > Is there a way of assigning a local variables in a view/template from > my description/spec? I'm using "render :partial => 'some_partial', :object => @mock_object" in those cases. Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/rspec-users/attachments/20070829/0f4ae3fa/attachment.bin From mathias at globalinn.com Wed Aug 29 16:18:38 2007 From: mathias at globalinn.com (=?ISO-8859-1?Q?Mathias_Stjernstr=F6m?=) Date: Wed, 29 Aug 2007 22:18:38 +0200 Subject: [rspec-users] assign local variable instead of instance variable. In-Reply-To: <1188397973.32283.1.camel@ip6-localhost> References: <1188397973.32283.1.camel@ip6-localhost> Message-ID: <2D9B9FEF-E8E6-4DE6-894E-71CA33EF4DB9@globalinn.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, Thanks Hans, that worked like a charm! I did however choose :locals => { :advert => @mock_object } because i think it tells me in a much clearer way that i want to assign a local value to the view and also the name of the variable. I do not know if it is possible but what about an assigns_local [:advert] => @mock_object ? This is how it turned out: http://pastie.textmate.org/92166 Cheers! Mathias Stjernstrom On 29 aug 2007, at 16.32, Hans de Graaff wrote: > On Wed, 2007-08-29 at 14:35 +0200, Mathias Stjernstr?m wrote: > >> And to describe that: http://pastie.textmate.org/91995 >> >> The problem is that (assigns[:advert] = advert) creates an instance >> variable and :collection => @adverts creates a local variable called >> advert. >> >> Is there a way of assigning a local variables in a view/template from >> my description/spec? > > I'm using "render :partial => 'some_partial', :object => @mock_object" > in those cases. > > Kind regards, > > Hans > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iQEVAwUBRtXUnskN6DtuoU6XAQIuVAf/SUYADCa1NUAXgoxujwrhh+J7qRJDgfDr 3QoyDeEsi3M4C1FjqWblTxy6qcdO5/2hzqgB/vs8EMvsFqm9LbLxWVRIM2DQgl9j tXVGvFTibCwb8pZnT/8QpNRwXhJQ0Yc1+G5ur1s0svtYGJevwg5Npkc9FMrDhFmI hqO6cnYOUCPps/2D6YAf0kZxV4UMmhQa7sBCOX2QlJEh3W6uBTX0oZF5GvVyq4Y3 YSSvA/RD/e9ZPVsMwk6rsnRAHt7rrt6zndMJ65j8qAFpFTBPze5p5KAeDrbuKuyy V8IC2vgvDCSHq1Z34kiM3TONP0tYb6Z/rtvz7F46sAU9AdFfhhEfyA== =eZvA -----END PGP SIGNATURE----- From mailing_lists at railsnewbie.com Wed Aug 29 16:48:52 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 29 Aug 2007 16:48:52 -0400 Subject: [rspec-users] rspec report diffs Message-ID: <0ACFBA2C-618D-4352-967E-E572C03DE2D5@railsnewbie.com> I'm working on a rails app, and we plan to release pretty frequently (maybe every week - 2 weeks). I'm wondering if there would be an easy (or not so easy) way to create an rspec report only showing the differences between two sets of specs docs. Scott From zach.dennis at gmail.com Wed Aug 29 18:19:28 2007 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 29 Aug 2007 18:19:28 -0400 Subject: [rspec-users] How do you keep mocks updated without pain? In-Reply-To: References: Message-ID: <85d99afe0708291519t4152d755m3700b024f528a4ac@mail.gmail.com> David's comments on integration testing is right on. The trick with mocks is to understand when to use them, and what advantages they give you. Mocks allow you to test the expected interaction between the object you are testing an some other object. This works great in TDD because while you're implementing an object, the object(s) it interacts with doesn't have to exist. You can create them as you need them. What mocks fail to do is test the true interaction of real objects. And that is because they are not intended to do so. They are intended to allow you to achieve a better level of unit testing. If I am testing ObjectA I want to know it works as expected. I don't care about ObjectB, ObjectC or ObjectD in my tests for ObjectA. So integration tests give you the ability to test real objects together. Integration tests are usually at a much higher level (not as detailed as unit tests) and they verify that you can step through your application as expected. If someone renames a database column and they do not update the tests then an integration test will catch it (if a unit test doesn't)l. And after seeing it fail you are reminded that you need to go update your tests for that change. In rspec, controller, model and view specs are just unit tests/specs. Google around for mocks and stubs. I don't think Martin Fowler's page on "Mocks aren't stubs" is a very clear form of explaining mocks, so I'm not going to recommend it with a link. If you happen to read it then that is a plus, but if you're just starting out with mocks it may not be the best starter resource. HTH, Zach Dennis http://www.continuousthinking.com http://www.atomicobject.com On 8/28/07, Priit Tamboom wrote: > Hi! > > I know you must be answering a lot of basic questions, sorry about that :-) > > However I have not get it, how do you keep mocks updated without pain? > > I reached to the point where mocking things for view. I spec > model-controller-view using "correct doc" way mocking-stubbing (plus I > should run integration test to be sure that everything really works > together). > > Now, when I want to change something in model then basically I have to > change mocks so many places, haven't I? It really feels a little too > messy for me as nuby rspecer. Or it's just my worry and you have to be > so good that you don't have to change things too much after specing > them? If so then I know that I should think much more when mocking(== > designing) things. > > When I googled about this topic I have found similar worries out there > and I got two solutions, where David [1] suggest to write integration > tests (what should indicate that mocks are outdated) and Ryan [2] > suggest to fall bact to fixtures. > > I feel I will fall back to fixtures, so no more designing fun with > mocks but things feels more lightweight and practical :-) Or perhaps > it's more up to project size and conditions... I don't know yet. > > Oki, > Priit at typical.nuby.reaction.to.mock.things > > [1] http://blog.davidchelimsky.net/articles/2006/11/06/view-spec-tutorial > "Now the risk here is that you could build a model that doesn't have a > title field in it and your app will blow up! Admittedly, if you only > write isolated, granular specs like this that risk is real. So you > should be doing this in conjunction with integration testing." > > [2] http://railsforum.com/viewtopic.php?id=6528 > "I took the past few hours and removed nearly all mocks from my specs. > I also merged the controller and view specs into one using > "integrate_views" in the controller spec. I am also loading all > fixtures for each controller spec so there's some test data to fill > the views. > > The end result? My specs are shorter, simpler, more consistent, less > rigid, and they test the entire stack together (model, view, > controller) so no bugs can slip through the cracks. > > I'm not saying this is the "right" way for everyone. If your project > requires a very strict spec case then it may not be for you, but in my > case this is worlds better than what I had before using mocks. I still > think stubbing is a good solution in a few spots so I'm still doing > that." > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Aug 30 00:47:30 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 29 Aug 2007 23:47:30 -0500 Subject: [rspec-users] experimental rails story adapter in trunk Message-ID: <57c63afe0708292147k58ab553ag68b064c3fa8d1351@mail.gmail.com> For those of you interested in getting a jump on learning about and using the new Story Runner in a Rails app, I've added an experimental Rails-Story adapter to trunk. You can see how to use it here: http://pastie.caboo.se/92320 This is PURELY EXPERIMENTAL, however it actually works and will likely not change much in the way that it does work. Happy hacking! David From edward.og at gmail.com Thu Aug 30 09:07:10 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Thu, 30 Aug 2007 09:07:10 -0400 Subject: [rspec-users] mock_model in spec/lib Message-ID: <46D6C0FE.3050907@gmail.com> Has anyone else run into a problem with trying to use mock_model in spec/lib ? For some reason, I can take the same spec, put it in spec/models, have it run fine, but put it in spec/lib, and have it complain about not being able to find #mock_model Thanks, Edward From dchelimsky at gmail.com Thu Aug 30 10:04:45 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 30 Aug 2007 09:04:45 -0500 Subject: [rspec-users] mock_model in spec/lib In-Reply-To: <46D6C0FE.3050907@gmail.com> References: <46D6C0FE.3050907@gmail.com> Message-ID: <57c63afe0708300704n5a873e63tc064529c500e012e@mail.gmail.com> On 8/30/07, Edward Ocampo-Gooding wrote: > Has anyone else run into a problem with trying to use mock_model in spec/lib ? > For some reason, I can take the same spec, put it in spec/models, have it run > fine, but put it in spec/lib, and have it complain about not being able to find > #mock_model mock_model is not supported outside of model, view, controller and helper specs. Feel free to submit a feature request if you think it should be. > > Thanks, > Edward > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From edward.og at gmail.com Thu Aug 30 10:09:35 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Thu, 30 Aug 2007 10:09:35 -0400 Subject: [rspec-users] mock_model in spec/lib In-Reply-To: <57c63afe0708300704n5a873e63tc064529c500e012e@mail.gmail.com> References: <46D6C0FE.3050907@gmail.com> <57c63afe0708300704n5a873e63tc064529c500e012e@mail.gmail.com> Message-ID: <46D6CF9F.4070609@gmail.com> David Chelimsky wrote: > On 8/30/07, Edward Ocampo-Gooding wrote: >> Has anyone else run into a problem with trying to use mock_model in spec/lib ? >> For some reason, I can take the same spec, put it in spec/models, have it run >> fine, but put it in spec/lib, and have it complain about not being able to find >> #mock_model > > mock_model is not supported outside of model, view, controller and > helper specs. Feel free to submit a feature request if you think it > should be. I can kind of understand why it's not, but it'd be good to have an error message that pops informing the user saying as such. Edward From lists-rspec at shopwatch.org Thu Aug 30 10:16:16 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Thu, 30 Aug 2007 10:16:16 -0400 Subject: [rspec-users] mock_model in spec/lib In-Reply-To: <46D6C0FE.3050907@gmail.com> References: <46D6C0FE.3050907@gmail.com> Message-ID: <46D6D130.2010905@jay.fm> Edward Ocampo-Gooding wrote: > Has anyone else run into a problem with trying to use mock_model in spec/lib ? > For some reason, I can take the same spec, put it in spec/models, have it run > fine, but put it in spec/lib, and have it complain about not being able to find > #mock_model Interesting. At first glance, at least, it looks like all of the controller/view/model behaviour includes base.rb's EvalContext, but if you're not in any of those behaviours, you don't get the base behaviour either - "general" specs don't get EvalBehaviour. I'm not positive, because I can't find the bit that loads (dir_name)Behaviours at the moment, but I think that's what's happening. I'm not sure if this is a bug or an enhancement request, and if the right behaviour is to have all Rails specs get EvalBehaviour if they don't live in a special-case dir, or if it would be better for lib to be another special case. Jay Levitt From lists-rspec at shopwatch.org Thu Aug 30 10:20:28 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Thu, 30 Aug 2007 10:20:28 -0400 Subject: [rspec-users] mock_model in spec/lib In-Reply-To: <46D6CF9F.4070609@gmail.com> References: <46D6C0FE.3050907@gmail.com> <57c63afe0708300704n5a873e63tc064529c500e012e@mail.gmail.com> <46D6CF9F.4070609@gmail.com> Message-ID: <46D6D22C.4010709@jay.fm> Edward Ocampo-Gooding wrote: > David Chelimsky wrote: >> On 8/30/07, Edward Ocampo-Gooding wrote: >>> Has anyone else run into a problem with trying to use mock_model in spec/lib ? >>> For some reason, I can take the same spec, put it in spec/models, have it run >>> fine, but put it in spec/lib, and have it complain about not being able to find >>> #mock_model >> mock_model is not supported outside of model, view, controller and >> helper specs. Feel free to submit a feature request if you think it >> should be. > > I can kind of understand why it's not, but it'd be good to have an error message > that pops informing the user saying as such. Also note that in trunk, you can work around this with describe my_lib_function, :behaviour_type => :controller (or model, or helper, or view) which is very useful for lib functions that are used in one of those contexts. Jay From dchelimsky at gmail.com Thu Aug 30 11:37:55 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 30 Aug 2007 10:37:55 -0500 Subject: [rspec-users] mock_model in spec/lib In-Reply-To: <46D6D22C.4010709@jay.fm> References: <46D6C0FE.3050907@gmail.com> <57c63afe0708300704n5a873e63tc064529c500e012e@mail.gmail.com> <46D6CF9F.4070609@gmail.com> <46D6D22C.4010709@jay.fm> Message-ID: <57c63afe0708300837k78172bddjd28e8620868cfb2@mail.gmail.com> On 8/30/07, Jay Levitt wrote: > Edward Ocampo-Gooding wrote: > > David Chelimsky wrote: > >> On 8/30/07, Edward Ocampo-Gooding wrote: > >>> Has anyone else run into a problem with trying to use mock_model in spec/lib ? > >>> For some reason, I can take the same spec, put it in spec/models, have it run > >>> fine, but put it in spec/lib, and have it complain about not being able to find > >>> #mock_model > >> mock_model is not supported outside of model, view, controller and > >> helper specs. Feel free to submit a feature request if you think it > >> should be. > > > > I can kind of understand why it's not, but it'd be good to have an error message > > that pops informing the user saying as such. > > Also note that in trunk, you can work around this with > > describe my_lib_function, :behaviour_type => :controller (or model, or > helper, or view) > > which is very useful for lib functions that are used in one of those > contexts. Correct - that is the correct usage. the lib directory is for stuff not related specifically to rails, in my view > > Jay > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists-rspec at shopwatch.org Thu Aug 30 15:12:16 2007 From: lists-rspec at shopwatch.org (Jay Levitt) Date: Thu, 30 Aug 2007 15:12:16 -0400 Subject: [rspec-users] mock_model in spec/lib In-Reply-To: <57c63afe0708300837k78172bddjd28e8620868cfb2@mail.gmail.com> References: <46D6C0FE.3050907@gmail.com> <57c63afe0708300704n5a873e63tc064529c500e012e@mail.gmail.com> <46D6CF9F.4070609@gmail.com> <46D6D22C.4010709@jay.fm> <57c63afe0708300837k78172bddjd28e8620868cfb2@mail.gmail.com> Message-ID: <46D71690.7030403@jay.fm> David Chelimsky wrote: > On 8/30/07, Jay Levitt wrote: >> Edward Ocampo-Gooding wrote: >>> David Chelimsky wrote: >>>> On 8/30/07, Edward Ocampo-Gooding wrote: >>>>> Has anyone else run into a problem with trying to use mock_model in spec/lib ? >>>>> For some reason, I can take the same spec, put it in spec/models, have it run >>>>> fine, but put it in spec/lib, and have it complain about not being able to find >>>>> #mock_model >>>> mock_model is not supported outside of model, view, controller and >>>> helper specs. Feel free to submit a feature request if you think it >>>> should be. >>> I can kind of understand why it's not, but it'd be good to have an error message >>> that pops informing the user saying as such. >> Also note that in trunk, you can work around this with >> >> describe my_lib_function, :behaviour_type => :controller (or model, or >> helper, or view) >> >> which is very useful for lib functions that are used in one of those >> contexts. > > Correct - that is the correct usage. > > the lib directory is for stuff not related specifically to rails, in my view I don't know how common that view is, though - in general, I think Rails folks use lib/ for classes that aren't part of a model (be it an ActiveRecord model or a "fake" model like a shopping cart). They're often non-Rails-specific, but f'rinstance I have an enum object that interacts with ActiveRecord, but isn't itself a model. Eventually might be a plugin, but for now it's only used in one app, so it lives in lib/. I created an enhancement request, but I can make a patch if you can remind me where on earth the directories are special-cased - I couldn't find it for the life of me. Jay From edward.og at gmail.com Thu Aug 30 15:30:38 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Thu, 30 Aug 2007 15:30:38 -0400 Subject: [rspec-users] mock_model in spec/lib In-Reply-To: <46D71690.7030403@jay.fm> References: <46D6C0FE.3050907@gmail.com> <57c63afe0708300704n5a873e63tc064529c500e012e@mail.gmail.com> <46D6CF9F.4070609@gmail.com> <46D6D22C.4010709@jay.fm> <57c63afe0708300837k78172bddjd28e8620868cfb2@mail.gmail.com> <46D71690.7030403@jay.fm> Message-ID: <46D71ADE.3040003@gmail.com> Jay Levitt wrote: > David Chelimsky wrote: >> On 8/30/07, Jay Levitt wrote: >>> Edward Ocampo-Gooding wrote: >>>> David Chelimsky wrote: >>>>> On 8/30/07, Edward Ocampo-Gooding wrote: >>>>>> Has anyone else run into a problem with trying to use mock_model in spec/lib ? >>>>>> For some reason, I can take the same spec, put it in spec/models, have it run >>>>>> fine, but put it in spec/lib, and have it complain about not being able to find >>>>>> #mock_model >>>>> mock_model is not supported outside of model, view, controller and >>>>> helper specs. Feel free to submit a feature request if you think it >>>>> should be. >>>> I can kind of understand why it's not, but it'd be good to have an error message >>>> that pops informing the user saying as such. >>> Also note that in trunk, you can work around this with >>> >>> describe my_lib_function, :behaviour_type => :controller (or model, or >>> helper, or view) >>> >>> which is very useful for lib functions that are used in one of those >>> contexts. >> Correct - that is the correct usage. >> >> the lib directory is for stuff not related specifically to rails, in my view > > I don't know how common that view is, though - in general, I think Rails > folks use lib/ for classes that aren't part of a model (be it an > ActiveRecord model or a "fake" model like a shopping cart). They're > often non-Rails-specific, but f'rinstance I have an enum object that > interacts with ActiveRecord, but isn't itself a model. Eventually might > be a plugin, but for now it's only used in one app, so it lives in lib/. Yep, I happen to be one of those folks who use lib/ for classes that aren't models. > I created an enhancement request, but I can make a patch if you can > remind me where on earth the directories are special-cased - I couldn't > find it for the life of me. Thanks Jay. It sounds like we'd make a new DSL module for Libs with the same behaviour as Models. Edward From flyeminent at hotmail.com Fri Aug 31 04:22:22 2007 From: flyeminent at hotmail.com (Shaker) Date: Fri, 31 Aug 2007 01:22:22 -0700 (PDT) Subject: [rspec-users] Can module spec "behave like" controller spec? Message-ID: <12422548.post@talk.nabble.com> Hello everyone: Right now I am writing spec on modules, which are provided by my colleagues. Some of the modules actually contain action methods. I tried very hard to spec those action methods in modules. But it seems that the rspec does not allow module spec to 'get' action like controller does. After I saw the documentation, I then used :behaviour_type=>:controller. However, it failed again. It reported an error for me. For illustration, I'd like a simple example. module MyModule def copy #an action method render :partial=>"/index", :layout=>false end end describe MyModule, :behaviour_type=>:controller do it "should render partial index" do get 'copy' #test code not provided yet, just want to get the action end end The error reported was: undefined method 'new' for MyModule:Module. Do you guys have any idea of the error? And how should I test the action methods in modules? Cheers! -- View this message in context: http://www.nabble.com/Can-module-spec-%22behave-like%22-controller-spec--tf4358891.html#a12422548 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Fri Aug 31 04:50:26 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 31 Aug 2007 03:50:26 -0500 Subject: [rspec-users] Can module spec "behave like" controller spec? In-Reply-To: <12422548.post@talk.nabble.com> References: <12422548.post@talk.nabble.com> Message-ID: <57c63afe0708310150n2c85597exb65c166285fedca4@mail.gmail.com> On 8/31/07, Shaker wrote: > > Hello everyone: > Right now I am writing spec on modules, which are provided by my > colleagues. Some of the modules actually contain action methods. I tried > very hard to spec those action methods in modules. But it seems that the > rspec does not allow module spec to 'get' action like controller does. After > I saw the documentation, I then used :behaviour_type=>:controller. However, > it failed again. It reported an error for me. For illustration, I'd like a > simple example. > module MyModule > def copy #an action method > render :partial=>"/index", :layout=>false > end > end > > describe MyModule, :behaviour_type=>:controller do > it "should render partial index" do > get 'copy' #test code not provided yet, just want to get the action > end > end > The error reported was: undefined method 'new' for MyModule:Module. Do you > guys have any idea of the error? And how should I test the action methods in > modules? The ControllerBehaviour is trying to instantiate MyModule. What you'd need to do is something like this: class ControllerThatUsesMyModule include MyModule end describe ControllerThatUsesMyModule, :behaviour_type=>:controller do it "should render partial index" do get 'copy' #test code not provided yet, just want to get the action end end I haven't tried it, but it seems like it should work. Give it a whirl and report back please. Cheers, David > Cheers! > > > -- > View this message in context: http://www.nabble.com/Can-module-spec-%22behave-like%22-controller-spec--tf4358891.html#a12422548 > 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 Fri Aug 31 05:00:31 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 31 Aug 2007 04:00:31 -0500 Subject: [rspec-users] Can module spec "behave like" controller spec? In-Reply-To: <57c63afe0708310150n2c85597exb65c166285fedca4@mail.gmail.com> References: <12422548.post@talk.nabble.com> <57c63afe0708310150n2c85597exb65c166285fedca4@mail.gmail.com> Message-ID: <57c63afe0708310200v7f301963ye003caae7f505b77@mail.gmail.com> On 8/31/07, David Chelimsky wrote: > On 8/31/07, Shaker wrote: > > > > Hello everyone: > > Right now I am writing spec on modules, which are provided by my > > colleagues. Some of the modules actually contain action methods. I tried > > very hard to spec those action methods in modules. But it seems that the > > rspec does not allow module spec to 'get' action like controller does. After > > I saw the documentation, I then used :behaviour_type=>:controller. However, > > it failed again. It reported an error for me. For illustration, I'd like a > > simple example. > > module MyModule > > def copy #an action method > > render :partial=>"/index", :layout=>false > > end > > end > > > > describe MyModule, :behaviour_type=>:controller do > > it "should render partial index" do > > get 'copy' #test code not provided yet, just want to get the action > > end > > end > > The error reported was: undefined method 'new' for MyModule:Module. Do you > > guys have any idea of the error? And how should I test the action methods in > > modules? > > The ControllerBehaviour is trying to instantiate MyModule. What you'd > need to do is something like this: > > class ControllerThatUsesMyModule > include MyModule > end > > describe ControllerThatUsesMyModule, :behaviour_type=>:controller do > it "should render partial index" do > get 'copy' #test code not provided yet, just want to get the action > end > end > > I haven't tried it, but it seems like it should work. Give it a whirl > and report back please. Of course, the subject of this thread should smack us all in the face and point in a different direction: describe "any controller", :shared => true do it "should render partial index" do get 'copy' #test code not provided yet, just want to get the action end end # an actual controller - not just for specs class FooController include AnyController end # in spec/controllers/foo_controller_spec.rb describe FooController do it_should_behave_like "any controller" ... #more stuff specific to FooController end > > Cheers, > David > > > Cheers! > > > > > > -- > > View this message in context: http://www.nabble.com/Can-module-spec-%22behave-like%22-controller-spec--tf4358891.html#a12422548 > > 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 tom at hobocentral.net Fri Aug 31 06:58:59 2007 From: tom at hobocentral.net (Tom Locke) Date: Fri, 31 Aug 2007 11:58:59 +0100 Subject: [rspec-users] Testing for confidence - is this a spec at all? In-Reply-To: <8BD595A9-7EDF-44E2-946F-F91388A073D2@railsnewbie.com> References: <8BD595A9-7EDF-44E2-946F-F91388A073D2@railsnewbie.com> Message-ID: <39FFAC18-5886-4CCD-A375-F949E05223D3@hobocentral.net> Hi BDDers Quick background: I'm working on the Hobo plugin for Rails which, amongst many things, automates a great deal of controller code for you. Hobo has a built in security mechanism, and the generic controller uses this to ensure that POSTs and PUTs only change the DB in ways you've permitted. I'm writing some rspec examples that test for holes in this security mechanism. My feeling is that this really is testing rather than specifying. I don't want to use mocks/stubs because I want to be absolutely sure that changes have not happened to the DB. For example, with stubs, I might say "Post.save should not be called", but there are other paths through AR that can result in that post being inserted into the DB. So I really want to say Post.find_by_title("test post").should == nil (where Post is the real thing, not a mock/stub) And my questions are..... This is clearly not a spec as such, or a unit test. What is it? A functional test? An integration test? Where then does it belong? Should I be using rspec at all? (I want to because I spec other parts of Hobo and the whole rspec environment is step up and ready to go) (Note that I don't have any problems here as such - I'm writing these tests in rspec style and it's all working fine. I'm just fearful of what the BDDPD might say if they catch me! Well really I'm just curious as to what "good form" would be) Thanks muchly -Tom From dchelimsky at gmail.com Fri Aug 31 10:24:53 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 31 Aug 2007 09:24:53 -0500 Subject: [rspec-users] Testing for confidence - is this a spec at all? In-Reply-To: <39FFAC18-5886-4CCD-A375-F949E05223D3@hobocentral.net> References: <8BD595A9-7EDF-44E2-946F-F91388A073D2@railsnewbie.com> <39FFAC18-5886-4CCD-A375-F949E05223D3@hobocentral.net> Message-ID: <57c63afe0708310724g7a618ed8l931ebba1c02cf604@mail.gmail.com> On 8/31/07, Tom Locke wrote: > Hi BDDers > > Quick background: I'm working on the Hobo plugin for Rails which, > amongst many things, automates a great deal of controller code for you. > > Hobo has a built in security mechanism, and the generic controller > uses this to ensure that POSTs and PUTs only change the DB in ways > you've permitted. > > I'm writing some rspec examples that test for holes in this security > mechanism. My feeling is that this really is testing rather than > specifying. I don't want to use mocks/stubs because I want to be > absolutely sure that changes have not happened to the DB. > > For example, with stubs, I might say "Post.save should not be > called", but there are other paths through AR that can result in that > post being inserted into the DB. So I really want to say > > Post.find_by_title("test post").should == nil > > (where Post is the real thing, not a mock/stub) > > And my questions are..... > > This is clearly not a spec as such, or a unit test. What is it? A > functional test? An integration test? > > Where then does it belong? > > Should I be using rspec at all? (I want to because I spec other parts > of Hobo and the whole rspec environment is step up and ready to go) > > (Note that I don't have any problems here as such - I'm writing these > tests in rspec style and it's all working fine. I'm just fearful of > what the BDDPD might say if they catch me! Well really I'm just > curious as to what "good form" would be) The subject of this thread says it all: 'testing for confidence'. That's what all of this is about. It's all about YOU, the developer, feeling confidence to take the next step. Driving with examples, if done with discipline, means you automatically get 100% code coverage. That gives you a lot of confidence to make a change, because you're sure to get feedback if you screw it up. Since these have a different feel in your mind, I'd certainly consider moving them to their own directory. You might consider the new Story Runner (trunk only, so far), that is designed to be more customer facing and in direct support of requirements, running things end to end (no mocks). The Story Runner comes from RBehave - so you can see what it looks like here: http://dannorth.net/2007/06/introducing-rbehave. If you were doing a BDD project (kind of like an XP project), you'd have User Stories that say specific things about security, and you'd represent them in Story Runner. Then you'd deal with the individual objects using the Example Runner (i.e. describe it). In that world, you'd use mocks to isolate things. Although, even that tends to be abused. The most visible model is Rails, which couples everything together so much that you have to use mock models to avoid hitting the DB from your view specs. But in non-rails projects, it's quite common for mocks to appear and disappear in process - using them as discovery tools, but then using the real objects as they appear. You can read more about that at http://mockobjects.com. Hope this all helps. Cheers, David co-Captain BDDPD > > Thanks muchly > > -Tom > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From peter_marklund at fastmail.fm Fri Aug 31 11:13:06 2007 From: peter_marklund at fastmail.fm (Peter Marklund) Date: Fri, 31 Aug 2007 17:13:06 +0200 Subject: [rspec-users] Setting use_transactional_fixtures=false for a single spec - a bad idea? Message-ID: Hi! I would really like to find a way to allow me to write RSpec specifications for code that use database transactions. I know I can set config.use_transactional_fixtures = false in my spec_helper.rb. That works, and that's great, but it will (I think) slow down my specs quite a bit. I would like to turn off transactional fixtures for just a single spec (describe), or even better, just a single example (it). I tried this: before(:all) do Spec::Runner.configure do |config| config.use_transactional_fixtures = false end end after(:all) do Spec::Runner.configure do |config| config.use_transactional_fixtures = true end end but that didn't work. Or is setting use_transactional_fixtures=false on a global level really the way to go even if it slows you down? It certainly feels a lot cleaner and solid to me. Maybe I need more db stubbing. Thanks in advance for any pointers! Cheers Peter http://marklunds.com From dchelimsky at gmail.com Fri Aug 31 11:18:41 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 31 Aug 2007 10:18:41 -0500 Subject: [rspec-users] Setting use_transactional_fixtures=false for a single spec - a bad idea? In-Reply-To: References: Message-ID: <57c63afe0708310818v2ef9405bw5aa399f7c79ffda1@mail.gmail.com> On 8/31/07, Peter Marklund wrote: > Hi! > I would really like to find a way to allow me to write RSpec > specifications for code that use database transactions. I know I can set > > config.use_transactional_fixtures = false > > in my spec_helper.rb. That works, and that's great, but it will (I > think) slow down my specs quite a bit. I would like to turn off > transactional fixtures for just a single spec (describe), or even > better, just a single example (it). I tried this: > > before(:all) do > Spec::Runner.configure do |config| > config.use_transactional_fixtures = false > end > end > > after(:all) do > Spec::Runner.configure do |config| > config.use_transactional_fixtures = true > end > end > > but that didn't work. > > Or is setting use_transactional_fixtures=false on a global level > really the way to go even if it slows you down? It certainly feels a > lot cleaner and solid to me. Maybe I need more db stubbing. > > Thanks in advance for any pointers! I'd set up a separate folder for these specs and tweak the rake tasks to run those specs in a separate process, w/ its own spec_helper that sets config.use_transactional_fixtures to false. > > Cheers > > Peter > http://marklunds.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Aug 31 11:19:44 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 31 Aug 2007 10:19:44 -0500 Subject: [rspec-users] Setting use_transactional_fixtures=false for a single spec - a bad idea? In-Reply-To: References: Message-ID: <57c63afe0708310819g37b22ea0v1bfdb53470ddeef4@mail.gmail.com> On 8/31/07, Peter Marklund wrote: > Hi! > I would really like to find a way to allow me to write RSpec > specifications for code that use database transactions. I know I can set > > config.use_transactional_fixtures = false > > in my spec_helper.rb. That works, and that's great, but it will (I > think) slow down my specs quite a bit. I would like to turn off > transactional fixtures for just a single spec (describe), or even > better, just a single example (it). I tried this: > > before(:all) do > Spec::Runner.configure do |config| > config.use_transactional_fixtures = false > end > end > > after(:all) do > Spec::Runner.configure do |config| > config.use_transactional_fixtures = true > end > end > > but that didn't work. > > Or is setting use_transactional_fixtures=false on a global level > really the way to go even if it slows you down? It certainly feels a > lot cleaner and solid to me. Maybe I need more db stubbing. > > Thanks in advance for any pointers! I'd set up a separate folder for these specs and tweak the rake tasks to run those specs in a separate process, w/ its own spec_helper that sets config.use_transactional_fixtures to false. > > Cheers > > Peter > http://marklunds.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From edgargonzalez at gmail.com Fri Aug 31 11:49:37 2007 From: edgargonzalez at gmail.com (Edgar Gonzalez) Date: Fri, 31 Aug 2007 11:49:37 -0400 Subject: [rspec-users] How to spec routes for a resource nested in multiples resources? Message-ID: Hi, I got the resource "Llamadas" nested in: - Operadores - Productos - Centros Here is part of my routes http://pastie.caboo.se/92767 I want to spec that the routes for Llamadas, I tried several approachs: - route_for(:controller => "llamadas", :action => "exitosas", :operador_id => 1).should == "/operador/1/llamadas;exitosas" - controller.send(:operador_exitosas_llamadas_path, at operador).should == "/operador/22/llamadas;exitosas" but nothing works. any clue? thanks in advance -- Edgar Gonz?lez Gonz?lez E-mail: edgargonzalez at gmail.com http://www.hasmanydevelopers.com http://www.rubycorner.com http://www.to2blogs.com http://www.lacaraoscura.com -- From pergesu at gmail.com Fri Aug 31 19:17:07 2007 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 31 Aug 2007 16:17:07 -0700 Subject: [rspec-users] Deprecating the mocking framework? Message-ID: <810a540e0708311617r7a85a9d8wf013add5f3647f10@mail.gmail.com> I saw in one of Dave C.'s comments to a ticket that "our current plan is to deprecate the mocking framework." I hadn't heard anything about that, but then again I haven't paid super close attention to the list. Are we planning on dumping the mock framework in favor of using Mocha (or any other framework one might want to plug in?). Pat