From jed.hurt at gmail.com Sat Mar 1 00:10:54 2008 From: jed.hurt at gmail.com (Jed Hurt) Date: Fri, 29 Feb 2008 22:10:54 -0700 Subject: [rspec-users] Quiet Backtrace in RSpec In-Reply-To: <57c63afe0802291352na6db27x99b501815383c30e@mail.gmail.com> References: <8d961d900801190039x7c973fb3xad1052df557c2e45@mail.gmail.com> <57c63afe0802210521x625ad9efg1c87a37f2c113cf8@mail.gmail.com> <57c63afe0802291352na6db27x99b501815383c30e@mail.gmail.com> Message-ID: Ahh, I see. Cool, cool :) On Fri, Feb 29, 2008 at 2:52 PM, David Chelimsky wrote: > On Fri, Feb 29, 2008 at 1:08 PM, Jed Hurt wrote: > > > > > > > > On Thu, Feb 21, 2008 at 6:21 AM, David Chelimsky > > wrote: > > > > > > On Thu, Feb 21, 2008 at 12:52 AM, Jed Hurt wrote: > > > > Ahh, I see. Is Spec::Runner::QuietBacktraceTweaker configurable for > more > > > > quietness? > > > > > > Nope. > > > > Haha. Is that a terse form of PDI? > > Not intentional. I think I was responding on my phone, which makes > everything more terse. > > Cheers, > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080229/155713f8/attachment-0001.html From bryansray at gmail.com Sat Mar 1 01:15:34 2008 From: bryansray at gmail.com (Bryan Ray) Date: Sat, 1 Mar 2008 00:15:34 -0600 Subject: [rspec-users] how do i get color with autotest on XP? In-Reply-To: <81d544a3ff8319219dfb3518d2aa3d61@ruby-forum.com> References: <71166b3b0802291708t52b6aac6v564faa4133e4d82b@mail.gmail.com> <81d544a3ff8319219dfb3518d2aa3d61@ruby-forum.com> Message-ID: <29a0119e0802292215o5443230cp1927a0afa45a4b9f@mail.gmail.com> A colleague of mine says he got his working, but I have yet to see it. I will ask him on Monday and report back with what I find. On Fri, Feb 29, 2008 at 9:15 PM, Spencer Roan wrote: > @Luis Lavena > ok, thank you! i'll stop beating my head against it then and keep an eye > out on the updates of win32console. > spencer > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Bryan Ray http://www.bryanray.net "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080301/01ecee1e/attachment.html From gilesb at gmail.com Sat Mar 1 12:37:19 2008 From: gilesb at gmail.com (Giles Bowkett) Date: Sat, 1 Mar 2008 09:37:19 -0800 Subject: [rspec-users] rspec with continuations: very strange Message-ID: <2d81dedb0803010937m797765aeqfb6f3a8bd7e0a9e0@mail.gmail.com> I appear to have written code which travels backwards through time: http://www.vimeo.com/742590 This disturbs me immensely. If anyone can explain it, that would be cool. I think it's an illusion brought about by how RSpec wraps the code it executes, and by the sheer weirdness of continuations. -- Giles Bowkett Blog: http://gilesbowkett.blogspot.com Portfolio: http://www.gilesgoatboy.org Tumblelog: http://giles.tumblr.com Podcast: http://hollywoodgrit.blogspot.com From omen.king at gmail.com Sat Mar 1 12:55:11 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Sat, 1 Mar 2008 12:55:11 -0500 Subject: [rspec-users] rspec with continuations: very strange In-Reply-To: <2d81dedb0803010937m797765aeqfb6f3a8bd7e0a9e0@mail.gmail.com> References: <2d81dedb0803010937m797765aeqfb6f3a8bd7e0a9e0@mail.gmail.com> Message-ID: Wow, thats reminds of when micheal jay fox flew back in time and he almost broke his specs by going out with his mom."should_not be_nil" LawL Couldn't you On Sat, Mar 1, 2008 at 12:37 PM, Giles Bowkett wrote: > I appear to have written code which travels backwards through time: > > http://www.vimeo.com/742590 > > This disturbs me immensely. If anyone can explain it, that would be cool. > > I think it's an illusion brought about by how RSpec wraps the code it > executes, and by the sheer weirdness of continuations. > > -- > Giles Bowkett > > Blog: http://gilesbowkett.blogspot.com > Portfolio: http://www.gilesgoatboy.org > Tumblelog: http://giles.tumblr.com > Podcast: http://hollywoodgrit.blogspot.com > _______________________________________________ > 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/20080301/5a9b78e8/attachment.html From dchelimsky at gmail.com Sat Mar 1 12:59:46 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 1 Mar 2008 11:59:46 -0600 Subject: [rspec-users] rspec with continuations: very strange In-Reply-To: <2d81dedb0803010937m797765aeqfb6f3a8bd7e0a9e0@mail.gmail.com> References: <2d81dedb0803010937m797765aeqfb6f3a8bd7e0a9e0@mail.gmail.com> Message-ID: <57c63afe0803010959o6b587b9dvf8890be4cd8c617d@mail.gmail.com> On Sat, Mar 1, 2008 at 11:37 AM, Giles Bowkett wrote: > I appear to have written code which travels backwards through time: > > http://www.vimeo.com/742590 > > This disturbs me immensely. If anyone can explain it, that would be cool. > > I think it's an illusion brought about by how RSpec wraps the code it > executes, and by the sheer weirdness of continuations. This has absolutely nothing to do with RSpec. Do the same thing in test/unit and you'll find the same result (http://pastie.caboo.se/159803) Continuations ARE time machines. So when you called the continuation again, it does in fact go back to where it exited the loop (from the interrupt). Now I haven't looked to see why the second time "through time" it's not working, but it actually makes perfect sense that it goes back in time. FWIW, David > > -- > Giles Bowkett > > Blog: http://gilesbowkett.blogspot.com > Portfolio: http://www.gilesgoatboy.org > Tumblelog: http://giles.tumblr.com > Podcast: http://hollywoodgrit.blogspot.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From srogers1 at gmail.com Sat Mar 1 13:04:33 2008 From: srogers1 at gmail.com (Steven Rogers) Date: Sat, 1 Mar 2008 12:04:33 -0600 Subject: [rspec-users] rspec with continuations: very strange In-Reply-To: References: <2d81dedb0803010937m797765aeqfb6f3a8bd7e0a9e0@mail.gmail.com> Message-ID: On Mar 1, 2008, at 11:55 AM, Andrew WC Brown wrote: > Wow, thats reminds of when micheal jay fox flew back in time and he > almost broke his specs by going out with his mom. > "should_not be_nil" LawL set whiny_exceeding_lightspeed => true SR From rick.denatale at gmail.com Sat Mar 1 15:53:03 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sat, 1 Mar 2008 15:53:03 -0500 Subject: [rspec-users] rspec with continuations: very strange In-Reply-To: <57c63afe0803010959o6b587b9dvf8890be4cd8c617d@mail.gmail.com> References: <2d81dedb0803010937m797765aeqfb6f3a8bd7e0a9e0@mail.gmail.com> <57c63afe0803010959o6b587b9dvf8890be4cd8c617d@mail.gmail.com> Message-ID: On 3/1/08, David Chelimsky wrote: > On Sat, Mar 1, 2008 at 11:37 AM, Giles Bowkett wrote: > > I appear to have written code which travels backwards through time: > > > > http://www.vimeo.com/742590 > > > > This disturbs me immensely. If anyone can explain it, that would be cool. > > > > I think it's an illusion brought about by how RSpec wraps the code it > > executes, and by the sheer weirdness of continuations. > > > This has absolutely nothing to do with RSpec. Do the same thing in > test/unit and you'll find the same result > (http://pastie.caboo.se/159803) > > Continuations ARE time machines. So when you called the continuation > again, it does in fact go back to where it exited the loop (from the > interrupt). > > Now I haven't looked to see why the second time "through time" it's > not working, but it actually makes perfect sense that it goes back in > time. I can't read all of the code, but it appears that the up_to method in ContinuationLooper looks like this: 1: def up_to(interrupt) 2: accumulator = "" 3: continuation = nil 4: for i in 1..100 do 5: accumulator += "Value of i: #{i}
\n" 6: callcc {|continuation| return accumulator, continuation} if i == interrupt 7: accumulator 8: end 9: end Ok now in the test we have: 10: it "resumes its continuation, returning a string" do 11: accumulator, continuation = ContinuationLooper.up_to(50) 12: continuation.class.should == Continuation 13: puts accumulator 14: puts continuation.call Now, when we first encounter line 11, we get to the point in the loop in the ContinuationLooper.up_to method where i == 50 and invoke callcc. This evaluates it's block argument which returns the accumulator and the continuation, returning them to line 12. So continuation here is a Continuation and the expectation is met. Now, we go on, and when we get to line 14, the continuation gets called, which puts us back at line 7 inside the loop, which continues until i gets to 100. The callcc doesn't get invoked again because i is now always > interrupt. Then the method returns the last expression in the loop which is simply: accumulator which is what gets returned as the value of the call in line 11 (i.e. the second time we've gotten there), and substituting the return value, the effect is as if line 11 were: accumulator, continuation = "Value of i: (1)
\n...Value of i: (100)
\n" Which because of the way Ruby parallel assignment works when there are not enough RHS values to go around sets the local continuation to nil. No mystery here at all. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From mhennemeyer at googlemail.com Sun Mar 2 06:37:36 2008 From: mhennemeyer at googlemail.com (Matthias Hennemeyer) Date: Sun, 2 Mar 2008 12:37:36 +0100 Subject: [rspec-users] rspec with continuations: very strange In-Reply-To: <2d81dedb0803010937m797765aeqfb6f3a8bd7e0a9e0@mail.gmail.com> References: <2d81dedb0803010937m797765aeqfb6f3a8bd7e0a9e0@mail.gmail.com> Message-ID: Hey Giles, i think that the problem is not that continuations are weird, but that computerscientists are not very creative at inventing helpful names. So i would call it a frozen_computation_state or frozen_environment because that is what a continuation object represents. And the call-with-current-continuation (callcc) really makes no exception when a part of the environment is dedicated to rspec. When you send 'call' to the continuation object, the environment will be set to the state that is represented by the continuation object - the variable with the name continuation points to nil and the next step in evaluation is line 13 in your spec file. Matthias Hennemeyer Am 01.03.2008 um 18:37 schrieb Giles Bowkett: > I appear to have written code which travels backwards through time: > > http://www.vimeo.com/742590 > > This disturbs me immensely. If anyone can explain it, that would be > cool. > > I think it's an illusion brought about by how RSpec wraps the code it > executes, and by the sheer weirdness of continuations. > > -- > Giles Bowkett > > Blog: http://gilesbowkett.blogspot.com > Portfolio: http://www.gilesgoatboy.org > Tumblelog: http://giles.tumblr.com > Podcast: http://hollywoodgrit.blogspot.com > _______________________________________________ > 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/20080302/156353e9/attachment.html From dbitsolutions at gmail.com Sun Mar 2 20:34:59 2008 From: dbitsolutions at gmail.com (David Beckwith) Date: Sun, 2 Mar 2008 17:34:59 -0800 Subject: [rspec-users] outside-in = integration tests on views? In-Reply-To: <57c63afe0802291606i322b68f1t1dbc3873fb573e4f@mail.gmail.com> References: <93ddac20802291533y167fcc58p4e1e2bbf017c39e7@mail.gmail.com> <57c63afe0802291606i322b68f1t1dbc3873fb573e4f@mail.gmail.com> Message-ID: <93ddac20803021734k5ce20b42qac1db87965b657c5@mail.gmail.com> Hi, 1. What is :steps_for for? 2. Is the GWT form of tests meant to replace it "should . . . . ." style of tests? I heard that GWT are written for your customer to represent a set of acceptance criteria, and it-should tests are more for programmers. Is that how we should think about the difference these two kinds of tests? Or are they really the same thing? BTW, Are the PeepCode rSpec tutorials worth buying? Thanks, David :) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080302/a4303f8a/attachment-0001.html From ben at benmabey.com Sun Mar 2 21:49:29 2008 From: ben at benmabey.com (Ben Mabey) Date: Sun, 02 Mar 2008 19:49:29 -0700 Subject: [rspec-users] outside-in = integration tests on views? In-Reply-To: <93ddac20803021734k5ce20b42qac1db87965b657c5@mail.gmail.com> References: <93ddac20802291533y167fcc58p4e1e2bbf017c39e7@mail.gmail.com> <57c63afe0802291606i322b68f1t1dbc3873fb573e4f@mail.gmail.com> <93ddac20803021734k5ce20b42qac1db87965b657c5@mail.gmail.com> Message-ID: <47CB6739.9090005@benmabey.com> > > > BTW, Are the PeepCode rSpec tutorials worth buying? > They are a steal. I watched them after I had already been using rSpec for a couple months and I still learned a lot and felt like they were a great investment. I haven't watched the Story one yet but the general rspec ones were great. -Ben From lists at ruby-forum.com Sun Mar 2 22:38:34 2008 From: lists at ruby-forum.com (Namrata Tiwari) Date: Mon, 3 Mar 2008 04:38:34 +0100 Subject: [rspec-users] rspec controller action list In-Reply-To: <29a0119e0802290552i44369de8u5d6f77728115d184@mail.gmail.com> References: <36a1f08323bd82582ae8b5df7e4f4072@ruby-forum.com> <57c63afe0802280605o5f0be241r522961fd5e04c55a@mail.gmail.com> <1289886a79437bf85fc8ce94a55bc4ce@ruby-forum.com> <29a0119e0802290552i44369de8u5d6f77728115d184@mail.gmail.com> Message-ID: <40a3a0f9880ab0dddaab44675cb0c637@ruby-forum.com> Bryan Ray wrote: > It has to do with your "find_city" method. You spec is expecting it to > be > called from controller, hence: > > controller.should_receive(:find_city) > > Where is that method and why isn't it being called should be your next > questions based on the code and spec you've pasted. > The method find_city is in application controller. I think the method 'find_city' is being called but its expecting some args. Thanks, Namrata. -- Posted via http://www.ruby-forum.com/. From mhennemeyer at googlemail.com Mon Mar 3 04:46:58 2008 From: mhennemeyer at googlemail.com (Matthias Hennemeyer) Date: Mon, 3 Mar 2008 10:46:58 +0100 Subject: [rspec-users] rspec controller action list In-Reply-To: <40a3a0f9880ab0dddaab44675cb0c637@ruby-forum.com> References: <36a1f08323bd82582ae8b5df7e4f4072@ruby-forum.com> <57c63afe0802280605o5f0be241r522961fd5e04c55a@mail.gmail.com> <1289886a79437bf85fc8ce94a55bc4ce@ruby-forum.com> <29a0119e0802290552i44369de8u5d6f77728115d184@mail.gmail.com> <40a3a0f9880ab0dddaab44675cb0c637@ruby-forum.com> Message-ID: <70B93E65-D33C-430F-A3E7-7A8D50EA94A9@googlemail.com> Am 03.03.2008 um 04:38 schrieb Namrata Tiwari: > The method find_city is in application controller. I think the method > 'find_city' is being called but its expecting some args. > The message: Mock 'ArticlesController' expected :find_city with (any args) once, but received it 0 times means that the method find_city was *not* called. If the original method expects args or not doesn't matter. Because should_receive works as both an expectation and a stub, the original method will not be called and no ArgumentError will be raised. > Thanks, > Namrata. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rob.holland at gmail.com Mon Mar 3 05:02:01 2008 From: rob.holland at gmail.com (Rob Holland) Date: Mon, 3 Mar 2008 10:02:01 +0000 Subject: [rspec-users] outside-in = integration tests on views? In-Reply-To: <93ddac20803021734k5ce20b42qac1db87965b657c5@mail.gmail.com> References: <93ddac20802291533y167fcc58p4e1e2bbf017c39e7@mail.gmail.com> <57c63afe0802291606i322b68f1t1dbc3873fb573e4f@mail.gmail.com> <93ddac20803021734k5ce20b42qac1db87965b657c5@mail.gmail.com> Message-ID: <6ea3a1b80803030202v5a34a7ffheae4ddb5f7029c10@mail.gmail.com> > BTW, Are the PeepCode rSpec tutorials worth buying? Anything from PeepCode is worth buying imho, but the specifically, the three rspec ones I have watched have been excellent. From lists at ruby-forum.com Mon Mar 3 06:04:43 2008 From: lists at ruby-forum.com (Namrata Tiwari) Date: Mon, 3 Mar 2008 12:04:43 +0100 Subject: [rspec-users] rspec controller action list In-Reply-To: <70B93E65-D33C-430F-A3E7-7A8D50EA94A9@googlemail.com> References: <36a1f08323bd82582ae8b5df7e4f4072@ruby-forum.com> <57c63afe0802280605o5f0be241r522961fd5e04c55a@mail.gmail.com> <1289886a79437bf85fc8ce94a55bc4ce@ruby-forum.com> <29a0119e0802290552i44369de8u5d6f77728115d184@mail.gmail.com> <40a3a0f9880ab0dddaab44675cb0c637@ruby-forum.com> <70B93E65-D33C-430F-A3E7-7A8D50EA94A9@googlemail.com> Message-ID: <997cd6a508b3f825a5e1ab9c922f8a50@ruby-forum.com> Matthias Hennemeyer wrote: > Am 03.03.2008 um 04:38 schrieb Namrata Tiwari: > >> The method find_city is in application controller. I think the method >> 'find_city' is being called but its expecting some args. >> > The message: > > Mock 'ArticlesController' expected :find_city with (any args) once, but > received > it 0 times > > means that the method find_city was *not* called. > > If the original method expects args or not doesn't matter. > Because should_receive works as both an expectation and a stub, the > original method will not be called and no ArgumentError will be raised. Okaayyy! Then can you also please say why its not calling this :find_city method? Thx, Namrata. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Mar 3 06:15:38 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 3 Mar 2008 05:15:38 -0600 Subject: [rspec-users] rspec controller action list In-Reply-To: <997cd6a508b3f825a5e1ab9c922f8a50@ruby-forum.com> References: <36a1f08323bd82582ae8b5df7e4f4072@ruby-forum.com> <57c63afe0802280605o5f0be241r522961fd5e04c55a@mail.gmail.com> <1289886a79437bf85fc8ce94a55bc4ce@ruby-forum.com> <29a0119e0802290552i44369de8u5d6f77728115d184@mail.gmail.com> <40a3a0f9880ab0dddaab44675cb0c637@ruby-forum.com> <70B93E65-D33C-430F-A3E7-7A8D50EA94A9@googlemail.com> <997cd6a508b3f825a5e1ab9c922f8a50@ruby-forum.com> Message-ID: <57c63afe0803030315g3f4ff229r497649dc9b7ac490@mail.gmail.com> On Mon, Mar 3, 2008 at 5:04 AM, Namrata Tiwari wrote: > Matthias Hennemeyer wrote: > > Am 03.03.2008 um 04:38 schrieb Namrata Tiwari: > > > >> The method find_city is in application controller. I think the method > >> 'find_city' is being called but its expecting some args. > >> > > The message: > > > > Mock 'ArticlesController' expected :find_city with (any args) once, but > > received > > it 0 times > > > > means that the method find_city was *not* called. > > > > If the original method expects args or not doesn't matter. > > Because should_receive works as both an expectation and a stub, the > > original method will not be called and no ArgumentError will be raised. > > Okaayyy! > Then can you also please say why its not calling this :find_city method? If the code is the same as it was in the first post in this thread, it's because the action is taking place before setting the expectations. > > Thx, > > > Namrata. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Mar 3 06:22:45 2008 From: lists at ruby-forum.com (Namrata Tiwari) Date: Mon, 3 Mar 2008 12:22:45 +0100 Subject: [rspec-users] rspec controller action list In-Reply-To: <57c63afe0803030315g3f4ff229r497649dc9b7ac490@mail.gmail.com> References: <36a1f08323bd82582ae8b5df7e4f4072@ruby-forum.com> <57c63afe0802280605o5f0be241r522961fd5e04c55a@mail.gmail.com> <1289886a79437bf85fc8ce94a55bc4ce@ruby-forum.com> <29a0119e0802290552i44369de8u5d6f77728115d184@mail.gmail.com> <40a3a0f9880ab0dddaab44675cb0c637@ruby-forum.com> <70B93E65-D33C-430F-A3E7-7A8D50EA94A9@googlemail.com> <997cd6a508b3f825a5e1ab9c922f8a50@ruby-forum.com> <57c63afe0803030315g3f4ff229r497649dc9b7ac490@mail.gmail.com> Message-ID: <7317f1371334b517a72ad383e8425fed@ruby-forum.com> > > If the code is the same as it was in the first post in this thread, > it's because the action is taking place before setting the > expectations. Yes, it is the same. As you have suggested earlier. I am pasting the spec again. #list it "should list all articles" do articles = mock("articles") articles.should_receive(:paginate).with(:order => "live_on DESC", :conditions => { :type_for => "blog" }) controller.should_receive(:find_city).and_return(articles) response.should be_success get :list end Thx, Namrata. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Mar 3 06:32:32 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 3 Mar 2008 05:32:32 -0600 Subject: [rspec-users] rspec controller action list In-Reply-To: <7317f1371334b517a72ad383e8425fed@ruby-forum.com> References: <36a1f08323bd82582ae8b5df7e4f4072@ruby-forum.com> <57c63afe0802280605o5f0be241r522961fd5e04c55a@mail.gmail.com> <1289886a79437bf85fc8ce94a55bc4ce@ruby-forum.com> <29a0119e0802290552i44369de8u5d6f77728115d184@mail.gmail.com> <40a3a0f9880ab0dddaab44675cb0c637@ruby-forum.com> <70B93E65-D33C-430F-A3E7-7A8D50EA94A9@googlemail.com> <997cd6a508b3f825a5e1ab9c922f8a50@ruby-forum.com> <57c63afe0803030315g3f4ff229r497649dc9b7ac490@mail.gmail.com> <7317f1371334b517a72ad383e8425fed@ruby-forum.com> Message-ID: <57c63afe0803030332y5ff467e7j7baa284813d0efb9@mail.gmail.com> On Mon, Mar 3, 2008 at 5:22 AM, Namrata Tiwari wrote: > > > > > If the code is the same as it was in the first post in this thread, > > it's because the action is taking place before setting the > > expectations. > > Yes, it is the same. As you have suggested earlier. > I am pasting the spec again. > > > #list > it "should list all articles" do > articles = mock("articles") > articles.should_receive(:paginate).with(:order => "live_on DESC", > :conditions => { :type_for => "blog" }) > controller.should_receive(:find_city).and_return(articles) > response.should be_success > get :list > > end That is NOT the same :) In the initial post the first line was 'get :list' - now that is the last line. So while you're at it, please post the action again as well. > > > > Thx, > Namrata. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From abroad-crawford at within3.com Mon Mar 3 12:08:25 2008 From: abroad-crawford at within3.com (Anthony Broad-Crawford) Date: Mon, 3 Mar 2008 12:08:25 -0500 Subject: [rspec-users] Rspec and plugins Message-ID: I have a question regarding best practices around module and plugin testing for rails applications. In our application we have created several plugins that extend ActiveRecord::Base with class methods, that when invoked in a model add behavior to that model. For example ... class SomeModel < ActiveRecord::Base adds_some_cool_behavior adds_another_wicked_sweet_behavior end My initial thoughts are that any model that add these behaviors "should" have this specified in their spec. With that in mind, I was leaning towards creating a module that when included inside a model spec adds the necessary specifications to ensure the behavior is there and is executing as intended. However, before proceeding too far I wanted to run it by the collective to hear your thoughts as I am sure this has been tackled by others in the community already (although google didn't yield anything noteworthy). Thanks, Anthony Broad-Crawford -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080303/8c9796e3/attachment-0001.html From mhennemeyer at googlemail.com Mon Mar 3 12:52:43 2008 From: mhennemeyer at googlemail.com (Matthias Hennemeyer) Date: Mon, 3 Mar 2008 18:52:43 +0100 Subject: [rspec-users] Rspec and plugins In-Reply-To: References: Message-ID: <5720E0AE-7DA3-4F33-ACEB-DB6DB7873BB5@googlemail.com> I would prefer two independent steps: 1) Specify (or test) the plugin so that you can trust that it works as intended. 2) Write a custom matcher (behave_in_a_cool_way) that lets you express that you want to have added some_cool_behavior to SomeModel: describe SomeModel it "should show some_cool_behavior" do SomeModel.should behave_in_a_cool_way end end This: http://stevetooke.karmatrading.co.uk/2007/8/10/simple-rails- association-matching-with-rspec may be an example. Matthias Am 03.03.2008 um 18:08 schrieb Anthony Broad-Crawford: > I have a question regarding best practices around module and plugin > testing for rails applications. In our application we have created > several plugins that extend ActiveRecord::Base with class methods, > that when invoked in a model add behavior to that model. For > example ... > > class SomeModel < ActiveRecord::Base > > adds_some_cool_behavior > adds_another_wicked_sweet_behavior > > end > > My initial thoughts are that any model that add these behaviors > "should" have this specified in their spec. With that in mind, I > was leaning towards creating a module that when included inside a > model spec adds the necessary specifications to ensure the behavior > is there and is executing as intended. However, before proceeding > too far I wanted to run it by the collective to hear your thoughts > as I am sure this has been tackled by others in the community > already (although google didn't yield anything noteworthy). > > Thanks, > Anthony Broad-Crawford > > > > _______________________________________________ > 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/20080303/f1bd9dc4/attachment-0001.html From lists at ruby-forum.com Mon Mar 3 18:17:53 2008 From: lists at ruby-forum.com (Mark Dodwell) Date: Tue, 4 Mar 2008 00:17:53 +0100 Subject: [rspec-users] Testing Plugins + Lib Code Message-ID: <546d58d7c0adaac217a4c2e783bd61ad@ruby-forum.com> Hi, I'm quite new to Rspec and I'm embarking on a new project. One thing I'm really not sure about is how to test plugins and code in your 'lib/' folder. Where would these specs actually live in the dir structure? Should you test plugins by creating specs within the plugin's dir? Or by adding a spec to the main '/specs' folder - and if so where? Any info/best practice advice greatly appreciated. ~ Mark -- Posted via http://www.ruby-forum.com/. From oli.azevedo.barnes at gmail.com Mon Mar 3 18:24:57 2008 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Mon, 3 Mar 2008 20:24:57 -0300 Subject: [rspec-users] stuck on testing validation Message-ID: <6466d9040803031524x42f2583ajb4776880b4a21fd8@mail.gmail.com> Hello, I must be doing something dumb, but here it goes... why does this work? before(:each) do @work = Work.new end #for testing validates_presence_of :title it "should require a title" do @work.title = nil @work.should_not be_valid end while this doesn't: def valid_work_attributes { :title => "guernica", :description => "lorem ipsum lorem ipsum", :date => Date.today, :category => Category.new(:name => "belle epoque") } end before(:each) do @work = Work.new end it "should require a title" do @work.attributes = valid_work_attributes.except(:title) @work.should_not be_valid end the latter example fails with "expected valid? to return false, got true" for @work.should_not be_valid doesn't make sense to me, and I've been stuck for a while already :P any help greatly appreciated, please bear with the newbie :) Oliver From pergesu at gmail.com Mon Mar 3 19:46:28 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 3 Mar 2008 16:46:28 -0800 Subject: [rspec-users] Testing Plugins + Lib Code In-Reply-To: <546d58d7c0adaac217a4c2e783bd61ad@ruby-forum.com> References: <546d58d7c0adaac217a4c2e783bd61ad@ruby-forum.com> Message-ID: <810a540e0803031646l2ff666bcj28b1523e54e3d4d6@mail.gmail.com> On Mon, Mar 3, 2008 at 3:17 PM, Mark Dodwell wrote: > Hi, > > I'm quite new to Rspec and I'm embarking on a new project. One thing I'm > really not sure about is how to test plugins and code in your 'lib/' > folder. Where would these specs actually live in the dir structure? > > Should you test plugins by creating specs within the plugin's dir? Or by > adding a spec to the main '/specs' folder - and if so where? > > Any info/best practice advice greatly appreciated. > > ~ Mark > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > For stuff in lib, I create a spec/lib dir and put my specs in there. For plugins, I use my nifty http://evang.eli.st/blog/2007/4/4/rspec_plugin-generator Pat From abroad-crawford at within3.com Mon Mar 3 22:42:36 2008 From: abroad-crawford at within3.com (Anthony Broad-Crawford) Date: Mon, 3 Mar 2008 22:42:36 -0500 Subject: [rspec-users] Matchers tutorial ... Message-ID: <16095B35-A25F-4BEA-A296-05349BED5016@within3.com> I am looking for a good a - z matchers tutorial . Anyone got a url for one? Thanks Anthony Broad-Crawford -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080303/fd652444/attachment-0001.html From dchelimsky at gmail.com Mon Mar 3 22:46:47 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 3 Mar 2008 21:46:47 -0600 Subject: [rspec-users] Matchers tutorial ... In-Reply-To: <16095B35-A25F-4BEA-A296-05349BED5016@within3.com> References: <16095B35-A25F-4BEA-A296-05349BED5016@within3.com> Message-ID: <57c63afe0803031946i63e482cdvcb7c7b420a421d9e@mail.gmail.com> On Mon, Mar 3, 2008 at 9:42 PM, Anthony Broad-Crawford wrote: > I am looking for a good a - z matchers tutorial . Anyone got a url for one? There are many. Here's mine: http://blog.davidchelimsky.net/articles/2007/02/18/custom-expectation-matchers > > Thanks > > > Anthony Broad-Crawford > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From abroad-crawford at within3.com Mon Mar 3 22:49:11 2008 From: abroad-crawford at within3.com (Anthony Broad-Crawford) Date: Mon, 3 Mar 2008 22:49:11 -0500 Subject: [rspec-users] Matchers tutorial ... In-Reply-To: <57c63afe0803031946i63e482cdvcb7c7b420a421d9e@mail.gmail.com> References: <16095B35-A25F-4BEA-A296-05349BED5016@within3.com> <57c63afe0803031946i63e482cdvcb7c7b420a421d9e@mail.gmail.com> Message-ID: <4143C646-7A2A-429D-B3A7-3E348FB1DFD8@within3.com> thank you! On Mar 3, 2008, at 10:46 PM, David Chelimsky wrote: > On Mon, Mar 3, 2008 at 9:42 PM, Anthony Broad-Crawford > wrote: >> I am looking for a good a - z matchers tutorial . Anyone got a url >> for one? > > There are many. Here's mine: > http://blog.davidchelimsky.net/articles/2007/02/18/custom-expectation-matchers > >> >> Thanks >> >> >> Anthony Broad-Crawford >> >> >> >> _______________________________________________ >> 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 at ruby-forum.com Tue Mar 4 00:21:26 2008 From: lists at ruby-forum.com (Namrata Tiwari) Date: Tue, 4 Mar 2008 06:21:26 +0100 Subject: [rspec-users] rspec controller action list In-Reply-To: <57c63afe0803030332y5ff467e7j7baa284813d0efb9@mail.gmail.com> References: <36a1f08323bd82582ae8b5df7e4f4072@ruby-forum.com> <57c63afe0802280605o5f0be241r522961fd5e04c55a@mail.gmail.com> <1289886a79437bf85fc8ce94a55bc4ce@ruby-forum.com> <29a0119e0802290552i44369de8u5d6f77728115d184@mail.gmail.com> <40a3a0f9880ab0dddaab44675cb0c637@ruby-forum.com> <70B93E65-D33C-430F-A3E7-7A8D50EA94A9@googlemail.com> <997cd6a508b3f825a5e1ab9c922f8a50@ruby-forum.com> <57c63afe0803030315g3f4ff229r497649dc9b7ac490@mail.gmail.com> <7317f1371334b517a72ad383e8425fed@ruby-forum.com> <57c63afe0803030332y5ff467e7j7baa284813d0efb9@mail.gmail.com> Message-ID: Here is the action - def list @articles = find_city.articles.paginate :all, :page => params[:page] , :order => "live_on DESC", :conditions => { :type_for => "blog" } end and the spec - it "should list all articles 2" do articles = mock("articles") get :list controller.should_receive(:find_city).and_return(articles) controller.should_receive(:articles) articles.should_receive(:paginate).with(:order => "live_on DESC", :conditions => { :type_for => "blog" }) response.should render_template('articles/list') end I am stubbing find_city and articles during set up before_post do controller.stub!(:find_city) controller.stub!(:articles) end Is this right? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Mar 4 00:36:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 3 Mar 2008 23:36:53 -0600 Subject: [rspec-users] rspec controller action list In-Reply-To: References: <36a1f08323bd82582ae8b5df7e4f4072@ruby-forum.com> <1289886a79437bf85fc8ce94a55bc4ce@ruby-forum.com> <29a0119e0802290552i44369de8u5d6f77728115d184@mail.gmail.com> <40a3a0f9880ab0dddaab44675cb0c637@ruby-forum.com> <70B93E65-D33C-430F-A3E7-7A8D50EA94A9@googlemail.com> <997cd6a508b3f825a5e1ab9c922f8a50@ruby-forum.com> <57c63afe0803030315g3f4ff229r497649dc9b7ac490@mail.gmail.com> <7317f1371334b517a72ad383e8425fed@ruby-forum.com> <57c63afe0803030332y5ff467e7j7baa284813d0efb9@mail.gmail.com> Message-ID: <57c63afe0803032136p7d98c14pbc6f6a662c8e22c6@mail.gmail.com> On Mon, Mar 3, 2008 at 11:21 PM, Namrata Tiwari wrote: > Here is the action - > > def list > @articles = find_city.articles.paginate :all, :page => > params[:page] , :order => "live_on DESC", :conditions => { :type_for > => "blog" } > end > > and the spec - > > it "should list all articles 2" do > articles = mock("articles") > get :list Whoa. A couple of posts ago you said the action (get :list) was the last thing. Now it's not anymore. When dealing with mocks and stubs, order is very important, which is why I asked you where the action was. Message expectations (mocks) and stub values MUST be set before the action. > controller.should_receive(:find_city).and_return(articles) The implementation is find_city.articles, so find_city needs to return something that owns articles. > controller.should_receive(:articles) This one is just wrong - it's the return value of find_city that should receive articles. > articles.should_receive(:paginate).with(:order => "live_on DESC", > :conditions => { :type_for => "blog" }) This one is right, but again, needs to happen before the action. > > response.should render_template('articles/list') This one is correct, and in the correct place (after the action). > end > > > I am stubbing find_city and articles during set up > > before_post do > controller.stub!(:find_city) Here find_city will not return anything, so it'll blow up on find_city.articles .... > controller.stub!(:articles) > end > > Is this right? Here's what you want: http://pastie.caboo.se/161001 HTH, David > -- > > > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From george at benevolentcode.com Tue Mar 4 00:41:52 2008 From: george at benevolentcode.com (George Anderson) Date: Tue, 4 Mar 2008 00:41:52 -0500 Subject: [rspec-users] Pretty story output for non-Rails project Message-ID: <782d66f30803032141o7d2d8ca1v56f24573a0eeb55d@mail.gmail.com> I'm taking my first fledgling steps driving a new ruby (non-rails) project with BDD. I've got a (test) story working. However, when I run the story in TextMate (via command-r), the output is plain text. See: http://skitch.com/georgeanderson/8grg/run-examples How do I get the output to look pretty (formatted)? rspec-1.1.3 OS X 10.5.2 TextMate v1.5.7 (1455) Thanks, /g -- George Anderson BenevolentCode LLC O: (410) 461-7553 C: (410) 218-5185 george at benevolentcode.com From dchelimsky at gmail.com Tue Mar 4 01:19:29 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Mar 2008 00:19:29 -0600 Subject: [rspec-users] Pretty story output for non-Rails project In-Reply-To: <782d66f30803032141o7d2d8ca1v56f24573a0eeb55d@mail.gmail.com> References: <782d66f30803032141o7d2d8ca1v56f24573a0eeb55d@mail.gmail.com> Message-ID: <57c63afe0803032219q3f6f532dmce3f30caa2f320b0@mail.gmail.com> On Mon, Mar 3, 2008 at 11:41 PM, George Anderson wrote: > I'm taking my first fledgling steps driving a new ruby (non-rails) > project with BDD. I've got a (test) story working. However, when I > run the story in TextMate (via command-r), the output is plain text. > > See: http://skitch.com/georgeanderson/8grg/run-examples > > How do I get the output to look pretty (formatted)? There's no textmate formatter for stories yet. In the mean time, you can do it on the command line with --format html and open the resulting file in a browser. Cheers, David > > rspec-1.1.3 > OS X 10.5.2 > TextMate v1.5.7 (1455) > > Thanks, > > /g > > -- > > George Anderson > > BenevolentCode LLC > O: (410) 461-7553 > C: (410) 218-5185 > > george at benevolentcode.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Tue Mar 4 01:42:38 2008 From: lists at ruby-forum.com (Namrata Tiwari) Date: Tue, 4 Mar 2008 07:42:38 +0100 Subject: [rspec-users] rspec controller action list In-Reply-To: <57c63afe0803032136p7d98c14pbc6f6a662c8e22c6@mail.gmail.com> References: <36a1f08323bd82582ae8b5df7e4f4072@ruby-forum.com> <57c63afe0802280605o5f0be241r522961fd5e04c55a@mail.gmail.com> <1289886a79437bf85fc8ce94a55bc4ce@ruby-forum.com> <29a0119e0802290552i44369de8u5d6f77728115d184@mail.gmail.com> <40a3a0f9880ab0dddaab44675cb0c637@ruby-forum.com> <70B93E65-D33C-430F-A3E7-7A8D50EA94A9@googlemail.com> <997cd6a508b3f825a5e1ab9c922f8a50@ruby-forum.com> <57c63afe0803030315g3f4ff229r497649dc9b7ac490@mail.gmail.com> <7317f1371334b517a72ad383e8425fed@ruby-forum.com> <57c63afe0803030332y5ff467e7j7baa284813d0efb9@mail.gmail.com> <57c63afe0803032136p7d98c14pbc6f6a662c8e22c6@mail.gmail.com> Message-ID: Followed your example! Still getting the following error - Spec::Mocks::MockExpectationError in 'ArticlesController should list all article s' Mock 'ArticlesController' expected :find_city with (any args) once, but received it 0 times spec/controllers/articles_controller_spec.rb:3: Thanks, Namrata -- Posted via http://www.ruby-forum.com/. From cwdinfo at gmail.com Tue Mar 4 02:03:09 2008 From: cwdinfo at gmail.com (s.ross) Date: Mon, 3 Mar 2008 23:03:09 -0800 Subject: [rspec-users] Pretty story output for non-Rails project In-Reply-To: <57c63afe0803032219q3f6f532dmce3f30caa2f320b0@mail.gmail.com> References: <782d66f30803032141o7d2d8ca1v56f24573a0eeb55d@mail.gmail.com> <57c63afe0803032219q3f6f532dmce3f30caa2f320b0@mail.gmail.com> Message-ID: <24E8AEAD-6829-49BF-9A47-337261DD0DCB@gmail.com> On Mar 3, 2008, at 10:19 PM, David Chelimsky wrote: > In the mean time, you > can do it on the command line with --format html and open the > resulting file in a browser. Er... stories? How do you format story output as html? From aslak.hellesoy at gmail.com Tue Mar 4 02:45:41 2008 From: aslak.hellesoy at gmail.com (=?UTF-8?Q?Aslak_Helles=C3=B8y?=) Date: Tue, 4 Mar 2008 08:45:41 +0100 Subject: [rspec-users] Pretty story output for non-Rails project In-Reply-To: <24E8AEAD-6829-49BF-9A47-337261DD0DCB@gmail.com> References: <782d66f30803032141o7d2d8ca1v56f24573a0eeb55d@mail.gmail.com> <57c63afe0803032219q3f6f532dmce3f30caa2f320b0@mail.gmail.com> <24E8AEAD-6829-49BF-9A47-337261DD0DCB@gmail.com> Message-ID: <4AF92DB0-BAF9-41E6-904F-B51B129F8C88@gmail.com> Like David said. Not working for you? Aslak On Mar 4, 2008, at 8:03, "s.ross" wrote: > On Mar 3, 2008, at 10:19 PM, David Chelimsky wrote: > >> In the mean time, you >> can do it on the command line with --format html and open the >> resulting file in a browser. > > Er... stories? How do you format story output as html? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Tue Mar 4 07:11:17 2008 From: lists at ruby-forum.com (Namrata Tiwari) Date: Tue, 4 Mar 2008 13:11:17 +0100 Subject: [rspec-users] stuck on testing validation In-Reply-To: <6466d9040803031524x42f2583ajb4776880b4a21fd8@mail.gmail.com> References: <6466d9040803031524x42f2583ajb4776880b4a21fd8@mail.gmail.com> Message-ID: Here is a very good example by Luke, which I think you should follow - http://www.lukeredpath.co.uk/2006/8/29/developing-a-rails-model-using-bdd-and-rspec-part-1 fyi, Namrata -- Posted via http://www.ruby-forum.com/. From mlangenberg at gmail.com Tue Mar 4 08:13:26 2008 From: mlangenberg at gmail.com (Matthijs Langenberg) Date: Tue, 4 Mar 2008 14:13:26 +0100 Subject: [rspec-users] What is your workflow? Or how to use the story runner the right way. Message-ID: <27c0ac6d0803040513l7b4fba44nfb3b314aae1bdcc3@mail.gmail.com> I really would like to know how people are using the Story and Example runner to write their software.It would be great to get some direction on it, because I think I'm missing some points. Taking the outside-in approach in thought: At first we write a high-level customer-facing story, this story fails. Then we start using mocks at object level to use them as a design tool, and so we implement the different layers of the system. After implementing the inner layer, the story should pass. When that happens we could remove the mocks and replace it with calls to the real code, making the suite less brittle (except for calls to external services/databases/file systems). So if the story passes all acceptance tests, why is there a need for examples at a lower level? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080304/84d32aee/attachment.html From ed.howland at gmail.com Tue Mar 4 08:18:01 2008 From: ed.howland at gmail.com (Ed Howland) Date: Tue, 4 Mar 2008 07:18:01 -0600 Subject: [rspec-users] Pretty story output for non-Rails project In-Reply-To: <57c63afe0803032219q3f6f532dmce3f30caa2f320b0@mail.gmail.com> References: <782d66f30803032141o7d2d8ca1v56f24573a0eeb55d@mail.gmail.com> <57c63afe0803032219q3f6f532dmce3f30caa2f320b0@mail.gmail.com> Message-ID: <3df642dd0803040518q11bdba2fj1eac2a73f467669b@mail.gmail.com> On Tue, Mar 4, 2008 at 12:19 AM, David Chelimsky wrote: > On Mon, Mar 3, 2008 at 11:41 PM, George Anderson > wrote: > > I'm taking my first fledgling steps driving a new ruby (non-rails) > > project with BDD. I've got a (test) story working. However, when I > > run the story in TextMate (via command-r), the output is plain text. > > > > See: http://skitch.com/georgeanderson/8grg/run-examples > > > > How do I get the output to look pretty (formatted)? > > There's no textmate formatter for stories yet. In the mean time, you > can do it on the command line with --format html and open the > resulting file in a browser. > > Cheers, > David > David, Is this something in trunk? all.rb does not except any arguments, and there is no argument to the run command for this. Also, the svn server seems to be offline this morning. Ed > > > > > > rspec-1.1.3 > > OS X 10.5.2 > > TextMate v1.5.7 (1455) > > > > Thanks, > > > > /g > > > > -- > > > > George Anderson > > > > BenevolentCode LLC > > O: (410) 461-7553 > > C: (410) 218-5185 > > > > george at benevolentcode.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 > -- Ed Howland http://greenprogrammer.blogspot.com "The information transmitted is intended only for the person or entity to which it is addressed and may contain proprietary, confidential and/or legally privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers." From aslak.hellesoy at gmail.com Tue Mar 4 08:24:15 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 4 Mar 2008 14:24:15 +0100 Subject: [rspec-users] Pretty story output for non-Rails project In-Reply-To: <3df642dd0803040518q11bdba2fj1eac2a73f467669b@mail.gmail.com> References: <782d66f30803032141o7d2d8ca1v56f24573a0eeb55d@mail.gmail.com> <57c63afe0803032219q3f6f532dmce3f30caa2f320b0@mail.gmail.com> <3df642dd0803040518q11bdba2fj1eac2a73f467669b@mail.gmail.com> Message-ID: <8d961d900803040524k37da5bdw58000689a89b0cb0@mail.gmail.com> On Tue, Mar 4, 2008 at 2:18 PM, Ed Howland wrote: > On Tue, Mar 4, 2008 at 12:19 AM, David Chelimsky wrote: > > On Mon, Mar 3, 2008 at 11:41 PM, George Anderson > > wrote: > > > I'm taking my first fledgling steps driving a new ruby (non-rails) > > > project with BDD. I've got a (test) story working. However, when I > > > run the story in TextMate (via command-r), the output is plain text. > > > > > > See: http://skitch.com/georgeanderson/8grg/run-examples > > > > > > How do I get the output to look pretty (formatted)? > > > > There's no textmate formatter for stories yet. In the mean time, you > > can do it on the command line with --format html and open the > > resulting file in a browser. > > > > Cheers, > > David > > > > David, > > Is this something in trunk? all.rb does not except any arguments, and > there is no argument to the run command for this. Also, the svn server > seems to be offline this morning. > This is in the latest release. Just pass --format html on the ocmmand line. ARGS is read by one of the internal files in RSpec - not all.rb. Try --help too. Aslak > > Ed > > > > > > > > > > > > rspec-1.1.3 > > > OS X 10.5.2 > > > TextMate v1.5.7 (1455) > > > > > > Thanks, > > > > > > /g > > > > > > -- > > > > > > George Anderson > > > > > > BenevolentCode LLC > > > O: (410) 461-7553 > > > C: (410) 218-5185 > > > > > > george at benevolentcode.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 > > > > > > -- > Ed Howland > http://greenprogrammer.blogspot.com > "The information transmitted is intended only for the person or entity > to which it is addressed and may contain proprietary, confidential > and/or legally privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance > upon, this information by persons or entities other than the intended > recipient is prohibited. If you received this in error, please contact > the sender and delete the material from all computers." > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From chris at edendevelopment.co.uk Tue Mar 4 08:43:09 2008 From: chris at edendevelopment.co.uk (Chris Parsons) Date: Tue, 4 Mar 2008 13:43:09 +0000 Subject: [rspec-users] What is your workflow? Or how to use the story runner the right way. In-Reply-To: <27c0ac6d0803040513l7b4fba44nfb3b314aae1bdcc3@mail.gmail.com> References: <27c0ac6d0803040513l7b4fba44nfb3b314aae1bdcc3@mail.gmail.com> Message-ID: On 4 Mar 2008, at 13:13, Matthijs Langenberg wrote: > Taking the outside-in approach in thought: > > At first we write a high-level customer-facing story, this story > fails. > Then we start using mocks at object level to use them as a design > tool, > and so we implement the different layers of the system. > After implementing the inner layer, the story should pass. > When that happens we could remove the mocks and replace it with > calls to the real code, making the suite less brittle (except for > calls to external services/databases/file systems). Don't use mocks at the story level. IMHO stories should always be using the full stack. This includes your database, but you might be permitted to exclude external services such as credit card billing systems. However, if you can set up a sandbox to test against (such as the Paypal sandbox), all to the good. We proceed based on two principles: A failure in a story means you change specs not code. A failure in a spec means you change the code. This is how we do it (assuming a rails application): 1. Write customer story, all steps are pending: Scenario: Viewing the front page When I view the front page Then I see the text 'welcome to the app' 2. Write the first step in the story: When "I view the front page" do get "/" end This then fails, as I don't have a front page yet! 3. Pay attention to the error given by the story, and fix that *by writing a spec*. In this case it'll be complaining that the controller doesn't exist. At this point I drop down to the specs as a failing story means we need a spec: describe MainController do end 4. Make your specs pass. 'rake spec' then fails, as MainController doesn't exist. In this case, I add a controller and a route (by hand, none of that scaffold business): class MainController < ApplicationController end 5. Run the story again if you need to, and use that as a guide to write more specs. Repeat steps 4 and 5. To continue the example - in this case it'll probably complain about no index action: describe MainController do it "should handle an index action" do get :index end end and then, to fix the spec: class MainController < ApplicationController def index end end Then it'll most likely complain about not having an index.html.erb. Because controller specs don't render the page, you'll need an an index.html.erb_spec.rb to test the view properly. And so on. Sound like a lot of work, but given practice you can zip through these steps very quickly. You also get a free 'focusing tool' (lose sight of where you are? just run the story test and write more specs). Hope this is helpful. Maybe I should write up an extended example as a blog post, including mocking etc, as it seems to come up a lot. Thanks Chris PS: Excuse the spelling/coding mistakes in the (untested) code :) Corrections and comments as to the methodology here most welcome. -- Chris Parsons Managing Director Eden Development (UK) Ltd chris at edendevelopment.co.uk www.edendevelopment.co.uk 0845 0097 094 po box 425, winchester, so23 0wy, uk Map: http://pininthemap.com/edendevelopment Tried Pin in the Map? Mark a map location, add text, send to friends. http://pininthemap.com This electronic message and all contents contain information from the sender which may be privileged, confidential or otherwise protected from disclosure. The information is intended to be for the addressee(s) only. If you are not an addressee, any copying, disclosure, distribution or use of the contents of this message is prohibited. If you have received this electronic message in error, please notify the sender by reply e-mail and destroy the original message and all copies. The sender does not accept liability for any errors or omissions. From dchelimsky at gmail.com Tue Mar 4 09:13:50 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Mar 2008 08:13:50 -0600 Subject: [rspec-users] What is your workflow? Or how to use the story runner the right way. In-Reply-To: <27c0ac6d0803040513l7b4fba44nfb3b314aae1bdcc3@mail.gmail.com> References: <27c0ac6d0803040513l7b4fba44nfb3b314aae1bdcc3@mail.gmail.com> Message-ID: <57c63afe0803040613xa3e6fd8wdc4a4a227ec494bc@mail.gmail.com> On Tue, Mar 4, 2008 at 7:13 AM, Matthijs Langenberg wrote: > I really would like to know how people are using the Story and Example > runner to write their software. > It would be great to get some direction on it, because I think I'm missing > some points. > > Taking the outside-in approach in thought: > > At first we write a high-level customer-facing story, this story fails. > Then we start using mocks at object level to use them as a design tool, > and so we implement the different layers of the system. > After implementing the inner layer, the story should pass. > When that happens we could remove the mocks and replace it with calls to the > real code, I do this sometimes - removing the mocks - as long as the objects are trivial to set up and they don't have dependencies that I don't want to expose. There's no one way to do this, and I'll sometimes remove mocks and reintroduce them over the life of a project. > making the suite less brittle What brittle means is a bit subjective here. Just a lengthy conversation about this in irc last night. The guy with whom I was chatting prefers to not use mocks because he'd rather see a change cause a bunch of lower level examples to fail than stories. From what I can tell, he doesn't like to use mocks even temporarily, in process. His approach has the benefit that you learn about side effects of your changes faster, and the cost that it means you sometimes have more "red bar" to wade through while you get things right. My approach has the benefit that you can address side effects of your changes with a green bar helping you know that the smaller bits (objects and methods) are functioning, and the cost that you sometimes don't learn about side effects until you run your stories (or integration suite). Neither solution is perfect. You just have to pick your poison. > (except for calls to external > services/databases/file systems). This is a funny thing about ruby, specifically rails. One of the hallmarks of OO is a high level of decoupling - especially decoupling your code from 3rd party code through adapters. There are a couple of reasons for this. One is that having an adapter lets you write exactly the code that you want to write throughout most of your system, rather than being subject to the naming conventions of the 3rd party library that might clash with those in your system or even with your domain. The other is that if you decide to switch to a different library, you're pretty well hosed unless you have adapters. If you look at the competitors to ActiveRecord, like Og and Datamapper, they are all VERY similar syntactically. Why? Two reasons I think. One is that AR got a lot of things right from a domain perspective. The other is that calls to AR internals have leaked out to a lot of controllers and even views: Person.find(:all, :conditions => ['active = ?', true]) In spite of guidelines all over the web that say that this should be wrapped in a #find_active method in the model, these sorts of things pop up all over the place anyhow. > So if the story passes all acceptance tests, why is there a need for > examples at a lower level? So that you can get things working one step at a time, and then change things as needed one step at a time, with green bars keeping you sane, stress free, and even happy all the way through. HTH, David From dchelimsky at gmail.com Tue Mar 4 09:17:30 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Mar 2008 08:17:30 -0600 Subject: [rspec-users] What is your workflow? Or how to use the story runner the right way. In-Reply-To: <57c63afe0803040613xa3e6fd8wdc4a4a227ec494bc@mail.gmail.com> References: <27c0ac6d0803040513l7b4fba44nfb3b314aae1bdcc3@mail.gmail.com> <57c63afe0803040613xa3e6fd8wdc4a4a227ec494bc@mail.gmail.com> Message-ID: <57c63afe0803040617h9ce5f15sa991f7337a2b8133@mail.gmail.com> On Tue, Mar 4, 2008 at 8:13 AM, David Chelimsky wrote: > On Tue, Mar 4, 2008 at 7:13 AM, Matthijs Langenberg > wrote: > > I really would like to know how people are using the Story and Example > > runner to write their software. > > It would be great to get some direction on it, because I think I'm missing > > some points. > > > > Taking the outside-in approach in thought: > > > > At first we write a high-level customer-facing story, this story fails. > > Then we start using mocks at object level to use them as a design tool, > > and so we implement the different layers of the system. > > After implementing the inner layer, the story should pass. > > When that happens we could remove the mocks and replace it with calls to the > > real code, > > I do this sometimes - removing the mocks - as long as the objects are > trivial to set up and they don't have dependencies that I don't want > to expose. There's no one way to do this, and I'll sometimes remove > mocks and reintroduce them over the life of a project. > > > > making the suite less brittle > > What brittle means is a bit subjective here. Just a lengthy > conversation about this in irc last night. The guy with whom I was > chatting prefers to not use mocks because he'd rather see a change > cause a bunch of lower level examples to fail than stories. From what > I can tell, he doesn't like to use mocks even temporarily, in process. > > His approach has the benefit that you learn about side effects of your > changes faster, and the cost that it means you sometimes have more > "red bar" to wade through while you get things right. > > My approach has the benefit that you can address side effects of your > changes with a green bar helping you know that the smaller bits > (objects and methods) are functioning, and the cost that you sometimes > don't learn about side effects until you run your stories (or > integration suite). > > Neither solution is perfect. You just have to pick your poison. > > > > (except for calls to external > > services/databases/file systems). > > This is a funny thing about ruby, specifically rails. > > One of the hallmarks of OO is a high level of decoupling - especially > decoupling your code from 3rd party code through adapters. There are a > couple of reasons for this. > > One is that having an adapter lets you write exactly the code that you > want to write throughout most of your system, rather than being > subject to the naming conventions of the 3rd party library that might > clash with those in your system or even with your domain. > > The other is that if you decide to switch to a different library, > you're pretty well hosed unless you have adapters. If you look at the > competitors to ActiveRecord, like Og and Datamapper, they are all VERY > similar syntactically. Why? Two reasons I think. One is that AR got a > lot of things right from a domain perspective. The other is that calls > to AR internals have leaked out to a lot of controllers and even > views: > > Person.find(:all, :conditions => ['active = ?', true]) > > In spite of guidelines all over the web that say that this should be > wrapped in a #find_active method in the model, these sorts of things > pop up all over the place anyhow. Finishing up that thought - find_active is an adapter - just at the method level instead of the object level. > > So if the story passes all acceptance tests, why is there a need for > > examples at a lower level? > > So that you can get things working one step at a time, and then change > things as needed one step at a time, with green bars keeping you sane, > stress free, and even happy all the way through. > > HTH, > David > From ed.howland at gmail.com Tue Mar 4 09:32:12 2008 From: ed.howland at gmail.com (Ed Howland) Date: Tue, 4 Mar 2008 08:32:12 -0600 Subject: [rspec-users] Pretty story output for non-Rails project In-Reply-To: <8d961d900803040524k37da5bdw58000689a89b0cb0@mail.gmail.com> References: <782d66f30803032141o7d2d8ca1v56f24573a0eeb55d@mail.gmail.com> <57c63afe0803032219q3f6f532dmce3f30caa2f320b0@mail.gmail.com> <3df642dd0803040518q11bdba2fj1eac2a73f467669b@mail.gmail.com> <8d961d900803040524k37da5bdw58000689a89b0cb0@mail.gmail.com> Message-ID: <3df642dd0803040632s793d725byfd4509202d6312ed@mail.gmail.com> On Tue, Mar 4, 2008 at 7:24 AM, aslak hellesoy wrote: > > This is in the latest release. Just pass --format html on the ocmmand > line. ARGS is read by one of the internal files in RSpec - not all.rb. > Try --help too. > > Aslak Thanks, Aslak. Seems I was consuming ARGV prematurely in my own story runner. The output seems a bit crude. I have to drop the output in public and copy the css there, or put it in vendors/plugins/rspec/story_server/prototype. Also, I can't seem to get the summarized output like the example in there. Ed -- Ed Howland http://greenprogrammer.blogspot.com From aslak.hellesoy at gmail.com Tue Mar 4 10:24:43 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 4 Mar 2008 16:24:43 +0100 Subject: [rspec-users] Pretty story output for non-Rails project In-Reply-To: <3df642dd0803040632s793d725byfd4509202d6312ed@mail.gmail.com> References: <782d66f30803032141o7d2d8ca1v56f24573a0eeb55d@mail.gmail.com> <57c63afe0803032219q3f6f532dmce3f30caa2f320b0@mail.gmail.com> <3df642dd0803040518q11bdba2fj1eac2a73f467669b@mail.gmail.com> <8d961d900803040524k37da5bdw58000689a89b0cb0@mail.gmail.com> <3df642dd0803040632s793d725byfd4509202d6312ed@mail.gmail.com> Message-ID: <8d961d900803040724i53bf6c05xbc201cecbda4984e@mail.gmail.com> On Tue, Mar 4, 2008 at 3:32 PM, Ed Howland wrote: > On Tue, Mar 4, 2008 at 7:24 AM, aslak hellesoy wrote: > > > > > This is in the latest release. Just pass --format html on the ocmmand > > line. ARGS is read by one of the internal files in RSpec - not all.rb. > > Try --help too. > > > > Aslak > > Thanks, Aslak. Seems I was consuming ARGV prematurely in my own story runner. > > The output seems a bit crude. I have to drop the output in public and > copy the css there, or put it in > vendors/plugins/rspec/story_server/prototype. > > Also, I can't seem to get the summarized output like the example in there. > Yeah, it's only a start. Patches are welcome as usual. Aslak > Ed > > -- > > Ed Howland > http://greenprogrammer.blogspot.com > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Tue Mar 4 11:43:01 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 4 Mar 2008 08:43:01 -0800 Subject: [rspec-users] What is your workflow? Or how to use the story runner the right way. In-Reply-To: <57c63afe0803040613xa3e6fd8wdc4a4a227ec494bc@mail.gmail.com> References: <27c0ac6d0803040513l7b4fba44nfb3b314aae1bdcc3@mail.gmail.com> <57c63afe0803040613xa3e6fd8wdc4a4a227ec494bc@mail.gmail.com> Message-ID: <810a540e0803040843o5a082292u67e67826748bc727@mail.gmail.com> On Tue, Mar 4, 2008 at 6:13 AM, David Chelimsky wrote: > What brittle means is a bit subjective here. Just a lengthy > conversation about this in irc last night. The guy with whom I was > chatting prefers to not use mocks because he'd rather see a change > cause a bunch of lower level examples to fail than stories. Do you happen to have a log of that convo? Pat From dchelimsky at gmail.com Tue Mar 4 11:46:11 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Mar 2008 10:46:11 -0600 Subject: [rspec-users] What is your workflow? Or how to use the story runner the right way. In-Reply-To: <810a540e0803040843o5a082292u67e67826748bc727@mail.gmail.com> References: <27c0ac6d0803040513l7b4fba44nfb3b314aae1bdcc3@mail.gmail.com> <57c63afe0803040613xa3e6fd8wdc4a4a227ec494bc@mail.gmail.com> <810a540e0803040843o5a082292u67e67826748bc727@mail.gmail.com> Message-ID: <57c63afe0803040846q2dc3a2k8bd695c8e2a2be86@mail.gmail.com> On Tue, Mar 4, 2008 at 10:43 AM, Pat Maddox wrote: > On Tue, Mar 4, 2008 at 6:13 AM, David Chelimsky wrote: > > > What brittle means is a bit subjective here. Just a lengthy > > conversation about this in irc last night. The guy with whom I was > > chatting prefers to not use mocks because he'd rather see a change > > cause a bunch of lower level examples to fail than stories. > > Do you happen to have a log of that convo? It was in caboose - are those public? > > Pat > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mhennemeyer at googlemail.com Tue Mar 4 11:51:15 2008 From: mhennemeyer at googlemail.com (Matthias Hennemeyer) Date: Tue, 4 Mar 2008 17:51:15 +0100 Subject: [rspec-users] rspec vs. test::more Message-ID: <68F9669F-5D69-415E-96CD-B0A679DC0E0C@googlemail.com> Hey all, you HAVE to read this blog post: http://blog.jrock.us/articles/RSpec%20vs.%20Test::More.pod#comments My favorite parts are: 1) ... some rspec code ... > For the sake of comparison lets translate this directly into perl: ... some perl code ... 2) >First, notice that the rspec-version isn't actually ruby code. It's not any real language. For the sake of comparison i have translated this blog post in Amiga Assembler and investigated that its actually a cheat for MonkeyIsland (SMI) . Cheers From pergesu at gmail.com Tue Mar 4 12:11:26 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 4 Mar 2008 09:11:26 -0800 Subject: [rspec-users] What is your workflow? Or how to use the story runner the right way. In-Reply-To: <57c63afe0803040846q2dc3a2k8bd695c8e2a2be86@mail.gmail.com> References: <27c0ac6d0803040513l7b4fba44nfb3b314aae1bdcc3@mail.gmail.com> <57c63afe0803040613xa3e6fd8wdc4a4a227ec494bc@mail.gmail.com> <810a540e0803040843o5a082292u67e67826748bc727@mail.gmail.com> <57c63afe0803040846q2dc3a2k8bd695c8e2a2be86@mail.gmail.com> Message-ID: <810a540e0803040911i467aac50v5af6340a0921f8e5@mail.gmail.com> On Tue, Mar 4, 2008 at 8:46 AM, David Chelimsky wrote: > > On Tue, Mar 4, 2008 at 10:43 AM, Pat Maddox wrote: > > On Tue, Mar 4, 2008 at 6:13 AM, David Chelimsky wrote: > > > > > What brittle means is a bit subjective here. Just a lengthy > > > conversation about this in irc last night. The guy with whom I was > > > chatting prefers to not use mocks because he'd rather see a change > > > cause a bunch of lower level examples to fail than stories. > > > > Do you happen to have a log of that convo? > > It was in caboose - are those public? Nope From cwdinfo at gmail.com Tue Mar 4 12:11:26 2008 From: cwdinfo at gmail.com (s.ross) Date: Tue, 4 Mar 2008 09:11:26 -0800 Subject: [rspec-users] Pretty story output for non-Rails project In-Reply-To: <8d961d900803040524k37da5bdw58000689a89b0cb0@mail.gmail.com> References: <782d66f30803032141o7d2d8ca1v56f24573a0eeb55d@mail.gmail.com> <57c63afe0803032219q3f6f532dmce3f30caa2f320b0@mail.gmail.com> <3df642dd0803040518q11bdba2fj1eac2a73f467669b@mail.gmail.com> <8d961d900803040524k37da5bdw58000689a89b0cb0@mail.gmail.com> Message-ID: <7B14FCE3-7789-48B2-BE9B-52025666057E@gmail.com> On Mar 4, 2008, at 5:24 AM, aslak hellesoy wrote: > This is in the latest release. Just pass --format html on the ocmmand > line. ARGS is read by one of the internal files in RSpec - not all.rb. > Try --help too. > > Aslak I must be dense: RSpec-1.1.3 (build 20080131122909) - BDD for Ruby ruby stories/all.rb --format html and this outputs text. Where would the html go? From aslak.hellesoy at gmail.com Tue Mar 4 12:26:10 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 4 Mar 2008 18:26:10 +0100 Subject: [rspec-users] Pretty story output for non-Rails project In-Reply-To: <7B14FCE3-7789-48B2-BE9B-52025666057E@gmail.com> References: <782d66f30803032141o7d2d8ca1v56f24573a0eeb55d@mail.gmail.com> <57c63afe0803032219q3f6f532dmce3f30caa2f320b0@mail.gmail.com> <3df642dd0803040518q11bdba2fj1eac2a73f467669b@mail.gmail.com> <8d961d900803040524k37da5bdw58000689a89b0cb0@mail.gmail.com> <7B14FCE3-7789-48B2-BE9B-52025666057E@gmail.com> Message-ID: <8d961d900803040926y59a6a5dv12d6ae57000190b3@mail.gmail.com> On Tue, Mar 4, 2008 at 6:11 PM, s.ross wrote: > On Mar 4, 2008, at 5:24 AM, aslak hellesoy wrote: > > > This is in the latest release. Just pass --format html on the ocmmand > > line. ARGS is read by one of the internal files in RSpec - not all.rb. > > Try --help too. > > > > Aslak > > I must be dense: > > RSpec-1.1.3 (build 20080131122909) - BDD for Ruby > > ruby stories/all.rb --format html > > and this outputs text. Where would the html go? > I forgot - this is an old bug - not working with rails, only "vanilla" http://rspec.lighthouseapp.com/projects/5645/tickets/113-13547-story-runner-html-formatted-output Aslak > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cwdinfo at gmail.com Tue Mar 4 12:52:41 2008 From: cwdinfo at gmail.com (s.ross) Date: Tue, 4 Mar 2008 09:52:41 -0800 Subject: [rspec-users] Pretty story output for non-Rails project In-Reply-To: <8d961d900803040926y59a6a5dv12d6ae57000190b3@mail.gmail.com> References: <782d66f30803032141o7d2d8ca1v56f24573a0eeb55d@mail.gmail.com> <57c63afe0803032219q3f6f532dmce3f30caa2f320b0@mail.gmail.com> <3df642dd0803040518q11bdba2fj1eac2a73f467669b@mail.gmail.com> <8d961d900803040524k37da5bdw58000689a89b0cb0@mail.gmail.com> <7B14FCE3-7789-48B2-BE9B-52025666057E@gmail.com> <8d961d900803040926y59a6a5dv12d6ae57000190b3@mail.gmail.com> Message-ID: <0ECB8EDB-3FF9-42CF-9908-93AA70953181@gmail.com> On Mar 4, 2008, at 9:26 AM, aslak hellesoy wrote: > I forgot - this is an old bug - not working with rails, only "vanilla" > http://rspec.lighthouseapp.com/projects/5645/tickets/113-13547-story-runner-html-formatted-output Ok, I feel a little less dense now :) From coreyhaines at gmail.com Tue Mar 4 15:04:50 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Tue, 4 Mar 2008 15:04:50 -0500 Subject: [rspec-users] textmate bundle Message-ID: <6bdacb70803041204g4814bc43p4bf823cebab10429@mail.gmail.com> Hi, I'm just getting e set up on my machine, and I was wondering if someone could point me to the current rspec bundle for textmate? I googled and found a million of them, I think. Thanks. -Corey -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080304/3484d010/attachment.html From dchelimsky at gmail.com Tue Mar 4 15:13:46 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 4 Mar 2008 14:13:46 -0600 Subject: [rspec-users] textmate bundle In-Reply-To: <6bdacb70803041204g4814bc43p4bf823cebab10429@mail.gmail.com> References: <6bdacb70803041204g4814bc43p4bf823cebab10429@mail.gmail.com> Message-ID: <57c63afe0803041213x53d2aa77q20aa531c94e128f1@mail.gmail.com> On Tue, Mar 4, 2008 at 2:04 PM, Corey Haines wrote: > Hi, > > I'm just getting e set up on my machine, and I was wondering if someone > could point me to the current rspec bundle for textmate? I googled and found > a million of them, I think. It's in the rspec repos: http://rspec.rubyforge.org/svn/trunk git://github.com/dchelimsky/rspec.git git://gitorious.org/rspec/mainline.git > > Thanks. > -Corey > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From coreyhaines at gmail.com Tue Mar 4 15:18:52 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Tue, 4 Mar 2008 15:18:52 -0500 Subject: [rspec-users] textmate bundle In-Reply-To: <57c63afe0803041213x53d2aa77q20aa531c94e128f1@mail.gmail.com> References: <6bdacb70803041204g4814bc43p4bf823cebab10429@mail.gmail.com> <57c63afe0803041213x53d2aa77q20aa531c94e128f1@mail.gmail.com> Message-ID: <6bdacb70803041218v7cc09156sc0148871b78b6048@mail.gmail.com> Thanks, David. On Tue, Mar 4, 2008 at 3:13 PM, David Chelimsky wrote: > On Tue, Mar 4, 2008 at 2:04 PM, Corey Haines > wrote: > > Hi, > > > > I'm just getting e set up on my machine, and I was wondering if someone > > could point me to the current rspec bundle for textmate? I googled and > found > > a million of them, I think. > > It's in the rspec repos: > > http://rspec.rubyforge.org/svn/trunk > git://github.com/dchelimsky/rspec.git > git://gitorious.org/rspec/mainline.git > > > > > Thanks. > > -Corey > > > > -- > > http://www.coreyhaines.com > > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > > 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 > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080304/31114379/attachment.html From korny at sietsma.com Tue Mar 4 15:22:54 2008 From: korny at sietsma.com (Korny Sietsma) Date: Wed, 5 Mar 2008 07:22:54 +1100 Subject: [rspec-users] rspec vs. test::more In-Reply-To: <68F9669F-5D69-415E-96CD-B0A679DC0E0C@googlemail.com> References: <68F9669F-5D69-415E-96CD-B0A679DC0E0C@googlemail.com> Message-ID: <8e15872b0803041222p6ababf83mb96fd7510853a257@mail.gmail.com> Wow - both funny and a little tragic. He really doesn't understand what "readable" means, does he? "you keep using that word - I do not think it means what you think it means" - Korny On Wed, Mar 5, 2008 at 3:51 AM, Matthias Hennemeyer < mhennemeyer at googlemail.com> wrote: > Hey all, > you HAVE to read this blog post: > > http://blog.jrock.us/articles/RSpec%20vs.%20Test::More.pod#comments > > My favorite parts are: > > 1) > ... some rspec code ... > > For the sake of comparison lets translate this directly into perl: > ... some perl code ... > 2) > >First, notice that the rspec-version isn't actually ruby code. It's > not any real language. > > For the sake of comparison i have translated this blog post in Amiga > Assembler and investigated that its actually a cheat for MonkeyIsland > (SMI) . > > Cheers > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Kornelis Sietsma korny at my surname dot com kornys at gmail dot com on google chat -- kornys on skype "we do what we must, because we can" -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080305/ce4c16f7/attachment.html From coreyhaines at gmail.com Tue Mar 4 16:28:17 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Tue, 4 Mar 2008 16:28:17 -0500 Subject: [rspec-users] rspec vs. test::more In-Reply-To: <8e15872b0803041222p6ababf83mb96fd7510853a257@mail.gmail.com> References: <68F9669F-5D69-415E-96CD-B0A679DC0E0C@googlemail.com> <8e15872b0803041222p6ababf83mb96fd7510853a257@mail.gmail.com> Message-ID: <6bdacb70803041328l658dba89j71b76a997c21bed5@mail.gmail.com> I like this line: "That sounds like something I should pay you a lot of money for! Sign me up!" David, I didn't realize that I was racking up a huge monetary debt to you. -Corey On Tue, Mar 4, 2008 at 3:22 PM, Korny Sietsma wrote: > Wow - both funny and a little tragic. > He really doesn't understand what "readable" means, does he? > > "you keep using that word - I do not think it means what you think it > means" > > - Korny > > > On Wed, Mar 5, 2008 at 3:51 AM, Matthias Hennemeyer < > mhennemeyer at googlemail.com> wrote: > > > Hey all, > > you HAVE to read this blog post: > > > > http://blog.jrock.us/articles/RSpec%20vs.%20Test::More.pod#comments > > > > My favorite parts are: > > > > 1) > > ... some rspec code ... > > > For the sake of comparison lets translate this directly into perl: > > ... some perl code ... > > 2) > > >First, notice that the rspec-version isn't actually ruby code. It's > > not any real language. > > > > For the sake of comparison i have translated this blog post in Amiga > > Assembler and investigated that its actually a cheat for MonkeyIsland > > (SMI) . > > > > Cheers > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > Kornelis Sietsma korny at my surname dot com > kornys at gmail dot com on google chat -- kornys on skype > "we do what we must, because we can" > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080304/cb680ff1/attachment-0001.html From pergesu at gmail.com Tue Mar 4 17:28:47 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 4 Mar 2008 14:28:47 -0800 Subject: [rspec-users] What is your workflow? Or how to use the story runner the right way. In-Reply-To: <810a540e0803040911i467aac50v5af6340a0921f8e5@mail.gmail.com> References: <27c0ac6d0803040513l7b4fba44nfb3b314aae1bdcc3@mail.gmail.com> <57c63afe0803040613xa3e6fd8wdc4a4a227ec494bc@mail.gmail.com> <810a540e0803040843o5a082292u67e67826748bc727@mail.gmail.com> <57c63afe0803040846q2dc3a2k8bd695c8e2a2be86@mail.gmail.com> <810a540e0803040911i467aac50v5af6340a0921f8e5@mail.gmail.com> Message-ID: <810a540e0803041428o6aa78595w8ed9f40a86fa7a66@mail.gmail.com> On Tue, Mar 4, 2008 at 9:11 AM, Pat Maddox wrote: > On Tue, Mar 4, 2008 at 8:46 AM, David Chelimsky wrote: > > > > On Tue, Mar 4, 2008 at 10:43 AM, Pat Maddox wrote: > > > On Tue, Mar 4, 2008 at 6:13 AM, David Chelimsky wrote: > > > > > > > What brittle means is a bit subjective here. Just a lengthy > > > > conversation about this in irc last night. The guy with whom I was > > > > chatting prefers to not use mocks because he'd rather see a change > > > > cause a bunch of lower level examples to fail than stories. > > > > > > Do you happen to have a log of that convo? > > > > It was in caboose - are those public? > > Nope Nevermind, turns out that I work with this nutcase From pergesu at gmail.com Tue Mar 4 18:22:45 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 4 Mar 2008 15:22:45 -0800 Subject: [rspec-users] rspec vs. test::more In-Reply-To: <6bdacb70803041328l658dba89j71b76a997c21bed5@mail.gmail.com> References: <68F9669F-5D69-415E-96CD-B0A679DC0E0C@googlemail.com> <8e15872b0803041222p6ababf83mb96fd7510853a257@mail.gmail.com> <6bdacb70803041328l658dba89j71b76a997c21bed5@mail.gmail.com> Message-ID: <810a540e0803041522o71f73042o975759de8f1a72ae@mail.gmail.com> On 3/4/08, Corey Haines wrote: > I like this line: > > "That sounds like something I should pay you a lot of money for! Sign me > up!" > > David, I didn't realize that I was racking up a huge monetary debt to you. > > -Corey You'll pay up if you value your kneecaps. Pat From lists at ruby-forum.com Wed Mar 5 05:25:05 2008 From: lists at ruby-forum.com (Namrata Tiwari) Date: Wed, 5 Mar 2008 11:25:05 +0100 Subject: [rspec-users] having trouble specing an ajax request Message-ID: <00b87bf2a68372c30f941e500c91ed10@ruby-forum.com> Do I need to spec an AR. If yes, what is the best way to spec this. here is the code - def index @deals = Deal.paginate(:all, :conditions => prepare_search_conditions, :order => 'created_at DESC', :page => params[:page] ) if request.xhr? render :update do |page| page.replace_html "table", :partial => "/deals/front/listing" end end I am new to Rspec. Is this the right way? it "should list all deals" do controller.stub!(:prepare_search_conditions).and_return(true) Deal.should_receive(:paginate).with(:all, {:conditions=>true, :order=>"created_at DESC", :page=>nil}).and_return(@deals) get :list controller.expect_render(:partial => '/deals/cms/list') end Thanks, Namrata. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Mar 5 05:27:49 2008 From: lists at ruby-forum.com (Namrata Tiwari) Date: Wed, 5 Mar 2008 11:27:49 +0100 Subject: [rspec-users] having trouble specing an ajax request In-Reply-To: <00b87bf2a68372c30f941e500c91ed10@ruby-forum.com> References: <00b87bf2a68372c30f941e500c91ed10@ruby-forum.com> Message-ID: Sorry I pasted the wrong spec. Here is correct one - it "should show deals listing" do controller.stub!(:prepare_search_conditions).and_return(true) Deal.should_receive(:paginate).and_return(@deals) get :index controller.expect_render(:partial => '/deals/front/listing') end > Thanks, > Namrata. -- Posted via http://www.ruby-forum.com/. From toastkid.williams at gmail.com Wed Mar 5 05:40:10 2008 From: toastkid.williams at gmail.com (Max Williams) Date: Wed, 5 Mar 2008 10:40:10 +0000 Subject: [rspec-users] has_many_polymorphs is breaking my spec file Message-ID: Hey folks I have a bunch of classes that are polymorphs, with has_many_polymorphs (they are all 'labellable', which is similar to being 'taggable' in the acts_as_taggable scheme). I have a couple of modules, LabellableInstanceMethods and LabellableClassMethods in a file called labellable_methods.rb. The classes all get labelled with 'properties', and i set out to write the Property class first, using bdd of course. This all went fine. However, when i came to start testing that the labelling was working properly, i added the following code: POLYMORPHIC_TABLENAMES = [:instructional_objects, :resources, :lessons, :courses] #this is breaking tests currently has_many_polymorphs :labellables, :from => POLYMORPHIC_TABLENAMES, :through => :labellings, :dependent => :destroy Now, whenever i run the spec file, it bombs out as soon as it hits a reference to the Property class (at the start of my main describe block), saying "/home/jars/rails/lesson_planner/branches/max/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:249:in `load_missing_constant': Expected /home/jars/rails/lesson_planner/branches/max/app/models/property.rb to define Property (LoadError)" If i play around with the labelling system in the console, it seems to work fine: ie, the above code works 'normally', but is totally breaking the spec file. Does anyone have any ideas about this? It's driving me crazy and stopping me speccing other aspects of my labelling system. thanks max -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080305/aa9ececa/attachment.html From dchelimsky at gmail.com Wed Mar 5 08:37:09 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Mar 2008 07:37:09 -0600 Subject: [rspec-users] has_many_polymorphs is breaking my spec file In-Reply-To: References: Message-ID: <57c63afe0803050537h79c41ed1qa810f4bc55b144ed@mail.gmail.com> On Wed, Mar 5, 2008 at 4:40 AM, Max Williams wrote: > Hey folks > > I have a bunch of classes that are polymorphs, with has_many_polymorphs > (they are all 'labellable', which is similar to being 'taggable' in the > acts_as_taggable scheme). I have a couple of modules, > LabellableInstanceMethods and LabellableClassMethods in a file called > labellable_methods.rb. > > The classes all get labelled with 'properties', and i set out to write the > Property class first, using bdd of course. This all went fine. However, > when i came to start testing that the labelling was working properly, i > added the following code: > > POLYMORPHIC_TABLENAMES = [:instructional_objects, :resources, :lessons, > :courses] > #this is breaking tests currently > has_many_polymorphs :labellables, > :from => POLYMORPHIC_TABLENAMES, > :through => :labellings, > :dependent => :destroy > > Now, whenever i run the spec file, it bombs out as soon as it hits a > reference to the Property class (at the start of my main describe block), > saying > "/home/jars/rails/lesson_planner/branches/max/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:249:in > `load_missing_constant': Expected > /home/jars/rails/lesson_planner/branches/max/app/models/property.rb to > define Property (LoadError)" This error is coming from Rails. Keep in mind that RSpec wrap Rails' built-in test infrastructure. Can you try writing the same examples in test/unit and see if they work? > > If i play around with the labelling system in the console, it seems to work > fine: ie, the above code works 'normally', but is totally breaking the spec > file. > > Does anyone have any ideas about this? It's driving me crazy and stopping > me speccing other aspects of my labelling system. > > thanks > max > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From toastkid.williams at gmail.com Wed Mar 5 08:53:16 2008 From: toastkid.williams at gmail.com (Max Williams) Date: Wed, 5 Mar 2008 13:53:16 +0000 Subject: [rspec-users] has_many_polymorphs is breaking my spec file In-Reply-To: <57c63afe0803050537h79c41ed1qa810f4bc55b144ed@mail.gmail.com> References: <57c63afe0803050537h79c41ed1qa810f4bc55b144ed@mail.gmail.com> Message-ID: Hmm, the results are exactly the same, down to the error message. And, as before, if i remove the has_many_polymorphs declaration there's no problem. So its not rspec's fault. But i'm still no closer to finding out what it is about my has_many_polymorphs declaration that the tests don't like. :( On 05/03/2008, David Chelimsky wrote: > > On Wed, Mar 5, 2008 at 4:40 AM, Max Williams > wrote: > > Hey folks > > > > I have a bunch of classes that are polymorphs, with has_many_polymorphs > > (they are all 'labellable', which is similar to being 'taggable' in the > > acts_as_taggable scheme). I have a couple of modules, > > LabellableInstanceMethods and LabellableClassMethods in a file called > > labellable_methods.rb. > > > > The classes all get labelled with 'properties', and i set out to write > the > > Property class first, using bdd of course. This all went > fine. However, > > when i came to start testing that the labelling was working properly, i > > added the following code: > > > > POLYMORPHIC_TABLENAMES = [:instructional_objects, :resources, > :lessons, > > :courses] > > #this is breaking tests currently > > has_many_polymorphs :labellables, > > :from => POLYMORPHIC_TABLENAMES, > > :through => :labellings, > > :dependent => :destroy > > > > Now, whenever i run the spec file, it bombs out as soon as it hits a > > reference to the Property class (at the start of my main describe > block), > > saying > > > "/home/jars/rails/lesson_planner/branches/max/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:249:in > > `load_missing_constant': Expected > > /home/jars/rails/lesson_planner/branches/max/app/models/property.rb to > > define Property (LoadError)" > > > This error is coming from Rails. Keep in mind that RSpec wrap Rails' > built-in test infrastructure. Can you try writing the same examples in > test/unit and see if they work? > > > > > > If i play around with the labelling system in the console, it seems to > work > > fine: ie, the above code works 'normally', but is totally breaking the > spec > > file. > > > > Does anyone have any ideas about this? It's driving me crazy and > stopping > > me speccing other aspects of my labelling system. > > > > thanks > > max > > > > > > > _______________________________________________ > > 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/20080305/517b1527/attachment.html From dchelimsky at gmail.com Wed Mar 5 09:01:25 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Mar 2008 08:01:25 -0600 Subject: [rspec-users] has_many_polymorphs is breaking my spec file In-Reply-To: References: <57c63afe0803050537h79c41ed1qa810f4bc55b144ed@mail.gmail.com> Message-ID: <57c63afe0803050601l2aa292abtb4eeb9e364db31@mail.gmail.com> On Wed, Mar 5, 2008 at 7:53 AM, Max Williams wrote: > Hmm, the results are exactly the same, down to the error message. And, as > before, if i remove the has_many_polymorphs declaration there's no problem. > > So its not rspec's fault. But i'm still no closer to finding out what it is > about my has_many_polymorphs declaration that the tests don't like. :( Have you posted to the rails list? > > > > On 05/03/2008, David Chelimsky wrote: > > On Wed, Mar 5, 2008 at 4:40 AM, Max Williams > > wrote: > > > Hey folks > > > > > > I have a bunch of classes that are polymorphs, with has_many_polymorphs > > > (they are all 'labellable', which is similar to being 'taggable' in the > > > acts_as_taggable scheme). I have a couple of modules, > > > LabellableInstanceMethods and LabellableClassMethods in a file called > > > labellable_methods.rb. > > > > > > The classes all get labelled with 'properties', and i set out to write > the > > > Property class first, using bdd of course. This all went fine. > However, > > > when i came to start testing that the labelling was working properly, i > > > added the following code: > > > > > > POLYMORPHIC_TABLENAMES = [:instructional_objects, :resources, > :lessons, > > > :courses] > > > #this is breaking tests currently > > > has_many_polymorphs :labellables, > > > :from => POLYMORPHIC_TABLENAMES, > > > :through => :labellings, > > > :dependent => :destroy > > > > > > Now, whenever i run the spec file, it bombs out as soon as it hits a > > > reference to the Property class (at the start of my main describe > block), > > > saying > > > > "/home/jars/rails/lesson_planner/branches/max/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:249:in > > > `load_missing_constant': Expected > > > /home/jars/rails/lesson_planner/branches/max/app/models/property.rb to > > > define Property (LoadError)" > > > > > > This error is coming from Rails. Keep in mind that RSpec wrap Rails' > > built-in test infrastructure. Can you try writing the same examples in > > test/unit and see if they work? > > > > > > > > > > If i play around with the labelling system in the console, it seems to > work > > > fine: ie, the above code works 'normally', but is totally breaking the > spec > > > file. > > > > > > Does anyone have any ideas about this? It's driving me crazy and > stopping > > > me speccing other aspects of my labelling system. > > > > > > thanks > > > max > > > > > > > > > > > _______________________________________________ > > > 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 toastkid.williams at gmail.com Wed Mar 5 09:17:55 2008 From: toastkid.williams at gmail.com (Max Williams) Date: Wed, 5 Mar 2008 14:17:55 +0000 Subject: [rspec-users] has_many_polymorphs is breaking my spec file In-Reply-To: <57c63afe0803050601l2aa292abtb4eeb9e364db31@mail.gmail.com> References: <57c63afe0803050537h79c41ed1qa810f4bc55b144ed@mail.gmail.com> <57c63afe0803050601l2aa292abtb4eeb9e364db31@mail.gmail.com> Message-ID: no, just the ruby forum. I'll try the rails list next. thanks On 05/03/2008, David Chelimsky wrote: > > On Wed, Mar 5, 2008 at 7:53 AM, Max Williams > > wrote: > > > Hmm, the results are exactly the same, down to the error message. And, > as > > before, if i remove the has_many_polymorphs declaration there's no > problem. > > > > So its not rspec's fault. But i'm still no closer to finding out what > it is > > about my has_many_polymorphs declaration that the tests don't like. :( > > > Have you posted to the rails list? > > > > > > > > > > On 05/03/2008, David Chelimsky wrote: > > > On Wed, Mar 5, 2008 at 4:40 AM, Max Williams > > > wrote: > > > > Hey folks > > > > > > > > I have a bunch of classes that are polymorphs, with > has_many_polymorphs > > > > (they are all 'labellable', which is similar to being 'taggable' in > the > > > > acts_as_taggable scheme). I have a couple of modules, > > > > LabellableInstanceMethods and LabellableClassMethods in a file > called > > > > labellable_methods.rb. > > > > > > > > The classes all get labelled with 'properties', and i set out to > write > > the > > > > Property class first, using bdd of course. This all went fine. > > However, > > > > when i came to start testing that the labelling was working > properly, i > > > > added the following code: > > > > > > > > POLYMORPHIC_TABLENAMES = [:instructional_objects, :resources, > > :lessons, > > > > :courses] > > > > #this is breaking tests currently > > > > has_many_polymorphs :labellables, > > > > :from => POLYMORPHIC_TABLENAMES, > > > > :through => :labellings, > > > > :dependent => :destroy > > > > > > > > Now, whenever i run the spec file, it bombs out as soon as it hits a > > > > reference to the Property class (at the start of my main describe > > block), > > > > saying > > > > > > > "/home/jars/rails/lesson_planner/branches/max/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:249:in > > > > `load_missing_constant': Expected > > > > /home/jars/rails/lesson_planner/branches/max/app/models/property.rb > to > > > > define Property (LoadError)" > > > > > > > > > This error is coming from Rails. Keep in mind that RSpec wrap Rails' > > > built-in test infrastructure. Can you try writing the same examples in > > > test/unit and see if they work? > > > > > > > > > > > > > > If i play around with the labelling system in the console, it seems > to > > work > > > > fine: ie, the above code works 'normally', but is totally breaking > the > > spec > > > > file. > > > > > > > > Does anyone have any ideas about this? It's driving me crazy and > > stopping > > > > me speccing other aspects of my labelling system. > > > > > > > > thanks > > > > max > > > > > > > > > > > > > > > _______________________________________________ > > > > 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/20080305/7ea9a9ed/attachment.html From rick.denatale at gmail.com Wed Mar 5 12:28:17 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 5 Mar 2008 12:28:17 -0500 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter Message-ID: I'm wanting to write a spec that a model is applying an :order option to a find call, but I don't want to completely specify all of the find parameters. So I want to write something like this, say in a controller spec User.should_receive(:find).with(:all, hash_with_at_least(:order => 'user.name ASC')) get 'index', :sort => 'up' This ability to partially specify the contents of a hash argument seems to be generally useful, particularly for Rails, and was wondering if anyone had done this. I don't think it would be too hard. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From doug+rspecuser at netinlet.com Wed Mar 5 12:30:14 2008 From: doug+rspecuser at netinlet.com (Doug Bryant) Date: Wed, 5 Mar 2008 12:30:14 -0500 Subject: [rspec-users] mocking successive return values Message-ID: <177c686f0803050930p7479ffecia5fa670df75a4817@mail.gmail.com> I'm having a problems mocking successive return values. I don't know if I'm doing something wrong or if this is a limitation of rspec mocks. Any ideas of what I may be doing wrong? I'm trying to test the generate_quote_number method. It generates a quote number, looks to see if it is in the db already. If it is, it calls itself to try again. I want to test that it looks in the database for matching numbers until it finds one which does not exist already. ## The code def generate_quote_number quote_num = "MMQ#{self.random_string}-001" if Policy.find(:first, :conditions => ["quote_number = ?", quote_num]) quote_num = generate_quote_number end quote_num end def random_string(size=8) # return a random string end For the test, I simply lookup 3 existing quote numbers, append nil to the end (for a total of 4) ## The test it "should not generate a duplicate quote number" do existing_quote_numbers = Policy.find(:all).map{|p| p.quote_number}[0,3] @policy_service.should_receive(:random_string).with(:no_args).exactly(4).times.and_return(existing_quote_numbers.concat([nil])) @policy_service.generate_quote_number end ## The result should not generate a duplicate quote number Mock 'Service::Base' expected :random_string with (no args) 4 times, but received it once I verified "and_return" is actually returning the array rather than an individual element of the existing_quote_numbers array which makes sense, but what about this? http://rspec.rubyforge.org/svn/branches/dogfood/spec/spec/mocks/mock_spec.rb specify "should use a list of return values for successive calls" do @mock.should_receive(:multi_call).twice.with(:no_args).and_return([8, 12]) @mock.multi_call.should_equal 8 @mock.multi_call.should_equal 12 @mock.__verify end Any feedback on how to properly test this is much appreciated. Thanks, Doug -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080305/c36fbd5f/attachment.html From rick.denatale at gmail.com Wed Mar 5 12:43:45 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 5 Mar 2008 12:43:45 -0500 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter In-Reply-To: References: Message-ID: On Wed, Mar 5, 2008 at 12:28 PM, Rick DeNatale wrote: > I'm wanting to write a spec that a model is applying an :order option > to a find call, but I don't want to completely specify all of the find > parameters. > > So I want to write something like this, say in a controller spec > > User.should_receive(:find).with(:all, hash_with_at_least(:order => > 'user.name ASC')) > get 'index', :sort => 'up' > > This ability to partially specify the contents of a hash argument > seems to be generally useful, particularly for Rails, and was > wondering if anyone had done this. I don't think it would be too hard. And by the way, here's my sketch of how to do this, just looking not to reinvent the wheel: class HashWithAtLeast def initialize(aHash) @expected = aHash end def ==(other) @expected.each do |key, value| return false unless other[key] == value end true end def to_s "Hash with at least (@expected.inspect)" end end def hash_with_at_least(hash) HashWithAtLeast.new(hash) end describe HashWithAtLeast do it "should match the same hash" do hash_with_at_least(:a => 2).should == {:a => 2} end it "should match a hash with an extra key/value" do hash_with_at_least(:a => 2).should == {:a => 2, :b => 3} end it "should not match a hash with a missing key" do hash_with_at_least(:a => 2).should_not == {:b => 2} hash_with_at_least(:a => 2, :b => 3).should_not == {:a => 2} end it "should not match a hash with the wrong value for a key" do hash_with_at_least(:a => 2).should_not == {:a => 3} hash_with_at_least(:a => 2, :b => 3).should_not == {:a => 0, :b => 3} end end describe HashWithAtLeast, "in a message expectation" do before(:all) do @foo = Object.new end it "should match exact" do @foo.should_receive(:bar).with(hash_with_at_least(:a => 2)) @foo.bar(:a => 2) end it "should allow extra keys" do @foo.should_receive(:bar).with(hash_with_at_least(:a => 2)) @foo.bar(:a => 2, :b => 3) end end -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From coreyhaines at gmail.com Wed Mar 5 13:05:34 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 5 Mar 2008 13:05:34 -0500 Subject: [rspec-users] Testing that a model helper method is called Message-ID: <6bdacb70803051005i7ba9ca24t1415a008f5c18f5d@mail.gmail.com> So, I have a plugin that adds a method to ActiveRecord::Base, let's call the method is_encrypted. class MyModel < ActiveRecord::Base is_encrypted end So, my question is, how do I write a spec to show that is_encrypted is called here? I would rather not write specs that say that the behavior is there, since I have tested the behavior already in my plugin. Thanks. -Corey -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080305/606e21ff/attachment.html From pergesu at gmail.com Wed Mar 5 13:10:52 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 5 Mar 2008 10:10:52 -0800 Subject: [rspec-users] Testing that a model helper method is called In-Reply-To: <6bdacb70803051005i7ba9ca24t1415a008f5c18f5d@mail.gmail.com> References: <6bdacb70803051005i7ba9ca24t1415a008f5c18f5d@mail.gmail.com> Message-ID: <810a540e0803051010k4661202en177e6bc1ee93ae6d@mail.gmail.com> On Wed, Mar 5, 2008 at 10:05 AM, Corey Haines wrote: > So, I have a plugin that adds a method to ActiveRecord::Base, let's call the > method is_encrypted. > > class MyModel < ActiveRecord::Base > > is_encrypted > > end > > So, my question is, how do I write a spec to show that is_encrypted is > called here? I would rather not write specs that say that the behavior is > there, since I have tested the behavior already in my plugin. MyModel.should_receive(:is_encrypted) load "my_model.rb" Pat From ben at benmabey.com Wed Mar 5 13:18:37 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 05 Mar 2008 11:18:37 -0700 Subject: [rspec-users] having trouble specing an ajax request In-Reply-To: References: <00b87bf2a68372c30f941e500c91ed10@ruby-forum.com> Message-ID: <47CEE3FD.6050205@benmabey.com> Namrata Tiwari wrote: > Sorry I pasted the wrong spec. > Here is correct one - > > it "should show deals listing" do > controller.stub!(:prepare_search_conditions).and_return(true) > Deal.should_receive(:paginate).and_return(@deals) > > get :index > controller.expect_render(:partial => '/deals/front/listing') > end > > >> Thanks, >> Namrata. >> > > Try setting your headers before your get request.. Like so: @request.env["HTTP_ACCEPT"] = "application/javascript" -Ben From coreyhaines at gmail.com Wed Mar 5 13:22:27 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 5 Mar 2008 13:22:27 -0500 Subject: [rspec-users] Testing that a model helper method is called In-Reply-To: <810a540e0803051010k4661202en177e6bc1ee93ae6d@mail.gmail.com> References: <6bdacb70803051005i7ba9ca24t1415a008f5c18f5d@mail.gmail.com> <810a540e0803051010k4661202en177e6bc1ee93ae6d@mail.gmail.com> Message-ID: <6bdacb70803051022o353f50edg994eda3e2e7b2e4c@mail.gmail.com> Thanks, Pat, that appeared to work. -Corey On Wed, Mar 5, 2008 at 1:10 PM, Pat Maddox wrote: > On Wed, Mar 5, 2008 at 10:05 AM, Corey Haines > wrote: > > So, I have a plugin that adds a method to ActiveRecord::Base, let's call > the > > method is_encrypted. > > > > class MyModel < ActiveRecord::Base > > > > is_encrypted > > > > end > > > > So, my question is, how do I write a spec to show that is_encrypted is > > called here? I would rather not write specs that say that the behavior > is > > there, since I have tested the behavior already in my plugin. > > MyModel.should_receive(:is_encrypted) > load "my_model.rb" > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080305/0dafab7c/attachment.html From ben at benmabey.com Wed Mar 5 13:25:43 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 05 Mar 2008 11:25:43 -0700 Subject: [rspec-users] mocking successive return values In-Reply-To: <177c686f0803050930p7479ffecia5fa670df75a4817@mail.gmail.com> References: <177c686f0803050930p7479ffecia5fa670df75a4817@mail.gmail.com> Message-ID: <47CEE5A7.1040703@benmabey.com> Doug Bryant wrote: > I'm having a problems mocking successive return values. I don't know > if I'm doing something wrong or if this is a limitation of rspec > mocks. Any ideas of what I may be doing wrong? > > > For the test, I simply lookup 3 existing quote numbers, append nil to > the end (for a total of 4) > ## The test > it "should not generate a duplicate quote number" do > existing_quote_numbers = Policy.find(:all).map{|p| > p.quote_number}[0,3] > > @policy_service.should_receive(:random_string).with(:no_args).exactly(4).times.and_return(existing_quote_numbers.concat([nil])) > @policy_service.generate_quote_number > end > You will need to have one expectation per return. Try this: it "should not generate a duplicate quote number" do #expect Policy.find(:all).map{|p| p.quote_number}[0,3].concat([nil]).each do |existing_quote_number| @policy_service.should_receive(:random_string).with(:no_args).once.and_return(existing_quote_number)) end #when @policy_service.generate_quote_number end -Ben From cwdinfo at gmail.com Wed Mar 5 13:26:37 2008 From: cwdinfo at gmail.com (s.ross) Date: Wed, 5 Mar 2008 10:26:37 -0800 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter In-Reply-To: References: Message-ID: On Mar 5, 2008, at 9:43 AM, Rick DeNatale wrote: > And by the way, here's my sketch of how to do this, just looking not > to reinvent the wheel: Are you aware that Rails extends Hash with a few extra methods: mymac:~/rails/myproj $ script/console Loading development environment (Rails 2.0.2) >> a = {:foo=>'bar', :zoo => 'zar'} => {:foo=>"bar", :zoo=>"zar"} >> a.except(:foo) => {:zoo=>"zar"} >> What's cool about this is that you can specify a fully valid hash once in a before block, then reuse it, omitting k/v pairs in order to verify behavior of missing-value conditions. This doesn't exactly answer your need, but perhaps it will help. From dchelimsky at gmail.com Wed Mar 5 13:31:23 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Mar 2008 12:31:23 -0600 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter In-Reply-To: References: Message-ID: <2D5C0532-49A3-4B42-8098-CD25FDB3D778@gmail.com> On Mar 5, 2008, at 11:43 AM, "Rick DeNatale" wrote: > On Wed, Mar 5, 2008 at 12:28 PM, Rick DeNatale > wrote: >> I'm wanting to write a spec that a model is applying an :order option >> to a find call, but I don't want to completely specify all of the >> find >> parameters. >> >> So I want to write something like this, say in a controller spec >> >> User.should_receive(:find).with(:all, hash_with_at_least(:order => >> 'user.name ASC')) >> get 'index', :sort => 'up' I really like this idea. What about something more general that can handle the first n args too? >> >> >> This ability to partially specify the contents of a hash argument >> seems to be generally useful, particularly for Rails, and was >> wondering if anyone had done this. I don't think it would be too >> hard. > > And by the way, here's my sketch of how to do this, just looking not > to reinvent the wheel: > > class HashWithAtLeast > > def initialize(aHash) > @expected = aHash > end > > def ==(other) > @expected.each do |key, value| > return false unless other[key] == value > end > true > end > > def to_s > "Hash with at least (@expected.inspect)" > end > end > > def hash_with_at_least(hash) > HashWithAtLeast.new(hash) > end > > describe HashWithAtLeast do > it "should match the same hash" do > hash_with_at_least(:a => 2).should == {:a => 2} > end > > it "should match a hash with an extra key/value" do > hash_with_at_least(:a => 2).should == {:a => 2, :b => 3} > end > > it "should not match a hash with a missing key" do > hash_with_at_least(:a => 2).should_not == {:b => 2} > hash_with_at_least(:a => 2, :b => 3).should_not == {:a => 2} > end > > it "should not match a hash with the wrong value for a key" do > hash_with_at_least(:a => 2).should_not == {:a => 3} > hash_with_at_least(:a => 2, :b => 3).should_not == {:a => 0, :b > => 3} > end > > end > > describe HashWithAtLeast, "in a message expectation" do > before(:all) do > @foo = Object.new > end > > it "should match exact" do > @foo.should_receive(:bar).with(hash_with_at_least(:a => 2)) > @foo.bar(:a => 2) > end > > it "should allow extra keys" do > @foo.should_receive(:bar).with(hash_with_at_least(:a => 2)) > @foo.bar(:a => 2, :b => 3) > end > end > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From doug+rspecuser at netinlet.com Wed Mar 5 13:36:44 2008 From: doug+rspecuser at netinlet.com (Doug Bryant) Date: Wed, 5 Mar 2008 13:36:44 -0500 Subject: [rspec-users] mocking successive return values In-Reply-To: <47CEE5A7.1040703@benmabey.com> References: <177c686f0803050930p7479ffecia5fa670df75a4817@mail.gmail.com> <47CEE5A7.1040703@benmabey.com> Message-ID: <177c686f0803051036me6e276cjc1a8a7994a2a5414@mail.gmail.com> Thanks Ben. I appreciate it. Doug On Wed, Mar 5, 2008 at 1:25 PM, Ben Mabey wrote: > Doug Bryant wrote: > > I'm having a problems mocking successive return values. I don't know > > if I'm doing something wrong or if this is a limitation of rspec > > mocks. Any ideas of what I may be doing wrong? > > > > > > For the test, I simply lookup 3 existing quote numbers, append nil to > > the end (for a total of 4) > > ## The test > > it "should not generate a duplicate quote number" do > > existing_quote_numbers = Policy.find(:all).map{|p| > > p.quote_number}[0,3] > > > > > @policy_service.should_receive(:random_string).with(:no_args).exactly(4).times.and_return(existing_quote_numbers.concat([nil])) > > @policy_service.generate_quote_number > > end > > > > You will need to have one expectation per return. Try this: > > it "should not generate a duplicate quote number" do > #expect > Policy.find(:all).map{|p| p.quote_number}[0,3].concat([nil]).each do > |existing_quote_number| > > > @policy_service.should_receive(:random_string).with(:no_args).once.and_return(existing_quote_number)) > end > #when > @policy_service.generate_quote_number > end > > > > -Ben > _______________________________________________ > 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/20080305/24144d0d/attachment.html From pergesu at gmail.com Wed Mar 5 14:17:27 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 5 Mar 2008 11:17:27 -0800 Subject: [rspec-users] mocking successive return values In-Reply-To: <177c686f0803050930p7479ffecia5fa670df75a4817@mail.gmail.com> References: <177c686f0803050930p7479ffecia5fa670df75a4817@mail.gmail.com> Message-ID: <810a540e0803051117h6ea0e565me905c704ae9d742b@mail.gmail.com> On Wed, Mar 5, 2008 at 9:30 AM, Doug Bryant wrote: @policy_service.should_receive(:random_string).with(:no_args).exactly(4).times.and_return(existing_quote_numbers.concat([nil])) > @policy_service.generate_quote_number > end > > ## The result > should not generate a duplicate quote number > Mock 'Service::Base' expected :random_string with (no args) 4 times, but > received it once > > I verified "and_return" is actually returning the array rather than an > individual element of the existing_quote_numbers array which makes sense You need to splat em out: and_return(*existing_quote_numbers.concat([nil])) Pat From coreyhaines at gmail.com Wed Mar 5 15:06:20 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 5 Mar 2008 15:06:20 -0500 Subject: [rspec-users] mocking successive return values In-Reply-To: <810a540e0803051117h6ea0e565me905c704ae9d742b@mail.gmail.com> References: <177c686f0803050930p7479ffecia5fa670df75a4817@mail.gmail.com> <810a540e0803051117h6ea0e565me905c704ae9d742b@mail.gmail.com> Message-ID: <6bdacb70803051206m288be403i70905aa4ebd2e841@mail.gmail.com> On Wed, Mar 5, 2008 at 2:17 PM, Pat Maddox wrote: > > You need to splat em out: > > and_return(*existing_quote_numbers.concat([nil])) > > Pat > Hi, Pat, Just for my own edification and education, if you have a minute, could you explain what this means and why you have to do it? Thanks, -Corey -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080305/20670b70/attachment.html From doug at netinlet.com Wed Mar 5 12:27:16 2008 From: doug at netinlet.com (Doug Bryant) Date: Wed, 5 Mar 2008 12:27:16 -0500 Subject: [rspec-users] mocking successive return values Message-ID: <4F74242D-0CB4-47A1-927F-4A0E2623BC5C@netinlet.com> I'm having a problems mocking successive return values. I don't know if I'm doing something wrong or if this is a limitation of rspec mocks. Any ideas of what I may be doing wrong? I'm trying to test the generate_quote_number method. It generates a quote number, looks to see if it is in the db already. If it is, it calls itself to try again. I want to test that it looks in the database for matching numbers until it finds one which does not exist already. ## The code def generate_quote_number quote_num = "MMQ#{self.random_string}-001" if Policy.find(:first, :conditions => ["quote_number = ?", quote_num]) quote_num = generate_quote_number end quote_num end def random_string(size=8) # return a random string end For the test, I simply lookup 3 existing quote numbers, append nil to the end (for a total of 4) ## The test it "should not generate a duplicate quote number" do existing_quote_numbers = Policy.find(:all).map{|p| p.quote_number} [0,3] @policy_service .should_receive (:random_string ).with (:no_args ).exactly(4).times.and_return(existing_quote_numbers.concat([nil])) @policy_service.generate_quote_number end ## The result should not generate a duplicate quote number Mock 'Service::Base' expected :random_string with (no args) 4 times, but received it once I verified "and_return" is actually returning the array rather than an individual element of the existing_quote_numbers array which makes sense, but what about this? http://rspec.rubyforge.org/svn/branches/dogfood/spec/spec/mocks/mock_spec.rb specify "should use a list of return values for successive calls" do @mock.should_receive(:multi_call).twice.with(:no_args).and_return([8, 12]) @mock.multi_call.should_equal 8 @mock.multi_call.should_equal 12 @mock.__verify end Any feedback on how to properly test this is much appreciated. Thanks, Doug -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080305/71cfbcb4/attachment-0001.html From pergesu at gmail.com Wed Mar 5 15:40:57 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 5 Mar 2008 12:40:57 -0800 Subject: [rspec-users] mocking successive return values In-Reply-To: <6bdacb70803051206m288be403i70905aa4ebd2e841@mail.gmail.com> References: <177c686f0803050930p7479ffecia5fa670df75a4817@mail.gmail.com> <810a540e0803051117h6ea0e565me905c704ae9d742b@mail.gmail.com> <6bdacb70803051206m288be403i70905aa4ebd2e841@mail.gmail.com> Message-ID: <810a540e0803051240l4ef277c6na2c6ee0702ce69a5@mail.gmail.com> On Wed, Mar 5, 2008 at 12:06 PM, Corey Haines wrote: > > On Wed, Mar 5, 2008 at 2:17 PM, Pat Maddox wrote: > > > > > > You need to splat em out: > > > > > > and_return(*existing_quote_numbers.concat([nil])) > > > > Pat > > > > Hi, Pat, > > Just for my own edification and education, if you have a minute, could you > explain what this means and why you have to do it? Basically it takes an array and splits it up. Here's a little irb session that ought to demonstrate it. >> def foo(val); p val; end => nil >> a = [1,2,3] => [1, 2, 3] >> foo(a) [1, 2, 3] => nil >> foo(*a) ArgumentError: wrong number of arguments (3 for 1) from (irb):4:in `foo' from (irb):4 The method expects one argument. When I pass it an array, everything is fine because it only has one object. However when I splat the array, it splits it up into three distinct objects and tries to pass it in, causing the method to blow up. In RSpec, you specify multiple values to return by passing in multiple objects. An array is just one object, so the mock just returns it. Splat it out and you've passed multiple values to and_return, causing it to return them in succession. * is called the splat operator and can be used to collect stuff in addition to splitting stuff up. Just google for "ruby splat operator" to get lots of info. Also you can define #to_splat on any object. Pat From rick.denatale at gmail.com Wed Mar 5 15:57:30 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 5 Mar 2008 15:57:30 -0500 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter In-Reply-To: <2D5C0532-49A3-4B42-8098-CD25FDB3D778@gmail.com> References: <2D5C0532-49A3-4B42-8098-CD25FDB3D778@gmail.com> Message-ID: On Wed, Mar 5, 2008 at 1:31 PM, David Chelimsky wrote: > On Mar 5, 2008, at 11:43 AM, "Rick DeNatale" > > wrote: > > > On Wed, Mar 5, 2008 at 12:28 PM, Rick DeNatale > > wrote: > >> I'm wanting to write a spec that a model is applying an :order option > >> to a find call, but I don't want to completely specify all of the > >> find > >> parameters. > >> > >> So I want to write something like this, say in a controller spec > >> > >> User.should_receive(:find).with(:all, hash_with_at_least(:order => > >> 'user.name ASC')) > >> get 'index', :sort => 'up' > > I really like this idea. What about something more general that can > handle the first n args too? That's a horse of a different color I think. It would need to dig into MessageExpectation#with and/or the way ArgumentExpectations are built. Dealing with it an argument at a time is easy since it just needs == to 'do the right thing' on an argument 'proxy'. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From coreyhaines at gmail.com Wed Mar 5 16:09:03 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 5 Mar 2008 16:09:03 -0500 Subject: [rspec-users] mocking successive return values In-Reply-To: <810a540e0803051240l4ef277c6na2c6ee0702ce69a5@mail.gmail.com> References: <177c686f0803050930p7479ffecia5fa670df75a4817@mail.gmail.com> <810a540e0803051117h6ea0e565me905c704ae9d742b@mail.gmail.com> <6bdacb70803051206m288be403i70905aa4ebd2e841@mail.gmail.com> <810a540e0803051240l4ef277c6na2c6ee0702ce69a5@mail.gmail.com> Message-ID: <6bdacb70803051309u3a4bc096v4a1f6563ed92e67b@mail.gmail.com> Wow! That is really cool. Thanks for the explanation, Pat. -Corey -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080305/52f09ef4/attachment.html From dchelimsky at gmail.com Wed Mar 5 16:12:15 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Mar 2008 15:12:15 -0600 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter In-Reply-To: References: <2D5C0532-49A3-4B42-8098-CD25FDB3D778@gmail.com> Message-ID: <3C842788-806E-4B90-8948-B8DA5DCC4DAF@gmail.com> On Mar 5, 2008, at 2:57 PM, "Rick DeNatale" wrote: > On Wed, Mar 5, 2008 at 1:31 PM, David Chelimsky > wrote: >> On Mar 5, 2008, at 11:43 AM, "Rick DeNatale" >> >> >> wrote: >> >>> On Wed, Mar 5, 2008 at 12:28 PM, Rick DeNatale >>> wrote: >>>> I'm wanting to write a spec that a model is applying an :order >>>> option >>>> to a find call, but I don't want to completely specify all of the >>>> find >>>> parameters. >>>> >>>> So I want to write something like this, say in a controller spec >>>> >>>> User.should_receive(:find).with(:all, hash_with_at_least(:order => >>>> 'user.name ASC')) >>>> get 'index', :sort => 'up' >> >> I really like this idea. What about something more general that can >> handle the first n args too? > > That's a horse of a different color I think. It would need to dig > into MessageExpectation#with and/or the way ArgumentExpectations are > built. > > Dealing with it an argument at a time is easy since it just needs == > to 'do the right thing' on an argument 'proxy'. Agreed. I think hash_with would be clear enough and a bit more terse. Agree? > > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rick.denatale at gmail.com Wed Mar 5 19:22:21 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 5 Mar 2008 19:22:21 -0500 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter In-Reply-To: <3C842788-806E-4B90-8948-B8DA5DCC4DAF@gmail.com> References: <2D5C0532-49A3-4B42-8098-CD25FDB3D778@gmail.com> <3C842788-806E-4B90-8948-B8DA5DCC4DAF@gmail.com> Message-ID: On 3/5/08, David Chelimsky wrote: > On Mar 5, 2008, at 2:57 PM, "Rick DeNatale" > > wrote: > > > On Wed, Mar 5, 2008 at 1:31 PM, David Chelimsky > > wrote: > >> On Mar 5, 2008, at 11:43 AM, "Rick DeNatale" > >> > >> > >> wrote: > >> > >>> On Wed, Mar 5, 2008 at 12:28 PM, Rick DeNatale >>>> wrote: > >>>> I'm wanting to write a spec that a model is applying an :order > >>>> option > >>>> to a find call, but I don't want to completely specify all of the > >>>> find > >>>> parameters. > >>>> > >>>> So I want to write something like this, say in a controller spec > >>>> > >>>> User.should_receive(:find).with(:all, hash_with_at_least(:order => > >>>> 'user.name ASC')) > >>>> get 'index', :sort => 'up' > >> > >> I really like this idea. What about something more general that can > >> handle the first n args too? > > > > That's a horse of a different color I think. It would need to dig > > into MessageExpectation#with and/or the way ArgumentExpectations are > > built. > > > > Dealing with it an argument at a time is easy since it just needs == > > to 'do the right thing' on an argument 'proxy'. > > > Agreed. > > I think hash_with would be clear enough and a bit more terse. Agree? Well that name has been bandied about for other purposes http://www.google.com/search?q=hash_with Maybe options_with since I think Rails tends to call a trailing hash argument options, or looking ahead to ruby 1.9, keywords_with These still don't really feel exactly right to me though since they don't carry the connotation that other key/values are acceptable. Another alternatives, which trade off slightly less brevity for a bit more clarity, might be hash_including Personally, since most folks use capable editors, I'm less concerned with minimizing keystrokes, for example in textmate, a longer and clearer version can be had for the cost of an esc key or a snippet. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From dchelimsky at gmail.com Wed Mar 5 19:32:55 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 5 Mar 2008 18:32:55 -0600 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter In-Reply-To: References: <2D5C0532-49A3-4B42-8098-CD25FDB3D778@gmail.com> <3C842788-806E-4B90-8948-B8DA5DCC4DAF@gmail.com> Message-ID: <3C3E30CE-6979-4B68-8B81-54CBBFE95D82@gmail.com> On Mar 5, 2008, at 6:22 PM, "Rick DeNatale" wrote: > On 3/5/08, David Chelimsky wrote: >> On Mar 5, 2008, at 2:57 PM, "Rick DeNatale" >> >> wrote: >> >>> On Wed, Mar 5, 2008 at 1:31 PM, David Chelimsky >>> wrote: >>>> On Mar 5, 2008, at 11:43 AM, "Rick DeNatale" >>>> >>>> >>>> wrote: >>>> >>>>> On Wed, Mar 5, 2008 at 12:28 PM, Rick DeNatale >>>>> wrote: >>>>>> I'm wanting to write a spec that a model is applying an :order >>>>>> option >>>>>> to a find call, but I don't want to completely specify all of the >>>>>> find >>>>>> parameters. >>>>>> >>>>>> So I want to write something like this, say in a controller spec >>>>>> >>>>>> User.should_receive(:find).with(:all, hash_with_at_least(:order >>>>>> => >>>>>> 'user.name ASC')) >>>>>> get 'index', :sort => 'up' >>>> >>>> I really like this idea. What about something more general that can >>>> handle the first n args too? >>> >>> That's a horse of a different color I think. It would need to dig >>> into MessageExpectation#with and/or the way ArgumentExpectations are >>> built. >>> >>> Dealing with it an argument at a time is easy since it just needs == >>> to 'do the right thing' on an argument 'proxy'. >> >> >> Agreed. >> >> I think hash_with would be clear enough and a bit more terse. Agree? > > Well that name has been bandied about for other purposes > http://www.google.com/search?q=hash_with > > Maybe options_with since I think Rails tends to call a trailing hash > argument options, or looking ahead to ruby 1.9, keywords_with > > These still don't really feel exactly right to me though since they > don't carry the connotation that other key/values are acceptable. > > Another alternatives, which trade off slightly less brevity for a bit > more clarity, might be hash_including > I like that. Have at it. Cheers, David > Personally, since most folks use capable editors, I'm less concerned > with minimizing keystrokes, for example in textmate, a longer and > clearer version can be had for the cost of an esc key or a snippet. > > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From zach.dennis at gmail.com Thu Mar 6 01:52:09 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 6 Mar 2008 01:52:09 -0500 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter In-Reply-To: References: Message-ID: <85d99afe0803052252v55accb9euacbe2abae4f650e5@mail.gmail.com> On Wed, Mar 5, 2008 at 12:28 PM, Rick DeNatale wrote: > I'm wanting to write a spec that a model is applying an :order option > to a find call, but I don't want to completely specify all of the find > parameters. > > So I want to write something like this, say in a controller spec > > User.should_receive(:find).with(:all, hash_with_at_least(:order => > 'user.name ASC')) > get 'index', :sort => 'up' > > This ability to partially specify the contents of a hash argument > seems to be generally useful, particularly for Rails, and was > wondering if anyone had done this. I don't think it would be too hard. Are you just wanting Mocha parameter matching? User.should_receive(:find).with(:all, has_entry(:order => 'user.name ASC')) get 'index', :sort => 'up' -- Zach Dennis http://www.continuousthinking.com From pergesu at gmail.com Thu Mar 6 02:01:38 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 5 Mar 2008 23:01:38 -0800 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter In-Reply-To: References: <2D5C0532-49A3-4B42-8098-CD25FDB3D778@gmail.com> <3C842788-806E-4B90-8948-B8DA5DCC4DAF@gmail.com> Message-ID: <810a540e0803052301j756089b5mfced5109a398e353@mail.gmail.com> On Wed, Mar 5, 2008 at 4:22 PM, Rick DeNatale wrote: > > On 3/5/08, David Chelimsky wrote: > > On Mar 5, 2008, at 2:57 PM, "Rick DeNatale" > > > > wrote: > > > > > On Wed, Mar 5, 2008 at 1:31 PM, David Chelimsky > > > wrote: > > >> On Mar 5, 2008, at 11:43 AM, "Rick DeNatale" > > >> > > >> > > >> wrote: > > >> > > >>> On Wed, Mar 5, 2008 at 12:28 PM, Rick DeNatale > >>>> wrote: > > >>>> I'm wanting to write a spec that a model is applying an :order > > >>>> option > > >>>> to a find call, but I don't want to completely specify all of the > > >>>> find > > >>>> parameters. > > >>>> > > >>>> So I want to write something like this, say in a controller spec > > >>>> > > >>>> User.should_receive(:find).with(:all, hash_with_at_least(:order => > > >>>> 'user.name ASC')) > > >>>> get 'index', :sort => 'up' > > >> > > >> I really like this idea. What about something more general that can > > >> handle the first n args too? > > > > > > That's a horse of a different color I think. It would need to dig > > > into MessageExpectation#with and/or the way ArgumentExpectations are > > > built. > > > > > > Dealing with it an argument at a time is easy since it just needs == > > > to 'do the right thing' on an argument 'proxy'. > > > > > > Agreed. > > > > I think hash_with would be clear enough and a bit more terse. Agree? > > Well that name has been bandied about for other purposes > http://www.google.com/search?q=hash_with > > Maybe options_with since I think Rails tends to call a trailing hash > argument options, or looking ahead to ruby 1.9, keywords_with > > These still don't really feel exactly right to me though since they > don't carry the connotation that other key/values are acceptable. > > Another alternatives, which trade off slightly less brevity for a bit > more clarity, might be hash_including > > Personally, since most folks use capable editors, I'm less concerned > with minimizing keystrokes, for example in textmate, a longer and > clearer version can be had for the cost of an esc key or a snippet. > Am I the only one that hates this whole thing and thinks it ought to be User.should_receive(:all_sorted_by_name) ? Pat From ben at benmabey.com Thu Mar 6 02:21:49 2008 From: ben at benmabey.com (Ben Mabey) Date: Thu, 06 Mar 2008 00:21:49 -0700 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter In-Reply-To: <810a540e0803052301j756089b5mfced5109a398e353@mail.gmail.com> References: <2D5C0532-49A3-4B42-8098-CD25FDB3D778@gmail.com> <3C842788-806E-4B90-8948-B8DA5DCC4DAF@gmail.com> <810a540e0803052301j756089b5mfced5109a398e353@mail.gmail.com> Message-ID: <47CF9B8D.8050008@benmabey.com> Pat Maddox wrote: > On Wed, Mar 5, 2008 at 4:22 PM, Rick DeNatale wrote: > >> On 3/5/08, David Chelimsky wrote: >> > On Mar 5, 2008, at 2:57 PM, "Rick DeNatale" >> > >> > wrote: >> > >> > > On Wed, Mar 5, 2008 at 1:31 PM, David Chelimsky >> > > wrote: >> > >> On Mar 5, 2008, at 11:43 AM, "Rick DeNatale" >> > >> >> > >> >> > >> wrote: >> > >> >> > >>> On Wed, Mar 5, 2008 at 12:28 PM, Rick DeNatale > > >>>> wrote: >> > >>>> I'm wanting to write a spec that a model is applying an :order >> > >>>> option >> > >>>> to a find call, but I don't want to completely specify all of the >> > >>>> find >> > >>>> parameters. >> > >>>> >> > >>>> So I want to write something like this, say in a controller spec >> > >>>> >> > >>>> User.should_receive(:find).with(:all, hash_with_at_least(:order => >> > >>>> 'user.name ASC')) >> > >>>> get 'index', :sort => 'up' >> > >> >> > >> I really like this idea. What about something more general that can >> > >> handle the first n args too? >> > > >> > > That's a horse of a different color I think. It would need to dig >> > > into MessageExpectation#with and/or the way ArgumentExpectations are >> > > built. >> > > >> > > Dealing with it an argument at a time is easy since it just needs == >> > > to 'do the right thing' on an argument 'proxy'. >> > >> > >> > Agreed. >> > >> > I think hash_with would be clear enough and a bit more terse. Agree? >> >> Well that name has been bandied about for other purposes >> http://www.google.com/search?q=hash_with >> >> Maybe options_with since I think Rails tends to call a trailing hash >> argument options, or looking ahead to ruby 1.9, keywords_with >> >> These still don't really feel exactly right to me though since they >> don't carry the connotation that other key/values are acceptable. >> >> Another alternatives, which trade off slightly less brevity for a bit >> more clarity, might be hash_including >> >> Personally, since most folks use capable editors, I'm less concerned >> with minimizing keystrokes, for example in textmate, a longer and >> clearer version can be had for the cost of an esc key or a snippet. >> >> > > Am I the only one that hates this whole thing and thinks it ought to be > User.should_receive(:all_sorted_by_name) > > ? > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I thought the same thing, but I have also wanted to only check certain keys in a hash before so I think that is really what this discussion is about. Whether or not that logic should be in the model is somewhat inconsequential because the functionality that is being proposed could be used elsewhere. I think having this would allow specs to be more flexible and not tie them to the implementation as much in some cases. -Ben From harm.aarts at innovationfactory.nl Thu Mar 6 03:16:50 2008 From: harm.aarts at innovationfactory.nl (Harm Aarts) Date: Thu, 6 Mar 2008 09:16:50 +0100 Subject: [rspec-users] having trouble specing an ajax request In-Reply-To: References: Message-ID: Hi Namrata, I recently ran into the same problem as well. The trick was to do something like: response.should have_rjs(some_arguments) The 'some_arguments' threw me off for a while but I believe you need :chained_replace_html. I wrote a little piece on it here: http://www.rubytutorials.net/2008/02/29/small-rspec-revelations-rjs/ Hope you find it helpful. With kind regards, Harm On 5 mrt 2008, at 15:01, rspec-users-request at rubyforge.org wrote: > Do I need to spec an AR. If yes, what is the best way to spec this. > here is the code - > > def index > @deals = Deal.paginate(:all, :conditions => > prepare_search_conditions, :order > => 'created_at DESC', :page => > params[:page] > ) > if request.xhr? > render :update do |page| > page.replace_html "table", :partial => "/deals/front/listing" > end > end > > I am new to Rspec. Is this the right way? > > it "should list all deals" do > controller.stub!(:prepare_search_conditions).and_return(true) > Deal.should_receive(:paginate).with(:all, {:conditions=>true, > :order=>"created_at DESC", > :page=>nil}).and_return(@deals) > get :list > controller.expect_render(:partial => '/deals/cms/list') > end > > Thanks, > Namrata. From dchelimsky at gmail.com Thu Mar 6 08:49:02 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 6 Mar 2008 07:49:02 -0600 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter In-Reply-To: <85d99afe0803052252v55accb9euacbe2abae4f650e5@mail.gmail.com> References: <85d99afe0803052252v55accb9euacbe2abae4f650e5@mail.gmail.com> Message-ID: <57c63afe0803060549p15983694icd9cf0ace4fb228@mail.gmail.com> On Thu, Mar 6, 2008 at 12:52 AM, Zach Dennis wrote: > On Wed, Mar 5, 2008 at 12:28 PM, Rick DeNatale wrote: > > > I'm wanting to write a spec that a model is applying an :order option > > to a find call, but I don't want to completely specify all of the find > > parameters. > > > > So I want to write something like this, say in a controller spec > > > > User.should_receive(:find).with(:all, hash_with_at_least(:order => > > 'user.name ASC')) > > get 'index', :sort => 'up' RSpec has similar parameter matching: http://blog.davidchelimsky.net/articles/2007/02/25/matchers-doing-double-duty That's why Rick is talking about writing a parameter matcher :) > > > > This ability to partially specify the contents of a hash argument > > seems to be generally useful, particularly for Rails, and was > > wondering if anyone had done this. I don't think it would be too hard. > > Are you just wanting Mocha parameter matching? > > User.should_receive(:find).with(:all, has_entry(:order => 'user.name ASC')) > get 'index', :sort => 'up' > > -- > Zach Dennis > http://www.continuousthinking.com > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Mar 6 08:50:39 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 6 Mar 2008 07:50:39 -0600 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter In-Reply-To: <810a540e0803052301j756089b5mfced5109a398e353@mail.gmail.com> References: <2D5C0532-49A3-4B42-8098-CD25FDB3D778@gmail.com> <3C842788-806E-4B90-8948-B8DA5DCC4DAF@gmail.com> <810a540e0803052301j756089b5mfced5109a398e353@mail.gmail.com> Message-ID: <57c63afe0803060550n564b9da3j6f8f26e9e0f454de@mail.gmail.com> On Thu, Mar 6, 2008 at 1:01 AM, Pat Maddox wrote: > > On Wed, Mar 5, 2008 at 4:22 PM, Rick DeNatale wrote: > > > > On 3/5/08, David Chelimsky wrote: > > > On Mar 5, 2008, at 2:57 PM, "Rick DeNatale" > > > > > > wrote: > > > > > > > On Wed, Mar 5, 2008 at 1:31 PM, David Chelimsky > > > > wrote: > > > >> On Mar 5, 2008, at 11:43 AM, "Rick DeNatale" > > > >> > > > >> > > > >> wrote: > > > >> > > > >>> On Wed, Mar 5, 2008 at 12:28 PM, Rick DeNatale > > >>>> wrote: > > > >>>> I'm wanting to write a spec that a model is applying an :order > > > >>>> option > > > >>>> to a find call, but I don't want to completely specify all of the > > > >>>> find > > > >>>> parameters. > > > >>>> > > > >>>> So I want to write something like this, say in a controller spec > > > >>>> > > > >>>> User.should_receive(:find).with(:all, hash_with_at_least(:order => > > > >>>> 'user.name ASC')) > > > >>>> get 'index', :sort => 'up' > > > >> > > > >> I really like this idea. What about something more general that can > > > >> handle the first n args too? > > > > > > > > That's a horse of a different color I think. It would need to dig > > > > into MessageExpectation#with and/or the way ArgumentExpectations are > > > > built. > > > > > > > > Dealing with it an argument at a time is easy since it just needs == > > > > to 'do the right thing' on an argument 'proxy'. > > > > > > > > > Agreed. > > > > > > I think hash_with would be clear enough and a bit more terse. Agree? > > > > Well that name has been bandied about for other purposes > > http://www.google.com/search?q=hash_with > > > > Maybe options_with since I think Rails tends to call a trailing hash > > argument options, or looking ahead to ruby 1.9, keywords_with > > > > These still don't really feel exactly right to me though since they > > don't carry the connotation that other key/values are acceptable. > > > > Another alternatives, which trade off slightly less brevity for a bit > > more clarity, might be hash_including > > > > Personally, since most folks use capable editors, I'm less concerned > > with minimizing keystrokes, for example in textmate, a longer and > > clearer version can be had for the cost of an esc key or a snippet. > > > > Am I the only one that hates this whole thing and thinks it ought to be > User.should_receive(:all_sorted_by_name) ? But wouldn't you want that spec'd on the model? > > Pat > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Mar 6 08:51:10 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 6 Mar 2008 07:51:10 -0600 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter In-Reply-To: <47CF9B8D.8050008@benmabey.com> References: <2D5C0532-49A3-4B42-8098-CD25FDB3D778@gmail.com> <3C842788-806E-4B90-8948-B8DA5DCC4DAF@gmail.com> <810a540e0803052301j756089b5mfced5109a398e353@mail.gmail.com> <47CF9B8D.8050008@benmabey.com> Message-ID: <57c63afe0803060551g6927f911k76689fc267ad41a7@mail.gmail.com> On Thu, Mar 6, 2008 at 1:21 AM, Ben Mabey wrote: > > Pat Maddox wrote: > > On Wed, Mar 5, 2008 at 4:22 PM, Rick DeNatale wrote: > > > >> On 3/5/08, David Chelimsky wrote: > >> > On Mar 5, 2008, at 2:57 PM, "Rick DeNatale" > >> > > >> > wrote: > >> > > >> > > On Wed, Mar 5, 2008 at 1:31 PM, David Chelimsky > >> > > wrote: > >> > >> On Mar 5, 2008, at 11:43 AM, "Rick DeNatale" > >> > >> > >> > >> > >> > >> wrote: > >> > >> > >> > >>> On Wed, Mar 5, 2008 at 12:28 PM, Rick DeNatale >> > >>>> wrote: > >> > >>>> I'm wanting to write a spec that a model is applying an :order > >> > >>>> option > >> > >>>> to a find call, but I don't want to completely specify all of the > >> > >>>> find > >> > >>>> parameters. > >> > >>>> > >> > >>>> So I want to write something like this, say in a controller spec > >> > >>>> > >> > >>>> User.should_receive(:find).with(:all, hash_with_at_least(:order => > >> > >>>> 'user.name ASC')) > >> > >>>> get 'index', :sort => 'up' > >> > >> > >> > >> I really like this idea. What about something more general that can > >> > >> handle the first n args too? > >> > > > >> > > That's a horse of a different color I think. It would need to dig > >> > > into MessageExpectation#with and/or the way ArgumentExpectations are > >> > > built. > >> > > > >> > > Dealing with it an argument at a time is easy since it just needs == > >> > > to 'do the right thing' on an argument 'proxy'. > >> > > >> > > >> > Agreed. > >> > > >> > I think hash_with would be clear enough and a bit more terse. Agree? > >> > >> Well that name has been bandied about for other purposes > >> http://www.google.com/search?q=hash_with > >> > >> Maybe options_with since I think Rails tends to call a trailing hash > >> argument options, or looking ahead to ruby 1.9, keywords_with > >> > >> These still don't really feel exactly right to me though since they > >> don't carry the connotation that other key/values are acceptable. > >> > >> Another alternatives, which trade off slightly less brevity for a bit > >> more clarity, might be hash_including > >> > >> Personally, since most folks use capable editors, I'm less concerned > >> with minimizing keystrokes, for example in textmate, a longer and > >> clearer version can be had for the cost of an esc key or a snippet. > >> > >> > > > > Am I the only one that hates this whole thing and thinks it ought to be > > User.should_receive(:all_sorted_by_name) > > > > ? > > > > Pat > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > I thought the same thing, but I have also wanted to only check certain > keys in a hash before so I think that is really what this discussion is > about. Whether or not that logic should be in the model is somewhat > inconsequential because the functionality that is being proposed could > be used elsewhere. I think having this would allow specs to be more > flexible and not tie them to the implementation as much in some cases. +1 David > > -Ben > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bastien.vaucher at gmail.com Wed Mar 5 17:30:32 2008 From: bastien.vaucher at gmail.com (Bastien) Date: Wed, 5 Mar 2008 14:30:32 -0800 (PST) Subject: [rspec-users] [Stories] Login and subdomain Message-ID: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> I've just begin using rspec stories, and i m encountering some problems. In my application i have different subdomains in which specific users can log in, for example an admin will go to admin.myapp.com/authenticate/login, and an user belonging to a specific company will log in company.myapp.com/authenticate/login, and of course both have a different login process. To perform some actions the user has to be logged in, and this is where the problem comes, how to test these actions ? - Is there a way to set a user as logged in ? (that would definitely be very convenient) So far I have tried to do the following : post "/authenticate/login", {:login => user_email, :password => password } but the problem is that it doesn't use the correct subdomain and the login, as expected in that case, fails, so how to define the correct subdomain ? Thank you in advance for your help. From dchelimsky at gmail.com Thu Mar 6 09:19:43 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 6 Mar 2008 08:19:43 -0600 Subject: [rspec-users] [Stories] Login and subdomain In-Reply-To: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> References: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> Message-ID: <57c63afe0803060619h4785b1dclfcdf44c95c6fe31e@mail.gmail.com> On Wed, Mar 5, 2008 at 4:30 PM, Bastien wrote: > I've just begin using rspec stories, and i m encountering some > problems. In my application i have different subdomains in which > specific users can log in, for example an admin will go to > admin.myapp.com/authenticate/login, and an user belonging to a > specific company will log in company.myapp.com/authenticate/login, and > of course both have a different login process. > > To perform some actions the user has to be logged in, and this is > where the problem comes, how to test these actions ? > > - Is there a way to set a user as logged in ? (that would definitely > be very convenient) > > So far I have tried to do the following : > > post "/authenticate/login", > {:login => user_email, > :password => password } > > but the problem is that it doesn't use the correct subdomain and the > login, as expected in that case, fails, so how to define the correct > subdomain ? RailsStory wraps ActionController::IntegrationTest, which delegates calls to ActionController::Integration::Session. Check out the rdoc (http://api.rubyonrails.com/classes/ActionController/Integration/Session.html) and you'll see a host! method (http://api.rubyonrails.com/classes/ActionController/Integration/Session.html#M000237). So ... host! "whatever subdomain" post "/authenticate/login", .... Cheers, David > > Thank you in advance for your help. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ivo.dancet at gmail.com Thu Mar 6 09:33:50 2008 From: ivo.dancet at gmail.com (Ivo Dancet) Date: Thu, 6 Mar 2008 15:33:50 +0100 Subject: [rspec-users] [Stories] Login and subdomain In-Reply-To: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> References: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> Message-ID: <01B68B81-9133-4F77-864F-B51D93CC7340@gmail.com> I think you can also use: post "/authentication/login", { :login => user_email, :password => password }, :host => "company.example.com" Op 5-mrt-08, om 23:30 heeft Bastien het volgende geschreven: > I've just begin using rspec stories, and i m encountering some > problems. In my application i have different subdomains in which > specific users can log in, for example an admin will go to > admin.myapp.com/authenticate/login, and an user belonging to a > specific company will log in company.myapp.com/authenticate/login, and > of course both have a different login process. > > To perform some actions the user has to be logged in, and this is > where the problem comes, how to test these actions ? > > - Is there a way to set a user as logged in ? (that would definitely > be very convenient) > > So far I have tried to do the following : > > post "/authenticate/login", > {:login => user_email, > :password => password } > > but the problem is that it doesn't use the correct subdomain and the > login, as expected in that case, fails, so how to define the correct > subdomain ? > > Thank you in advance for your help. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From bastien.vaucher at gmail.com Thu Mar 6 10:12:47 2008 From: bastien.vaucher at gmail.com (Bastien) Date: Thu, 6 Mar 2008 07:12:47 -0800 (PST) Subject: [rspec-users] [Stories] Login and subdomain In-Reply-To: <01B68B81-9133-4F77-864F-B51D93CC7340@gmail.com> References: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> <01B68B81-9133-4F77-864F-B51D93CC7340@gmail.com> Message-ID: <9f10480b-a3e3-41f1-8e85-93958bdedae1@q33g2000hsh.googlegroups.com> Thanks David, this works just fine. I would rather do some stubbing there if it's possible though. I tried : ApplicationController.stub! (:user_authentication_required).and_return(true) (which is the filter called before each action that checks whether the user is logged in or not) But it doesn't work. When I do this : class ApplicationController def user_authentication_required return true end end it works fine (but I find it quite dirty to redefine my method that way). Aren't this two solutions supposed to give me the same result ? Is something wrong with my stubbing ? On Mar 6, 3:33 pm, Ivo Dancet wrote: > I think you can also use: > > post "/authentication/login", > { :login => user_email, > :password => password }, > :host => "company.example.com" > > Op 5-mrt-08, om 23:30 heeft Bastien het volgende geschreven: > > > > > I've just begin using rspec stories, and i m encountering some > > problems. In my application i have different subdomains in which > > specific users can log in, for example an admin will go to > > admin.myapp.com/authenticate/login, and an user belonging to a > > specific company will log in company.myapp.com/authenticate/login, and > > of course both have a different login process. > > > To perform some actions the user has to be logged in, and this is > > where the problem comes, how to test these actions ? > > > - Is there a way to set a user as logged in ? (that would definitely > > be very convenient) > > > So far I have tried to do the following : > > > post "/authenticate/login", > > {:login => user_email, > > :password => password } > > > but the problem is that it doesn't use the correct subdomain and the > > login, as expected in that case, fails, so how to define the correct > > subdomain ? > > > Thank you in advance for your help. > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Thu Mar 6 10:21:35 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 6 Mar 2008 07:21:35 -0800 Subject: [rspec-users] ActiveRecord, spec'ing find has right :order parameter In-Reply-To: <57c63afe0803060550n564b9da3j6f8f26e9e0f454de@mail.gmail.com> References: <2D5C0532-49A3-4B42-8098-CD25FDB3D778@gmail.com> <3C842788-806E-4B90-8948-B8DA5DCC4DAF@gmail.com> <810a540e0803052301j756089b5mfced5109a398e353@mail.gmail.com> <57c63afe0803060550n564b9da3j6f8f26e9e0f454de@mail.gmail.com> Message-ID: <810a540e0803060721t344ca0d7mc8dd5f18100a45ff@mail.gmail.com> On Thu, Mar 6, 2008 at 5:50 AM, David Chelimsky wrote: > > On Thu, Mar 6, 2008 at 1:01 AM, Pat Maddox wrote: > > > > > > >>> On Wed, Mar 5, 2008 at 12:28 PM, Rick DeNatale > > > >>>> wrote: > > > > >>>> So I want to write something like this, say in a controller spec > > > > >>>> > > > > >>>> User.should_receive(:find).with(:all, hash_with_at_least(:order => > > > > >>>> 'user.name ASC')) > > > > >>>> get 'index', :sort => 'up' > > Am I the only one that hates this whole thing and thinks it ought to be > > User.should_receive(:all_sorted_by_name) ? > > But wouldn't you want that spec'd on the model? Yes, but my spec would hit the db. (1) I feel icky specifying the call to find so precisely (2) the behavior that I want is to find stuff in a certain order, the fact that it uses AR is an implementation detail (3) "don't mock APIs you don't own" However I can also +1 Ben Mabey's reply that partial hash matching is an interesting problem in its own right. Pat From pergesu at gmail.com Thu Mar 6 10:23:32 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 6 Mar 2008 07:23:32 -0800 Subject: [rspec-users] [Stories] Login and subdomain In-Reply-To: <9f10480b-a3e3-41f1-8e85-93958bdedae1@q33g2000hsh.googlegroups.com> References: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> <01B68B81-9133-4F77-864F-B51D93CC7340@gmail.com> <9f10480b-a3e3-41f1-8e85-93958bdedae1@q33g2000hsh.googlegroups.com> Message-ID: <810a540e0803060723t1ad3d747ha9eb23897f8976ae@mail.gmail.com> On Thu, Mar 6, 2008 at 7:12 AM, Bastien wrote: > Thanks David, this works just fine. I would rather do some stubbing > there if it's possible though. I tried : > > ApplicationController.stub! > (:user_authentication_required).and_return(true) try controller.stub!(....) Pat From pergesu at gmail.com Thu Mar 6 10:27:00 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 6 Mar 2008 07:27:00 -0800 Subject: [rspec-users] [Stories] Login and subdomain In-Reply-To: <810a540e0803060723t1ad3d747ha9eb23897f8976ae@mail.gmail.com> References: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> <01B68B81-9133-4F77-864F-B51D93CC7340@gmail.com> <9f10480b-a3e3-41f1-8e85-93958bdedae1@q33g2000hsh.googlegroups.com> <810a540e0803060723t1ad3d747ha9eb23897f8976ae@mail.gmail.com> Message-ID: <810a540e0803060727h448e13ddo7c51ee15bb9082b4@mail.gmail.com> On Thu, Mar 6, 2008 at 7:23 AM, Pat Maddox wrote: > On Thu, Mar 6, 2008 at 7:12 AM, Bastien wrote: > > Thanks David, this works just fine. I would rather do some stubbing > > there if it's possible though. I tried : > > > > ApplicationController.stub! > > (:user_authentication_required).and_return(true) > > try > controller.stub!(....) Perhaps I should explain why this is. stub! adds a stubbed method to an object. In Ruby, classes are objects as well, so what you've done is to stub a method on the ApplicationController class object itself - effectively creating a class method. When you override the method yourself, you're overriding an instance method. So in order to stub out the method for a request, you want to stub it on the _instance_ of the controller being used in the test. That controller instance is made available to you through a method named "controller". Pat From ivo.dancet at gmail.com Thu Mar 6 10:27:57 2008 From: ivo.dancet at gmail.com (Ivo Dancet) Date: Thu, 6 Mar 2008 16:27:57 +0100 Subject: [rspec-users] [Stories] Login and subdomain In-Reply-To: <9f10480b-a3e3-41f1-8e85-93958bdedae1@q33g2000hsh.googlegroups.com> References: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> <01B68B81-9133-4F77-864F-B51D93CC7340@gmail.com> <9f10480b-a3e3-41f1-8e85-93958bdedae1@q33g2000hsh.googlegroups.com> Message-ID: <10C0EB28-2F5F-4324-936E-065C4B7CEE1C@gmail.com> You should not stub the authentication method in a story. The story should test the whole application framework, that way your story might look like this: Given a user from company x When logging in And requesting some page Then the application should do all the stuff it should In the given step you set your host, user name and password and you create that user. In the when steps you make the login request and then you can start doing the stuff you really want to test here as you'll have the session you want at that moment. Regards Ivo Dancet Op 6-mrt-08, om 16:12 heeft Bastien het volgende geschreven: > Thanks David, this works just fine. I would rather do some stubbing > there if it's possible though. I tried : > > ApplicationController.stub! > (:user_authentication_required).and_return(true) > > (which is the filter called before each action that checks whether the > user is logged in or not) > But it doesn't work. When I do this : > > class ApplicationController > def user_authentication_required > return true > end > end > > it works fine (but I find it quite dirty to redefine my method that > way). Aren't this two solutions supposed to give me the same result ? > Is something wrong with my stubbing ? > > On Mar 6, 3:33 pm, Ivo Dancet wrote: >> I think you can also use: >> >> post "/authentication/login", >> { :login => user_email, >> :password => password }, >> :host => "company.example.com" >> >> Op 5-mrt-08, om 23:30 heeft Bastien het volgende geschreven: >> >> >> >>> I've just begin using rspec stories, and i m encountering some >>> problems. In my application i have different subdomains in which >>> specific users can log in, for example an admin will go to >>> admin.myapp.com/authenticate/login, and an user belonging to a >>> specific company will log in company.myapp.com/authenticate/login, >>> and >>> of course both have a different login process. >> >>> To perform some actions the user has to be logged in, and this is >>> where the problem comes, how to test these actions ? >> >>> - Is there a way to set a user as logged in ? (that would definitely >>> be very convenient) >> >>> So far I have tried to do the following : >> >>> post "/authenticate/login", >>> {:login => user_email, >>> :password => password } >> >>> but the problem is that it doesn't use the correct subdomain and the >>> login, as expected in that case, fails, so how to define the correct >>> subdomain ? >> >>> Thank you in advance for your help. >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://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 Thu Mar 6 10:38:53 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 6 Mar 2008 07:38:53 -0800 Subject: [rspec-users] [Stories] Login and subdomain In-Reply-To: <10C0EB28-2F5F-4324-936E-065C4B7CEE1C@gmail.com> References: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> <01B68B81-9133-4F77-864F-B51D93CC7340@gmail.com> <9f10480b-a3e3-41f1-8e85-93958bdedae1@q33g2000hsh.googlegroups.com> <10C0EB28-2F5F-4324-936E-065C4B7CEE1C@gmail.com> Message-ID: <810a540e0803060738p2b736dc9qd89e86b2291cf6ca@mail.gmail.com> On Thu, Mar 6, 2008 at 7:27 AM, Ivo Dancet wrote: > You should not stub the authentication method in a story. The story > should test the whole application framework, that way your story might > look like this: > > Given a user from company x > When logging in > And requesting some page > Then the application should do all the stuff it should > > In the given step you set your host, user name and password and you > create that user. > In the when steps you make the login request and then you can start > doing the stuff you really want to test here as you'll have the > session you want at that moment. That's a little too dogmatic for me. You needn't go through the entire stack every story, and you needn't go through the entire app path either. That said, I think you want to keep stubbing to an absolute minimum. I only stub out stuff that hits external services - even then I have a "full integration mode" that runs the same tests but DOES hit the real services (assuming they provide a sandbox or I have some other innocuous way to mess with stuff). Sometimes I'm lazy about the login step and will do controller.send(:current_user=, User.find(1)) if I don't feel there's any benefit at all to making a login request. Pat From bastien.vaucher at gmail.com Thu Mar 6 10:42:31 2008 From: bastien.vaucher at gmail.com (Bastien) Date: Thu, 6 Mar 2008 07:42:31 -0800 (PST) Subject: [rspec-users] [Stories] Login and subdomain In-Reply-To: <10C0EB28-2F5F-4324-936E-065C4B7CEE1C@gmail.com> References: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> <01B68B81-9133-4F77-864F-B51D93CC7340@gmail.com> <9f10480b-a3e3-41f1-8e85-93958bdedae1@q33g2000hsh.googlegroups.com> <10C0EB28-2F5F-4324-936E-065C4B7CEE1C@gmail.com> Message-ID: <6ec2a753-f7c1-4499-9459-47010f23e2fb@d62g2000hsf.googlegroups.com> Thanks for your help. I tried the controller.stub!(...) as well, and it doesn't work. Ivo I totally agree with you and I'll follow your recommendations, thanks. (Would still be nice to know if the stubbing could work or if it's intended not to) On Mar 6, 4:27 pm, Ivo Dancet wrote: > You should not stub the authentication method in a story. The story > should test the whole application framework, that way your story might > look like this: > > Given a user from company x > When logging in > And requesting some page > Then the application should do all the stuff it should > > In the given step you set your host, user name and password and you > create that user. > In the when steps you make the login request and then you can start > doing the stuff you really want to test here as you'll have the > session you want at that moment. > > Regards > Ivo Dancet > > Op 6-mrt-08, om 16:12 heeft Bastien het volgende geschreven: > > > > > Thanks David, this works just fine. I would rather do some stubbing > > there if it's possible though. I tried : > > > ApplicationController.stub! > > (:user_authentication_required).and_return(true) > > > (which is the filter called before each action that checks whether the > > user is logged in or not) > > But it doesn't work. When I do this : > > > class ApplicationController > > def user_authentication_required > > return true > > end > > end > > > it works fine (but I find it quite dirty to redefine my method that > > way). Aren't this two solutions supposed to give me the same result ? > > Is something wrong with my stubbing ? > > > On Mar 6, 3:33 pm, Ivo Dancet wrote: > >> I think you can also use: > > >> post "/authentication/login", > >> { :login => user_email, > >> :password => password }, > >> :host => "company.example.com" > > >> Op 5-mrt-08, om 23:30 heeft Bastien het volgende geschreven: > > >>> I've just begin using rspec stories, and i m encountering some > >>> problems. In my application i have different subdomains in which > >>> specific users can log in, for example an admin will go to > >>> admin.myapp.com/authenticate/login, and an user belonging to a > >>> specific company will log in company.myapp.com/authenticate/login, > >>> and > >>> of course both have a different login process. > > >>> To perform some actions the user has to be logged in, and this is > >>> where the problem comes, how to test these actions ? > > >>> - Is there a way to set a user as logged in ? (that would definitely > >>> be very convenient) > > >>> So far I have tried to do the following : > > >>> post "/authenticate/login", > >>> {:login => user_email, > >>> :password => password } > > >>> but the problem is that it doesn't use the correct subdomain and the > >>> login, as expected in that case, fails, so how to define the correct > >>> subdomain ? > > >>> Thank you in advance for your help. > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-us... at rubyforge.org > >>>http://rubyforge.org/mailman/listinfo/rspec-users > > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From coreyhaines at gmail.com Thu Mar 6 15:36:20 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Thu, 6 Mar 2008 15:36:20 -0500 Subject: [rspec-users] Including my plugin specs into rake spec Message-ID: <6bdacb70803061236j2982bf88x323dc4f582cd9244@mail.gmail.com> Hi, We've been building plugins for our app, and we kept running into forgetting to run the plugin specs when we updated from svn. So, I took the task on to have the rake spec command include our plugin specs, as well. I only wanted to have our plugin specs run, not third party ones. In order to do this, I edited the rspec_on_rails /tasks/rspec.rake file to include our specs in the FileList. I don't especially like the fact that I had to change the rake task for rspec_on_rails in order to do this. Is there a more preferred way to do this? Thanks, -Corey -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080306/1605ca00/attachment.html From oli.azevedo.barnes at gmail.com Thu Mar 6 15:54:14 2008 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Thu, 6 Mar 2008 17:54:14 -0300 Subject: [rspec-users] stuck on testing validation In-Reply-To: References: <6466d9040803031524x42f2583ajb4776880b4a21fd8@mail.gmail.com> Message-ID: <6466d9040803061254q7fe6b067kf628580b8ba57630@mail.gmail.com> Hi Namrata, thanks, that's a great resource and I ended up beefing my tests based on the recommendations there. actually though, the problem I was having was that validations weren't being recognized by the test suite. later I found out that when regenerating the scaffold for the app a while back, the database.yml used the sqlite adapter instead of mysql (I'd forgotten about this) - once I switched back to mysql, where the database was prepared, the flunking tests starting passing. :P - Oliver 2008/3/4, Namrata Tiwari : > Here is a very good example by Luke, which I think you should follow - > > http://www.lukeredpath.co.uk/2006/8/29/developing-a-rails-model-using-bdd-and-rspec-part-1 > > fyi, > Namrata > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From oli.azevedo.barnes at gmail.com Thu Mar 6 16:33:23 2008 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Thu, 6 Mar 2008 18:33:23 -0300 Subject: [rspec-users] rake spec aborting Message-ID: <6466d9040803061333w14a63362q4312eb9c3f4c9158@mail.gmail.com> hello, when running rake spec, I'm getting a stack trace similar to the one mentioned in this ticket, which has been resolved: http://rspec.lighthouseapp.com/projects/5645/tickets/237 but from what I understood, if the project is using rspec 1.1.3 (as is the case with mine), this shouldn't be happening? here's the stack-trace: rake aborted! Command ruby -I"/Users/oliver/Sites/portfolio/vendor/plugins/rspec/lib" "/Users/oliver/Sites/portfolio/vendor/plugins/rspec/bin/spec" "spec/controllers/categories_controller_spec.rb" "spec/controllers/categories_routing_spec.rb" "spec/controllers/sessions_controller_spec.rb" "spec/controllers/users_controller_spec.rb" "spec/controllers/works_controller_spec.rb" "spec/controllers/works_routing_spec.rb" "spec/helpers/categories_helper_spec.rb" "spec/helpers/works_helper_spec.rb" "spec/models/category_spec.rb" "spec/models/image_spec.rb" "spec/models/user_spec.rb" "spec/models/work_spec.rb" "spec/views/categories/edit.html.erb_spec.rb" "spec/views/categories/index.html.erb_spec.rb" "spec/views/categories/new.html.erb_spec.rb" "spec/views/categories/show.html.erb_spec.rb" "spec/views/works/edit.html.erb_spec.rb" "spec/views/works/index.html.erb_spec.rb" "spec/views/works/new.html.erb_spec.rb" "spec/views/works/show.html.erb_spec.rb" --options "/Users/oliver/Sites/portfolio/spec/spec.opts" failed /Users/oliver/Sites/portfolio/vendor/plugins/rspec/lib/spec/rake/spectask.rb:184:in `define' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1003:in `verbose' /Users/oliver/Sites/portfolio/vendor/plugins/rspec/lib/spec/rake/spectask.rb:153:in `define' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in `invoke_task' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake:31 /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/bin/rake:19:in `load' /Applications/Locomotive2/Bundles/custom_rails2.locobundle/framework/bin/rake:19 From zach.dennis at gmail.com Fri Mar 7 11:13:58 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 7 Mar 2008 11:13:58 -0500 Subject: [rspec-users] [Stories] Login and subdomain In-Reply-To: <810a540e0803060738p2b736dc9qd89e86b2291cf6ca@mail.gmail.com> References: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> <01B68B81-9133-4F77-864F-B51D93CC7340@gmail.com> <9f10480b-a3e3-41f1-8e85-93958bdedae1@q33g2000hsh.googlegroups.com> <10C0EB28-2F5F-4324-936E-065C4B7CEE1C@gmail.com> <810a540e0803060738p2b736dc9qd89e86b2291cf6ca@mail.gmail.com> Message-ID: <85d99afe0803070813w4c777e90p41bf23918710c146@mail.gmail.com> On Thu, Mar 6, 2008 at 10:38 AM, Pat Maddox wrote: > On Thu, Mar 6, 2008 at 7:27 AM, Ivo Dancet wrote: > > You should not stub the authentication method in a story. The story > > should test the whole application framework, that way your story might > > look like this: > > > > Given a user from company x > > When logging in > > And requesting some page > > Then the application should do all the stuff it should > > > > In the given step you set your host, user name and password and you > > create that user. > > In the when steps you make the login request and then you can start > > doing the stuff you really want to test here as you'll have the > > session you want at that moment. > > That's a little too dogmatic for me. You needn't go through the > entire stack every story, and you needn't go through the entire app > path either. > IMO you should be simulating as much as possible what the user is doing. If they have to go through path a, b, c ... to get to Z, then so be it. This involves keeping a well-factored set of helpers which can be used to navigate the app just like a user would. The only things you probably should be stubbing in a story are third party components your site may have to integrate with that aren't realistic to be run for every story (for the most part, there are other exceptions as well I know). I would avoid stubbing core functionality related to your site, -- Zach Dennis http://www.continuousthinking.com From toastkid.williams at gmail.com Fri Mar 7 11:53:57 2008 From: toastkid.williams at gmail.com (Max Williams) Date: Fri, 7 Mar 2008 16:53:57 +0000 Subject: [rspec-users] [Stories] Login and subdomain In-Reply-To: <6ec2a753-f7c1-4499-9459-47010f23e2fb@d62g2000hsf.googlegroups.com> References: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> <01B68B81-9133-4F77-864F-B51D93CC7340@gmail.com> <9f10480b-a3e3-41f1-8e85-93958bdedae1@q33g2000hsh.googlegroups.com> <10C0EB28-2F5F-4324-936E-065C4B7CEE1C@gmail.com> <6ec2a753-f7c1-4499-9459-47010f23e2fb@d62g2000hsf.googlegroups.com> Message-ID: I found it a little confusing to stub my authentication filters as well, but figured it out with a little help from the interwebs: in spec_helper i have this: describe "a controller requiring login", :shared => true do it "should have login_required set in the before filter" do controller.class.before_filters.should include(:login_required) end end def mock_login_required(allow_user_to_pass=true) controller.stub!(:login_required).and_return(allow_user_to_pass) end Then, in any spec where i want to mock that filter, i just write it_should_behave_like "a controller requiring login" at the top of the describe block. Sorry, i can't remember the web page where i found this solution but respect to whoever posted it :) On 06/03/2008, Bastien wrote: > > Thanks for your help. > I tried the controller.stub!(...) as well, and it doesn't work. > > Ivo I totally agree with you and I'll follow your recommendations, > thanks. > > (Would still be nice to know if the stubbing could work or if it's > intended not to) > > > On Mar 6, 4:27 pm, Ivo Dancet wrote: > > You should not stub the authentication method in a story. The story > > should test the whole application framework, that way your story might > > look like this: > > > > Given a user from company x > > When logging in > > And requesting some page > > Then the application should do all the stuff it should > > > > In the given step you set your host, user name and password and you > > create that user. > > In the when steps you make the login request and then you can start > > doing the stuff you really want to test here as you'll have the > > session you want at that moment. > > > > Regards > > Ivo Dancet > > > > Op 6-mrt-08, om 16:12 heeft Bastien het volgende geschreven: > > > > > > > > > Thanks David, this works just fine. I would rather do some stubbing > > > there if it's possible though. I tried : > > > > > ApplicationController.stub! > > > (:user_authentication_required).and_return(true) > > > > > (which is the filter called before each action that checks whether the > > > user is logged in or not) > > > But it doesn't work. When I do this : > > > > > class ApplicationController > > > def user_authentication_required > > > return true > > > end > > > end > > > > > it works fine (but I find it quite dirty to redefine my method that > > > way). Aren't this two solutions supposed to give me the same result ? > > > Is something wrong with my stubbing ? > > > > > On Mar 6, 3:33 pm, Ivo Dancet wrote: > > >> I think you can also use: > > > > >> post "/authentication/login", > > >> { :login => user_email, > > >> :password => password }, > > >> :host => "company.example.com" > > > > >> Op 5-mrt-08, om 23:30 heeft Bastien het volgende geschreven: > > > > >>> I've just begin using rspec stories, and i m encountering some > > >>> problems. In my application i have different subdomains in which > > >>> specific users can log in, for example an admin will go to > > >>> admin.myapp.com/authenticate/login, and an user belonging to a > > >>> specific company will log in company.myapp.com/authenticate/login, > > >>> and > > >>> of course both have a different login process. > > > > >>> To perform some actions the user has to be logged in, and this is > > >>> where the problem comes, how to test these actions ? > > > > >>> - Is there a way to set a user as logged in ? (that would definitely > > >>> be very convenient) > > > > >>> So far I have tried to do the following : > > > > >>> post "/authenticate/login", > > >>> {:login => user_email, > > >>> :password => password } > > > > >>> but the problem is that it doesn't use the correct subdomain and the > > >>> login, as expected in that case, fails, so how to define the correct > > >>> subdomain ? > > > > >>> Thank you in advance for your help. > > >>> _______________________________________________ > > >>> rspec-users mailing list > > >>> rspec-us... at rubyforge.org > > >>>http://rubyforge.org/mailman/listinfo/rspec-users > > > > >> _______________________________________________ > > >> rspec-users mailing list > > >> rspec-us... at rubyforge > .orghttp://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.org > > >http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge > .orghttp://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/20080307/78046744/attachment.html From toastkid.williams at gmail.com Fri Mar 7 11:55:07 2008 From: toastkid.williams at gmail.com (Max Williams) Date: Fri, 7 Mar 2008 16:55:07 +0000 Subject: [rspec-users] [Stories] Login and subdomain In-Reply-To: References: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> <01B68B81-9133-4F77-864F-B51D93CC7340@gmail.com> <9f10480b-a3e3-41f1-8e85-93958bdedae1@q33g2000hsh.googlegroups.com> <10C0EB28-2F5F-4324-936E-065C4B7CEE1C@gmail.com> <6ec2a753-f7c1-4499-9459-47010f23e2fb@d62g2000hsf.googlegroups.com> Message-ID: Oh, sorry, and this line in your specs to actually mock the filter: mock_login_required :) On 07/03/2008, Max Williams wrote: > > I found it a little confusing to stub my authentication filters as well, > but figured it out with a little help from the interwebs: > > in spec_helper i have this: > > describe "a controller requiring login", :shared => true do > it "should have login_required set in the before filter" do > controller.class.before_filters.should include(:login_required) > end > end > > def mock_login_required(allow_user_to_pass=true) > controller.stub!(:login_required).and_return(allow_user_to_pass) > end > > Then, in any spec where i want to mock that filter, i just write > > it_should_behave_like "a controller requiring login" > > at the top of the describe block. > > Sorry, i can't remember the web page where i found this solution but > respect to whoever posted it :) > > On 06/03/2008, Bastien wrote: > > > > Thanks for your help. > > I tried the controller.stub!(...) as well, and it doesn't work. > > > > Ivo I totally agree with you and I'll follow your recommendations, > > thanks. > > > > (Would still be nice to know if the stubbing could work or if it's > > intended not to) > > > > > > On Mar 6, 4:27 pm, Ivo Dancet wrote: > > > You should not stub the authentication method in a story. The story > > > should test the whole application framework, that way your story might > > > look like this: > > > > > > Given a user from company x > > > When logging in > > > And requesting some page > > > Then the application should do all the stuff it should > > > > > > In the given step you set your host, user name and password and you > > > create that user. > > > In the when steps you make the login request and then you can start > > > doing the stuff you really want to test here as you'll have the > > > session you want at that moment. > > > > > > Regards > > > Ivo Dancet > > > > > > Op 6-mrt-08, om 16:12 heeft Bastien het volgende geschreven: > > > > > > > > > > > > > Thanks David, this works just fine. I would rather do some stubbing > > > > there if it's possible though. I tried : > > > > > > > ApplicationController.stub! > > > > (:user_authentication_required).and_return(true) > > > > > > > (which is the filter called before each action that checks whether > > the > > > > user is logged in or not) > > > > But it doesn't work. When I do this : > > > > > > > class ApplicationController > > > > def user_authentication_required > > > > return true > > > > end > > > > end > > > > > > > it works fine (but I find it quite dirty to redefine my method that > > > > way). Aren't this two solutions supposed to give me the same result > > ? > > > > Is something wrong with my stubbing ? > > > > > > > On Mar 6, 3:33 pm, Ivo Dancet wrote: > > > >> I think you can also use: > > > > > > >> post "/authentication/login", > > > >> { :login => user_email, > > > >> :password => password }, > > > >> :host => "company.example.com" > > > > > > >> Op 5-mrt-08, om 23:30 heeft Bastien het volgende geschreven: > > > > > > >>> I've just begin using rspec stories, and i m encountering some > > > >>> problems. In my application i have different subdomains in which > > > >>> specific users can log in, for example an admin will go to > > > >>> admin.myapp.com/authenticate/login, and an user belonging to a > > > >>> specific company will log in company.myapp.com/authenticate/login, > > > >>> and > > > >>> of course both have a different login process. > > > > > > >>> To perform some actions the user has to be logged in, and this is > > > >>> where the problem comes, how to test these actions ? > > > > > > >>> - Is there a way to set a user as logged in ? (that would > > definitely > > > >>> be very convenient) > > > > > > >>> So far I have tried to do the following : > > > > > > >>> post "/authenticate/login", > > > >>> {:login => user_email, > > > >>> :password => password } > > > > > > >>> but the problem is that it doesn't use the correct subdomain and > > the > > > >>> login, as expected in that case, fails, so how to define the > > correct > > > >>> subdomain ? > > > > > > >>> Thank you in advance for your help. > > > >>> _______________________________________________ > > > >>> rspec-users mailing list > > > >>> rspec-us... at rubyforge.org > > > >>>http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > >> _______________________________________________ > > > >> rspec-users mailing list > > > >> rspec-us... at rubyforge > > .orghttp://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-us... at rubyforge.org > > > >http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge > > .orghttp://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/20080307/1b516a6d/attachment-0001.html From zach.dennis at gmail.com Fri Mar 7 14:24:54 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 7 Mar 2008 14:24:54 -0500 Subject: [rspec-users] [Stories] Login and subdomain In-Reply-To: References: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> <01B68B81-9133-4F77-864F-B51D93CC7340@gmail.com> <9f10480b-a3e3-41f1-8e85-93958bdedae1@q33g2000hsh.googlegroups.com> <10C0EB28-2F5F-4324-936E-065C4B7CEE1C@gmail.com> <6ec2a753-f7c1-4499-9459-47010f23e2fb@d62g2000hsf.googlegroups.com> Message-ID: <85d99afe0803071124o7c5a077bk7e9d5dfa97a3e60@mail.gmail.com> We do something very very similar but rather then it_should_behave_like we wrap it in a it_requires_login method... describe SomeController do it_requires_login end Zach On Fri, Mar 7, 2008 at 11:53 AM, Max Williams wrote: > I found it a little confusing to stub my authentication filters as well, but > figured it out with a little help from the interwebs: > > in spec_helper i have this: > > describe "a controller requiring login", :shared => true do > it "should have login_required set in the before filter" do > controller.class.before_filters.should include(:login_required) > end > end > > def mock_login_required(allow_user_to_pass=true) > controller.stub!(:login_required).and_return(allow_user_to_pass) > end > > Then, in any spec where i want to mock that filter, i just write > > it_should_behave_like "a controller requiring login" > > at the top of the describe block. > > Sorry, i can't remember the web page where i found this solution but respect > to whoever posted it :) > > > > On 06/03/2008, Bastien wrote: > > Thanks for your help. > > I tried the controller.stub!(...) as well, and it doesn't work. > > > > Ivo I totally agree with you and I'll follow your recommendations, > > thanks. > > > > (Would still be nice to know if the stubbing could work or if it's > > intended not to) > > > > > > On Mar 6, 4:27 pm, Ivo Dancet wrote: > > > You should not stub the authentication method in a story. The story > > > should test the whole application framework, that way your story might > > > look like this: > > > > > > Given a user from company x > > > When logging in > > > And requesting some page > > > Then the application should do all the stuff it should > > > > > > In the given step you set your host, user name and password and you > > > create that user. > > > In the when steps you make the login request and then you can start > > > doing the stuff you really want to test here as you'll have the > > > session you want at that moment. > > > > > > Regards > > > Ivo Dancet > > > > > > Op 6-mrt-08, om 16:12 heeft Bastien het volgende geschreven: > > > > > > > > > > > > > Thanks David, this works just fine. I would rather do some stubbing > > > > there if it's possible though. I tried : > > > > > > > ApplicationController.stub! > > > > (:user_authentication_required).and_return(true) > > > > > > > (which is the filter called before each action that checks whether the > > > > user is logged in or not) > > > > But it doesn't work. When I do this : > > > > > > > class ApplicationController > > > > def user_authentication_required > > > > return true > > > > end > > > > end > > > > > > > it works fine (but I find it quite dirty to redefine my method that > > > > way). Aren't this two solutions supposed to give me the same result ? > > > > Is something wrong with my stubbing ? > > > > > > > On Mar 6, 3:33 pm, Ivo Dancet wrote: > > > >> I think you can also use: > > > > > > >> post "/authentication/login", > > > >> { :login => user_email, > > > >> :password => password }, > > > >> :host => "company.example.com" > > > > > > >> Op 5-mrt-08, om 23:30 heeft Bastien het volgende geschreven: > > > > > > >>> I've just begin using rspec stories, and i m encountering some > > > >>> problems. In my application i have different subdomains in which > > > >>> specific users can log in, for example an admin will go to > > > >>> admin.myapp.com/authenticate/login, and an user belonging to a > > > >>> specific company will log in company.myapp.com/authenticate/login, > > > >>> and > > > >>> of course both have a different login process. > > > > > > >>> To perform some actions the user has to be logged in, and this is > > > >>> where the problem comes, how to test these actions ? > > > > > > >>> - Is there a way to set a user as logged in ? (that would definitely > > > >>> be very convenient) > > > > > > >>> So far I have tried to do the following : > > > > > > >>> post "/authenticate/login", > > > >>> {:login => user_email, > > > >>> :password => password } > > > > > > >>> but the problem is that it doesn't use the correct subdomain and the > > > >>> login, as expected in that case, fails, so how to define the correct > > > >>> subdomain ? > > > > > > >>> Thank you in advance for your help. > > > >>> _______________________________________________ > > > >>> rspec-users mailing list > > > >>> rspec-us... at rubyforge.org > > > >>>http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > >> _______________________________________________ > > > >> rspec-users mailing list > > > >> > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-us... at rubyforge.org > > > >http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > _______________________________________________ > > > rspec-users mailing list > > > > rspec-us... at rubyforge.orghttp://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 > -- Zach Dennis http://www.continuousthinking.com From zach.dennis at gmail.com Fri Mar 7 15:35:31 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 7 Mar 2008 15:35:31 -0500 Subject: [rspec-users] [Stories] Login and subdomain In-Reply-To: <85d99afe0803070813w4c777e90p41bf23918710c146@mail.gmail.com> References: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> <01B68B81-9133-4F77-864F-B51D93CC7340@gmail.com> <9f10480b-a3e3-41f1-8e85-93958bdedae1@q33g2000hsh.googlegroups.com> <10C0EB28-2F5F-4324-936E-065C4B7CEE1C@gmail.com> <810a540e0803060738p2b736dc9qd89e86b2291cf6ca@mail.gmail.com> <85d99afe0803070813w4c777e90p41bf23918710c146@mail.gmail.com> Message-ID: <85d99afe0803071235i48b6909djbf68168362f48611@mail.gmail.com> In case it isn't clear... I agree with Ivo's statement: "You should not stub the authentication method in a story. The story should test the whole application framework". emphasis on "story" Zach On Fri, Mar 7, 2008 at 11:13 AM, Zach Dennis wrote: > On Thu, Mar 6, 2008 at 10:38 AM, Pat Maddox wrote: > > On Thu, Mar 6, 2008 at 7:27 AM, Ivo Dancet wrote: > > > You should not stub the authentication method in a story. The story > > > should test the whole application framework, that way your story might > > > look like this: > > > > > > Given a user from company x > > > When logging in > > > And requesting some page > > > Then the application should do all the stuff it should > > > > > > In the given step you set your host, user name and password and you > > > create that user. > > > In the when steps you make the login request and then you can start > > > doing the stuff you really want to test here as you'll have the > > > session you want at that moment. > > > > That's a little too dogmatic for me. You needn't go through the > > entire stack every story, and you needn't go through the entire app > > path either. > > > > IMO you should be simulating as much as possible what the user is > doing. If they have to go through path a, b, c ... to get to Z, then > so be it. This involves keeping a well-factored set of helpers which > can be used to navigate the app just like a user would. > > The only things you probably should be stubbing in a story are third > party components your site may have to integrate with that aren't > realistic to be run for every story (for the most part, there are > other exceptions as well I know). I would avoid stubbing core > functionality related to your site, > > -- > Zach Dennis > http://www.continuousthinking.com > -- Zach Dennis http://www.continuousthinking.com From will.sargent at gmail.com Fri Mar 7 22:40:24 2008 From: will.sargent at gmail.com (Will Sargent) Date: Fri, 7 Mar 2008 19:40:24 -0800 Subject: [rspec-users] rspec groups? Message-ID: One of the things I really liked about TestNG was the grouping feature. Are there any plans for rSpec to incorporate that? Is there any way to emulate that functionality in rspec? Will. From dchelimsky at gmail.com Sat Mar 8 11:11:18 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 8 Mar 2008 10:11:18 -0600 Subject: [rspec-users] rspec groups? In-Reply-To: References: Message-ID: <57c63afe0803080811l5b4b1e76vae9e234d45eb0ee3@mail.gmail.com> On Fri, Mar 7, 2008 at 9:40 PM, Will Sargent wrote: > One of the things I really liked about TestNG was the grouping > feature. Are there any plans for rSpec to incorporate that? Is there > any way to emulate that functionality in rspec? I'm not familiar with the feature you're talking about. What is it? > > Will. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From vertebrate at gmail.com Sat Mar 8 11:37:29 2008 From: vertebrate at gmail.com (Steve) Date: Sat, 8 Mar 2008 16:37:29 +0000 (UTC) Subject: [rspec-users] Session empty after request Message-ID: Can anyone tell me what I'm doing wrong here? it 'should try to set the current user from the session' do controller.session[SessionKeys::USER_ID] = 1 user = mock_model(User) User.stub!(:find).and_return(user) User.should_receive(:find).with(1).and_return(user) controller.should_receive(:set_current_user) do_request end When I watch the spec with my debugger, when it gets to the code, the session is empty, and the spec fails. What would be causing this? Am I setting the session wrong? I have also tried just session, and request.session with the same results. Thanks, Steve From agilejoe at gmail.com Sat Mar 8 12:37:37 2008 From: agilejoe at gmail.com (Joe Ocampo) Date: Sat, 8 Mar 2008 11:37:37 -0600 Subject: [rspec-users] BDD Google Mailing list. Message-ID: <93cf9750803080937x34d1de85w4475ec26e468c01b@mail.gmail.com> Hi everyone, We went ahead a created a BDD mailing list in Google to talk towards BDD and how it can be applied to just software development in general (language agnostic). We try to mediate the usage of language syntax but occasionally it creeps up in there. We would love to have Ruby BDD'rs (is that a word) lend their perspective on BDD as well. Looking forward to hear from you all. Google BDD Mailing List -- God Bless, Joe Ocampo agilejoe.lostechies.com "How do you benefit if you gain the whole world but lose your soul in the process?" Mark 8:36 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080308/d80ed4f6/attachment.html From zach.dennis at gmail.com Sat Mar 8 15:51:01 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sat, 8 Mar 2008 15:51:01 -0500 Subject: [rspec-users] ridding away with do_request Message-ID: <85d99afe0803081251xfb78f80k54d48cfadeea685c@mail.gmail.com> I'm heading out of town, but had a quick thought I wanted to share. Rather then using ambiguous named request helpers in controller specs like "do_request", I've been using more readable helpers like "post_create". For example... describe ProjectController do def post_create post :create, ... end before do end it "creates a new project" do Project.should_receive(:create).with(....) post_create end end IMO is adds a little more readability when looking at an individual "it" behavior on a controller spec. We've been keeping the request helpers as the first things immediately following a controller specification, ie: "describe SomeController do". Thoughts? -- Zach Dennis http://www.continuousthinking.com From stillepost at gmail.com Sat Mar 8 17:56:00 2008 From: stillepost at gmail.com (=?ISO-8859-1?Q?Thorben_Schr=F6der?=) Date: Sat, 8 Mar 2008 23:56:00 +0100 Subject: [rspec-users] should_receive(:foo).with(any_object) Message-ID: <64fe838e0803081456q253e8d17u1f64ff2445273084@mail.gmail.com> Hey, I just ran into a situation where I would like to expect a method call with an argument I know and another one, which is a random number. I think mocking up the rand method is somehow ugly so I thought maybe this is the first time where I can take something from Java to Ruby ;) Java's EasyMock mocking library knows things like "anyObject()" and "anyInteger()" in their method equivalent to should_receive. I like the idea so I added this to my Rails spec_helper.rb: class AnyObjectComparator attr_reader :object def ==(other) @object = other true end end class AnyNumberComparator < AnyObjectComparator def ==(other) super.==(other) other.is_a?(Numeric) end end def any_object @any_object ||= AnyObjectComparator.new @any_object end def any_number @any_number ||= AnyNumberComparator.new @any_number end Which gives me the ability to do the should_receive call like this: Item.should_receive(:random_item).with(any_object, any_number).at_least(1).times.and_return(mock_model(Item)) (the first any_object parameter is only in there for demonstration purposes ;) ) And if I would like to it's possible to get the actual value which was passed to as an argument with: any_xxx.object Ok, these any_xxx things behave somehow like a singleton but it's no problem at all to instantiate more of them to use many of them and afterwards get the actual value of any of them. So long. My question is: Is this too much effort? Is something like this already built into RSpec, I can't find something but I can't believe there isn't ;) and could this be done smarter? This singleton like behavior of any_xxx feels grubby. Thank you a lot! Thorben From pergesu at gmail.com Sat Mar 8 18:06:46 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 8 Mar 2008 15:06:46 -0800 Subject: [rspec-users] ridding away with do_request In-Reply-To: <85d99afe0803081251xfb78f80k54d48cfadeea685c@mail.gmail.com> References: <85d99afe0803081251xfb78f80k54d48cfadeea685c@mail.gmail.com> Message-ID: <810a540e0803081506m5cd573deredbc7827a1f8e150@mail.gmail.com> I've always used do_post/do_put etc. But your way is perfectly acceptable :) Pat On 3/8/08, Zach Dennis wrote: > I'm heading out of town, but had a quick thought I wanted to share. > Rather then using ambiguous named request helpers in controller specs > like "do_request", I've been using more readable helpers like > "post_create". > > For example... > > describe ProjectController do > def post_create > post :create, ... > end > > before do > end > > it "creates a new project" do > Project.should_receive(:create).with(....) > post_create > end > > end > > IMO is adds a little more readability when looking at an individual > "it" behavior on a controller spec. We've been keeping the request > helpers as the first things immediately following a controller > specification, ie: "describe SomeController do". > > Thoughts? > > -- > Zach Dennis > http://www.continuousthinking.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Sat Mar 8 19:22:01 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sat, 8 Mar 2008 19:22:01 -0500 Subject: [rspec-users] should_receive(:foo).with(any_object) In-Reply-To: <64fe838e0803081456q253e8d17u1f64ff2445273084@mail.gmail.com> References: <64fe838e0803081456q253e8d17u1f64ff2445273084@mail.gmail.com> Message-ID: On 3/8/08, Thorben Schr?der wrote: > Hey, > > I just ran into a situation where I would like to expect a method call > with an argument I know and another one, which is a random number. ... > Which gives me the ability to do the should_receive call like this: > > Item.should_receive(:random_item).with(any_object, > any_number).at_least(1).times.and_return(mock_model(Item)) > My question is: Is this too much effort? Is something like > this already built into RSpec, Item.should_receive(:random_item).with(:anything, :numeric) -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From stillepost at gmail.com Sat Mar 8 19:33:41 2008 From: stillepost at gmail.com (=?ISO-8859-1?Q?Thorben_Schr=F6der?=) Date: Sun, 9 Mar 2008 01:33:41 +0100 Subject: [rspec-users] should_receive(:foo).with(any_object) In-Reply-To: References: <64fe838e0803081456q253e8d17u1f64ff2445273084@mail.gmail.com> Message-ID: <64fe838e0803081633g67b18a54ibfd4d1e545915fa1@mail.gmail.com> Thanks a lot! Thorben On Sun, Mar 9, 2008 at 1:22 AM, Rick DeNatale wrote: > On 3/8/08, Thorben Schr?der wrote: > > Hey, > > > > I just ran into a situation where I would like to expect a method call > > with an argument I know and another one, which is a random number. > ... > > > > Which gives me the ability to do the should_receive call like this: > > > > Item.should_receive(:random_item).with(any_object, > > any_number).at_least(1).times.and_return(mock_model(Item)) > > > > My question is: Is this too much effort? Is something like > > this already built into RSpec, > > Item.should_receive(:random_item).with(:anything, :numeric) > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From stillepost at gmail.com Sat Mar 8 19:41:10 2008 From: stillepost at gmail.com (=?ISO-8859-1?Q?Thorben_Schr=F6der?=) Date: Sun, 9 Mar 2008 01:41:10 +0100 Subject: [rspec-users] should_receive(:foo).with(any_object) In-Reply-To: <64fe838e0803081633g67b18a54ibfd4d1e545915fa1@mail.gmail.com> References: <64fe838e0803081456q253e8d17u1f64ff2445273084@mail.gmail.com> <64fe838e0803081633g67b18a54ibfd4d1e545915fa1@mail.gmail.com> Message-ID: <64fe838e0803081641n7913bdrf628e3d5d158f281@mail.gmail.com> Just to stay correct: This Item.should_receive(:random_item).with(:anything, :numeric) is marked deprecated. It looks like it should be Item.should_receive(:random_item).with(anything, an_instance_of(Numeric)) Thorben On Sun, Mar 9, 2008 at 1:33 AM, Thorben Schr?der wrote: > Thanks a lot! > > Thorben > > > > On Sun, Mar 9, 2008 at 1:22 AM, Rick DeNatale wrote: > > On 3/8/08, Thorben Schr?der wrote: > > > Hey, > > > > > > I just ran into a situation where I would like to expect a method call > > > with an argument I know and another one, which is a random number. > > ... > > > > > > > Which gives me the ability to do the should_receive call like this: > > > > > > Item.should_receive(:random_item).with(any_object, > > > any_number).at_least(1).times.and_return(mock_model(Item)) > > > > > > > My question is: Is this too much effort? Is something like > > > this already built into RSpec, > > > > Item.should_receive(:random_item).with(:anything, :numeric) > > > > -- > > Rick DeNatale > > > > My blog on Ruby > > http://talklikeaduck.denhaven2.com/ > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From vertebrate at gmail.com Sun Mar 9 01:55:57 2008 From: vertebrate at gmail.com (Steve) Date: Sun, 9 Mar 2008 06:55:57 +0000 (UTC) Subject: [rspec-users] ridding away with do_request References: <85d99afe0803081251xfb78f80k54d48cfadeea685c@mail.gmail.com> Message-ID: On Sat, 08 Mar 2008 15:51:01 -0500, Zach Dennis wrote: > I'm heading out of town, but had a quick thought I wanted to share. > Rather then using ambiguous named request helpers in controller specs > like "do_request", I've been using more readable helpers like > "post_create". snip > IMO is adds a little more readability when looking at an individual "it" > behavior on a controller spec. We've been keeping the request helpers as > the first things immediately following a controller specification, ie: > "describe SomeController do". > > Thoughts? I would agree on the readability. The reason I stay with it though is that I have some shared behaviors that need to make the call on their own. It seems like it would be somewhat less convenient to wrap up or alias whatever method was performing a given HTTP verb. From dchelimsky at gmail.com Sun Mar 9 07:37:57 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 9 Mar 2008 11:37:57 +0000 Subject: [rspec-users] ridding away with do_request In-Reply-To: <85d99afe0803081251xfb78f80k54d48cfadeea685c@mail.gmail.com> References: <85d99afe0803081251xfb78f80k54d48cfadeea685c@mail.gmail.com> Message-ID: <57c63afe0803090437u3f783d3aye32e0c3a25e29a00@mail.gmail.com> On Sat, Mar 8, 2008 at 8:51 PM, Zach Dennis wrote: > I'm heading out of town, but had a quick thought I wanted to share. > Rather then using ambiguous named request helpers in controller specs > like "do_request", I've been using more readable helpers like > "post_create". > > For example... > > describe ProjectController do > def post_create > post :create, ... > end > > before do > end > > it "creates a new project" do > Project.should_receive(:create).with(....) > post_create > end > > end > > IMO is adds a little more readability when looking at an individual > "it" behavior on a controller spec. We've been keeping the request > helpers as the first things immediately following a controller > specification, ie: "describe SomeController do". > > Thoughts? Seems reasonable to me. > > -- > Zach Dennis > http://www.continuousthinking.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Mar 9 07:46:39 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 9 Mar 2008 11:46:39 +0000 Subject: [rspec-users] ridding away with do_request In-Reply-To: <810a540e0803081506m5cd573deredbc7827a1f8e150@mail.gmail.com> References: <85d99afe0803081251xfb78f80k54d48cfadeea685c@mail.gmail.com> <810a540e0803081506m5cd573deredbc7827a1f8e150@mail.gmail.com> Message-ID: <57c63afe0803090446g3abb8107pf3deec7ec7e517e@mail.gmail.com> On Sat, Mar 8, 2008 at 11:06 PM, Pat Maddox wrote: > I've always used do_post/do_put etc. But your way is perfectly acceptable :) That's what I do too - but I like Zach's idea here. Do you guys think the generated examples should use this? David > > Pat > > > > On 3/8/08, Zach Dennis wrote: > > I'm heading out of town, but had a quick thought I wanted to share. > > Rather then using ambiguous named request helpers in controller specs > > like "do_request", I've been using more readable helpers like > > "post_create". > > > > For example... > > > > describe ProjectController do > > def post_create > > post :create, ... > > end > > > > before do > > end > > > > it "creates a new project" do > > Project.should_receive(:create).with(....) > > post_create > > end > > > > end > > > > IMO is adds a little more readability when looking at an individual > > "it" behavior on a controller spec. We've been keeping the request > > helpers as the first things immediately following a controller > > specification, ie: "describe SomeController do". > > > > Thoughts? > > > > -- > > Zach Dennis > > http://www.continuousthinking.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 coreyhaines at gmail.com Sun Mar 9 11:31:12 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sun, 9 Mar 2008 10:31:12 -0500 Subject: [rspec-users] ridding away with do_request In-Reply-To: <57c63afe0803090446g3abb8107pf3deec7ec7e517e@mail.gmail.com> References: <85d99afe0803081251xfb78f80k54d48cfadeea685c@mail.gmail.com> <810a540e0803081506m5cd573deredbc7827a1f8e150@mail.gmail.com> <57c63afe0803090446g3abb8107pf3deec7ec7e517e@mail.gmail.com> Message-ID: <6bdacb70803090831i2a68c542ge734400ff355ad11@mail.gmail.com> What about overriding method_missing in the shared example group that will make conversions: post_XXXX -> post :XXXX put_XXXX -> put :XXXX etc. David posted thoughts on the before/after stuff, which is similar to what I do : http://blog.davidchelimsky.net/articles/2007/11/06/before_action-after_action I do like having the before/after part, too, as it is nice to pass a block in occasionally. -Corey On Sun, Mar 9, 2008 at 6:46 AM, David Chelimsky wrote: > On Sat, Mar 8, 2008 at 11:06 PM, Pat Maddox wrote: > > I've always used do_post/do_put etc. But your way is perfectly > acceptable :) > > That's what I do too - but I like Zach's idea here. Do you guys think > the generated examples should use this? > > David > > > > > Pat > > > > > > > > On 3/8/08, Zach Dennis wrote: > > > I'm heading out of town, but had a quick thought I wanted to share. > > > Rather then using ambiguous named request helpers in controller specs > > > like "do_request", I've been using more readable helpers like > > > "post_create". > > > > > > For example... > > > > > > describe ProjectController do > > > def post_create > > > post :create, ... > > > end > > > > > > before do > > > end > > > > > > it "creates a new project" do > > > Project.should_receive(:create).with(....) > > > post_create > > > end > > > > > > end > > > > > > IMO is adds a little more readability when looking at an individual > > > "it" behavior on a controller spec. We've been keeping the request > > > helpers as the first things immediately following a controller > > > specification, ie: "describe SomeController do". > > > > > > Thoughts? > > > > > > -- > > > Zach Dennis > > > http://www.continuousthinking.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 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080309/bd287277/attachment.html From dchelimsky at gmail.com Sun Mar 9 14:16:35 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 9 Mar 2008 18:16:35 +0000 Subject: [rspec-users] ridding away with do_request In-Reply-To: <6bdacb70803090831i2a68c542ge734400ff355ad11@mail.gmail.com> References: <85d99afe0803081251xfb78f80k54d48cfadeea685c@mail.gmail.com> <810a540e0803081506m5cd573deredbc7827a1f8e150@mail.gmail.com> <57c63afe0803090446g3abb8107pf3deec7ec7e517e@mail.gmail.com> <6bdacb70803090831i2a68c542ge734400ff355ad11@mail.gmail.com> Message-ID: <57c63afe0803091116y7393edf6mcddb87fd4d99c70d@mail.gmail.com> On Sun, Mar 9, 2008 at 3:31 PM, Corey Haines wrote: > What about overriding method_missing in the shared example group that will > make conversions: > > post_XXXX -> post :XXXX > put_XXXX -> put :XXXX That's fine until you start adding parameters, at which point you'd end up calling this: put_update :id => 3 I don't see much point in that :) Cheers, David > > etc. > > David posted thoughts on the before/after stuff, which is similar to what I > do : > http://blog.davidchelimsky.net/articles/2007/11/06/before_action-after_action > > I do like having the before/after part, too, as it is nice to pass a block > in occasionally. > > -Corey > > > > On Sun, Mar 9, 2008 at 6:46 AM, David Chelimsky > wrote: > > > > > On Sat, Mar 8, 2008 at 11:06 PM, Pat Maddox wrote: > > > I've always used do_post/do_put etc. But your way is perfectly > acceptable :) > > > > That's what I do too - but I like Zach's idea here. Do you guys think > > the generated examples should use this? > > > > David > > > > > > > > > > > > > > Pat > > > > > > > > > > > > On 3/8/08, Zach Dennis wrote: > > > > I'm heading out of town, but had a quick thought I wanted to share. > > > > Rather then using ambiguous named request helpers in controller specs > > > > like "do_request", I've been using more readable helpers like > > > > "post_create". > > > > > > > > For example... > > > > > > > > describe ProjectController do > > > > def post_create > > > > post :create, ... > > > > end > > > > > > > > before do > > > > end > > > > > > > > it "creates a new project" do > > > > Project.should_receive(:create).with(....) > > > > post_create > > > > end > > > > > > > > end > > > > > > > > IMO is adds a little more readability when looking at an individual > > > > "it" behavior on a controller spec. We've been keeping the request > > > > helpers as the first things immediately following a controller > > > > specification, ie: "describe SomeController do". > > > > > > > > Thoughts? > > > > > > > > -- > > > > Zach Dennis > > > > http://www.continuousthinking.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 > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Sun Mar 9 14:36:12 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 9 Mar 2008 11:36:12 -0700 Subject: [rspec-users] ridding away with do_request In-Reply-To: <57c63afe0803090446g3abb8107pf3deec7ec7e517e@mail.gmail.com> References: <85d99afe0803081251xfb78f80k54d48cfadeea685c@mail.gmail.com> <810a540e0803081506m5cd573deredbc7827a1f8e150@mail.gmail.com> <57c63afe0803090446g3abb8107pf3deec7ec7e517e@mail.gmail.com> Message-ID: <810a540e0803091136j684742b0qa45650d7183c310a@mail.gmail.com> On Sun, Mar 9, 2008 at 4:46 AM, David Chelimsky wrote: > On Sat, Mar 8, 2008 at 11:06 PM, Pat Maddox wrote: > > I've always used do_post/do_put etc. But your way is perfectly acceptable :) > > That's what I do too - but I like Zach's idea here. Do you guys think > the generated examples should use this? I'm indifferent to it. The reason I use do_put instead of put_update is because when dealing with resources, the interface is PUT /resource. The fact that it maps to the #update method is a Rails implementation detail. So I find it useful to name that little helper method in a way that reflects the external API. That's just the way I think of it though. I'd be pissed off if someone did a global search and replace on my code, but for RSpec generated code I don't have a strong opinion. I think it raises an interesting philosophical issue though. We care about naming a great deal, so do_request->post_create is certainly an improvement. And for me, do_post is better than post_create, because my apps are all RESTful. So the question in my mind is whether our suggestion ends at better naming, or if we ought to subtly encourage more RESTful apps, which seems to be a widespread good practice in the Rails community. I'm also afraid that this is a bike shed scenario and I'm thinking way too deeply into it. Someone please show me the light :) Pat From dchelimsky at gmail.com Sun Mar 9 17:10:08 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 9 Mar 2008 21:10:08 +0000 Subject: [rspec-users] Session empty after request In-Reply-To: References: Message-ID: <57c63afe0803091410i57493836vbd31c10eb698abe6@mail.gmail.com> On Sat, Mar 8, 2008 at 4:37 PM, Steve wrote: > Can anyone tell me what I'm doing wrong here? > > it 'should try to set the current user from the session' do > controller.session[SessionKeys::USER_ID] = 1 > user = mock_model(User) > User.stub!(:find).and_return(user) > User.should_receive(:find).with(1).and_return(user) > controller.should_receive(:set_current_user) > do_request > end > > When I watch the spec with my debugger, when it gets to the code, the > session is empty, and the spec fails. What would be causing this? Am I > setting the session wrong? I have also tried just session, and > request.session with the same results. You've uncovered a bug. I forwarded this mail to http://rspec.lighthouseapp.com (please put bug reports there in the future), creating http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/331. Fixed in http://github.com/dchelimsky/rspec/commit/097d63d. Cheers, David > > Thanks, > Steve > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From will.sargent at gmail.com Sun Mar 9 20:36:04 2008 From: will.sargent at gmail.com (Will Sargent) Date: Sun, 9 Mar 2008 17:36:04 -0700 Subject: [rspec-users] rspec groups? In-Reply-To: <57c63afe0803080811l5b4b1e76vae9e234d45eb0ee3@mail.gmail.com> References: <57c63afe0803080811l5b4b1e76vae9e234d45eb0ee3@mail.gmail.com> Message-ID: On Sat, Mar 8, 2008 at 9:11 AM, David Chelimsky wrote: > > On Fri, Mar 7, 2008 at 9:40 PM, Will Sargent wrote: > > One of the things I really liked about TestNG was the grouping > > feature. Are there any plans for rSpec to incorporate that? Is there > > any way to emulate that functionality in rspec? > > I'm not familiar with the feature you're talking about. What is it? The idea is that you can specify that certain tests exist in groups, and can be run as a set. You can define groups and groups of groups, and so you can run a set of functional tests or all the tests dealing with a specific feature without running through the entire thing. It's kinda like an rspec pattern, but more flexible. Documentation is here: http://testng.org/doc/documentation-main.html#test-groups Will. From bastien.vaucher at gmail.com Mon Mar 10 06:50:35 2008 From: bastien.vaucher at gmail.com (Bastien) Date: Mon, 10 Mar 2008 03:50:35 -0700 (PDT) Subject: [rspec-users] [Stories] Login and subdomain In-Reply-To: <85d99afe0803071235i48b6909djbf68168362f48611@mail.gmail.com> References: <3bff4fe6-20aa-4e7d-9dbf-cbf0da80324a@n77g2000hse.googlegroups.com> <01B68B81-9133-4F77-864F-B51D93CC7340@gmail.com> <9f10480b-a3e3-41f1-8e85-93958bdedae1@q33g2000hsh.googlegroups.com> <10C0EB28-2F5F-4324-936E-065C4B7CEE1C@gmail.com> <810a540e0803060738p2b736dc9qd89e86b2291cf6ca@mail.gmail.com> <85d99afe0803070813w4c777e90p41bf23918710c146@mail.gmail.com> <85d99afe0803071235i48b6909djbf68168362f48611@mail.gmail.com> Message-ID: Thanks to all of you, I added the login as a part of the story and now it works smoothly. On Mar 7, 9:35 pm, "Zach Dennis" wrote: > In case it isn't clear... I agree with Ivo's statement: > > "You should not stub the authentication method in a story. The story > should test the whole application framework". > > emphasis on "story" > > Zach > > > > On Fri, Mar 7, 2008 at 11:13 AM, Zach Dennis wrote: > > On Thu, Mar 6, 2008 at 10:38 AM, Pat Maddox wrote: > > > On Thu, Mar 6, 2008 at 7:27 AM, Ivo Dancet wrote: > > > > You should not stub the authentication method in a story. The story > > > > should test the whole application framework, that way your story might > > > > look like this: > > > > > Given a user from company x > > > > When logging in > > > > And requesting some page > > > > Then the application should do all the stuff it should > > > > > In the given step you set your host, user name and password and you > > > > create that user. > > > > In the when steps you make the login request and then you can start > > > > doing the stuff you really want to test here as you'll have the > > > > session you want at that moment. > > > > That's a little too dogmatic for me. You needn't go through the > > > entire stack every story, and you needn't go through the entire app > > > path either. > > > IMO you should be simulating as much as possible what the user is > > doing. If they have to go through path a, b, c ... to get to Z, then > > so be it. This involves keeping a well-factored set of helpers which > > can be used to navigate the app just like a user would. > > > The only things you probably should be stubbing in a story are third > > party components your site may have to integrate with that aren't > > realistic to be run for every story (for the most part, there are > > other exceptions as well I know). I would avoid stubbing core > > functionality related to your site, > > > -- > > Zach Dennis > > http://www.continuousthinking.com > > -- > Zach Dennishttp://www.continuousthinking.com > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From edvard at majakari.net Mon Mar 10 08:42:26 2008 From: edvard at majakari.net (Edvard Majakari) Date: Mon, 10 Mar 2008 14:42:26 +0200 Subject: [rspec-users] rspec groups? In-Reply-To: References: <57c63afe0803080811l5b4b1e76vae9e234d45eb0ee3@mail.gmail.com> Message-ID: > The idea is that you can specify that certain tests exist in groups, > and can be run as a set. You can define groups and groups of groups, > and so you can run a set of functional tests or all the tests dealing > with a specific feature without running through the entire thing. > It's kinda like an rspec pattern, but more flexible. Might not be of help, but my problem was a tad similar when I used test/spec (rspecish test/unit wrapper). I had five types of test tasks in my Rakefile: test:units, test:functionals, test:integration, test:libs and test:helpers. The integration and lib tests took the most of the time, so I created custom tasks test:all_but_integration (quite self-explanatory, no?) and test:webserver, which ran everything else except test:libs. The way I did it was that test:all_but_integration just depended on the tasks test:units, tests:functionals etc. So, if you want grouping inside features in a single test suite, this won't help, but for me, being able to control which (whole) files were run with Rake was sufficient for me. The whole suite took something like 15 minutes, but we had thousands of tests and when we started, we didn't use that much mock objects. That said, I have never needed nor wished the ability to combine test suites using test/spec or rspec. Being able to choose which contexts/describes or individual specs will be run has been more than sufficient to me, but of course, YNMDFTOM. -- "One day, when he was naughty, Mr Bunnsy looked over the hedge into Farmer Fred's field and it was full of fresh green lettuces. Mr Bunnsy, however, was not full of lettuces. This did not seem fair." -- Terry Pratchett, Mr. Bunnsy Has An Adventure From oli.azevedo.barnes at gmail.com Mon Mar 10 17:01:44 2008 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Mon, 10 Mar 2008 18:01:44 -0300 Subject: [rspec-users] tutes on testing controllers Message-ID: <6466d9040803101401o3169fe3dl47a8d00626ce540@mail.gmail.com> hello spec'ers, i'm in the hunt for guides on testing controllers with rspec, would you guys recommend any? thanks Oliver -- Oliver Azevedo Barnes oli.azevedo.barnes at gmail.com +55 11 9768 0193 http://www.linkedin.com/in/oliverbarnes http://workingwithrails.com/person/4704-oliver-barnes From coreyhaines at gmail.com Mon Mar 10 22:53:14 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Mon, 10 Mar 2008 22:53:14 -0400 Subject: [rspec-users] Story testing views in isolation Message-ID: <6bdacb70803101953n74a3c0cbn7a1f84326e82e832@mail.gmail.com> Hi, I've been investigating plain text stories, and I had a quick question. How would I go about creating story tests for views in isolation, instead of the full stack? I had hoped to be able to do a straight render '/', but it says it can't find the method. The reason that I want to do this is that I want to give our designer/business people a way to write stories to describe their user interface while they work on the prototype, then give us the stories to help us integrate their prototypes more safely. I realize that I could use examples for this, but I was hoping to use stories. -Corey -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080310/9273f15e/attachment.html From jonathan at parkerhill.com Mon Mar 10 23:23:41 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Mon, 10 Mar 2008 23:23:41 -0400 Subject: [rspec-users] view spec on rails questions Message-ID: <494102C5-4401-4924-836B-424DF5206D37@parkerhill.com> Hi I have a couple of questions 1) how do you test the response inside a content_for block I see reference to it in the release notes but dont know where to find it (tried http://rspec.info/rdoc-rails/ ) 2) I dont seem to be able to stub partials in a different directory eg <%= render :partial => "foos/show" %> And I put this in the spec template.stub_render(:partial => "foos/show") the stub gets ignored and the partial still gets rendered It works fine with partials in the same directory I'm runing rspec 1.1.3 thanks linoj From pergesu at gmail.com Tue Mar 11 02:38:46 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 10 Mar 2008 23:38:46 -0700 Subject: [rspec-users] tutes on testing controllers In-Reply-To: <6466d9040803101401o3169fe3dl47a8d00626ce540@mail.gmail.com> References: <6466d9040803101401o3169fe3dl47a8d00626ce540@mail.gmail.com> Message-ID: <810a540e0803102338y4ede00efge3e460512d0af2ab@mail.gmail.com> On Mon, Mar 10, 2008 at 2:01 PM, Oliver Barnes wrote: > hello spec'ers, > > i'm in the hunt for guides on testing controllers with rspec, would > you guys recommend any? Oldie but goodie (I hope) - http://evang.eli.st/blog/2007/9/15/easy-controller-tests-and-expressing-intent-through-expectations Pat From dchelimsky at gmail.com Tue Mar 11 06:16:29 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Mar 2008 10:16:29 +0000 Subject: [rspec-users] Story testing views in isolation In-Reply-To: <6bdacb70803101953n74a3c0cbn7a1f84326e82e832@mail.gmail.com> References: <6bdacb70803101953n74a3c0cbn7a1f84326e82e832@mail.gmail.com> Message-ID: <57c63afe0803110316x24226c40m252690ad90869c00@mail.gmail.com> On Tue, Mar 11, 2008 at 2:53 AM, Corey Haines wrote: > Hi, > > I've been investigating plain text stories, and I had a quick question. How > would I go about creating story tests for views in isolation, instead of the > full stack? I had hoped to be able to do a straight render '/', but it says > it can't find the method. We didn't really think of views in isolation for stories. > The reason that I want to do this is that I want to give our > designer/business people a way to write stories to describe their user > interface while they work on the prototype, then give us the stories to help > us integrate their prototypes more safely. So you're hoping they'll use the stories and get them to pass against the views as they evolve? > I realize that I could use examples for this, but I was hoping to use > stories. There's really no support for this as it stands. Not sure if I'd want that to change. Other opinions? David > > -Corey > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From coreyhaines at gmail.com Tue Mar 11 08:03:06 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Tue, 11 Mar 2008 08:03:06 -0400 Subject: [rspec-users] Story testing views in isolation In-Reply-To: <57c63afe0803110316x24226c40m252690ad90869c00@mail.gmail.com> References: <6bdacb70803101953n74a3c0cbn7a1f84326e82e832@mail.gmail.com> <57c63afe0803110316x24226c40m252690ad90869c00@mail.gmail.com> Message-ID: <6bdacb70803110503m7c2fdd8m6b68aa0292b3a028@mail.gmail.com> On Tue, Mar 11, 2008 at 6:16 AM, David Chelimsky wrote: > > The reason that I want to do this is that I want to give our > > designer/business people a way to write stories to describe their user > > interface while they work on the prototype, then give us the stories to > help > > us integrate their prototypes more safely. > > So you're hoping they'll use the stories and get them to pass against > the views as they evolve? > Yeah. I'd like to have them use the stories against the mockups they build, then we move the stories to the live app as we integrate their changes. These are just some initial thoughts I've had, so I'm always open to alternate ideas. One option I thought about was to use pages that don't have any functionality behind them (other than perhaps some basic navigation), then they could design their mockups against these. As we integrate their designs in, we can start adding functionality behind it. This seems more in line with (perhaps one of) the original ideas for stories. > > > I realize that I could use examples for this, but I was hoping to use > > stories. > > There's really no support for this as it stands. Not sure if I'd want > that to change. Other opinions? > > Would it be as simple as supporting render/assigns, like in view specs? In the end, our designer/business have programming skills, so I could have them use example groups; it isn't like example groups are so incredibly cryptic. When you format as specdoc, they provide a decent doumentation; I do like stories better, though. :) -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080311/fe1e48fb/attachment.html From coreyhaines at gmail.com Tue Mar 11 08:08:23 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Tue, 11 Mar 2008 08:08:23 -0400 Subject: [rspec-users] outside-in = integration tests on views? In-Reply-To: <47CB6739.9090005@benmabey.com> References: <93ddac20802291533y167fcc58p4e1e2bbf017c39e7@mail.gmail.com> <57c63afe0802291606i322b68f1t1dbc3873fb573e4f@mail.gmail.com> <93ddac20803021734k5ce20b42qac1db87965b657c5@mail.gmail.com> <47CB6739.9090005@benmabey.com> Message-ID: <6bdacb70803110508o57f9e405i49b90aa07a4b5de7@mail.gmail.com> I just watched the story one on Sunday, and it was great. I bought a 5 pack and can't wait to watch the next one. -Corey On Sun, Mar 2, 2008 at 10:49 PM, Ben Mabey wrote: > > > > > > > BTW, Are the PeepCode rSpec tutorials worth buying? > > > > They are a steal. I watched them after I had already been using rSpec > for a couple months and I still learned a lot and felt like they were a > great investment. I haven't watched the Story one yet but the general > rspec ones were great. > > -Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080311/9179c10e/attachment.html From rick.denatale at gmail.com Tue Mar 11 08:14:38 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 11 Mar 2008 08:14:38 -0400 Subject: [rspec-users] Composed Stories/Scenarios Message-ID: In using stories, I find myself wanting to build scenarios on top of each other, For example I want something like Scenario: The user logs on Given a And b When c And d Then e And f Scenario: The user changes his password Given the user logs on And g Then h In other words, I'd like to write the second scenario starting with the 'state' produced by the first. I'd like to 'invoke' a scenario in a Given or When clause. I think that this should mean that the Given and When clauses of the scenario being invoked would be inserted/run at this point. The Then clauses wouldn't I would think since these are 'tested' when the original scenario is run. Does this make sense? How have others dealt with this? This is probably at tension with the XP notion of stories being minimal and isolated, but RBehave/RSpec stories already seem to have that tension IMHO. Thoughts? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From zach.dennis at gmail.com Tue Mar 11 08:39:41 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 11 Mar 2008 08:39:41 -0400 Subject: [rspec-users] Story testing views in isolation In-Reply-To: <6bdacb70803110503m7c2fdd8m6b68aa0292b3a028@mail.gmail.com> References: <6bdacb70803101953n74a3c0cbn7a1f84326e82e832@mail.gmail.com> <57c63afe0803110316x24226c40m252690ad90869c00@mail.gmail.com> <6bdacb70803110503m7c2fdd8m6b68aa0292b3a028@mail.gmail.com> Message-ID: <85d99afe0803110539k70d15cadna752b91b12135236@mail.gmail.com> On Tue, Mar 11, 2008 at 8:03 AM, Corey Haines wrote: > > > On Tue, Mar 11, 2008 at 6:16 AM, David Chelimsky > wrote: > > > > > The reason that I want to do this is that I want to give our > > > designer/business people a way to write stories to describe their user > > > interface while they work on the prototype, then give us the stories to > help > > > us integrate their prototypes more safely. > > > > So you're hoping they'll use the stories and get them to pass against > > the views as they evolve? > > > > > > Yeah. I'd like to have them use the stories against the mockups they build, > then we move the stories to the live app as we integrate their changes. > These are just some initial thoughts I've had, so I'm always open to > alternate ideas. > > One option I thought about was to use pages that don't have any > functionality behind them (other than perhaps some basic navigation), then > they could design their mockups against these. As we integrate their designs > in, we can start adding functionality behind it. This seems more in line > with (perhaps one of) the original ideas for stories. > > > > > > > > I realize that I could use examples for this, but I was hoping to use > > > stories. > > > > There's really no support for this as it stands. Not sure if I'd want > > that to change. Other opinions? > > > This feels like a square peg in a round hole type of situation. It doesn't seem like in practice this works very well: Given a user When they Then they see In isolation the Given/When/Then don't make as much sense because you can't do anything, you don't go anywhere and the Given/When/Then make less sense in the context of isolation. It also seems to muddy the definition of a story. All in all it just feels kind of funny. +1 for keeping view specs act as view specs and stories act as stories. -- Zach Dennis http://www.continuousthinking.com From dchelimsky at gmail.com Tue Mar 11 08:40:38 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 11 Mar 2008 12:40:38 +0000 Subject: [rspec-users] Composed Stories/Scenarios In-Reply-To: References: Message-ID: <57c63afe0803110540x5c605f58yc1a7b16356a478b@mail.gmail.com> On Tue, Mar 11, 2008 at 12:14 PM, Rick DeNatale wrote: > In using stories, I find myself wanting to build scenarios on top of each other, > > For example > > I want something like > > Scenario: The user logs on > Given a > And b > When c > And d > Then e > And f > > Scenario: The user changes his password > Given the user logs on > And g > Then h > > In other words, I'd like to write the second scenario starting with > the 'state' produced by the first. I'd like to 'invoke' a scenario in > a Given or When clause. I think that this should mean that the Given > and When clauses of the scenario being invoked would be inserted/run > at this point. The Then clauses wouldn't I would think since these > are 'tested' when the original scenario is run. > > Does this make sense? How have others dealt with this? > > This is probably at tension with the XP notion of stories being > minimal and isolated, but RBehave/RSpec stories already seem to have > that tension IMHO. This is already supported - use GivenScenario like this: Scenario: The user changes his password GivenScenario: The user logs on And g Then h This only works within the same story. Cheers, David > > Thoughts? > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Tue Mar 11 08:54:06 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 11 Mar 2008 08:54:06 -0400 Subject: [rspec-users] Story testing views in isolation In-Reply-To: <85d99afe0803110539k70d15cadna752b91b12135236@mail.gmail.com> References: <6bdacb70803101953n74a3c0cbn7a1f84326e82e832@mail.gmail.com> <57c63afe0803110316x24226c40m252690ad90869c00@mail.gmail.com> <6bdacb70803110503m7c2fdd8m6b68aa0292b3a028@mail.gmail.com> <85d99afe0803110539k70d15cadna752b91b12135236@mail.gmail.com> Message-ID: <85d99afe0803110554q7fba1dfy2668209818b2b90b@mail.gmail.com> Corey, What part of the Story do you like that you want the designers to be exposed to? A higher level API, the plain text part (separation from implementation of the test), etc... ? Zach On Tue, Mar 11, 2008 at 8:39 AM, Zach Dennis wrote: > On Tue, Mar 11, 2008 at 8:03 AM, Corey Haines wrote: > > > > > > On Tue, Mar 11, 2008 at 6:16 AM, David Chelimsky > > wrote: > > > > > > > The reason that I want to do this is that I want to give our > > > > designer/business people a way to write stories to describe their user > > > > interface while they work on the prototype, then give us the stories to > > help > > > > us integrate their prototypes more safely. > > > > > > So you're hoping they'll use the stories and get them to pass against > > > the views as they evolve? > > > > > > > > > > Yeah. I'd like to have them use the stories against the mockups they build, > > then we move the stories to the live app as we integrate their changes. > > These are just some initial thoughts I've had, so I'm always open to > > alternate ideas. > > > > One option I thought about was to use pages that don't have any > > functionality behind them (other than perhaps some basic navigation), then > > they could design their mockups against these. As we integrate their designs > > in, we can start adding functionality behind it. This seems more in line > > with (perhaps one of) the original ideas for stories. > > > > > > > > > > > > I realize that I could use examples for this, but I was hoping to use > > > > stories. > > > > > > There's really no support for this as it stands. Not sure if I'd want > > > that to change. Other opinions? > > > > > > > This feels like a square peg in a round hole type of situation. It > doesn't seem like in practice this works very well: > > Given a user > When they > Then they see > > In isolation the Given/When/Then don't make as much sense because you > can't do anything, you don't go anywhere and the Given/When/Then make > less sense in the context of isolation. It also seems to muddy the > definition of a story. All in all it just feels kind of funny. > > +1 for keeping view specs act as view specs and stories act as stories. > > > -- > Zach Dennis > http://www.continuousthinking.com > -- Zach Dennis http://www.continuousthinking.com From rick.denatale at gmail.com Tue Mar 11 09:28:43 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 11 Mar 2008 09:28:43 -0400 Subject: [rspec-users] Composed Stories/Scenarios In-Reply-To: <57c63afe0803110540x5c605f58yc1a7b16356a478b@mail.gmail.com> References: <57c63afe0803110540x5c605f58yc1a7b16356a478b@mail.gmail.com> Message-ID: On 3/11/08, David Chelimsky wrote: > On Tue, Mar 11, 2008 at 12:14 PM, Rick DeNatale wrote: > > In using stories, I find myself wanting to build scenarios on top of each other, > > > > For example > > > > I want something like > > > > Scenario: The user logs on > > Given a > > And b > > When c > > And d > > Then e > > And f > > > > Scenario: The user changes his password > > Given the user logs on > > And g > > Then h > > > > In other words, I'd like to write the second scenario starting with > > the 'state' produced by the first. I'd like to 'invoke' a scenario in > > a Given or When clause. I think that this should mean that the Given > > and When clauses of the scenario being invoked would be inserted/run > > at this point. The Then clauses wouldn't I would think since these > > are 'tested' when the original scenario is run. > > > > Does this make sense? How have others dealt with this? > > > > This is probably at tension with the XP notion of stories being > > minimal and isolated, but RBehave/RSpec stories already seem to have > > that tension IMHO. > > > This is already supported - use GivenScenario like this: > > > Scenario: The user changes his password > > GivenScenario: The user logs on > And g > Then h > > This only works within the same story. Cool! -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From zach.dennis at gmail.com Tue Mar 11 09:30:15 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 11 Mar 2008 09:30:15 -0400 Subject: [rspec-users] view spec on rails questions In-Reply-To: <494102C5-4401-4924-836B-424DF5206D37@parkerhill.com> References: <494102C5-4401-4924-836B-424DF5206D37@parkerhill.com> Message-ID: <85d99afe0803110630i3d301691o9b8a07fdf80ddfe1@mail.gmail.com> For content_for blocks we have a separate "testing.html.erb" layout which we use when rendering our view from our spec. We then ensure the things generated in content_for are rendered correctly.. ie: render "foo/index", :layout => "testing" Zach On Mon, Mar 10, 2008 at 11:23 PM, Jonathan Linowes wrote: > Hi > I have a couple of questions > > 1) > how do you test the response inside a content_for block > I see reference to it in the release notes but dont know where to > find it (tried http://rspec.info/rdoc-rails/ ) > > 2) > I dont seem to be able to stub partials in a different directory eg > <%= render :partial => "foos/show" %> > And I put this in the spec > template.stub_render(:partial => "foos/show") > the stub gets ignored and the partial still gets rendered > It works fine with partials in the same directory > > I'm runing rspec 1.1.3 > thanks > linoj > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com From origin at fortuity.com Tue Mar 11 09:52:57 2008 From: origin at fortuity.com (Daniel Kehoe) Date: Tue, 11 Mar 2008 06:52:57 -0700 Subject: [rspec-users] for a beginner - good rspec examples? Message-ID: <7930AF35-A365-4C9A-8216-744AC0375B34@fortuity.com> I'm learning to use rspec and I want to see some good examples. Any recommendations of open source projects that demonstrate the use of rspec? So far I've found: 1) the Caboose sample app (http://sample.caboo.se/) 2) the Altered Beast forums app (http://beast.caboo.se/forums/1/topics/4650 ) Any others come to mind? I'm especially interested in seeing examples that spec RESTful authentication. Thanks, Daniel From jarkko at jlaine.net Tue Mar 11 10:00:00 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Tue, 11 Mar 2008 16:00:00 +0200 Subject: [rspec-users] Story testing views in isolation In-Reply-To: <85d99afe0803110539k70d15cadna752b91b12135236@mail.gmail.com> References: <6bdacb70803101953n74a3c0cbn7a1f84326e82e832@mail.gmail.com> <57c63afe0803110316x24226c40m252690ad90869c00@mail.gmail.com> <6bdacb70803110503m7c2fdd8m6b68aa0292b3a028@mail.gmail.com> <85d99afe0803110539k70d15cadna752b91b12135236@mail.gmail.com> Message-ID: <909400ef0803110700k68668732je9d0a72c243939ea@mail.gmail.com> On Tue, Mar 11, 2008 at 2:39 PM, Zach Dennis wrote: > +1 for keeping view specs act as view specs and stories act as stories. Agreed. AFAIK stories are for describing a series of actions and behavior and that doesn't really fit in nicely with specifying views in isolation. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi From cremes.devlist at mac.com Tue Mar 11 10:06:31 2008 From: cremes.devlist at mac.com (Chuck Remes) Date: Tue, 11 Mar 2008 09:06:31 -0500 Subject: [rspec-users] for a beginner - good rspec examples? In-Reply-To: <7930AF35-A365-4C9A-8216-744AC0375B34@fortuity.com> References: <7930AF35-A365-4C9A-8216-744AC0375B34@fortuity.com> Message-ID: On Mar 11, 2008, at 8:52 AM, Daniel Kehoe wrote: > I'm learning to use rspec and I want to see some good examples. > > Any recommendations of open source projects that demonstrate the use > of rspec? > > So far I've found: > > 1) the Caboose sample app (http://sample.caboo.se/) > > 2) the Altered Beast forums app (http://beast.caboo.se/forums/1/topics/4650 > ) > > Any others come to mind? > > I'm especially interested in seeing examples that spec RESTful > authentication. Daniel, I was in your place asking this question about a month ago. Here are the pointers that were helpful to me. [1] http://www.oreillynet.com/pub/a/ruby/2007/08/09/behavior-driven-development-using-ruby-part-1.html [2] http://svn.nightlite.org/applications/cody/trunk/ After examining the links above, I rewrote a small project that I already had working only this time I used BDD for the process. I ended up writing about 50% more code and created about 100% more methods, but the resulting program was much easier to understand and very easy to extend. I also had 100% code coverage which was a first for me. I don't know if the code I wrote would be useful to you but I would be happy to send you a tarball (under 50k) containing this project. Good luck. cr From bastien.vaucher at gmail.com Tue Mar 11 10:30:58 2008 From: bastien.vaucher at gmail.com (Bastien) Date: Tue, 11 Mar 2008 07:30:58 -0700 (PDT) Subject: [rspec-users] [Stories]Changes in the database not taken into account Message-ID: <944ecce7-40cb-4e90-9ade-8fc00e52eaa6@m44g2000hsc.googlegroups.com> I have these scenarios : Story: Filling a profile As a user I want to fill a profile So that I can see my score Scenario: Starting a new profile ...* And 3 questions ...* When the user answers a question Then there should be one more answer Then there should be one question less to answer Scenario: Ending a profile ...* And 1 question ...* When the user answers a question Then there should be one more answer Then there should be no more question to answer * code hidden for clarity If I run these two scenarios independently they both work, but when i run them one after the other, the second scenario fails. The problem appears in Given($amount questions?), even I create a new question in the database, it doesn't seem to be taken into account and keeps the 3 questions I created in the previous scenario. Here is what it looks like : Given("$amount questions?") do |amount| Question.delete_all amount.to_i.times do Factory.create_valid_question end end class Factory def self.create_valid_question() Question.create!(:value => "some question ") end end By adding outputs I observed that during the second scenario there are no questions in the database before the "times" loop, that they are created inside it, but after the loop I have the same questions in the database as the ones i had in the previous scenario and not the one i just created through the loop. This is really strange. (Sorry for this long question). Do you have any idea what I do wrong ? From bryansray at gmail.com Tue Mar 11 18:21:50 2008 From: bryansray at gmail.com (Bryan Ray) Date: Tue, 11 Mar 2008 17:21:50 -0500 Subject: [rspec-users] for a beginner - good rspec examples? In-Reply-To: References: <7930AF35-A365-4C9A-8216-744AC0375B34@fortuity.com> Message-ID: <29a0119e0803111521k6a6240b5h810e04371d5d0726@mail.gmail.com> David Chelimsky's blog has a lot of good information as well. On Tue, Mar 11, 2008 at 9:06 AM, Chuck Remes wrote: > > On Mar 11, 2008, at 8:52 AM, Daniel Kehoe wrote: > > > I'm learning to use rspec and I want to see some good examples. > > > > Any recommendations of open source projects that demonstrate the use > > of rspec? > > > > So far I've found: > > > > 1) the Caboose sample app (http://sample.caboo.se/) > > > > 2) the Altered Beast forums app ( > http://beast.caboo.se/forums/1/topics/4650 > > ) > > > > Any others come to mind? > > > > I'm especially interested in seeing examples that spec RESTful > > authentication. > > Daniel, > > I was in your place asking this question about a month ago. Here are > the pointers that were helpful to me. > > [1] > http://www.oreillynet.com/pub/a/ruby/2007/08/09/behavior-driven-development-using-ruby-part-1.html > > [2] http://svn.nightlite.org/applications/cody/trunk/ > > After examining the links above, I rewrote a small project that I > already had working only this time I used BDD for the process. I ended > up writing about 50% more code and created about 100% more methods, > but the resulting program was much easier to understand and very easy > to extend. I also had 100% code coverage which was a first for me. > > I don't know if the code I wrote would be useful to you but I would be > happy to send you a tarball (under 50k) containing this project. > > Good luck. > > cr > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Bryan Ray http://www.bryanray.net "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080311/02e3fca4/attachment.html From rubyphunk at googlemail.com Tue Mar 11 18:29:07 2008 From: rubyphunk at googlemail.com (rubyphunk) Date: Tue, 11 Mar 2008 15:29:07 -0700 (PDT) Subject: [rspec-users] [ANN] RSpactor 0.0.2 : autorun your spec files Message-ID: <6d1eaf57-ceaf-426e-b771-7ba6071980be@f63g2000hsf.googlegroups.com> Hi all. I want to introduce RSpactor and its "draft" release 0.2.0. RSpactor is a little command line tool to automatically run your changed specs (much like autotest). As you may expect, it concentrates on the use of RSpec. It was especially designed to use filesystem events like FSEvent on Leopard (Mac OS X 10.5) instead of permanently polling a directory structure. RSpactor is currently only working on Mac OS 10.5, but I'm very confident that the next version of RSpactor will work on Linux boxes, too. I would really appreciate if you give it try: "sudo gem install rspactor", to help me find bugs and make it a good working application. You can read the rest of this introduction at: http://rubyphunk.com/2008/3/11/hello-world-introducing-rspactor Project page and bug tracker: http://rubyforge.org/projects/rspactor/ bye, - andreas From davids at tower-mt.com Tue Mar 11 23:19:03 2008 From: davids at tower-mt.com (David Schmidt) Date: Tue, 11 Mar 2008 20:19:03 -0700 Subject: [rspec-users] RSpec view test for :partial with :locals? Message-ID: <7F407545-C57D-42D0-B002-8CAF02CE3CEE@tower-mt.com> I'm currently working on some RSpec view tests and I'm having problems with expect_render. Most of the expect_render's work fine, but in one of my views I have: <%= render :partial => "user_cloud", :locals => {:user => @featured_user} %> I see that expect_render supports ":object" or ":collection" for the second parameter, but this partial uses ":locals". I tried expect_render without the second parameter and with ":locals" and it failed to match both times. I confirmed that the partial is rendering in the test.log. Is there a way to match this render? On a similar note, is there a way to test that layout views are rendered? I can test that the :partials in the layout are rendered, but not the layout file itself. In both of these cases I know I could do a "has_tag" and test for something inside the layout file or partial, but I'd rather test contents in a view test for each partial and just verify that the partial is rendered in the view tests that render the partial. Thank you, David From james.deville at gmail.com Wed Mar 12 00:23:29 2008 From: james.deville at gmail.com (James Deville) Date: Tue, 11 Mar 2008 21:23:29 -0700 Subject: [rspec-users] rspec groups? In-Reply-To: References: <57c63afe0803080811l5b4b1e76vae9e234d45eb0ee3@mail.gmail.com> Message-ID: <9D7BCC9A-19DD-44D5-AED5-255A3B000E82@gmail.com> Using the -e option from the command line, you can also specify a string which is to be run, this is a way to run only one describe block, or one it block. The rake task method suggested by Edvard is the other option On Mar 10, 2008, at 5:42 AM, Edvard Majakari wrote: >> The idea is that you can specify that certain tests exist in groups, >> and can be run as a set. You can define groups and groups of groups, >> and so you can run a set of functional tests or all the tests dealing >> with a specific feature without running through the entire thing. >> It's kinda like an rspec pattern, but more flexible. > > Might not be of help, but my problem was a tad similar when I used > test/spec (rspecish test/unit wrapper). > I had five types of test tasks in my Rakefile: test:units, > test:functionals, test:integration, test:libs and test:helpers. The > integration and lib tests took the most of the time, so I created > custom tasks test:all_but_integration (quite self-explanatory, no?) > and test:webserver, which ran everything else except test:libs. The > way I did it was that test:all_but_integration just > depended on the tasks test:units, tests:functionals etc. > > So, if you want grouping inside features in a single test suite, this > won't help, but for me, being able to control which (whole) files were > run with Rake was sufficient for me. The whole suite took something > like 15 minutes, but we had thousands of tests and when we started, we > didn't use that much mock objects. > > That said, I have never needed nor wished the ability to combine test > suites using test/spec or rspec. Being able to choose which > contexts/describes or individual specs will be run has been more than > sufficient to me, but of course, YNMDFTOM. > > -- > "One day, when he was naughty, Mr Bunnsy looked over the hedge into > Farmer Fred's field and it was full of fresh green lettuces. Mr > Bunnsy, however, was not full of lettuces. This did not seem fair." > -- Terry Pratchett, Mr. Bunnsy Has An Adventure > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users James Deville http://devillecompanies.org james.deville at gmail.com rspec r3172 rspec_on_rails r3172 rails r8331 From james.deville at gmail.com Wed Mar 12 00:26:13 2008 From: james.deville at gmail.com (James Deville) Date: Tue, 11 Mar 2008 21:26:13 -0700 Subject: [rspec-users] running a specific describe block In-Reply-To: <169689.56966.qm@web56008.mail.re3.yahoo.com> References: <169689.56966.qm@web56008.mail.re3.yahoo.com> Message-ID: the -e option should run a describe block if the string passed matches a describe block On Feb 29, 2008, at 10:57 AM, Jay Donnell wrote: > I use a lot of nested describe blocks and am wondering if there is a > way to run a specific describe block similar to the -e option for > running specific examples. > > Jay > > > > > > ____________________________________________________________________________________ > Looking for last minute shopping deals? > Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users James Deville http://devillecompanies.org james.deville at gmail.com rspec r3172 rspec_on_rails r3172 rails r8331 From dchelimsky at gmail.com Wed Mar 12 06:55:07 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Mar 2008 10:55:07 +0000 Subject: [rspec-users] RSpec view test for :partial with :locals? In-Reply-To: <7F407545-C57D-42D0-B002-8CAF02CE3CEE@tower-mt.com> References: <7F407545-C57D-42D0-B002-8CAF02CE3CEE@tower-mt.com> Message-ID: <57c63afe0803120355j2216e1dfx529e0d7c343e4618@mail.gmail.com> On Wed, Mar 12, 2008 at 3:19 AM, David Schmidt wrote: > I'm currently working on some RSpec view tests and I'm having problems > with expect_render. Most of the expect_render's work fine, but in one > of my views I have: > > <%= render :partial => "user_cloud", :locals => {:user => > @featured_user} %> > > I see that expect_render supports ":object" or ":collection" for the > second parameter, but this partial uses ":locals". I tried > expect_render without the second parameter and with ":locals" and it > failed to match both times. I confirmed that the partial is rendering > in the test.log. Is there a way to match this render? Sounds like a missing feature. Please enter a ticket at http://rspec.lighthouseapp.com. > > On a similar note, is there a way to test that layout views are > rendered? Not in view specs. Layouts are rendered by controllers, not by the views themselves, so you should do that in controller specs. Cheers, David > I can test that the :partials in the layout are rendered, > but not the layout file itself. > > In both of these cases I know I could do a "has_tag" and test for > something inside the layout file or partial, but I'd rather test > contents in a view test for each partial and just verify that the > partial is rendered in the view tests that render the partial. > > Thank you, > > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From Nathan.Zook at amd.com Wed Mar 12 08:45:45 2008 From: Nathan.Zook at amd.com (nzook) Date: Wed, 12 Mar 2008 05:45:45 -0700 (PDT) Subject: [rspec-users] Whence "post" in a description? Message-ID: <15988683.post@talk.nabble.com> I'm having the exact problem described in this earlier post: http://www.nabble.com/Odd-response.body-behavior-to12837556.html#a12837556 That is, after a post, response.body is just the controller/view string ("user/login" in my case). Failing to find any answer on the web, I'm trying to trace execution, but hitting a bit of a snag. I'm tracing the ancestry of self inside a test example to see where the "post" function is actually defined. I'm getting a hit on Spec::Rails::Example::FunctionalExampleGroup, but I cannot find where it is defined in this module! ????? -- View this message in context: http://www.nabble.com/Whence-%22post%22-in-a-description--tp15988683p15988683.html Sent from the rspec-users mailing list archive at Nabble.com. From zach.dennis at gmail.com Wed Mar 12 09:23:31 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 12 Mar 2008 09:23:31 -0400 Subject: [rspec-users] RSpec view test for :partial with :locals? In-Reply-To: <7F407545-C57D-42D0-B002-8CAF02CE3CEE@tower-mt.com> References: <7F407545-C57D-42D0-B002-8CAF02CE3CEE@tower-mt.com> Message-ID: <85d99afe0803120623k6410f225t6c89116b2d526c51@mail.gmail.com> Are you assigning @featured_user (ie: assigns[:featured_user]) before you render your template? We use :locals w/o any problem, for example: template.expect_render(:partial => 'profiles/data', :locals => {:profile => @profile}).and_return(%|

|) Zach On Tue, Mar 11, 2008 at 11:19 PM, David Schmidt wrote: > I'm currently working on some RSpec view tests and I'm having problems > with expect_render. Most of the expect_render's work fine, but in one > of my views I have: > > <%= render :partial => "user_cloud", :locals => {:user => > @featured_user} %> > > I see that expect_render supports ":object" or ":collection" for the > second parameter, but this partial uses ":locals". I tried > expect_render without the second parameter and with ":locals" and it > failed to match both times. I confirmed that the partial is rendering > in the test.log. Is there a way to match this render? > > On a similar note, is there a way to test that layout views are > rendered? I can test that the :partials in the layout are rendered, > but not the layout file itself. > > In both of these cases I know I could do a "has_tag" and test for > something inside the layout file or partial, but I'd rather test > contents in a view test for each partial and just verify that the > partial is rendered in the view tests that render the partial. > > Thank you, > > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com From byrnejb at harte-lyne.ca Wed Mar 12 09:54:48 2008 From: byrnejb at harte-lyne.ca (James B. Byrne) Date: Wed, 12 Mar 2008 09:54:48 -0400 (EDT) Subject: [rspec-users] Testing helper methods in rspec Message-ID: <33234.216.185.71.22.1205330088.squirrel@webmail.harte-lyne.ca> This is perhaps a naive question, but what is the recommended manner of testing a helper method in rspec? I have created a simple string manipulation function and I want to write some tests for it. It it were a script then I would just add if __FILE__ == $0 and add the tests below that but I do not feel that this is the best way to handle a rails helper. The code (I said it was simple) : module ApplicationHelper # keycase strips leading spaces, squeezes out extra whitespace # between words, downshifts all and then capitalizes the first # character of each word. # # This method prepares descriptive strings that are used # as indices for lookups. To preserve common initialisms insert # periods between letters. Thus: # IBM => Ibm but I.B.M. => I.B.M. # # Do not use ! methods as they return nil under certain circumstances # def keycase(value) value = value.to_s.strip.squeeze(" ").downcase.gsub(/\b\w/){$&.upcase} end end -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3 From jarkko at jlaine.net Wed Mar 12 13:04:32 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Wed, 12 Mar 2008 19:04:32 +0200 Subject: [rspec-users] Testing helper methods in rspec In-Reply-To: <33234.216.185.71.22.1205330088.squirrel@webmail.harte-lyne.ca> References: <33234.216.185.71.22.1205330088.squirrel@webmail.harte-lyne.ca> Message-ID: <909400ef0803121004p7dcf4fd6k51bb66698117e34f@mail.gmail.com> On Wed, Mar 12, 2008 at 3:54 PM, James B. Byrne wrote: > This is perhaps a naive question, but what is the recommended manner of > testing a helper method in rspec? You just describe the helper module and call the helper method like you'd do in the views: require File.dirname(__FILE__) + '/../spec_helper' describe ApplicationHelper do describe "breadcrumbs" do describe "when breadcrumbs empty" do it "should show nothing" do breadcrumbs.should == "" end end end end I have created a simple string manipulation > function and I want to write some tests for it. It it were a script then I > would just add if __FILE__ == $0 and add the tests below that but I do not > feel that this is the best way to handle a rails helper. > > The code (I said it was simple) : > > module ApplicationHelper > > # keycase strips leading spaces, squeezes out extra whitespace > # between words, downshifts all and then capitalizes the first > # character of each word. > # > # This method prepares descriptive strings that are used > # as indices for lookups. To preserve common initialisms insert > # periods between letters. Thus: > # IBM => Ibm but I.B.M. => I.B.M. > # > # Do not use ! methods as they return nil under certain circumstances > # > def keycase(value) > value = value.to_s.strip.squeeze(" ").downcase.gsub(/\b\w/){$&.upcase} > end > > end Something like this: require File.dirname(__FILE__) + '/../spec_helper' describe ApplicationHelper do describe "keycase" do describe "when no dots" do before(:each) do @value = "IBM" end it "should convert to lowercase" do keycase(@value).should == "Ibm" end end end end And so on. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi From jaydonnell at yahoo.com Wed Mar 12 13:22:29 2008 From: jaydonnell at yahoo.com (Jay Donnell) Date: Wed, 12 Mar 2008 10:22:29 -0700 (PDT) Subject: [rspec-users] running a specific describe block Message-ID: <583013.18451.qm@web56008.mail.re3.yahoo.com> This doesn't work for me on 1.1.3 I have something like this: describe Support do describe "attached image" do it "should validate presence of attachment" do # test stuff ... end it "should validate that attachment is an image" do # test stuff ... end it "should cleanly save attachment" do # test stuff ... end end end Here's what I'm doing and the results # It doesn't test when I use the text from the describe block jays-imac:ov2 jay$ ruby spec/models/support_spec.rb -e "attached image" Finished in 0.015778 seconds 0 examples, 0 failures # it works fine with the test from an example jays-imac:ov2 jay$ ruby spec/models/support_spec.rb -e "should validate presence of attachment" . Finished in 0.379727 seconds 1 example, 0 failures ----- Original Message ---- From: James Deville To: rspec-users Sent: Tuesday, March 11, 2008 9:26:13 PM Subject: Re: [rspec-users] running a specific describe block the -e option should run a describe block if the string passed matches a describe block On Feb 29, 2008, at 10:57 AM, Jay Donnell wrote: > I use a lot of nested describe blocks and am wondering if there is a > way to run a specific describe block similar to the -e option for > running specific examples. > > Jay > > > > > > ____________________________________________________________________________________ > Looking for last minute shopping deals? > Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users James Deville http://devillecompanies.org james.deville at gmail.com rspec r3172 rspec_on_rails r3172 rails r8331 _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs From dchelimsky at gmail.com Wed Mar 12 13:41:20 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Mar 2008 17:41:20 +0000 Subject: [rspec-users] running a specific describe block In-Reply-To: <583013.18451.qm@web56008.mail.re3.yahoo.com> References: <583013.18451.qm@web56008.mail.re3.yahoo.com> Message-ID: <57c63afe0803121041l1810f899ua7c85d5c074bb3fd@mail.gmail.com> On Wed, Mar 12, 2008 at 5:22 PM, Jay Donnell wrote: > This doesn't work for me on 1.1.3 > I have something like this: > > describe Support do > describe "attached image" do > it "should validate presence of attachment" do > # test stuff ... > end > > it "should validate that attachment is an image" do > # test stuff ... > end > > it "should cleanly save attachment" do > # test stuff ... > end > end > end > > Here's what I'm doing and the results > > # It doesn't test when I use the text from the describe block > jays-imac:ov2 jay$ ruby spec/models/support_spec.rb -e "attached image" > Finished in 0.015778 seconds > 0 examples, 0 failures > > # it works fine with the test from an example > jays-imac:ov2 jay$ ruby spec/models/support_spec.rb -e "should validate presence of attachment" > . > Finished in 0.379727 seconds > 1 example, 0 failures Seems like a nested-example-group bug. Would you kindly submit this as a report to http://rspec.lighthouseapp.com? Cheers, David > > > > > > > ----- Original Message ---- > From: James Deville > To: rspec-users > Sent: Tuesday, March 11, 2008 9:26:13 PM > Subject: Re: [rspec-users] running a specific describe block > > the -e option should run a describe block if the string passed matches > a describe block > > > On Feb 29, 2008, at 10:57 AM, Jay Donnell wrote: > > > I use a lot of nested describe blocks and am wondering if there is a > > way to run a specific describe block similar to the -e option for > > running specific examples. > > > > Jay > > > > > > > > > > > > ____________________________________________________________________________________ > > Looking for last minute shopping deals? > > Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > James Deville > http://devillecompanies.org > james.deville at gmail.com > rspec r3172 > rspec_on_rails r3172 > rails r8331 > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > ____________________________________________________________________________________ > Never miss a thing. Make Yahoo your home page. > http://www.yahoo.com/r/hs > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From Nathan.Zook at amd.com Wed Mar 12 16:23:03 2008 From: Nathan.Zook at amd.com (nzook) Date: Wed, 12 Mar 2008 13:23:03 -0700 (PDT) Subject: [rspec-users] Warning: integrate_views and nested description groups Message-ID: <16012571.post@talk.nabble.com> describe MyController do integrate_views describe "A common base senario" do it "no longer integrates views" do be_careful end end end integrate_views affects an attribute in the class formed by the describe factory method. The second describe generates its own class, so integrate_views is OFF at that level. I've already spent far, far too much time tracking this one down to verify that sub-describes at the same level independently integrate_views (I expect that they should). This might be a candidate for additional documentation. -- View this message in context: http://www.nabble.com/Warning%3A--integrate_views-and-nested-description-groups-tp16012571p16012571.html Sent from the rspec-users mailing list archive at Nabble.com. From jonathan at parkerhill.com Wed Mar 12 16:24:02 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Wed, 12 Mar 2008 16:24:02 -0400 Subject: [rspec-users] Problems with form_for and partials In-Reply-To: <7ADD9917-8E8A-4576-B10B-6624B06C6C66@rupespad.com> References: <1d2f8d6f0710200718m75339e7dyc3109d48b9f02a4b@mail.gmail.com> <7ADD9917-8E8A-4576-B10B-6624B06C6C66@rupespad.com> Message-ID: <704797A7-7C90-46D9-B589-8AF8CC464F04@parkerhill.com> Has anyone come up with a solution for stubbing partials and passing form builders to it? i have a complex form with many parts, and those are rendered in partials On Oct 21, 2007, at 8:46 AM, rupert wrote: >> i'm having problem with a form_for situation where i'm trying to DRY >> out the repeated parts of my forms and put them in common/form and >> render the form elements via another partial in controller_name/ >> _form. >> Here's the first form >> >> # app/views/common/form >> <% form_for ... do |f| -%> >> <%= render :partial => "params[:controller]/form", :object => f %> >>

Submit buttons...

>> <% end -%> > > I had exactly the same problem and ending up putting the > > form_for ...do |f| > > in the partial so I didn't have to pass form builders around. This > won't be practical though if you are using multiple partials for your > forms fields. > > Rupert > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From james.deville at gmail.com Wed Mar 12 17:14:20 2008 From: james.deville at gmail.com (James Deville) Date: Wed, 12 Mar 2008 14:14:20 -0700 Subject: [rspec-users] running a specific describe block In-Reply-To: <57c63afe0803121041l1810f899ua7c85d5c074bb3fd@mail.gmail.com> References: <583013.18451.qm@web56008.mail.re3.yahoo.com> <57c63afe0803121041l1810f899ua7c85d5c074bb3fd@mail.gmail.com> Message-ID: <302A3532-4707-430A-AED3-6B21E2507E0C@gmail.com> Does "Support attached image" or "support attached image" work? JD On Mar 12, 2008, at 10:41 AM, David Chelimsky wrote: > On Wed, Mar 12, 2008 at 5:22 PM, Jay Donnell > wrote: >> This doesn't work for me on 1.1.3 >> I have something like this: >> >> describe Support do >> describe "attached image" do >> it "should validate presence of attachment" do >> # test stuff ... >> end >> >> it "should validate that attachment is an image" do >> # test stuff ... >> end >> >> it "should cleanly save attachment" do >> # test stuff ... >> end >> end >> end >> >> Here's what I'm doing and the results >> >> # It doesn't test when I use the text from the describe block >> jays-imac:ov2 jay$ ruby spec/models/support_spec.rb -e "attached >> image" >> Finished in 0.015778 seconds >> 0 examples, 0 failures >> >> # it works fine with the test from an example >> jays-imac:ov2 jay$ ruby spec/models/support_spec.rb -e "should >> validate presence of attachment" >> . >> Finished in 0.379727 seconds >> 1 example, 0 failures > > Seems like a nested-example-group bug. Would you kindly submit this as > a report to http://rspec.lighthouseapp.com? > > Cheers, > David > >> >> >> >> >> >> >> ----- Original Message ---- >> From: James Deville >> To: rspec-users >> Sent: Tuesday, March 11, 2008 9:26:13 PM >> Subject: Re: [rspec-users] running a specific describe block >> >> the -e option should run a describe block if the string passed >> matches >> a describe block >> >> >> On Feb 29, 2008, at 10:57 AM, Jay Donnell wrote: >> >>> I use a lot of nested describe blocks and am wondering if there is a >>> way to run a specific describe block similar to the -e option for >>> running specific examples. >>> >>> Jay >>> >>> >>> >>> >>> >>> ____________________________________________________________________________________ >>> Looking for last minute shopping deals? >>> Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> >> James Deville >> http://devillecompanies.org >> james.deville at gmail.com >> rspec r3172 >> rspec_on_rails r3172 >> rails r8331 >> >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> >> >> >> >> >> ____________________________________________________________________________________ >> Never miss a thing. Make Yahoo your home page. >> http://www.yahoo.com/r/hs >> >> >> _______________________________________________ >> 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 Mar 12 17:21:33 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Mar 2008 21:21:33 +0000 Subject: [rspec-users] Warning: integrate_views and nested description groups In-Reply-To: <16012571.post@talk.nabble.com> References: <16012571.post@talk.nabble.com> Message-ID: <57c63afe0803121421y2a6be23bjd9dcdd203c4558e5@mail.gmail.com> On Wed, Mar 12, 2008 at 8:23 PM, nzook wrote: > > describe MyController do > integrate_views > describe "A common base senario" do > it "no longer integrates views" do > be_careful > end > end > end > > integrate_views affects an attribute in the class formed by the describe > factory method. The second describe generates its own class, so > integrate_views is OFF at that level. I've already spent far, far too much > time tracking this one down to verify that sub-describes at the same level > independently integrate_views (I expect that they should). > > This might be a candidate for additional documentation. I took the liberty of forwarding this to a ticket at lighthouse: http://rspec.lighthouseapp.com/projects/5645/tickets/335 From zach.dennis at gmail.com Wed Mar 12 17:43:18 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 12 Mar 2008 17:43:18 -0400 Subject: [rspec-users] Problems with form_for and partials In-Reply-To: <704797A7-7C90-46D9-B589-8AF8CC464F04@parkerhill.com> References: <1d2f8d6f0710200718m75339e7dyc3109d48b9f02a4b@mail.gmail.com> <7ADD9917-8E8A-4576-B10B-6624B06C6C66@rupespad.com> <704797A7-7C90-46D9-B589-8AF8CC464F04@parkerhill.com> Message-ID: <85d99afe0803121443x698522b4id75618b5e6ce9ba5@mail.gmail.com> You can use mocha parameter matching to match on "anything" where your form builder would be passed in. You could also use Mocha's "kind_of" parameter matcher to ensure that what you expect is a FormBuilder object. Another way to do this is to not pass in your form builder, but the object needed, and then use fields_for inside the partial itself. This works well in some scenarios. Zach On Wed, Mar 12, 2008 at 4:24 PM, Jonathan Linowes wrote: > Has anyone come up with a solution for stubbing partials and passing > form builders to it? > i have a complex form with many parts, and those are rendered in > partials > > > > > On Oct 21, 2007, at 8:46 AM, rupert wrote: > > >> i'm having problem with a form_for situation where i'm trying to DRY > >> out the repeated parts of my forms and put them in common/form and > >> render the form elements via another partial in controller_name/ > >> _form. > >> Here's the first form > >> > >> # app/views/common/form > >> <% form_for ... do |f| -%> > >> <%= render :partial => "params[:controller]/form", :object => f %> > >>

Submit buttons...

> >> <% end -%> > > > > I had exactly the same problem and ending up putting the > > > > form_for ...do |f| > > > > in the partial so I didn't have to pass form builders around. This > > won't be practical though if you are using multiple partials for your > > forms fields. > > > > Rupert > > > > _______________________________________________ > > 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 > -- Zach Dennis http://www.continuousthinking.com From dchelimsky at gmail.com Wed Mar 12 17:47:35 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 12 Mar 2008 21:47:35 +0000 Subject: [rspec-users] Problems with form_for and partials In-Reply-To: <85d99afe0803121443x698522b4id75618b5e6ce9ba5@mail.gmail.com> References: <1d2f8d6f0710200718m75339e7dyc3109d48b9f02a4b@mail.gmail.com> <7ADD9917-8E8A-4576-B10B-6624B06C6C66@rupespad.com> <704797A7-7C90-46D9-B589-8AF8CC464F04@parkerhill.com> <85d99afe0803121443x698522b4id75618b5e6ce9ba5@mail.gmail.com> Message-ID: <57c63afe0803121447k2ec7ecb3t6399cc37988eda75@mail.gmail.com> On Wed, Mar 12, 2008 at 9:43 PM, Zach Dennis wrote: > You can use mocha parameter matching to match on "anything" where your > form builder would be passed in. You could also use Mocha's "kind_of" > parameter matcher to ensure that what you expect is a FormBuilder > object. > > Another way to do this is to not pass in your form builder, but the > object needed, and then use fields_for inside the partial itself. This > works well in some scenarios. You could also use rspec's parameter matching, which also supports "anything" but not "kind_of" ;) > > Zach > > > > On Wed, Mar 12, 2008 at 4:24 PM, Jonathan Linowes > wrote: > > Has anyone come up with a solution for stubbing partials and passing > > form builders to it? > > i have a complex form with many parts, and those are rendered in > > partials > > > > > > > > > > On Oct 21, 2007, at 8:46 AM, rupert wrote: > > > > >> i'm having problem with a form_for situation where i'm trying to DRY > > >> out the repeated parts of my forms and put them in common/form and > > >> render the form elements via another partial in controller_name/ > > >> _form. > > >> Here's the first form > > >> > > >> # app/views/common/form > > >> <% form_for ... do |f| -%> > > >> <%= render :partial => "params[:controller]/form", :object => f %> > > >>

Submit buttons...

> > >> <% end -%> > > > > > > I had exactly the same problem and ending up putting the > > > > > > form_for ...do |f| > > > > > > in the partial so I didn't have to pass form builders around. This > > > won't be practical though if you are using multiple partials for your > > > forms fields. > > > > > > Rupert > > > > > > _______________________________________________ > > > 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 > > > > > > -- > Zach Dennis > http://www.continuousthinking.com > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jonathan at parkerhill.com Wed Mar 12 18:19:42 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Wed, 12 Mar 2008 18:19:42 -0400 Subject: [rspec-users] Problems with form_for and partials In-Reply-To: <57c63afe0803121447k2ec7ecb3t6399cc37988eda75@mail.gmail.com> References: <1d2f8d6f0710200718m75339e7dyc3109d48b9f02a4b@mail.gmail.com> <7ADD9917-8E8A-4576-B10B-6624B06C6C66@rupespad.com> <704797A7-7C90-46D9-B589-8AF8CC464F04@parkerhill.com> <85d99afe0803121443x698522b4id75618b5e6ce9ba5@mail.gmail.com> <57c63afe0803121447k2ec7ecb3t6399cc37988eda75@mail.gmail.com> Message-ID: On Mar 12, 2008, at 5:47 PM, David Chelimsky wrote: > On Wed, Mar 12, 2008 at 9:43 PM, Zach Dennis > wrote: >> You can use mocha parameter matching to match on "anything" where >> your >> form builder would be passed in. You could also use Mocha's >> "kind_of" >> parameter matcher to ensure that what you expect is a FormBuilder >> object. >> >> Another way to do this is to not pass in your form builder, but the >> object needed, and then use fields_for inside the partial itself. >> This >> works well in some scenarios. > > You could also use rspec's parameter matching, which also supports > "anything" but not "kind_of" ;) how would i use that in stub_render? eg if my view has <%= render :partial => 'pages/foo', :layout => 'bar', :locals => { :f => f } %> what's the stub? From raasdnil at gmail.com Thu Mar 13 00:17:18 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 13 Mar 2008 15:17:18 +1100 Subject: [rspec-users] What is SpecServer? Message-ID: <57a815bf0803122117t6c16754bqfa3b5eea94598221@mail.gmail.com> I have looked through the docs, looked at the code, even gave a cursory (2 page) glance at google, and it is not clear to me what SpecServer is or what it is for. Is it meant to speed up the execution of specs in a rails environment by doing some magic on the database? Or I am thinking it keeps a copy of Rails running to avoid the rails reload delay... Is there any documentation on this so I can go find out instead of bugging the list? :) Regards Mikel From mailing_lists at railsnewbie.com Thu Mar 13 00:36:31 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 13 Mar 2008 00:36:31 -0400 Subject: [rspec-users] What is SpecServer? In-Reply-To: <57a815bf0803122117t6c16754bqfa3b5eea94598221@mail.gmail.com> References: <57a815bf0803122117t6c16754bqfa3b5eea94598221@mail.gmail.com> Message-ID: <07767F96-D97F-407A-AF0D-0104218D2E77@railsnewbie.com> On Mar 13, 2008, at 12:17 AM, Mikel Lindsaar wrote: > I have looked through the docs, looked at the code, even gave a > cursory (2 page) glance at google, and it is not clear to me what > SpecServer is or what it is for. > > Is it meant to speed up the execution of specs in a rails environment > by doing some magic on the database? The spec server does no magic. It load the rails environment, and the runs the specs through Drb (look up the rdoc for Drb/Rinda). > Or I am thinking it keeps a copy of Rails running to avoid the rails > reload delay... Yep - that's pretty much it. It usually takes a few seconds to load up the rails environment, and if you are running your specs every few seconds, that can shave off a lot of time from your dev cycle over time. > > Is there any documentation on this so I can go find out instead of > bugging the list? :) No - not really. All you need to do is start the spec_server: ruby script/spec_server The specs can then be run through the server with --drb (put it in spec.opts, if you always want to use it). Scott From dchelimsky at gmail.com Thu Mar 13 05:05:19 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 13 Mar 2008 09:05:19 +0000 Subject: [rspec-users] Problems with form_for and partials In-Reply-To: References: <1d2f8d6f0710200718m75339e7dyc3109d48b9f02a4b@mail.gmail.com> <7ADD9917-8E8A-4576-B10B-6624B06C6C66@rupespad.com> <704797A7-7C90-46D9-B589-8AF8CC464F04@parkerhill.com> <85d99afe0803121443x698522b4id75618b5e6ce9ba5@mail.gmail.com> <57c63afe0803121447k2ec7ecb3t6399cc37988eda75@mail.gmail.com> Message-ID: <57c63afe0803130205r2afed9fel1c36406e51d9d4d8@mail.gmail.com> On Wed, Mar 12, 2008 at 10:19 PM, Jonathan Linowes wrote: > > On Mar 12, 2008, at 5:47 PM, David Chelimsky wrote: > > > On Wed, Mar 12, 2008 at 9:43 PM, Zach Dennis > > wrote: > >> You can use mocha parameter matching to match on "anything" where > >> your > >> form builder would be passed in. You could also use Mocha's > >> "kind_of" > >> parameter matcher to ensure that what you expect is a FormBuilder > >> object. > >> > >> Another way to do this is to not pass in your form builder, but the > >> object needed, and then use fields_for inside the partial itself. > >> This > >> works well in some scenarios. > > > > You could also use rspec's parameter matching, which also supports > > "anything" but not "kind_of" ;) > > how would i use that in stub_render? eg if my view has > <%= render :partial => 'pages/foo', :layout => 'bar', :locals => > { :f => f } %> > > what's the stub? As of 1.1.3: stub_render(:partial => 'pages/foo', :layout => 'bar', :locals => {:f => }) There is now, in trunk, hash_including matcher, so you *should* (I haven't tried yet) be able to do this: stub_render(hash_including(:locals => {:f => })) That keeps it a bit less brittle, as the previous version will fail if you add anything else to the actual render call this won't fail. Cheers, David > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From Nathan.Zook at amd.com Thu Mar 13 08:40:47 2008 From: Nathan.Zook at amd.com (nzook) Date: Thu, 13 Mar 2008 05:40:47 -0700 (PDT) Subject: [rspec-users] Warning: integrate_views and nested description groups In-Reply-To: <57c63afe0803121421y2a6be23bjd9dcdd203c4558e5@mail.gmail.com> References: <16012571.post@talk.nabble.com> <57c63afe0803121421y2a6be23bjd9dcdd203c4558e5@mail.gmail.com> Message-ID: <16025037.post@talk.nabble.com> I'm not sure that this is buggy behavior, which is why I did not post it over there. The question is if integrate_views should be a heritable trait or not. If it is, then we almost certainly need to be able to override it--and as a convenience method, to be able to do so locally. Implementing such a scheme would involve a four-state @integrate_views -- heritably_no (default), heritably_yes, heritably_yes_but_no_this_once, and heritably_no_but_yes_this_once (current effect of calling integrate_views). Speaking of convenience, it would be nice to be able to set the value globally. And a pony. Thanks David Chelimsky-2 wrote: > > On Wed, Mar 12, 2008 at 8:23 PM, nzook wrote: >> >> describe MyController do >> integrate_views >> describe "A common base senario" do >> it "no longer integrates views" do >> be_careful >> end >> end >> end >> >> integrate_views affects an attribute in the class formed by the describe >> factory method. The second describe generates its own class, so >> integrate_views is OFF at that level. I've already spent far, far too >> much >> time tracking this one down to verify that sub-describes at the same >> level >> independently integrate_views (I expect that they should). >> >> This might be a candidate for additional documentation. > > I took the liberty of forwarding this to a ticket at lighthouse: > > http://rspec.lighthouseapp.com/projects/5645/tickets/335 > _______________________________________________ > 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/Warning%3A--integrate_views-and-nested-description-groups-tp16012571p16025037.html Sent from the rspec-users mailing list archive at Nabble.com. From loop at superinfinite.com Thu Mar 13 09:13:42 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Thu, 13 Mar 2008 14:13:42 +0100 Subject: [rspec-users] Specifing methods in a steps_for block Message-ID: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> Hey list, I'm refactoring some much-used functionality into a common_steps step group. Methods like this are in there: steps_for :common do Given "a number of existing $types?" do |type| @initial_item_count = type.singularize.classify.constantize.count end When "the user adds an invalid $type" do |type| post "/#{type.pluralize}/create", type.to_sym => {} end When "the user adds a valid $type" do |type| post "/#{type.pluralize}/create", type.to_sym => valid_attributes end Then "there should be $number more $type? in the system" do | number, type| type.classify.constantize.count.should == (@initial_item_count + number.to_i) end Then "there should be an error message explaining what went wrong" do response.should have_tag('div#errorExplanation') end Then "the user should see the form again" do response.should have_tag('form[method=post]') end end This more or less works for me. However, I'm interested in two things. First, is this good practice? It's DRY, but I'm coupling my stories to these common steps in a way.. And second, is it possible to define a method in my specific stepgroup, that can be called from my common stepgroup? For instance, in the "user adds a valid type" step, I call a valid_attributes method. I'd like to define that on the specific stepgroup, but so far I haven't been able to get it called... thanks! bartz From rob.holland at gmail.com Thu Mar 13 12:11:28 2008 From: rob.holland at gmail.com (Rob Holland) Date: Thu, 13 Mar 2008 16:11:28 +0000 Subject: [rspec-users] Stories (well, integration tests) which aren't plain text Message-ID: <6ea3a1b80803130911t5f7c0f9bo626fb2f9349afdec@mail.gmail.com> Hi, Having just played with getting my first plain text story working, I like how it all fits together. It worked out nicely. However, I don't feel our project needs to have stories as plain text, in fact it's a slight hindrance for us. Is there any sensible mechanism for doing integration testing using rspec without plain text stories? Thanks, Rob From james.deville at gmail.com Thu Mar 13 12:21:19 2008 From: james.deville at gmail.com (James Deville) Date: Thu, 13 Mar 2008 09:21:19 -0700 Subject: [rspec-users] Stories (well, integration tests) which aren't plain text In-Reply-To: <6ea3a1b80803130911t5f7c0f9bo626fb2f9349afdec@mail.gmail.com> References: <6ea3a1b80803130911t5f7c0f9bo626fb2f9349afdec@mail.gmail.com> Message-ID: <07336E70-C950-4912-B127-2B8BCC57F268@gmail.com> Google for some of the stuff about story runner. It was originally not plain text, that's just a convenience. There are some earlier tutorials on David's blog about just doing stories. JD On Mar 13, 2008, at 9:11 AM, Rob Holland wrote: > Hi, > > Having just played with getting my first plain text story working, I > like how it all fits together. It worked out nicely. > > However, I don't feel our project needs to have stories as plain text, > in fact it's a slight hindrance for us. Is there any sensible > mechanism for doing integration testing using rspec without plain text > stories? > > Thanks, > > Rob > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rob.holland at gmail.com Thu Mar 13 12:32:24 2008 From: rob.holland at gmail.com (Rob Holland) Date: Thu, 13 Mar 2008 16:32:24 +0000 Subject: [rspec-users] Stories (well, integration tests) which aren't plain text In-Reply-To: <07336E70-C950-4912-B127-2B8BCC57F268@gmail.com> References: <6ea3a1b80803130911t5f7c0f9bo626fb2f9349afdec@mail.gmail.com> <07336E70-C950-4912-B127-2B8BCC57F268@gmail.com> Message-ID: <6ea3a1b80803130932rc7d5681vc487dcfc72f09e0@mail.gmail.com> On Thu, Mar 13, 2008 at 4:21 PM, James Deville wrote: > Google for some of the stuff about story runner. It was originally not > plain text, that's just a convenience. There are some earlier > tutorials on David's blog about just doing stories. I couldn't see anything on David's blog about !textual stories. I have however now found some clues by googling for RailsStory, which I hadn't tried before. Thanks From zach.dennis at gmail.com Thu Mar 13 12:34:32 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 13 Mar 2008 12:34:32 -0400 Subject: [rspec-users] Stories (well, integration tests) which aren't plain text In-Reply-To: <07336E70-C950-4912-B127-2B8BCC57F268@gmail.com> References: <6ea3a1b80803130911t5f7c0f9bo626fb2f9349afdec@mail.gmail.com> <07336E70-C950-4912-B127-2B8BCC57F268@gmail.com> Message-ID: <85d99afe0803130934gd9f6e4dw47d6417c4a594a71@mail.gmail.com> I put up a short post with code snippets of using RSpec's rubyesque stories: http://www.continuousthinking.com/2008/3/5/trying-rspec-s-rubyesque-stories Zach On Thu, Mar 13, 2008 at 12:21 PM, James Deville wrote: > Google for some of the stuff about story runner. It was originally not > plain text, that's just a convenience. There are some earlier > tutorials on David's blog about just doing stories. > > JD > > > On Mar 13, 2008, at 9:11 AM, Rob Holland wrote: > > > Hi, > > > > Having just played with getting my first plain text story working, I > > like how it all fits together. It worked out nicely. > > > > However, I don't feel our project needs to have stories as plain text, > > in fact it's a slight hindrance for us. Is there any sensible > > mechanism for doing integration testing using rspec without plain text > > stories? > > > > Thanks, > > > > Rob > > _______________________________________________ > > 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 > -- Zach Dennis http://www.continuousthinking.com From jonathan at parkerhill.com Thu Mar 13 13:25:51 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Thu, 13 Mar 2008 13:25:51 -0400 Subject: [rspec-users] Problems with form_for and partials In-Reply-To: <57c63afe0803130205r2afed9fel1c36406e51d9d4d8@mail.gmail.com> References: <1d2f8d6f0710200718m75339e7dyc3109d48b9f02a4b@mail.gmail.com> <7ADD9917-8E8A-4576-B10B-6624B06C6C66@rupespad.com> <704797A7-7C90-46D9-B589-8AF8CC464F04@parkerhill.com> <85d99afe0803121443x698522b4id75618b5e6ce9ba5@mail.gmail.com> <57c63afe0803121447k2ec7ecb3t6399cc37988eda75@mail.gmail.com> <57c63afe0803130205r2afed9fel1c36406e51d9d4d8@mail.gmail.com> Message-ID: <652EC023-3330-4742-8CBC-FB4E1500C0EC@parkerhill.com> Thank you! for the record, I refactored my code so the view does a form_for, and any partials that render fields with the form builder does its own fields_for. This makes the design cleaner and more testable. However, I'm not sure if there's any performance cost in doing it this way instead of passing the form builder around, anyone? On Mar 13, 2008, at 5:05 AM, David Chelimsky wrote: > On Wed, Mar 12, 2008 at 10:19 PM, Jonathan Linowes > wrote: >> >> On Mar 12, 2008, at 5:47 PM, David Chelimsky wrote: >> >>> On Wed, Mar 12, 2008 at 9:43 PM, Zach Dennis >>> wrote: >>>> You can use mocha parameter matching to match on "anything" where >>>> your >>>> form builder would be passed in. You could also use Mocha's >>>> "kind_of" >>>> parameter matcher to ensure that what you expect is a FormBuilder >>>> object. >>>> >>>> Another way to do this is to not pass in your form builder, >>>> but the >>>> object needed, and then use fields_for inside the partial itself. >>>> This >>>> works well in some scenarios. >>> >>> You could also use rspec's parameter matching, which also supports >>> "anything" but not "kind_of" ;) >> >> how would i use that in stub_render? eg if my view has >> <%= render :partial => 'pages/foo', :layout => >> 'bar', :locals => >> { :f => f } %> >> >> what's the stub? > > As of 1.1.3: > > stub_render(:partial => 'pages/foo', :layout => 'bar', :locals => > {:f => }) > > There is now, in trunk, hash_including matcher, so you *should* (I > haven't tried yet) be able to do this: > > stub_render(hash_including(:locals => {:f => })) > > That keeps it a bit less brittle, as the previous version will fail if > you add anything else to the actual render call this won't fail. > > Cheers, > 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 zach.lists at gmail.com Thu Mar 13 13:46:34 2008 From: zach.lists at gmail.com (Zach Moazeni) Date: Thu, 13 Mar 2008 13:46:34 -0400 Subject: [rspec-users] Problems with form_for and partials In-Reply-To: <652EC023-3330-4742-8CBC-FB4E1500C0EC@parkerhill.com> References: <1d2f8d6f0710200718m75339e7dyc3109d48b9f02a4b@mail.gmail.com> <7ADD9917-8E8A-4576-B10B-6624B06C6C66@rupespad.com> <704797A7-7C90-46D9-B589-8AF8CC464F04@parkerhill.com> <85d99afe0803121443x698522b4id75618b5e6ce9ba5@mail.gmail.com> <57c63afe0803121447k2ec7ecb3t6399cc37988eda75@mail.gmail.com> <57c63afe0803130205r2afed9fel1c36406e51d9d4d8@mail.gmail.com> <652EC023-3330-4742-8CBC-FB4E1500C0EC@parkerhill.com> Message-ID: <5CE0BBD7-25CD-40F0-8135-95260C34B817@gmail.com> We've been going down this route: http://pastie.caboo.se/165265 We use mocha for our mocking and originally we mocked out the form builder, but the specs felt crufty. We then converted to instantiating the FormBuilder and passing it to partials that needed it. For the views that send in the FormBuilder, we use the #with passing a block and assert the "is_a?" inside (I'm still not too keen on using the param helper/matchers). This looks a bit more bulky (and is kinda ugly in having assertions in a setup) but it really greased the wheels for us. We ended up preferring to assert the presence of html vs expectations on a FormBuilder stub, and it made the view specs feel a bit more natural. One last note: we hacked the #render in rspec_on_rails to output the contents of a partial (which is why the template stubbing the render returns "form partial") and we assert the presence of that text in the response. Helps catch those rascally <% %> instead of <%= %>. I've been meaning to form together a patch and submit a proper extension, but it's as time allows. Perhaps a bit more than you were asking for, but I hope this helps -Zach On Mar 13, 2008, at 1:25 PM, Jonathan Linowes wrote: > Thank you! > > for the record, I refactored my code so the view does a form_for, and > any partials that render fields with the form builder does its own > fields_for. This makes the design cleaner and more testable. However, > I'm not sure if there's any performance cost in doing it this way > instead of passing the form builder around, anyone? > > On Mar 13, 2008, at 5:05 AM, David Chelimsky wrote: > >> On Wed, Mar 12, 2008 at 10:19 PM, Jonathan Linowes >> wrote: >>> >>> On Mar 12, 2008, at 5:47 PM, David Chelimsky wrote: >>> >>>> On Wed, Mar 12, 2008 at 9:43 PM, Zach Dennis >>>> wrote: >>>>> You can use mocha parameter matching to match on "anything" where >>>>> your >>>>> form builder would be passed in. You could also use Mocha's >>>>> "kind_of" >>>>> parameter matcher to ensure that what you expect is a FormBuilder >>>>> object. >>>>> >>>>> Another way to do this is to not pass in your form builder, >>>>> but the >>>>> object needed, and then use fields_for inside the partial itself. >>>>> This >>>>> works well in some scenarios. >>>> >>>> You could also use rspec's parameter matching, which also supports >>>> "anything" but not "kind_of" ;) >>> >>> how would i use that in stub_render? eg if my view has >>> <%= render :partial => 'pages/foo', :layout => >>> 'bar', :locals => >>> { :f => f } %> >>> >>> what's the stub? >> >> As of 1.1.3: >> >> stub_render(:partial => 'pages/foo', :layout => 'bar', :locals => >> {:f => }) >> >> There is now, in trunk, hash_including matcher, so you *should* (I >> haven't tried yet) be able to do this: >> >> stub_render(hash_including(:locals => {:f => })) >> >> That keeps it a bit less brittle, as the previous version will fail >> if >> you add anything else to the actual render call this won't fail. >> >> Cheers, >> 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080313/790b74e3/attachment-0001.html From jay at mcgavren.com Thu Mar 13 16:43:10 2008 From: jay at mcgavren.com (Jay McGavren) Date: Thu, 13 Mar 2008 13:43:10 -0700 Subject: [rspec-users] Equivalent to before(:all) for StepGroups? Message-ID: <839490bc0803131343xfefafb9jf214d0a009b146f4@mail.gmail.com> I have a helper object that I'd like to have available inside each of my story steps, but would like to declare it *outside* all the steps. (It knows how to create various objects in my library, then stores a string reference to it for later steps to refer to.) Problem is, I've tried assigning to a module variable both inside and outside my steps_for block, and I get an error that the variable hasn't been previously assigned when I reference it within a step block. To get it to work, I have to create the object within a step block: steps_for(:all) do #TODO: This is a total kludge. Given /an environment/ do @om = ObjectManager.new @environment = @om.resolve_objects("an environment").first def add_to_environment(object) @environment << object object end @om.on_create("target") {add_to_environment Creature.new} @om.on_create("creature") {add_to_environment Creature.new} @om.on_create("game object") {add_to_environment GameObject.new} end Given /(an? (?:creature|game object|target))/i do |subject| @om.resolve_objects(subject) end ... ...meaning I have to begin each story with "Given an environment", whether that's appropriate to the story or not. Is there some equivalent to before(:all) that I can use within stories? Or failing that, how else can I create a module variable in the context that the step blocks run within? (I'd prefer to avoid global variables, of course.) Many thanks for any advice! -Jay McGavren http://jay.mcgavren.com/zyps From oli.azevedo.barnes at gmail.com Thu Mar 13 18:54:47 2008 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Thu, 13 Mar 2008 19:54:47 -0300 Subject: [rspec-users] tutes on testing controllers In-Reply-To: <810a540e0803102338y4ede00efge3e460512d0af2ab@mail.gmail.com> References: <6466d9040803101401o3169fe3dl47a8d00626ce540@mail.gmail.com> <810a540e0803102338y4ede00efge3e460512d0af2ab@mail.gmail.com> Message-ID: <6466d9040803131554g6bf2ecb3u775bcc482acec735@mail.gmail.com> thanks pat, it's still a good primer ;) I'm getting a better handle at it, but I'm still confused as to how to test assigment of associated objects. for instance, how do I test this (using attachment_fu)? @work.image = @image 2008/3/11, Pat Maddox : > On Mon, Mar 10, 2008 at 2:01 PM, Oliver Barnes > wrote: > > hello spec'ers, > > > > i'm in the hunt for guides on testing controllers with rspec, would > > you guys recommend any? > > > Oldie but goodie (I hope) - > http://evang.eli.st/blog/2007/9/15/easy-controller-tests-and-expressing-intent-through-expectations > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Oliver Azevedo Barnes oli.azevedo.barnes at gmail.com +55 11 9768 0193 http://www.linkedin.com/in/oliverbarnes http://workingwithrails.com/person/4704-oliver-barnes From pergesu at gmail.com Thu Mar 13 19:35:30 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 13 Mar 2008 16:35:30 -0700 Subject: [rspec-users] tutes on testing controllers In-Reply-To: <6466d9040803131554g6bf2ecb3u775bcc482acec735@mail.gmail.com> References: <6466d9040803101401o3169fe3dl47a8d00626ce540@mail.gmail.com> <810a540e0803102338y4ede00efge3e460512d0af2ab@mail.gmail.com> <6466d9040803131554g6bf2ecb3u775bcc482acec735@mail.gmail.com> Message-ID: <810a540e0803131635i1cc6752fvca740eace3206455@mail.gmail.com> On Thu, Mar 13, 2008 at 3:54 PM, Oliver Barnes wrote: > thanks pat, it's still a good primer ;) > > I'm getting a better handle at it, but I'm still confused as to how to > test assigment of associated objects. for instance, how do I test this > (using attachment_fu)? > > @work.image = @image You could either use an interaction-based or state-based test. it "should assign the work image" do @mock_work.should_receive(:image=).with(@mock_image) end it "should assign the work image" do Work.find(3).image.should_not be_nil end The basic idea is that you're specifying that it receives a method call that you know works, or you can verify some state that should be true once the action has taken place. hth Pat From oli.azevedo.barnes at gmail.com Thu Mar 13 19:55:28 2008 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Thu, 13 Mar 2008 20:55:28 -0300 Subject: [rspec-users] tutes on testing controllers In-Reply-To: <810a540e0803131635i1cc6752fvca740eace3206455@mail.gmail.com> References: <6466d9040803101401o3169fe3dl47a8d00626ce540@mail.gmail.com> <810a540e0803102338y4ede00efge3e460512d0af2ab@mail.gmail.com> <6466d9040803131554g6bf2ecb3u775bcc482acec735@mail.gmail.com> <810a540e0803131635i1cc6752fvca740eace3206455@mail.gmail.com> Message-ID: <6466d9040803131655q9eabba6xc811a991dfdaca3d@mail.gmail.com> I see. I had gotten to trying the first way you suggested (haven't tried the second yet): it "should assign an image to the work" do @work.should_receive(:image=).with(@image) end but I got the following error: should assign an image to the work Mock 'Work_1002' expected :image= with (#) once, but received it 0 times though in the actual controller @work does receive it: def create @work = @category.works.build(params[:work]) @image = Image.new(params[:image]) @work.image = @image respond_to do |format| if @image.save and @work.save flash[:notice] = 'Work was successfully created.' format.html { redirect_to admin_category_work_path(@category, at work) } else format.html { render :action => "new" } end end end I'm sure I'm missing something here... 2008/3/13, Pat Maddox : > On Thu, Mar 13, 2008 at 3:54 PM, Oliver Barnes > > wrote: > > > thanks pat, it's still a good primer ;) > > > > I'm getting a better handle at it, but I'm still confused as to how to > > test assigment of associated objects. for instance, how do I test this > > (using attachment_fu)? > > > > @work.image = @image > > > You could either use an interaction-based or state-based test. > > it "should assign the work image" do > @mock_work.should_receive(:image=).with(@mock_image) > end > > it "should assign the work image" do > Work.find(3).image.should_not be_nil > end > > The basic idea is that you're specifying that it receives a method > call that you know works, or you can verify some state that should be > true once the action has taken place. > > hth > > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Oliver Azevedo Barnes oli.azevedo.barnes at gmail.com +55 11 9768 0193 http://www.linkedin.com/in/oliverbarnes http://workingwithrails.com/person/4704-oliver-barnes From lists at ruby-forum.com Thu Mar 13 20:54:53 2008 From: lists at ruby-forum.com (__iso __) Date: Fri, 14 Mar 2008 01:54:53 +0100 Subject: [rspec-users] Am I off track on my testing? Message-ID: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> Is it just me or does anyone else miss being able to create something quickly. Once you start writing all the tests your time is now increased by a factor of 10. I agree with the logic in testing, but am I doing something wrong? Take the simple example of a controller test for an index action that shows all the forum posts for a user account. The controller code would be something like what is shown below, and on a bad day may take a minute to do (a really bad day) ========= before_filter :login_required before_filter :find_account def index @posts = @account.posts end ========= Now the controller tests are as following, and with the make it fail, make the update, make it pass strategy would could take about 10 minutes. ========= describe PostsController, "index" do before :each do @posts = mock("posts") @account.stub!(:posts).and_return(@posts) end it "should call the find account method" do controller.should_receive(:find... do :get end it "should assign the @account model" do do :get assigns[:account] ... end it "should call the login required" do controller.should_receive.... do :get end it "should call on the account.posts" do @account.should_recei... get :index end it "should assign posts" do do_get assigns[:posts].... end end ========= Now this is a simple example, but that is a lot of extra tests for three lines of code. I don't know if it is just me, but it takes away some of the fun in being able to see results right away. I understand that with more complex code it may be easy to make a change that could have unexpected effects elsewhere. In the above example, there is no logic that would ever get changed by accident on later updates at least not by anyone who knows what they are doing. Maybe I am way out in left field with the tests that I write, but the tests above are done using the fails, update, pass sequence. I just can't see the reasoning for writing all these tests for something so simple. I guess my thing is that I like writing tests when they will eliminate a lot of manual testing ex automated scheduling class. This would require a lot of different tests to make sure that the scheduler works as it should. I also don't have a problem with model testing seeing as there may be some logic within the model that is unique to it. I do find view testing to be a very unenjoyable, and I haven't event looked at stories yet. I am not trying to say that testing isn't good and that everyone is on the wrong track, but rather wondering if, as in the example, am testing more than I should be. Thanks -- Posted via http://www.ruby-forum.com/. From smingins at elctech.com Thu Mar 13 20:58:08 2008 From: smingins at elctech.com (Shane Mingins) Date: Fri, 14 Mar 2008 13:58:08 +1300 Subject: [rspec-users] tutes on testing controllers In-Reply-To: <6466d9040803131655q9eabba6xc811a991dfdaca3d@mail.gmail.com> References: <6466d9040803101401o3169fe3dl47a8d00626ce540@mail.gmail.com> <810a540e0803102338y4ede00efge3e460512d0af2ab@mail.gmail.com> <6466d9040803131554g6bf2ecb3u775bcc482acec735@mail.gmail.com> <810a540e0803131635i1cc6752fvca740eace3206455@mail.gmail.com> <6466d9040803131655q9eabba6xc811a991dfdaca3d@mail.gmail.com> Message-ID: Are u stubbing Image.new and returning @image?? otherwise I think the error is accurately complaining that it did not receive :image= with the object that you have said. Cheers Shane On 14/03/2008, at 12:55 PM, Oliver Barnes wrote: > I see. I had gotten to trying the first way you suggested (haven't > tried the second yet): > > it "should assign an image to the work" do > @work.should_receive(:image=).with(@image) > end > > but I got the following error: > > should assign an image to the work > Mock 'Work_1002' expected :image= with (# @name="Image_1001">) once, but received it 0 times > > though in the actual controller @work does receive it: > > def create > @work = @category.works.build(params[:work]) > @image = Image.new(params[:image]) > @work.image = @image > respond_to do |format| > if @image.save and @work.save > flash[:notice] = 'Work was successfully created.' > format.html { redirect_to > admin_category_work_path(@category, at work) } > else > format.html { render :action => "new" } > end > end > end > > I'm sure I'm missing something here... > > > 2008/3/13, Pat Maddox : >> On Thu, Mar 13, 2008 at 3:54 PM, Oliver Barnes >> >> wrote: >> >>> thanks pat, it's still a good primer ;) >>> >>> I'm getting a better handle at it, but I'm still confused as to >>> how to >>> test assigment of associated objects. for instance, how do I test >>> this >>> (using attachment_fu)? >>> >>> @work.image = @image >> >> >> You could either use an interaction-based or state-based test. >> >> it "should assign the work image" do >> @mock_work.should_receive(:image=).with(@mock_image) >> end >> >> it "should assign the work image" do >> Work.find(3).image.should_not be_nil >> end >> >> The basic idea is that you're specifying that it receives a method >> call that you know works, or you can verify some state that should be >> true once the action has taken place. >> >> hth >> >> >> Pat >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > -- > Oliver Azevedo Barnes > oli.azevedo.barnes at gmail.com > +55 11 9768 0193 > http://www.linkedin.com/in/oliverbarnes > http://workingwithrails.com/person/4704-oliver-barnes > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Shane Mingins ELC Technologies (TM) 1921 State Street Santa Barbara, CA 93101 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. From smingins at elctech.com Thu Mar 13 21:01:06 2008 From: smingins at elctech.com (Shane Mingins) Date: Fri, 14 Mar 2008 14:01:06 +1300 Subject: [rspec-users] tutes on testing controllers In-Reply-To: <6466d9040803131655q9eabba6xc811a991dfdaca3d@mail.gmail.com> References: <6466d9040803101401o3169fe3dl47a8d00626ce540@mail.gmail.com> <810a540e0803102338y4ede00efge3e460512d0af2ab@mail.gmail.com> <6466d9040803131554g6bf2ecb3u775bcc482acec735@mail.gmail.com> <810a540e0803131635i1cc6752fvca740eace3206455@mail.gmail.com> <6466d9040803131655q9eabba6xc811a991dfdaca3d@mail.gmail.com> Message-ID: <2761B0C2-2C97-463C-A232-DAAE3739D88B@elctech.com> And the other thing I am not seeing .... you are calling create somewhere in the spec? Always a good idea to post all the code :-) Cheers Shane On 14/03/2008, at 12:55 PM, Oliver Barnes wrote: > I see. I had gotten to trying the first way you suggested (haven't > tried the second yet): > > it "should assign an image to the work" do > @work.should_receive(:image=).with(@image) > end > > but I got the following error: > > should assign an image to the work > Mock 'Work_1002' expected :image= with (# @name="Image_1001">) once, but received it 0 times > > though in the actual controller @work does receive it: > > def create > @work = @category.works.build(params[:work]) > @image = Image.new(params[:image]) > @work.image = @image > respond_to do |format| > if @image.save and @work.save > flash[:notice] = 'Work was successfully created.' > format.html { redirect_to > admin_category_work_path(@category, at work) } > else > format.html { render :action => "new" } > end > end > end > > I'm sure I'm missing something here... > > > 2008/3/13, Pat Maddox : >> On Thu, Mar 13, 2008 at 3:54 PM, Oliver Barnes >> >> wrote: >> >>> thanks pat, it's still a good primer ;) >>> >>> I'm getting a better handle at it, but I'm still confused as to >>> how to >>> test assigment of associated objects. for instance, how do I test >>> this >>> (using attachment_fu)? >>> >>> @work.image = @image >> >> >> You could either use an interaction-based or state-based test. >> >> it "should assign the work image" do >> @mock_work.should_receive(:image=).with(@mock_image) >> end >> >> it "should assign the work image" do >> Work.find(3).image.should_not be_nil >> end >> >> The basic idea is that you're specifying that it receives a method >> call that you know works, or you can verify some state that should be >> true once the action has taken place. >> >> hth >> >> >> Pat >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > -- > Oliver Azevedo Barnes > oli.azevedo.barnes at gmail.com > +55 11 9768 0193 > http://www.linkedin.com/in/oliverbarnes > http://workingwithrails.com/person/4704-oliver-barnes > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Shane Mingins ELC Technologies (TM) 1921 State Street Santa Barbara, CA 93101 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. From smingins at elctech.com Thu Mar 13 21:31:26 2008 From: smingins at elctech.com (Shane Mingins) Date: Fri, 14 Mar 2008 14:31:26 +1300 Subject: [rspec-users] Lib Specs and config.use_transactional_fixtures = true Message-ID: <3B3BE374-4904-4C70-AD94-C610EDB9B488@elctech.com> Hi We have specs in our rails project other than model/view/controller .. we have interests and lib ... using use_transactional_fixtures = true seems fine in a spec in the m/ v/c and interests directories but not in lib Just wondered if anyone had any quick thoughts as to why that may be??? Shane Mingins ELC Technologies (TM) 1921 State Street Santa Barbara, CA 93101 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. From pergesu at gmail.com Thu Mar 13 22:09:19 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 13 Mar 2008 19:09:19 -0700 Subject: [rspec-users] tutes on testing controllers In-Reply-To: <6466d9040803131655q9eabba6xc811a991dfdaca3d@mail.gmail.com> References: <6466d9040803101401o3169fe3dl47a8d00626ce540@mail.gmail.com> <810a540e0803102338y4ede00efge3e460512d0af2ab@mail.gmail.com> <6466d9040803131554g6bf2ecb3u775bcc482acec735@mail.gmail.com> <810a540e0803131635i1cc6752fvca740eace3206455@mail.gmail.com> <6466d9040803131655q9eabba6xc811a991dfdaca3d@mail.gmail.com> Message-ID: <810a540e0803131909r1be42620sd5a1b9d4939e37c8@mail.gmail.com> On Thu, Mar 13, 2008 at 4:55 PM, Oliver Barnes wrote: > I see. I had gotten to trying the first way you suggested (haven't > tried the second yet): > > it "should assign an image to the work" do > @work.should_receive(:image=).with(@image) > end > > but I got the following error: > > should assign an image to the work > Mock 'Work_1002' expected :image= with (# @name="Image_1001">) once, but received it 0 times > > though in the actual controller @work does receive it: > > def create > @work = @category.works.build(params[:work]) > @image = Image.new(params[:image]) > @work.image = @image > respond_to do |format| > if @image.save and @work.save > flash[:notice] = 'Work was successfully created.' > format.html { redirect_to admin_category_work_path(@category, at work) } > else > format.html { render :action => "new" } > end > end > end > > I'm sure I'm missing something here... In all likelihood, you're not stubbing the call to @category.works.build, and instead are just letting Rails do its thing. You need to take control of the objects if you want to make interaction verifications of them. Read through some of the documentation starting at http://rspec.info/documentation/mocks/ and see if you can grok it. Feel free to ask more questions if you run into trouble. Pat From pergesu at gmail.com Thu Mar 13 22:21:08 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 13 Mar 2008 19:21:08 -0700 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> Message-ID: <810a540e0803131921of4fe03eg53c82167fa2f787f@mail.gmail.com> A couple comments inline... On Thu, Mar 13, 2008 at 5:54 PM, __iso __ wrote: > it "should call the login required" do > controller.should_receive.... > do :get > end This is testing too much. Just stub the call to logged_in? or whatever > it "should call on the account.posts" do > @account.should_recei... > get :index > end There's no need for this. If your mocks are set up properly, then the only way for assigns[:post] to == your mock list of posts is if @account receives #posts. So this example duplicates some of the stuff that's implicitly tested in the next one, which is a much more useful example. > it "should assign posts" do > do_get > assigns[:posts].... > end > end > > > I am not trying to say that testing isn't good and that everyone is on > the wrong track, but rather wondering if, as in the example, am testing > more than I should be. Personally, I write tests when I feel that they will help me design my code better, give me confidence that the code works as expected, or serve as useful documentation. If you aren't benefiting from certain tests, then don't write them (*gasp*) Remember, BDD isn't some magical routine that, if followed, leads to perfect applications. It can be very helpful in achieving certain desirable ends, but it's not a substitute for your own thinking. Pragmatism and creativity reign supreme. Lately I've started to write fewer interaction-based specs (like the example you gave) when dealing with controllers. I tend to just make the request and let it go all the way down to the database, to make sure that everything is hooked up properly. The catch is that your controllers have to be super skinny - you should be able to cover an action with one or two examples - and have the majority of permutations be handled by the model (and thus covered with model specs). Pat From lists at ruby-forum.com Fri Mar 14 01:42:56 2008 From: lists at ruby-forum.com (__iso __) Date: Fri, 14 Mar 2008 06:42:56 +0100 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: <810a540e0803131921of4fe03eg53c82167fa2f787f@mail.gmail.com> References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> <810a540e0803131921of4fe03eg53c82167fa2f787f@mail.gmail.com> Message-ID: Thanks for the info Pat. To be honest that is what I wanted to hear. There seems to be such an importance set on the lines of code to lines of testing ratio that it seems a person is violating some rule if the ratio isn't high enough to the right. The thing that bugged me when writing out the tests for controllers is that there really was no logic in the controller code. It looked just like 90% of the controllers I have created, so it made no sense to why I had (or so I thought) to write so many tests. It seems that most tests are written in the fear that someone will later make a change and not realize what they have done unless a test now fails. For example in model testing I am sure most people create a tests for the relations to other models, but for what reason. You write the test to whether the relation exists, it fails, you make the relation, it passes. Why not just write the relation and be done with it, because there is paranoia that someone will later decide to delete the relation...I guess. The same is also true for testing if there the various validators exist for the various columns. As I mentioned before, I am totally in favour of writing tests where there is some fear that it may not work as I expected, for that tests rock. It is the tests that acts as a double check that I don't care for so much. Maybe the book below that amazon displays on main page every time I visit the site should be something I check out soon. Thanks again Pat. http://amazon.ca/gp/product/0321146530/ref=s9_flash_asin_image_1_wish_c2?ie=UTF8&coliid=I2GQJNWRWB147V&colid=7OMS5OB238SP&pf_rd_m=A3DWYIK6Y9EEQB&pf_rd_s=center-2&pf_rd_r=1Z4Z31VY2YQ6P9PHQSK6&pf_rd_t=101&pf_rd_p=289767901&pf_rd_i=915398 -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Fri Mar 14 02:46:45 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 13 Mar 2008 23:46:45 -0700 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> <810a540e0803131921of4fe03eg53c82167fa2f787f@mail.gmail.com> Message-ID: <810a540e0803132346p2c2daafbg4a2604574b8c637c@mail.gmail.com> On the other hand, earlier today my pair and I had to override a find_by_param method. We quickly wrote it down: def find_by_param(val) find_by_id val end We were puzzled, then saw that it should be User.find_by_param. Who'da thunk. Pat On Thu, Mar 13, 2008 at 10:42 PM, __iso __ wrote: > Maybe the book below that amazon displays on main page every > time I visit the site should be something I check out soon. > http://amazon.ca/gp/product/0321146530/ref=s9_flash_asin_image_1_wish_c2?ie=UTF8&coliid=I2GQJNWRWB147V&colid=7OMS5OB238SP&pf_rd_m=A3DWYIK6Y9EEQB&pf_rd_s=center-2&pf_rd_r=1Z4Z31VY2YQ6P9PHQSK6&pf_rd_t=101&pf_rd_p=289767901&pf_rd_i=915398 Yes, you should From dchelimsky at gmail.com Fri Mar 14 05:14:03 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 14 Mar 2008 09:14:03 +0000 Subject: [rspec-users] Lib Specs and config.use_transactional_fixtures = true In-Reply-To: <3B3BE374-4904-4C70-AD94-C610EDB9B488@elctech.com> References: <3B3BE374-4904-4C70-AD94-C610EDB9B488@elctech.com> Message-ID: <57c63afe0803140214v26707beds2f3b3c3a96fcf5a3@mail.gmail.com> On Fri, Mar 14, 2008 at 1:31 AM, Shane Mingins wrote: > Hi > > We have specs in our rails project other than model/view/controller .. > we have interests and lib ... > > using use_transactional_fixtures = true seems fine in a spec in the m/ > v/c and interests directories but not in lib > > Just wondered if anyone had any quick thoughts as to why that may be??? This should answer your question: http://rspec.info/documentation/rails/writing/. > > > Shane Mingins > ELC Technologies (TM) > 1921 State Street > Santa Barbara, CA 93101 > > > 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 lists at ruby-forum.com Fri Mar 14 06:55:37 2008 From: lists at ruby-forum.com (Dmitry Vanidovsky) Date: Fri, 14 Mar 2008 11:55:37 +0100 Subject: [rspec-users] `const_missing': uninitialized constant Spec::Rails Message-ID: <134397f35fcfb4757285f2038b3f9fcc@ruby-forum.com> Hi! I'm experiencing such error while running simple model rspec just to make sure everything is working. $ script/spec spec/models/site_user_spec.rb /var/lib/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in `const_missing': uninitialized constant Spec::Rails (NameError) from /home/dv/www/ob/config/../vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/spec/example/configuration.rb:14 from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require' from /var/lib/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require' from /home/dv/www/ob/config/../vendor/plugins/rspec_on_rails/lib/spec/rails/extensions.rb:5 from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require' from /var/lib/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require' ... 11 levels... from /home/dv/www/ob/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:13:in `load_files' from /home/dv/www/ob/vendor/plugins/rspec/lib/spec/runner/options.rb:85:in `run_examples' from /home/dv/www/ob/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run' from script/spec:4 ruby/rails/rspec versions: Rails 1.1.2 ruby 1.8.5 (2006-08-25) [i486-linux] RSpec-1.1.3 (build 20080309210001) Have anyone had similar problem? What is by experience the most suiteable version of rspec framework for rails 1.1.2? Thanks! Dmitry. -- Posted via http://www.ruby-forum.com/. From coreyhaines at gmail.com Fri Mar 14 07:00:25 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Fri, 14 Mar 2008 07:00:25 -0400 Subject: [rspec-users] Story testing views in isolation In-Reply-To: <909400ef0803110700k68668732je9d0a72c243939ea@mail.gmail.com> References: <6bdacb70803101953n74a3c0cbn7a1f84326e82e832@mail.gmail.com> <57c63afe0803110316x24226c40m252690ad90869c00@mail.gmail.com> <6bdacb70803110503m7c2fdd8m6b68aa0292b3a028@mail.gmail.com> <85d99afe0803110539k70d15cadna752b91b12135236@mail.gmail.com> <909400ef0803110700k68668732je9d0a72c243939ea@mail.gmail.com> Message-ID: <6bdacb70803140400o2ee40d7evc9a3733dc2250052@mail.gmail.com> Thanks, everyone, for the thoughts. After thinking about it further and reflecting on all the thoughts, I think it definitely is more of a square peg - round hole situation. Luckily, my designer is well able to handle building view specs for the prototypes that he is building. We then are going to use the specs to integrate the prototype views into our main application. Thanks. -Corey On Tue, Mar 11, 2008 at 10:00 AM, Jarkko Laine wrote: > On Tue, Mar 11, 2008 at 2:39 PM, Zach Dennis > wrote: > > +1 for keeping view specs act as view specs and stories act as stories. > > Agreed. AFAIK stories are for describing a series of actions and > behavior and that doesn't really fit in nicely with specifying views > in isolation. > > //jarkko > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080314/5760b24e/attachment.html From zach.lists at gmail.com Fri Mar 14 08:20:59 2008 From: zach.lists at gmail.com (Zach Moazeni) Date: Fri, 14 Mar 2008 08:20:59 -0400 Subject: [rspec-users] Problems with form_for and partials References: <5CE0BBD7-25CD-40F0-8135-95260C34B817@gmail.com> Message-ID: This hints at another extension I've wanted to write for us for a while. Common html selector strings, Labels, input fields, textareas, forms, links, etc Really just rolling up something like: response.should have_tag("input[type=text][name=?][value=?][id=company- name]", "user[company_name]", "Some Company Inc.") into something like: respose.should have_text_input(:user, :company_name, :id => "company- name", "Some Company Inc.") It feels closer to the Rails view helpers. Not a huge win, but we have so many selectors than abstracting up one would make our specs more readable. Damn "To Code" list... -Zach Begin forwarded message: > From: Zach Moazeni > Date: March 13, 2008 1:46:34 PM GMT-04:00 > To: rspec-users > Subject: Re: [rspec-users] Problems with form_for and partials > > We've been going down this route: > > http://pastie.caboo.se/165265 > > We use mocha for our mocking and originally we mocked out the form > builder, but the specs felt crufty. We then converted to > instantiating the FormBuilder and passing it to partials that needed > it. > > For the views that send in the FormBuilder, we use the #with passing > a block and assert the "is_a?" inside (I'm still not too keen on > using the param helper/matchers). This looks a bit more bulky (and > is kinda ugly in having assertions in a setup) but it really greased > the wheels for us. > > We ended up preferring to assert the presence of html vs > expectations on a FormBuilder stub, and it made the view specs feel > a bit more natural. > > One last note: we hacked the #render in rspec_on_rails to output the > contents of a partial (which is why the template stubbing the render > returns "form partial") and we assert the presence of that text in > the response. Helps catch those rascally <% %> instead of <%= %>. > I've been meaning to form together a patch and submit a proper > extension, but it's as time allows. > > Perhaps a bit more than you were asking for, but I hope this helps > > -Zach > > > On Mar 13, 2008, at 1:25 PM, Jonathan Linowes wrote: > >> Thank you! >> >> for the record, I refactored my code so the view does a form_for, and >> any partials that render fields with the form builder does its own >> fields_for. This makes the design cleaner and more testable. However, >> I'm not sure if there's any performance cost in doing it this way >> instead of passing the form builder around, anyone? >> >> On Mar 13, 2008, at 5:05 AM, David Chelimsky wrote: >> >>> On Wed, Mar 12, 2008 at 10:19 PM, Jonathan Linowes >>> wrote: >>>> >>>> On Mar 12, 2008, at 5:47 PM, David Chelimsky wrote: >>>> >>>>> On Wed, Mar 12, 2008 at 9:43 PM, Zach Dennis >>>>> wrote: >>>>>> You can use mocha parameter matching to match on "anything" where >>>>>> your >>>>>> form builder would be passed in. You could also use Mocha's >>>>>> "kind_of" >>>>>> parameter matcher to ensure that what you expect is a FormBuilder >>>>>> object. >>>>>> >>>>>> Another way to do this is to not pass in your form builder, >>>>>> but the >>>>>> object needed, and then use fields_for inside the partial itself. >>>>>> This >>>>>> works well in some scenarios. >>>>> >>>>> You could also use rspec's parameter matching, which also supports >>>>> "anything" but not "kind_of" ;) >>>> >>>> how would i use that in stub_render? eg if my view has >>>> <%= render :partial => 'pages/foo', :layout => >>>> 'bar', :locals => >>>> { :f => f } %> >>>> >>>> what's the stub? >>> >>> As of 1.1.3: >>> >>> stub_render(:partial => 'pages/foo', :layout => 'bar', :locals => >>> {:f => }) >>> >>> There is now, in trunk, hash_including matcher, so you *should* (I >>> haven't tried yet) be able to do this: >>> >>> stub_render(hash_including(:locals => {:f => })) >>> >>> That keeps it a bit less brittle, as the previous version will >>> fail if >>> you add anything else to the actual render call this won't fail. >>> >>> Cheers, >>> 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080314/497b8b48/attachment-0001.html From alan.larkin at gmail.com Fri Mar 14 08:44:47 2008 From: alan.larkin at gmail.com (Alan Larkin) Date: Fri, 14 Mar 2008 12:44:47 +0000 Subject: [rspec-users] Multiple should_receive(:render).with Message-ID: <47DA733F.2090708@gmail.com> I'm trying to specify that a particular view must render two different partials. My spec looks like: describe AClass do it do template.should_receive(:render).with(:partial => 'foo', :locals => { ... }) ... end describe 'some conditional case' do it do template.should_receive(:render).with(:partial => 'bar', :locals => { ... }) ... end end end Rendering the foo partial passes off fine, but the spec fails when it comes to rendering the bar partial: Mock 'ActionView::Base' expected :render with ({:partial=>"bar", :locals=>{...}}) but received it with ({:partial=>"foo", :locals=>{...}}) In the view the foo partial is rendered first, and presumably that is being intercepted in the second example and thus failing. How do I avoid this? From brandon at opensoul.org Fri Mar 14 08:48:24 2008 From: brandon at opensoul.org (Brandon Keepers) Date: Fri, 14 Mar 2008 08:48:24 -0400 Subject: [rspec-users] Problems with form_for and partials In-Reply-To: References: <5CE0BBD7-25CD-40F0-8135-95260C34B817@gmail.com> Message-ID: <1f64430d0803140548o7f729fe2ta1a9ae5c367bde61@mail.gmail.com> Zach, On 3/14/08, Zach Moazeni wrote: > > This hints at another extension I've wanted to write for us for a while. > Common html selector strings, Labels, input fields, textareas, forms, > links, etc > > Really just rolling up something like: > > response.shouldhave_tag("input[type=text][name=?][value=?][id=company-name]", > "user[company_name]", "Some Company Inc.") > > into something like: > > respose.should have_text_input(:user, :company_name, :id => > "company-name", "Some Company Inc.") > > It feels closer to the Rails view helpers. Not a huge win, but we have so > many selectors than abstracting up one would make our specs more readable. > I've been thinking about doing the same thing. I want matchers like have_text_input and have_text_input_with_label. I think I'll write them for my next project, and then extract them if they're useful. brandon -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080314/ab85cea8/attachment.html From zach.dennis at gmail.com Fri Mar 14 08:55:12 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 14 Mar 2008 08:55:12 -0400 Subject: [rspec-users] Problems with form_for and partials In-Reply-To: References: <5CE0BBD7-25CD-40F0-8135-95260C34B817@gmail.com> Message-ID: <85d99afe0803140555tb6d8c83l2ce797a2e668ba65@mail.gmail.com> My pair and I have written a bunch of these helpers. I'll post what we have later, perhaps it will be a starting point, Zach On Fri, Mar 14, 2008 at 8:20 AM, Zach Moazeni wrote: > This hints at another extension I've wanted to write for us for a while. > > Common html selector strings, Labels, input fields, textareas, forms, links, > etc > > Really just rolling up something like: > > > response.should > have_tag("input[type=text][name=?][value=?][id=company-name]", > "user[company_name]", "Some Company Inc.") > > into something like: > > respose.should have_text_input(:user, :company_name, :id => "company-name", > "Some Company Inc.") > > It feels closer to the Rails view helpers. Not a huge win, but we have so > many selectors than abstracting up one would make our specs more readable. > > Damn "To Code" list... > > -Zach > > Begin forwarded message: > > From: Zach Moazeni > Date: March 13, 2008 1:46:34 PM GMT-04:00 > To: rspec-users > Subject: Re: [rspec-users] Problems with form_for and partials > > > > > We've been going down this route: > > > http://pastie.caboo.se/165265 > > We use mocha for our mocking and originally we mocked out the form builder, > but the specs felt crufty. We then converted to instantiating the > FormBuilder and passing it to partials that needed it. > > For the views that send in the FormBuilder, we use the #with passing a block > and assert the "is_a?" inside (I'm still not too keen on using the param > helper/matchers). This looks a bit more bulky (and is kinda ugly in having > assertions in a setup) but it really greased the wheels for us. > > We ended up preferring to assert the presence of html vs expectations on a > FormBuilder stub, and it made the view specs feel a bit more natural. > > One last note: we hacked the #render in rspec_on_rails to output the > contents of a partial (which is why the template stubbing the render returns > "form partial") and we assert the presence of that text in the response. > Helps catch those rascally <% %> instead of <%= %>. I've been meaning to > form together a patch and submit a proper extension, but it's as time > allows. > > Perhaps a bit more than you were asking for, but I hope this helps > > -Zach > > > > On Mar 13, 2008, at 1:25 PM, Jonathan Linowes wrote: > Thank you! > > for the record, I refactored my code so the view does a form_for, and > any partials that render fields with the form builder does its own > fields_for. This makes the design cleaner and more testable. However, > I'm not sure if there's any performance cost in doing it this way > instead of passing the form builder around, anyone? > > On Mar 13, 2008, at 5:05 AM, David Chelimsky wrote: > > On Wed, Mar 12, 2008 at 10:19 PM, Jonathan Linowes > wrote: > > > > On Mar 12, 2008, at 5:47 PM, David Chelimsky wrote: > > > > On Wed, Mar 12, 2008 at 9:43 PM, Zach Dennis > > wrote: > > > You can use mocha parameter matching to match on "anything" where > > > your > > > form builder would be passed in. You could also use Mocha's > > > "kind_of" > > > parameter matcher to ensure that what you expect is a FormBuilder > > > object. > > > > > > Another way to do this is to not pass in your form builder, > > > but the > > > object needed, and then use fields_for inside the partial itself. > > > This > > > works well in some scenarios. > > > > You could also use rspec's parameter matching, which also supports > > "anything" but not "kind_of" ;) > > > > how would i use that in stub_render? eg if my view has > > <%= render :partial => 'pages/foo', :layout => > > 'bar', :locals => > > { :f => f } %> > > > > what's the stub? > > As of 1.1.3: > > stub_render(:partial => 'pages/foo', :layout => 'bar', :locals => > {:f => }) > > There is now, in trunk, hash_including matcher, so you *should* (I > haven't tried yet) be able to do this: > > stub_render(hash_including(:locals => {:f => })) > > That keeps it a bit less brittle, as the previous version will fail if > you add anything else to the actual render call this won't fail. > > Cheers, > 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 > -- Zach Dennis http://www.continuousthinking.com From coreyhaines at gmail.com Fri Mar 14 09:13:50 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Fri, 14 Mar 2008 09:13:50 -0400 Subject: [rspec-users] Multiple should_receive(:render).with In-Reply-To: <47DA733F.2090708@gmail.com> References: <47DA733F.2090708@gmail.com> Message-ID: <6bdacb70803140613m36abb86do9454efc61332e28@mail.gmail.com> Stub out the first one, something like template.stub!(:render) Then, each of your tests set the actual should_receive expectation. -Corey On Fri, Mar 14, 2008 at 8:44 AM, Alan Larkin wrote: > I'm trying to specify that a particular view must render two different > partials. > My spec looks like: > > describe AClass do > it do > template.should_receive(:render).with(:partial => 'foo', :locals => { > ... }) > ... > end > > describe 'some conditional case' do > it do > template.should_receive(:render).with(:partial => 'bar', :locals => > { ... }) > ... > end > end > end > > Rendering the foo partial passes off fine, but the spec fails when it > comes to > rendering the bar partial: > > Mock 'ActionView::Base' expected :render with ({:partial=>"bar", > :locals=>{...}}) but received it with ({:partial=>"foo", :locals=>{...}}) > > In the view the foo partial is rendered first, and presumably that is > being > intercepted in the second example and thus failing. How do I avoid this? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080314/8c357b3a/attachment.html From alan.larkin at gmail.com Fri Mar 14 09:20:20 2008 From: alan.larkin at gmail.com (Alan Larkin) Date: Fri, 14 Mar 2008 13:20:20 +0000 Subject: [rspec-users] Multiple should_receive(:render).with In-Reply-To: <6bdacb70803140613m36abb86do9454efc61332e28@mail.gmail.com> References: <47DA733F.2090708@gmail.com> <6bdacb70803140613m36abb86do9454efc61332e28@mail.gmail.com> Message-ID: <47DA7B94.5080903@gmail.com> Corey Haines wrote: > Stub out the first one, something like > > template.stub!(:render) > > Then, each of your tests set the actual should_receive expectation. > > -Corey > > On Fri, Mar 14, 2008 at 8:44 AM, Alan Larkin > wrote: > > I'm trying to specify that a particular view must render two > different partials. > My spec looks like: > > describe AClass do > it do > template.should_receive(:render).with(:partial => 'foo', :locals > => { ... }) > ... > end > > describe 'some conditional case' do > it do > template.should_receive(:render).with(:partial => 'bar', > :locals => { ... }) > ... > end > end > end > > Rendering the foo partial passes off fine, but the spec fails when > it comes to > rendering the bar partial: > > Mock 'ActionView::Base' expected :render with ({:partial=>"bar", > :locals=>{...}}) but received it with ({:partial=>"foo", > :locals=>{...}}) > > In the view the foo partial is rendered first, and presumably that > is being > intercepted in the second example and thus failing. How do I avoid this? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > > > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Thanks. From zach.dennis at gmail.com Fri Mar 14 11:29:10 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 14 Mar 2008 11:29:10 -0400 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> Message-ID: <85d99afe0803140829i776b47bch710b48b0601e227e@mail.gmail.com> > Is it just me or does anyone else miss being able to create something > quickly. When I write customer paid for software I strive to apply the best practices to ensure they have high quality, low bug software which is well-factored with the goal that it is easier to maintain and extend over its lifetime, assuming there will be developers added to the project over its lifetime that were not there for its original development efforts. When I write software for myself I tend to flip flop. Sometimes I am writing things to learn or play and I don't test. Sometimes I want to work on my ability to write well designed testable software, so I do test. Also, don't forget that sometimes when producing software you need to SPIKE some things out, which means you code upfront to investigate (kind of like prototyping) and then when you figure out what you want to do, or how-to do it you scratch the prototype and reimplement w/tests. > Once you start writing all the tests your time is now > increased by a factor of 10. Here's another perspective to look at it from. When you write testable and tested software you spend less time coming back to it to track down and fix erroneous bugs. There is a much higher risk you will have to track down and fix erroneous bugs when you don't test (or don't test well there is a difference). There are also the things to account for like when you design for testability and the fact that you usually end up with simpler components which are easier to add to, extend or change. So as your program grows and changes from your customer's perspective you are able to maintain fluid momentum for changing the code as well. When you don't test there is usually a lot of momentum in the first few weeks, but then development slows down and even comes to a halt because the codebase is not well factored, and bugs are much more easily introduced with these changes and you spend more time tracking down bugs, fixing bugs and trying to understand the codebase. So I don't agree with the factor of 10 because when you don't test you spend a lot more time over the life of the project tracking down bugs, fixing bugs, and a much more difficult time changing the codebase to grow with its users needs and your customers desires. All of the time spent doing these things should be added to the time it took to originally develop a feature upfront since it really wasn't done. People also have different levels of software development skills (design, testing, object decomposition, etc) and they can produce things at different speeds so a factor of 10 for you may be a factor or 0 for someone else. > I agree with the logic in testing, but am > I doing something wrong? > > Take the simple example of a controller test for an index action that > shows all the forum posts for a user account. > > The controller code would be something like what is shown below, and on > a bad day may take a minute to do (a really bad day) > ========= > before_filter :login_required > before_filter :find_account > > def index > @posts = @account.posts > end > ========= > > Now the controller tests are as following, and with the make it fail, > make the update, make it pass strategy would could take about 10 > minutes. > ========= > > describe PostsController, "index" do > > before :each do > @posts = mock("posts") > @account.stub!(:posts).and_return(@posts) > end > > it "should call the find account method" do > controller.should_receive(:find... > do :get > end > > it "should assign the @account model" do > do :get > assigns[:account] ... > end > > it "should call the login required" do > controller.should_receive.... > do :get > end > > it "should call on the account.posts" do > @account.should_recei... > get :index > end > > it "should assign posts" do > do_get > assigns[:posts].... > end > end > > ========= > > Now this is a simple example, but that is a lot of extra tests for three > lines of code. I don't know if it is just me, but it takes away some of > the fun in being able to see results right away. First thing: do not stub or mock expect the object under test. When you're testing a controller do not "stub!" the controller and do not "should_receive" the controller. This removes the value you get for testing the controller itself. There are exceptions to this rule, and this is largely because people violate the use of mixins. That is for another conversation though. I know that Pat said that the "controller.should_receive(:login_required)" is too much testing, but I'm going to be more forward. It is not too much testing, it is testing the wrong thing. > I understand that with more complex code it may be easy to make a change > that could have unexpected effects elsewhere. In the above example, > there is no logic that would ever get changed by accident on later > updates at least not by anyone who knows what they are doing. > > Maybe I am way out in left field with the tests that I write, but the > tests above are done using the fails, update, pass sequence. I just > can't see the reasoning for writing all these tests for something so > simple. > So when the application gradually becomes more complex do you think you'll eventually get to a point and say, "well I need to test this now?". Unfortunately even if you do do that when you get to point there's a really good chance you didn't write the code for testability, so the barrier to test is much higher, and it's easier for people to give in and not test at this point because it's now to difficult to test, and they can't spend a long time fixing bad code they've written. > I guess my thing is that I like writing tests when they will eliminate a > lot of manual testing ex automated scheduling class. This would require > a lot of different tests to make sure that the scheduler works as it > should. I also don't have a problem with model testing seeing as there > may be some logic within the model that is unique to it. I do find view > testing to be a very unenjoyable, and I haven't event looked at stories > yet. Testing is not about developer enjoyment. It's about producing high quality low bug software in a way that allows you to sustain a consistent development pace over the lifetime of the project. Although I do get enjoyment knowing I'm producing high quality software. > I am not trying to say that testing isn't good and that everyone is on > the wrong track, but rather wondering if, as in the example, am testing > more than I should be. I think you're experiencing growing pains. Thank you for posting your concerns and questions. I used to have some of the same questions you're having. Hopefully my response has been helpful to raise some counter arguments to your concerns, Zach Dennis http://www.continuousthinking.com From steve.tooke at gmail.com Fri Mar 14 11:33:40 2008 From: steve.tooke at gmail.com (Steve Tooke) Date: Fri, 14 Mar 2008 15:33:40 +0000 Subject: [rspec-users] Adding before / after blocks to every spec Message-ID: <78d462040803140833m64117504l433db2d9ccf6adcb@mail.gmail.com> Folks, I was wondering if someone would be able to help me out with a quandry. I'm trying to write an rspec plugin module for merb that will run all specs within an ActiveRecord (initially) database transaction - to give functionality similar to rails transactional fixtures. Here is the module: module Merb module Test module TransactionalSpecs def begin_transaction ActiveRecord::Base.send :increment_open_transactions ActiveRecord::Base.connection.begin_db_transaction end def rollback_transaction if Thread.current['open_transactions'] != 0 ActiveRecord::Base.connection.rollback_db_transaction Thread.current['open_transactions'] = 0 end end def self.included(base) base.before(:each) { begin_transaction } base.after(:each) { rollback_transaction } end end end end and I'm including it in a spec_helper like so: Spec::Runner.configure do |config| config.include(Merb::Test::TransactionalSpecs) end Unfortunately this results in every spec throwing a SQLite3::SQLException "SQL logic error or missing database". if I remove the self.included method from the module, and just add: before(:each) { begin_transaction } after(:each) { rollback_transaction } within the describe block it works perfectly. Does anybody know what might be causing this, or a way around it? Thanks for your help. Steve From jonathan at parkerhill.com Fri Mar 14 11:46:02 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Fri, 14 Mar 2008 11:46:02 -0400 Subject: [rspec-users] Problems with form_for and partials In-Reply-To: <1f64430d0803140548o7f729fe2ta1a9ae5c367bde61@mail.gmail.com> References: <5CE0BBD7-25CD-40F0-8135-95260C34B817@gmail.com> <1f64430d0803140548o7f729fe2ta1a9ae5c367bde61@mail.gmail.com> Message-ID: seems like it'd make sense to just add this to http://code.google.com/ p/rspec-on-rails-matchers/ linoj On Mar 14, 2008, at 8:48 AM, Brandon Keepers wrote: > Zach, > > On 3/14/08, Zach Moazeni wrote: > This hints at another extension I've wanted to write for us for a > while. > > Common html selector strings, Labels, input fields, textareas, > forms, links, etc > > Really just rolling up something like: > > response.should have_tag("input[type=text][name=?][value=?] > [id=company-name]", "user[company_name]", "Some Company Inc.") > > into something like: > > respose.should have_text_input(:user, :company_name, :id => > "company-name", "Some Company Inc.") > > It feels closer to the Rails view helpers. Not a huge win, but we > have so many selectors than abstracting up one would make our specs > more readable. > > > I've been thinking about doing the same thing. I want matchers > like have_text_input and have_text_input_with_label. > > I think I'll write them for my next project, and then extract them > if they're useful. > > brandon > > _______________________________________________ > 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/20080314/af3c1a35/attachment.html From oli.azevedo.barnes at gmail.com Fri Mar 14 11:49:13 2008 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Fri, 14 Mar 2008 12:49:13 -0300 Subject: [rspec-users] tutes on testing controllers In-Reply-To: <2761B0C2-2C97-463C-A232-DAAE3739D88B@elctech.com> References: <6466d9040803101401o3169fe3dl47a8d00626ce540@mail.gmail.com> <810a540e0803102338y4ede00efge3e460512d0af2ab@mail.gmail.com> <6466d9040803131554g6bf2ecb3u775bcc482acec735@mail.gmail.com> <810a540e0803131635i1cc6752fvca740eace3206455@mail.gmail.com> <6466d9040803131655q9eabba6xc811a991dfdaca3d@mail.gmail.com> <2761B0C2-2C97-463C-A232-DAAE3739D88B@elctech.com> Message-ID: <6466d9040803140849s2fddbad7p8eb5a47b13c95094@mail.gmail.com> should have posted the code, sorry about that :) http://pastie.caboo.se/165708 I was actually posting to :create, but hadn't added do_post() to the example :P adding it solved this specific problem, thanks. hope the pastie helps another newb out 2008/3/13, Shane Mingins : > And the other thing I am not seeing .... you are calling create > somewhere in the spec? > > Always a good idea to post all the code :-) > > > Cheers > Shane > > > On 14/03/2008, at 12:55 PM, Oliver Barnes wrote: > > > > I see. I had gotten to trying the first way you suggested (haven't > > tried the second yet): > > > > it "should assign an image to the work" do > > @work.should_receive(:image=).with(@image) > > end > > > > but I got the following error: > > > > should assign an image to the work > > Mock 'Work_1002' expected :image= with (# > @name="Image_1001">) once, but received it 0 times > > > > though in the actual controller @work does receive it: > > > > def create > > @work = @category.works.build(params[:work]) > > @image = Image.new(params[:image]) > > @work.image = @image > > respond_to do |format| > > if @image.save and @work.save > > flash[:notice] = 'Work was successfully created.' > > format.html { redirect_to > > admin_category_work_path(@category, at work) } > > else > > format.html { render :action => "new" } > > end > > end > > end > > > > I'm sure I'm missing something here... > > > > > > 2008/3/13, Pat Maddox : > >> On Thu, Mar 13, 2008 at 3:54 PM, Oliver Barnes > >> > >> wrote: > >> > >>> thanks pat, it's still a good primer ;) > >>> > >>> I'm getting a better handle at it, but I'm still confused as to > >>> how to > >>> test assigment of associated objects. for instance, how do I test > >>> this > >>> (using attachment_fu)? > >>> > >>> @work.image = @image > >> > >> > >> You could either use an interaction-based or state-based test. > >> > >> it "should assign the work image" do > >> @mock_work.should_receive(:image=).with(@mock_image) > >> end > >> > >> it "should assign the work image" do > >> Work.find(3).image.should_not be_nil > >> end > >> > >> The basic idea is that you're specifying that it receives a method > >> call that you know works, or you can verify some state that should be > >> true once the action has taken place. > >> > >> hth > >> > >> > >> Pat > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > > > > > -- > > Oliver Azevedo Barnes > > oli.azevedo.barnes at gmail.com > > +55 11 9768 0193 > > http://www.linkedin.com/in/oliverbarnes > > http://workingwithrails.com/person/4704-oliver-barnes > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > Shane Mingins > ELC Technologies (TM) > 1921 State Street > Santa Barbara, CA 93101 > > > 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 > -- Oliver Azevedo Barnes oli.azevedo.barnes at gmail.com +55 11 9768 0193 http://www.linkedin.com/in/oliverbarnes http://workingwithrails.com/person/4704-oliver-barnes From oli.azevedo.barnes at gmail.com Fri Mar 14 11:50:53 2008 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Fri, 14 Mar 2008 12:50:53 -0300 Subject: [rspec-users] tutes on testing controllers In-Reply-To: <810a540e0803131909r1be42620sd5a1b9d4939e37c8@mail.gmail.com> References: <6466d9040803101401o3169fe3dl47a8d00626ce540@mail.gmail.com> <810a540e0803102338y4ede00efge3e460512d0af2ab@mail.gmail.com> <6466d9040803131554g6bf2ecb3u775bcc482acec735@mail.gmail.com> <810a540e0803131635i1cc6752fvca740eace3206455@mail.gmail.com> <6466d9040803131655q9eabba6xc811a991dfdaca3d@mail.gmail.com> <810a540e0803131909r1be42620sd5a1b9d4939e37c8@mail.gmail.com> Message-ID: <6466d9040803140850t66eef30aib965059774e42d57@mail.gmail.com> thanks, will do - I am still wrapping my mind around mocks and stubs indeed :) 2008/3/13, Pat Maddox : > On Thu, Mar 13, 2008 at 4:55 PM, Oliver Barnes > > wrote: > > > I see. I had gotten to trying the first way you suggested (haven't > > tried the second yet): > > > > it "should assign an image to the work" do > > @work.should_receive(:image=).with(@image) > > end > > > > but I got the following error: > > > > should assign an image to the work > > Mock 'Work_1002' expected :image= with (# > @name="Image_1001">) once, but received it 0 times > > > > though in the actual controller @work does receive it: > > > > def create > > @work = @category.works.build(params[:work]) > > @image = Image.new(params[:image]) > > @work.image = @image > > respond_to do |format| > > if @image.save and @work.save > > flash[:notice] = 'Work was successfully created.' > > format.html { redirect_to admin_category_work_path(@category, at work) } > > else > > format.html { render :action => "new" } > > end > > end > > end > > > > I'm sure I'm missing something here... > > > In all likelihood, you're not stubbing the call to > @category.works.build, and instead are just letting Rails do its > thing. You need to take control of the objects if you want to make > interaction verifications of them. > > Read through some of the documentation starting at > http://rspec.info/documentation/mocks/ and see if you can grok it. > Feel free to ask more questions if you run into trouble. > > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Oliver Azevedo Barnes oli.azevedo.barnes at gmail.com +55 11 9768 0193 http://www.linkedin.com/in/oliverbarnes http://workingwithrails.com/person/4704-oliver-barnes From oli.azevedo.barnes at gmail.com Fri Mar 14 13:19:02 2008 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Fri, 14 Mar 2008 14:19:02 -0300 Subject: [rspec-users] tutes on testing controllers In-Reply-To: <6466d9040803140850t66eef30aib965059774e42d57@mail.gmail.com> References: <6466d9040803101401o3169fe3dl47a8d00626ce540@mail.gmail.com> <810a540e0803102338y4ede00efge3e460512d0af2ab@mail.gmail.com> <6466d9040803131554g6bf2ecb3u775bcc482acec735@mail.gmail.com> <810a540e0803131635i1cc6752fvca740eace3206455@mail.gmail.com> <6466d9040803131655q9eabba6xc811a991dfdaca3d@mail.gmail.com> <810a540e0803131909r1be42620sd5a1b9d4939e37c8@mail.gmail.com> <6466d9040803140850t66eef30aib965059774e42d57@mail.gmail.com> Message-ID: <6466d9040803141019n18d0ab69u877a2cf68d0c3971@mail.gmail.com> I got the spec and controller minimally working now, here's the code paste for both in full. http://pastie.caboo.se/165743 still working on it, any suggestions on possible improvements would be greatly appreciated. 2008/3/14, Oliver Barnes : > thanks, will do - I am still wrapping my mind around mocks and stubs indeed :) > > > 2008/3/13, Pat Maddox : > > > On Thu, Mar 13, 2008 at 4:55 PM, Oliver Barnes > > > > wrote: > > > > > I see. I had gotten to trying the first way you suggested (haven't > > > tried the second yet): > > > > > > it "should assign an image to the work" do > > > @work.should_receive(:image=).with(@image) > > > end > > > > > > but I got the following error: > > > > > > should assign an image to the work > > > Mock 'Work_1002' expected :image= with (# > > @name="Image_1001">) once, but received it 0 times > > > > > > though in the actual controller @work does receive it: > > > > > > def create > > > @work = @category.works.build(params[:work]) > > > @image = Image.new(params[:image]) > > > @work.image = @image > > > respond_to do |format| > > > if @image.save and @work.save > > > flash[:notice] = 'Work was successfully created.' > > > format.html { redirect_to admin_category_work_path(@category, at work) } > > > else > > > format.html { render :action => "new" } > > > end > > > end > > > end > > > > > > I'm sure I'm missing something here... > > > > > > In all likelihood, you're not stubbing the call to > > @category.works.build, and instead are just letting Rails do its > > thing. You need to take control of the objects if you want to make > > interaction verifications of them. > > > > Read through some of the documentation starting at > > http://rspec.info/documentation/mocks/ and see if you can grok it. > > Feel free to ask more questions if you run into trouble. > > > > > > Pat > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > Oliver Azevedo Barnes > > oli.azevedo.barnes at gmail.com > > +55 11 9768 0193 > http://www.linkedin.com/in/oliverbarnes > http://workingwithrails.com/person/4704-oliver-barnes > -- Oliver Azevedo Barnes oli.azevedo.barnes at gmail.com +55 11 9768 0193 http://www.linkedin.com/in/oliverbarnes http://workingwithrails.com/person/4704-oliver-barnes From will.sargent at gmail.com Fri Mar 14 13:46:38 2008 From: will.sargent at gmail.com (Will Sargent) Date: Fri, 14 Mar 2008 10:46:38 -0700 Subject: [rspec-users] Disabling a set of tests? Message-ID: Hi all, Part of the integration test suite involves running against a sandbox on Paypal's server. Lately that server's been acting flakely. It doesn't fail all the time, but enough to confuse people. I made pending some tests that looked like they were repeat offenders, but now I'm seeing the same thing appear elsewhere. Is there any way to disable all the tests in a spec file at once? Will. From zach.dennis at gmail.com Fri Mar 14 14:00:11 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 14 Mar 2008 14:00:11 -0400 Subject: [rspec-users] Disabling a set of tests? In-Reply-To: References: Message-ID: <85d99afe0803141100o350a0ebdme1c95b8654c18820@mail.gmail.com> At the top of the file put... __END__ Zach On Fri, Mar 14, 2008 at 1:46 PM, Will Sargent wrote: > Hi all, > > Part of the integration test suite involves running against a sandbox > on Paypal's server. > > Lately that server's been acting flakely. It doesn't fail all the > time, but enough to confuse people. > > I made pending some tests that looked like they were repeat offenders, > but now I'm seeing the same thing appear elsewhere. Is there any way > to disable all the tests in a spec file at once? > > Will. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com From lists at ruby-forum.com Fri Mar 14 14:08:11 2008 From: lists at ruby-forum.com (__iso __) Date: Fri, 14 Mar 2008 19:08:11 +0100 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: <85d99afe0803140829i776b47bch710b48b0601e227e@mail.gmail.com> References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> <85d99afe0803140829i776b47bch710b48b0601e227e@mail.gmail.com> Message-ID: Zach Dennis wrote: > When I write software for myself I tend to flip flop. Sometimes I am > writing things to learn or play and I don't test. I did that on a recent small project and I was amazed at how fast I was able to get things done. > Here's another perspective to look at it from. When you write testable > and tested software you spend less time coming back to it to track > down and fix erroneous bugs. There is a much higher risk you will have > to track down and fix erroneous bugs when you don't test (or don't > test well there is a difference). One of the issues that I have had a couple times is that since I am writing the tests and the corresponding code in a serial fashion, sometimes my mind is off tangent and I write a test that is incorrect, I then write the corresponding code to allow the incorrect test to pass. And voila I have given myself confidence that everything is in working order since I tested it, but it is wrong. I believe, that one of the reasons for this is that I am writing too many tests, and because of that the tests start to lose their meaning. The tests become a series of tasks that I hastily try to place a check next to so I can feel I am working efficiently and move on to the next one. I think cutting down on the number of tests I write will allow me to better ensure the tests I have are required and correct. I am beginning to think that if a person checks the code to test code ratio more than once a week they may be testing for the wrong reason. > First thing: do not stub or mock expect the object under test. > > When you're testing a controller do not "stub!" the controller and do > not > "should_receive" the controller. This removes the value you get for > testing > the controller itself. There are exceptions to this rule, and this is > largely > because people violate the use of mixins. That is for another > conversation though. What would you recommend instead? Since the before_filter contains a login_required check I have to stub something to allow the test to be completed. > So when the application gradually becomes more complex do you think > you'll eventually > get to a point and say, "well I need to test this now?". Unfortunately > even if you do > do that when you get to point there's a really good chance you didn't > write the code > for testability, so the barrier to test is much higher, and it's > easier for people to > give in and not test at this point because it's now to difficult to > test, and they can't > spend a long time fixing bad code they've written. Good point. I guess my confusion is to whether testing should exist where there is really no logic. Take an update controller method: @user = User.find(params[:id]) if @user.update_attributes(params[:user) flash[:success] = "..." redirect_to admin_users_url else render :action => :index end Pretty simple stuff. Is it worth 40 lines of test code? That is what I am wondering, because I don't think so. > Testing is not about developer enjoyment. It's about producing high > quality > low bug software in a way that allows you to sustain a consistent > development > pace over the lifetime of the project. I find that the issue with writing more tests than are required is that things become more brittle. One small change results in 10 failed tests and 20 minutes of work to clean up, and that is not enjoyable. I think that writing tests should be enjoyable since that is what it takes for me to keep doing them. > I think you're experiencing growing pains. Adolescence all over again :) Thank you for posting your > concerns and questions. I used to have some of the same questions > you're having. Hopefully > my response has been helpful to raise some counter arguments to your > concerns, Input from experienced people always allows me to look at things from a different angle. Thanks Dennis. -- Posted via http://www.ruby-forum.com/. From rick.denatale at gmail.com Fri Mar 14 16:12:12 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 14 Mar 2008 16:12:12 -0400 Subject: [rspec-users] Branching scenarios, GivenScenario and database Message-ID: I'm trying to use stories to drive some high-level design. I've got some branching scenarios where I want to follow a scenario, to establish a base situation, and then have different scenarios which 'branch' out from that state, possibly several levels deep. I asked a bit about this a few days ago, and David pointed out the rather undocumented GivenScenario which seems to give the basic ability to do what I'm after. So far it's been working fairly well, but I've run into a few quirks. 1) I've been working through my scenarios, and I'd commented out the later ones to cut down on the 'pending' output while I develop the steps. I'd get one scenario working and then go on to the next. So at one point my plain text story looked something like this: Scenario A Given ... When ... Then ... #Scenario B # GivenScenario A # Given ... # ... And I got Scenario A working and uncommented the next scenario, or so I thought: Scenario A Given ... When ... Then ... #Scenario B GivenScenario A Given ... It took me a while to debug the resulting infinite loop. Perhaps GivenScenario should check to see that it's not asking for the CURRENT scenario. 2) Having figured that out and moving on, I now have another problem, which is what's the best way to clean up the database so that Scenario A can run again if it assumes that the stuff it put in the DB isn't there each time it runs. Cleaning the DB after running the scenario won't work since it defeats the purpose of using the scenario as a pre-condition. Cleaning it before is more difficult, particularly if I'm using parameterized steps. It would be nice if I could somehow use database transactions, but I don't see a nice way to do that either. Has anyone faced issues like these? Any ideas? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From mlangenberg at gmail.com Fri Mar 14 17:37:35 2008 From: mlangenberg at gmail.com (Matthijs Langenberg) Date: Fri, 14 Mar 2008 22:37:35 +0100 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> <85d99afe0803140829i776b47bch710b48b0601e227e@mail.gmail.com> Message-ID: <27c0ac6d0803141437oa964232ua2adeaceb0ad7047@mail.gmail.com> I really agree with the topic starter. I've always done the rspec testing with all layers in isolation, a bit like the first example. Now for my latest project I went a bit for a more TDD approach, sending a request to a controller and testing the full stack, including the dynamic bits of the layout. It really helped me getting a quick start. Now I don't know how this will work out on the long term, I'll probably write some additional tests on the model level to assure workings with different variables. I found out that I was wasting way too much time trying to practise and especially trying the come up with the best theory behind BDD, while I just should have get started and make things work. On Fri, Mar 14, 2008 at 7:08 PM, __iso __ wrote: > Zach Dennis wrote: > > When I write software for myself I tend to flip flop. Sometimes I am > > writing things to learn or play and I don't test. > > I did that on a recent small project and I was amazed at how fast I was > able to get things done. > > > Here's another perspective to look at it from. When you write testable > > and tested software you spend less time coming back to it to track > > down and fix erroneous bugs. There is a much higher risk you will have > > to track down and fix erroneous bugs when you don't test (or don't > > test well there is a difference). > > One of the issues that I have had a couple times is that since I am > writing the tests and the corresponding code in a serial fashion, > sometimes my mind is off tangent and I write a test that is incorrect, I > then write the corresponding code to allow the incorrect test to pass. > And voila I have given myself confidence that everything is in working > order since I tested it, but it is wrong. > > I believe, that one of the reasons for this is that I am writing too > many tests, and because of that the tests start to lose their meaning. > The tests become a series of tasks that I hastily try to place a check > next to so I can feel I am working efficiently and move on to the next > one. I think cutting down on the number of tests I write will allow me > to better ensure the tests I have are required and correct. > > I am beginning to think that if a person checks the code to test code > ratio more than once a week they may be testing for the wrong reason. > > > > First thing: do not stub or mock expect the object under test. > > > > When you're testing a controller do not "stub!" the controller and do > > not > > "should_receive" the controller. This removes the value you get for > > testing > > the controller itself. There are exceptions to this rule, and this is > > largely > > because people violate the use of mixins. That is for another > > conversation though. > > What would you recommend instead? Since the before_filter contains a > login_required check I have to stub something to allow the test to be > completed. > > > > So when the application gradually becomes more complex do you think > > you'll eventually > > get to a point and say, "well I need to test this now?". Unfortunately > > even if you do > > do that when you get to point there's a really good chance you didn't > > write the code > > for testability, so the barrier to test is much higher, and it's > > easier for people to > > give in and not test at this point because it's now to difficult to > > test, and they can't > > spend a long time fixing bad code they've written. > > Good point. I guess my confusion is to whether testing should exist > where there is really no logic. Take an update controller method: > > @user = User.find(params[:id]) > if @user.update_attributes(params[:user) > flash[:success] = "..." > redirect_to admin_users_url > else > render :action => :index > end > > Pretty simple stuff. Is it worth 40 lines of test code? That is what I > am wondering, because I don't think so. > > > Testing is not about developer enjoyment. It's about producing high > > quality > > low bug software in a way that allows you to sustain a consistent > > development > > pace over the lifetime of the project. > > I find that the issue with writing more tests than are required is that > things become more brittle. One small change results in 10 failed tests > and 20 minutes of work to clean up, and that is not enjoyable. I think > that writing tests should be enjoyable since that is what it takes for > me to keep doing them. > > > I think you're experiencing growing pains. > > Adolescence all over again :) > > Thank you for posting your > > concerns and questions. I used to have some of the same questions > > you're having. Hopefully > > my response has been helpful to raise some counter arguments to your > > concerns, > > Input from experienced people always allows me to look at things from a > different angle. > > Thanks Dennis. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > 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/20080314/c5dfc76b/attachment.html From zach.dennis at gmail.com Fri Mar 14 21:08:28 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 14 Mar 2008 21:08:28 -0400 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> <85d99afe0803140829i776b47bch710b48b0601e227e@mail.gmail.com> Message-ID: <85d99afe0803141808o5f0712aclbcbd9b8f9671b20c@mail.gmail.com> On Fri, Mar 14, 2008 at 2:08 PM, __iso __ wrote: > Zach Dennis wrote: > > When I write software for myself I tend to flip flop. Sometimes I am > > writing things to learn or play and I don't test. > > I did that on a recent small project and I was amazed at how fast I was > able to get things done. > > > > Here's another perspective to look at it from. When you write testable > > and tested software you spend less time coming back to it to track > > down and fix erroneous bugs. There is a much higher risk you will have > > to track down and fix erroneous bugs when you don't test (or don't > > test well there is a difference). > > One of the issues that I have had a couple times is that since I am > writing the tests and the corresponding code in a serial fashion, > sometimes my mind is off tangent and I write a test that is incorrect, I > then write the corresponding code to allow the incorrect test to pass. > And voila I have given myself confidence that everything is in working > order since I tested it, but it is wrong. > > I believe, that one of the reasons for this is that I am writing too > many tests, and because of that the tests start to lose their meaning. > The tests become a series of tasks that I hastily try to place a check > next to so I can feel I am working efficiently and move on to the next > one. I think cutting down on the number of tests I write will allow me > to better ensure the tests I have are required and correct. > > I am beginning to think that if a person checks the code to test code > ratio more than once a week they may be testing for the wrong reason. > > > > > First thing: do not stub or mock expect the object under test. > > > > When you're testing a controller do not "stub!" the controller and do > > not > > "should_receive" the controller. This removes the value you get for > > testing > > the controller itself. There are exceptions to this rule, and this is > > largely > > because people violate the use of mixins. That is for another > > conversation though. > > What would you recommend instead? Since the before_filter contains a > login_required check I have to stub something to allow the test to be > completed. > I typically test filters by themselves, and then stub out the filters when testing the action, so there is a clear separation between the two. For logins I use a helper to ensure that a controller/action is requiring login if necessary. describe SomeController, "#index" do it_requires_login :get, :index end Then when testing the action itself I do stub all before filters, because I have already tested them elsewhere. If the action requires login I have a login_with_user helper which sets the logged in user to some mock User and then returns it so I can use it in my test. LIke below: describe SomeController, '#index" do def get_index get :index end before do stub_before_filters! @user = login_with_a_user end ... end > > > So when the application gradually becomes more complex do you think > > you'll eventually > > get to a point and say, "well I need to test this now?". Unfortunately > > even if you do > > do that when you get to point there's a really good chance you didn't > > write the code > > for testability, so the barrier to test is much higher, and it's > > easier for people to > > give in and not test at this point because it's now to difficult to > > test, and they can't > > spend a long time fixing bad code they've written. > > Good point. I guess my confusion is to whether testing should exist > where there is really no logic. Take an update controller method: > > @user = User.find(params[:id]) > if @user.update_attributes(params[:user) > flash[:success] = "..." > redirect_to admin_users_url > else > render :action => :index > end > > Pretty simple stuff. Is it worth 40 lines of test code? That is what I > am wondering, because I don't think so. Can someone change this implementation and still have your tests pass, but have the implementation be broken? If they can then yes it is worth the 40 lines. Pat mentioned that he uses very skinny controllers and does integration tests which go through the whole stack to make sure things work. So if he doesn't test the controller#action's because they are too simple he at least will have a failing integration test if someone breaks the implementation. The problem I have with what Pat is doing is that it takes a lot of discipline from the developer to not let the controller grow into a cesspool of logic and interaction that shouldn't be there, but you put it there because you aren't "testing" it directly. From what I've seen most Rails apps have important interaction in the controller actions and logic in the before filters. I would not personally take this approach on customer paid for software. Pat may be more disciplined then me though. =) > > Testing is not about developer enjoyment. It's about producing high > > quality > > low bug software in a way that allows you to sustain a consistent > > development > > pace over the lifetime of the project. > > I find that the issue with writing more tests than are required is that > things become more brittle. One small change results in 10 failed tests > and 20 minutes of work to clean up, and that is not enjoyable. If a change to one object results in multiple failing integration tests, then that is awesome because you know exactly what you broke with that change. If that change breaks a bunch of model, controller, etc specs then how there is an issue in how you're testing. > I think > that writing tests should be enjoyable since that is what it takes for > me to keep doing them. Testing is a skill to be learned. I get a lot of enjoyment out of producing high quality software for my customers. Testing reinforces that I do just that. I also get enjoyment out of finding better ways to write software which makes them more easily testable. If you're looking for the instantaneous gratification that you get with hacking something together real quick then you're not going to find that with testing. If that's your motive for writing tests then you're writing tests for the wrong reasons. > > > I think you're experiencing growing pains. > > Adolescence all over again :) > > > Thank you for posting your > > concerns and questions. I used to have some of the same questions > > you're having. Hopefully > > my response has been helpful to raise some counter arguments to your > > concerns, > > Input from experienced people always allows me to look at things from a > different angle. > > Thanks Dennis. > > Dennis my last name. Zach is my first name ;) -- Zach Dennis http://www.continuousthinking.com From mailing_lists at railsnewbie.com Fri Mar 14 21:22:50 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 14 Mar 2008 21:22:50 -0400 Subject: [rspec-users] Disabling a set of tests? In-Reply-To: References: Message-ID: <3F5A5ACA-52EF-40CB-A32B-BEA828BE070A@railsnewbie.com> On Mar 14, 2008, at 1:46 PM, Will Sargent wrote: > Hi all, > > Part of the integration test suite involves running against a sandbox > on Paypal's server. > > Lately that server's been acting flakely. It doesn't fail all the > time, but enough to confuse people. > > I made pending some tests that looked like they were repeat offenders, > but now I'm seeing the same thing appear elsewhere. Is there any way > to disable all the tests in a spec file at once? I like to use xit("Specs temporarily disable at: #{__FILE__}:# {__LINE__}") { ... } Scott From lists at ruby-forum.com Fri Mar 14 21:41:56 2008 From: lists at ruby-forum.com (__iso __) Date: Sat, 15 Mar 2008 02:41:56 +0100 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: <85d99afe0803141808o5f0712aclbcbd9b8f9671b20c@mail.gmail.com> References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> <85d99afe0803140829i776b47bch710b48b0601e227e@mail.gmail.com> <85d99afe0803141808o5f0712aclbcbd9b8f9671b20c@mail.gmail.com> Message-ID: <49d2409cfbcc6088683f4336ec4a10d1@ruby-forum.com> Zach Dennis wrote: > Can someone change this implementation and still have your tests pass, > but have the implementation be broken? If they can then yes it is > worth the 40 lines. It is partly this paranoia of someone changing the code that makes me question testing of this magnitude. Other than attaching files if a file was uploaded I have yet to have any real logic in my controllers, so I can't imagine why I would change anything, but maybe that is how it all starts :) > The problem I have with what Pat is doing is that it takes a lot of > discipline from the developer to not let the controller grow into a > cesspool of logic and interaction that shouldn't be there, but you put > it there because you aren't "testing" it directly. From what I've seen > most Rails apps have important interaction in the controller actions > and logic in the before filters. I would not personally take this > approach on customer paid for software. Pat may be more disciplined > then me though. =) I guess that is where I am blind, as I don't have any apps that have reached the point of "additional functionality" yet. > If a change to one object results in multiple failing integration > tests, then that is awesome because you know exactly what you broke > with that change. If that change breaks a bunch of model, controller, > etc specs then how there is an issue in how you're testing. After writing a lot of tests I began to think that taking more of a black box approach, ie test what goes in and what comes out, is the best way in that it allows me to make changes inside the box, without having to pick up the pieces of all the broken tests. > Dennis my last name. Zach is my first name ;) :) Sorry about that, I figured that out right after I posted. Somehow I saw Dennis and that is what registered upstairs. -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Sat Mar 15 15:02:02 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 15 Mar 2008 12:02:02 -0700 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: <85d99afe0803141808o5f0712aclbcbd9b8f9671b20c@mail.gmail.com> References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> <85d99afe0803140829i776b47bch710b48b0601e227e@mail.gmail.com> <85d99afe0803141808o5f0712aclbcbd9b8f9671b20c@mail.gmail.com> Message-ID: <810a540e0803151202x74b00f8ehc117e8593f15dcee@mail.gmail.com> On Fri, Mar 14, 2008 at 6:08 PM, Zach Dennis wrote: > Pat mentioned that he uses very skinny controllers and does > integration tests which go through the whole stack to make sure things > work. So if he doesn't test the controller#action's because they are > too simple he at least will have a failing integration test if someone > breaks the implementation. > > The problem I have with what Pat is doing is that it takes a lot of > discipline from the developer to not let the controller grow into a > cesspool of logic and interaction that shouldn't be there, but you put > it there because you aren't "testing" it directly. From what I've seen > most Rails apps have important interaction in the controller actions > and logic in the before filters. I would not personally take this > approach on customer paid for software. Pat may be more disciplined > then me though. =) The way to do this is to not put any business logic in the action, and the way to do THAT is to metaprogram the action away. Our controllers look like this: class PostsController < ApplicationController actions :show, :new, :create end with hooks for stuff like on_successful_create if the default behavior isn't sufficient. It feels pretty radical at first, but it just takes a bit of creativity to make it work. I find it to be a very elegant approach. Pat From xtrmclmb at gmail.com Sat Mar 15 15:11:20 2008 From: xtrmclmb at gmail.com (Camilo Torres) Date: Sun, 16 Mar 2008 14:41:20 +1930 Subject: [rspec-users] [HELP]No :secret given to the #protect_from_forgery call Message-ID: <5e2dde260803151211p46d528ecwb60bf24922b81443@mail.gmail.com> I am starting to BDD. When specing the controller I want to test for object creation: it "deberia crear una nueva persona en post create" do Usuario.should_receive(:create).with({:nombre => "camilo", :clave => "secreta", :tipo => "administrador"}).and_return(@usuario) post 'create', {:usuario => {:nombre => "camilo", :clave => "secreta", :tipo => "administrador"}} end But when I add this spec, I start getting this: 1) ActionController::InvalidAuthenticityToken in 'UsuarioController deberia crear una nueva persona en post create' No :secret given to the #protect_from_forgery call. Set that or use a session store capable of generating its own keys (Cookie Session Store). ./spec/controllers/usuario_controller_spec.rb:30: script/spec:4: This is the only failure. Line 30 is the post "create". I am on Ruby 1.8.6, Rails 2.0.2, Rspec 1.1.3 (saw in vendor/plugins/rspec/CHANGES). I searched google for solutions, found this: http://blog.stonean.com/2007/12/rspec-and-protectfromforgery.html then I added @controller.class.protect_from_forgery :secret => "secretkey" in the before(:each) method. I put the same secret key I found in environment.rb. But now it gives me: ActionController::InvalidAuthenticityToken I am lost. Why this happens? should not work just fine from the rails default configuration?. I have not changed anything in the environment.rb nor application.rb. This is just a new project to learn BDD and RoR. Thanks for any clue to get this to work. From mailing_lists at railsnewbie.com Sat Mar 15 15:26:15 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 15 Mar 2008 15:26:15 -0400 Subject: [rspec-users] [HELP]No :secret given to the #protect_from_forgery call In-Reply-To: <5e2dde260803151211p46d528ecwb60bf24922b81443@mail.gmail.com> References: <5e2dde260803151211p46d528ecwb60bf24922b81443@mail.gmail.com> Message-ID: <39AA63E1-2534-49CF-9B00-CFDA0B0A769C@railsnewbie.com> On Mar 16, 2008, at 2:41 PM, Camilo Torres wrote: > I am starting to BDD. When specing the controller I want to test for > object creation: > > it "deberia crear una nueva persona en post create" do > Usuario.should_receive(:create).with({:nombre => "camilo", :clave > => "secreta", :tipo => "administrador"}).and_return(@usuario) > > post 'create', {:usuario => {:nombre => "camilo", :clave => > "secreta", :tipo => "administrador"}} > end > > But when I add this spec, I start getting this: > 1) > ActionController::InvalidAuthenticityToken in 'UsuarioController > deberia crear una nueva persona en post create' > No :secret given to the #protect_from_forgery call. Set that or use a > session store capable of generating its own keys (Cookie Session > Store). > ./spec/controllers/usuario_controller_spec.rb:30: > script/spec:4: > > This is the only failure. Line 30 is the post "create". > > I am on Ruby 1.8.6, Rails 2.0.2, Rspec 1.1.3 (saw in > vendor/plugins/rspec/CHANGES). > > > I searched google for solutions, found this: > > http://blog.stonean.com/2007/12/rspec-and-protectfromforgery.html > > then I added > @controller.class.protect_from_forgery :secret => "secretkey" > in the before(:each) method. I put the same secret key I found in > environment.rb. But now it gives me: > ActionController::InvalidAuthenticityToken > > I am lost. Why this happens? should not work just fine from the rails > default configuration?. > > I have not changed anything in the environment.rb nor application.rb. > This is just a new project to learn BDD and RoR. Thanks for any clue > to get this to work. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users I haven't tried any of this, but here's my guess: One way to get this to work is to stub out protect_from_forgery: controller.stub!(protect_from_forgery).and_return "foo" The better question is: why would you intentionally remove a security feature? Scott From ben at benmabey.com Sat Mar 15 17:38:04 2008 From: ben at benmabey.com (Ben Mabey) Date: Sat, 15 Mar 2008 15:38:04 -0600 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: <810a540e0803151202x74b00f8ehc117e8593f15dcee@mail.gmail.com> References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> <85d99afe0803140829i776b47bch710b48b0601e227e@mail.gmail.com> <85d99afe0803141808o5f0712aclbcbd9b8f9671b20c@mail.gmail.com> <810a540e0803151202x74b00f8ehc117e8593f15dcee@mail.gmail.com> Message-ID: <47DC41BC.4070706@benmabey.com> > > Lately I've started to write fewer interaction-based specs (like the > example you gave) when dealing with controllers. I tend to just make > the request and let it go all the way down to the database, to make > sure that everything is hooked up properly. The catch is that your > controllers have to be super skinny - you should be able to cover an > action with one or two examples - and have the majority of > permutations be handled by the model (and thus covered with model > specs). > The way to do this is to not put any business logic in the action, and > the way to do THAT is to metaprogram the action away. > > Our controllers look like this: > > class PostsController < ApplicationController > actions :show, :new, :create > end > > with hooks for stuff like on_successful_create if the default behavior > isn't sufficient. > > I've been doing this for several months, ever since I started to use the make_resourceful plugin. There are several plugins that have this similar goal. The only downside I have run into with this approach is that people newer to rails and MVC in general have a very hard time figuring out what is going on. It is a layer of abstraction that is not for the faint of heart or inexperienced. Other than that I love the approach. > It feels pretty radical at first, but it just takes a bit of > creativity to make it work. I find it to be a very elegant approach. > > I am interested why having this approach has motivated you to take more of a state based approach on testing controllers. Assuming that you have other integration tests (stories) that test the full stack then having the controller specs hit the DB doesn't seem to buy you much and will slow your tests down quite a bit as compared to the interaction-based approach. I know you know this already so I am trying to understand how this newer way of writing controllers is more suited for allowing the specs to hit the db. Skinny controllers have been common practice for quite a while so I don't see how the layer of abstraction of declaring actions like above really changes things on the testing level. Do you feel that interaction-based specs on the controllers are too brittle.. or verbose.. or what? Thanks for sharing :) -Ben From ben at benmabey.com Sat Mar 15 17:43:52 2008 From: ben at benmabey.com (Ben Mabey) Date: Sat, 15 Mar 2008 15:43:52 -0600 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: <85d99afe0803141808o5f0712aclbcbd9b8f9671b20c@mail.gmail.com> References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> <85d99afe0803140829i776b47bch710b48b0601e227e@mail.gmail.com> <85d99afe0803141808o5f0712aclbcbd9b8f9671b20c@mail.gmail.com> Message-ID: <47DC4318.4060003@benmabey.com> Zach Dennis wrote: > Can someone change this implementation and still have your tests pass, > but have the implementation be broken? If they can then yes it is > worth the 40 lines. > > Pat mentioned that he uses very skinny controllers and does > integration tests which go through the whole stack to make sure things > work. So if he doesn't test the controller#action's because they are > too simple he at least will have a failing integration test if someone > breaks the implementation. > > The problem I have with what Pat is doing is that it takes a lot of > discipline from the developer to not let the controller grow into a > cesspool of logic and interaction that shouldn't be there, but you put > it there because you aren't "testing" it directly. From what I've seen > most Rails apps have important interaction in the controller actions > and logic in the before filters. I would not personally take this > approach on customer paid for software. Pat may be more disciplined > then me though. =) > > I totally agree with this point. Using interaction-based testing really helps in forcing the logic down into the model. I'm curious about your comment: "From what I've seen most Rails apps have important interaction in the controller actions and logic in the before filters". What are you exactly referring to? I generally use before filters for authentication... How have you seen them abused? -Ben From zach.dennis at gmail.com Sat Mar 15 18:12:21 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sat, 15 Mar 2008 18:12:21 -0400 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: <47DC4318.4060003@benmabey.com> References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> <85d99afe0803140829i776b47bch710b48b0601e227e@mail.gmail.com> <85d99afe0803141808o5f0712aclbcbd9b8f9671b20c@mail.gmail.com> <47DC4318.4060003@benmabey.com> Message-ID: <85d99afe0803151512p3ae83973vccf26b14ae1e1c6f@mail.gmail.com> On Sat, Mar 15, 2008 at 5:43 PM, Ben Mabey wrote: > Zach Dennis wrote: > > Can someone change this implementation and still have your tests pass, > > but have the implementation be broken? If they can then yes it is > > worth the 40 lines. > > > > Pat mentioned that he uses very skinny controllers and does > > integration tests which go through the whole stack to make sure things > > work. So if he doesn't test the controller#action's because they are > > too simple he at least will have a failing integration test if someone > > breaks the implementation. > > > > The problem I have with what Pat is doing is that it takes a lot of > > discipline from the developer to not let the controller grow into a > > cesspool of logic and interaction that shouldn't be there, but you put > > it there because you aren't "testing" it directly. From what I've seen > > most Rails apps have important interaction in the controller actions > > and logic in the before filters. I would not personally take this > > approach on customer paid for software. Pat may be more disciplined > > then me though. =) > > > > > > I totally agree with this point. Using interaction-based testing really > helps in forcing the logic down into the model. > > I'm curious about your comment: "From what I've seen most Rails apps > > have important interaction in the controller actions > and logic in the before filters". What are you exactly referring to? I > generally use before filters for authentication... How have you seen > them abused? I've seen before filters be abused. Authentication is typical an application level responsibility and it makes sense for the controller to protect its resources. No qualms there. I have inherited code bases which abused before filters for things like checking permissions for business requirements. For example: class ProjectsController < ApplicationController before_filter :login_required # i'm ok with this before_filter :ensure_project_manager, :only => [:new, :create] before_filter :ensure_project_write_access, :only => [:edit, :update] # ... I've seen this filter list go on and on and on, based on any possible persmission I would rather introduce a Manager/Service object which is responsible for accessing a project, and allow that do handle the responsibility for knowing what permissions allow someone to create or edit a project. I've been experimenting with using an approach similar in spirit to what Pat is doing, but slightly different: class ApplicationController < ActionController::Base rescue_from AccessDenied, ResourceNotFoundError do |exception| redirect_to "/access_denied.html" end # ... end class ProjectsController < ApplicationController before_filter :login_required def new @project = ProjectManager.new_project end def create ProjectManager.create_project params[:project] do |project_creation| project_creation.success do |project| flash[:notice] = "Project created successfully" @project = project end project_creation.failure do |project| flash[:notice] = "Project creation failed" @project = project render :action => "new" end end # ... end I tend to like this for projects I've worked on where it doesn't make sense to shove all of the responsibility onto a model because it abstracts out the "Manager" who is in charge of ensuring permissions and doing odds and ends things involved in the creation of a project that the model should not be doing (like upload an associated picture of the project manager or ensure memberships status). In the above approach the application controller is setup to rescue from certain application exceptions, and the controllers just do their thing, and the managers which enforce the business logic will throw the exceptions it a business rule has been violated. -- Zach Dennis http://www.continuousthinking.com From mike at vincent.ws Sat Mar 15 18:19:08 2008 From: mike at vincent.ws (Mike Vincent) Date: Sat, 15 Mar 2008 17:19:08 -0500 Subject: [rspec-users] [HELP]No :secret given to the #protect_from_forgery call In-Reply-To: <39AA63E1-2534-49CF-9B00-CFDA0B0A769C@railsnewbie.com> References: <5e2dde260803151211p46d528ecwb60bf24922b81443@mail.gmail.com> <39AA63E1-2534-49CF-9B00-CFDA0B0A769C@railsnewbie.com> Message-ID: <2386bfa00803151519m37e2d575rc31ae52976311da0@mail.gmail.com> I presume the feature is well tested in rails and disable it in the test environment (which is done by default, I think). # in config/environments/test.rb # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false -Mike On Sat, Mar 15, 2008 at 2:26 PM, Scott Taylor wrote: > > > On Mar 16, 2008, at 2:41 PM, Camilo Torres wrote: > > > I am starting to BDD. When specing the controller I want to test for > > object creation: > > > > it "deberia crear una nueva persona en post create" do > > Usuario.should_receive(:create).with({:nombre => "camilo", :clave > > => "secreta", :tipo => "administrador"}).and_return(@usuario) > > > > post 'create', {:usuario => {:nombre => "camilo", :clave => > > "secreta", :tipo => "administrador"}} > > end > > > > But when I add this spec, I start getting this: > > 1) > > ActionController::InvalidAuthenticityToken in 'UsuarioController > > deberia crear una nueva persona en post create' > > No :secret given to the #protect_from_forgery call. Set that or use a > > session store capable of generating its own keys (Cookie Session > > Store). > > ./spec/controllers/usuario_controller_spec.rb:30: > > script/spec:4: > > > > This is the only failure. Line 30 is the post "create". > > > > I am on Ruby 1.8.6, Rails 2.0.2, Rspec 1.1.3 (saw in > > vendor/plugins/rspec/CHANGES). > > > > > > I searched google for solutions, found this: > > > > http://blog.stonean.com/2007/12/rspec-and-protectfromforgery.html > > > > then I added > > @controller.class.protect_from_forgery :secret => "secretkey" > > in the before(:each) method. I put the same secret key I found in > > environment.rb. But now it gives me: > > ActionController::InvalidAuthenticityToken > > > > I am lost. Why this happens? should not work just fine from the rails > > default configuration?. > > > > I have not changed anything in the environment.rb nor application.rb. > > This is just a new project to learn BDD and RoR. Thanks for any clue > > to get this to work. > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > I haven't tried any of this, but here's my guess: > > One way to get this to work is to stub out protect_from_forgery: > > controller.stub!(protect_from_forgery).and_return "foo" > > The better question is: why would you intentionally remove a security > feature? > > Scott > > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Sat Mar 15 19:56:05 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 15 Mar 2008 16:56:05 -0700 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: <47DC41BC.4070706@benmabey.com> References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> <85d99afe0803140829i776b47bch710b48b0601e227e@mail.gmail.com> <85d99afe0803141808o5f0712aclbcbd9b8f9671b20c@mail.gmail.com> <810a540e0803151202x74b00f8ehc117e8593f15dcee@mail.gmail.com> <47DC41BC.4070706@benmabey.com> Message-ID: <810a540e0803151656m44b3a2fcu3c6fd2f2212bdc5f@mail.gmail.com> On Sat, Mar 15, 2008 at 2:38 PM, Ben Mabey wrote: > I am interested why having this approach has motivated you to take more > of a state based approach on testing controllers. > Assuming that you have other integration tests (stories) that test the > full stack then having the controller specs hit the DB doesn't seem to > buy you much and will slow your tests down quite a bit as compared to > the interaction-based approach. I know you know this already so I am > trying to understand how this newer way of writing controllers is more > suited for allowing the specs to hit the db. Skinny controllers have > been common practice for quite a while so I don't see how the layer of > abstraction of declaring actions like above really changes things on the > testing level. Do you feel that interaction-based specs on the > controllers are too brittle.. or verbose.. or what? At work where we're doing this, we don't use stories. So our controller specs act as the integration tests. I think if we were using stories, we likely wouldn't have controller tests at all. Not too sure about that though. Another major reason for not using interaction-based tests is that all of the controllers are identical, so any specs we write are just testing framework code. No sense in that. Pat From pergesu at gmail.com Sat Mar 15 19:57:00 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 15 Mar 2008 16:57:00 -0700 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: <810a540e0803151656m44b3a2fcu3c6fd2f2212bdc5f@mail.gmail.com> References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> <85d99afe0803140829i776b47bch710b48b0601e227e@mail.gmail.com> <85d99afe0803141808o5f0712aclbcbd9b8f9671b20c@mail.gmail.com> <810a540e0803151202x74b00f8ehc117e8593f15dcee@mail.gmail.com> <47DC41BC.4070706@benmabey.com> <810a540e0803151656m44b3a2fcu3c6fd2f2212bdc5f@mail.gmail.com> Message-ID: <810a540e0803151657u4f919289g722c7b418ed2831e@mail.gmail.com> On Sat, Mar 15, 2008 at 4:56 PM, Pat Maddox wrote: > > At work where we're doing this, we don't use stories. So our > controller specs act as the integration tests. I think if we were > using stories, we likely wouldn't have controller tests at all. Not > too sure about that though. This should be "I'm not 100% sure about that though" From raasdnil at gmail.com Sun Mar 16 03:44:12 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Sun, 16 Mar 2008 18:44:12 +1100 Subject: [rspec-users] Corrupt rspec_on_rails tar file? Message-ID: <57a815bf0803160044ga5ab9e3vd2cc42238e0adb9b@mail.gmail.com> I just downloaded rspec_on_rails-1.1.3.tgz onto a mac on OSX 10.4 and another computer (Ubuntu 7.10) and I get the same tar errors when I try to decompress: rspec_on_rails-1.1.3/spec_resources/views/view_spec/implicit_helper.rhtml rspec_on_rails-1.1.3/spec_resources/views/view_spec/multiple_helpers.rhtml gzip: stdin: decompression OK, trailing garbage ignored rspec_on_rails-1.1.3/spec_resources/views/view_spec/template_with_partial.rhtml rspec_on_rails-1.1.3/spec_resources/views/view_spec/template_with_partial_using_collection.rhtml rspec_on_rails-1.1.3/spec_resources/views/view_spec/template_with_partial_with_array.rhtml rspec_on_rails-1.1.3/stories/ rspec_on_rails-1.1.3/stories/all.rb rspec_on_rails-1.1.3/stories/helper.rb rspec_on_rails-1.1.3/stories/steps/ rspec_on_rails-1.1.3/stories/steps/people.rb rspec_on_rails-1.1.3/stories/transactions_should_rollback rspec_on_rails-1.1.3/stories/transactions_should_rollback.rb rspec_on_rails-1.1.3/tasks/ rspec_on_rails-1.1.3/tasks/rspec.rake tar: Child returned status 2 tar: Error exit delayed from previous errors I tried downloading it from within safari as well as just a straight wget on the command line. I can get it via SVN, but this package needs to be replaced. The link I am downloading is: http://rubyforge.org/frs/download.php/31548/rspec_on_rails-1.1.3.tgz and command to untar is "tar -xvzf rspec_on_rails-1.1.3.tgz" Regards Mikel From dchelimsky at gmail.com Sun Mar 16 05:43:57 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 16 Mar 2008 09:43:57 +0000 Subject: [rspec-users] Branching scenarios, GivenScenario and database In-Reply-To: References: Message-ID: <57c63afe0803160243t2d007787jcda3599543401c98@mail.gmail.com> On Fri, Mar 14, 2008 at 8:12 PM, Rick DeNatale wrote: > I'm trying to use stories to drive some high-level design. > > > I've got some branching scenarios where I want to follow a scenario, > to establish a base situation, and then have different scenarios which > 'branch' out from that state, possibly several levels deep. > > I asked a bit about this a few days ago, and David pointed out the > rather undocumented GivenScenario which seems to give the basic > ability to do what I'm after. So far it's been working fairly well, > but I've run into a few quirks. > > 1) I've been working through my scenarios, and I'd commented out the > later ones to cut down on the 'pending' output while I develop the > steps. I'd get one scenario working and then go on to the next. So > at one point my plain text story looked something like this: > > Scenario A > Given ... > When ... > Then ... > > #Scenario B > # GivenScenario A > # Given ... > # ... > > And I got Scenario A working and uncommented the next scenario, or so I thought: > Scenario A > Given ... > When ... > Then ... > > #Scenario B > GivenScenario A > Given ... > > It took me a while to debug the resulting infinite loop. Perhaps > GivenScenario should check to see that it's not asking for the CURRENT > scenario. Patches welcome :) > > 2) Having figured that out and moving on, I now have another > problem, which is what's the best way to clean up the database so that > Scenario A can run again if it assumes that the stuff it put in the DB > isn't there each time it runs. Cleaning the DB after running the > scenario won't work since it defeats the purpose of using the scenario > as a pre-condition. Cleaning it before is more difficult, > particularly if I'm using parameterized steps. It would be nice if I > could somehow use database transactions, but I don't see a nice way to > do that either. This should just work. If you look at story_adapter.rb, which defines the RailsStory class (maybe we should align :) ) you'll see that the transaction is opened when the scenario starts and rolled back when it is finished. GivenScenario should not result in a call to any of the scenario finished methods (scenario_succeeded, _pending, _failed), so it should get rolled back. If that's not happening, please do file a ticket. Cheers, David > > Has anyone faced issues like these? Any ideas? > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From xtrmclmb at gmail.com Sun Mar 16 10:26:45 2008 From: xtrmclmb at gmail.com (Camilo Torres) Date: Mon, 17 Mar 2008 09:56:45 +1930 Subject: [rspec-users] [HELP]No :secret given to the #protect_from_forgery call In-Reply-To: <2386bfa00803151519m37e2d575rc31ae52976311da0@mail.gmail.com> References: <5e2dde260803151211p46d528ecwb60bf24922b81443@mail.gmail.com> <39AA63E1-2534-49CF-9B00-CFDA0B0A769C@railsnewbie.com> <2386bfa00803151519m37e2d575rc31ae52976311da0@mail.gmail.com> Message-ID: <5e2dde260803160726t2eae428dj2fa2dc59a94b718c@mail.gmail.com> Thanks Mike, your comment lead me to the answer: I was using the development environment to make the tests. I didn't realized there were some difference between the environments (not guessed it). When I started the project, I edited spec/spec_helper.rb (and also stories/helper.rb) and changed ENV["RAILS_ENV"] to "development", because I had only one DB user. Of course I can create as many DB users as I need, this is a development box... Now using the (right) ENV["RAILS_ENV"] = "test" and problem is solved. Thanks to Scott Taylor for the other comment. 2008/3/16, Mike Vincent : > I presume the feature is well tested in rails and disable it in the > test environment (which is done by default, I think). > > # in config/environments/test.rb > # Disable request forgery protection in test environment > config.action_controller.allow_forgery_protection = false > > > -Mike > > > On Sat, Mar 15, 2008 at 2:26 PM, Scott Taylor > wrote: > > > > > > On Mar 16, 2008, at 2:41 PM, Camilo Torres wrote: > > > > > I am starting to BDD. When specing the controller I want to test for > > > object creation: > > > > > > it "deberia crear una nueva persona en post create" do > > > Usuario.should_receive(:create).with({:nombre => "camilo", :clave > > > => "secreta", :tipo => "administrador"}).and_return(@usuario) > > > > > > post 'create', {:usuario => {:nombre => "camilo", :clave => > > > "secreta", :tipo => "administrador"}} > > > end > > > > > > But when I add this spec, I start getting this: > > > 1) > > > ActionController::InvalidAuthenticityToken in 'UsuarioController > > > deberia crear una nueva persona en post create' > > > No :secret given to the #protect_from_forgery call. Set that or use a > > > session store capable of generating its own keys (Cookie Session > > > Store). > > > ./spec/controllers/usuario_controller_spec.rb:30: > > > script/spec:4: > > > > > > This is the only failure. Line 30 is the post "create". > > > > > > I am on Ruby 1.8.6, Rails 2.0.2, Rspec 1.1.3 (saw in > > > vendor/plugins/rspec/CHANGES). > > > > > > > > > I searched google for solutions, found this: > > > > > > http://blog.stonean.com/2007/12/rspec-and-protectfromforgery.html > > > > > > then I added > > > @controller.class.protect_from_forgery :secret => "secretkey" > > > in the before(:each) method. I put the same secret key I found in > > > environment.rb. But now it gives me: > > > ActionController::InvalidAuthenticityToken > > > > > > I am lost. Why this happens? should not work just fine from the rails > > > default configuration?. > > > > > > I have not changed anything in the environment.rb nor application.rb. > > > This is just a new project to learn BDD and RoR. Thanks for any clue > > > to get this to work. > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > I haven't tried any of this, but here's my guess: > > > > One way to get this to work is to stub out protect_from_forgery: > > > > controller.stub!(protect_from_forgery).and_return "foo" > > > > The better question is: why would you intentionally remove a security > > feature? > > > > 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 rick.denatale at gmail.com Sun Mar 16 10:37:41 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sun, 16 Mar 2008 10:37:41 -0400 Subject: [rspec-users] Branching scenarios, GivenScenario and database In-Reply-To: <57c63afe0803160243t2d007787jcda3599543401c98@mail.gmail.com> References: <57c63afe0803160243t2d007787jcda3599543401c98@mail.gmail.com> Message-ID: On 3/16/08, David Chelimsky wrote: > On Fri, Mar 14, 2008 at 8:12 PM, Rick DeNatale wrote: > > I'm trying to use stories to drive some high-level design. > > ... So far it's been working fairly well, > > but I've run into a few quirks. > > > > 1) I've been working through my scenarios, and I'd commented out the > > later ones to cut down on the 'pending' output while I develop the > > steps. I'd get one scenario working and then go on to the next. So > > at one point my plain text story looked something like this: > > > > Scenario A > > Given ... > > When ... > > Then ... > > > > #Scenario B > > # GivenScenario A > > # Given ... > > # ... > > > > And I got Scenario A working and uncommented the next scenario, or so I thought: > > Scenario A > > Given ... > > When ... > > Then ... > > > > #Scenario B > > GivenScenario A > > Given ... > > > > It took me a while to debug the resulting infinite loop. Perhaps > > GivenScenario should check to see that it's not asking for the CURRENT > > scenario. > > > Patches welcome :) Fair enough, I'll look at that when I find the time. > > 2) Having figured that out and moving on, I now have another > > problem, which is what's the best way to clean up the database so that > > Scenario A can run again if it assumes that the stuff it put in the DB > > isn't there each time it runs. Cleaning the DB after running the > > scenario won't work since it defeats the purpose of using the scenario > > as a pre-condition. Cleaning it before is more difficult, > > particularly if I'm using parameterized steps. It would be nice if I > > could somehow use database transactions, but I don't see a nice way to > > do that either. > > > This should just work. If you look at story_adapter.rb, which defines > the RailsStory class (maybe we should align :) ) you'll see that the > transaction is opened when the scenario starts and rolled back when it > is finished. GivenScenario should not result in a call to any of the > scenario finished methods (scenario_succeeded, _pending, _failed), so > it should get rolled back. > > If that's not happening, please do file a ticket. Okay, right now, I'm not actually using rails stories since I'm working through pure business logic sans a UI so there's been no need for Rails "integration" testing. On the other hand I guess it wouldn't hurt to "declare" them as rails stories. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From pergesu at gmail.com Sun Mar 16 13:21:38 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 16 Mar 2008 10:21:38 -0700 Subject: [rspec-users] Branching scenarios, GivenScenario and database In-Reply-To: References: <57c63afe0803160243t2d007787jcda3599543401c98@mail.gmail.com> Message-ID: <810a540e0803161021s5334602al4a270b6a0504adaa@mail.gmail.com> On Sun, Mar 16, 2008 at 7:37 AM, Rick DeNatale wrote: > Okay, right now, I'm not actually using rails stories since I'm > working through pure business logic sans a UI so there's been no need > for Rails "integration" testing. > > On the other hand I guess it wouldn't hurt to "declare" them as rails stories. I assume that stories don't get transactional goodness unless they're Rails stories. Pat From smingins at elctech.com Mon Mar 17 00:09:42 2008 From: smingins at elctech.com (Shane Mingins) Date: Mon, 17 Mar 2008 17:09:42 +1300 Subject: [rspec-users] Lib Specs and config.use_transactional_fixtures = true In-Reply-To: <57c63afe0803140214v26707beds2f3b3c3a96fcf5a3@mail.gmail.com> References: <3B3BE374-4904-4C70-AD94-C610EDB9B488@elctech.com> <57c63afe0803140214v26707beds2f3b3c3a96fcf5a3@mail.gmail.com> Message-ID: <1EC70452-EBC9-4400-96E8-83151CB0619C@elctech.com> On 14/03/2008, at 10:14 PM, David Chelimsky wrote: > On Fri, Mar 14, 2008 at 1:31 AM, Shane Mingins > wrote: >> Hi >> >> We have specs in our rails project other than model/view/ >> controller .. >> we have interests and lib ... >> >> using use_transactional_fixtures = true seems fine in a spec in the >> m/ >> v/c and interests directories but not in lib >> >> Just wondered if anyone had any quick thoughts as to why that may >> be??? > > This should answer your question: > http://rspec.info/documentation/rails/writing/. > >> Thanks, that was helpful to know. It did not seem to be the issue I was having though, the specs in lib causing the problem were using before(:all) to setup database records ... changed to use (:each) and all was happy in the land of nod ... that was the difference between the specs in lib and interests ... so not sure what I may be losing (and not know it) without doing something like :behaviour_type => :model ... I do suspect that may have been why I could not use mock_model in a spec once ... will have to find that example sometime and look. Thanks again Shane From loop at superinfinite.com Mon Mar 17 04:40:19 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Mon, 17 Mar 2008 09:40:19 +0100 Subject: [rspec-users] Specifing methods in a steps_for block In-Reply-To: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> Message-ID: <64B3E556-6A7C-4298-A9A9-C4BE941565F4@superinfinite.com> No replies? That doesn't happen very often :). regards, bartz On 13-mrt-2008, at 14:13, Bart Zonneveld wrote: > Hey list, > > I'm refactoring some much-used functionality into a common_steps step > group. Methods like this are in there: > > steps_for :common do > Given "a number of existing $types?" do |type| > @initial_item_count = type.singularize.classify.constantize.count > end > > When "the user adds an invalid $type" do |type| > post "/#{type.pluralize}/create", type.to_sym => {} > end > > When "the user adds a valid $type" do |type| > post "/#{type.pluralize}/create", type.to_sym => valid_attributes > end > > Then "there should be $number more $type? in the system" do | > number, type| > type.classify.constantize.count.should == (@initial_item_count + > number.to_i) > end > > Then "there should be an error message explaining what went > wrong" do > response.should have_tag('div#errorExplanation') > end > > Then "the user should see the form again" do > response.should have_tag('form[method=post]') > end > end > > This more or less works for me. However, I'm interested in two > things. First, is this good practice? It's DRY, but I'm coupling my > stories to these common steps in a way.. And second, is it possible > to define a method in my specific stepgroup, that can be called from > my common stepgroup? > For instance, in the "user adds a valid type" step, I call a > valid_attributes method. I'd like to define that on the specific > stepgroup, but so far I haven't been able to get it called... > > thanks! > bartz > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From backslash451 at yahoo.it Mon Mar 17 06:53:31 2008 From: backslash451 at yahoo.it (roberto belardo) Date: Mon, 17 Mar 2008 11:53:31 +0100 (CET) Subject: [rspec-users] RSpec'ing model association callbacks Message-ID: <586269.252.qm@web27005.mail.ukl.yahoo.com> Hi all, i'm learning rspec and i must admit i really love it. But at the time i started learning it, i already developed my models classes and their callbacks. Now i'm trying to get a 100% coverage of my code but i cannot reach it because i do not understand how to spec my callbacks. Look at this for example: ----------------- User Model class User < ActiveRecord::Base before_destroy :delete_associated_comments def delete_associated_comments comments = Comment.find_all_by_user_id(self.id) comments.each { |c| c.destroy } end end ----------------- User Spec describe User, " being deleted" do before(:each) do end it "should see deleted his own comments" do user = Factory.create_user() comment_1 = Factory.create_comment(:author => user) comment_2 = Factory.create_comment(:author => user) user.destroy comment_1.should be nil comment_2.should be nil end end ----------------- Factory Module def self.create_user(attributes = {}) default_attributes = { :first_name => "Foo", :second_name => "Bar", :user_name => "FooBar", :email => "foo at bar.com" } User.create! default_attributes.merge(attributes) end def self.create_comment(attributes = {}) default_attributes = { :title => "title", :text => "text", :author => create_user } Comment.create! default_attributes.merge(attributes) end ----------------- I imagined a spec like the one above but obviously it doesn't works. :-( I really do no understand how i can spec my callbacks. Could someone help me with this? Thanks in advance, Backslas451. Inviato da Yahoo! Mail. Il servizio di posta?con lo spazio illimitato. http://it.docs.yahoo.com/mail/overview/index.html From dchelimsky at gmail.com Mon Mar 17 07:16:37 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 17 Mar 2008 06:16:37 -0500 Subject: [rspec-users] RSpec'ing model association callbacks In-Reply-To: <586269.252.qm@web27005.mail.ukl.yahoo.com> References: <586269.252.qm@web27005.mail.ukl.yahoo.com> Message-ID: <57c63afe0803170416hc8c8bdft4fa07822639334ce@mail.gmail.com> On Mon, Mar 17, 2008 at 5:53 AM, roberto belardo wrote: > Hi all, > i'm learning rspec and i must admit i really love it. > But at the time i started learning it, i already > developed my models classes and their callbacks. > > Now i'm trying to get a 100% coverage of my code but i > cannot reach it because i do not understand how to > spec my callbacks. > > Look at this for example: > > ----------------- User Model > > class User < ActiveRecord::Base > before_destroy :delete_associated_comments > def delete_associated_comments > comments = Comment.find_all_by_user_id(self.id) > comments.each { |c| > c.destroy > } > end > end > > ----------------- User Spec > > describe User, " being deleted" do > > before(:each) do > end > > it "should see deleted his own comments" do > user = Factory.create_user() > comment_1 = Factory.create_comment(:author => > user) > comment_2 = Factory.create_comment(:author => > user) > user.destroy > comment_1.should be nil > comment_2.should be nil This won't work because you already have a handle on each of these objects. They are likely deleted from the database, but destroying an object (in AR terms) does not turn an instance of it to nil. Give this a shot: lambda { Comment.find(comment_1.id) }.should raise_error(ActiveRecord::RecordNotFound) lambda { Comment.find(comment_2.id) }.should raise_error(ActiveRecord::RecordNotFound) Although generally I prefer to keep only one expectation per example. HTH, David > end > > end > > ----------------- Factory Module > > def self.create_user(attributes = {}) > default_attributes = { > :first_name => "Foo", > :second_name => "Bar", > :user_name => "FooBar", > :email => "foo at bar.com" > } > User.create! default_attributes.merge(attributes) > end > > def self.create_comment(attributes = {}) > default_attributes = { > :title => "title", > :text => "text", > :author => create_user > } > Comment.create! > default_attributes.merge(attributes) > end > > ----------------- > > I imagined a spec like the one above but obviously it > doesn't works. :-( > I really do no understand how i can spec my callbacks. > Could someone help me with this? > > Thanks in advance, > Backslas451. From rick.denatale at gmail.com Mon Mar 17 07:28:37 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 17 Mar 2008 07:28:37 -0400 Subject: [rspec-users] RSpec'ing model association callbacks In-Reply-To: <57c63afe0803170416hc8c8bdft4fa07822639334ce@mail.gmail.com> References: <586269.252.qm@web27005.mail.ukl.yahoo.com> <57c63afe0803170416hc8c8bdft4fa07822639334ce@mail.gmail.com> Message-ID: On 3/17/08, David Chelimsky wrote: > On Mon, Mar 17, 2008 at 5:53 AM, roberto belardo wrote: > > Hi all, > > i'm learning rspec and i must admit i really love it. > > But at the time i started learning it, i already > > developed my models classes and their callbacks. > > > > Now i'm trying to get a 100% coverage of my code but i > > cannot reach it because i do not understand how to > > spec my callbacks. > > > > Look at this for example: > > > > ----------------- User Model > > > > class User < ActiveRecord::Base > > before_destroy :delete_associated_comments > > def delete_associated_comments > > comments = Comment.find_all_by_user_id(self.id) > > comments.each { |c| > > c.destroy > > } > > end > > end > > > > ----------------- User Spec > > > > describe User, " being deleted" do > > > > before(:each) do > > end > > > > it "should see deleted his own comments" do > > user = Factory.create_user() > > comment_1 = Factory.create_comment(:author => > > user) > > comment_2 = Factory.create_comment(:author => > > user) > > user.destroy > > comment_1.should be nil > > comment_2.should be nil > > > This won't work because you already have a handle on each of these > objects. They are likely deleted from the database, but destroying an > object (in AR terms) does not turn an instance of it to nil. > > Give this a shot: > > lambda { Comment.find(comment_1.id) }.should > raise_error(ActiveRecord::RecordNotFound) > lambda { Comment.find(comment_2.id) }.should > raise_error(ActiveRecord::RecordNotFound) > > Although generally I prefer to keep only one expectation per example. > > HTH, > > David Or perhaps Comment.find_all_by_user_id(user.id).should be_empty -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From backslash451 at yahoo.it Mon Mar 17 07:30:44 2008 From: backslash451 at yahoo.it (roberto belardo) Date: Mon, 17 Mar 2008 12:30:44 +0100 (CET) Subject: [rspec-users] RSpec'ing model association callbacks In-Reply-To: <57c63afe0803170416hc8c8bdft4fa07822639334ce@mail.gmail.com> Message-ID: <739550.22735.qm@web27002.mail.ukl.yahoo.com> Wow, as expected this works. Thank you very much for your help. Do you think this approach for model callbacks specing is right (apart from the number of expectations per example)? --- David Chelimsky ha scritto: > On Mon, Mar 17, 2008 at 5:53 AM, roberto belardo > wrote: > > Hi all, > > i'm learning rspec and i must admit i really love > it. > > But at the time i started learning it, i already > > developed my models classes and their callbacks. > > > > Now i'm trying to get a 100% coverage of my code > but i > > cannot reach it because i do not understand how > to > > spec my callbacks. > > > > Look at this for example: > > > > ----------------- User Model > > > > class User < ActiveRecord::Base > > before_destroy :delete_associated_comments > > def delete_associated_comments > > comments = > Comment.find_all_by_user_id(self.id) > > comments.each { |c| > > c.destroy > > } > > end > > end > > > > ----------------- User Spec > > > > describe User, " being deleted" do > > > > before(:each) do > > end > > > > it "should see deleted his own comments" do > > user = Factory.create_user() > > comment_1 = Factory.create_comment(:author => > > user) > > comment_2 = Factory.create_comment(:author => > > user) > > user.destroy > > comment_1.should be nil > > comment_2.should be nil > > This won't work because you already have a handle on > each of these > objects. They are likely deleted from the database, > but destroying an > object (in AR terms) does not turn an instance of it > to nil. > > Give this a shot: > > lambda { Comment.find(comment_1.id) }.should > raise_error(ActiveRecord::RecordNotFound) > lambda { Comment.find(comment_2.id) }.should > raise_error(ActiveRecord::RecordNotFound) > > Although generally I prefer to keep only one > expectation per example. > > HTH, > David > > > > end > > > > end > > > > ----------------- Factory Module > > > > def self.create_user(attributes = {}) > > default_attributes = { > > :first_name => "Foo", > > :second_name => "Bar", > > :user_name => "FooBar", > > :email => "foo at bar.com" > > } > > User.create! > default_attributes.merge(attributes) > > end > > > > def self.create_comment(attributes = {}) > > default_attributes = { > > :title => "title", > > :text => "text", > > :author => create_user > > } > > Comment.create! > > default_attributes.merge(attributes) > > end > > > > ----------------- > > > > I imagined a spec like the one above but > obviously it > > doesn't works. :-( > > I really do no understand how i can spec my > callbacks. > > Could someone help me with this? > > > > Thanks in advance, > > Backslas451. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Inviato da Yahoo! Mail. Il servizio di posta?con lo spazio illimitato. http://it.docs.yahoo.com/mail/overview/index.html From dchelimsky at gmail.com Mon Mar 17 07:33:02 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 17 Mar 2008 06:33:02 -0500 Subject: [rspec-users] RSpec'ing model association callbacks In-Reply-To: References: <586269.252.qm@web27005.mail.ukl.yahoo.com> <57c63afe0803170416hc8c8bdft4fa07822639334ce@mail.gmail.com> Message-ID: <57c63afe0803170433q2af201b9m18fd45a5e00224b9@mail.gmail.com> On Mon, Mar 17, 2008 at 6:28 AM, Rick DeNatale wrote: > > On 3/17/08, David Chelimsky wrote: > > On Mon, Mar 17, 2008 at 5:53 AM, roberto belardo wrote: > > > Hi all, > > > i'm learning rspec and i must admit i really love it. > > > But at the time i started learning it, i already > > > developed my models classes and their callbacks. > > > > > > Now i'm trying to get a 100% coverage of my code but i > > > cannot reach it because i do not understand how to > > > spec my callbacks. > > > > > > Look at this for example: > > > > > > ----------------- User Model > > > > > > class User < ActiveRecord::Base > > > before_destroy :delete_associated_comments > > > def delete_associated_comments > > > comments = Comment.find_all_by_user_id(self.id) > > > comments.each { |c| > > > c.destroy > > > } > > > end > > > end > > > > > > ----------------- User Spec > > > > > > describe User, " being deleted" do > > > > > > before(:each) do > > > end > > > > > > it "should see deleted his own comments" do > > > user = Factory.create_user() > > > comment_1 = Factory.create_comment(:author => > > > user) > > > comment_2 = Factory.create_comment(:author => > > > user) > > > user.destroy > > > comment_1.should be nil > > > comment_2.should be nil > > > > > > This won't work because you already have a handle on each of these > > objects. They are likely deleted from the database, but destroying an > > object (in AR terms) does not turn an instance of it to nil. > > > > Give this a shot: > > > > lambda { Comment.find(comment_1.id) }.should > > raise_error(ActiveRecord::RecordNotFound) > > lambda { Comment.find(comment_2.id) }.should > > raise_error(ActiveRecord::RecordNotFound) > > > > Although generally I prefer to keep only one expectation per example. > > > > HTH, > > > > David > > Or perhaps > > Comment.find_all_by_user_id(user.id).should be_empty +1 From ashley.moran at patchspace.co.uk Mon Mar 17 08:05:06 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 17 Mar 2008 12:05:06 +0000 Subject: [rspec-users] Specifing methods in a steps_for block In-Reply-To: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> Message-ID: On 13/03/2008, Bart Zonneveld wrote: > > Hey list, > > I'm refactoring some much-used functionality into a common_steps step > group. Methods like this are in there: Hi Bart / list This is not quite what you are thinking but I've noticed something strange about steps_for. Basically when the steps are define the Given, When, Then methods run in the context of a StepGroup, but when they run they have a different context. So to call a method in a step group you have to do something like this: steps_for :login do def sign_in(page, username, password) # ... end Given "a signed-in support user" do # ... @page = browser.open_page("/signin") steps_for(:login).sign_in(@page, "support_user at becta.org.uk", "support-password") end # ... end (If you wonder about the code, I'm using Selenium not Rails Stories) Two consequences of this scoping : * you have to use steps_for(:login) as the explicit receiver of the sign_in method * you have to pass in the instance variable because when the code runs, sign_in puts the instance variables in the StepGroup, not in whatever object the runner uses (didn't bother to figure that out) Really strange behaviour - I wonder if there's a better way to do this. Am I going about it the wrong way by using methods in steps_for? Comments welcome Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080317/bbae0960/attachment.html From dchelimsky at gmail.com Mon Mar 17 08:12:46 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 17 Mar 2008 07:12:46 -0500 Subject: [rspec-users] Specifing methods in a steps_for block In-Reply-To: References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> Message-ID: <57c63afe0803170512n30945ab1x195c49397d6c0de2@mail.gmail.com> On Mon, Mar 17, 2008 at 7:05 AM, Ashley Moran wrote: > On 13/03/2008, Bart Zonneveld wrote: > > > Hey list, > > > > I'm refactoring some much-used functionality into a common_steps step > > group. Methods like this are in there: > > > Hi Bart / list > > This is not quite what you are thinking but I've noticed something strange > about steps_for. Basically when the steps are define the Given, When, Then > methods run in the context of a StepGroup, but when they run they have a > different context. > > So to call a method in a step group you have to do something like this: > > steps_for :login do > def sign_in(page, username, password) > # ... > end > > Given "a signed-in support user" do > # ... > @page = browser.open_page("/signin") > steps_for(:login).sign_in(@page, "support_user at becta.org.uk", > "support-password") > end > > # ... > end > > (If you wonder about the code, I'm using Selenium not Rails Stories) > > Two consequences of this scoping : > * you have to use steps_for(:login) as the explicit receiver of the sign_in > method > * you have to pass in the instance variable because when the code runs, > sign_in puts the instance variables in the StepGroup, not in whatever object > the runner uses (didn't bother to figure that out) I have mixed feelings about this. If you do build up a library of step groups, having explicit scoping like this can be a great benefit. Agreed it makes things less convenient otherwise. I can see copying the helper methods to the scope in which the steps are executed. WDYT? David > > Really strange behaviour - I wonder if there's a better way to do this. Am > I going about it the wrong way by using methods in steps_for? Comments > welcome > > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tobias.torkler at meco.de Mon Mar 17 08:27:39 2008 From: tobias.torkler at meco.de (Tobias Torkler) Date: Mon, 17 Mar 2008 13:27:39 +0100 Subject: [rspec-users] RSpec and RCov with JRuby Message-ID: <8BDE707C-7B3D-4D3E-96F8-BAE4C39F078D@meco.de> Hi, I am using JRuby (trunk) and wrote a bunch of specifications for my code. Everything works fine so far. Now I am trying to integrate RCov in my test run. I have installed RCov without the C extensions. I tried it with a simple script and it worked (pretty slow, but it doesn?t matter). But when I add the rcov options to my Rake task, RCov is not invoke properly! Rakefile: Spec::Rake::SpecTask.new('specs') do |t| t.spec_files = FileList['spec/**/*.rb'] t.rcov = true t.rcov_opts = ['--exclude', 'spec'] t.verbose = true end Output: ... Finished in 11.376 seconds 187 examples, 0 failures, 10 pending Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov Started Finished in 0.0080 seconds. 0 tests, 0 assertions, 0 failures, 0 errors Why is rcov started at the end of the test run? From ashley.moran at patchspace.co.uk Mon Mar 17 09:11:57 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 17 Mar 2008 13:11:57 +0000 Subject: [rspec-users] Specifing methods in a steps_for block In-Reply-To: <57c63afe0803170512n30945ab1x195c49397d6c0de2@mail.gmail.com> References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <57c63afe0803170512n30945ab1x195c49397d6c0de2@mail.gmail.com> Message-ID: > > I have mixed feelings about this. If you do build up a library of step > groups, having explicit scoping like this can be a great benefit. > Agreed it makes things less convenient otherwise. Hi David Not sure I follow. Do you mean explicit scoping as having to type "steps_for(:login)."? If so, I guess that would be handy to call methods across step groups, but that would probably be bad style if they were in different files. I see these helper methods as just a factoring out of identical code. I can see copying the helper methods to the scope in which the steps > are executed. WDYT? Do you mean copy and paste? Or have the code track down the methods you created in the StepGroup scope and copy them into the runner scope? If so that would be cool, it would be transparent then. Name clashes could be an issue though. Syntax day-dreaming led me to think of something like this: Given "a signed-in support user called '$name'" do |name| @support_user = SupportUser.new # log in, etc end Given "something that needs a support user" do give_me "a signed-in support user called 'Fred'" @support_user.support_someone end or When "user signs in with '$username' and '$password'" do |username, password| # type form, click submit etc end Given "a signed-in support user called '$name'" do |name| perform_step "user signs in with 'support_user' and 'secret'" end or Then "user should see text '$text'" do |text| page.should =~ /text/ # type form, click submit etc end Then "user should see their details" do include_requirement "user should see text 'Adam'" include_requirement "user should see text 'Smith'" include_requirement "user should see text 'adam at smith.com'" end Is anything like this currently possible? If not, would it be (a) a Good Thing and (b) straightforward to implement? Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080317/d8330a76/attachment-0001.html From coreyhaines at gmail.com Mon Mar 17 09:20:50 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Mon, 17 Mar 2008 09:20:50 -0400 Subject: [rspec-users] Specifing methods in a steps_for block In-Reply-To: References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <57c63afe0803170512n30945ab1x195c49397d6c0de2@mail.gmail.com> Message-ID: <6bdacb70803170620y678ea536la23fc3f1ba0d4ea3@mail.gmail.com> As an interim solution, we added this as helper file in the stories root. The key was figuring out what to mixin to. class ActionController::Integration::Session def with_input(id) with_tag('input[id=?]',id) end def with_label(text) with_tag('label',text) end def show_login_form with_tag('h2','Log In') have_tag ('form[action=?]','/sessions') do with_input('username') with_input('password') with_tag('input[class=?]','image-submit') end end def show_invitation_form have_tag('form[action=?][method=?]', membership_application_path(:show), 'get') do with_label('Invitation Code:') with_input('code') end end end -Corey On Mon, Mar 17, 2008 at 9:11 AM, Ashley Moran wrote: > I have mixed feelings about this. If you do build up a library of step > > groups, having explicit scoping like this can be a great benefit. > > Agreed it makes things less convenient otherwise. > > > > Hi David > > Not sure I follow. Do you mean explicit scoping as having to type > "steps_for(:login)."? If so, I guess that would be handy to call methods > across step groups, but that would probably be bad style if they were in > different files. I see these helper methods as just a factoring out of > identical code. > > > I can see copying the helper methods to the scope in which the steps > > are executed. WDYT? > > > Do you mean copy and paste? Or have the code track down the methods you > created in the StepGroup scope and copy them into the runner scope? If so > that would be cool, it would be transparent then. Name clashes could be an > issue though. > > Syntax day-dreaming led me to think of something like this: > Given "a signed-in support user called '$name'" do |name| > @support_user = SupportUser.new > # log in, etc > end > > Given "something that needs a support user" do > give_me "a signed-in support user called 'Fred'" > @support_user.support_someone > end > > or > When "user signs in with '$username' and '$password'" do |username, > password| > # type form, click submit etc > end > > Given "a signed-in support user called '$name'" do |name| > perform_step "user signs in with 'support_user' and 'secret'" > end > > or > Then "user should see text '$text'" do |text| > page.should =~ /text/ > # type form, click submit etc > end > > Then "user should see their details" do > include_requirement "user should see text 'Adam'" > include_requirement "user should see text 'Smith'" > include_requirement "user should see text 'adam at smith.com'" > end > > > Is anything like this currently possible? If not, would it be (a) a Good > Thing and (b) straightforward to implement? > > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080317/db49b5fc/attachment.html From ashley.moran at patchspace.co.uk Mon Mar 17 09:41:57 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 17 Mar 2008 13:41:57 +0000 Subject: [rspec-users] Specifing methods in a steps_for block In-Reply-To: <6bdacb70803170620y678ea536la23fc3f1ba0d4ea3@mail.gmail.com> References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <57c63afe0803170512n30945ab1x195c49397d6c0de2@mail.gmail.com> <6bdacb70803170620y678ea536la23fc3f1ba0d4ea3@mail.gmail.com> Message-ID: On 17/03/2008, Corey Haines wrote: > > As an interim solution, we added this as helper file in the stories root. > The key was figuring out what to mixin to. > > class ActionController::Integration::Session > # ... > end > > -Corey Pretty neat! Unfortunately I don't think I can do something similar. I'm using the story runner raw to drive selenium, so only have access to the RSpec library and nowhere to inject these helper methods. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080317/b7b2387e/attachment.html From zach.dennis at gmail.com Mon Mar 17 09:51:53 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 17 Mar 2008 09:51:53 -0400 Subject: [rspec-users] Specifing methods in a steps_for block In-Reply-To: References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <57c63afe0803170512n30945ab1x195c49397d6c0de2@mail.gmail.com> <6bdacb70803170620y678ea536la23fc3f1ba0d4ea3@mail.gmail.com> Message-ID: <85d99afe0803170651p1d1c0412s1c8af8428cbf71fd@mail.gmail.com> I have been putting helper methods inside of my own modules and then including them in RSpec::Story::World, which included in the context that stories are defined and run in (David, feel free to correct me if this is not 100% accurate). module Spec::Story::World def foo # this is now available to all stories being run end end Zach On Mon, Mar 17, 2008 at 9:41 AM, Ashley Moran wrote: > On 17/03/2008, Corey Haines wrote: > > > > As an interim solution, we added this as helper file in the stories root. > The key was figuring out what to mixin to. > > > > class ActionController::Integration::Session > > # ... > > end > > > > -Corey > > > Pretty neat! Unfortunately I don't think I can do something similar. I'm > using the story runner raw to drive selenium, so only have access to the > RSpec library and nowhere to inject these helper methods. > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com From loop at superinfinite.com Mon Mar 17 09:55:48 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Mon, 17 Mar 2008 14:55:48 +0100 Subject: [rspec-users] Specifing methods in a steps_for block In-Reply-To: <57c63afe0803170512n30945ab1x195c49397d6c0de2@mail.gmail.com> References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <57c63afe0803170512n30945ab1x195c49397d6c0de2@mail.gmail.com> Message-ID: Hmm, all of a sudden this thread is spiraling away from my original question :). Which is good of course :). I've made some inline comments. On 17-mrt-2008, at 13:12, David Chelimsky wrote: > On Mon, Mar 17, 2008 at 7:05 AM, Ashley Moran > wrote: >> On 13/03/2008, Bart Zonneveld wrote: >> >>> Hey list, >>> >>> I'm refactoring some much-used functionality into a common_steps >>> step >>> group. Methods like this are in there: >> >> >> Hi Bart / list >> >> This is not quite what you are thinking but I've noticed something >> strange >> about steps_for. Basically when the steps are define the Given, >> When, Then >> methods run in the context of a StepGroup, but when they run they >> have a >> different context. >> >> So to call a method in a step group you have to do something like >> this: >> >> steps_for :login do >> def sign_in(page, username, password) >> # ... >> end >> >> Given "a signed-in support user" do >> # ... >> @page = browser.open_page("/signin") >> steps_for(:login).sign_in(@page, "support_user at becta.org.uk", >> "support-password") >> end I can see how this would work for you, but I actually want something more abstracted. You're specifing the sign_in method inside the same stepgroup, but I want to reference it from another stepgroup. So, to follow your example, I want to call sign_in(page, username, password) from my common_steps stepgroup. regards, bartz From loop at superinfinite.com Mon Mar 17 09:59:06 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Mon, 17 Mar 2008 14:59:06 +0100 Subject: [rspec-users] Specifing methods in a steps_for block In-Reply-To: <85d99afe0803170651p1d1c0412s1c8af8428cbf71fd@mail.gmail.com> References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <57c63afe0803170512n30945ab1x195c49397d6c0de2@mail.gmail.com> <6bdacb70803170620y678ea536la23fc3f1ba0d4ea3@mail.gmail.com> <85d99afe0803170651p1d1c0412s1c8af8428cbf71fd@mail.gmail.com> Message-ID: <9C508AFA-1768-4B2E-AA9D-8B78892F9BB2@superinfinite.com> On 17-mrt-2008, at 14:51, Zach Dennis wrote: > I have been putting helper methods inside of my own modules and then > including them in RSpec::Story::World, which included in the context > that stories are defined and run in (David, feel free to correct me if > this is not 100% accurate). > Hmm, maybe I should clarify some more.. Imagine the following, untested, proof-of-idea code: steps_for(:adding_posts) do def valid_post { :title => 'My First Post' } end end steps_for(:common) do Given "a valid post" do post "/posts/create", post => valid_post end end valid_post is not defined for steps_for(:common). regards, bartz From ashley.moran at patchspace.co.uk Mon Mar 17 10:01:48 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 17 Mar 2008 14:01:48 +0000 Subject: [rspec-users] Specifing methods in a steps_for block In-Reply-To: References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <57c63afe0803170512n30945ab1x195c49397d6c0de2@mail.gmail.com> Message-ID: On 17/03/2008, Bart Zonneveld wrote: > > Hmm, all of a sudden this thread is spiraling away from my original > question :). Which is good of course :). > I've made some inline comments. > > I can see how this would work for you, but I actually want something > more abstracted. > You're specifing the sign_in method inside the same stepgroup, but I > want to reference it from another stepgroup. So, to follow your > example, I want to call sign_in(page, username, password) from my > common_steps stepgroup. > > regards, > bartz > Bartz, Without checking, I assume this could be done as steps_for :common do Given "something" do steps_for(:login).sign_in(...) end end Is that what you mean? Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080317/8621c332/attachment.html From loop at superinfinite.com Mon Mar 17 10:14:55 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Mon, 17 Mar 2008 15:14:55 +0100 Subject: [rspec-users] Specifing methods in a steps_for block In-Reply-To: References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <57c63afe0803170512n30945ab1x195c49397d6c0de2@mail.gmail.com> Message-ID: <4C468C81-6640-4F85-AF85-F1F4CB2DC5E2@superinfinite.com> On 17-mrt-2008, at 15:01, Ashley Moran wrote: > On 17/03/2008, Bart Zonneveld wrote: > Hmm, all of a sudden this thread is spiraling away from my original > question :). Which is good of course :). > I've made some inline comments. > > I can see how this would work for you, but I actually want something > more abstracted. > You're specifing the sign_in method inside the same stepgroup, but I > want to reference it from another stepgroup. So, to follow your > example, I want to call sign_in(page, username, password) from my > common_steps stepgroup. > > regards, > bartz > > > Bartz, > > Without checking, I assume this could be done as > > steps_for :common do > Given "something" do > steps_for(:login).sign_in(...) > end > end > > Is that what you mean? Very close, but not quite :). In my common step group, I'd like to call a (for instance) valid_attributes method, which is defined on the stepgroup which is used in my story. Hope that makes sense... regards, bartz From zach.dennis at gmail.com Mon Mar 17 10:20:33 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 17 Mar 2008 10:20:33 -0400 Subject: [rspec-users] Specifing methods in a steps_for block In-Reply-To: <9C508AFA-1768-4B2E-AA9D-8B78892F9BB2@superinfinite.com> References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <57c63afe0803170512n30945ab1x195c49397d6c0de2@mail.gmail.com> <6bdacb70803170620y678ea536la23fc3f1ba0d4ea3@mail.gmail.com> <85d99afe0803170651p1d1c0412s1c8af8428cbf71fd@mail.gmail.com> <9C508AFA-1768-4B2E-AA9D-8B78892F9BB2@superinfinite.com> Message-ID: <85d99afe0803170720w33e2f398sc84f57ec70984cd8@mail.gmail.com> On Mon, Mar 17, 2008 at 9:59 AM, Bart Zonneveld wrote: > > On 17-mrt-2008, at 14:51, Zach Dennis wrote: > > > I have been putting helper methods inside of my own modules and then > > including them in RSpec::Story::World, which included in the context > > that stories are defined and run in (David, feel free to correct me if > > this is not 100% accurate). > > > > Hmm, maybe I should clarify some more.. > > Imagine the following, untested, proof-of-idea code: > > steps_for(:adding_posts) do > def valid_post > { :title => 'My First Post' } > end > end > > steps_for(:common) do > Given "a valid post" do > post "/posts/create", post => valid_post > end > end > > valid_post is not defined for steps_for(:common). I'm sorry my last email should have said Spec::Story::World not RSpec::Story::World. And your steps are executed in the context of Spec::Story::World, so it doesn't matter if the method is defined inside of your steps for. I understand what you want to do, but you can write better helpers which don't have this problem. For example I use the form_test_helper to submit forms in Story's, so I don't have to call "post" directly. I have a "submit_event_form" which submits a valid form by default. ie: def submit_event_form submit_form "event-form" do |form| form.event.name = "Foo" end end Then in my step matcher I have something like: When "they submit the event form with invalid information" do submit_event_form do |form| form.event.name = "" end end If I have to reuse that in more then one place I pull it out into a submit_event_form_with_invalid_information method. -- Zach Dennis http://www.continuousthinking.com From aslak.hellesoy at gmail.com Mon Mar 17 10:43:09 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 17 Mar 2008 15:43:09 +0100 Subject: [rspec-users] RSpec and RCov with JRuby In-Reply-To: <8BDE707C-7B3D-4D3E-96F8-BAE4C39F078D@meco.de> References: <8BDE707C-7B3D-4D3E-96F8-BAE4C39F078D@meco.de> Message-ID: <8d961d900803170743x16f8cb02jfc51ef7f31c2b6af@mail.gmail.com> On Mon, Mar 17, 2008 at 1:27 PM, Tobias Torkler wrote: > Hi, > > I am using JRuby (trunk) and wrote a bunch of specifications for my > code. Everything works fine so far. > Now I am trying to integrate RCov in my test run. I have installed > RCov without the C extensions. I tried it with a simple script and it > worked (pretty slow, but it doesn?t matter). > But when I add the rcov options to my Rake task, RCov is not invoke > properly! > > Rakefile: > Spec::Rake::SpecTask.new('specs') do |t| > t.spec_files = FileList['spec/**/*.rb'] > t.rcov = true > t.rcov_opts = ['--exclude', 'spec'] > t.verbose = true > end > > Output: > ... > Finished in 11.376 seconds > > 187 examples, 0 failures, 10 pending > Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov > Started > > Finished in 0.0080 seconds. > > 0 tests, 0 assertions, 0 failures, 0 errors > This is Test::Unit output > Why is rcov started at the end of the test run? Did you mean: Why is Test::Unit started at the end of the RSpec run? I'm not sure exactly what you're asking. Aslak > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Mon Mar 17 10:45:33 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 17 Mar 2008 14:45:33 +0000 Subject: [rspec-users] should have_tag outside Rails Message-ID: Hi Google has not helped me here. I'm looking for a way to use the have_tag assert_select wrapper outside RSpec on Rails (but in a Rails project) so I can use it to check text strings. Has anyone managed this? Thanks Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080317/9eeff5fb/attachment.html From tobias.torkler at meco.de Mon Mar 17 10:50:36 2008 From: tobias.torkler at meco.de (Tobias Torkler) Date: Mon, 17 Mar 2008 15:50:36 +0100 Subject: [rspec-users] RSpec and RCov with JRuby In-Reply-To: <8d961d900803170743x16f8cb02jfc51ef7f31c2b6af@mail.gmail.com> References: <8BDE707C-7B3D-4D3E-96F8-BAE4C39F078D@meco.de> <8d961d900803170743x16f8cb02jfc51ef7f31c2b6af@mail.gmail.com> Message-ID: <616C9BC9-E172-434F-96E7-81F26AC2D1D4@meco.de> This is not Test::Unit output! As you can see I created a Rake task to run my specs and tried to integrate rcov as described on http://rspec.info/documentation/tools/rcov.html RSpec works as expected (187 examples, 0 failures, 10 pending) but I am missing the RCov report. Am 17.03.2008 um 15:43 schrieb aslak hellesoy: > On Mon, Mar 17, 2008 at 1:27 PM, Tobias Torkler > wrote: >> Hi, >> >> I am using JRuby (trunk) and wrote a bunch of specifications for my >> code. Everything works fine so far. >> Now I am trying to integrate RCov in my test run. I have installed >> RCov without the C extensions. I tried it with a simple script and it >> worked (pretty slow, but it doesn?t matter). >> But when I add the rcov options to my Rake task, RCov is not invoke >> properly! >> >> Rakefile: >> Spec::Rake::SpecTask.new('specs') do |t| >> t.spec_files = FileList['spec/**/*.rb'] >> t.rcov = true >> t.rcov_opts = ['--exclude', 'spec'] >> t.verbose = true >> end >> >> Output: >> ... >> Finished in 11.376 seconds >> >> 187 examples, 0 failures, 10 pending >> Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov >> Started >> >> Finished in 0.0080 seconds. >> >> 0 tests, 0 assertions, 0 failures, 0 errors >> > > This is Test::Unit output > >> Why is rcov started at the end of the test run? > > Did you mean: Why is Test::Unit started at the end of the RSpec run? > > I'm not sure exactly what you're asking. > > Aslak > >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> From aslak.hellesoy at gmail.com Mon Mar 17 11:10:58 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 17 Mar 2008 16:10:58 +0100 Subject: [rspec-users] RSpec and RCov with JRuby In-Reply-To: <616C9BC9-E172-434F-96E7-81F26AC2D1D4@meco.de> References: <8BDE707C-7B3D-4D3E-96F8-BAE4C39F078D@meco.de> <8d961d900803170743x16f8cb02jfc51ef7f31c2b6af@mail.gmail.com> <616C9BC9-E172-434F-96E7-81F26AC2D1D4@meco.de> Message-ID: <8d961d900803170810y7d784cf9m1a4a0a9ea0afcd21@mail.gmail.com> On Mon, Mar 17, 2008 at 3:50 PM, Tobias Torkler wrote: > This is not Test::Unit output! The following text - taken from your first email - is Test::Unit output. It is not RCov or RSpec output. ------------8<------------ Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov Started Finished in 0.0080 seconds. 0 tests, 0 assertions, 0 failures, 0 errors ------------8<------------ > As you can see I created a Rake task to run my specs and tried to > integrate rcov as described on http://rspec.info/documentation/tools/rcov.html > RSpec works as expected (187 examples, 0 failures, 10 pending) but I > am missing the RCov report. > In your first email you asked: Why is rcov started at the end of the test run? I got confused about what you mean by "test run" (that usually mean Test::Unit run - and you do have Test::Unit output). Are you trying to figure out what order things are happening in, or are you trying to figure out why you're not getting an RCov report? Aslak > > Am 17.03.2008 um 15:43 schrieb aslak hellesoy: > > > > > On Mon, Mar 17, 2008 at 1:27 PM, Tobias Torkler > > wrote: > >> Hi, > >> > >> I am using JRuby (trunk) and wrote a bunch of specifications for my > >> code. Everything works fine so far. > >> Now I am trying to integrate RCov in my test run. I have installed > >> RCov without the C extensions. I tried it with a simple script and it > >> worked (pretty slow, but it doesn?t matter). > >> But when I add the rcov options to my Rake task, RCov is not invoke > >> properly! > >> > >> Rakefile: > >> Spec::Rake::SpecTask.new('specs') do |t| > >> t.spec_files = FileList['spec/**/*.rb'] > >> t.rcov = true > >> t.rcov_opts = ['--exclude', 'spec'] > >> t.verbose = true > >> end > >> > >> Output: > >> ... > >> Finished in 11.376 seconds > >> > >> 187 examples, 0 failures, 10 pending > >> Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov > >> Started > >> > >> Finished in 0.0080 seconds. > >> > >> 0 tests, 0 assertions, 0 failures, 0 errors > >> > > > > This is Test::Unit output > > > >> Why is rcov started at the end of the test run? > > > > Did you mean: Why is Test::Unit started at the end of the RSpec run? > > > > I'm not sure exactly what you're asking. > > > > Aslak > > > >> _______________________________________________ > >> 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 tobias.torkler at meco.de Mon Mar 17 11:23:20 2008 From: tobias.torkler at meco.de (Tobias Torkler) Date: Mon, 17 Mar 2008 16:23:20 +0100 Subject: [rspec-users] RSpec and RCov with JRuby In-Reply-To: <8d961d900803170810y7d784cf9m1a4a0a9ea0afcd21@mail.gmail.com> References: <8BDE707C-7B3D-4D3E-96F8-BAE4C39F078D@meco.de> <8d961d900803170743x16f8cb02jfc51ef7f31c2b6af@mail.gmail.com> <616C9BC9-E172-434F-96E7-81F26AC2D1D4@meco.de> <8d961d900803170810y7d784cf9m1a4a0a9ea0afcd21@mail.gmail.com> Message-ID: Ok, so the question is then why I don?t get an RCov report? Sorry for the "test run". Better call it an RSpec run? Am 17.03.2008 um 16:10 schrieb aslak hellesoy: > On Mon, Mar 17, 2008 at 3:50 PM, Tobias Torkler > wrote: >> This is not Test::Unit output! > > The following text - taken from your first email - is Test::Unit > output. It is not RCov or RSpec output. > > ------------8<------------ > Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov > Started > > Finished in 0.0080 seconds. > > 0 tests, 0 assertions, 0 failures, 0 errors > ------------8<------------ > >> As you can see I created a Rake task to run my specs and tried to >> integrate rcov as described on http://rspec.info/documentation/tools/rcov.html >> RSpec works as expected (187 examples, 0 failures, 10 pending) but I >> am missing the RCov report. >> > > In your first email you asked: Why is rcov started at the end of the > test run? > I got confused about what you mean by "test run" (that usually mean > Test::Unit run - and you do have Test::Unit output). > > Are you trying to figure out what order things are happening in, or > are you trying to figure out why you're not getting an RCov report? > > Aslak > >> >> Am 17.03.2008 um 15:43 schrieb aslak hellesoy: >> >> >> >>> On Mon, Mar 17, 2008 at 1:27 PM, Tobias Torkler >>> wrote: >>>> Hi, >>>> >>>> I am using JRuby (trunk) and wrote a bunch of specifications for my >>>> code. Everything works fine so far. >>>> Now I am trying to integrate RCov in my test run. I have installed >>>> RCov without the C extensions. I tried it with a simple script >>>> and it >>>> worked (pretty slow, but it doesn?t matter). >>>> But when I add the rcov options to my Rake task, RCov is not invoke >>>> properly! >>>> >>>> Rakefile: >>>> Spec::Rake::SpecTask.new('specs') do |t| >>>> t.spec_files = FileList['spec/**/*.rb'] >>>> t.rcov = true >>>> t.rcov_opts = ['--exclude', 'spec'] >>>> t.verbose = true >>>> end >>>> >>>> Output: >>>> ... >>>> Finished in 11.376 seconds >>>> >>>> 187 examples, 0 failures, 10 pending >>>> Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov >>>> Started >>>> >>>> Finished in 0.0080 seconds. >>>> >>>> 0 tests, 0 assertions, 0 failures, 0 errors >>>> >>> >>> This is Test::Unit output >>> >>>> Why is rcov started at the end of the test run? >>> >>> Did you mean: Why is Test::Unit started at the end of the RSpec run? >>> >>> I'm not sure exactly what you're asking. >>> >>> Aslak >>> >>>> _______________________________________________ >>>> 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 ashley.moran at patchspace.co.uk Mon Mar 17 11:44:45 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 17 Mar 2008 15:44:45 +0000 Subject: [rspec-users] should have_tag outside Rails In-Reply-To: References: Message-ID: On 17/03/2008, Ashley Moran wrote: > > Has anyone managed this? > Cracked it. Really ugly, but my stories/helper.rb looks like this ENV["RAILS_ENV"] = "test_integration" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") # We don't want to use the story adapter because it interferes # starts creating transactions that stop multi-process testing (ie # story runner and mongrel) seeing each other's data #require 'spec/rails/story_adapter' # ... # Hack to let us use should have_tag without loading rspec_on_rails module ActionController class TestResponse end end include Test::Unit::Assertions require 'action_controller/assertions' include ActionController::Assertions require 'spec/rails/matchers/assert_select' include Spec::Rails::Matchers It's just waiting to break, I know it. Actually having done this and discussed assert_select with my team, I think I'll write a have_tag matcher using Hpricot. That way I'm not putting the quality of our application in the hands of Rails code. I thought I'd post this anyway for reference. Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080317/023571ce/attachment.html From tastapod at gmail.com Mon Mar 17 12:08:46 2008 From: tastapod at gmail.com (Dan North) Date: Mon, 17 Mar 2008 16:08:46 +0000 Subject: [rspec-users] What is your workflow? Or how to use the story runner the right way. In-Reply-To: References: <27c0ac6d0803040513l7b4fba44nfb3b314aae1bdcc3@mail.gmail.com> Message-ID: Thanks Chris. This is a really nice description of how I think of BDD. I call it "we should fix that" after Liz Keogh's blog post: http://sirenian.livejournal.com/42871.html (Check the comments for the myriad ways you can misinterpret this!) Cheers, Dan On 04/03/2008, Chris Parsons wrote: > > On 4 Mar 2008, at 13:13, Matthijs Langenberg wrote: > > > Taking the outside-in approach in thought: > > > > At first we write a high-level customer-facing story, this story > > fails. > > Then we start using mocks at object level to use them as a design > > tool, > > and so we implement the different layers of the system. > > After implementing the inner layer, the story should pass. > > When that happens we could remove the mocks and replace it with > > calls to the real code, making the suite less brittle (except for > > calls to external services/databases/file systems). > > > Don't use mocks at the story level. IMHO stories should always be > using the full stack. This includes your database, but you might be > permitted to exclude external services such as credit card billing > systems. However, if you can set up a sandbox to test against (such as > the Paypal sandbox), all to the good. > > We proceed based on two principles: > > A failure in a story means you change specs not code. > A failure in a spec means you change the code. > > This is how we do it (assuming a rails application): > > 1. Write customer story, all steps are pending: > > Scenario: Viewing the front page > When I view the front page > Then I see the text 'welcome to the app' > > 2. Write the first step in the story: > > When "I view the front page" do > get "/" > end > > This then fails, as I don't have a front page yet! > > 3. Pay attention to the error given by the story, and fix that *by > writing a spec*. > > In this case it'll be complaining that the controller doesn't exist. > At this point I drop down to the specs as a failing story means we > need a spec: > > describe MainController do > end > > 4. Make your specs pass. > > 'rake spec' then fails, as MainController doesn't exist. In this case, > I add a controller and a route (by hand, none of that scaffold > business): > > class MainController < ApplicationController > end > > 5. Run the story again if you need to, and use that as a guide to > write more specs. Repeat steps 4 and 5. > > To continue the example - in this case it'll probably complain about > no index action: > > describe MainController do > it "should handle an index action" do > get :index > end > end > > and then, to fix the spec: > > class MainController < ApplicationController > def index > end > end > > Then it'll most likely complain about not having an index.html.erb. > Because controller specs don't render the page, you'll need an an > index.html.erb_spec.rb to test the view properly. And so on. > > Sound like a lot of work, but given practice you can zip through these > steps very quickly. You also get a free 'focusing tool' (lose sight of > where you are? just run the story test and write more specs). > > Hope this is helpful. Maybe I should write up an extended example as a > blog post, including mocking etc, as it seems to come up a lot. > > Thanks > Chris > > PS: Excuse the spelling/coding mistakes in the (untested) code :) > Corrections and comments as to the methodology here most welcome. > > -- > Chris Parsons > Managing Director > Eden Development (UK) Ltd > > chris at edendevelopment.co.uk > www.edendevelopment.co.uk > > 0845 0097 094 > po box 425, winchester, so23 0wy, uk > Map: http://pininthemap.com/edendevelopment > > > Tried Pin in the Map? Mark a map location, add text, send to friends. > http://pininthemap.com > > This electronic message and all contents contain information from the > sender which may be privileged, confidential or otherwise protected > from disclosure. The information is intended to be for the > addressee(s) only. If you are not an addressee, any copying, > disclosure, distribution or use of the contents of this message is > prohibited. If you have received this electronic message in error, > please notify the sender by reply e-mail and destroy the original > message and all copies. The sender does not accept liability for any > errors or omissions. > > _______________________________________________ > 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/20080317/df4de8d0/attachment-0001.html From aslak.hellesoy at gmail.com Mon Mar 17 12:37:28 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 17 Mar 2008 17:37:28 +0100 Subject: [rspec-users] RSpec and RCov with JRuby In-Reply-To: References: <8BDE707C-7B3D-4D3E-96F8-BAE4C39F078D@meco.de> <8d961d900803170743x16f8cb02jfc51ef7f31c2b6af@mail.gmail.com> <616C9BC9-E172-434F-96E7-81F26AC2D1D4@meco.de> <8d961d900803170810y7d784cf9m1a4a0a9ea0afcd21@mail.gmail.com> Message-ID: <8d961d900803170937g3f388314t96b90db9c9da3fae@mail.gmail.com> On Mon, Mar 17, 2008 at 4:23 PM, Tobias Torkler wrote: > Ok, so the question is then why I don?t get an RCov report? Sorry for > the "test run". Better call it an RSpec run? > RSpec run is much clearer, thanks :-) I'm looking into the problem, but I'm struggling to install RCov into JRuby. I get the following error: $ /usr/local/jruby-1.1RC2/bin/jruby -S gem install rcov Building native extensions. This could take a while... extconf.rb:1: no such file to load -- mkmf (LoadError) ERROR: Error installing rcov: ERROR: Failed to build gem native extension. /usr/local/jruby-1.1RC2/bin/jruby extconf.rb install rcov Gem files will remain installed in /usr/local/jruby-1.1RC2/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0 for inspection. Results logged to /usr/local/jruby-1.1RC2/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/ext/rcovrt/gem_make.out How did you install rcov bypassing the building of the C extensions? Aslak > > Am 17.03.2008 um 16:10 schrieb aslak hellesoy: > > > > > On Mon, Mar 17, 2008 at 3:50 PM, Tobias Torkler > > wrote: > >> This is not Test::Unit output! > > > > The following text - taken from your first email - is Test::Unit > > output. It is not RCov or RSpec output. > > > > ------------8<------------ > > Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov > > Started > > > > Finished in 0.0080 seconds. > > > > 0 tests, 0 assertions, 0 failures, 0 errors > > ------------8<------------ > > > >> As you can see I created a Rake task to run my specs and tried to > >> integrate rcov as described on http://rspec.info/documentation/tools/rcov.html > >> RSpec works as expected (187 examples, 0 failures, 10 pending) but I > >> am missing the RCov report. > >> > > > > In your first email you asked: Why is rcov started at the end of the > > test run? > > I got confused about what you mean by "test run" (that usually mean > > Test::Unit run - and you do have Test::Unit output). > > > > Are you trying to figure out what order things are happening in, or > > are you trying to figure out why you're not getting an RCov report? > > > > Aslak > > > >> > >> Am 17.03.2008 um 15:43 schrieb aslak hellesoy: > >> > >> > >> > >>> On Mon, Mar 17, 2008 at 1:27 PM, Tobias Torkler >>>> wrote: > >>>> Hi, > >>>> > >>>> I am using JRuby (trunk) and wrote a bunch of specifications for my > >>>> code. Everything works fine so far. > >>>> Now I am trying to integrate RCov in my test run. I have installed > >>>> RCov without the C extensions. I tried it with a simple script > >>>> and it > >>>> worked (pretty slow, but it doesn?t matter). > >>>> But when I add the rcov options to my Rake task, RCov is not invoke > >>>> properly! > >>>> > >>>> Rakefile: > >>>> Spec::Rake::SpecTask.new('specs') do |t| > >>>> t.spec_files = FileList['spec/**/*.rb'] > >>>> t.rcov = true > >>>> t.rcov_opts = ['--exclude', 'spec'] > >>>> t.verbose = true > >>>> end > >>>> > >>>> Output: > >>>> ... > >>>> Finished in 11.376 seconds > >>>> > >>>> 187 examples, 0 failures, 10 pending > >>>> Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov > >>>> Started > >>>> > >>>> Finished in 0.0080 seconds. > >>>> > >>>> 0 tests, 0 assertions, 0 failures, 0 errors > >>>> > >>> > >>> This is Test::Unit output > >>> > >>>> Why is rcov started at the end of the test run? > >>> > >>> Did you mean: Why is Test::Unit started at the end of the RSpec run? > >>> > >>> I'm not sure exactly what you're asking. > >>> > >>> Aslak > >>> > >>>> _______________________________________________ > >>>> 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 tobias.torkler at meco.de Mon Mar 17 12:47:55 2008 From: tobias.torkler at meco.de (Tobias Torkler) Date: Mon, 17 Mar 2008 17:47:55 +0100 Subject: [rspec-users] RSpec and RCov with JRuby In-Reply-To: <8d961d900803170937g3f388314t96b90db9c9da3fae@mail.gmail.com> References: <8BDE707C-7B3D-4D3E-96F8-BAE4C39F078D@meco.de> <8d961d900803170743x16f8cb02jfc51ef7f31c2b6af@mail.gmail.com> <616C9BC9-E172-434F-96E7-81F26AC2D1D4@meco.de> <8d961d900803170810y7d784cf9m1a4a0a9ea0afcd21@mail.gmail.com> <8d961d900803170937g3f388314t96b90db9c9da3fae@mail.gmail.com> Message-ID: <8DAA6697-1C79-4403-BACA-E09AD855BF3A@meco.de> 1. Download http://eigenclass.org/static/rcov/rcov-0.8.1.2.tar.gz and extract the archive 2. jruby -S setup.rb all --without-ext 3. Change shebang of /bin/rcov to #!/usr/bin/env jruby 4. rcov script.rb should work now (warning appears, that no extensions are installed) Am 17.03.2008 um 17:37 schrieb aslak hellesoy: > On Mon, Mar 17, 2008 at 4:23 PM, Tobias Torkler > wrote: >> Ok, so the question is then why I don?t get an RCov report? Sorry for >> the "test run". Better call it an RSpec run? >> > > RSpec run is much clearer, thanks :-) > > I'm looking into the problem, but I'm struggling to install RCov into > JRuby. I get the following error: > > $ /usr/local/jruby-1.1RC2/bin/jruby -S gem install rcov > Building native extensions. This could take a while... > extconf.rb:1: no such file to load -- mkmf (LoadError) > ERROR: Error installing rcov: > ERROR: Failed to build gem native extension. > > /usr/local/jruby-1.1RC2/bin/jruby extconf.rb install rcov > > > Gem files will remain installed in > /usr/local/jruby-1.1RC2/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0 for > inspection. > Results logged to > /usr/local/jruby-1.1RC2/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/ext/ > rcovrt/gem_make.out > > How did you install rcov bypassing the building of the C extensions? > > Aslak >> >> Am 17.03.2008 um 16:10 schrieb aslak hellesoy: >> >> >> >>> On Mon, Mar 17, 2008 at 3:50 PM, Tobias Torkler >>> wrote: >>>> This is not Test::Unit output! >>> >>> The following text - taken from your first email - is Test::Unit >>> output. It is not RCov or RSpec output. >>> >>> ------------8<------------ >>> Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov >>> Started >>> >>> Finished in 0.0080 seconds. >>> >>> 0 tests, 0 assertions, 0 failures, 0 errors >>> ------------8<------------ >>> >>>> As you can see I created a Rake task to run my specs and tried to >>>> integrate rcov as described on http://rspec.info/documentation/tools/rcov.html >>>> RSpec works as expected (187 examples, 0 failures, 10 pending) >>>> but I >>>> am missing the RCov report. >>>> >>> >>> In your first email you asked: Why is rcov started at the end of the >>> test run? >>> I got confused about what you mean by "test run" (that usually mean >>> Test::Unit run - and you do have Test::Unit output). >>> >>> Are you trying to figure out what order things are happening in, or >>> are you trying to figure out why you're not getting an RCov report? >>> >>> Aslak >>> >>>> >>>> Am 17.03.2008 um 15:43 schrieb aslak hellesoy: >>>> >>>> >>>> >>>>> On Mon, Mar 17, 2008 at 1:27 PM, Tobias Torkler >>>>> wrote: >>>>>> Hi, >>>>>> >>>>>> I am using JRuby (trunk) and wrote a bunch of specifications >>>>>> for my >>>>>> code. Everything works fine so far. >>>>>> Now I am trying to integrate RCov in my test run. I have >>>>>> installed >>>>>> RCov without the C extensions. I tried it with a simple script >>>>>> and it >>>>>> worked (pretty slow, but it doesn?t matter). >>>>>> But when I add the rcov options to my Rake task, RCov is not >>>>>> invoke >>>>>> properly! >>>>>> >>>>>> Rakefile: >>>>>> Spec::Rake::SpecTask.new('specs') do |t| >>>>>> t.spec_files = FileList['spec/**/*.rb'] >>>>>> t.rcov = true >>>>>> t.rcov_opts = ['--exclude', 'spec'] >>>>>> t.verbose = true >>>>>> end >>>>>> >>>>>> Output: >>>>>> ... >>>>>> Finished in 11.376 seconds >>>>>> >>>>>> 187 examples, 0 failures, 10 pending >>>>>> Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov >>>>>> Started >>>>>> >>>>>> Finished in 0.0080 seconds. >>>>>> >>>>>> 0 tests, 0 assertions, 0 failures, 0 errors >>>>>> >>>>> >>>>> This is Test::Unit output >>>>> >>>>>> Why is rcov started at the end of the test run? >>>>> >>>>> Did you mean: Why is Test::Unit started at the end of the RSpec >>>>> run? >>>>> >>>>> I'm not sure exactly what you're asking. >>>>> >>>>> Aslak >>>>> >>>>>> _______________________________________________ >>>>>> 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 philodespotos at gmail.com Mon Mar 17 14:41:25 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Mon, 17 Mar 2008 13:41:25 -0500 Subject: [rspec-users] should have_tag outside Rails In-Reply-To: References: Message-ID: <60f3810c0803171141x196bf4dft1e9a8c1834cec44f@mail.gmail.com> On Mon, Mar 17, 2008 at 10:44 AM, Ashley Moran wrote: > On 17/03/2008, Ashley Moran wrote: > > Has anyone managed this? > > > > Cracked it. Really ugly, but my stories/helper.rb looks like this > > ENV["RAILS_ENV"] = "test_integration" > require File.expand_path(File.dirname(__FILE__) + > "/../config/environment") > # We don't want to use the story adapter because it interferes > # starts creating transactions that stop multi-process testing (ie > # story runner and mongrel) seeing each other's data > #require 'spec/rails/story_adapter' > > # ... > > # Hack to let us use should have_tag without loading rspec_on_rails > module ActionController > class TestResponse > > end > end > > include Test::Unit::Assertions > > require 'action_controller/assertions' > include ActionController::Assertions > > require 'spec/rails/matchers/assert_select' > include Spec::Rails::Matchers > > It's just waiting to break, I know it. > > Actually having done this and discussed assert_select with my team, I think > I'll write a have_tag matcher using Hpricot. That way I'm not putting the > quality of our application in the hands of Rails code. > > I thought I'd post this anyway for reference. > > Ashley We discussed this in a ticket on lighthouse, and I ended up writing a workalike that's sitting atop hpricot. It's not quite identical, but generally close enough and so far does everything I've needed: http://github.com/pd/rspec_hpricot_matchers Patches and/or suggestions welcome if you need anything else out of it Kyle From aslak.hellesoy at gmail.com Mon Mar 17 14:54:29 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 17 Mar 2008 19:54:29 +0100 Subject: [rspec-users] RSpec and RCov with JRuby In-Reply-To: <8DAA6697-1C79-4403-BACA-E09AD855BF3A@meco.de> References: <8BDE707C-7B3D-4D3E-96F8-BAE4C39F078D@meco.de> <8d961d900803170743x16f8cb02jfc51ef7f31c2b6af@mail.gmail.com> <616C9BC9-E172-434F-96E7-81F26AC2D1D4@meco.de> <8d961d900803170810y7d784cf9m1a4a0a9ea0afcd21@mail.gmail.com> <8d961d900803170937g3f388314t96b90db9c9da3fae@mail.gmail.com> <8DAA6697-1C79-4403-BACA-E09AD855BF3A@meco.de> Message-ID: <8d961d900803171154t39419a57y2f0a7f97a14b5dd5@mail.gmail.com> On Mon, Mar 17, 2008 at 5:47 PM, Tobias Torkler wrote: > 1. Download http://eigenclass.org/static/rcov/rcov-0.8.1.2.tar.gz and > extract the archive > 2. jruby -S setup.rb all --without-ext > 3. Change shebang of /bin/rcov to #!/usr/bin/env jruby > 4. rcov script.rb should work now (warning appears, that no extensions > are installed) > Thanks, those installation instructions were useful. Unfortunately, I'm unable to run RCov 0.8.1.2 on JRuby 1.1.RC2 at all: $ /usr/local/jruby-1.1RC2/bin/jruby -S rcov --version Exception in thread "main" java.lang.RuntimeException: MethodBlock does not have a static scope; this should not be called at org.jruby.runtime.MethodBlock.getStaticScope(MethodBlock.java:128) at org.jruby.RubyModule.createProcMethod(RubyModule.java:1079) ... (lots more) ... at org.jruby.Main.main(Main.java:79) Can you recommend a JRuby version where RCov will actually start up? Aslak > > Am 17.03.2008 um 17:37 schrieb aslak hellesoy: > > > > > On Mon, Mar 17, 2008 at 4:23 PM, Tobias Torkler > > wrote: > >> Ok, so the question is then why I don?t get an RCov report? Sorry for > >> the "test run". Better call it an RSpec run? > >> > > > > RSpec run is much clearer, thanks :-) > > > > I'm looking into the problem, but I'm struggling to install RCov into > > JRuby. I get the following error: > > > > $ /usr/local/jruby-1.1RC2/bin/jruby -S gem install rcov > > Building native extensions. This could take a while... > > extconf.rb:1: no such file to load -- mkmf (LoadError) > > ERROR: Error installing rcov: > > ERROR: Failed to build gem native extension. > > > > /usr/local/jruby-1.1RC2/bin/jruby extconf.rb install rcov > > > > > > Gem files will remain installed in > > /usr/local/jruby-1.1RC2/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0 for > > inspection. > > Results logged to > > /usr/local/jruby-1.1RC2/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/ext/ > > rcovrt/gem_make.out > > > > How did you install rcov bypassing the building of the C extensions? > > > > Aslak > >> > >> Am 17.03.2008 um 16:10 schrieb aslak hellesoy: > >> > >> > >> > >>> On Mon, Mar 17, 2008 at 3:50 PM, Tobias Torkler >>>> wrote: > >>>> This is not Test::Unit output! > >>> > >>> The following text - taken from your first email - is Test::Unit > >>> output. It is not RCov or RSpec output. > >>> > >>> ------------8<------------ > >>> Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov > >>> Started > >>> > >>> Finished in 0.0080 seconds. > >>> > >>> 0 tests, 0 assertions, 0 failures, 0 errors > >>> ------------8<------------ > >>> > >>>> As you can see I created a Rake task to run my specs and tried to > >>>> integrate rcov as described on http://rspec.info/documentation/tools/rcov.html > >>>> RSpec works as expected (187 examples, 0 failures, 10 pending) > >>>> but I > >>>> am missing the RCov report. > >>>> > >>> > >>> In your first email you asked: Why is rcov started at the end of the > >>> test run? > >>> I got confused about what you mean by "test run" (that usually mean > >>> Test::Unit run - and you do have Test::Unit output). > >>> > >>> Are you trying to figure out what order things are happening in, or > >>> are you trying to figure out why you're not getting an RCov report? > >>> > >>> Aslak > >>> > >>>> > >>>> Am 17.03.2008 um 15:43 schrieb aslak hellesoy: > >>>> > >>>> > >>>> > >>>>> On Mon, Mar 17, 2008 at 1:27 PM, Tobias Torkler >>>>>> wrote: > >>>>>> Hi, > >>>>>> > >>>>>> I am using JRuby (trunk) and wrote a bunch of specifications > >>>>>> for my > >>>>>> code. Everything works fine so far. > >>>>>> Now I am trying to integrate RCov in my test run. I have > >>>>>> installed > >>>>>> RCov without the C extensions. I tried it with a simple script > >>>>>> and it > >>>>>> worked (pretty slow, but it doesn?t matter). > >>>>>> But when I add the rcov options to my Rake task, RCov is not > >>>>>> invoke > >>>>>> properly! > >>>>>> > >>>>>> Rakefile: > >>>>>> Spec::Rake::SpecTask.new('specs') do |t| > >>>>>> t.spec_files = FileList['spec/**/*.rb'] > >>>>>> t.rcov = true > >>>>>> t.rcov_opts = ['--exclude', 'spec'] > >>>>>> t.verbose = true > >>>>>> end > >>>>>> > >>>>>> Output: > >>>>>> ... > >>>>>> Finished in 11.376 seconds > >>>>>> > >>>>>> 187 examples, 0 failures, 10 pending > >>>>>> Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov > >>>>>> Started > >>>>>> > >>>>>> Finished in 0.0080 seconds. > >>>>>> > >>>>>> 0 tests, 0 assertions, 0 failures, 0 errors > >>>>>> > >>>>> > >>>>> This is Test::Unit output > >>>>> > >>>>>> Why is rcov started at the end of the test run? > >>>>> > >>>>> Did you mean: Why is Test::Unit started at the end of the RSpec > >>>>> run? > >>>>> > >>>>> I'm not sure exactly what you're asking. > >>>>> > >>>>> Aslak > >>>>> > >>>>>> _______________________________________________ > >>>>>> 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 tobias.torkler at meco.de Mon Mar 17 15:08:45 2008 From: tobias.torkler at meco.de (Tobias Torkler) Date: Mon, 17 Mar 2008 20:08:45 +0100 Subject: [rspec-users] RSpec and RCov with JRuby In-Reply-To: <8d961d900803171154t39419a57y2f0a7f97a14b5dd5@mail.gmail.com> References: <8BDE707C-7B3D-4D3E-96F8-BAE4C39F078D@meco.de> <8d961d900803170743x16f8cb02jfc51ef7f31c2b6af@mail.gmail.com> <616C9BC9-E172-434F-96E7-81F26AC2D1D4@meco.de> <8d961d900803170810y7d784cf9m1a4a0a9ea0afcd21@mail.gmail.com> <8d961d900803170937g3f388314t96b90db9c9da3fae@mail.gmail.com> <8DAA6697-1C79-4403-BACA-E09AD855BF3A@meco.de> <8d961d900803171154t39419a57y2f0a7f97a14b5dd5@mail.gmail.com> Message-ID: <36BF93CF-CD24-4843-A830-C66B00489B52@meco.de> That?s right, sorry! There was a call and it will be fixed in RC3. But you can checkout the sources (http://svn.codehaus.org/jruby/trunk/jruby/ ) and build the jruby.jar via ant. It will work then! I know it?s complicated, but I need this for my diploma thesis and I appreciate your help! Am 17.03.2008 um 19:54 schrieb aslak hellesoy: > On Mon, Mar 17, 2008 at 5:47 PM, Tobias Torkler > wrote: >> 1. Download http://eigenclass.org/static/rcov/rcov-0.8.1.2.tar.gz and >> extract the archive >> 2. jruby -S setup.rb all --without-ext >> 3. Change shebang of /bin/rcov to #!/usr/bin/env jruby >> 4. rcov script.rb should work now (warning appears, that no >> extensions >> are installed) >> > > Thanks, those installation instructions were useful. > > Unfortunately, I'm unable to run RCov 0.8.1.2 on JRuby 1.1.RC2 at all: > > $ /usr/local/jruby-1.1RC2/bin/jruby -S rcov --version > Exception in thread "main" java.lang.RuntimeException: MethodBlock > does not have a static scope; this should not be called > at > org.jruby.runtime.MethodBlock.getStaticScope(MethodBlock.java:128) > at org.jruby.RubyModule.createProcMethod(RubyModule.java:1079) > ... > (lots more) > ... > at org.jruby.Main.main(Main.java:79) > > Can you recommend a JRuby version where RCov will actually start up? > > Aslak > >> >> Am 17.03.2008 um 17:37 schrieb aslak hellesoy: >> >> >> >>> On Mon, Mar 17, 2008 at 4:23 PM, Tobias Torkler >>> wrote: >>>> Ok, so the question is then why I don?t get an RCov report? Sorry >>>> for >>>> the "test run". Better call it an RSpec run? >>>> >>> >>> RSpec run is much clearer, thanks :-) >>> >>> I'm looking into the problem, but I'm struggling to install RCov >>> into >>> JRuby. I get the following error: >>> >>> $ /usr/local/jruby-1.1RC2/bin/jruby -S gem install rcov >>> Building native extensions. This could take a while... >>> extconf.rb:1: no such file to load -- mkmf (LoadError) >>> ERROR: Error installing rcov: >>> ERROR: Failed to build gem native extension. >>> >>> /usr/local/jruby-1.1RC2/bin/jruby extconf.rb install rcov >>> >>> >>> Gem files will remain installed in >>> /usr/local/jruby-1.1RC2/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0 for >>> inspection. >>> Results logged to >>> /usr/local/jruby-1.1RC2/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/ext/ >>> rcovrt/gem_make.out >>> >>> How did you install rcov bypassing the building of the C extensions? >>> >>> Aslak >>>> >>>> Am 17.03.2008 um 16:10 schrieb aslak hellesoy: >>>> >>>> >>>> >>>>> On Mon, Mar 17, 2008 at 3:50 PM, Tobias Torkler >>>>> wrote: >>>>>> This is not Test::Unit output! >>>>> >>>>> The following text - taken from your first email - is Test::Unit >>>>> output. It is not RCov or RSpec output. >>>>> >>>>> ------------8<------------ >>>>> Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov >>>>> Started >>>>> >>>>> Finished in 0.0080 seconds. >>>>> >>>>> 0 tests, 0 assertions, 0 failures, 0 errors >>>>> ------------8<------------ >>>>> >>>>>> As you can see I created a Rake task to run my specs and tried to >>>>>> integrate rcov as described on http://rspec.info/documentation/tools/rcov.html >>>>>> RSpec works as expected (187 examples, 0 failures, 10 pending) >>>>>> but I >>>>>> am missing the RCov report. >>>>>> >>>>> >>>>> In your first email you asked: Why is rcov started at the end of >>>>> the >>>>> test run? >>>>> I got confused about what you mean by "test run" (that usually >>>>> mean >>>>> Test::Unit run - and you do have Test::Unit output). >>>>> >>>>> Are you trying to figure out what order things are happening in, >>>>> or >>>>> are you trying to figure out why you're not getting an RCov >>>>> report? >>>>> >>>>> Aslak >>>>> >>>>>> >>>>>> Am 17.03.2008 um 15:43 schrieb aslak hellesoy: >>>>>> >>>>>> >>>>>> >>>>>>> On Mon, Mar 17, 2008 at 1:27 PM, Tobias Torkler >>>>>>> wrote: >>>>>>>> Hi, >>>>>>>> >>>>>>>> I am using JRuby (trunk) and wrote a bunch of specifications >>>>>>>> for my >>>>>>>> code. Everything works fine so far. >>>>>>>> Now I am trying to integrate RCov in my test run. I have >>>>>>>> installed >>>>>>>> RCov without the C extensions. I tried it with a simple script >>>>>>>> and it >>>>>>>> worked (pretty slow, but it doesn?t matter). >>>>>>>> But when I add the rcov options to my Rake task, RCov is not >>>>>>>> invoke >>>>>>>> properly! >>>>>>>> >>>>>>>> Rakefile: >>>>>>>> Spec::Rake::SpecTask.new('specs') do |t| >>>>>>>> t.spec_files = FileList['spec/**/*.rb'] >>>>>>>> t.rcov = true >>>>>>>> t.rcov_opts = ['--exclude', 'spec'] >>>>>>>> t.verbose = true >>>>>>>> end >>>>>>>> >>>>>>>> Output: >>>>>>>> ... >>>>>>>> Finished in 11.376 seconds >>>>>>>> >>>>>>>> 187 examples, 0 failures, 10 pending >>>>>>>> Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov >>>>>>>> Started >>>>>>>> >>>>>>>> Finished in 0.0080 seconds. >>>>>>>> >>>>>>>> 0 tests, 0 assertions, 0 failures, 0 errors >>>>>>>> >>>>>>> >>>>>>> This is Test::Unit output >>>>>>> >>>>>>>> Why is rcov started at the end of the test run? >>>>>>> >>>>>>> Did you mean: Why is Test::Unit started at the end of the RSpec >>>>>>> run? >>>>>>> >>>>>>> I'm not sure exactly what you're asking. >>>>>>> >>>>>>> Aslak >>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> 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 Nathan.Zook at amd.com Mon Mar 17 15:50:00 2008 From: Nathan.Zook at amd.com (nzook) Date: Mon, 17 Mar 2008 12:50:00 -0700 (PDT) Subject: [rspec-users] Shouldn't should return true? Message-ID: <16100539.post@talk.nabble.com> 'cause it doesn't... This is an issue for nested custom matchers, ie: module CRFT class RFT def initialize(args) blah end def matches?(target) "Yeah, baby!" end end def r_f_t(args) RFT.new(args) end end module CRLT class RLT include CRFT def initialize(args) blag end def matches?(target) target.should r_f_t('foo', 'bar', 'baz') #Whoops! Matcher FAILS end end def r_l_t(args) RLT.new(args) end end -- View this message in context: http://www.nabble.com/Shouldn%27t-should-return-true--tp16100539p16100539.html Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Mon Mar 17 15:57:10 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 17 Mar 2008 14:57:10 -0500 Subject: [rspec-users] Shouldn't should return true? In-Reply-To: <16100539.post@talk.nabble.com> References: <16100539.post@talk.nabble.com> Message-ID: <57c63afe0803171257k1b47053fmf8af44d294598d02@mail.gmail.com> On Mon, Mar 17, 2008 at 2:50 PM, nzook wrote: > > 'cause it doesn't... > > This is an issue for nested custom matchers, ie: > > module CRFT > class RFT > def initialize(args) > blah > end > def matches?(target) > "Yeah, baby!" > end > end > def r_f_t(args) > RFT.new(args) > end > end > > module CRLT > class RLT > include CRFT > def initialize(args) > blag > end > def matches?(target) > target.should r_f_t('foo', 'bar', 'baz') #Whoops! Matcher FAILS > end > end > def r_l_t(args) > RLT.new(args) > end > end Yes! From rick.denatale at gmail.com Mon Mar 17 16:11:46 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 17 Mar 2008 16:11:46 -0400 Subject: [rspec-users] Branching scenarios, GivenScenario and database In-Reply-To: <57c63afe0803160243t2d007787jcda3599543401c98@mail.gmail.com> References: <57c63afe0803160243t2d007787jcda3599543401c98@mail.gmail.com> Message-ID: On 3/16/08, David Chelimsky wrote: > On Fri, Mar 14, 2008 at 8:12 PM, Rick DeNatale wrote: > > 2) Having figured that out and moving on, I now have another > > problem, which is what's the best way to clean up the database so that > > Scenario A can run again if it assumes that the stuff it put in the DB > > isn't there each time it runs. Cleaning the DB after running the > > scenario won't work since it defeats the purpose of using the scenario > > as a pre-condition. Cleaning it before is more difficult, > > particularly if I'm using parameterized steps. It would be nice if I > > could somehow use database transactions, but I don't see a nice way to > > do that either. > > > This should just work. If you look at story_adapter.rb, which defines > the RailsStory class (maybe we should align :) ) you'll see that the > transaction is opened when the scenario starts and rolled back when it > is finished. GivenScenario should not result in a call to any of the > scenario finished methods (scenario_succeeded, _pending, _failed), so > it should get rolled back. I've gotten stuck here. To recap, when I don't make the story a RailsStory, then the the first scenario (A) works but fails when invoked from B as a GivenScenario. One of the steps is failing because of a validates_uniqueness in on of the models which fails because of stuff left in the DB from the initial running. When I change it to a RailsStory then Scenario A fails in the same step the FIRST time. In this case it's because records which it needs aren't there. The records in question have been loaded by a helper which calls Fixtures.create_fixtures to load them. These particular tables are basically 'constants' for the app. A few more tidbits. There's are models called Role, Membership, and a join model MembershipRole Role has_many :membership_roles has_many :memberships :through => :membership_roles end Membership has_many :membership_roles has_many :membersships, :through => :membership_roles end MembershipRole belongs_to :membership belongs_to :role validates uniqueness_of :role_id, :scope => :membership_id end Role has a class method get which takes a string and effectivly does this: def self.get(name) @role_objects ||= {} @role_objects[name] ||= find_by_name(name) end And the method ultimately invoked by the failing step has a skeleton like this: class Membership < ActiveRecord::Base def add_role(name) if role = Role.get(name) ... else raise "Can't find Role named #{name} end end If I change the Role.get method to bypass the cache then the exception gets raised the first time the step is executed for a RailsStory, and second time for a non-RailsStory. With that method left alone, the Role objects are found at some time previous to the step and cached, in which case the failure happens inside the if where a simplified version of that ... looks like this: unless self.roles(true).include(role) membership_role = MembershipRole.create(:membership => self, :role => role) end role.dependencies.each {|dependency| add_role(dependency) The problem is that the validates_uniqueness_of in MemberRole is failing, again the second time the step in question is called for a non-RailsStory, and the first time for a RailsStory. The reason is that the query generated by the roles association is doing a join on roles and membership roles and the roles aren't in the DB, but then validates_uniqueness of just checks the membership_id and role_id fields. It looks to me as though running as a RailsStory is causing the roles records to be deleted before the scenario runs, but after the class cached them. s Any ideas? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From tobias.torkler at meco.de Mon Mar 17 17:04:59 2008 From: tobias.torkler at meco.de (Tobias Torkler) Date: Mon, 17 Mar 2008 22:04:59 +0100 Subject: [rspec-users] RSpec and RCov with JRuby In-Reply-To: <36BF93CF-CD24-4843-A830-C66B00489B52@meco.de> References: <8BDE707C-7B3D-4D3E-96F8-BAE4C39F078D@meco.de> <8d961d900803170743x16f8cb02jfc51ef7f31c2b6af@mail.gmail.com> <616C9BC9-E172-434F-96E7-81F26AC2D1D4@meco.de> <8d961d900803170810y7d784cf9m1a4a0a9ea0afcd21@mail.gmail.com> <8d961d900803170937g3f388314t96b90db9c9da3fae@mail.gmail.com> <8DAA6697-1C79-4403-BACA-E09AD855BF3A@meco.de> <8d961d900803171154t39419a57y2f0a7f97a14b5dd5@mail.gmail.com> <36BF93CF-CD24-4843-A830-C66B00489B52@meco.de> Message-ID: Issue is solved!!! I had a require 'test/unit' in my spec_helper.rb. I removed it and it works now. Am 17.03.2008 um 20:08 schrieb Tobias Torkler: > That?s right, sorry! There was a call and it will be fixed in RC3. > But you can checkout the sources (http://svn.codehaus.org/jruby/trunk/jruby/ > ) and build the jruby.jar via ant. > It will work then! > > I know it?s complicated, but I need this for my diploma thesis and I > appreciate your help! > > > Am 17.03.2008 um 19:54 schrieb aslak hellesoy: > >> On Mon, Mar 17, 2008 at 5:47 PM, Tobias Torkler >> wrote: >>> 1. Download http://eigenclass.org/static/rcov/rcov-0.8.1.2.tar.gz >>> and >>> extract the archive >>> 2. jruby -S setup.rb all --without-ext >>> 3. Change shebang of /bin/rcov to #!/usr/bin/env jruby >>> 4. rcov script.rb should work now (warning appears, that no >>> extensions >>> are installed) >>> >> >> Thanks, those installation instructions were useful. >> >> Unfortunately, I'm unable to run RCov 0.8.1.2 on JRuby 1.1.RC2 at >> all: >> >> $ /usr/local/jruby-1.1RC2/bin/jruby -S rcov --version >> Exception in thread "main" java.lang.RuntimeException: MethodBlock >> does not have a static scope; this should not be called >> at >> org.jruby.runtime.MethodBlock.getStaticScope(MethodBlock.java:128) >> at org.jruby.RubyModule.createProcMethod(RubyModule.java:1079) >> ... >> (lots more) >> ... >> at org.jruby.Main.main(Main.java:79) >> >> Can you recommend a JRuby version where RCov will actually start up? >> >> Aslak >> >>> >>> Am 17.03.2008 um 17:37 schrieb aslak hellesoy: >>> >>> >>> >>>> On Mon, Mar 17, 2008 at 4:23 PM, Tobias Torkler >>>> wrote: >>>>> Ok, so the question is then why I don?t get an RCov report? Sorry >>>>> for >>>>> the "test run". Better call it an RSpec run? >>>>> >>>> >>>> RSpec run is much clearer, thanks :-) >>>> >>>> I'm looking into the problem, but I'm struggling to install RCov >>>> into >>>> JRuby. I get the following error: >>>> >>>> $ /usr/local/jruby-1.1RC2/bin/jruby -S gem install rcov >>>> Building native extensions. This could take a while... >>>> extconf.rb:1: no such file to load -- mkmf (LoadError) >>>> ERROR: Error installing rcov: >>>> ERROR: Failed to build gem native extension. >>>> >>>> /usr/local/jruby-1.1RC2/bin/jruby extconf.rb install rcov >>>> >>>> >>>> Gem files will remain installed in >>>> /usr/local/jruby-1.1RC2/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0 for >>>> inspection. >>>> Results logged to >>>> /usr/local/jruby-1.1RC2/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/ext/ >>>> rcovrt/gem_make.out >>>> >>>> How did you install rcov bypassing the building of the C >>>> extensions? >>>> >>>> Aslak >>>>> >>>>> Am 17.03.2008 um 16:10 schrieb aslak hellesoy: >>>>> >>>>> >>>>> >>>>>> On Mon, Mar 17, 2008 at 3:50 PM, Tobias Torkler >>>>>> wrote: >>>>>>> This is not Test::Unit output! >>>>>> >>>>>> The following text - taken from your first email - is Test::Unit >>>>>> output. It is not RCov or RSpec output. >>>>>> >>>>>> ------------8<------------ >>>>>> Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov >>>>>> Started >>>>>> >>>>>> Finished in 0.0080 seconds. >>>>>> >>>>>> 0 tests, 0 assertions, 0 failures, 0 errors >>>>>> ------------8<------------ >>>>>> >>>>>>> As you can see I created a Rake task to run my specs and tried >>>>>>> to >>>>>>> integrate rcov as described on http://rspec.info/documentation/tools/rcov.html >>>>>>> RSpec works as expected (187 examples, 0 failures, 10 pending) >>>>>>> but I >>>>>>> am missing the RCov report. >>>>>>> >>>>>> >>>>>> In your first email you asked: Why is rcov started at the end of >>>>>> the >>>>>> test run? >>>>>> I got confused about what you mean by "test run" (that usually >>>>>> mean >>>>>> Test::Unit run - and you do have Test::Unit output). >>>>>> >>>>>> Are you trying to figure out what order things are happening in, >>>>>> or >>>>>> are you trying to figure out why you're not getting an RCov >>>>>> report? >>>>>> >>>>>> Aslak >>>>>> >>>>>>> >>>>>>> Am 17.03.2008 um 15:43 schrieb aslak hellesoy: >>>>>>> >>>>>>> >>>>>>> >>>>>>>> On Mon, Mar 17, 2008 at 1:27 PM, Tobias Torkler >>>>>>>> wrote: >>>>>>>>> Hi, >>>>>>>>> >>>>>>>>> I am using JRuby (trunk) and wrote a bunch of specifications >>>>>>>>> for my >>>>>>>>> code. Everything works fine so far. >>>>>>>>> Now I am trying to integrate RCov in my test run. I have >>>>>>>>> installed >>>>>>>>> RCov without the C extensions. I tried it with a simple script >>>>>>>>> and it >>>>>>>>> worked (pretty slow, but it doesn?t matter). >>>>>>>>> But when I add the rcov options to my Rake task, RCov is not >>>>>>>>> invoke >>>>>>>>> properly! >>>>>>>>> >>>>>>>>> Rakefile: >>>>>>>>> Spec::Rake::SpecTask.new('specs') do |t| >>>>>>>>> t.spec_files = FileList['spec/**/*.rb'] >>>>>>>>> t.rcov = true >>>>>>>>> t.rcov_opts = ['--exclude', 'spec'] >>>>>>>>> t.verbose = true >>>>>>>>> end >>>>>>>>> >>>>>>>>> Output: >>>>>>>>> ... >>>>>>>>> Finished in 11.376 seconds >>>>>>>>> >>>>>>>>> 187 examples, 0 failures, 10 pending >>>>>>>>> Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/ >>>>>>>>> rcov >>>>>>>>> Started >>>>>>>>> >>>>>>>>> Finished in 0.0080 seconds. >>>>>>>>> >>>>>>>>> 0 tests, 0 assertions, 0 failures, 0 errors >>>>>>>>> >>>>>>>> >>>>>>>> This is Test::Unit output >>>>>>>> >>>>>>>>> Why is rcov started at the end of the test run? >>>>>>>> >>>>>>>> Did you mean: Why is Test::Unit started at the end of the RSpec >>>>>>>> run? >>>>>>>> >>>>>>>> I'm not sure exactly what you're asking. >>>>>>>> >>>>>>>> Aslak >>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> 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 aslak.hellesoy at gmail.com Mon Mar 17 17:14:43 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 17 Mar 2008 22:14:43 +0100 Subject: [rspec-users] RSpec and RCov with JRuby In-Reply-To: References: <8BDE707C-7B3D-4D3E-96F8-BAE4C39F078D@meco.de> <8d961d900803170743x16f8cb02jfc51ef7f31c2b6af@mail.gmail.com> <616C9BC9-E172-434F-96E7-81F26AC2D1D4@meco.de> <8d961d900803170810y7d784cf9m1a4a0a9ea0afcd21@mail.gmail.com> <8d961d900803170937g3f388314t96b90db9c9da3fae@mail.gmail.com> <8DAA6697-1C79-4403-BACA-E09AD855BF3A@meco.de> <8d961d900803171154t39419a57y2f0a7f97a14b5dd5@mail.gmail.com> <36BF93CF-CD24-4843-A830-C66B00489B52@meco.de> Message-ID: <8d961d900803171414r600cd15ft5dbb8508c1758722@mail.gmail.com> On Mon, Mar 17, 2008 at 10:04 PM, Tobias Torkler wrote: > Issue is solved!!! > I had a require 'test/unit' in my spec_helper.rb. I removed it and it > works now. Good. That makes sense. Two competing exit hooks or something. I bet your Test::Unit output went away too. Aslak > > > Am 17.03.2008 um 20:08 schrieb Tobias Torkler: > > > > > That?s right, sorry! There was a call and it will be fixed in RC3. > > But you can checkout the sources (http://svn.codehaus.org/jruby/trunk/jruby/ > > ) and build the jruby.jar via ant. > > It will work then! > > > > I know it?s complicated, but I need this for my diploma thesis and I > > appreciate your help! > > > > > > Am 17.03.2008 um 19:54 schrieb aslak hellesoy: > > > >> On Mon, Mar 17, 2008 at 5:47 PM, Tobias Torkler >>> wrote: > >>> 1. Download http://eigenclass.org/static/rcov/rcov-0.8.1.2.tar.gz > >>> and > >>> extract the archive > >>> 2. jruby -S setup.rb all --without-ext > >>> 3. Change shebang of /bin/rcov to #!/usr/bin/env jruby > >>> 4. rcov script.rb should work now (warning appears, that no > >>> extensions > >>> are installed) > >>> > >> > >> Thanks, those installation instructions were useful. > >> > >> Unfortunately, I'm unable to run RCov 0.8.1.2 on JRuby 1.1.RC2 at > >> all: > >> > >> $ /usr/local/jruby-1.1RC2/bin/jruby -S rcov --version > >> Exception in thread "main" java.lang.RuntimeException: MethodBlock > >> does not have a static scope; this should not be called > >> at > >> org.jruby.runtime.MethodBlock.getStaticScope(MethodBlock.java:128) > >> at org.jruby.RubyModule.createProcMethod(RubyModule.java:1079) > >> ... > >> (lots more) > >> ... > >> at org.jruby.Main.main(Main.java:79) > >> > >> Can you recommend a JRuby version where RCov will actually start up? > >> > >> Aslak > >> > >>> > >>> Am 17.03.2008 um 17:37 schrieb aslak hellesoy: > >>> > >>> > >>> > >>>> On Mon, Mar 17, 2008 at 4:23 PM, Tobias Torkler >>>>> wrote: > >>>>> Ok, so the question is then why I don?t get an RCov report? Sorry > >>>>> for > >>>>> the "test run". Better call it an RSpec run? > >>>>> > >>>> > >>>> RSpec run is much clearer, thanks :-) > >>>> > >>>> I'm looking into the problem, but I'm struggling to install RCov > >>>> into > >>>> JRuby. I get the following error: > >>>> > >>>> $ /usr/local/jruby-1.1RC2/bin/jruby -S gem install rcov > >>>> Building native extensions. This could take a while... > >>>> extconf.rb:1: no such file to load -- mkmf (LoadError) > >>>> ERROR: Error installing rcov: > >>>> ERROR: Failed to build gem native extension. > >>>> > >>>> /usr/local/jruby-1.1RC2/bin/jruby extconf.rb install rcov > >>>> > >>>> > >>>> Gem files will remain installed in > >>>> /usr/local/jruby-1.1RC2/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0 for > >>>> inspection. > >>>> Results logged to > >>>> /usr/local/jruby-1.1RC2/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/ext/ > >>>> rcovrt/gem_make.out > >>>> > >>>> How did you install rcov bypassing the building of the C > >>>> extensions? > >>>> > >>>> Aslak > >>>>> > >>>>> Am 17.03.2008 um 16:10 schrieb aslak hellesoy: > >>>>> > >>>>> > >>>>> > >>>>>> On Mon, Mar 17, 2008 at 3:50 PM, Tobias Torkler >>>>>>> wrote: > >>>>>>> This is not Test::Unit output! > >>>>>> > >>>>>> The following text - taken from your first email - is Test::Unit > >>>>>> output. It is not RCov or RSpec output. > >>>>>> > >>>>>> ------------8<------------ > >>>>>> Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/rcov > >>>>>> Started > >>>>>> > >>>>>> Finished in 0.0080 seconds. > >>>>>> > >>>>>> 0 tests, 0 assertions, 0 failures, 0 errors > >>>>>> ------------8<------------ > >>>>>> > >>>>>>> As you can see I created a Rake task to run my specs and tried > >>>>>>> to > >>>>>>> integrate rcov as described on http://rspec.info/documentation/tools/rcov.html > >>>>>>> RSpec works as expected (187 examples, 0 failures, 10 pending) > >>>>>>> but I > >>>>>>> am missing the RCov report. > >>>>>>> > >>>>>> > >>>>>> In your first email you asked: Why is rcov started at the end of > >>>>>> the > >>>>>> test run? > >>>>>> I got confused about what you mean by "test run" (that usually > >>>>>> mean > >>>>>> Test::Unit run - and you do have Test::Unit output). > >>>>>> > >>>>>> Are you trying to figure out what order things are happening in, > >>>>>> or > >>>>>> are you trying to figure out why you're not getting an RCov > >>>>>> report? > >>>>>> > >>>>>> Aslak > >>>>>> > >>>>>>> > >>>>>>> Am 17.03.2008 um 15:43 schrieb aslak hellesoy: > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>>> On Mon, Mar 17, 2008 at 1:27 PM, Tobias Torkler >>>>>>>>> wrote: > >>>>>>>>> Hi, > >>>>>>>>> > >>>>>>>>> I am using JRuby (trunk) and wrote a bunch of specifications > >>>>>>>>> for my > >>>>>>>>> code. Everything works fine so far. > >>>>>>>>> Now I am trying to integrate RCov in my test run. I have > >>>>>>>>> installed > >>>>>>>>> RCov without the C extensions. I tried it with a simple script > >>>>>>>>> and it > >>>>>>>>> worked (pretty slow, but it doesn?t matter). > >>>>>>>>> But when I add the rcov options to my Rake task, RCov is not > >>>>>>>>> invoke > >>>>>>>>> properly! > >>>>>>>>> > >>>>>>>>> Rakefile: > >>>>>>>>> Spec::Rake::SpecTask.new('specs') do |t| > >>>>>>>>> t.spec_files = FileList['spec/**/*.rb'] > >>>>>>>>> t.rcov = true > >>>>>>>>> t.rcov_opts = ['--exclude', 'spec'] > >>>>>>>>> t.verbose = true > >>>>>>>>> end > >>>>>>>>> > >>>>>>>>> Output: > >>>>>>>>> ... > >>>>>>>>> Finished in 11.376 seconds > >>>>>>>>> > >>>>>>>>> 187 examples, 0 failures, 10 pending > >>>>>>>>> Loaded suite /Users/tobias/bin/JRuby.framework/Current/bin/ > >>>>>>>>> rcov > >>>>>>>>> Started > >>>>>>>>> > >>>>>>>>> Finished in 0.0080 seconds. > >>>>>>>>> > >>>>>>>>> 0 tests, 0 assertions, 0 failures, 0 errors > >>>>>>>>> > >>>>>>>> > >>>>>>>> This is Test::Unit output > >>>>>>>> > >>>>>>>>> Why is rcov started at the end of the test run? > >>>>>>>> > >>>>>>>> Did you mean: Why is Test::Unit started at the end of the RSpec > >>>>>>>> run? > >>>>>>>> > >>>>>>>> I'm not sure exactly what you're asking. > >>>>>>>> > >>>>>>>> Aslak > >>>>>>>> > >>>>>>>>> _______________________________________________ > >>>>>>>>> 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 ashley.moran at patchspace.co.uk Mon Mar 17 17:22:22 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 17 Mar 2008 21:22:22 +0000 Subject: [rspec-users] should have_tag outside Rails In-Reply-To: <60f3810c0803171141x196bf4dft1e9a8c1834cec44f@mail.gmail.com> References: <60f3810c0803171141x196bf4dft1e9a8c1834cec44f@mail.gmail.com> Message-ID: <40DB682C-E939-4591-875B-99BCAF9CAF49@patchspace.co.uk> On 17 Mar 2008, at 18:41, Kyle Hargraves wrote: > We discussed this in a ticket on lighthouse, and I ended up writing a > workalike that's sitting atop hpricot. It's not quite identical, but > generally close enough and so far does everything I've needed: > > http://github.com/pd/rspec_hpricot_matchers > > Patches and/or suggestions welcome if you need anything else out of it > > Kyle Hi Kyle That's brilliant! I looked for something but couldn't find anything. I did some work on it this afternoon and got as far as @elements.should have_tag("#selector", :count => 2) but didn't manage inner text comparisons or nested matchers. I'm unfamiliar with git - what's the best way to include that code in a Rails app stored in SVN? RTFM link to the git docs or similar welcome... When I've finished this contract I hope to spend some time working on open source code for story/runner selenium integration, if so I will definitely put anything relevant back into that matcher. Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080317/e3f914a6/attachment-0001.html From zach.dennis at gmail.com Mon Mar 17 18:17:38 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 17 Mar 2008 18:17:38 -0400 Subject: [rspec-users] should have_tag outside Rails In-Reply-To: <40DB682C-E939-4591-875B-99BCAF9CAF49@patchspace.co.uk> References: <60f3810c0803171141x196bf4dft1e9a8c1834cec44f@mail.gmail.com> <40DB682C-E939-4591-875B-99BCAF9CAF49@patchspace.co.uk> Message-ID: <85d99afe0803171517o30d8b22cu7a87332639753078@mail.gmail.com> http://git.or.cz/course/svn.html and also search google for "git for svn users" Zach On Mon, Mar 17, 2008 at 5:22 PM, Ashley Moran wrote: > > > > On 17 Mar 2008, at 18:41, Kyle Hargraves wrote: > We discussed this in a ticket on lighthouse, and I ended up writing a > workalike that's sitting atop hpricot. It's not quite identical, but > generally close enough and so far does everything I've needed: > > http://github.com/pd/rspec_hpricot_matchers > > Patches and/or suggestions welcome if you need anything else out of it > > Kyle > > Hi Kyle > > That's brilliant! I looked for something but couldn't find anything. I did > some work on it this afternoon and got as far as > > @elements.should have_tag("#selector", :count => 2) > > but didn't manage inner text comparisons or nested matchers. > > I'm unfamiliar with git - what's the best way to include that code in a > Rails app stored in SVN? RTFM link to the git docs or similar welcome... > > When I've finished this contract I hope to spend some time working on open > source code for story/runner selenium integration, if so I will definitely > put anything relevant back into that matcher. > > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com From davids at tower-mt.com Tue Mar 18 04:15:50 2008 From: davids at tower-mt.com (David Schmidt) Date: Tue, 18 Mar 2008 01:15:50 -0700 Subject: [rspec-users] "Why not MockEverthing" or why use fixtures for all tests? Message-ID: Hello fellow RSpec users. Before you all start warming up your flame throwers please let me explain my Subject line. I've been working over 4 months on a large Rails project with a few other developers. Test coverage was spotty at best, though they *were* RSpec tests. One of the other developers and I had started adding more tests, mostly controller tests using the methodology given at rspec.info for writing controller tests isolated from the model and view layers using stubs and mocks. Recently a new project manager was put in place and he brought in another developer. This developer promptly started to re-write all the *existing* controller (and later view) tests, removing all mocks and stubs and replacing them with code to use fixtures. (He also deletes many comments he finds in the code if *he* thinks they're obvious, but that's another story...). His commit messages include comments like "Stop mocking around" and "More fixes due to our test mockery". When challenged on why he's re-writing these tests instead of writing new, missing tests (even tests using fixtures) he replied with this e- mail with the subject "Why not MockEverything". (Note that I *do* use fixtures for model tests but follow the RSpec documentation and use mocks/stubs for controller and view tests for isolation.) In the email this developer mentions tests broken by the addition of conditional to the view. This conditional used a model method not previously used in the view, and the addition of one stub was sufficient to fix the view test in question. Here is his email to me, less his signature as I don't want to make this personal. I'd like to see what the RSpec user community has to say in response to his comments, below: --- Why not MockEverything --- David I've removed the mocks on purpuse. Not that I have sufficient ills with them to meddle without a *need*. We committed simple template fixes adding a conditional and there, yet the tests broke. Now this was to be expected, the tests were constructed by exhaustively mocking out all methods called on the object. Add a simple conditional be it harmless as it is now means another method needs to be mocked out. The MockEverything approach is not healthy, judicious use is preferable. One thing is to write a short sample in a blog and another is to have a working app with lots of tests. From all my apps that I have worked on this has by far the lowest coverage both in profile and in test value. There is no discussion we are all committed to tests. To better see what constitutes good practice I recommend you to inspect the source of RadiantCMS a beautiful and well engineered app recently rewrote to use rspec instead of Test::Unit: http://dev.radiantcms.org/browser/trunk/radiant/spec Observe how the code is restrained in mocking, real objects are preferred wherever possible. Incidentally they don't use fixtures rather factories to create *real* objects. Now the factory part is a separate issue I'll don't discuss here, as it has its own disadvantages especially a project with many models ... With real objects your test will not be brittle, and their value will be kept even after adjusting the templates or doing other small refactorings. Contrary to common misconception test speed will not be affected either. Especially for view tests where you don't even have to save to the db upon preparing the test rig. Beside Radiant there where efforts to rspec Typo and Mephisto (both noted rails blog engines). Still these were half harted conversions so my arguments based on them would not have the same weight. RadiantCMS is enough - they are used on ruby-lang.org and have converted 100% to rspec ... plus they also have good coverage showing that they actually believe in tests. So please look into Radiant, you'll find it most helpful I think. --- END OF EMAIL--- Thank you, David Schmidt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080318/88dce0fe/attachment.html From chris at edendevelopment.co.uk Tue Mar 18 06:04:37 2008 From: chris at edendevelopment.co.uk (Chris Parsons) Date: Tue, 18 Mar 2008 10:04:37 +0000 Subject: [rspec-users] "Why not MockEverthing" or why use fixtures for all tests? In-Reply-To: References: Message-ID: <54C5C719-0E53-4BEA-A904-A041DBDDB3F6@edendevelopment.co.uk> Hi David On 18 Mar 2008, at 08:15, David Schmidt wrote: > Here is his email to me, less his signature as I don't want to make > this personal. I'd like to see what the RSpec user community has to > say in response to his comments, below: [snip email] For me, it basically boils down to: use whichever is appropriate for what you're testing, as long as it provides good coverage and makes the tests easy to write. If the tests are hard to write, and you're mocking/stubbing all over the place, it's a smell that your implementation is probably not loosely coupled enough - perhaps you need to refactor. Mocks are a very useful testing construct, but using them religiously everywhere is as bad as not using them religiously, IMHO. Have you read Mocks aren't Stubs[1]? It's a very good treatise on the advantages and disadvantages of using mocks in testing. Pat Maddox also wrote an article on this subject recently that I found very helpful[2]. Thanks Chris [1] http://martinfowler.com/articles/mocksArentStubs.html [2] http://evang.eli.st/blog/2008/2/3/it-s-not-about-state-or-interactions-it-s-about-behavior From dchelimsky at gmail.com Tue Mar 18 08:45:06 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Mar 2008 07:45:06 -0500 Subject: [rspec-users] "Why not MockEverthing" or why use fixtures for all tests? In-Reply-To: <54C5C719-0E53-4BEA-A904-A041DBDDB3F6@edendevelopment.co.uk> References: <54C5C719-0E53-4BEA-A904-A041DBDDB3F6@edendevelopment.co.uk> Message-ID: <57c63afe0803180545w5d57e465tc073864e7f68a261@mail.gmail.com> On Tue, Mar 18, 2008 at 5:04 AM, Chris Parsons wrote: > Hi David > > > On 18 Mar 2008, at 08:15, David Schmidt wrote: > > > Here is his email to me, less his signature as I don't want to make > > this personal. I'd like to see what the RSpec user community has to > > say in response to his comments, below: > > [snip email] > > For me, it basically boils down to: use whichever is appropriate for > what you're testing, as long as it provides good coverage and makes > the tests easy to write. If the tests are hard to write, and you're > mocking/stubbing all over the place, it's a smell that your > implementation is probably not loosely coupled enough - perhaps you > need to refactor. > > Mocks are a very useful testing construct, but using them religiously > everywhere is as bad as not using them religiously, IMHO. > > Have you read Mocks aren't Stubs[1]? It's a very good treatise on the > advantages and disadvantages of using mocks in testing. Pat Maddox > also wrote an article on this subject recently that I found very > helpful[2]. I agree wholeheartedly! I'd also recommend Mock Roles, Not Objects[3] When I'm spec'ing views, for example, I tend to follow this path: 1. start with an expectation, watch it fail 2. get it to pass with hard-coded values in the view 3. replace the hard-coded view code with the code I wish I had[4] 4. mock/stub whatever I need at the time in the example to get it to pass This last step varies depending on the state of the system. If the model class I want doesn't exist, I use a mock object. If it does exist, I'll use stub_model[5] to provide isolation from the db, but allow the real model code to be invoked. If I used a mock to begin with, I may switch it later. The point is that while I'm in the view I want to stay focused on the view. FWIW. Cheers, David [3] jmock.org/oopsla2004.pdf [4] Writing "the code I wish I had" is something I learned from James Grenning at Object Mentor. [5] stub_model is a new method in git - will be released with 1.1.4. It creates a real model instance and prevents database access a la unit_record (but on an instance by instance basis). This allows you to reap the benefit of isolation from the db while reducing the false positives that concern so many with using mocks in Ruby. > > Thanks > Chris > > [1] http://martinfowler.com/articles/mocksArentStubs.html > [2] http://evang.eli.st/blog/2008/2/3/it-s-not-about-state-or-interactions-it-s-about-behavior > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Tue Mar 18 09:20:56 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 18 Mar 2008 13:20:56 +0000 Subject: [rspec-users] should have_tag outside Rails In-Reply-To: <85d99afe0803171517o30d8b22cu7a87332639753078@mail.gmail.com> References: <60f3810c0803171141x196bf4dft1e9a8c1834cec44f@mail.gmail.com> <40DB682C-E939-4591-875B-99BCAF9CAF49@patchspace.co.uk> <85d99afe0803171517o30d8b22cu7a87332639753078@mail.gmail.com> Message-ID: On 17/03/2008, Zach Dennis wrote: > > http://git.or.cz/course/svn.html > > and also search google for "git for svn users" > > Zach Ta - I ended up doing a git clone into our SVN repo. Not sure if that's a good idea but seems to work... Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080318/90eb0e54/attachment.html From alan.larkin at gmail.com Tue Mar 18 09:36:50 2008 From: alan.larkin at gmail.com (Alan Larkin) Date: Tue, 18 Mar 2008 13:36:50 +0000 Subject: [rspec-users] "Why not MockEverthing" or why use fixtures for all tests? In-Reply-To: References: Message-ID: <47DFC572.2070802@gmail.com> David Schmidt wrote: > Hello fellow RSpec users. > > Before you all start warming up your flame throwers please let me > explain my Subject line. > > I've been working over 4 months on a large Rails project with a few > other developers. Test coverage was spotty at best, though they *were* > RSpec tests. One of the other developers and I had started adding more > tests, mostly controller tests using the methodology given at rspec.info > for writing controller tests isolated from the model and view layers > using stubs and mocks. > > Recently a new project manager was put in place and he brought in > another developer. This developer promptly started to re-write all the > *existing* controller (and later view) tests, removing all mocks and > stubs and replacing them with code to use fixtures. (He also deletes > many comments he finds in the code if *he* thinks they're obvious, but > that's another story...). His commit messages include comments > like "Stop mocking around" and "More fixes due to our test mockery". > > When challenged on why he's re-writing these tests instead of writing > new, missing tests (even tests using fixtures) he replied with this > e-mail with the subject "Why not MockEverything". (Note that I *do* use > fixtures for model tests but follow the RSpec documentation and use > mocks/stubs for controller and view tests for isolation.) In the email > this developer mentions tests broken by the addition of conditional to > the view. This conditional used a model method not previously used in > the view, and the addition of one stub was sufficient to fix the view > test in question. > > Here is his email to me, less his signature as I don't want to make this > personal. I'd like to see what the RSpec user community has to say in > response to his comments, below: > > --- Why not MockEverything --- > David I've removed the mocks on purpuse. Not that I have sufficient ills > with them to meddle without a *need*. We committed simple template fixes > adding a conditional and there, yet the tests broke. > > Now this was to be expected, the tests were constructed by exhaustively > mocking out all methods called on the object. Add a simple conditional > be it harmless as it is now means another method needs to be mocked out. > > The MockEverything approach is not healthy, judicious use is preferable. > One thing is to write a short sample in a blog and another is to have a > working app with lots of tests. From all my apps that I have worked on > this has by far the lowest coverage both in profile and in test value. > There is no discussion we are all committed to tests. > > To better see what constitutes good practice I recommend you to > inspect the source of RadiantCMS a beautiful and well engineered app > recently rewrote to use rspec instead of Test::Unit: > > http://dev.radiantcms.org/browser/trunk/radiant/spec > > Observe how the code is restrained in mocking, real objects are > preferred wherever possible. Incidentally they don't use fixtures rather > factories to create *real* objects. Now the factory part is a separate > issue I'll don't discuss here, as it has its own disadvantages > especially a project with many models ... > > With real objects your test will not be brittle, and their value will be > kept even after adjusting the templates or doing other small refactorings. > Contrary to common misconception test speed will not be affected either. > Especially for view tests where you don't even have to save to the db > upon preparing the test rig. > > Beside Radiant there where efforts to rspec Typo and Mephisto (both > noted rails blog engines). Still these were half harted conversions so > my arguments based on them would not have the same weight. RadiantCMS is > enough - they are used on ruby-lang.org and have converted 100% to > rspec ... plus they also have good coverage showing that they actually > believe in tests. So please look into Radiant, you'll find it most > helpful I think. > --- END OF EMAIL--- > > Thank you, > > David Schmidt > > > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users I was going to start a thread about mocks and fixtures this morning too, so Ill use this one. Let me first say that I am a very very recent comer to RSpec so my opinions dont carry much weight, but ... I have come to the tentative conclusion that mocking is fine in view specs where you are really only interested that certain assigns have been made and that they respond to certain messages. In fact mocks are ideal. Possibly in models too. However in controller specs I think you find examples where fixtures are just the best way to go. In these cases, from what I have seen, mocking leads to brittle and frankly worthless tests (a half-arsed test is worse than no test at all, right?). The case that crystalised that opinion for me was a spec for a destroy action. In spec::rails scaffold (and in many examples I see online) this action is tested by asserting that the instance receives a destroy message. I personally think thats inadequate. It makes assumptions about implementation and doesnt guard against unwanted side effects. I should be able to delete a record any way I please (delete, destroy, connection().execute(...)) and the test should pass. This is BDD after all. We should be testing the behaviour of the action, not the implementation, and the desired behaviour is that the corresponding record *and only that record* are deleted ... no one cares how its achieved. The only correct way to test this IMHO is to assert that TheModel.find(:all) before the action is equal to TheModel.find(:all) after the action less the record in question. For this I see fixtures as the way to go. Just my opinion. Commence flaming. From lists at ruby-forum.com Tue Mar 18 09:39:20 2008 From: lists at ruby-forum.com (Max Williams) Date: Tue, 18 Mar 2008 14:39:20 +0100 Subject: [rspec-users] rspec groups? In-Reply-To: <9D7BCC9A-19DD-44D5-AED5-255A3B000E82@gmail.com> References: <57c63afe0803080811l5b4b1e76vae9e234d45eb0ee3@mail.gmail.com> <9D7BCC9A-19DD-44D5-AED5-255A3B000E82@gmail.com> Message-ID: <41ce87db9cc6908ea07e975d6b850d52@ruby-forum.com> James Deville wrote: > Using the -e option from the command line, you can also specify a > string which is to be run, this is a way to run only one describe > block, or one it block. The rake task method suggested by Edvard is > the other option I'm having problems with the -e option - it doesn't recognise the string and so runs no tests. I have several nested describe blocks, and i want to run one of the top-level ones: describe "add_descendants_from_xml" do before do ... ... end I'm trying to run just this block like so: ruby script/spec spec/models/property_spec.rb --format specdoc -c -e "add_descendants_from_xml" (the linebreak after -e isn't in my command, it's just split to fit this text field) And it runs 0 tests. Can anyone tell me what i'm doing wrong? thanks max -- Posted via http://www.ruby-forum.com/. From ashley.moran at patchspace.co.uk Tue Mar 18 10:04:14 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 18 Mar 2008 14:04:14 +0000 Subject: [rspec-users] should have_tag outside Rails In-Reply-To: <60f3810c0803171141x196bf4dft1e9a8c1834cec44f@mail.gmail.com> References: <60f3810c0803171141x196bf4dft1e9a8c1834cec44f@mail.gmail.com> Message-ID: On 17/03/2008, Kyle Hargraves wrote: > > We discussed this in a ticket on lighthouse, and I ended up writing a > workalike that's sitting atop hpricot. It's not quite identical, but > generally close enough and so far does everything I've needed: > > http://github.com/pd/rspec_hpricot_matchers > > Patches and/or suggestions welcome if you need anything else out of it > > Kyle Hi Kyle Really impressed with that! Seems to be working ok in our app, only starting to use it though. Here's how I got it working in Rails: git clone into RAILS_ROOT/lib However you are using a require that depends on rspec_hpricot_matchers/lib being in the load path, so for now I added this to spec_helper: rspec_hpricot_matcher_lib_path = File.expand_path( File.join(RAILS_ROOT, "/lib/rspec_hpricot_matchers/lib")) $:.unshift(rspec_hpricot_matcher_lib_path) unless $:.include?(rspec_hpricot_matcher_lib_path) I could have changed the line: require 'rspec_hpricot_matchers/have_tag' to something like (untested): File.expand_path( File.join(File.dirname(__FILE__), "/rspec_hpricot_matchers/lib")) so it would work from any location - but I wasn't sure how to get the patch back from git. I also found it's pretty easy to replace the RSpec assert_select wrapper: module Spec::Rails module Matchers undef_method :have_tag, :with_tag, :without_tag, :with_encoded end module Example class RailsExampleGroup include RspecHpricotMatchers end end end Already rolling this out across the developers here, everyone seems pretty positive about it. Any chance this will make it into RSpec, David? Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080318/e96ca2b2/attachment.html From rick.denatale at gmail.com Tue Mar 18 10:11:28 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 18 Mar 2008 10:11:28 -0400 Subject: [rspec-users] Branching scenarios, GivenScenario and database In-Reply-To: References: <57c63afe0803160243t2d007787jcda3599543401c98@mail.gmail.com> Message-ID: On 3/17/08, Rick DeNatale wrote: > [quite a lot] Okay, I've got it working now. The problem seems to be wrapped up in the use of transactional fixtures to load the db, and the fact that fixture teardown actually happens in the SETUP phase, in other words when you declare a fixture in Rails, it first deletes all records from any tables with declared fixtures, and then loads the fixtures. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From philodespotos at gmail.com Tue Mar 18 15:38:39 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Tue, 18 Mar 2008 14:38:39 -0500 Subject: [rspec-users] should have_tag outside Rails In-Reply-To: References: <60f3810c0803171141x196bf4dft1e9a8c1834cec44f@mail.gmail.com> Message-ID: <60f3810c0803181238p7b2b7cbdv91c70a8882dad99@mail.gmail.com> On Tue, Mar 18, 2008 at 9:04 AM, Ashley Moran wrote: > On 17/03/2008, Kyle Hargraves wrote: > > > We discussed this in a ticket on lighthouse, and I ended up writing a > > workalike that's sitting atop hpricot. It's not quite identical, but > > generally close enough and so far does everything I've needed: > > > > http://github.com/pd/rspec_hpricot_matchers > > > > Patches and/or suggestions welcome if you need anything else out of it > > > > Kyle > > Hi Kyle > > Really impressed with that! Seems to be working ok in our app, only > starting to use it though. Here's how I got it working in Rails: I personally just toss things into vendor/gems, and add something along these lines to environment.rb: config.load_paths += Dir[File.join('vendor', 'gems', '*', 'lib')].map do |libdir| File.expand_path(libdir) end This'll let it be loaded as a gem and you can put this in spec_helper: require 'rspec_hpricot_matchers' Spec::Runner.configure do |config| config.include(RspecHpricotMatchers) end I really like your undef magic for disabling the rspec_on_rails matchers; hadn't thought of doing that. One problem you will run into, I'm sure, is nested expectation failure messages: body.should have_tag('ul') do |ul| ul.should have_tag('li') end Fails with "expected body to have tag 'ul'", even if it's the inner 'li' that was missing. I haven't come up with a good way to fix this, but it's very annoying! Kyle From james.deville at gmail.com Tue Mar 18 18:58:00 2008 From: james.deville at gmail.com (James Deville) Date: Tue, 18 Mar 2008 15:58:00 -0700 Subject: [rspec-users] "Why not MockEverthing" or why use fixtures for all tests? In-Reply-To: <47DFC572.2070802@gmail.com> References: <47DFC572.2070802@gmail.com> Message-ID: <41BDB1CD-19FB-479A-9F7D-EAAF3F2A865D@gmail.com> On Mar 18, 2008, at 6:36 AM, Alan Larkin wrote: > David Schmidt wrote: >> Hello fellow RSpec users. >> >> Before you all start warming up your flame throwers please let me >> explain my Subject line. >> >> I've been working over 4 months on a large Rails project with a few >> other developers. Test coverage was spotty at best, though they >> *were* >> RSpec tests. One of the other developers and I had started adding >> more >> tests, mostly controller tests using the methodology given at >> rspec.info >> for writing controller tests isolated from the model and view layers >> using stubs and mocks. >> >> Recently a new project manager was put in place and he brought in >> another developer. This developer promptly started to re-write all >> the >> *existing* controller (and later view) tests, removing all mocks and >> stubs and replacing them with code to use fixtures. (He also deletes >> many comments he finds in the code if *he* thinks they're obvious, >> but >> that's another story...). His commit messages include comments >> like "Stop mocking around" and "More fixes due to our test mockery". >> >> When challenged on why he's re-writing these tests instead of writing >> new, missing tests (even tests using fixtures) he replied with this >> e-mail with the subject "Why not MockEverything". (Note that I >> *do* use >> fixtures for model tests but follow the RSpec documentation and use >> mocks/stubs for controller and view tests for isolation.) In the >> email >> this developer mentions tests broken by the addition of conditional >> to >> the view. This conditional used a model method not previously used >> in >> the view, and the addition of one stub was sufficient to fix the view >> test in question. >> >> Here is his email to me, less his signature as I don't want to make >> this >> personal. I'd like to see what the RSpec user community has to say in >> response to his comments, below: >> >> --- Why not MockEverything --- >> David I've removed the mocks on purpuse. Not that I have sufficient >> ills >> with them to meddle without a *need*. We committed simple template >> fixes >> adding a conditional and there, yet the tests broke. >> >> Now this was to be expected, the tests were constructed by >> exhaustively >> mocking out all methods called on the object. Add a simple >> conditional >> be it harmless as it is now means another method needs to be mocked >> out. >> >> The MockEverything approach is not healthy, judicious use is >> preferable. >> One thing is to write a short sample in a blog and another is to >> have a >> working app with lots of tests. From all my apps that I have worked >> on >> this has by far the lowest coverage both in profile and in test >> value. >> There is no discussion we are all committed to tests. >> >> To better see what constitutes good practice I recommend you to >> inspect the source of RadiantCMS a beautiful and well engineered app >> recently rewrote to use rspec instead of Test::Unit: >> >> http://dev.radiantcms.org/browser/trunk/radiant/spec >> >> Observe how the code is restrained in mocking, real objects are >> preferred wherever possible. Incidentally they don't use fixtures >> rather >> factories to create *real* objects. Now the factory part is a >> separate >> issue I'll don't discuss here, as it has its own disadvantages >> especially a project with many models ... >> >> With real objects your test will not be brittle, and their value >> will be >> kept even after adjusting the templates or doing other small >> refactorings. >> Contrary to common misconception test speed will not be affected >> either. >> Especially for view tests where you don't even have to save to the db >> upon preparing the test rig. >> >> Beside Radiant there where efforts to rspec Typo and Mephisto (both >> noted rails blog engines). Still these were half harted conversions >> so >> my arguments based on them would not have the same weight. >> RadiantCMS is >> enough - they are used on ruby-lang.org and have converted 100% to >> rspec ... plus they also have good coverage showing that they >> actually >> believe in tests. So please look into Radiant, you'll find it most >> helpful I think. >> --- END OF EMAIL--- >> >> Thank you, >> >> David Schmidt >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > I was going to start a thread about mocks and fixtures this morning > too, so Ill > use this one. > > Let me first say that I am a very very recent comer to RSpec so my > opinions dont > carry much weight, but ... > > I have come to the tentative conclusion that mocking is fine in view > specs where > you are really only interested that certain assigns have been made > and that they > respond to certain messages. In fact mocks are ideal. Possibly in > models too. > However in controller specs I think you find examples where fixtures > are just > the best way to go. In these cases, from what I have seen, mocking > leads to > brittle and frankly worthless tests (a half-arsed test is worse than > no test at > all, right?). > > The case that crystalised that opinion for me was a spec for a > destroy action. > In spec::rails scaffold (and in many examples I see online) this > action is > tested by asserting that the instance receives a destroy message. I > personally > think thats inadequate. It makes assumptions about implementation > and doesnt > guard against unwanted side effects. > > I should be able to delete a record any way I please (delete, destroy, > connection().execute(...)) and the test should pass. However, each of those have different behaviour, and that is what I am spec'ing when I do model.should_receive(:destroy) James Deville > This is BDD after all. We > should be testing the behaviour of the action, not the > implementation, and the > desired behaviour is that the corresponding record *and only that > record* are > deleted ... no one cares how its achieved. The only correct way to > test this > IMHO is to assert that TheModel.find(:all) before the action is > equal to > TheModel.find(:all) after the action less the record in question. > For this I see > fixtures as the way to go. > > Just my opinion. Commence flaming. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ashley.moran at patchspace.co.uk Tue Mar 18 18:58:53 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 18 Mar 2008 22:58:53 +0000 Subject: [rspec-users] should have_tag outside Rails In-Reply-To: <60f3810c0803181238p7b2b7cbdv91c70a8882dad99@mail.gmail.com> References: <60f3810c0803171141x196bf4dft1e9a8c1834cec44f@mail.gmail.com> <60f3810c0803181238p7b2b7cbdv91c70a8882dad99@mail.gmail.com> Message-ID: <347EB557-DD87-470B-9565-DDC2D99DDFA0@patchspace.co.uk> On 18 Mar 2008, at 19:38, Kyle Hargraves wrote: > config.load_paths += Dir[File.join('vendor', 'gems', '*', > 'lib')].map do |libdir| > File.expand_path(libdir) > end > > This'll let it be loaded as a gem and you can put this in spec_helper: > > require 'rspec_hpricot_matchers' > Spec::Runner.configure do |config| > config.include(RspecHpricotMatchers) > end Ah that's neater than my way. Forgot about the Rails load path. Don't use rails regularly enough to memorise all these tricks... > I really like your undef magic for disabling the rspec_on_rails > matchers; hadn't thought of doing that. > > One problem you will run into, I'm sure, is nested expectation > failure messages: > > body.should have_tag('ul') do |ul| > ul.should have_tag('li') > end > > Fails with "expected body to have tag 'ul'", even if it's the inner > 'li' that was missing. I haven't come up with a good way to fix this, > but it's very annoying! Yep that one caught me! I'd like a neater solution too, not sure how though. Just had a look at the code and it doesn't look easy. Because RSpec raises exceptions on your behalf when a match fails, you only get chance to set the message and not tag any extra information on there. Short of a really ugly hack, the only way round this I can see would be extend RSpec's ExpectationMatcherHandler and Expectation to support retrieving another object from the matcher to go with failure_message (maybe failure_data). Then you could collect those as the exceptions bubble up to the top level matcher. Or for a kludge you could subclass HpricotMatcherString < String, attach the failures to it and pass instances of that up as failure messages instead of plain strings. Nasty nasty nasty, but it would give you everthing you need to generate a detailed message at the top. Ashley From ashley.moran at patchspace.co.uk Tue Mar 18 19:12:51 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 18 Mar 2008 23:12:51 +0000 Subject: [rspec-users] rspec groups? In-Reply-To: References: <57c63afe0803080811l5b4b1e76vae9e234d45eb0ee3@mail.gmail.com> Message-ID: <14FBB390-36F0-44F2-A2CC-15F40058108D@patchspace.co.uk> On 10 Mar 2008, at 12:42, Edvard Majakari wrote: > Being able to choose which > contexts/describes or individual specs will be run has been more than > sufficient to me, but of course, YNMDFTOM. Hi Edvard Sorry for the delayed reaction, but was just catching up on old posts and saw this. I googled for "YNMDFTOM" and apparently this mailing list contains the only use of it in the known universe. Please put me out of my misery and explain the acronym :D Ashley From lists at ruby-forum.com Tue Mar 18 19:26:20 2008 From: lists at ruby-forum.com (Nikos Dimitrakopoulos) Date: Wed, 19 Mar 2008 00:26:20 +0100 Subject: [rspec-users] Problem with mocking a simple has_many relationship Message-ID: <05b3e0b5063629cdf3532be4cf5d298b@ruby-forum.com> Hi there all. Sorry if the question sounds silly but i'm rather new at the 'mocking' stuff... So here is my problem (code helps more than talking): the model: class Item < ActiveRecord::Base ... has_many :images, :dependent => :destroy ... protected def validate errors.add(:images, "cannot be empty") if self.images.count end end the spec: describe Item do before(:each) do @item = Item.new end ... it "should have at least one image" do @item.should have(1).error_on(:images) @item.images.should_receive(:count).at_least(:once).and_return(1) @item.should have(0).errors_on(:images) end end Obviously i'm doing something wrong cause this doesn't work: 1) 'Item should have at least one image' FAILED expected 0 errors on :images, got 1 ./spec/models/item_spec.rb:60: script/spec:4: Finished in 0.341594 seconds 10 examples, 1 failure, 5 pending (ignore the rest) Any help would be more than welcome :) -- Posted via http://www.ruby-forum.com/. From james.deville at gmail.com Tue Mar 18 19:37:56 2008 From: james.deville at gmail.com (James Deville) Date: Tue, 18 Mar 2008 16:37:56 -0700 Subject: [rspec-users] Problem with mocking a simple has_many relationship In-Reply-To: <05b3e0b5063629cdf3532be4cf5d298b@ruby-forum.com> References: <05b3e0b5063629cdf3532be4cf5d298b@ruby-forum.com> Message-ID: <0BABADD6-1001-4759-AA98-5DF5836A49A8@gmail.com> On Mar 18, 2008, at 4:26 PM, Nikos Dimitrakopoulos wrote: > Hi there all. Sorry if the question sounds silly but i'm rather new at > the 'mocking' stuff... So here is my problem (code helps more than > talking): > > the model: > > class Item < ActiveRecord::Base > ... > has_many :images, :dependent => :destroy > ... > > protected > > def validate > errors.add(:images, "cannot be empty") if self.images.count > end > end > > > the spec: > > describe Item do > before(:each) do > @item = Item.new > end > > ... > > it "should have at least one image" do > @item.should have(1).error_on(:images) > @item.images.should_receive(:count).at_least(:once).and_return(1) > @item.should have(0).errors_on(:images) > end > end > I would try: it "should have an error with no images" do @item.should have(1).error_on(:images) end it "should be okay with one image" do @item.stub!(:images).and_return(mock("images",:count => 1)) @item.should have(0).errors_on(:images) end JD > > Obviously i'm doing something wrong cause this doesn't work: > > 1) > 'Item should have at least one image' FAILED > expected 0 errors on :images, got 1 > ./spec/models/item_spec.rb:60: > script/spec:4: > > Finished in 0.341594 seconds > > 10 examples, 1 failure, 5 pending > > (ignore the rest) > > Any help would be more than welcome :) > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mueller182 at gmail.com Tue Mar 18 19:38:17 2008 From: mueller182 at gmail.com (Rafael Mueller) Date: Tue, 18 Mar 2008 20:38:17 -0300 Subject: [rspec-users] Problem with mocking a simple has_many relationship In-Reply-To: <05b3e0b5063629cdf3532be4cf5d298b@ruby-forum.com> References: <05b3e0b5063629cdf3532be4cf5d298b@ruby-forum.com> Message-ID: <89af23f20803181638v6e433f9ep491a6675a398e0@mail.gmail.com> Hi Nikos, On Tue, Mar 18, 2008 at 8:26 PM, Nikos Dimitrakopoulos wrote: > > the model: > class Item < ActiveRecord::Base > has_many :images, :dependent => :destroy > protected > def validate > errors.add(:images, "cannot be empty") if self.images.count > end > end self.images.count is always true, the Fixnum 0 (returned when theres no images) is true try on irb: foo = "bar" if [].size I guess the correct way is errors.add(:images, "cannot be empty") if self.images.size < 1 Regards, -- Rafael Mueller http://queroseragil.wordpress.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080318/18dfec24/attachment.html From james.deville at gmail.com Tue Mar 18 19:47:14 2008 From: james.deville at gmail.com (James Deville) Date: Tue, 18 Mar 2008 16:47:14 -0700 Subject: [rspec-users] Problem with mocking a simple has_many relationship In-Reply-To: <89af23f20803181638v6e433f9ep491a6675a398e0@mail.gmail.com> References: <05b3e0b5063629cdf3532be4cf5d298b@ruby-forum.com> <89af23f20803181638v6e433f9ep491a6675a398e0@mail.gmail.com> Message-ID: <8ADCC834-76AB-4541-A4B1-F72F1A0CCD85@gmail.com> Doh! I can't believe that I missed that. You can also use if self.images.size.zero? Just a little more readable. James Deville On Mar 18, 2008, at 4:38 PM, Rafael Mueller wrote: > Hi Nikos, > > > On Tue, Mar 18, 2008 at 8:26 PM, Nikos Dimitrakopoulos > wrote: > > the model: > class Item < ActiveRecord::Base > has_many :images, :dependent => :destroy > protected > def validate > errors.add(:images, "cannot be empty") if self.images.count > end > end > > self.images.count is always true, the Fixnum 0 (returned when theres > no images) is true > > try on irb: foo = "bar" if [].size > > I guess the correct way is errors.add(:images, "cannot be empty") if > self.images.size < 1 > > Regards, > -- > Rafael Mueller > http://queroseragil.wordpress.com > _______________________________________________ > 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/20080318/1b9f6552/attachment.html From lists at ruby-forum.com Tue Mar 18 19:48:05 2008 From: lists at ruby-forum.com (Nikos Dimitrakopoulos) Date: Wed, 19 Mar 2008 00:48:05 +0100 Subject: [rspec-users] Problem with mocking a simple has_many relationship In-Reply-To: <0BABADD6-1001-4759-AA98-5DF5836A49A8@gmail.com> References: <05b3e0b5063629cdf3532be4cf5d298b@ruby-forum.com> <0BABADD6-1001-4759-AA98-5DF5836A49A8@gmail.com> Message-ID: <01693bada3d9b3141a330bad7d305697@ruby-forum.com> Ok, i'm really stupid... i was taking a break (i've been on the pc for several hours) and the problem came to me before reading your posts :D Obviously the "if self.images.count" was waaaayyy too stupid! added the necessary == 0 and everything is fine... Thanks a lot anyway :) -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Mar 18 19:49:24 2008 From: lists at ruby-forum.com (Nikos Dimitrakopoulos) Date: Wed, 19 Mar 2008 00:49:24 +0100 Subject: [rspec-users] Problem with mocking a simple has_many relationship In-Reply-To: <8ADCC834-76AB-4541-A4B1-F72F1A0CCD85@gmail.com> References: <05b3e0b5063629cdf3532be4cf5d298b@ruby-forum.com> <89af23f20803181638v6e433f9ep491a6675a398e0@mail.gmail.com> <8ADCC834-76AB-4541-A4B1-F72F1A0CCD85@gmail.com> Message-ID: James Deville wrote: > Doh! I can't believe that I missed that. > > You can also use if self.images.size.zero? > > Just a little more readable. > > James Deville You were writing while i was writing :D nice one, i didn't know the #zero? - way more readable :) -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Mar 18 20:04:10 2008 From: lists at ruby-forum.com (Nikos Dimitrakopoulos) Date: Wed, 19 Mar 2008 01:04:10 +0100 Subject: [rspec-users] Problem with mocking a simple has_many relationship In-Reply-To: References: <05b3e0b5063629cdf3532be4cf5d298b@ruby-forum.com> <89af23f20803181638v6e433f9ep491a6675a398e0@mail.gmail.com> <8ADCC834-76AB-4541-A4B1-F72F1A0CCD85@gmail.com> Message-ID: Ok, last one - for your interest validates_length_of can be used for this purpose. There is an open bug/patch on the rails trac regarding the :within parameter but the :minimum works fine for me. As for the example the method called on @item.images is #size and not #count so -> @item.images.should_receive(:size).and_return(1) P.S.: The bug on the rails trac: http://dev.rubyonrails.org/ticket/11295 -- Posted via http://www.ruby-forum.com/. From dsisnero at gmail.com Tue Mar 18 21:41:43 2008 From: dsisnero at gmail.com (Dominic Sisneros) Date: Tue, 18 Mar 2008 19:41:43 -0600 Subject: [rspec-users] svn externals and git submodules Message-ID: This is a request to split up the repository into at least two repositories rspec rspec_core (loaded as svn_external or git submodule) rspec_on_rails (loaded as svn_external or git submodule) We could load the plugins the same way as before ruby script/plugin install http://rspec.rubyforge.org/svn/trunk/rspec_core ruby script/plugin install http://rspec.rubyforge.org/svn/trunk/rspec_on_rails but it would be easier to install from git using git submodules using git and calling from RAILS_ROOT git submodule add git//github.com/dchelimsky/rspec_on_rails.git vendor/plugins/rspec_on_rails git submodule add git//github.com/dchelimsky/rspec_core.git vendor/plugins/rspec -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080318/902561ca/attachment.html From dchelimsky at gmail.com Tue Mar 18 22:31:10 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 18 Mar 2008 21:31:10 -0500 Subject: [rspec-users] svn externals and git submodules In-Reply-To: References: Message-ID: <57c63afe0803181931i6f9ed9fbq9598b89429cf446a@mail.gmail.com> On Tue, Mar 18, 2008 at 8:41 PM, Dominic Sisneros wrote: > This is a request to split up the repository into at least two repositories I forwarded this to http://rspec.lighthouseapp.com/projects/5645/tickets/347. Please make future feature requests there instead of this mailing list. Thanks, David > > rspec > rspec_core (loaded as svn_external or git submodule) > rspec_on_rails (loaded as svn_external or git submodule) > > We could load the plugins the same way as before > ruby script/plugin install http://rspec.rubyforge.org/svn/trunk/rspec_core > ruby script/plugin install > http://rspec.rubyforge.org/svn/trunk/rspec_on_rails > > but it would be easier to install from git using git submodules > > using git and calling from RAILS_ROOT > > > git submodule add git//github.com/dchelimsky/rspec_on_rails.git > vendor/plugins/rspec_on_rails > git submodule add git//github.com/dchelimsky/rspec_core.git > vendor/plugins/rspec > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From linojon at gmail.com Tue Mar 18 23:13:59 2008 From: linojon at gmail.com (linojon) Date: Tue, 18 Mar 2008 23:13:59 -0400 Subject: [rspec-users] rescue Message-ID: Hi, whats the correct way to spec a rescue? This will raise it but doesnt test my code's response # controller def edit @foo = Foo.find(params[:id]) rescue flash[:notice] = "Unknown foo #{params[:id]}" redirect_to foos_path end # spec it "should flash error if not found" do Foo.should_receive(:find).and_raise get :edit, :id => '1' flash[:notice].should == "Unknown foo 1" end # run Exception in... -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080318/dc23a3bc/attachment-0001.html From zach.dennis at gmail.com Tue Mar 18 23:35:47 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 18 Mar 2008 23:35:47 -0400 Subject: [rspec-users] "Why not MockEverthing" or why use fixtures for all tests? In-Reply-To: References: Message-ID: <85d99afe0803182035w268623fuc728c7085fa7ae97@mail.gmail.com> Hello, On Tue, Mar 18, 2008 at 4:15 AM, David Schmidt wrote: > Hello fellow RSpec users. > > Before you all start warming up your flame throwers please let me explain my > Subject line. > > I've been working over 4 months on a large Rails project with a few other > developers. Test coverage was spotty at best, though they *were* RSpec > tests. One of the other developers and I had started adding more tests, > mostly controller tests using the methodology given at rspec.info for > writing controller tests isolated from the model and view layers using stubs > and mocks. > > Recently a new project manager was put in place and he brought in another > developer. This developer promptly started to re-write all the *existing* > controller (and later view) tests, removing all mocks and stubs and > replacing them with code to use fixtures. (He also deletes many comments he > finds in the code if *he* thinks they're obvious, but that's another > story...). His commit messages include comments like "Stop mocking around" > and "More fixes due to our test mockery". > > When challenged on why he's re-writing these tests instead of writing new, > missing tests (even tests using fixtures) he replied with this e-mail with > the subject "Why not MockEverything". (Note that I *do* use fixtures for > model tests but follow the RSpec documentation and use mocks/stubs for > controller and view tests for isolation.) In the email this developer > mentions tests broken by the addition of conditional to the view. This > conditional used a model method not previously used in the view, and the > addition of one stub was sufficient to fix the view test in question. > > Here is his email to me, less his signature as I don't want to make this > personal. I'd like to see what the RSpec user community has to say in > response to his comments, below: > > --- Why not MockEverything --- > David I've removed the mocks on purpuse. Not that I have sufficient ills > with them to meddle without a *need*. We committed simple template fixes > adding a conditional and there, yet the tests broke. > > Now this was to be expected, the tests were constructed by exhaustively > mocking out all methods called on the object. Add a simple conditional be it > harmless as it is now means another method needs to be mocked out. > > The MockEverything approach is not healthy, judicious use is preferable. One > thing is to write a short sample in a blog and another is to have a working > app with lots of tests. From all my apps that I have worked on this has by > far the lowest coverage both in profile and in test value. There is no > discussion we are all committed to tests. > > To better see what constitutes good practice I recommend you to inspect > the source of RadiantCMS a beautiful and well engineered app recently > rewrote to use rspec instead of Test::Unit: > > http://dev.radiantcms.org/browser/trunk/radiant/spec > > Observe how the code is restrained in mocking, real objects are preferred > wherever possible. Incidentally they don't use fixtures rather factories to > create *real* objects. Now the factory part is a separate issue I'll don't > discuss here, as it has its own disadvantages especially a project with many > models ... > > With real objects your test will not be brittle, and their value will be > kept even after adjusting the templates or doing other small refactorings. > Contrary to common misconception test speed will not be affected either. > Especially for view tests where you don't even have to save to the db upon > preparing the test rig. > > Beside Radiant there where efforts to rspec Typo and Mephisto (both noted > rails blog engines). Still these were half harted conversions so my > arguments based on them would not have the same weight. RadiantCMS is enough > - they are used on ruby-lang.org and have converted 100% to rspec ... plus > they also have good coverage showing that they actually believe in tests. So > please look into Radiant, you'll find it most helpful I think. > --- END OF EMAIL--- > > Thank you, > > David Schmidt There are a few bad assumptions in your colleague's response, so to set the record straight: * test coverage and tests which use the interaction-based test approach are not mutually exclusive * you can have crappy tests which take the state-based approach and crappy tests which use a interaction-based approach * interaction-based testing is not merely limited to contrived examples on people's blogs, it is a real practice which adds value on lots of "real-world" projects * using factories to generate required objects in tests has several pros over the use of fixtures, and very very very few cons State-based testing and interaction-based testing both have their place. There are number of reasons why they are both useful, but I'm going to pick two: object decomposition (and coordinators) and integration testing. Others have mentioned the value of writing tests with the interface you want so I'm going to leave that out. As an application grows in features and complexity (business logic of course) good developers will decompose the problem into a number of simple objects. Some of these objects are responsible for doing the work and others are responsible for coordinating other objects to do the work. Objects which are responsible for coordinating are great candidates for using interaction-based testing, because you are concerned in the interaction, not the "state". If you don't have integration tests then using an interaction-based testing approach is not worth it because you need something that is going to test the real objects working with real objects. In Rails you can write integration tests as Rail's ActionController::IntegrationTests, Rail's functional tests, RSpec stories, or RSpec controller tests w/view isolation turned off. IMO, one false benefit of only using a state-based approach when writing a full-fledged application is that every object is essentially an integration test at some level. You are always testing everything with everything that it touches. This can lead to having one failure in one model make several other model tests fail, and it can make several controller tests failing (as well as any other object which touches the model that is failing). I see this has a big negative because it makes it more difficult to pinpoint the issue. People will end up tracking it down, but it can be time consuming and frustrating. Now on the flip side people will complain that they renamed a model method and re-ran all of their tests and everything passed, but when running the application a bug exists. Doh, we forgot to update the controller that relied on calling that model method. It is normal to say/think, "well that should have failed because the method doesn't exist on the model". (It sounds like David Chelimsky may have something in trunk to help with this.) The main problem here though is that an integration test didn't fail exposing that you weren't done with your change. Thinking back to coordinating objects, my controllers don't contain business logic in them because they are application layer classes, they aren't apart of the domain of my software. They are only used by the application to allow the software to fulfill the requirements of my customer. Controllers are coordinators, not DOERS. They ask other objects to fulfill a business requirement for them like moving stocks from one portfolio to the another. So I used interaction-based testing here to ensure that my controller is finding a stock, finding a portfolio and asking a portfolio manager to move the stock to the designed portfolio. I don't need to have those things written or even fully implemented to ensure my controller works as I expect. I should be able to see that my controller does what it should be doing, even if the pieces it will use to do the work in the application aren't finished. Now if those aren't implemented I should have an integration test which fails showing me that the feature for moving stocks from one portfolio to another is not completed, but that isn't what I'm testing in my controller. Also after my controller works as expected I can go make sure the PortfolioManager works as expected, and then I can go down and make sure the Stock model does what I expect. When these objects are working correctly individual I run my integration tests to ensure they work well together. Another drawback of only using state-based testing is that you always have to develop bottom up. You have to start with the low level components and work your way out. I used to write code this way. I think I have progressed beyond that, and now I write things in a Acceptance Test Driven Development style. I start by writing an integration test from the user's perspective proving that the feature doesn't work, and then I move to the view, and then to the controller, then to any manager/factory/presenter/service objects that are required, and then down to any domain level objects (models and non-models alike). You can't do this approach with state-based testing only. There is a lot of value that can be gained by developing software this way. In short: Interaction-based testing allows you to ensure that an object is doing what you expect, without the underlying implementation having to exist yet at all or in full. It is great for application layer objects which typically only coordinate domain layer objects where the correct interaction is what is important. It also helps you develop interfaces, and it can scream loudly when you have an object doing way too much. * "Blaming "brittleness" of tests upon interaction-based testing is a red herring. Both interaction-based tests and state-based tests become brittle if they make assertions upon implementation details and overly constrain the interfaces between modules." - Nat Pryce * http://nat.truemesh.com/archives/000342.html - a wonderful read on interaction-based vs state-based testing -- Zach Dennis http://www.continuousthinking.com From luislavena at gmail.com Tue Mar 18 23:39:45 2008 From: luislavena at gmail.com (Luis Lavena) Date: Wed, 19 Mar 2008 00:39:45 -0300 Subject: [rspec-users] svn externals and git submodules In-Reply-To: References: Message-ID: <71166b3b0803182039k10d9e969g427e0365232bd16a@mail.gmail.com> On Tue, Mar 18, 2008 at 10:41 PM, Dominic Sisneros wrote: > This is a request to split up the repository into at least two repositories > > rspec > rspec_core (loaded as svn_external or git submodule) > rspec_on_rails (loaded as svn_external or git submodule) > > We could load the plugins the same way as before > ruby script/plugin install http://rspec.rubyforge.org/svn/trunk/rspec_core > ruby script/plugin install > http://rspec.rubyforge.org/svn/trunk/rspec_on_rails > > but it would be easier to install from git using git submodules > > using git and calling from RAILS_ROOT > > > git submodule add git//github.com/dchelimsky/rspec_on_rails.git > vendor/plugins/rspec_on_rails > git submodule add git//github.com/dchelimsky/rspec_core.git > vendor/plugins/rspec > Wow, a short command line to type, putting that into my brain will push out of the stack my 3 years old memories... Wouldn't be better submit some patches to Rails and make script/plugin Git-aware? -- Luis Lavena Multimedia systems - Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. Douglas Adams From zach.dennis at gmail.com Tue Mar 18 23:50:51 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 18 Mar 2008 23:50:51 -0400 Subject: [rspec-users] rescue In-Reply-To: References: Message-ID: <85d99afe0803182050r24df9ae7la9cfc83ac8b98e33@mail.gmail.com> On Tue, Mar 18, 2008 at 11:13 PM, linojon wrote: > Hi, whats the correct way to spec a rescue? This will raise it but doesnt > test my code's response > > > > # controller > > def edit > @foo = Foo.find(params[:id]) > rescue > flash[:notice] = "Unknown foo #{params[:id]}" > redirect_to foos_path > end > > > # spec > > it "should flash error if not found" do > Foo.should_receive(:find).and_raise > get :edit, :id => '1' > flash[:notice].should == "Unknown foo 1" > end > > # run > > Exception in... > > I have done a very similar thing: Foo.should_receive(:find).and_raise ActiveRecord::ActiveRecordError and then change your rescue to handle ActiveRecord::ActiveRecordError. If you get to the point where you have a generic way you'd like to handle the exceptions in a controller, or across controllers look into using the controller class method rescue_from. I'm not 100% this is what you were asking, hopefully you were just looking for confirmation, -- Zach Dennis http://www.continuousthinking.com From ben at benmabey.com Wed Mar 19 00:15:23 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 18 Mar 2008 22:15:23 -0600 Subject: [rspec-users] Am I off track on my testing? In-Reply-To: <85d99afe0803151512p3ae83973vccf26b14ae1e1c6f@mail.gmail.com> References: <0e943ba8159ed3c1d1f0454b813f4b90@ruby-forum.com> <85d99afe0803140829i776b47bch710b48b0601e227e@mail.gmail.com> <85d99afe0803141808o5f0712aclbcbd9b8f9671b20c@mail.gmail.com> <47DC4318.4060003@benmabey.com> <85d99afe0803151512p3ae83973vccf26b14ae1e1c6f@mail.gmail.com> Message-ID: <47E0935B.1070605@benmabey.com> Zach Dennis wrote: > On Sat, Mar 15, 2008 at 5:43 PM, Ben Mabey wrote: > >> Zach Dennis wrote: >> > Can someone change this implementation and still have your tests pass, >> > but have the implementation be broken? If they can then yes it is >> > worth the 40 lines. >> > >> > Pat mentioned that he uses very skinny controllers and does >> > integration tests which go through the whole stack to make sure things >> > work. So if he doesn't test the controller#action's because they are >> > too simple he at least will have a failing integration test if someone >> > breaks the implementation. >> > >> > The problem I have with what Pat is doing is that it takes a lot of >> > discipline from the developer to not let the controller grow into a >> > cesspool of logic and interaction that shouldn't be there, but you put >> > it there because you aren't "testing" it directly. From what I've seen >> > most Rails apps have important interaction in the controller actions >> > and logic in the before filters. I would not personally take this >> > approach on customer paid for software. Pat may be more disciplined >> > then me though. =) >> > >> > >> >> I totally agree with this point. Using interaction-based testing really >> helps in forcing the logic down into the model. >> >> I'm curious about your comment: "From what I've seen most Rails apps >> >> have important interaction in the controller actions >> and logic in the before filters". What are you exactly referring to? I >> generally use before filters for authentication... How have you seen >> them abused? >> > > I've seen before filters be abused. Authentication is typical an > application level responsibility and it makes sense for the controller > to protect its resources. No qualms there. I have inherited code bases > which abused before filters for things like checking permissions for > business requirements. For example: > > class ProjectsController < ApplicationController > before_filter :login_required # i'm ok with this > before_filter :ensure_project_manager, :only => [:new, :create] > before_filter :ensure_project_write_access, :only => [:edit, :update] > # ... I've seen this filter list go on and on and on, based on > any possible persmission > Ahh, yes... I have seen this before. In fact people have told me that they don't test there controllers because of such permutations that take too long to test fully (because they have to test it on EVERY controller with those set of filters). Thats when I tell them that if things are too hard to test that is probably a good sign the are doing something wrong. :) In the past I have always pushed this in the model. I have ofter though just let the controller call one simple predicate method on the model in a filter. So perhaps I am guilty of abusing filters as well... > I would rather introduce a Manager/Service object which is responsible > for accessing a project, and allow that do handle the responsibility > for knowing what permissions allow someone to create or edit a > project. > > Makes sense- I really like that idea. Having a service handle all of this makes a lot of sense the more I think about it. As I have developed rails apps I always keep my controllers extremely thin but certain models become too large, IMO. I've actually been reading DDD and have been trying to think of ways of creating more service objects to remove the extra responsibility I have added in my models. Thanks for pointing this one out to me. > I've been experimenting with using an approach similar in spirit to > what Pat is doing, but slightly different: > > class ApplicationController < ActionController::Base > rescue_from AccessDenied, ResourceNotFoundError do |exception| > redirect_to "/access_denied.html" > end > # ... > end > > class ProjectsController < ApplicationController > before_filter :login_required > > def new > @project = ProjectManager.new_project > end > > def create > ProjectManager.create_project params[:project] do |project_creation| > project_creation.success do |project| > flash[:notice] = "Project created successfully" > @project = project > end > > project_creation.failure do |project| > flash[:notice] = "Project creation failed" > @project = project > render :action => "new" > end > end > # ... > end > > I tend to like this for projects I've worked on where it doesn't make > sense to shove all of the responsibility onto a model because it > abstracts out the "Manager" who is in charge of ensuring permissions > and doing odds and ends things involved in the creation of a project > that the model should not be doing (like upload an associated picture > of the project manager or ensure memberships status). > Very nice... I will definitely steal that slick use of blocks ;) My one question about this implementation is how does the ProjectManager get access to the session or at least gets the information about the current user? Without that information you can't have any permissions logic in the manager... > In the above approach the application controller is setup to rescue > from certain application exceptions, and the controllers just do their > thing, and the managers which enforce the business logic will throw > the exceptions it a business rule has been violated. > > I have used a similar approach in apps in the past (by throwing an AccessDenied exception), but I have somewhat gone away from that. My hesitation was caused by me wondering if a violation of these permissions really deems an exception. Is having a user trying to get into an area where they don't have the needed rights *exceptional*? So seeing you use this same pattern makes me think that it probably is a good use of exceptions. Having the logic in a manger I think the only way to handle incorrect permissions cleanly would be an exception so I guess the argument is somehwat moot in this context. Thank so much for taking the time to answer my question. I always learn a great deal from this list so thank you for contributing so much to it. -Ben From dsisnero at gmail.com Wed Mar 19 00:44:17 2008 From: dsisnero at gmail.com (Dominic Sisneros) Date: Tue, 18 Mar 2008 22:44:17 -0600 Subject: [rspec-users] svn externals and git submodules In-Reply-To: <71166b3b0803182039k10d9e969g427e0365232bd16a@mail.gmail.com> References: <71166b3b0803182039k10d9e969g427e0365232bd16a@mail.gmail.com> Message-ID: rails/plugin is git aware already in trunk for cloning a git repository. However, you can only clone from the git repository root (the directory which contains the .git directory). You can't clone from a subdirectory. That's why the project needs to be split to install both rspec and rspec_on_rails in the vendor/plugins directory using git. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080318/52cba60e/attachment.html From jonathan at parkerhill.com Wed Mar 19 01:59:46 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Wed, 19 Mar 2008 01:59:46 -0400 Subject: [rspec-users] rescue In-Reply-To: <85d99afe0803182050r24df9ae7la9cfc83ac8b98e33@mail.gmail.com> References: <85d99afe0803182050r24df9ae7la9cfc83ac8b98e33@mail.gmail.com> Message-ID: <6C2F0739-40B3-48F8-B001-0757499BA9BE@parkerhill.com> yep, that did it :) thx On Mar 18, 2008, at 11:50 PM, Zach Dennis wrote: > On Tue, Mar 18, 2008 at 11:13 PM, linojon wrote: >> Hi, whats the correct way to spec a rescue? This will raise it but >> doesnt >> test my code's response >> >> >> >> # controller >> >> def edit >> @foo = Foo.find(params[:id]) >> rescue >> flash[:notice] = "Unknown foo #{params[:id]}" >> redirect_to foos_path >> end >> >> >> # spec >> >> it "should flash error if not found" do >> Foo.should_receive(:find).and_raise >> get :edit, :id => '1' >> flash[:notice].should == "Unknown foo 1" >> end >> >> # run >> >> Exception in... >> >> > > I have done a very similar thing: > > Foo.should_receive(:find).and_raise ActiveRecord::ActiveRecordError > > and then change your rescue to handle ActiveRecord::ActiveRecordError. > > If you get to the point where you have a generic way you'd like to > handle the exceptions in a controller, or across controllers look into > using the controller class method rescue_from. > > I'm not 100% this is what you were asking, hopefully you were just > looking for confirmation, > > -- > Zach Dennis > http://www.continuousthinking.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ashley.moran at patchspace.co.uk Wed Mar 19 07:15:52 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 19 Mar 2008 11:15:52 +0000 Subject: [rspec-users] Are there hooks to record messages to be displayed after a spec run? Message-ID: Hi I am working on a class for use in spec code that has an "unsafe" version that does not catch common errors. Currently I have it using STDERR.puts to display warning messages, but these scroll past when there are failures. Is there way I can record a message to be displayed after the spec run output? Thanks Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080319/58c49c36/attachment.html From dhoefler at gmail.com Wed Mar 19 11:33:03 2008 From: dhoefler at gmail.com (Dave) Date: Wed, 19 Mar 2008 10:33:03 -0500 Subject: [rspec-users] Stub / Mock - A little guidance? Message-ID: <7d983dfe0803190833x3b8b432md57d24fdaebe3559@mail.gmail.com> Hi there, I'm still trying to wrap my head around when to use a stub and a mock. If I understand this right, I should be using a 'mock' when imitating an object, but not its behavior. I should be using a stub when I want to imitate the behavior of an object. Does that sound about right? With that said, I'm struggling a little trying to spec out this instance method that is available to a User object. The method takes an OrderPaymentInfo object and copies its attributes onto the User's attributes (Ignore the clunky design... that's just how it has to be). The User's instance method looks like so: class User def update_billing_info(billing_info) unless self.has_billing_address? self.bill_to_address1 = billing_info.address1 self.bill_to_address2 = billing_info.address2 self.bill_to_address3 = billing_info.address3 self.bill_to_city = billing_info.city self.bill_to_country_code = billing_info.country_code self.bill_to_state_province_code = billing_info.state_province_code self.bill_to_postal_code = billing_info.postal_code self.bill_to_phone_number = billing_info.phone_number self.bill_to_extension = billing_info.extension self.bill_to_fax = billing_info.fax_number self.save ? true : false else true end end Here's the spec: describe User, "when checking billing information" do before(:each) do @user = User.new(:id => 1) @order_payment_info = mock_model(OrderPaymentInfo, :id => 1, :user_id => @user.id, :address1 => "555 Rd.", :address2 => "Ste 2", :address3 => "line 3", :city => "Chicago", :country_code => "USA", :state_province_code => "IL", :psotal_code => "12345", :phone_number => "5551234321", :extension => "123", :fax_number => "5551234321") @user.stub!(:update_billing_info).with(@order_payment_info) end it "should update billing information when User's billing info is nil" do @user.should_receive(:update_billing_info).with(@order_payment_info) @user.update_billing_info(@order_payment_info) @user.stub!(:has_billing_address?).and_return(false) @user.bill_to_address1.should eql("555 Rd.") @user.bill_to_address2.should eql("Ste 2") end end When I run this spec I get an "error" of: 1) 'User when checking billing information should update billing information when User's billing info is nil' FAILED expected "555 Rd.", got nil (using .eql?) I'm just wondering what the best way to approach this would be. Thank you, Dave Hoefler From glenn at aldenta.com Wed Mar 19 11:42:44 2008 From: glenn at aldenta.com (Glenn Ford) Date: Wed, 19 Mar 2008 11:42:44 -0400 Subject: [rspec-users] "Why not MockEverthing" or why use fixtures for all tests? In-Reply-To: <85d99afe0803182035w268623fuc728c7085fa7ae97@mail.gmail.com> References: <85d99afe0803182035w268623fuc728c7085fa7ae97@mail.gmail.com> Message-ID: >> [Big Snip] > > There are a few bad assumptions in your colleague's response, so to > set the record straight: > > * test coverage and tests which use the interaction-based test > approach are not mutually exclusive > * you can have crappy tests which take the state-based approach and > crappy tests which use a interaction-based approach > * interaction-based testing is not merely limited to contrived > examples on people's blogs, it is a real practice which adds value on > lots of "real-world" projects > * using factories to generate required objects in tests has several > pros over the use of fixtures, and very very very few cons > > State-based testing and interaction-based testing both have their > place. There are number of reasons why they are both useful, but I'm > going to pick two: object decomposition (and coordinators) and > integration testing. Others have mentioned the value of writing tests > with the interface you want so I'm going to leave that out. > > As an application grows in features and complexity (business logic of > course) good developers will decompose the problem into a number of > simple objects. Some of these objects are responsible for doing the > work and others are responsible for coordinating other objects to do > the work. Objects which are responsible for coordinating are great > candidates for using interaction-based testing, because you are > concerned in the interaction, not the "state". > > If you don't have integration tests then using an interaction-based > testing approach is not worth it because you need something that is > going to test the real objects working with real objects. In Rails you > can write integration tests as Rail's > ActionController::IntegrationTests, Rail's functional tests, RSpec > stories, or RSpec controller tests w/view isolation turned off. > > IMO, one false benefit of only using a state-based approach when > writing a full-fledged application is that every object is essentially > an integration test at some level. You are always testing everything > with everything that it touches. This can lead to having one failure > in one model make several other model tests fail, and it can make > several controller tests failing (as well as any other object which > touches the model that is failing). I see this has a big negative > because it makes it more difficult to pinpoint the issue. People will > end up tracking it down, but it can be time consuming and frustrating. > > Now on the flip side people will complain that they renamed a model > method and re-ran all of their tests and everything passed, but when > running the application a bug exists. Doh, we forgot to update the > controller that relied on calling that model method. It is normal to > say/think, "well that should have failed because the method doesn't > exist on the model". (It sounds like David Chelimsky may have > something in trunk to help with this.) The main problem here though is > that an integration test didn't fail exposing that you weren't done > with your change. > > Thinking back to coordinating objects, my controllers don't contain > business logic in them because they are application layer classes, > they aren't apart of the domain of my software. They are only used by > the application to allow the software to fulfill the requirements of > my customer. Controllers are coordinators, not DOERS. They ask other > objects to fulfill a business requirement for them like moving stocks > from one portfolio to the another. So I used interaction-based testing > here to ensure that my controller is finding a stock, finding a > portfolio and asking a portfolio manager to move the stock to the > designed portfolio. I don't need to have those things written or even > fully implemented to ensure my controller works as I expect. I should > be able to see that my controller does what it should be doing, even > if the pieces it will use to do the work in the application aren't > finished. Now if those aren't implemented I should have an integration > test which fails showing me that the feature for moving stocks from > one portfolio to another is not completed, but that isn't what I'm > testing in my controller. > > Also after my controller works as expected I can go make sure the > PortfolioManager works as expected, and then I can go down and make > sure the Stock model does what I expect. When these objects are > working correctly individual I run my integration tests to ensure they > work well together. > > Another drawback of only using state-based testing is that you always > have to develop bottom up. You have to start with the low level > components and work your way out. I used to write code this way. I > think I have progressed beyond that, and now I write things in a > Acceptance Test Driven Development style. I start by writing an > integration test from the user's perspective proving that the feature > doesn't work, and then I move to the view, and then to the controller, > then to any manager/factory/presenter/service objects that are > required, and then down to any domain level objects (models and > non-models alike). You can't do this approach with state-based testing > only. There is a lot of value that can be gained by developing > software this way. > > In short: Interaction-based testing allows you to ensure that an > object is doing what you expect, without the underlying implementation > having to exist yet at all or in full. It is great for application > layer objects which typically only coordinate domain layer objects > where the correct interaction is what is important. It also helps you > develop interfaces, and it can scream loudly when you have an object > doing way too much. > > * "Blaming "brittleness" of tests upon interaction-based testing is a > red herring. Both interaction-based tests and state-based tests become > brittle if they make assertions upon implementation details and overly > constrain the interfaces between modules." - Nat Pryce > > * http://nat.truemesh.com/archives/000342.html - a wonderful read on > interaction-based vs state-based testing > > -- > Zach Dennis > http://www.continuousthinking.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users A lot of what you say makes me wish I was more experienced in this department :) I am very new to this! A part of me wishes I had the knowledge to write in the order of story -> view spec -> controller spec -> model spec. However most of the time (I emphasize MOST) I don't have the foresight to do that. The problem I'm trying to solve is almost always too complicated for me to know right away where to really start (my latest client has some crazy ideas). Maybe the problem is that I make things too complicated for myself :) However I have been a developer (just not using RSpec) for a very long time so I know fairly well how to recognize when things need to be complicated and when they don't. This means .should_receive is often out of the question because I have no idea what the model should receive! My primary concern when writing my specs that are to cover complicated features is that I do NOT want false confidence. If I write a spec, and it passes, I want that to mean it works in my app. When the spec goes green, my next step is to go hit Refresh in my browser. If it doesn't work in my browser, then in my opinion, my spec is crap. It's telling me things work when they don't. I hear the concern being voiced that if you break one thing and 15 specs pass then you're not mocking enough. Well since this is BDD, after all, then we should be working closely to the current spec we're trying to make pass. I change code, and 15 specs break, well I have a good idea of what code got broken because it's the top-most file in my editor! I hit save, Autotest screamed at me, I'm going to go hit undo now. Sometimes I make noob decisions and give model A a certain responsibility when it should have been done by model B. I get it to work in the short term, my spec's pass, but later I need to add another feature and realize that old responsibility needs to be moved from A to B. Now I have a red spec and X green specs. I move that responsibility, X specs are green, with still the same 1 red spec. I implement the new feature, X+1 green specs. I refresh in my browser, sure enough, it all works. I didn't have to go change all of my stubs and should_recieve's everywhere that just got moved. There's no need to, because my specs cover the true business logic behavior, and not the model-specific "behavior". While I do certainly believe the ability to spread everything out well enough so that 1 error = 1 broken spec comes from great wisdom and experience, I certainly don't have it, and I don't want to encourage others like me to try to strive for that because I don't know how to teach them from my own example. What I do know, is that I use a lot of real models, and I don't spend any time fixing specs that are broken by working code. I did that on my last project and it, in my opinion, wasn't worth it. I'd change a variable assignment with a .save to a .update_attribute and then I had a broken spec. My fear is that I'll write green specs, pat myself on the back, and then my company loses money because the site has bugs that my specs show green for because I don't have enough integration tests or whatever. But I don't want to have to double my tests for the same amount of coverage. I should have 1 spec for 1 feature and when that feature is working, that spec is green, plain and simple. I admit I may be ignorant to a lot of the power behind RSpec, but I like this level of simplicity and straightforwardness. Glenn Ford http://www.glennfu.com From ivo.dancet at gmail.com Wed Mar 19 12:01:00 2008 From: ivo.dancet at gmail.com (Ivo Dancet) Date: Wed, 19 Mar 2008 17:01:00 +0100 Subject: [rspec-users] Stub / Mock - A little guidance? In-Reply-To: <7d983dfe0803190833x3b8b432md57d24fdaebe3559@mail.gmail.com> References: <7d983dfe0803190833x3b8b432md57d24fdaebe3559@mail.gmail.com> Message-ID: Op 19-mrt-08, om 16:33 heeft Dave het volgende geschreven: > Hi there, > > I'm still trying to wrap my head around when to use a stub and a mock. > If I understand this right, I should be using a 'mock' when imitating > an object, but not its behavior. I should be using a stub when I want > to imitate the behavior of an object. Does that sound about right? > > With that said, I'm struggling a little trying to spec out this > instance method that is available to a User object. The method takes > an OrderPaymentInfo object and copies its attributes onto the User's > attributes (Ignore the clunky design... that's just how it has to be). > > The User's instance method looks like so: > > class User > def update_billing_info(billing_info) > unless self.has_billing_address? > self.bill_to_address1 = billing_info.address1 > self.bill_to_address2 = billing_info.address2 > self.bill_to_address3 = billing_info.address3 > self.bill_to_city = billing_info.city > self.bill_to_country_code = billing_info.country_code > self.bill_to_state_province_code = > billing_info.state_province_code > self.bill_to_postal_code = billing_info.postal_code > self.bill_to_phone_number = billing_info.phone_number > self.bill_to_extension = billing_info.extension > self.bill_to_fax = billing_info.fax_number > self.save ? true : false > else > true > end > end > If this is activerecord you could use self.update_attributes(billing_info) > > Here's the spec: > > describe User, "when checking billing information" do > before(:each) do > @user = User.new(:id => 1) > @order_payment_info = mock_model(OrderPaymentInfo, > :id => 1, > :user_id => @user.id, > :address1 => "555 Rd.", > :address2 => "Ste 2", > :address3 => "line 3", > :city => "Chicago", > :country_code => "USA", > :state_province_code => "IL", > :psotal_code => "12345", > :phone_number => "5551234321", > :extension => "123", > :fax_number => "5551234321") > @user.stub!(:update_billing_info).with(@order_payment_info) > end You just stubbed update_billing_info (called with @order_payment_info) on @user, which means the real method will not be used anymore. Your tests will use the stub instead of the real method. Don't stub the very thing you want to test! > > > it "should update billing information when User's billing info is > nil" do > > @user.should_receive(:update_billing_info).with(@order_payment_info) > @user.update_billing_info(@order_payment_info) > @user.stub!(:has_billing_address?).and_return(false) > @user.bill_to_address1.should eql("555 Rd.") > @user.bill_to_address2.should eql("Ste 2") > end > > > end > > When I run this spec I get an "error" of: > > 1) > 'User when checking billing information should update billing > information when User's billing info is nil' FAILED > expected "555 Rd.", got nil (using .eql?) > Try to test one thing at a time, you shouldn't test everything about that method in one test. To me your test description does not tell a thing: 'User when checking billing information should update billing information when User's billing info is nil' This says much more: 'User instance object update_billing_info should update the billing address part 1' You can build this up like this: describe User, "instance object" do before(:each) do @user = User.create( ... ) end describe "update_billing_info" do it "should update the billing address part 1" do @user.update_billing_info( @order_payment_info ) @user.bill_to_address1.should == "555 Rd." end it "should ..." ... end end Try to make small tests (make a new test if the first works) and try to build the model with the tests instead of the other way around. gr Ivo From dhoefler at gmail.com Wed Mar 19 12:32:26 2008 From: dhoefler at gmail.com (Dave) Date: Wed, 19 Mar 2008 11:32:26 -0500 Subject: [rspec-users] Stub / Mock - A little guidance? In-Reply-To: References: <7d983dfe0803190833x3b8b432md57d24fdaebe3559@mail.gmail.com> Message-ID: <7d983dfe0803190932l2d2cb394ve3d50371552dc231@mail.gmail.com> Ivo, Thank you for that explanation! That was exactly what I needed. I feel like I understand things more clearly after that. I just need to remember to keep my tests small. Thanks! Dave On Wed, Mar 19, 2008 at 11:01 AM, Ivo Dancet wrote: > Op 19-mrt-08, om 16:33 heeft Dave het volgende geschreven: > > > > > Hi there, > > > > I'm still trying to wrap my head around when to use a stub and a mock. > > If I understand this right, I should be using a 'mock' when imitating > > an object, but not its behavior. I should be using a stub when I want > > to imitate the behavior of an object. Does that sound about right? > > > > With that said, I'm struggling a little trying to spec out this > > instance method that is available to a User object. The method takes > > an OrderPaymentInfo object and copies its attributes onto the User's > > attributes (Ignore the clunky design... that's just how it has to be). > > > > The User's instance method looks like so: > > > > class User > > def update_billing_info(billing_info) > > unless self.has_billing_address? > > self.bill_to_address1 = billing_info.address1 > > self.bill_to_address2 = billing_info.address2 > > self.bill_to_address3 = billing_info.address3 > > self.bill_to_city = billing_info.city > > self.bill_to_country_code = billing_info.country_code > > self.bill_to_state_province_code = > > billing_info.state_province_code > > self.bill_to_postal_code = billing_info.postal_code > > self.bill_to_phone_number = billing_info.phone_number > > self.bill_to_extension = billing_info.extension > > self.bill_to_fax = billing_info.fax_number > > self.save ? true : false > > else > > true > > end > > end > > > > If this is activerecord you could use > self.update_attributes(billing_info) > > > > > > Here's the spec: > > > > describe User, "when checking billing information" do > > before(:each) do > > @user = User.new(:id => 1) > > @order_payment_info = mock_model(OrderPaymentInfo, > > :id => 1, > > :user_id => @user.id, > > :address1 => "555 Rd.", > > :address2 => "Ste 2", > > :address3 => "line 3", > > :city => "Chicago", > > :country_code => "USA", > > :state_province_code => "IL", > > :psotal_code => "12345", > > :phone_number => "5551234321", > > :extension => "123", > > :fax_number => "5551234321") > > @user.stub!(:update_billing_info).with(@order_payment_info) > > end > > You just stubbed update_billing_info (called with @order_payment_info) > on @user, which means the real method will not be used anymore. Your > tests will use the stub instead of the real method. Don't stub the > very thing you want to test! > > > > > > > > it "should update billing information when User's billing info is > > nil" do > > > > @user.should_receive(:update_billing_info).with(@order_payment_info) > > @user.update_billing_info(@order_payment_info) > > @user.stub!(:has_billing_address?).and_return(false) > > @user.bill_to_address1.should eql("555 Rd.") > > @user.bill_to_address2.should eql("Ste 2") > > end > > > > > > end > > > > When I run this spec I get an "error" of: > > > > 1) > > 'User when checking billing information should update billing > > information when User's billing info is nil' FAILED > > expected "555 Rd.", got nil (using .eql?) > > > > Try to test one thing at a time, you shouldn't test everything about > that method in one test. To me your test description does not tell a > thing: > > > 'User when checking billing information should update billing > information when User's billing info is nil' > > This says much more: > > 'User instance object update_billing_info should update the billing > address part 1' > > You can build this up like this: > > describe User, "instance object" do > before(:each) do > @user = User.create( ... ) > end > describe "update_billing_info" do > it "should update the billing address part 1" do > > @user.update_billing_info( @order_payment_info ) > @user.bill_to_address1.should == "555 Rd." > end > it "should ..." ... > end > end > > > Try to make small tests (make a new test if the first works) and try > to build the model with the tests instead of the other way around. > > gr > Ivo > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Mar 19 13:03:07 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 19 Mar 2008 12:03:07 -0500 Subject: [rspec-users] "Why not MockEverthing" or why use fixtures for all tests? In-Reply-To: References: <85d99afe0803182035w268623fuc728c7085fa7ae97@mail.gmail.com> Message-ID: <57c63afe0803191003x43cf11cci205af91fab62a76c@mail.gmail.com> On Wed, Mar 19, 2008 at 10:42 AM, Glenn Ford wrote: > >> [Big Snip] > > > > > > There are a few bad assumptions in your colleague's response, so to > > set the record straight: > > > > * test coverage and tests which use the interaction-based test > > approach are not mutually exclusive > > * you can have crappy tests which take the state-based approach and > > crappy tests which use a interaction-based approach > > * interaction-based testing is not merely limited to contrived > > examples on people's blogs, it is a real practice which adds value on > > lots of "real-world" projects > > * using factories to generate required objects in tests has several > > pros over the use of fixtures, and very very very few cons > > > > State-based testing and interaction-based testing both have their > > place. There are number of reasons why they are both useful, but I'm > > going to pick two: object decomposition (and coordinators) and > > integration testing. Others have mentioned the value of writing tests > > with the interface you want so I'm going to leave that out. > > > > As an application grows in features and complexity (business logic of > > course) good developers will decompose the problem into a number of > > simple objects. Some of these objects are responsible for doing the > > work and others are responsible for coordinating other objects to do > > the work. Objects which are responsible for coordinating are great > > candidates for using interaction-based testing, because you are > > concerned in the interaction, not the "state". > > > > If you don't have integration tests then using an interaction-based > > testing approach is not worth it because you need something that is > > going to test the real objects working with real objects. In Rails you > > can write integration tests as Rail's > > ActionController::IntegrationTests, Rail's functional tests, RSpec > > stories, or RSpec controller tests w/view isolation turned off. > > > > IMO, one false benefit of only using a state-based approach when > > writing a full-fledged application is that every object is essentially > > an integration test at some level. You are always testing everything > > with everything that it touches. This can lead to having one failure > > in one model make several other model tests fail, and it can make > > several controller tests failing (as well as any other object which > > touches the model that is failing). I see this has a big negative > > because it makes it more difficult to pinpoint the issue. People will > > end up tracking it down, but it can be time consuming and frustrating. > > > > Now on the flip side people will complain that they renamed a model > > method and re-ran all of their tests and everything passed, but when > > running the application a bug exists. Doh, we forgot to update the > > controller that relied on calling that model method. It is normal to > > say/think, "well that should have failed because the method doesn't > > exist on the model". (It sounds like David Chelimsky may have > > something in trunk to help with this.) The main problem here though is > > that an integration test didn't fail exposing that you weren't done > > with your change. > > > > Thinking back to coordinating objects, my controllers don't contain > > business logic in them because they are application layer classes, > > they aren't apart of the domain of my software. They are only used by > > the application to allow the software to fulfill the requirements of > > my customer. Controllers are coordinators, not DOERS. They ask other > > objects to fulfill a business requirement for them like moving stocks > > from one portfolio to the another. So I used interaction-based testing > > here to ensure that my controller is finding a stock, finding a > > portfolio and asking a portfolio manager to move the stock to the > > designed portfolio. I don't need to have those things written or even > > fully implemented to ensure my controller works as I expect. I should > > be able to see that my controller does what it should be doing, even > > if the pieces it will use to do the work in the application aren't > > finished. Now if those aren't implemented I should have an integration > > test which fails showing me that the feature for moving stocks from > > one portfolio to another is not completed, but that isn't what I'm > > testing in my controller. > > > > Also after my controller works as expected I can go make sure the > > PortfolioManager works as expected, and then I can go down and make > > sure the Stock model does what I expect. When these objects are > > working correctly individual I run my integration tests to ensure they > > work well together. > > > > Another drawback of only using state-based testing is that you always > > have to develop bottom up. You have to start with the low level > > components and work your way out. I used to write code this way. I > > think I have progressed beyond that, and now I write things in a > > Acceptance Test Driven Development style. I start by writing an > > integration test from the user's perspective proving that the feature > > doesn't work, and then I move to the view, and then to the controller, > > then to any manager/factory/presenter/service objects that are > > required, and then down to any domain level objects (models and > > non-models alike). You can't do this approach with state-based testing > > only. There is a lot of value that can be gained by developing > > software this way. > > > > In short: Interaction-based testing allows you to ensure that an > > object is doing what you expect, without the underlying implementation > > having to exist yet at all or in full. It is great for application > > layer objects which typically only coordinate domain layer objects > > where the correct interaction is what is important. It also helps you > > develop interfaces, and it can scream loudly when you have an object > > doing way too much. > > > > * "Blaming "brittleness" of tests upon interaction-based testing is a > > red herring. Both interaction-based tests and state-based tests become > > brittle if they make assertions upon implementation details and overly > > constrain the interfaces between modules." - Nat Pryce > > > > * http://nat.truemesh.com/archives/000342.html - a wonderful read on > > interaction-based vs state-based testing > > > > -- > > Zach Dennis > > http://www.continuousthinking.com > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > A lot of what you say makes me wish I was more experienced in this > department :) I am very new to this! A part of me wishes I had the > knowledge to write in the order of story -> view spec -> controller > spec -> model spec. However most of the time (I emphasize MOST) I > don't have the foresight to do that. The problem I'm trying to solve > is almost always too complicated for me to know right away where to > really start (my latest client has some crazy ideas). Maybe the > problem is that I make things too complicated for myself :) However I > have been a developer (just not using RSpec) for a very long time so I > know fairly well how to recognize when things need to be complicated > and when they don't. This means .should_receive is often out of the > question because I have no idea what the model should receive! > > My primary concern when writing my specs that are to cover complicated > features is that I do NOT want false confidence. If I write a spec, > and it passes, I want that to mean it works in my app. When the spec > goes green, my next step is to go hit Refresh in my browser. If it > doesn't work in my browser, then in my opinion, my spec is crap. It's > telling me things work when they don't. Sounds like you're thinking of specs as application-level specifications. They *can* be, but that is not the intent. They are intended to be examples of how individual objects work in isolation. So I disagree that if the spec passes and the application fails that the spec is crap. It's just isolated. > > I hear the concern being voiced that if you break one thing and 15 > specs pass then you're not mocking enough. Well since this is BDD, > after all, then we should be working closely to the current spec we're > trying to make pass. I change code, and 15 specs break, well I have a > good idea of what code got broken because it's the top-most file in my > editor! I hit save, Autotest screamed at me, I'm going to go hit undo > now. That's great that you can back out, but you now have a small problem to solve that has a bigger short-term impact than you want. Ideally, you'd be able to solve the small problems, one at a time, until the big problem is solved. The way you know you're solving small problems is the object-level examples pass. The way you know you're solving big problems is that the application-level examples (stories, or even manual-in-browser testing) > Sometimes I make noob decisions and give model A a certain > responsibility when it should have been done by model B. I get it to > work in the short term, my spec's pass, but later I need to add > another feature and realize that old responsibility needs to be moved > from A to B. Now I have a red spec and X green specs. I move that > responsibility, X specs are green, with still the same 1 red spec. I > implement the new feature, X+1 green specs. I refresh in my browser, > sure enough, it all works. I didn't have to go change all of my stubs > and should_recieve's everywhere that just got moved. There's no need > to, because my specs cover the true business logic behavior, and not > the model-specific "behavior". Again - this is a matter of granularity. The whole point of having granular examples is to enable you to make changes to the system easily via refactoring. Sometimes refactoring requires moving examples around along with the implementation code. This is refactoring 101 stuff, and an accepted part of the refactoring process in all of my experience prior to working in Ruby. It's only people in the Ruby community that I see expressing this concern. I think it's because the refactoring tools for Java and C# are superior, so they automate a lot of the granular steps you need to take when refactoring manually. The problem with decreasing the granularity is that it makes fault isolation more difficult. It means less work right now for lots more work down the road. > While I do certainly believe the ability to spread everything out well > enough so that 1 error = 1 broken spec comes from great wisdom and > experience, I certainly don't have it, and I don't want to encourage > others like me to try to strive for that because I don't know how to > teach them from my own example. What I do know, is that I use a lot > of real models, and I don't spend any time fixing specs that are > broken by working code. I did that on my last project and it, in my > opinion, wasn't worth it. I'd change a variable assignment with > a .save to a .update_attribute and then I had a broken spec. > > My fear is that I'll write green specs, pat myself on the back, and > then my company loses money because the site has bugs that my specs > show green for because I don't have enough integration tests or > whatever. You throw that out like integration testing is an afterthought and specs are king. In my view, they are equal partners. > But I don't want to have to double my tests for the same > amount of coverage. You just suggested that you fear that your green specs don't provide enough coverage, but that the addition of integration testing would provide sufficient additional coverage. How is that "the same amount of coverage"? > I should have 1 spec for 1 feature and when that > feature is working, that spec is green, plain and simple. I admit I > may be ignorant to a lot of the power behind RSpec, but I like this > level of simplicity and straightforwardness. This is not really about RSpec. It is about an approach to using tests to drive out the behaviour of your application, and then help you to maintain it by simply living on as regression tests. I appreciate the motivation to do less work now. Especially with Rails, which makes it so damned easy to prototype something that the extra effort of automated testing seems painful. All I can say is that I've consistently had a much easier time of maintaining an application over time when I've been disciplined about both high and low level testing. If you find that you can live with only one level of testing, then more power to you. FWIW, David > > Glenn Ford > http://www.glennfu.com > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From davids at tower-mt.com Wed Mar 19 13:47:02 2008 From: davids at tower-mt.com (David Schmidt) Date: Wed, 19 Mar 2008 10:47:02 -0700 Subject: [rspec-users] "Why not MockEverthing" or why use fixtures for all tests? In-Reply-To: References: <85d99afe0803182035w268623fuc728c7085fa7ae97@mail.gmail.com> Message-ID: <26459092-31F8-4DAD-B546-E9E5472510BD@tower-mt.com> On Mar 19, 2008, at 8:42 AM, Glenn Ford wrote: > My primary concern when writing my specs that are to cover complicated > features is that I do NOT want false confidence. If I write a spec, > and it passes, I want that to mean it works in my app. When the spec > goes green, my next step is to go hit Refresh in my browser. If it > doesn't work in my browser, then in my opinion, my spec is crap. It's > telling me things work when they don't. This paragraph caught my eye, especially in my specific issue of mocks/ stubs versus fixtures in our own tests. In my view tests I use mock_model with a hash of valid attributes. This allows a mock with automatic stubs for these valid attributes: valid_user_attributes = { 'name' => 'user name', 'userid' => 'userid' } before (:each) do @mock_user = mock_model(User, valid_user_attributes) [...] end A sample test to verify that one of these attributes is properly displayed looks like: it "should display the user name in the contact box" do do_render response.should have_tag('div#contact', /.*#{@mock_user.name}.*/) end The dev that wants all fixtures does this by loading a fixture record: before (:each) do user = User.find( users(:david).id ) [...] end His tests written to check that particular attributes were properly displayed in the view look like: it "should display the user name in Contact Pod" do do_render response.should have_tag('div#contact', /^#{users(:david).name}/) end This developer added some new code to the view in question, displaying a new table value and complained when my mock/stub version of the test failed because there was no stub to display that new attribute. However, though his test passed, he had failed to add the "name" attribute to his fixtures. This meant that users(:david).name was returning an empty string ('') and his test was just checking that an empty string was in the view output, which would pass EVERY time! I demonstrated this by putting an 'X' after each of the names in the regex (like /.*#{@mockuser.name}X.*/) to force a failure. When I ran both versions of the test I saw the following output for my test: expected but was <"User Name\n 123 Any St.... The fixtures version of the test with the 'X' returned this error: expected but was <"User Name\n \n \n... Note that nothing is showing prior to the X, because name wasn't in the fixture. My point is that was much easier to forget to add the new attributes to the fixtures in another file. When adding the new attribute to the valid_user_attributes you'd have to create it as an empty string ('name' => '') which would be much less likely to happen. With the fixtures version pulling data from the fixtures files it's much less obvious when you have bad data in the fixture. As far as maintenance, the mock/stub version only required one line to be added to the valid_user_attributes hash. The fixtures version requires that new attribute to be added to every fixture that will be using that attribute and it's easy to accidently leave it out of some fixture records. The result, at least in *this* particular case, is that it was much easier to end up with a number of tests returning false "passes" using the fixtures method. I'm not a 100% mock/stub proponent, but I'm very much against 100% fixtures and like using mocks and stubs for view tests where what you are testing is that the proper data is displayed in the correct containers in the view. David From glenn at aldenta.com Wed Mar 19 15:10:30 2008 From: glenn at aldenta.com (Glenn Ford) Date: Wed, 19 Mar 2008 15:10:30 -0400 Subject: [rspec-users] "Why not MockEverthing" or why use fixtures for all tests? In-Reply-To: <57c63afe0803191003x43cf11cci205af91fab62a76c@mail.gmail.com> References: <85d99afe0803182035w268623fuc728c7085fa7ae97@mail.gmail.com> <57c63afe0803191003x43cf11cci205af91fab62a76c@mail.gmail.com> Message-ID: On Mar 19, 2008, at 1:03 PM, David Chelimsky wrote: > On Wed, Mar 19, 2008 at 10:42 AM, Glenn Ford > wrote: >>>> [Big Snip] >> >> >>> >>> There are a few bad assumptions in your colleague's response, so to >>> set the record straight: >>> >>> * test coverage and tests which use the interaction-based test >>> approach are not mutually exclusive >>> * you can have crappy tests which take the state-based approach and >>> crappy tests which use a interaction-based approach >>> * interaction-based testing is not merely limited to contrived >>> examples on people's blogs, it is a real practice which adds value >>> on >>> lots of "real-world" projects >>> * using factories to generate required objects in tests has several >>> pros over the use of fixtures, and very very very few cons >>> >>> State-based testing and interaction-based testing both have their >>> place. There are number of reasons why they are both useful, but I'm >>> going to pick two: object decomposition (and coordinators) and >>> integration testing. Others have mentioned the value of writing >>> tests >>> with the interface you want so I'm going to leave that out. >>> >>> As an application grows in features and complexity (business logic >>> of >>> course) good developers will decompose the problem into a number of >>> simple objects. Some of these objects are responsible for doing the >>> work and others are responsible for coordinating other objects to do >>> the work. Objects which are responsible for coordinating are great >>> candidates for using interaction-based testing, because you are >>> concerned in the interaction, not the "state". >>> >>> If you don't have integration tests then using an interaction-based >>> testing approach is not worth it because you need something that is >>> going to test the real objects working with real objects. In Rails >>> you >>> can write integration tests as Rail's >>> ActionController::IntegrationTests, Rail's functional tests, RSpec >>> stories, or RSpec controller tests w/view isolation turned off. >>> >>> IMO, one false benefit of only using a state-based approach when >>> writing a full-fledged application is that every object is >>> essentially >>> an integration test at some level. You are always testing everything >>> with everything that it touches. This can lead to having one failure >>> in one model make several other model tests fail, and it can make >>> several controller tests failing (as well as any other object which >>> touches the model that is failing). I see this has a big negative >>> because it makes it more difficult to pinpoint the issue. People >>> will >>> end up tracking it down, but it can be time consuming and >>> frustrating. >>> >>> Now on the flip side people will complain that they renamed a model >>> method and re-ran all of their tests and everything passed, but when >>> running the application a bug exists. Doh, we forgot to update the >>> controller that relied on calling that model method. It is normal to >>> say/think, "well that should have failed because the method doesn't >>> exist on the model". (It sounds like David Chelimsky may have >>> something in trunk to help with this.) The main problem here >>> though is >>> that an integration test didn't fail exposing that you weren't done >>> with your change. >>> >>> Thinking back to coordinating objects, my controllers don't contain >>> business logic in them because they are application layer classes, >>> they aren't apart of the domain of my software. They are only used >>> by >>> the application to allow the software to fulfill the requirements of >>> my customer. Controllers are coordinators, not DOERS. They ask other >>> objects to fulfill a business requirement for them like moving >>> stocks >>> from one portfolio to the another. So I used interaction-based >>> testing >>> here to ensure that my controller is finding a stock, finding a >>> portfolio and asking a portfolio manager to move the stock to the >>> designed portfolio. I don't need to have those things written or >>> even >>> fully implemented to ensure my controller works as I expect. I >>> should >>> be able to see that my controller does what it should be doing, even >>> if the pieces it will use to do the work in the application aren't >>> finished. Now if those aren't implemented I should have an >>> integration >>> test which fails showing me that the feature for moving stocks from >>> one portfolio to another is not completed, but that isn't what I'm >>> testing in my controller. >>> >>> Also after my controller works as expected I can go make sure the >>> PortfolioManager works as expected, and then I can go down and make >>> sure the Stock model does what I expect. When these objects are >>> working correctly individual I run my integration tests to ensure >>> they >>> work well together. >>> >>> Another drawback of only using state-based testing is that you >>> always >>> have to develop bottom up. You have to start with the low level >>> components and work your way out. I used to write code this way. I >>> think I have progressed beyond that, and now I write things in a >>> Acceptance Test Driven Development style. I start by writing an >>> integration test from the user's perspective proving that the >>> feature >>> doesn't work, and then I move to the view, and then to the >>> controller, >>> then to any manager/factory/presenter/service objects that are >>> required, and then down to any domain level objects (models and >>> non-models alike). You can't do this approach with state-based >>> testing >>> only. There is a lot of value that can be gained by developing >>> software this way. >>> >>> In short: Interaction-based testing allows you to ensure that an >>> object is doing what you expect, without the underlying >>> implementation >>> having to exist yet at all or in full. It is great for application >>> layer objects which typically only coordinate domain layer objects >>> where the correct interaction is what is important. It also helps >>> you >>> develop interfaces, and it can scream loudly when you have an object >>> doing way too much. >>> >>> * "Blaming "brittleness" of tests upon interaction-based testing >>> is a >>> red herring. Both interaction-based tests and state-based tests >>> become >>> brittle if they make assertions upon implementation details and >>> overly >>> constrain the interfaces between modules." - Nat Pryce >>> >>> * http://nat.truemesh.com/archives/000342.html - a wonderful read on >>> interaction-based vs state-based testing >>> >>> -- >>> Zach Dennis >>> http://www.continuousthinking.com >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> A lot of what you say makes me wish I was more experienced in this >> department :) I am very new to this! A part of me wishes I had the >> knowledge to write in the order of story -> view spec -> controller >> spec -> model spec. However most of the time (I emphasize MOST) I >> don't have the foresight to do that. The problem I'm trying to solve >> is almost always too complicated for me to know right away where to >> really start (my latest client has some crazy ideas). Maybe the >> problem is that I make things too complicated for myself :) >> However I >> have been a developer (just not using RSpec) for a very long time >> so I >> know fairly well how to recognize when things need to be complicated >> and when they don't. This means .should_receive is often out of the >> question because I have no idea what the model should receive! >> >> My primary concern when writing my specs that are to cover >> complicated >> features is that I do NOT want false confidence. If I write a spec, >> and it passes, I want that to mean it works in my app. When the spec >> goes green, my next step is to go hit Refresh in my browser. If it >> doesn't work in my browser, then in my opinion, my spec is crap. >> It's >> telling me things work when they don't. > > Sounds like you're thinking of specs as application-level > specifications. They *can* be, but that is not the intent. They are > intended to be examples of how individual objects work in isolation. > So I disagree that if the spec passes and the application fails that > the spec is crap. It's just isolated. I see your point here, very true. If my usage of RSpec improves with better integration testing, I'm sure I'll be able to use them more appropriately in this manner. >> I hear the concern being voiced that if you break one thing and 15 >> specs pass then you're not mocking enough. Well since this is BDD, >> after all, then we should be working closely to the current spec >> we're >> trying to make pass. I change code, and 15 specs break, well I >> have a >> good idea of what code got broken because it's the top-most file in >> my >> editor! I hit save, Autotest screamed at me, I'm going to go hit >> undo >> now. > > That's great that you can back out, but you now have a small problem > to solve that has a bigger short-term impact than you want. Ideally, > you'd be able to solve the small problems, one at a time, until the > big problem is solved. The way you know you're solving small problems > is the object-level examples pass. The way you know you're solving big > problems is that the application-level examples (stories, or even > manual-in-browser testing) I can see your point here, but I don't believe it disagrees with my idea so much. My approach still involves small specs passing building up to larger functionality in the end. The limitation is just that I start from the bottom level and work my way up. I just don't have the option of working in the other direction, which from a design perspective can certainly be limiting like you're pointing out. I think it's my own fault that more than anything else that I can't ever seem to plan in the other direction :) It's typically not until I find a solution on the model level that I understand what will be coming back on the top level. Experience will probably change this so that I can see it more like you do. >> Sometimes I make noob decisions and give model A a certain >> responsibility when it should have been done by model B. I get it to >> work in the short term, my spec's pass, but later I need to add >> another feature and realize that old responsibility needs to be moved >> from A to B. Now I have a red spec and X green specs. I move that >> responsibility, X specs are green, with still the same 1 red spec. I >> implement the new feature, X+1 green specs. I refresh in my browser, >> sure enough, it all works. I didn't have to go change all of my >> stubs >> and should_recieve's everywhere that just got moved. There's no need >> to, because my specs cover the true business logic behavior, and not >> the model-specific "behavior". > > Again - this is a matter of granularity. The whole point of having > granular examples is to enable you to make changes to the system > easily via refactoring. Sometimes refactoring requires moving examples > around along with the implementation code. This is refactoring 101 > stuff, and an accepted part of the refactoring process in all of my > experience prior to working in Ruby. It's only people in the Ruby > community that I see expressing this concern. I think it's because the > refactoring tools for Java and C# are superior, so they automate a lot > of the granular steps you need to take when refactoring manually. > > The problem with decreasing the granularity is that it makes fault > isolation more difficult. It means less work right now for lots more > work down the road. Perhaps my example simplified my problem too much. The chore that I was referring to unfortunately wasn't about refactoring. I wish it had been that easy! Instead it was really the behavior that got transfered, but the logic and code was quite different. The goal was to ensure the end result was still the same, that way I would know I hadn't broken anything but still had the new structure that I needed. Without my specs covering the resulting state I would have had no guidance to help me here. >> While I do certainly believe the ability to spread everything out >> well >> enough so that 1 error = 1 broken spec comes from great wisdom and >> experience, I certainly don't have it, and I don't want to encourage >> others like me to try to strive for that because I don't know how to >> teach them from my own example. What I do know, is that I use a lot >> of real models, and I don't spend any time fixing specs that are >> broken by working code. I did that on my last project and it, in my >> opinion, wasn't worth it. I'd change a variable assignment with >> a .save to a .update_attribute and then I had a broken spec. >> >> My fear is that I'll write green specs, pat myself on the back, and >> then my company loses money because the site has bugs that my specs >> show green for because I don't have enough integration tests or >> whatever. > > You throw that out like integration testing is an afterthought and > specs are king. In my view, they are equal partners. Chalk that one up to ignorance I suppose, I don't have much good integration testing and I don't even know much about good ways to do it. Even with integration testing, however, I'd still have my original spec broken and in need of repair when I don't believe it should need fixing. >> But I don't want to have to double my tests for the same >> amount of coverage. > > You just suggested that you fear that your green specs don't provide > enough coverage, but that the addition of integration testing would > provide sufficient additional coverage. How is that "the same amount > of coverage"? What I meant was that if I wrote them with less real models and more mocks, I would feel I had less coverage, and that the only way to match coverage without real models would be to up the number of tests (aka lots more integration testing). If I can just change my approach to writing the spec in a way that's more easy to write anyway, why should I feel required to write additional tests on top of that to re- verify that things work? >> I should have 1 spec for 1 feature and when that >> feature is working, that spec is green, plain and simple. I admit I >> may be ignorant to a lot of the power behind RSpec, but I like this >> level of simplicity and straightforwardness. > > This is not really about RSpec. It is about an approach to using tests > to drive out the behaviour of your application, and then help you to > maintain it by simply living on as regression tests. > > I appreciate the motivation to do less work now. Especially with > Rails, which makes it so damned easy to prototype something that the > extra effort of automated testing seems painful. All I can say is that > I've consistently had a much easier time of maintaining an application > over time when I've been disciplined about both high and low level > testing. If you find that you can live with only one level of testing, > then more power to you. I don't mean to make it sound so much like a short-term laziness thing. Maybe it comes out that way! I'm certainly more encouraged now to better learn about the high-level testing options. Thank you for the time you spent offering your feedback. I hope you can also find value in the perspectives of those who come in struggling for direction. Even as hard as I try to read and research everything (while still managing to find development time in there) it's often difficult to see what all is available/possible/best. Thank you! Glenn > FWIW, > David > >> >> Glenn Ford >> http://www.glennfu.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 dchelimsky at gmail.com Wed Mar 19 15:21:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 19 Mar 2008 14:21:21 -0500 Subject: [rspec-users] "Why not MockEverthing" or why use fixtures for all tests? In-Reply-To: References: <85d99afe0803182035w268623fuc728c7085fa7ae97@mail.gmail.com> <57c63afe0803191003x43cf11cci205af91fab62a76c@mail.gmail.com> Message-ID: <57c63afe0803191221g45034d45o9a6aceda526095bf@mail.gmail.com> On Wed, Mar 19, 2008 at 2:10 PM, Glenn Ford wrote: > > On Mar 19, 2008, at 1:03 PM, David Chelimsky wrote: > > Again - this is a matter of granularity. The whole point of having > > granular examples is to enable you to make changes to the system > > easily via refactoring. Sometimes refactoring requires moving examples > > around along with the implementation code. This is refactoring 101 > > stuff, and an accepted part of the refactoring process in all of my > > experience prior to working in Ruby. It's only people in the Ruby > > community that I see expressing this concern. I think it's because the > > refactoring tools for Java and C# are superior, so they automate a lot > > of the granular steps you need to take when refactoring manually. > > > > The problem with decreasing the granularity is that it makes fault > > isolation more difficult. It means less work right now for lots more > > work down the road. > > Perhaps my example simplified my problem too much. The chore that I > was referring to unfortunately wasn't about refactoring. I wish it > had been that easy! Instead it was really the behavior that got > transfered, but the logic and code was quite different. The goal was > to ensure the end result was still the same, that way I would know I > hadn't broken anything but still had the new structure that I needed. > Without my specs covering the resulting state I would have had no > guidance to help me here. >From Fowler: "Refactoring is the process of changing a software system in such a way that it does not alter the external behaviour of the code yet improves its internal structure." Sounds like what you are describing is exactly that, no? David From glenn at aldenta.com Wed Mar 19 15:34:15 2008 From: glenn at aldenta.com (Glenn Ford) Date: Wed, 19 Mar 2008 15:34:15 -0400 Subject: [rspec-users] "Why not MockEverthing" or why use fixtures for all tests? In-Reply-To: <57c63afe0803191221g45034d45o9a6aceda526095bf@mail.gmail.com> References: <85d99afe0803182035w268623fuc728c7085fa7ae97@mail.gmail.com> <57c63afe0803191003x43cf11cci205af91fab62a76c@mail.gmail.com> <57c63afe0803191221g45034d45o9a6aceda526095bf@mail.gmail.com> Message-ID: On Mar 19, 2008, at 3:21 PM, David Chelimsky wrote: > On Wed, Mar 19, 2008 at 2:10 PM, Glenn Ford wrote: >> >> On Mar 19, 2008, at 1:03 PM, David Chelimsky wrote: >>> Again - this is a matter of granularity. The whole point of having >>> granular examples is to enable you to make changes to the system >>> easily via refactoring. Sometimes refactoring requires moving >>> examples >>> around along with the implementation code. This is refactoring 101 >>> stuff, and an accepted part of the refactoring process in all of my >>> experience prior to working in Ruby. It's only people in the Ruby >>> community that I see expressing this concern. I think it's because >>> the >>> refactoring tools for Java and C# are superior, so they automate a >>> lot >>> of the granular steps you need to take when refactoring manually. >>> >>> The problem with decreasing the granularity is that it makes fault >>> isolation more difficult. It means less work right now for lots more >>> work down the road. >> >> Perhaps my example simplified my problem too much. The chore that I >> was referring to unfortunately wasn't about refactoring. I wish it >> had been that easy! Instead it was really the behavior that got >> transfered, but the logic and code was quite different. The goal was >> to ensure the end result was still the same, that way I would know I >> hadn't broken anything but still had the new structure that I needed. >> Without my specs covering the resulting state I would have had no >> guidance to help me here. > >> From Fowler: "Refactoring is the process of changing a software >> system > in such a way that it does not alter the external behaviour of the > code yet improves its internal structure." > > Sounds like what you are describing is exactly that, no? Yes, it is, but since you spoke mostly of the simple kind of refactoring that Eclipse might do for Java I figured that's all you thought I was talking about. I was speaking about redesigning the stuff under the hood. There's no ctrl+ function in Eclipse that would do that one for me! Glenn > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From Nathan.Zook at amd.com Wed Mar 19 15:55:30 2008 From: Nathan.Zook at amd.com (nzook) Date: Wed, 19 Mar 2008 12:55:30 -0700 (PDT) Subject: [rspec-users] ApplicationHelper Message-ID: <16149622.post@talk.nabble.com> When working with views, I use instance methods of ApplicationHelper: # app/helpers/application_helper.rb: module ApplicationHelper def distribute(total, min, cutof, list) [1,2,3] end end # app/views/planner/_mta_colors.rhtml: <% ... dist = distribute(total_v_px, 4, 0, colors.collect{|color| color[1]}) ... %> So to test the distribute method in ApplicationHelper, I have to extend my spec models: describe ApplicationHelper do extend(ApplicationHelper) it "doesn't find what it's looking for do distribute(1,2,3,[4,5,6]).should eql([1,2,3]) end end This could use some documentation. -- View this message in context: http://www.nabble.com/ApplicationHelper-tp16149622p16149622.html Sent from the rspec-users mailing list archive at Nabble.com. From joe at pinkpucker.net Wed Mar 19 22:47:32 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Wed, 19 Mar 2008 19:47:32 -0700 Subject: [rspec-users] cleaning up after stories Message-ID: do I have to manually clear out the database after a story runs? Seems like the data the story left is still in there. Joe From joe at pinkpucker.net Thu Mar 20 00:35:51 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Wed, 19 Mar 2008 21:35:51 -0700 Subject: [rspec-users] Attachment-fu + Story Runner In-Reply-To: <57c63afe0712120554j147ffbe6lcff9faf8d5af743f@mail.gmail.com> References: <57c63afe0712110528l7551f346r86adf8ca71790e91@mail.gmail.com> <8D52CE6F-5E7A-47E7-A436-7098186978E3@tenner.org> <71166b3b0712110639p3acb5c3am16cddc67a9cb619d@mail.gmail.com> <14291797.post@talk.nabble.com> <57c63afe0712120554j147ffbe6lcff9faf8d5af743f@mail.gmail.com> Message-ID: What was the resolution on this? How do you people test uploads with rspec stories? On Wed, Dec 12, 2007 at 6:54 AM, David Chelimsky wrote: > On Dec 12, 2007 5:41 AM, Daniel Tenner wrote: > > > > Ok, a bit more digging and I found this is a Rails issue, that is logged > > here: > > > > http://dev.rubyonrails.org/ticket/4635 > > > > File uploads don't work in Rails integration tests either, only in > > functional tests. This is not specific to Attachment-Fu. > > > > There is, however, a monkey patch that you can download to enable a > > multipart_post method which will not mangle the params anymore. > > > > Hope this helps others too! > > Daniel - thanks for doing the research on this. There are no tests for > the rails patch. If you're willing to add rspec examples and > contribute it to the rspec tracker, I'll add it to rspec as a > temporary fix until that ticket is resolved. > > > > > > > Daniel > > > > > > > > On 12 Dec 2007, at 09:38 12 Dec 2007, voodoorai2000 wrote: > > > > > > Hi, > > > > I had the same problem, couldn't get it to run with Stories thought... > > Had to test file uploads using controller specs, which works but is not as > > clear as a Story. > > > > I'm guessing the bug where it changes the TempFile to a String will be fixed > > soon by the core team, but if someone has a patch it would be awesome! > > > > > > Rai > > > > > > > > Daniel Tenner wrote: > > > > I've now located where this is going wrong, though I am not yet sure > > how to fix it. > > > > In rails' integration.rb, there is a method called 'process'. around > > line 226. It mangles the parameters by calling: > > data = requestify(parameters) > > > > doing: > > puts "\n1----===#{parameters.inspect}" > > puts "\n2----===#{data.inspect}" > > > > a bit later reveals the problem: > > 1----==={:quick_file=>{:filename=>"file- > > TFile.txt", :uploaded_data=># > 0x3434150 @content_type="text/plain", @tempfile=# > test_upload29259-0.txt>, > > @original_filename="test_upload.txt">}, :quick_folder=> > > {:id=>1330}, :request_type=>"xml"} > > > > 2----==="quick_file%5Bfilename%5D=file-TFile.txt&quick_file% > > 5Buploaded_data%5D=%23%3CActionController%3A%3ATestUploadedFile% > > 3A0x3434150%3E&quick_folder%5Bid%5D=1330&request_type=xml" > > > > Obviously that's not going to work. I wonder how Test::Unit does it, > > then, though... > > > > Daniel > > > > On 11 Dec 2007, at 14:54 11 Dec 2007, Daniel Tenner wrote: > > > > > > Hi Luis, > > > > I read through that thread, but unfortunately it wasn't much help. > > > > fixture_file_upload also creates an > > ActionController::TestUploadedFile. It's is just a shortcut to > > ActionController::TestUploadedFile.new. > > > > There's no problem with the path - it creates the fixture and loads > > the file, and has the right values inside if I inspect the params > > directly before posting them: > > > > {:filename=>"file- > > TFile.txt", :uploaded_data=># > 0x33f83bc @content_type=# > @synonyms=[], @string="text/plain">, @tempfile=# > test_upload29049-0.txt>, @original_filename="test_upload.txt">} > > > > It's only once this is passed into the controller that it all gets > > to_s'ed. > > > > I like the idea of 'providing a real file upload', but I'm not sure > > how to do that in a Story... if anyone has any suggestions or > > pointers, they would be welcome! > > > > Thanks, > > > > Daniel > > > > On 11 Dec 2007, at 14:39 11 Dec 2007, Luis Lavena wrote: > > > > > > On Dec 11, 2007 10:57 AM, Daniel Tenner > > wrote: > > > > I've pasted up the code at: > > > > http://pastie.caboo.se/126925 > > > > Since there are quite a few files involved. > > > > Thanks for your time, > > > > > > > > A similar discussion was raised back in november (about > > fixture_file_upload): > > > > http://rubyforge.org/pipermail/rspec-users/2007-November/004378.html > > > > Instead of mocking the FileUpload, why not provide a real one? > > > > After all, the StoryRunner is aimed to fully exercise your code :-D > > > > Also, adjust the path of your TestFileUpload file location, > > instead of > > a relative one (../spec/fixtures) provide one related to RAILS_ROOT, > > which will work no matter where you put your helper or what is your > > current directory (Dir.chdir). > > > > HTH, > > > > -- > > Luis Lavena > > Multimedia systems > > - > > A common mistake that people make when trying to design > > something completely foolproof is to underestimate > > the ingenuity of complete fools. > > Douglas Adams > > _______________________________________________ > > 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 > > > > > > > > -- > > View this message in context: > > http://www.nabble.com/Attachment-fu-%2B-Story-Runner-tp14272891p14291797.html > > 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 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From joe at pinkpucker.net Thu Mar 20 00:44:44 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Wed, 19 Mar 2008 21:44:44 -0700 Subject: [rspec-users] sharing story steps Message-ID: Hi, How can I have a common set of steps that all my stories share? i.e. My stories often start out looking like this: Given a user Joe Given a user Jordan then: Given("a user $username") do |username| @users ||= {} @user_sessions ||= {} @users[username] = create_user(:username => username) @user_sessions[username] = login_as(@users[username]) end I want to share that Given with all my stories. Or is there a better way to do it? Joe From tero at tilus.net Thu Mar 20 01:01:01 2008 From: tero at tilus.net (Tero Tilus) Date: Thu, 20 Mar 2008 07:01:01 +0200 Subject: [rspec-users] cleaning up after stories In-Reply-To: References: Message-ID: <20080320050101.GD8816@uivelo.tilus.net> On Wed, 19 Mar 2008, Joe Van Dyk wrote: > do I have to manually clear out the database after a story runs? I'm wondering the same, but with specs. Database gets dirty and tests start to fail when i repeatedly do rake spec. -- Tero Tilus ## +358 (0)50 3635 235 ## http://www.tilus.net/koti/tero/ From aslak.hellesoy at gmail.com Thu Mar 20 05:05:32 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 20 Mar 2008 10:05:32 +0100 Subject: [rspec-users] sharing story steps In-Reply-To: References: Message-ID: <8d961d900803200205t258fe0e1n1b4478a9099c1e8b@mail.gmail.com> On Thu, Mar 20, 2008 at 5:44 AM, Joe Van Dyk wrote: > Hi, > > How can I have a common set of steps that all my stories share? > > i.e. My stories often start out looking like this: > > Given a user Joe > Given a user Jordan > > then: put this in steps/users.rb: steps_for(:user) do > Given("a user $username") do |username| > @users ||= {} > @user_sessions ||= {} > @users[username] = create_user(:username => username) > @user_sessions[username] = login_as(@users[username]) > end end Now, in your file running stories: with_steps_for(:user, :project, :comment) do ... end > > I want to share that Given with all my stories. Or is there a better > way to do it? > At one of our current projects in BEKK we have come up with a convention for naming and grouping steps. It simply follows the same convention as the controllers for file names, and in each file we put all steps that are relevant to a given controller. In the run file we simply run stories with_steps_for all of them. Try it out, I think you'll like it. Aslak > Joe > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Thu Mar 20 06:34:46 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 20 Mar 2008 06:34:46 -0400 Subject: [rspec-users] Attachment-fu + Story Runner In-Reply-To: References: <57c63afe0712110528l7551f346r86adf8ca71790e91@mail.gmail.com> <8D52CE6F-5E7A-47E7-A436-7098186978E3@tenner.org> <71166b3b0712110639p3acb5c3am16cddc67a9cb619d@mail.gmail.com> <14291797.post@talk.nabble.com> <57c63afe0712120554j147ffbe6lcff9faf8d5af743f@mail.gmail.com> Message-ID: On 3/20/08, Joe Van Dyk wrote: > What was the resolution on this? How do you people test uploads with > rspec stories? I submitted a Rails patch to address the underlying problem http://dev.rubyonrails.org/ticket/11091 It got in as changeset 8978 and should be in edge rails. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From lists at ruby-forum.com Thu Mar 20 06:50:53 2008 From: lists at ruby-forum.com (Dmitry Vanidovsky) Date: Thu, 20 Mar 2008 11:50:53 +0100 Subject: [rspec-users] `const_missing': uninitialized constant Spec::Rails In-Reply-To: <134397f35fcfb4757285f2038b3f9fcc@ruby-forum.com> References: <134397f35fcfb4757285f2038b3f9fcc@ruby-forum.com> Message-ID: Dmitry Vanidovsky wrote: > Have anyone had similar problem? What is by experience the most > suiteable version of rspec framework for rails 1.1.2? Thanks! It appeared rspec/rspec_on_rails version 1.0.8 runs without errors for env described obove. (used svn co for dovnloading rspec/rspec_on_rails) Hope this saves someone time. -- Posted via http://www.ruby-forum.com/. From rick.denatale at gmail.com Thu Mar 20 07:02:22 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 20 Mar 2008 07:02:22 -0400 Subject: [rspec-users] cleaning up after stories In-Reply-To: <20080320050101.GD8816@uivelo.tilus.net> References: <20080320050101.GD8816@uivelo.tilus.net> Message-ID: On 3/20/08, Tero Tilus wrote: > On Wed, 19 Mar 2008, Joe Van Dyk wrote: > > do I have to manually clear out the database after a story runs? > > > I'm wondering the same, but with specs. Database gets dirty and > tests start to fail when i repeatedly do rake spec. >From what I've seen, the test infrastructure (which RSpec takes from the Rails Test::Unit based code) relies on fixtures to initialize the database BEFORE running tests. The setup code clears any tables for which fixtures are declared, then loads those fixtures. It's a little counterintuitive that the tables don't get cleared AFTER the test, but I guess it makes sense in that without clearing before loading those tables wouldn't be in a known state at the beginning of the test. What I've done is to have fixtures with a single record for tables I want to 'clear'. Alternatively you can do something like: MyModel.delete_all For any tables you want to clear, in the before block for tests, or in the xxx_story.rb for stories. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From anthony at digitalphenom.com Thu Mar 20 08:56:36 2008 From: anthony at digitalphenom.com (Anthony Carlos) Date: Thu, 20 Mar 2008 08:56:36 -0400 Subject: [rspec-users] Combining autotest, rspec, rspec_on_rails and spec-server Message-ID: <0A9F76B5-E1C0-4934-A664-22F75AE26C76@digitalphenom.com> Hello, I've been trying to google the definitive way to combine autotest, rspec, and spec-server, but to no avail. It seems like there are lots of suggestions from old versions. Furthermore, some commands such as rake:autotest don't seem to be around anymore. So, is it required to install ZenTest as a gem? I have version 3.9.1. I believe this gets me the autotest command that I can issue on the command line. Must I install rspec as a gem? At first, I tried to not install it as a gem and followed the instructions from http://rspec.info/ documentation/rails/install.html. I installed rspec as a plugin to my Rails project and used just rake spec, but found that unless I install rspec as a gem, there is no spec command for the command line. That might make it easier to run my specs with options. So, I installed rspec 1.1.3 as a gem. That provided me with the spec command that I can issue on the command line. What is the recommended way to start the spec-server? ./script/ spec_server or rake:spec:server:start? I've tried both and cannot discern the differences. Finally, what is the recommended way to run my specs? spec -O spec/ spec.opts spec/XXX or rake spec:XXX ? I've edited spec.opts to include --drb on the first line. The rake method didn't seem to use the spec-server, despite this suggestion. So, I've tried the spec command above. It still didn't seem to use spec-server. However, when I use spec -X -O spec/spec.opts, it does seem to use the spec_server. I'm glad I'm able to finally use the spec_server, but it's a real drag switching back to my command line to issue this command after every save. That's exactly why I want to run autotest. What is the recommended way to run autotest? autotest or rake spec:autotest (I've seen this on google, but the command itself no longer appears when I run rake -T spec. Is there something wrong with my setup? Am I supposed to have a rake task for this or is it deprecated). Without an available rake task, I am forced to try the autotest command. However, I don't think that the autotest command accepts any options that tell it to use the spec_server. I tried autotest -X, and of course, my spec.opts file does already say --drb in the first line. As you can see, I am really confused because there are at least 2 ways to do everything, and I haven't been able to try every combination. I've also noticed that autotest no longer runs the entire test suite after a red-green cycle. I actually liked this behavior, but all I could find was David Chelimsky's blog on how to de-activate the behavior. Why has it changed? Can it be restored? If it helps, I'm running on Mac OS X 10.4.11, ruby 1.8.6 (2007-09-24 patchlevel 111) [powerpc-darwin8.11.0] Thanks for your help! -Anthony From mtsbtt at googlemail.com Thu Mar 20 09:30:41 2008 From: mtsbtt at googlemail.com (Martin Sadler) Date: Thu, 20 Mar 2008 13:30:41 +0000 Subject: [rspec-users] Command line option to run a story scenario? Message-ID: <6E7EC1A3-6A7B-4ABA-9924-40C0E790510B@googlemail.com> Hi Folks, Quick question. Anybody know if there is a command line option to run an individual scenario for the given story e.g. something like: ruby stories/my_story.rb -s "the name of the scenario" Thanks in advance, Martin. PS: Really loving story runner at the moment. Got it hooked up with Selenium and the results are really nice. From edvard at majakari.net Thu Mar 20 09:57:41 2008 From: edvard at majakari.net (Edvard Majakari) Date: Thu, 20 Mar 2008 15:57:41 +0200 Subject: [rspec-users] rspec groups? In-Reply-To: <14FBB390-36F0-44F2-A2CC-15F40058108D@patchspace.co.uk> References: <57c63afe0803080811l5b4b1e76vae9e234d45eb0ee3@mail.gmail.com> <14FBB390-36F0-44F2-A2CC-15F40058108D@patchspace.co.uk> Message-ID: On Wed, Mar 19, 2008 at 1:12 AM, Ashley Moran wrote: > > sufficient to me, but of course, YNMDFTOM. > Please put me out of my misery and explain the acronym :D My bad. My favorite hobby is to invent new acronyms on the fly, of which the one concerned is an example. It is short for "Your Needs May Differ From Those Of Mine" :) -- "One day, when he was naughty, Mr Bunnsy looked over the hedge into Farmer Fred's field and it was full of fresh green lettuces. Mr Bunnsy, however, was not full of lettuces. This did not seem fair." -- Terry Pratchett, Mr. Bunnsy Has An Adventure From lists at ruby-forum.com Thu Mar 20 10:31:23 2008 From: lists at ruby-forum.com (Max Williams) Date: Thu, 20 Mar 2008 15:31:23 +0100 Subject: [rspec-users] rspec groups? In-Reply-To: References: <57c63afe0803080811l5b4b1e76vae9e234d45eb0ee3@mail.gmail.com> <14FBB390-36F0-44F2-A2CC-15F40058108D@patchspace.co.uk> Message-ID: Edvard Majakari wrote: > On Wed, Mar 19, 2008 at 1:12 AM, Ashley Moran > wrote: > >> > sufficient to me, but of course, YNMDFTOM. > >> Please put me out of my misery and explain the acronym :D > > My bad. My favorite hobby is to invent new acronyms on the fly, of > which the one concerned is an example. > It is short for "Your Needs May Differ From Those Of Mine" :) > > -- > "One day, when he was naughty, Mr Bunnsy looked over the hedge into > Farmer Fred's field and it was full of fresh green lettuces. Mr > Bunnsy, however, was not full of lettuces. This did not seem fair." > -- Terry Pratchett, Mr. Bunnsy Has An Adventure Sorry to be pedantic, but shouldn't that be "Your needs may differ from mine"? There's no party called 'mine', so 'mine' has no needs :) Anyway, does anyone have any idea why -e "the name of a describe block" results in 0 tests being run for me? -- Posted via http://www.ruby-forum.com/. From coreyhaines at gmail.com Thu Mar 20 14:30:35 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Thu, 20 Mar 2008 14:30:35 -0400 Subject: [rspec-users] ApplicationHelper In-Reply-To: <16149622.post@talk.nabble.com> References: <16149622.post@talk.nabble.com> Message-ID: <6bdacb70803201130x2034e8aav1c3ecee59e8e807d@mail.gmail.com> You could just write specs for ApplicationHelper::distribute -Corey On Wed, Mar 19, 2008 at 3:55 PM, nzook wrote: > > When working with views, I use instance methods of ApplicationHelper: > > # app/helpers/application_helper.rb: > module ApplicationHelper > def distribute(total, min, cutof, list) > [1,2,3] > end > end > > # app/views/planner/_mta_colors.rhtml: > > <% > ... > dist = distribute(total_v_px, 4, 0, colors.collect{|color| color[1]}) > ... > %> > > So to test the distribute method in ApplicationHelper, I have to extend my > spec models: > describe ApplicationHelper do > extend(ApplicationHelper) > it "doesn't find what it's looking for do > distribute(1,2,3,[4,5,6]).should eql([1,2,3]) > end > end > > This could use some documentation. > > > -- > View this message in context: > http://www.nabble.com/ApplicationHelper-tp16149622p16149622.html > 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 > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080320/c47494c2/attachment.html From coreyhaines at gmail.com Thu Mar 20 14:32:26 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Thu, 20 Mar 2008 14:32:26 -0400 Subject: [rspec-users] ApplicationHelper In-Reply-To: <6bdacb70803201130x2034e8aav1c3ecee59e8e807d@mail.gmail.com> References: <16149622.post@talk.nabble.com> <6bdacb70803201130x2034e8aav1c3ecee59e8e807d@mail.gmail.com> Message-ID: <6bdacb70803201132y57c5d161uc50982bbaf2ace2b@mail.gmail.com> If I need to have it interact with the object it is mixed into, I usually put the following above my examples class TestMixer include MyMixIn end or, even, class TestMixer end then, in the spec, TestMixer.include MyMixIn On Thu, Mar 20, 2008 at 2:30 PM, Corey Haines wrote: > You could just write specs for ApplicationHelper::distribute > > -Corey > > > On Wed, Mar 19, 2008 at 3:55 PM, nzook wrote: > > > > > When working with views, I use instance methods of ApplicationHelper: > > > > # app/helpers/application_helper.rb: > > module ApplicationHelper > > def distribute(total, min, cutof, list) > > [1,2,3] > > end > > end > > > > # app/views/planner/_mta_colors.rhtml: > > > > <% > > ... > > dist = distribute(total_v_px, 4, 0, colors.collect{|color| color[1]}) > > ... > > %> > > > > So to test the distribute method in ApplicationHelper, I have to extend > > my > > spec models: > > describe ApplicationHelper do > > extend(ApplicationHelper) > > it "doesn't find what it's looking for do > > distribute(1,2,3,[4,5,6]).should eql([1,2,3]) > > end > > end > > > > This could use some documentation. > > > > > > -- > > View this message in context: > > http://www.nabble.com/ApplicationHelper-tp16149622p16149622.html > > 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 > > > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080320/2fcbc900/attachment.html From james.deville at gmail.com Thu Mar 20 14:36:14 2008 From: james.deville at gmail.com (James Deville) Date: Thu, 20 Mar 2008 11:36:14 -0700 Subject: [rspec-users] ApplicationHelper In-Reply-To: <6bdacb70803201130x2034e8aav1c3ecee59e8e807d@mail.gmail.com> References: <16149622.post@talk.nabble.com> <6bdacb70803201130x2034e8aav1c3ecee59e8e807d@mail.gmail.com> Message-ID: <7666D425-9A4E-4A48-94E1-06067BDDF2FB@gmail.com> That shouldn't be needed. In my spec's it works fine. does: describe ApplicationHelper do it "doesn't find what it's looking for do helper.distribute(1,2,3,[4,5,6]).should eql([1,2,3]) end end work? I know that there was some talk of introducing an explicit helper object on the list. JD On Mar 20, 2008, at 11:30 AM, Corey Haines wrote: > You could just write specs for ApplicationHelper::distribute > > -Corey > > On Wed, Mar 19, 2008 at 3:55 PM, nzook wrote: > > When working with views, I use instance methods of ApplicationHelper: > > # app/helpers/application_helper.rb: > module ApplicationHelper > def distribute(total, min, cutof, list) > [1,2,3] > end > end > > # app/views/planner/_mta_colors.rhtml: > > <% > ... > dist = distribute(total_v_px, 4, 0, colors.collect{|color| color[1]}) > ... > %> > > So to test the distribute method in ApplicationHelper, I have to > extend my > spec models: > describe ApplicationHelper do > extend(ApplicationHelper) > it "doesn't find what it's looking for do > distribute(1,2,3,[4,5,6]).should eql([1,2,3]) > end > end > > This could use some documentation. > > > -- > View this message in context: http://www.nabble.com/ApplicationHelper-tp16149622p16149622.html > 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 > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > 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/20080320/df6316f9/attachment-0001.html From ivo.dancet at gmail.com Thu Mar 20 18:58:51 2008 From: ivo.dancet at gmail.com (Ivo Dancet) Date: Thu, 20 Mar 2008 23:58:51 +0100 Subject: [rspec-users] stories with selenium and the db Message-ID: <51EA967A-0B96-43E7-9B22-ECF763F17207@gmail.com> Hi all Tonight I wanted to test out selenium in a story to test some ajax stuff on a page. After struggling for an hour or two with disappearing database objects I found the solution in a blog post by Kerry Buckley. with the comment included it reads: # Don't add an ActiveRecordSafetyListener, or it'll roll stuff back class Spec::Story::Runner::ScenarioRunner def initialize @listeners = [] end end (the above code belongs in the story helper file, or more specific, for me in my selenium helper file as not every story uses selenium) Ok, that worked, but I don't understand why. Can someone explain what the big difference is with normal stories and can't it be solved in a more cleaner way? That said, it's actually very easy to use selenium in a story. Just in case someone is searching: 1) Add this in the helper file for selenium stories: #################### class Spec::Story::Runner::ScenarioRunner def initialize @listeners = [] end end require 'vendor/plugins/selenium-ruby-client-driver/selenium' $s = Selenium::SeleniumDriver.new("localhost", 4444, "*firefox", "http://localhost:3000 ", 10000); $s.start #################### 2) download the selenium ruby driver, place it in vendor/plugins/ selenium-ruby-client-driver 3) start the selenium server (java -jar selenium-server.jar) 4) start the script/server in test environment That's it, in stories you can now use things like: $s.open("/orders") -gr Ivo From ashley.moran at patchspace.co.uk Thu Mar 20 19:17:49 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 20 Mar 2008 23:17:49 +0000 Subject: [rspec-users] rspec groups? In-Reply-To: References: <57c63afe0803080811l5b4b1e76vae9e234d45eb0ee3@mail.gmail.com> <14FBB390-36F0-44F2-A2CC-15F40058108D@patchspace.co.uk> Message-ID: <70F6A0BE-B06B-45AB-9EBB-2E5A1A9E26BA@patchspace.co.uk> On 20 Mar 2008, at 14:31, Max Williams wrote: > Sorry to be pedantic, but shouldn't that be > "Your needs may differ from mine"? There's no party called 'mine', so > 'mine' has no needs :) A quick google for "those of mine" brings back a google book hit for Shakespeare so maybe Edvard was being poetic :D > Anyway, does anyone have any idea why > -e "the name of a describe block" > > results in 0 tests being run for me? Are you sure you are running the outer-most group, and not an inner group or example? I just tried this file as test.spec.rb: describe "add_descendants_from_xml" do it "should add descendants" do true.should be_false end describe "with attributes" do it "should add attributes too" do false.should be_true end end end * the outer group name works ~/Desktop % spec -e "add_descendants_from_xml" test.spec.rb F 1) 'add_descendants_from_xml should add descendants' FAILED expected false, got true ./test.spec.rb:3: Finished in 0.007168 seconds * testing the name of the inner group fails ~/Desktop % spec -e "with attributes" test.spec.rb Finished in 0.001734 seconds 0 examples, 0 failures * but, as expected ~/Desktop % spec -e "add_descendants_from_xml with attributes" test.spec.rb F 1) 'add_descendants_from_xml with attributes should add attributes too' FAILED expected true, got false ./test.spec.rb:8: Finished in 0.007056 seconds Failing that, are you sure you haven't got a typo? I can't see a problem with the -e option. Ashley From ashley.moran at patchspace.co.uk Thu Mar 20 19:40:58 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 20 Mar 2008 23:40:58 +0000 Subject: [rspec-users] stories with selenium and the db In-Reply-To: <51EA967A-0B96-43E7-9B22-ECF763F17207@gmail.com> References: <51EA967A-0B96-43E7-9B22-ECF763F17207@gmail.com> Message-ID: <2CDA6819-4528-4673-BC17-3D8B1D91C5F1@patchspace.co.uk> On 20 Mar 2008, at 22:58, Ivo Dancet wrote: > Hi all > > Tonight I wanted to test out selenium in a story to test some ajax > stuff on a page. > > After struggling for an hour or two with disappearing database objects > I found the solution in a blog post by Kerry Buckley. > > with the comment included it reads: > > # Don't add an ActiveRecordSafetyListener, or it'll roll stuff back > class Spec::Story::Runner::ScenarioRunner > def initialize > @listeners = [] > end > end > > (the above code belongs in the story helper file, or more specific, > for me in my selenium helper file as not every story uses selenium) > > Ok, that worked, but I don't understand why. Can someone explain what > the big difference is with normal stories and can't it be solved in a > more cleaner way? With specs and Rails Stories, the application is running in the same process as the specs. With selenium remote control (I assume this is what you are using throughout), the specs sending requests to the selenium RC server, which is sending the requests to a *different* process. Therefore, if you create the models in a transaction in the spec process, they will be invisible to the app process (unless you work read-uncommitted...) This one bit me too, I lost a day scratching my head. > That said, it's actually very easy to use selenium in a story. Just in > case someone is searching: > > 1) Add this in the helper file for selenium stories: > > #################### > class Spec::Story::Runner::ScenarioRunner > def initialize > @listeners = [] > end > end I just commented out the line that includes Rails Stories from helper.rb. It's not needed at all with Selenium. > require 'vendor/plugins/selenium-ruby-client-driver/selenium' > > $s = Selenium::SeleniumDriver.new("localhost", 4444, "*firefox", "http://localhost:3000 > ", 10000); > $s.start > > #################### > > 2) download the selenium ruby driver, place it in vendor/plugins/ > selenium-ruby-client-driver There's also a nice gem you can get with (note the capitalisation) # gem install Selenium Then you can do step 3 as just % selenium > 3) start the selenium server (java -jar selenium-server.jar) > 4) start the script/server in test environment > > That's it, in stories you can now use things like: $s.open("/orders") I've been working on something pretty similar for a client. This is what I've made work so far: * browser session per story run, for some isolation (uses a custom listener) * browser window stays open on failed scenarios * auto reset database before scenarios (uses the listener again) * a much neater syntax for the selenium ruby driver, such as (OTTOMH) browser.username_text_field.type("fred") browser.submit_button.click browser.should land_on_page("/home") # works with redirects I'm pretty sure they will let me open source all the code when the project is complete. Unfortunately it's a bit of a hectic right now but hopefully in the second half of May I'll get chance to bundle it up and push it back to the community. It's a bit frustrating not being able to do that now, but at least it means by then my selenium- story runner bridge will have been bashed through a decent sized app by (if everyone uses it) four developers. Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080320/512057e1/attachment.html From pietromas at gmail.com Thu Mar 20 21:03:23 2008 From: pietromas at gmail.com (Pietro Mascagni) Date: Fri, 21 Mar 2008 01:03:23 +0000 Subject: [rspec-users] Oh inheritacne, wherefore art thou Message-ID: Is there anyway to achieve inheritance of specifications? Suppose I had an action like def index filter = params[:filter] ? params[:filter] : '%' order = params[:order] ? params[:order] : 'created_at DESC' @posts = Post.find(:conditions => "title LIKE #{filter}", :order => order) ... end Now I might have half a dozen specs for this action that test it when neither :filter nor :order are supplied as params. But now what I would like to do is test it when one, other or both of the params are passed to the action. Most of the specs will probably not need to change, but I would still like to run them in the case where params are supplied, just to be sure there are no unwanted side effects. Probably only one or two of the specs need to be modified, for example to assert that only Posts matching the filter are returned. It seems to me that a nice way to do this would be if descriptions could be extended. So I could have a basic description of the action describe 'test index w/o params' do ... it 'should return the right posts' end and would then be able to extend it for each case, e.g. describe 'test index with filter param' do; extends('test index w/o params') ... it 'should return the right posts' # overrides example in base spec end So this tests everything just like the base spec did, but changes/overrides one of the examples to correctly assert that the right posts are returned, thus giving me good confidence that the presence of the param does'nt cause breakage in places I might not normally bother to test because of my knowledge of the implementation. I can't find anything online to this effect. So far the best I have been able to do is write shared descriptions but this gets messy very quickly and causes all sorts of problems that I think makes it undesirable. Can anyone suggest a nice way for me to achieve the above. From coreyhaines at gmail.com Thu Mar 20 23:47:39 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Thu, 20 Mar 2008 23:47:39 -0400 Subject: [rspec-users] Oh inheritacne, wherefore art thou In-Reply-To: References: Message-ID: <6bdacb70803202047h746c6488je1e034d6f919e2ac@mail.gmail.com> Look up SharedExamplesGroups http://rspec.info/rdoc/ On Thu, Mar 20, 2008 at 9:03 PM, Pietro Mascagni wrote: > Is there anyway to achieve inheritance of specifications? > > Suppose I had an action like > > def index > filter = params[:filter] ? params[:filter] : '%' > order = params[:order] ? params[:order] : 'created_at DESC' > @posts = Post.find(:conditions => "title LIKE #{filter}", :order => > order) > ... > end > > Now I might have half a dozen specs for this action that test it when > neither :filter nor :order are supplied as params. But now what I > would like to do is test it when one, other or both of the params are > passed to the action. Most of the specs will probably not need to > change, but I would still like to run them in the case where params > are supplied, just to be sure there are no unwanted side effects. > Probably only one or two of the specs need to be modified, for example > to assert that only Posts matching the filter are returned. > > It seems to me that a nice way to do this would be if descriptions > could be extended. So I could have a basic description of the action > > describe 'test index w/o params' do > ... > it 'should return the right posts' > end > > and would then be able to extend it for each case, e.g. > > describe 'test index with filter param' do; > extends('test index w/o params') > ... > it 'should return the right posts' # overrides example in base spec > end > > So this tests everything just like the base spec did, but > changes/overrides one of the examples to correctly assert that the > right posts are returned, thus giving me good confidence that the > presence of the param does'nt cause breakage in places I might not > normally bother to test because of my knowledge of the implementation. > > I can't find anything online to this effect. So far the best I have > been able to do is write shared descriptions but this gets messy very > quickly and causes all sorts of problems that I think makes it > undesirable. > > Can anyone suggest a nice way for me to achieve the above. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080320/75a24a18/attachment-0001.html From pergesu at gmail.com Fri Mar 21 00:01:05 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 20 Mar 2008 21:01:05 -0700 Subject: [rspec-users] Oh inheritacne, wherefore art thou In-Reply-To: References: Message-ID: <810a540e0803202101w54149553y4f4c6be394ed862b@mail.gmail.com> On Thu, Mar 20, 2008 at 6:03 PM, Pietro Mascagni wrote: > Is there anyway to achieve inheritance of specifications? > > Suppose I had an action like > > def index > filter = params[:filter] ? params[:filter] : '%' > order = params[:order] ? params[:order] : 'created_at DESC' > @posts = Post.find(:conditions => "title LIKE #{filter}", :order => order) > ... > end If you use shared example groups, you can do stuff like describe FooController do it_should_behave_like "super filtered out thing" end The docs at rspec.info have examples. As a side note, you can shorten that action (and get rid of the ternary operators) by doing: filter = params[:filter] || '%' order = params[:order] || 'created_at DESC' Pat From mailing_lists at railsnewbie.com Fri Mar 21 00:07:31 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 21 Mar 2008 00:07:31 -0400 Subject: [rspec-users] Combining autotest, rspec, rspec_on_rails and spec-server In-Reply-To: <0A9F76B5-E1C0-4934-A664-22F75AE26C76@digitalphenom.com> References: <0A9F76B5-E1C0-4934-A664-22F75AE26C76@digitalphenom.com> Message-ID: On Mar 20, 2008, at 8:56 AM, Anthony Carlos wrote: > Hello, > > I've been trying to google the definitive way to combine autotest, > rspec, and spec-server, but to no avail. It seems like there are lots > of suggestions from old versions. Furthermore, some commands such as > rake:autotest don't seem to be around anymore. > > So, is it required to install ZenTest as a gem? I have version 3.9.1. > I believe this gets me the autotest command that I can issue on the > command line. Yep. > > Must I install rspec as a gem? At first, I tried to not install it as > a gem and followed the instructions from http://rspec.info/ > documentation/rails/install.html. I installed rspec as a plugin to my > Rails project and used just rake spec, but found that unless I > install rspec as a gem, there is no spec command for the command > line. That might make it easier to run my specs with options. So, I If you have both rspec and rspec_on_rails installed in vendor/ plugins, and have issued a "ruby script/generate rspec" command, you shouldn't need the gem (in the rails project, at least) > installed rspec 1.1.3 as a gem. That provided me with the spec > command that I can issue on the command line. > > What is the recommended way to start the spec-server? ./script/ > spec_server or rake:spec:server:start? I've tried both and cannot > discern the differences. There is no difference, except that the one gives you the command line back. I'd recommend starting it directly. You *will* need to restart it once in a while. > > Finally, what is the recommended way to run my specs? spec -O spec/ > spec.opts spec/XXX or rake spec:XXX ? I've edited spec.opts to > include --drb on the first line. The rake method didn't seem to use > the spec-server, despite this suggestion. So, I've tried the spec > command above. It still didn't seem to use spec-server. However, when > I use spec -X -O spec/spec.opts, it does seem to use the spec_server. > I'm glad I'm able to finally use the spec_server, but it's a real > drag switching back to my command line to issue this command after > every save. That's exactly why I want to run autotest. Yeah. The spec server is great, but I've found it to be buggy (as have others). Recently I've noticed that it doesn't play well with shared example groups. Usually what I do is run a single spec file with -X (or --drb) and -c (--color): script/spec foo_spec.rb -X -c If I have any problems, I'll first try restarting the spec_server (which I have running in a seperate term window). Otherwise, I'll just run the file individually. When I'm done with each spec file individually, I'll go and run rake spec, which recreates the test database and so on, and runs the whole suite of specs. > > What is the recommended way to run autotest? autotest or rake > spec:autotest (I've seen this on google, but the command itself no just plain old autotest. > longer appears when I run rake -T spec. Is there something wrong with > my setup? Am I supposed to have a rake task for this or is it > deprecated). Without an available rake task, I am forced to try the > autotest command. However, I don't think that the autotest command > accepts any options that tell it to use the spec_server. I tried > autotest -X, and of course, my spec.opts file does already say --drb > in the first line. Oh - there was a bug in the last stable release with --drb (or -X) in spec.opts: http://rspec.lighthouseapp.com/projects/5645/tickets/293-drb-does-not- work-from-spec-opts It's been resolved in trunk. Scott -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080321/1ac793e4/attachment.html From mailing_lists at railsnewbie.com Fri Mar 21 00:16:30 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 21 Mar 2008 00:16:30 -0400 Subject: [rspec-users] Oh inheritacne, wherefore art thou In-Reply-To: <6bdacb70803202047h746c6488je1e034d6f919e2ac@mail.gmail.com> References: <6bdacb70803202047h746c6488je1e034d6f919e2ac@mail.gmail.com> Message-ID: On Mar 20, 2008, at 11:47 PM, Corey Haines wrote: > Look up SharedExamplesGroups > > http://rspec.info/rdoc/ Yep - and "it_should_behave_like". SharedExampleGroups subclass Module, so it fits in with the "inheritance" idea quite nicely. Scott > > > On Thu, Mar 20, 2008 at 9:03 PM, Pietro Mascagni > wrote: > Is there anyway to achieve inheritance of specifications? > > Suppose I had an action like > > def index > filter = params[:filter] ? params[:filter] : '%' > order = params[:order] ? params[:order] : 'created_at DESC' > @posts = Post.find(:conditions => "title LIKE #{filter}", :order > => order) > ... > end > > Now I might have half a dozen specs for this action that test it when > neither :filter nor :order are supplied as params. But now what I > would like to do is test it when one, other or both of the params are > passed to the action. Most of the specs will probably not need to > change, but I would still like to run them in the case where params > are supplied, just to be sure there are no unwanted side effects. > Probably only one or two of the specs need to be modified, for example > to assert that only Posts matching the filter are returned. > > It seems to me that a nice way to do this would be if descriptions > could be extended. So I could have a basic description of the action > > describe 'test index w/o params' do > ... > it 'should return the right posts' > end > > and would then be able to extend it for each case, e.g. > > describe 'test index with filter param' do; > extends('test index w/o params') > ... > it 'should return the right posts' # overrides example in base spec > end > > So this tests everything just like the base spec did, but > changes/overrides one of the examples to correctly assert that the > right posts are returned, thus giving me good confidence that the > presence of the param does'nt cause breakage in places I might not > normally bother to test because of my knowledge of the implementation. > > I can't find anything online to this effect. So far the best I have > been able to do is write shared descriptions but this gets messy very > quickly and causes all sorts of problems that I think makes it > undesirable. > > Can anyone suggest a nice way for me to achieve the above. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > 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/20080321/63644200/attachment.html From joe at pinkpucker.net Fri Mar 21 02:29:57 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Thu, 20 Mar 2008 23:29:57 -0700 Subject: [rspec-users] cleaning up after stories In-Reply-To: References: <20080320050101.GD8816@uivelo.tilus.net> Message-ID: On Thu, Mar 20, 2008 at 4:02 AM, Rick DeNatale wrote: > On 3/20/08, Tero Tilus wrote: > > On Wed, 19 Mar 2008, Joe Van Dyk wrote: > > > do I have to manually clear out the database after a story runs? > > > > > > I'm wondering the same, but with specs. Database gets dirty and > > tests start to fail when i repeatedly do rake spec. > > >From what I've seen, the test infrastructure (which RSpec takes from > the Rails Test::Unit based code) relies on fixtures to initialize the > database BEFORE running tests. > > The setup code clears any tables for which fixtures are declared, then > loads those fixtures. > > It's a little counterintuitive that the tables don't get cleared AFTER > the test, but I guess it makes sense in that without clearing before > loading those tables wouldn't be in a known state at the beginning of > the test. > > What I've done is to have fixtures with a single record for tables I > want to 'clear'. Alternatively you can do something like: > > MyModel.delete_all > > For any tables you want to clear, in the before block for tests, or in > the xxx_story.rb for stories. Seems like the tables should get cleared before and after the tests? From joe at pinkpucker.net Fri Mar 21 02:32:35 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Thu, 20 Mar 2008 23:32:35 -0700 Subject: [rspec-users] sharing story steps In-Reply-To: <8d961d900803200205t258fe0e1n1b4478a9099c1e8b@mail.gmail.com> References: <8d961d900803200205t258fe0e1n1b4478a9099c1e8b@mail.gmail.com> Message-ID: On Thu, Mar 20, 2008 at 2:05 AM, aslak hellesoy wrote: > On Thu, Mar 20, 2008 at 5:44 AM, Joe Van Dyk wrote: > > Hi, > > > > How can I have a common set of steps that all my stories share? > > > > i.e. My stories often start out looking like this: > > > > Given a user Joe > > Given a user Jordan > > > > then: > > put this in steps/users.rb: rails_proj/stories/steps or just rails_proj/steps? > steps_for(:user) do > > > Given("a user $username") do |username| > > @users ||= {} > > @user_sessions ||= {} > > @users[username] = create_user(:username => username) > > @user_sessions[username] = login_as(@users[username]) > > end > > end > > Now, in your file running stories: > > with_steps_for(:user, :project, :comment) do > ... > > end > > > > > I want to share that Given with all my stories. Or is there a better > > way to do it? > > > > At one of our current projects in BEKK we have come up with a > convention for naming and grouping steps. It simply follows the same > convention as the controllers for file names, and in each file we put > all steps that are relevant to a given controller. Makes sense. > In the run file we simply run stories with_steps_for all of them. > > Try it out, I think you'll like it. Thanks, I will. From joe at pinkpucker.net Fri Mar 21 02:35:32 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Thu, 20 Mar 2008 23:35:32 -0700 Subject: [rspec-users] Attachment-fu + Story Runner In-Reply-To: References: <8D52CE6F-5E7A-47E7-A436-7098186978E3@tenner.org> <71166b3b0712110639p3acb5c3am16cddc67a9cb619d@mail.gmail.com> <14291797.post@talk.nabble.com> <57c63afe0712120554j147ffbe6lcff9faf8d5af743f@mail.gmail.com> Message-ID: On Thu, Mar 20, 2008 at 3:34 AM, Rick DeNatale wrote: > On 3/20/08, Joe Van Dyk wrote: > > What was the resolution on this? How do you people test uploads with > > rspec stories? > > I submitted a Rails patch to address the underlying problem > http://dev.rubyonrails.org/ticket/11091 > > It got in as changeset 8978 and should be in edge rails. Would it be worth it to monkeypatch that patch into rspec? From lists at ruby-forum.com Fri Mar 21 05:15:44 2008 From: lists at ruby-forum.com (Max Williams) Date: Fri, 21 Mar 2008 10:15:44 +0100 Subject: [rspec-users] rspec groups? In-Reply-To: <70F6A0BE-B06B-45AB-9EBB-2E5A1A9E26BA@patchspace.co.uk> References: <57c63afe0803080811l5b4b1e76vae9e234d45eb0ee3@mail.gmail.com> <14FBB390-36F0-44F2-A2CC-15F40058108D@patchspace.co.uk> <70F6A0BE-B06B-45AB-9EBB-2E5A1A9E26BA@patchspace.co.uk> Message-ID: > Are you sure you are running the outer-most group, and not an inner > group or example? I just tried this file as test.spec.rb: > describe "add_descendants_from_xml" do > it "should add descendants" do > true.should be_false > end > > describe "with attributes" do > it "should add attributes too" do > false.should be_true > end > end > end > > * the outer group name works Ah - that'll be the problem then: i was trying to run an inner group. I tend to wrap all the tests in a single file up in a single block, and then lots of nested blocks inside. thanks max -- Posted via http://www.ruby-forum.com/. From tmhaines at gmail.com Fri Mar 21 06:24:43 2008 From: tmhaines at gmail.com (Tim Haines) Date: Fri, 21 Mar 2008 23:24:43 +1300 Subject: [rspec-users] Pending Scenarios Message-ID: Hi there, newb q: The "pending" support for spec's and steps is nice. I'm just wondering why a scenario itself can't be pending? I.e. it seems to me like it would be nice to write up scenario titles for scenarios as you think of them, and for low-priority fringe scenarios leave the steps unwritten until it comes time to implement the scenario? Is there a way to add comments to the plain text file in plain text stories? Cheers, Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080321/b626245d/attachment.html From dchelimsky at gmail.com Fri Mar 21 08:46:00 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 21 Mar 2008 07:46:00 -0500 Subject: [rspec-users] Attachment-fu + Story Runner In-Reply-To: References: <71166b3b0712110639p3acb5c3am16cddc67a9cb619d@mail.gmail.com> <14291797.post@talk.nabble.com> <57c63afe0712120554j147ffbe6lcff9faf8d5af743f@mail.gmail.com> Message-ID: <57c63afe0803210546q314323b4g63d5029a71d64291@mail.gmail.com> On Fri, Mar 21, 2008 at 1:35 AM, Joe Van Dyk wrote: > On Thu, Mar 20, 2008 at 3:34 AM, Rick DeNatale wrote: > > On 3/20/08, Joe Van Dyk wrote: > > > What was the resolution on this? How do you people test uploads with > > > rspec stories? > > > > I submitted a Rails patch to address the underlying problem > > http://dev.rubyonrails.org/ticket/11091 > > > > It got in as changeset 8978 and should be in edge rails. > > Would it be worth it to monkeypatch that patch into rspec? Why would we do that? It's already in edge rails. > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Mar 21 09:38:59 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 21 Mar 2008 08:38:59 -0500 Subject: [rspec-users] Pending Scenarios In-Reply-To: References: Message-ID: <57c63afe0803210638gc4f4eddj30379b603c0353c0@mail.gmail.com> On Fri, Mar 21, 2008 at 5:24 AM, Tim Haines wrote: > Hi there, > > newb q: The "pending" support for spec's and steps is nice. I'm just > wondering why a scenario itself can't be pending? Because nobody asked for it :) Wanna file a feature request at lighthouse? http://rspec.lighthouseapp.com > I.e. it seems to me like > it would be nice to write up scenario titles for scenarios as you think of > them, and for low-priority fringe scenarios leave the steps unwritten until > it comes time to implement the scenario? > > Is there a way to add comments to the plain text file in plain text stories? Anything between the line that begins with Story: and the first line that begins with Scenario: will be part of the story narrative. Sort of like a comment, but it gets printed out. So I sometimes add additional commentary there to provide context around the "As a .., I want ..., So that ..." statement. Anything after the first Scenario: that does not begin with any of the keywords (Scenario:, Given, When, Then, And) is simply ignored, so you can put comments between steps and they will not be processed. I would not go crazy with this at this point because there has been a request to support multiline text in plain text stories, at which point your comments might accidentally get interpreted. Perhaps now is the time to devise a formal "comment indicator." I think the obvious choice would be the same one we use in Ruby: # Given this step # this is a comment When this other step etc Thoughts? Cheers, David > > Cheers, > > Tim. > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Fri Mar 21 10:35:48 2008 From: aslak.hellesoy at gmail.com (=?UTF-8?Q?Aslak_Helles=C3=B8y?=) Date: Fri, 21 Mar 2008 15:35:48 +0100 Subject: [rspec-users] sharing story steps In-Reply-To: References: <8d961d900803200205t258fe0e1n1b4478a9099c1e8b@mail.gmail.com> Message-ID: On 21. mars. 2008, at 07.32, "Joe Van Dyk" wrote: > On Thu, Mar 20, 2008 at 2:05 AM, aslak hellesoy > wrote: >> On Thu, Mar 20, 2008 at 5:44 AM, Joe Van Dyk >> wrote: >>> Hi, >>> >>> How can I have a common set of steps that all my stories share? >>> >>> i.e. My stories often start out looking like this: >>> >>> Given a user Joe >>> Given a user Jordan >>> >>> then: >> >> put this in steps/users.rb: > > rails_proj/stories/steps or just rails_proj/steps? Whichever you like. I prefer the first one. Aslak > > >> steps_for(:user) do >> >>> Given("a user $username") do |username| >>> @users ||= {} >>> @user_sessions ||= {} >>> @users[username] = create_user(:username => username) >>> @user_sessions[username] = login_as(@users[username]) >>> end >> >> end >> >> Now, in your file running stories: >> >> with_steps_for(:user, :project, :comment) do >> ... >> >> end >> >>> >>> I want to share that Given with all my stories. Or is there a >>> better >>> way to do it? >>> >> >> At one of our current projects in BEKK we have come up with a >> convention for naming and grouping steps. It simply follows the same >> convention as the controllers for file names, and in each file we put >> all steps that are relevant to a given controller. > > Makes sense. > >> In the run file we simply run stories with_steps_for all of them. >> >> Try it out, I think you'll like it. > > Thanks, I will. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From zach.dennis at gmail.com Fri Mar 21 11:02:47 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 21 Mar 2008 11:02:47 -0400 Subject: [rspec-users] Pending Scenarios In-Reply-To: <57c63afe0803210638gc4f4eddj30379b603c0353c0@mail.gmail.com> References: <57c63afe0803210638gc4f4eddj30379b603c0353c0@mail.gmail.com> Message-ID: <85d99afe0803210802j74b36b94l96494ef54c70497b@mail.gmail.com> On Fri, Mar 21, 2008 at 9:38 AM, David Chelimsky wrote: > On Fri, Mar 21, 2008 at 5:24 AM, Tim Haines wrote: > > Hi there, > > > > newb q: The "pending" support for spec's and steps is nice. I'm just > > wondering why a scenario itself can't be pending? > > Because nobody asked for it :) > > Wanna file a feature request at lighthouse? http://rspec.lighthouseapp.com > > > > I.e. it seems to me like > > it would be nice to write up scenario titles for scenarios as you think of > > them, and for low-priority fringe scenarios leave the steps unwritten until > > it comes time to implement the scenario? > > > > Is there a way to add comments to the plain text file in plain text stories? > > Anything between the line that begins with Story: and the first line > that begins with Scenario: will be part of the story narrative. Sort > of like a comment, but it gets printed out. So I sometimes add > additional commentary there to provide context around the "As a .., I > want ..., So that ..." statement. > > Anything after the first Scenario: that does not begin with any of the > keywords (Scenario:, Given, When, Then, And) is simply ignored, so you > can put comments between steps and they will not be processed. > > I would not go crazy with this at this point because there has been a > request to support multiline text in plain text stories, at which > point your comments might accidentally get interpreted. > > Perhaps now is the time to devise a formal "comment indicator." I > think the obvious choice would be the same one we use in Ruby: # > > Given this step > # this is a comment > When this other step > etc > > Thoughts? > Rather than anything that does not start with Scenario|Given|When|Then|And being treated as a comment it seems more future-proof if we just say that any line whose first non-whitespace character is a # ... is a comment. Although I'm not crazy about inserting comments into plain text story files, I think that there are times when it would indeed be useful and I'd want to give the developer or customer the ability to make the call when they might need it. Zach -- Zach Dennis http://www.continuousthinking.com From zach.dennis at gmail.com Fri Mar 21 11:03:29 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 21 Mar 2008 11:03:29 -0400 Subject: [rspec-users] sharing story steps In-Reply-To: References: <8d961d900803200205t258fe0e1n1b4478a9099c1e8b@mail.gmail.com> Message-ID: <85d99afe0803210803o24de2dd6if5b671fbb8864488@mail.gmail.com> On Fri, Mar 21, 2008 at 10:35 AM, Aslak Helles?y wrote: > > > On 21. mars. 2008, at 07.32, "Joe Van Dyk" wrote: > > > On Thu, Mar 20, 2008 at 2:05 AM, aslak hellesoy > > wrote: > >> On Thu, Mar 20, 2008 at 5:44 AM, Joe Van Dyk > >> wrote: > >>> Hi, > >>> > >>> How can I have a common set of steps that all my stories share? > >>> > >>> i.e. My stories often start out looking like this: > >>> > >>> Given a user Joe > >>> Given a user Jordan > >>> > >>> then: > >> > >> put this in steps/users.rb: > > > > rails_proj/stories/steps or just rails_proj/steps? > > Whichever you like. I prefer the first one. I prefer the first one as well, -- Zach Dennis http://www.continuousthinking.com From dchelimsky at gmail.com Fri Mar 21 11:18:01 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 21 Mar 2008 10:18:01 -0500 Subject: [rspec-users] Pending Scenarios In-Reply-To: <85d99afe0803210802j74b36b94l96494ef54c70497b@mail.gmail.com> References: <57c63afe0803210638gc4f4eddj30379b603c0353c0@mail.gmail.com> <85d99afe0803210802j74b36b94l96494ef54c70497b@mail.gmail.com> Message-ID: <57c63afe0803210818j6a2fd6c2qe5a3e8d10ce1f66a@mail.gmail.com> On Fri, Mar 21, 2008 at 10:02 AM, Zach Dennis wrote: > > On Fri, Mar 21, 2008 at 9:38 AM, David Chelimsky wrote: > > Perhaps now is the time to devise a formal "comment indicator." I > > think the obvious choice would be the same one we use in Ruby: # > > > > Given this step > > # this is a comment > > When this other step > > etc > > > > Thoughts? > > > > Rather than anything that does not start with > Scenario|Given|When|Then|And being treated as a comment it seems more > future-proof if we just say that any line whose first non-whitespace > character is a # ... is a comment. Great idea Zach! Glad you thought of it ;) Cheers, David From rick.denatale at gmail.com Fri Mar 21 11:56:30 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 21 Mar 2008 11:56:30 -0400 Subject: [rspec-users] Pending Scenarios In-Reply-To: <57c63afe0803210818j6a2fd6c2qe5a3e8d10ce1f66a@mail.gmail.com> References: <57c63afe0803210638gc4f4eddj30379b603c0353c0@mail.gmail.com> <85d99afe0803210802j74b36b94l96494ef54c70497b@mail.gmail.com> <57c63afe0803210818j6a2fd6c2qe5a3e8d10ce1f66a@mail.gmail.com> Message-ID: On 3/21/08, David Chelimsky wrote: > On Fri, Mar 21, 2008 at 10:02 AM, Zach Dennis wrote: > > > > On Fri, Mar 21, 2008 at 9:38 AM, David Chelimsky wrote: > > > > Perhaps now is the time to devise a formal "comment indicator." I > > > think the obvious choice would be the same one we use in Ruby: # > > > > > > Given this step > > > # this is a comment > > > When this other step > > > etc > > > > > > Thoughts? > > > > > > > Rather than anything that does not start with > > Scenario|Given|When|Then|And being treated as a comment it seems more > > future-proof if we just say that any line whose first non-whitespace > > character is a # ... is a comment. > > > Great idea Zach! Glad you thought of it ;) Doesn't it already work this way? If I "comment out" lines this way in a plain text story, they seem to be totally ignored. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From dchelimsky at gmail.com Fri Mar 21 12:31:33 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 21 Mar 2008 11:31:33 -0500 Subject: [rspec-users] Pending Scenarios In-Reply-To: References: <57c63afe0803210638gc4f4eddj30379b603c0353c0@mail.gmail.com> <85d99afe0803210802j74b36b94l96494ef54c70497b@mail.gmail.com> <57c63afe0803210818j6a2fd6c2qe5a3e8d10ce1f66a@mail.gmail.com> Message-ID: <57c63afe0803210931n6b0f9a9bs99a1c65452c2643b@mail.gmail.com> On Fri, Mar 21, 2008 at 10:56 AM, Rick DeNatale wrote: > > On 3/21/08, David Chelimsky wrote: > > On Fri, Mar 21, 2008 at 10:02 AM, Zach Dennis wrote: > > > > > > On Fri, Mar 21, 2008 at 9:38 AM, David Chelimsky wrote: > > > > > > Perhaps now is the time to devise a formal "comment indicator." I > > > > think the obvious choice would be the same one we use in Ruby: # > > > > > > > > Given this step > > > > # this is a comment > > > > When this other step > > > > etc > > > > > > > > Thoughts? > > > > > > > > > > Rather than anything that does not start with > > > Scenario|Given|When|Then|And being treated as a comment it seems more > > > future-proof if we just say that any line whose first non-whitespace > > > character is a # ... is a comment. > > > > > > Great idea Zach! Glad you thought of it ;) > > Doesn't it already work this way? > > If I "comment out" lines this way in a plain text story, they seem to > be totally ignored. Yes but that's not because it is explicitly ignored based on that character. What we're discussing here is making it explicit. From coreyhaines at gmail.com Fri Mar 21 12:39:52 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Fri, 21 Mar 2008 12:39:52 -0400 Subject: [rspec-users] Pending Scenarios In-Reply-To: References: <57c63afe0803210638gc4f4eddj30379b603c0353c0@mail.gmail.com> <85d99afe0803210802j74b36b94l96494ef54c70497b@mail.gmail.com> <57c63afe0803210818j6a2fd6c2qe5a3e8d10ce1f66a@mail.gmail.com> Message-ID: <6bdacb70803210939q236588f8yaf5033be6c9016e7@mail.gmail.com> On Fri, Mar 21, 2008 at 11:56 AM, Rick DeNatale wrote: > > Doesn't it already work this way? > > If I "comment out" lines this way in a plain text story, they seem to > be totally ignored. > I believe that is because the current behavior is that anything that doesn't start with a keyword is considered a comment. -Corey -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080321/822ba1f1/attachment.html From coreyhaines at gmail.com Fri Mar 21 12:44:55 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Fri, 21 Mar 2008 12:44:55 -0400 Subject: [rspec-users] Pending Scenarios In-Reply-To: <85d99afe0803210802j74b36b94l96494ef54c70497b@mail.gmail.com> References: <57c63afe0803210638gc4f4eddj30379b603c0353c0@mail.gmail.com> <85d99afe0803210802j74b36b94l96494ef54c70497b@mail.gmail.com> Message-ID: <6bdacb70803210944s3dcf5e18v502ef54495474e6d@mail.gmail.com> All, On Fri, Mar 21, 2008 at 11:02 AM, Zach Dennis wrote: > > Perhaps now is the time to devise a formal "comment indicator." I > > think the obvious choice would be the same one we use in Ruby: # > > > > Given this step > > # this is a comment > > When this other step > > etc > > > > Thoughts? > > > Just a counter-thought off the top of my head. I like the idea that the plain text stories are just that: plain text. If we start adding comment tokens, then it just feels a bit like it is pulling away from plain text. It seems like this really would only contribute to the ease-of-implementation for multi-line steps. Could you instead have a token for multi-line, some sort of (shudder) line continuation character? -Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080321/79e73398/attachment.html From ashley.moran at patchspace.co.uk Fri Mar 21 14:24:24 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 21 Mar 2008 18:24:24 +0000 Subject: [rspec-users] sharing story steps In-Reply-To: References: <8d961d900803200205t258fe0e1n1b4478a9099c1e8b@mail.gmail.com> Message-ID: <1FDB7B90-2948-4B6B-A3E7-BF71A6CA0253@patchspace.co.uk> On Mar 21, 2008, at 2:35 pm, Aslak Helles?y wrote: >> rails_proj/stories/steps or just rails_proj/steps? > > Whichever you like. I prefer the first one. I ended up creating RAILS_ROOT/stories/stories and RAILS_ROOT/stories/ steps I don't like the duplication of "stories" but I prefer it to (apparently) having a group of stories called "steps". I also have a folder called RAILS_ROOT/stories/story_support where I've dumped selenium extensions etc. But arguably I should pull that out into vendor/gems or something. Ashley From ashley.moran at patchspace.co.uk Fri Mar 21 14:50:44 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 21 Mar 2008 18:50:44 +0000 Subject: [rspec-users] Pending Scenarios In-Reply-To: <57c63afe0803210818j6a2fd6c2qe5a3e8d10ce1f66a@mail.gmail.com> References: <57c63afe0803210638gc4f4eddj30379b603c0353c0@mail.gmail.com> <85d99afe0803210802j74b36b94l96494ef54c70497b@mail.gmail.com> <57c63afe0803210818j6a2fd6c2qe5a3e8d10ce1f66a@mail.gmail.com> Message-ID: <90F8BCC9-F5EC-4507-B2BD-732EE5E07C03@patchspace.co.uk> On Mar 21, 2008, at 3:18 pm, David Chelimsky wrote: >> Rather than anything that does not start with >> Scenario|Given|When|Then|And being treated as a comment it seems more >> future-proof if we just say that any line whose first non-whitespace >> character is a # ... is a comment. > > Great idea Zach! Glad you thought of it ;) I was about to say I've got mixed feelings about this because I always considered the plain text story files to be a publishable document. But now I've noticed there's a class Story::HtmlFormatter hidden away in the gem that could be used to prepare that, which means the .story files are really just another source file (so I vote +1 for the /^ \s*#/ comment rule). Raises the question, though - how do you *use* the story formatters? Can you do it through the spec command somehow? I've never seen anything about them. Ashley From lists at ruby-forum.com Sat Mar 22 06:45:23 2008 From: lists at ruby-forum.com (Asdas Safasf) Date: Sat, 22 Mar 2008 11:45:23 +0100 Subject: [rspec-users] Win MoNeY Online Message-ID: <4d7dc048c72f52203f366e87e2992ff3@ruby-forum.com> Make money online:the first thing you have to do is to enter: http://bux.to/?r=costel333 register then start making money by clicking on surf ads and visit sites from the list for 30s, for each site that you visit you receive 0.01$.The secret for making serious money is to gather referrals which are users that register on bux.to using the link you gave them...so for each site they visit both you and them win these money......Make notice that this is one of the few sites that really pay you the money you earn...all you need is a VISA card....good luck...PS: if you want to know a good trick of how to make money easier take my messenger id:costel333...... -- Posted via http://www.ruby-forum.com/. From omen.king at gmail.com Sat Mar 22 09:10:53 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Sat, 22 Mar 2008 09:10:53 -0400 Subject: [rspec-users] Win MoNeY Online In-Reply-To: <4d7dc048c72f52203f366e87e2992ff3@ruby-forum.com> References: <4d7dc048c72f52203f366e87e2992ff3@ruby-forum.com> Message-ID: Easy money was full working specs?How can I go wrong!!??!! On Sat, Mar 22, 2008 at 6:45 AM, Asdas Safasf wrote: > Make money online:the first thing you have to do is to enter: > http://bux.to/?r=costel333 register then start making money by > clicking on surf ads and visit sites from the list for 30s, for each > site that you visit you receive 0.01$.The secret for making serious > money is to gather referrals which are users that register on bux.to > using the link you gave them...so for each site they visit both you and > them win these money......Make notice that this is one of the few sites > that really pay you the money you earn...all you need is a VISA > card....good luck...PS: if you want to know a good trick of how to make > money easier take my messenger id:costel333...... > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > 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/20080322/1ae91a99/attachment.html From coreyhaines at gmail.com Sat Mar 22 09:18:43 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sat, 22 Mar 2008 09:18:43 -0400 Subject: [rspec-users] Win MoNeY Online In-Reply-To: <4d7dc048c72f52203f366e87e2992ff3@ruby-forum.com> References: <4d7dc048c72f52203f366e87e2992ff3@ruby-forum.com> Message-ID: <6bdacb70803220618n77b0ff37j6800922979846e5b@mail.gmail.com> Make notice that this is one of the few sites that really pay you the money you earn...all you need is a VISA card +1 On Sat, Mar 22, 2008 at 6:45 AM, Asdas Safasf wrote: > Make money online:the first thing you have to do is to enter: > http://bux.to/?r=costel333 register then start making money by > clicking on surf ads and visit sites from the list for 30s, for each > site that you visit you receive 0.01$.The secret for making serious > money is to gather referrals which are users that register on bux.to > using the link you gave them...so for each site they visit both you and > them win these money......Make notice that this is one of the few sites > that really pay you the money you earn...all you need is a VISA > card....good luck...PS: if you want to know a good trick of how to make > money easier take my messenger id:costel333...... > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080322/c845c042/attachment-0001.html From dhoefler at gmail.com Sat Mar 22 12:17:43 2008 From: dhoefler at gmail.com (Dave) Date: Sat, 22 Mar 2008 11:17:43 -0500 Subject: [rspec-users] Foreign characters in strings Message-ID: <7d983dfe0803220917l3380877creaa694993bb232a1@mail.gmail.com> Hi there, I have a test that checks to make sure a string has been URI.unescape'd. I'm testing two different strings. One string that I'm dealing with contains foreign characters, and the other string contains 'regular' English characters. Here are the tests: describe Song, "should be valid" do before(:each) do @song = Song.new end it "when location= has been sanitized dealing with foreign characters" do @song.location = "file://localhost/Users/dave/Music/iTunes/iTunes%20Music/Sigur%20Ros/Agaetis%20Byrjun/05%20Ny%CC%81%20batteri%CC%81.m4a" @song.save @song.location.should == "/Users/dave/Music/iTunes/iTunes Music/Sigur Ros/Agaetis Byrjun/05 N? batter?.m4a" end it "when location= has been sanitized dealing with non-foreign characters" do @song.location = "file://localhost/Users/dave/Music/iTunes/iTunes%20Music/Mogwai/Mr.%20Beast/Travel%20Is%20Dangerous.mp3" @song.save @song.location.should eql("/Users/dave/Music/iTunes/iTunes Music/Mogwai/Mr. Beast/Travel Is Dangerous.mp3") end end Here's the following error I get when running the example: when location= has been sanitized dealing with foreign characters expected: "/Users/dave/Music/iTunes/iTunes Music/Sigur Ros/Agaetis Byrjun/05 N? batter?.m4a", got: "/Users/dave/Music/iTunes/iTunes Music/Sigur Ros/Agaetis Byrjun/05 N? batter?.m4a" (using ==) And for what it's worth, here's the location= method: def location=(location) self[:location] = URI.unescape(location).gsub!("file://localhost", "") end Obviously those strings are not equal in the result above, but when I view the output using Textmate's Rspec bundle, I see this: http://antrover.com/data/rspec_results.png (screenshot) The strings look identical using Textmate's Rspec bundle until I copy and paste the output into some other text editor only to reveal the fact the strings are not equal. This leads me to believe there's an encoding issue somewhere, but I'm not sure where. Textmate and the terminal are both in UTF8. When I copy the above error message into vim from Textmate's Rspec bundle I see this: expected: "/Users/dave/Music/iTunes/iTunes Music/Sigur Ros/Agaetis Byrjun/05 N? batter?.m4a", got: "/Users/dave/Music/iTunes/iTunes Music/Sigur Ros/Agaetis Byrjun/05 Ny?~A batteri?~A.m4a" (using ==) Anyone have any ideas on how to make this (simple!) test pass with flying colors? Thank you, Dave From ashley.moran at patchspace.co.uk Sat Mar 22 14:11:46 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sat, 22 Mar 2008 18:11:46 +0000 Subject: [rspec-users] Foreign characters in strings In-Reply-To: <7d983dfe0803220917l3380877creaa694993bb232a1@mail.gmail.com> References: <7d983dfe0803220917l3380877creaa694993bb232a1@mail.gmail.com> Message-ID: On Mar 22, 2008, at 4:17 pm, Dave wrote: > Anyone have any ideas on how to make this (simple!) test pass with > flying colors? You will need to use a unicode library. Judging by the length of the strings being compared, I think what is happening is the ? and ? characters are being entered in different ways. URI is encoding them as letter+accent (total length 84) whereas your test string is encoding them as single character (total length 82). (Actual length of the string is 80, I counted by hand). I'm no unicode expert but I do know that some characters can be encoded either the form or the form Without resorting to a unicode library you would have to do URI.should_receive(:unescape).with("...") to test it, which is more of a unit test than a functional test. Hope this helps. Ashley ##### Here's the code I wrote as a test: Error: Song when location= has been sanitized dealing with foreign character expected: 82, got: 84 (using ==) $KCODE = "u" require 'uri' class Song attr_reader :location def location=(location) @location = URI.unescape(location).gsub!("file://localhost", "") end end describe Song do before(:each) do @song = Song.new end it "when location= has been sanitized dealing with foreign characters" do location = "file://localhost/Users/dave/Music/iTunes/iTunes%20Music/Sigur%20Ros/Agaetis%20Byrjun/05%20Ny%CC%81%20batteri%CC%81.m4a " @song.location = location expected_sanitized_location = "/Users/dave/Music/iTunes/iTunes Music/Sigur Ros/Agaetis Byrjun/05 N? batter?.m4a" @song.location.length.should == expected_sanitized_location.length @song.location.should == expected_sanitized_location end it "when location= has been sanitized dealing with non-foreign characters" do location = "file://localhost/Users/dave/Music/iTunes/iTunes%20Music/Mogwai/Mr.%20Beast/Travel%20Is%20Dangerous.mp3 " @song.location = location expected_sanitized_location = "/Users/dave/Music/iTunes/iTunes Music/Mogwai/Mr. Beast/Travel Is Dangerous.mp3" @song.location.length.should == expected_sanitized_location.length @song.location.should eql(expected_sanitized_location) end end From ashley.moran at patchspace.co.uk Sat Mar 22 14:49:37 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sat, 22 Mar 2008 18:49:37 +0000 Subject: [rspec-users] Win MoNeY Online In-Reply-To: <6bdacb70803220618n77b0ff37j6800922979846e5b@mail.gmail.com> References: <4d7dc048c72f52203f366e87e2992ff3@ruby-forum.com> <6bdacb70803220618n77b0ff37j6800922979846e5b@mail.gmail.com> Message-ID: <98B5DAD2-4214-48C4-A9F4-5A8EAA0B8CF5@patchspace.co.uk> On Mar 22, 2008, at 1:18 pm, Corey Haines wrote: > start making money by > clicking on surf ads and visit sites from the list for 30s, for each > site that you visit you receive 0.01$.The secret for making serious > money is to gather referrals which are users that register on bux.to > using the link you gave them...so for each site they visit both you > and > them win these money..... Story: As an upstanding member of the internet community I want to be able to click on loads of virus-ridden links So that I can be filthy rich without doing any real work Scenario: I'm a bit lazy Given a browser And a browser automation tool And a page of links When I click on several hundred links in 30 seconds Then my bank balance should increase considerably And my credit card should not be charged from Nigeria The ruby implementation of the steps is left as an exercise for the reader. Ashley From coreyhaines at gmail.com Sat Mar 22 15:09:09 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sat, 22 Mar 2008 15:09:09 -0400 Subject: [rspec-users] Win MoNeY Online In-Reply-To: <98B5DAD2-4214-48C4-A9F4-5A8EAA0B8CF5@patchspace.co.uk> References: <4d7dc048c72f52203f366e87e2992ff3@ruby-forum.com> <6bdacb70803220618n77b0ff37j6800922979846e5b@mail.gmail.com> <98B5DAD2-4214-48C4-A9F4-5A8EAA0B8CF5@patchspace.co.uk> Message-ID: <6bdacb70803221209vddd037ex899886af1fc772e8@mail.gmail.com> +1 On Sat, Mar 22, 2008 at 2:49 PM, Ashley Moran wrote: > > On Mar 22, 2008, at 1:18 pm, Corey Haines wrote: > > start making money by > > clicking on surf ads and visit sites from the list for 30s, for each > > site that you visit you receive 0.01$.The secret for making serious > > money is to gather referrals which are users that register on bux.to > > using the link you gave them...so for each site they visit both you > > and > > them win these money..... > > > Story: > As an upstanding member of the internet community > I want to be able to click on loads of virus-ridden links > So that I can be filthy rich without doing any real work > > Scenario: I'm a bit lazy > Given a browser > And a browser automation tool > And a page of links > When I click on several hundred links in 30 seconds > Then my bank balance should increase considerably > And my credit card should not be charged from Nigeria > > The ruby implementation of the steps is left as an exercise for the > reader. > > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080322/18ec1c28/attachment.html From omen.king at gmail.com Sat Mar 22 17:15:35 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Sat, 22 Mar 2008 17:15:35 -0400 Subject: [rspec-users] Win MoNeY Online In-Reply-To: <6bdacb70803221209vddd037ex899886af1fc772e8@mail.gmail.com> References: <4d7dc048c72f52203f366e87e2992ff3@ruby-forum.com> <6bdacb70803220618n77b0ff37j6800922979846e5b@mail.gmail.com> <98B5DAD2-4214-48C4-A9F4-5A8EAA0B8CF5@patchspace.co.uk> <6bdacb70803221209vddd037ex899886af1fc772e8@mail.gmail.com> Message-ID: What would spec first? the views or controllers.Honestly I don't see any point since views are so britle. I guess you'd just check with reg exp for the changing name On Sat, Mar 22, 2008 at 3:09 PM, Corey Haines wrote: > +1 > > > On Sat, Mar 22, 2008 at 2:49 PM, Ashley Moran < > ashley.moran at patchspace.co.uk> wrote: > > > > > On Mar 22, 2008, at 1:18 pm, Corey Haines wrote: > > > start making money by > > > clicking on surf ads and visit sites from the list for 30s, for each > > > site that you visit you receive 0.01$.The secret for making serious > > > money is to gather referrals which are users that register on bux.to > > > using the link you gave them...so for each site they visit both you > > > and > > > them win these money..... > > > > > > Story: > > As an upstanding member of the internet community > > I want to be able to click on loads of virus-ridden links > > So that I can be filthy rich without doing any real work > > > > Scenario: I'm a bit lazy > > Given a browser > > And a browser automation tool > > And a page of links > > When I click on several hundred links in 30 seconds > > Then my bank balance should increase considerably > > And my credit card should not be charged from Nigeria > > > > The ruby implementation of the steps is left as an exercise for the > > reader. > > > > Ashley > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > > _______________________________________________ > 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/20080322/65ea315a/attachment.html From cremes.devlist at mac.com Sat Mar 22 22:00:35 2008 From: cremes.devlist at mac.com (Chuck Remes) Date: Sat, 22 Mar 2008 21:00:35 -0500 Subject: [rspec-users] What is your workflow? Or how to use the story runner the right way. In-Reply-To: References: <27c0ac6d0803040513l7b4fba44nfb3b314aae1bdcc3@mail.gmail.com> Message-ID: On Mar 4, 2008, at 7:43 AM, Chris Parsons wrote: > [snip details about story & spec workflow] > > Sound like a lot of work, but given practice you can zip through these > steps very quickly. You also get a free 'focusing tool' (lose sight of > where you are? just run the story test and write more specs). > > Hope this is helpful. Maybe I should write up an extended example as a > blog post, including mocking etc, as it seems to come up a lot. > > Thanks > Chris Sorry to resurrect an old thread... I've just spent the last 10 hours working on understanding user stories and their role in designing code. Here's what I've done: * watched the "RSpec User Stories" peepcode * scoured this newsgroup for tips & suggestions * used Chris' methodology to BDD a new app So far things are going well though the process is S L O W. I've tried to cobble together tips from other threads regarding directory structure for the stories, steps & specs amongst other things, but it just feels really scattered to me. I would love to see Chris put together a more detailed example of his workflow. It's likely I am making some boneheaded mistakes that I just can't pick out yet. When I'm further with my example project, I'll try to post it up somewhere (or turn it into doc for the rspec site) so others can learn from my mistakes. cr From backslash451 at yahoo.it Sun Mar 23 09:57:37 2008 From: backslash451 at yahoo.it (roberto belardo) Date: Sun, 23 Mar 2008 14:57:37 +0100 (CET) Subject: [rspec-users] Multiple should sentences one lambda Message-ID: <96296.25743.qm@web27001.mail.ukl.yahoo.com> Hi all, i have one problem. I'm just trying to get the restful_authentication plugin work, but i discovered that its rspec tests are not working, because of this: it 'requires password confirmation' do lambda do u = Factory.create_user(:password_confirmation => nil) u.errors.on(:password_confirmation).should_not be_nil end.should_not change(User, :count) end where in the user model i have a simple: validates_presence_of :password_confirmation Autotest continues to tell me that: ActiveRecord::RecordInvalid in 'User requires password confirmation' Validation failed: Password confirmation can't be blank The question is: how can i test both the presence of error and the change on count? Thanks in advance, Roberto. Inviato da Yahoo! Mail. Tanti modi per restare in contatto con chi vuoi. http://it.docs.yahoo.com/mail/overview/index.html From dchelimsky at gmail.com Sun Mar 23 11:43:16 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 23 Mar 2008 10:43:16 -0500 Subject: [rspec-users] Multiple should sentences one lambda In-Reply-To: <96296.25743.qm@web27001.mail.ukl.yahoo.com> References: <96296.25743.qm@web27001.mail.ukl.yahoo.com> Message-ID: <57c63afe0803230843i4dfd9751nafee76ab35b29ec6@mail.gmail.com> On Sun, Mar 23, 2008 at 8:57 AM, roberto belardo wrote: > Hi all, > i have one problem. I'm just trying to get the > restful_authentication plugin work, but i discovered > that its rspec tests are not working, because of this: > > it 'requires password confirmation' do > lambda do > u = Factory.create_user(:password_confirmation => > nil) > u.errors.on(:password_confirmation).should_not > be_nil > end.should_not change(User, :count) > end > > where in the user model i have a simple: > > validates_presence_of :password_confirmation > > Autotest continues to tell me that: > > ActiveRecord::RecordInvalid in 'User requires password > confirmation' > Validation failed: Password confirmation can't be > blank > > The question is: how can i test both the presence of > error and the change on count? These are two different behaviours and should, IMO, have two separate examples: it 'does not save a user with nil password_confirmation' do lambda do Factory.create_user(:password_confirmation => nil) end.should_not change(User, :count) end it 'reports an error for nil password_confirmation' do u = Factory.create_user(:password_confirmation => nil) u.should have(1).error_on(:password_confirmation) end end HTH, David > > Thanks in advance, > Roberto. > > > Inviato da Yahoo! Mail. > Tanti modi per restare in contatto con chi vuoi. > http://it.docs.yahoo.com/mail/overview/index.html > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From alan.larkin at gmail.com Sun Mar 23 17:41:47 2008 From: alan.larkin at gmail.com (Alan Larkin) Date: Sun, 23 Mar 2008 21:41:47 +0000 Subject: [rspec-users] Does one use mocks in stories? Message-ID: <47E6CE9B.30100@gmail.com> My site is an external Facebook app. I need users to come to the start page and if they are not already logged into their Facebook account (and have the app installed) see a button to take them to the Facebook login/install page. Using RFacebook, login is normally achieved with a before_filter. The user is sent to the Facebook login/install page and then the app redirects them back to one of my pages. In a story, am I supposed to mock out that filter method to set the necessary variables and do the redirection or what? I haven't seen any examples that use mocks in stories. Also am I right in thinking that if I am to mock this then I will need to use something like Mocha? My initial draft looks like this: Story 'An unlogged in user', %{ As an unlogged in user I want to log in to my Facebook account and start using MyApp }, :type => RailsStory do Scenario 'starts at /' do When 'arrive at /' do get '/' end Then 'the user should see the MyApp home page' do response.should render_template('/sessions/index') end When 'the user clicks the log in/install button' do post '/' end Then 'the user should be redirected to the Facebook login/MyApp install page and on success back to their personal MyApp home page' do ### What might go here??? end end end From rick.denatale at gmail.com Mon Mar 24 11:38:09 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 24 Mar 2008 11:38:09 -0400 Subject: [rspec-users] Has anyone seen this strange mock behaviour? Message-ID: I've got this example 'group': before(:all) do @mock_user = mock_model(User) @mock_email_field = mock_model(EmailField, :user => @mock_user) @mock_email_field.stub!(:user).and_return(@mock_user) EmailField.stub!(:find_by_value).and_return(@mock_email_field) end it "should find existing user by email when asked for group_user_from_attributes" do # @mock_email_field.stub!(:user).and_return(@mock_user) EmailField.should_receive(:find_by_value).with("joe at blow.com").and_return(@mock_email_field) User.group_user_from_attributes(:email=>"joe at blow.com") end This fails with a message: should find existing user by email when asked for group_user_from_attributes Mock 'EmailField_1001' received unexpected message :user with (no args) Note that I defined the @mock_email_field to stub the user method. If I uncomment the restubbing of the @mock_email_field in the example, it works. It certainly seems that @mock_email_field points to the same object in either case. I've also tried using stub! in the before block instead or or in addition to hash stub in mock_model, but unless I stub it in the example no joy. A couple of us have been scratching our heads over this and I thought I'd throw it out to the wider RSpec community. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From aslak.hellesoy at gmail.com Mon Mar 24 11:54:23 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 24 Mar 2008 16:54:23 +0100 Subject: [rspec-users] Has anyone seen this strange mock behaviour? In-Reply-To: References: Message-ID: <8d961d900803240854r6066f066t38c0e9de233252d0@mail.gmail.com> On Mon, Mar 24, 2008 at 4:38 PM, Rick DeNatale wrote: > I've got this example 'group': > > before(:all) do > @mock_user = mock_model(User) > @mock_email_field = mock_model(EmailField, :user => @mock_user) > @mock_email_field.stub!(:user).and_return(@mock_user) > EmailField.stub!(:find_by_value).and_return(@mock_email_field) > end > before(:all) will only be executed once - before all of your examples. Why are you using before(:all)? It's highly recommended you don't use before(:all) - and definitely not with mocks. All sort of sideeffects might happen. Aslak > it "should find existing user by email when asked for > group_user_from_attributes" do > # @mock_email_field.stub!(:user).and_return(@mock_user) > EmailField.should_receive(:find_by_value).with("joe at blow.com").and_return(@mock_email_field) > User.group_user_from_attributes(:email=>"joe at blow.com") > end > > > This fails with a message: > should find existing user by email when asked for group_user_from_attributes > Mock 'EmailField_1001' received unexpected message :user with (no args) > > Note that I defined the @mock_email_field to stub the user method. > > If I uncomment the restubbing of the @mock_email_field in the example, it works. > > It certainly seems that @mock_email_field points to the same object in > either case. > > I've also tried using stub! in the before block instead or or in > addition to hash stub in mock_model, but unless I stub it in the > example no joy. > > A couple of us have been scratching our heads over this and I thought > I'd throw it out to the wider RSpec community. > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Mon Mar 24 12:31:10 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 24 Mar 2008 12:31:10 -0400 Subject: [rspec-users] Has anyone seen this strange mock behaviour? In-Reply-To: <8d961d900803240854r6066f066t38c0e9de233252d0@mail.gmail.com> References: <8d961d900803240854r6066f066t38c0e9de233252d0@mail.gmail.com> Message-ID: On Mon, Mar 24, 2008 at 11:54 AM, aslak hellesoy wrote: > On Mon, Mar 24, 2008 at 4:38 PM, Rick DeNatale wrote: > > I've got this example 'group': > > > > before(:all) do > > @mock_user = mock_model(User) > > @mock_email_field = mock_model(EmailField, :user => @mock_user) > > @mock_email_field.stub!(:user).and_return(@mock_user) > > EmailField.stub!(:find_by_value).and_return(@mock_email_field) > > end > > > > before(:all) will only be executed once - before all of your examples. > Why are you using before(:all)? Because I had a brain f*rt. Actually I just caught this myself before checking back with the list. Thanks! -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From cremes.devlist at mac.com Mon Mar 24 21:50:55 2008 From: cremes.devlist at mac.com (Chuck Remes) Date: Mon, 24 Mar 2008 20:50:55 -0500 Subject: [rspec-users] [Q] how do I test the behavior of a Builder pattern object? Message-ID: So I have a complex object that I need to construct. This complex object, at runtime, takes an object in its initializer. The initializer interrogates the object and creates several collaborative objects based upon values from that interrogation. The construction is complicated enough that it pretty much begs to be implemented via the Builder Pattern. My problem is that I don't know how to test this behavior regardless of whether the object handles its own construction or I create a separate Builder object to construct it for me. For example: class ComplexObjectBuilder def initialize @complex_object = ComplexObject.new end def create_foo(control, value) case control do when :a then @complex_object.foo = SpecialObject.new(value * 4) when :v then @complex_object.foo = OtherObject.new when :z then @complex_object.foo = YAObject.new end end def create_bar(control, value) # similar to above end def construct # some business rules to make sure the object is complete; use # defaults for fields that were not set via the interface return @complex_object end end @builder = ComplexObjectBuilder.new @builder.create_foo(params_object.accessor1, params_object.accessor2) @builder.create_bar(params_object.accessor3, params_object.accessor4) baz = @builder.construct How the heck do I test anything here? I do not see how I can validate the behavior of #create_foo or #create_bar without exposing @complex_object via a public interface. Those #create_* methods are purely for construction and do not return a value. Only #construct returns a value which should be the completed object Is there a transformation to consider to make this more testable? I'm hoping someone has tackled this before and can provide me some insight. Many thanks... cr From cremes.devlist at mac.com Mon Mar 24 22:49:43 2008 From: cremes.devlist at mac.com (Chuck Remes) Date: Mon, 24 Mar 2008 21:49:43 -0500 Subject: [rspec-users] [Q] how do I test the behavior of a Builder pattern object? In-Reply-To: References: Message-ID: On Mar 24, 2008, at 8:50 PM, Chuck Remes wrote: > [snip code] > > How the heck do I test anything here? I do not see how I can validate > the behavior of #create_foo or #create_bar without exposing > @complex_object via a public interface. Those #create_* methods are > purely for construction and do not return a value. Only #construct > returns a value which should be the completed object > > Is there a transformation to consider to make this more testable? Just to show I'm not sitting back and waiting for the answer to be handed to me on a silver platter... I looked through the rspec specs and found a construction that might be useful. In spec/spec/extensions/main_spec.rb we see this: it "should create an Options object" do @main.send(:rspec_options).should be_instance_of(Spec::Runner::Options) @main.send(:rspec_options).should === $rspec_options end In a #before block the @main instance variable was instantiated and a module was included. I'm assuming #send is used to check the value of a private accessor. So I could potentially do something like this: describe ComplexObjectBuilder, "construction" do before(:each) do @builder = ComplexObjectBuilder.new @builder.foo(control1, val1) @builder.bar(control2, val2) end it "should create a YAObject for #foo" do @builder.send(:foo).should be_instance_of(YAObject) end it "should create a ZObject for #bar" do @builder.send(:bar).should be_instance_of(ZObject) end end Is this acceptable? I read through the "specs on private methods" thread and the consensus was this should only be done when there is *no other option*. Is there another option? cr From pergesu at gmail.com Tue Mar 25 01:04:34 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 24 Mar 2008 22:04:34 -0700 Subject: [rspec-users] [Q] how do I test the behavior of a Builder pattern object? In-Reply-To: References: Message-ID: <810a540e0803242204v23ca1919w60a31348d9c800ba@mail.gmail.com> On Mon, Mar 24, 2008 at 6:50 PM, Chuck Remes wrote: > So I have a complex object that I need to construct. This complex > object, at runtime, takes an object in its initializer. The > initializer interrogates the object and creates several collaborative > objects based upon values from that interrogation. > > The construction is complicated enough that it pretty much begs to be > implemented via the Builder Pattern. > > My problem is that I don't know how to test this behavior regardless > of whether the object handles its own construction or I create a > separate Builder object to construct it for me. > > For example: > > class ComplexObjectBuilder > def initialize > @complex_object = ComplexObject.new > end > > def create_foo(control, value) > case control do > when :a then @complex_object.foo = SpecialObject.new(value * 4) > when :v then @complex_object.foo = OtherObject.new > when :z then @complex_object.foo = YAObject.new > end > end > > def create_bar(control, value) > # similar to above > end > > def construct > # some business rules to make sure the object is complete; use > # defaults for fields that were not set via the interface > return @complex_object > end > end > > @builder = ComplexObjectBuilder.new > @builder.create_foo(params_object.accessor1, params_object.accessor2) > @builder.create_bar(params_object.accessor3, params_object.accessor4) > baz = @builder.construct > > How the heck do I test anything here? I do not see how I can validate > the behavior of #create_foo or #create_bar without exposing > @complex_object via a public interface. Those #create_* methods are > purely for construction and do not return a value. Only #construct > returns a value which should be the completed object > > Is there a transformation to consider to make this more testable? > > I'm hoping someone has tackled this before and can provide me some > insight. Many thanks... > > cr Hey Chuck, I would toss whatever code you have and BDD it from scratch. Shouldn't be that difficult...you can start off with stuff like describe ComplexObjectBuilder, " when foo is built with :a" do before(:each) do builder = ComplexObjectBuilder.new builder.create_foo :a, 3 @built = builder.construct end it "should create a special object" do @built.foo.should be_a(SpecialObject) end it "should quadruple the value passed to the special object" do @built.foo.some_val.should == 12 end end Alternatively, you could mock the calls to the constructed objects. In this case though, that probably leads to specs that are too tightly coupled to the implementation. I know this seems like kind of a cop-out, but you'll get much better results if you BDD this from scratch. If this is super complex legacy stuff, just try to get some semi-high level tests around it (the sort of test I showed would work fine), and then you can refactor it. Pat From pergesu at gmail.com Tue Mar 25 01:08:45 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 24 Mar 2008 22:08:45 -0700 Subject: [rspec-users] [Q] how do I test the behavior of a Builder pattern object? In-Reply-To: References: Message-ID: <810a540e0803242208q5a940836g42aaa0e9a1bfff21@mail.gmail.com> On Mon, Mar 24, 2008 at 7:49 PM, Chuck Remes wrote: > Is this acceptable? I read through the "specs on private methods" > thread and the consensus was this should only be done when there is > *no other option*. Is there another option? There's always another option, and anybody who says otherwise is flat out wrong. You can *always* test an object via its public interface. If there's a private method that you want to test, but there's no way to exercise it by the public interface, then that means the code is not used and should be deleted. Pat From sethladd at gmail.com Tue Mar 25 02:35:56 2008 From: sethladd at gmail.com (Seth Ladd) Date: Mon, 24 Mar 2008 20:35:56 -1000 Subject: [rspec-users] Testing Controllers with respond_to? Message-ID: <64f07e2c0803242335i2d3a9bbbo48d31e9285e1a359@mail.gmail.com> Hello, I'm having a hard time testing my controllers that use respond_to. I'm trying to test that I can correctly handle each MIME type on request. For instance, I have this: respond_to do |format| format.html format.json end And I've tried things like this: get 'show', :id => databases(:one).id, :format => 'json' response.should render_template('show') but I keep getting a nil template. I know this works in the code, when I try a URI like http://localhost:3000/foo.json Any tips for setting the format or MIME Type correctly so I can activate other respond_to blocks? Thanks very much, Seth From sethladd at gmail.com Tue Mar 25 03:06:52 2008 From: sethladd at gmail.com (Seth Ladd) Date: Mon, 24 Mar 2008 21:06:52 -1000 Subject: [rspec-users] Testing Controllers with respond_to? In-Reply-To: <64f07e2c0803242335i2d3a9bbbo48d31e9285e1a359@mail.gmail.com> References: <64f07e2c0803242335i2d3a9bbbo48d31e9285e1a359@mail.gmail.com> Message-ID: <64f07e2c0803250006q33f5174eyf1fe2d4adb02a208@mail.gmail.com> Hm, of course, now that I have sent the previous email, I found the bug in my code and have fixed it. So I know I am using RSpec correctly with controllers and a respond_to block. Using the :format => 'json' attribute in my get call was all I needed. However, not matter what the format I choose, the template rendered is always "databases/show" (this is essentially correct behavior). However, it's hard to determine which show was rendered: show.json.erb or show.html.erb I can check the content-type header, but that's not exactly what I'd like to test. Is there a better way to write a spec to ensure that the correct template is rendered when I use certain formats? Seth On Mon, Mar 24, 2008 at 8:35 PM, Seth Ladd wrote: > Hello, > > I'm having a hard time testing my controllers that use respond_to. > I'm trying to test that I can correctly handle each MIME type on > request. > > For instance, I have this: > > respond_to do |format| > format.html > format.json > end > > And I've tried things like this: > > get 'show', :id => databases(:one).id, :format => 'json' > response.should render_template('show') > > but I keep getting a nil template. > > I know this works in the code, when I try a URI like > http://localhost:3000/foo.json > > Any tips for setting the format or MIME Type correctly so I can > activate other respond_to blocks? > > Thanks very much, > Seth > From bastien.vaucher at gmail.com Tue Mar 25 06:13:01 2008 From: bastien.vaucher at gmail.com (Bastien) Date: Tue, 25 Mar 2008 03:13:01 -0700 (PDT) Subject: [rspec-users] [Stories]Troubles with GivenScenario Message-ID: <21401e90-5d6d-4a43-9b79-385c967bbf57@i29g2000prf.googlegroups.com> I have some problems with GivenScenario, my scenario keeps on failing when I use GivenScenario, like if the database or the session was not in the same state at the beginning of the new scenario as it was at the end of the given one. If I try to group my two scenari in only one big scenario then it passes... Any clue of what I might do wrong there ? you can see here my story : Story: Filling a profile As a user I want to fill a profile So that I can see my score Scenario: Starting a new profile Given a company And a department And 2 questions And a number of replies And the logged in user somone at example.com When the user starts a new profile Then there should be a new profile for this user And there should be a list of remaining questions ( ids stored in the session ) When the user answers a question Then there should be one more answer Then there should be one question less to answer Scenario: Ending a profile GivenScenario: Starting a new profile # if i remove these 2 lines it passes When the user answers a question # fails here because the question which id's is stored in the session can't be found Then there should be one more answer Then there should be no more question to answer Then the profile should be set as terminated From dchelimsky at gmail.com Tue Mar 25 07:07:34 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 25 Mar 2008 06:07:34 -0500 Subject: [rspec-users] [Stories]Troubles with GivenScenario In-Reply-To: <21401e90-5d6d-4a43-9b79-385c967bbf57@i29g2000prf.googlegroups.com> References: <21401e90-5d6d-4a43-9b79-385c967bbf57@i29g2000prf.googlegroups.com> Message-ID: <57c63afe0803250407x19afb7dfr35b491f26ff70a8@mail.gmail.com> On Tue, Mar 25, 2008 at 5:13 AM, Bastien wrote: > I have some problems with GivenScenario, my scenario keeps on failing > when I use GivenScenario, like if the database or the session was not > in the same state at the beginning of the new scenario as it was at > the end of the given one. If I try to group my two scenari in only one > big scenario then it passes... Any clue of what I might do wrong > there ? Hard to tell from plain text. Can you post the steps definitions? > > you can see here my story : > > Story: Filling a profile > > As a user > I want to fill a profile > So that I can see my score > > Scenario: Starting a new profile > > Given a company > And a department > And 2 questions > And a number of replies > And the logged in user somone at example.com > > When the user starts a new profile > > Then there should be a new profile for this user > And there should be a list of remaining questions ( ids stored in > the session ) > > When the user answers a question > > Then there should be one more answer > Then there should be one question less to answer > > Scenario: Ending a profile > GivenScenario: Starting a new profile # if i remove these 2 lines it > passes > > When the user answers a question # fails here because the question > which id's is stored in the session can't be found > > Then there should be one more answer > Then there should be no more question to answer > Then the profile should be set as terminated > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bastien.vaucher at gmail.com Tue Mar 25 07:31:17 2008 From: bastien.vaucher at gmail.com (Bastien) Date: Tue, 25 Mar 2008 04:31:17 -0700 (PDT) Subject: [rspec-users] [Stories]Troubles with GivenScenario In-Reply-To: <57c63afe0803250407x19afb7dfr35b491f26ff70a8@mail.gmail.com> References: <21401e90-5d6d-4a43-9b79-385c967bbf57@i29g2000prf.googlegroups.com> <57c63afe0803250407x19afb7dfr35b491f26ff70a8@mail.gmail.com> Message-ID: Of course, here you go : steps_for(:work_area_execution) do Given("a company") do @account = Factory.create_valid_account() end Given("$amount questions?") do |amount| Question.delete_all category = Factory.create_valid_category work_area = Factory.create_valid_work_area(category) amount.to_i.times do Factory.create_valid_questions(work_area) end end Given("a department") do @department = Factory.create_valid_department(:account_id => @account.id) end Given("a number of replies") do @replies = Reply.find(:all).size end Given("the logged in user $email") do |email| @user = Factory.create_valid_user(:email=>email, :department_id => @department.id, :account_id => @account.id) @user_profiles = Profile.find(:all, :conditions => ['user_id = ?', at user.id]).size host! "company.example.com" post "sessions", {:login => email, :password => "bacon"} follow_redirect! if redirect? end When("the user starts a new profile") do post person_profiles_path(@user) follow_redirect! if redirect? end When("the user answers a question") do q = Question.find(session[:current_question]) # doesn't work with GivenScenario w = q.work_area c = w.category post profile_question_answers_path(@user.profiles.first, q.id), { 'reply[current]' => 4, 'reply[work_area_id]' => w.id, 'reply[question_id]' =>q.id, 'reply[category_id]'=> c.id, 'reply[base]' => nil, } follow_redirect! if redirect? end Then("there should be a new profile for this user") do @user.profiles.size.should == @user_profiles + 1 end Then("there should be a list of remaining questions") do session[:current_question].should_not == nil session[:pending_questions].should_not == nil @remaining_questions = session[:pending_questions].size end Then("there should be one question less to answer") do session[:pending_questions].size.should == @remaining_questions - 1 @remaining_questions = session[:pending_questions].size end Then("there should be one more answer") do Reply.find(:all).size.should == @replies + 1 @replies = Reply.find(:all).size end Then("there should be no more question to answer") do session[:pending_questions].size.should == 0 session[:current_question].should == nil end Then("the profile should be set as terminated") do @user.profiles.first.finished_at.should_not == nil end end Thanks for your time and help. On Mar 25, 12:07 pm, "David Chelimsky" wrote: > On Tue, Mar 25, 2008 at 5:13 AM, Bastien wrote: > > I have some problems with GivenScenario, my scenario keeps on failing > > when I use GivenScenario, like if the database or the session was not > > in the same state at the beginning of the new scenario as it was at > > the end of the given one. If I try to group my two scenari in only one > > big scenario then it passes... Any clue of what I might do wrong > > there ? > > Hard to tell from plain text. Can you post the steps definitions? > > > > > > > you can see here my story : > > > Story: Filling a profile > > > As a user > > I want to fill a profile > > So that I can see my score > > > Scenario: Starting a new profile > > > Given a company > > And a department > > And 2 questions > > And a number of replies > > And the logged in user som... at example.com > > > When the user starts a new profile > > > Then there should be a new profile for this user > > And there should be a list of remaining questions ( ids stored in > > the session ) > > > When the user answers a question > > > Then there should be one more answer > > Then there should be one question less to answer > > > Scenario: Ending a profile > > GivenScenario: Starting a new profile # if i remove these 2 lines it > > passes > > > When the user answers a question # fails here because the question > > which id's is stored in the session can't be found > > > Then there should be one more answer > > Then there should be no more question to answer > > Then the profile should be set as terminated > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Mar 25 07:35:23 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 25 Mar 2008 06:35:23 -0500 Subject: [rspec-users] Testing Controllers with respond_to? In-Reply-To: <64f07e2c0803250006q33f5174eyf1fe2d4adb02a208@mail.gmail.com> References: <64f07e2c0803242335i2d3a9bbbo48d31e9285e1a359@mail.gmail.com> <64f07e2c0803250006q33f5174eyf1fe2d4adb02a208@mail.gmail.com> Message-ID: <57c63afe0803250435x132f3447qe7215518bd9c7782@mail.gmail.com> On Tue, Mar 25, 2008 at 2:06 AM, Seth Ladd wrote: > Hm, of course, now that I have sent the previous email, I found the > bug in my code and have fixed it. So I know I am using RSpec > correctly with controllers and a respond_to block. Using the :format > => 'json' attribute in my get call was all I needed. > > However, not matter what the format I choose, the template rendered is > always "databases/show" (this is essentially correct behavior). > However, it's hard to determine which show was rendered: > show.json.erb or show.html.erb There is a guideline in TDD that you should test your code and not other people's code. The behaviour you're interested in testing is that of ActionController::Base, not of your code. > I can check the content-type header, but that's not exactly what I'd > like to test. > > Is there a better way to write a spec to ensure that the correct > template is rendered when I use certain formats? The transformation from loosely-bound name ('databases/show') to explicit template name with extensions happens deep in ActionController::Base. Between that fact and the aforementioned guideline, there is no direct support for what you are looking for in rspec_on_rails. You *can* do this to get closer to what you are looking for: controller.expect_render(hash_including(:xml => anything)) or controller.expect_render(hash_including(:json => anything)) But I, personally, would not. Since this is not supported directly by rspec_on_rails, should the Rails implementation of render change you'd be on your own to keep up with those changes. HTH, David > > Seth > > > > On Mon, Mar 24, 2008 at 8:35 PM, Seth Ladd wrote: > > Hello, > > > > I'm having a hard time testing my controllers that use respond_to. > > I'm trying to test that I can correctly handle each MIME type on > > request. > > > > For instance, I have this: > > > > respond_to do |format| > > format.html > > format.json > > end > > > > And I've tried things like this: > > > > get 'show', :id => databases(:one).id, :format => 'json' > > response.should render_template('show') > > > > but I keep getting a nil template. > > > > I know this works in the code, when I try a URI like > > http://localhost:3000/foo.json > > > > Any tips for setting the format or MIME Type correctly so I can > > activate other respond_to blocks? > > > > Thanks very much, > > Seth > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Mar 25 08:00:35 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 25 Mar 2008 07:00:35 -0500 Subject: [rspec-users] [Stories]Troubles with GivenScenario In-Reply-To: References: <21401e90-5d6d-4a43-9b79-385c967bbf57@i29g2000prf.googlegroups.com> <57c63afe0803250407x19afb7dfr35b491f26ff70a8@mail.gmail.com> Message-ID: <57c63afe0803250500v2e5bc6dep883895f46f363b56@mail.gmail.com> On Tue, Mar 25, 2008 at 6:31 AM, Bastien wrote: > Of course, here you go : > > steps_for(:work_area_execution) do > > Given("a company") do > @account = Factory.create_valid_account() > end > > Given("$amount questions?") do |amount| > Question.delete_all > category = Factory.create_valid_category > work_area = Factory.create_valid_work_area(category) > amount.to_i.times do > Factory.create_valid_questions(work_area) > end > end > > Given("a department") do > @department = Factory.create_valid_department(:account_id => > @account.id) > end > > Given("a number of replies") do > @replies = Reply.find(:all).size > end > > Given("the logged in user $email") do |email| > @user = Factory.create_valid_user(:email=>email, :department_id => > @department.id, :account_id => @account.id) > @user_profiles = Profile.find(:all, :conditions => ['user_id > = ?', at user.id]).size > host! "company.example.com" > post "sessions", > {:login => email, > :password => "bacon"} > follow_redirect! if redirect? > end > > When("the user starts a new profile") do > post person_profiles_path(@user) > follow_redirect! if redirect? > end > > When("the user answers a question") do > q = Question.find(session[:current_question]) # doesn't work with > GivenScenario > w = q.work_area > c = w.category > > post profile_question_answers_path(@user.profiles.first, q.id), > { 'reply[current]' => 4, > 'reply[work_area_id]' => w.id, > 'reply[question_id]' =>q.id, > 'reply[category_id]'=> c.id, > 'reply[base]' => nil, } > follow_redirect! if redirect? > end > > Then("there should be a new profile for this user") do > @user.profiles.size.should == @user_profiles + 1 > end > > Then("there should be a list of remaining questions") do > session[:current_question].should_not == nil > session[:pending_questions].should_not == nil > @remaining_questions = session[:pending_questions].size > end > > Then("there should be one question less to answer") do > session[:pending_questions].size.should == @remaining_questions - > 1 > @remaining_questions = session[:pending_questions].size > end > > Then("there should be one more answer") do > Reply.find(:all).size.should == @replies + 1 > @replies = Reply.find(:all).size > end > > Then("there should be no more question to answer") do > session[:pending_questions].size.should == 0 > session[:current_question].should == nil > end > > Then("the profile should be set as terminated") do > @user.profiles.first.finished_at.should_not == nil > end > > end Looks like GivenScenario gets run in a separate instance of RailsStory (which is derived from ActionController::IntegrationSession) from the rest of the scenario. This would explain why the session gets cleared out. I can tell you that the DB state does NOT get cleared out, but the mechanism is different. I'm not going to have cycles to investigate a solution right away, so would you please submit a ticket at http://rspec.lighthouseapp.com? Thanks, David > > Thanks for your time and help. > > > On Mar 25, 12:07 pm, "David Chelimsky" wrote: > > > On Tue, Mar 25, 2008 at 5:13 AM, Bastien wrote: > > > I have some problems with GivenScenario, my scenario keeps on failing > > > when I use GivenScenario, like if the database or the session was not > > > in the same state at the beginning of the new scenario as it was at > > > the end of the given one. If I try to group my two scenari in only one > > > big scenario then it passes... Any clue of what I might do wrong > > > there ? > > > > Hard to tell from plain text. Can you post the steps definitions? > > > > > > > > > > > > > you can see here my story : > > > > > Story: Filling a profile > > > > > As a user > > > I want to fill a profile > > > So that I can see my score > > > > > Scenario: Starting a new profile > > > > > Given a company > > > And a department > > > And 2 questions > > > And a number of replies > > > And the logged in user som... at example.com > > > > > > When the user starts a new profile > > > > > Then there should be a new profile for this user > > > And there should be a list of remaining questions ( ids stored in > > > the session ) > > > > > When the user answers a question > > > > > Then there should be one more answer > > > Then there should be one question less to answer > > > > > Scenario: Ending a profile > > > GivenScenario: Starting a new profile # if i remove these 2 lines it > > > passes > > > > > When the user answers a question # fails here because the question > > > which id's is stored in the session can't be found > > > > > Then there should be one more answer > > > Then there should be no more question to answer > > > Then the profile should be set as terminated > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Tue Mar 25 08:37:49 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 25 Mar 2008 12:37:49 +0000 Subject: [rspec-users] Release date for 1.1.4? Message-ID: Hi Does anyone have an idea when RSpec 1.1.4 will be released? It has a bug fix I really want - just bought a USB-controller LED traffic light but RSpec 1.1.3 never fires the :red hook so I just get a green light constantly. (Have been pulling my hair out wondering what I was doing...) Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080325/19074266/attachment.html From dchelimsky at gmail.com Tue Mar 25 09:10:11 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 25 Mar 2008 08:10:11 -0500 Subject: [rspec-users] Release date for 1.1.4? In-Reply-To: References: Message-ID: On Mar 25, 2008, at 7:37 AM, "Ashley Moran" wrote: > Hi > > Does anyone have an idea when RSpec 1.1.4 will be released? We've been talking about it for a few weeks now but have been too busy to make it happen. Can't make a guarantee but I think it is likely that we can get it out by the end of next week. Cheers, David > It has a bug fix I really want - just bought a USB-controller LED > traffic light but RSpec 1.1.3 never fires the :red hook so I just > get a green light constantly. (Have been pulling my hair out > wondering what I was doing...) > > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From bastien.vaucher at gmail.com Tue Mar 25 09:34:22 2008 From: bastien.vaucher at gmail.com (Bastien) Date: Tue, 25 Mar 2008 06:34:22 -0700 (PDT) Subject: [rspec-users] [Stories]Troubles with GivenScenario In-Reply-To: <57c63afe0803250500v2e5bc6dep883895f46f363b56@mail.gmail.com> References: <21401e90-5d6d-4a43-9b79-385c967bbf57@i29g2000prf.googlegroups.com> <57c63afe0803250407x19afb7dfr35b491f26ff70a8@mail.gmail.com> <57c63afe0803250500v2e5bc6dep883895f46f363b56@mail.gmail.com> Message-ID: <532e548e-09de-4af9-b4e5-e1b88a67016f@d21g2000prf.googlegroups.com> done : http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/350 Thanks for your great work. On Mar 25, 1:00 pm, "David Chelimsky" wrote: > On Tue, Mar 25, 2008 at 6:31 AM, Bastien wrote: > > Of course, here you go : > > > steps_for(:work_area_execution) do > > > Given("a company") do > > @account = Factory.create_valid_account() > > end > > > Given("$amount questions?") do |amount| > > Question.delete_all > > category = Factory.create_valid_category > > work_area = Factory.create_valid_work_area(category) > > amount.to_i.times do > > Factory.create_valid_questions(work_area) > > end > > end > > > Given("a department") do > > @department = Factory.create_valid_department(:account_id => > > @account.id) > > end > > > Given("a number of replies") do > > @replies = Reply.find(:all).size > > end > > > Given("the logged in user $email") do |email| > > @user = Factory.create_valid_user(:email=>email, :department_id => > > @department.id, :account_id => @account.id) > > @user_profiles = Profile.find(:all, :conditions => ['user_id > > = ?', at user.id]).size > > host! "company.example.com" > > post "sessions", > > {:login => email, > > :password => "bacon"} > > follow_redirect! if redirect? > > end > > > When("the user starts a new profile") do > > post person_profiles_path(@user) > > follow_redirect! if redirect? > > end > > > When("the user answers a question") do > > q = Question.find(session[:current_question]) # doesn't work with > > GivenScenario > > w = q.work_area > > c = w.category > > > post profile_question_answers_path(@user.profiles.first, q.id), > > { 'reply[current]' => 4, > > 'reply[work_area_id]' => w.id, > > 'reply[question_id]' =>q.id, > > 'reply[category_id]'=> c.id, > > 'reply[base]' => nil, } > > follow_redirect! if redirect? > > end > > > Then("there should be a new profile for this user") do > > @user.profiles.size.should == @user_profiles + 1 > > end > > > Then("there should be a list of remaining questions") do > > session[:current_question].should_not == nil > > session[:pending_questions].should_not == nil > > @remaining_questions = session[:pending_questions].size > > end > > > Then("there should be one question less to answer") do > > session[:pending_questions].size.should == @remaining_questions - > > 1 > > @remaining_questions = session[:pending_questions].size > > end > > > Then("there should be one more answer") do > > Reply.find(:all).size.should == @replies + 1 > > @replies = Reply.find(:all).size > > end > > > Then("there should be no more question to answer") do > > session[:pending_questions].size.should == 0 > > session[:current_question].should == nil > > end > > > Then("the profile should be set as terminated") do > > @user.profiles.first.finished_at.should_not == nil > > end > > > end > > Looks like GivenScenario gets run in a separate instance of RailsStory > (which is derived from ActionController::IntegrationSession) from the > rest of the scenario. This would explain why the session gets cleared > out. I can tell you that the DB state does NOT get cleared out, but > the mechanism is different. > > I'm not going to have cycles to investigate a solution right away, so > would you please submit a ticket athttp://rspec.lighthouseapp.com? > > Thanks, > David > > > > > > > Thanks for your time and help. > > > On Mar 25, 12:07 pm, "David Chelimsky" wrote: > > > > On Tue, Mar 25, 2008 at 5:13 AM, Bastien wrote: > > > > I have some problems with GivenScenario, my scenario keeps on failing > > > > when I use GivenScenario, like if the database or the session was not > > > > in the same state at the beginning of the new scenario as it was at > > > > the end of the given one. If I try to group my two scenari in only one > > > > big scenario then it passes... Any clue of what I might do wrong > > > > there ? > > > > Hard to tell from plain text. Can you post the steps definitions? > > > > > you can see here my story : > > > > > Story: Filling a profile > > > > > As a user > > > > I want to fill a profile > > > > So that I can see my score > > > > > Scenario: Starting a new profile > > > > > Given a company > > > > And a department > > > > And 2 questions > > > > And a number of replies > > > > And the logged in user som... at example.com > > > > > When the user starts a new profile > > > > > Then there should be a new profile for this user > > > > And there should be a list of remaining questions ( ids stored in > > > > the session ) > > > > > When the user answers a question > > > > > Then there should be one more answer > > > > Then there should be one question less to answer > > > > > Scenario: Ending a profile > > > > GivenScenario: Starting a new profile # if i remove these 2 lines it > > > > passes > > > > > When the user answers a question # fails here because the question > > > > which id's is stored in the session can't be found > > > > > Then there should be one more answer > > > > Then there should be no more question to answer > > > > Then the profile should be set as terminated > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-us... at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From ashley.moran at patchspace.co.uk Tue Mar 25 09:44:51 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 25 Mar 2008 13:44:51 +0000 Subject: [rspec-users] Release date for 1.1.4? In-Reply-To: References: Message-ID: On 25/03/2008, David Chelimsky wrote: > > We've been talking about it for a few weeks now but have been too busy > to make it happen. Can't make a guarantee but I think it is likely > that we can get it out by the end of next week. > > Cheers, > David > Cool, thanks David. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080325/f801a0e8/attachment.html From cremes.devlist at mac.com Tue Mar 25 10:22:00 2008 From: cremes.devlist at mac.com (Chuck Remes) Date: Tue, 25 Mar 2008 09:22:00 -0500 Subject: [rspec-users] [Q] how do I test the behavior of a Builder pattern object? In-Reply-To: <810a540e0803242204v23ca1919w60a31348d9c800ba@mail.gmail.com> References: <810a540e0803242204v23ca1919w60a31348d9c800ba@mail.gmail.com> Message-ID: <8152B374-663E-47D7-8AC8-FB1A34AA253A@mac.com> On Mar 25, 2008, at 12:04 AM, Pat Maddox wrote: > On Mon, Mar 24, 2008 at 6:50 PM, Chuck Remes > wrote: >> So I have a complex object that I need to construct. This complex >> object, at runtime, takes an object in its initializer. The >> initializer interrogates the object and creates several collaborative >> objects based upon values from that interrogation. >> >> The construction is complicated enough that it pretty much begs to be >> implemented via the Builder Pattern. >> >> My problem is that I don't know how to test this behavior regardless >> of whether the object handles its own construction or I create a >> separate Builder object to construct it for me. >> >> For example: >> >> class ComplexObjectBuilder >> def initialize >> @complex_object = ComplexObject.new >> end >> >> def create_foo(control, value) >> case control do >> when :a then @complex_object.foo = SpecialObject.new(value * 4) >> when :v then @complex_object.foo = OtherObject.new >> when :z then @complex_object.foo = YAObject.new >> end >> end >> >> def create_bar(control, value) >> # similar to above >> end >> >> def construct >> # some business rules to make sure the object is complete; use >> # defaults for fields that were not set via the interface >> return @complex_object >> end >> end >> >> @builder = ComplexObjectBuilder.new >> @builder.create_foo(params_object.accessor1, params_object.accessor2) >> @builder.create_bar(params_object.accessor3, params_object.accessor4) >> baz = @builder.construct >> >> How the heck do I test anything here? I do not see how I can >> validate >> the behavior of #create_foo or #create_bar without exposing >> @complex_object via a public interface. Those #create_* methods are >> purely for construction and do not return a value. Only #construct >> returns a value which should be the completed object >> >> Is there a transformation to consider to make this more testable? >> >> I'm hoping someone has tackled this before and can provide me some >> insight. Many thanks... >> >> cr > > Hey Chuck, > > I would toss whatever code you have and BDD it from scratch. > Shouldn't be that difficult...you can start off with stuff like > > describe ComplexObjectBuilder, " when foo is built with :a" do > before(:each) do > builder = ComplexObjectBuilder.new > builder.create_foo :a, 3 > @built = builder.construct > end > it "should create a special object" do > @built.foo.should be_a(SpecialObject) > end > > it "should quadruple the value passed to the special object" do > @built.foo.some_val.should == 12 > end > end > Pat, thanks for your response. I have question regarding your suggestion. In the first "it" you are asserting that @built.foo should be an object. The @built instance variable is the ComplexObject and not the ComplexObjectBuilder. Shouldn't we be testing the behavior of the builder and not the ComplexObject the builder produces? Another way, shouldn't I put the ComplexObject assertions into its own set of specs? It just seems like we're mixing the behavior of two objects here: ComplexObjectBuilder and ComplexObject. Perhaps that is okay since they are so tightly coupled. In a sense the ComplexObjectBuilder is just a fancy constructor for the other object; it only gets refactored out to its own object because it has so many parts/steps. ?? cr From sethladd at gmail.com Tue Mar 25 12:38:21 2008 From: sethladd at gmail.com (Seth Ladd) Date: Tue, 25 Mar 2008 06:38:21 -1000 Subject: [rspec-users] Testing Controllers with respond_to? In-Reply-To: <57c63afe0803250435x132f3447qe7215518bd9c7782@mail.gmail.com> References: <64f07e2c0803242335i2d3a9bbbo48d31e9285e1a359@mail.gmail.com> <64f07e2c0803250006q33f5174eyf1fe2d4adb02a208@mail.gmail.com> <57c63afe0803250435x132f3447qe7215518bd9c7782@mail.gmail.com> Message-ID: <64f07e2c0803250938y72b0c93fod4638ee03a1f82b@mail.gmail.com> > There is a guideline in TDD that you should test your code and not > other people's code. The behaviour you're interested in testing is > that of ActionController::Base, not of your code. I, of course, do not want to test Rails. I do, however, want to ensure that I have a block to handle the correct MIME type and I have a template for that MIME type. I suppose checking for the template "foo/show" is good enough in this case. If there was an error, I'd get a nil there. I guess where this strategy falls down is if I forgot to put a responds_to in my controller. Then, no matter the format, I'll still render 'foo/show' (assuming I do indeed have that template) Thanks for your help, Seth From dchelimsky at gmail.com Tue Mar 25 12:43:30 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 25 Mar 2008 11:43:30 -0500 Subject: [rspec-users] Testing Controllers with respond_to? In-Reply-To: <64f07e2c0803250938y72b0c93fod4638ee03a1f82b@mail.gmail.com> References: <64f07e2c0803242335i2d3a9bbbo48d31e9285e1a359@mail.gmail.com> <64f07e2c0803250006q33f5174eyf1fe2d4adb02a208@mail.gmail.com> <57c63afe0803250435x132f3447qe7215518bd9c7782@mail.gmail.com> <64f07e2c0803250938y72b0c93fod4638ee03a1f82b@mail.gmail.com> Message-ID: <57c63afe0803250943s788e93eeofe9b605c2913e485@mail.gmail.com> On Tue, Mar 25, 2008 at 11:38 AM, Seth Ladd wrote: > > There is a guideline in TDD that you should test your code and not > > other people's code. The behaviour you're interested in testing is > > that of ActionController::Base, not of your code. > > I, of course, do not want to test Rails. I do, however, want to > ensure that I have a block to handle the correct MIME type and I have > a template for that MIME type. I suppose checking for the template > "foo/show" is good enough in this case. If there was an error, I'd > get a nil there. If you're really concerned about it, you could also mock respond_to: format = mock("format") format.should_receive(:json).and_return("this text") controller.should_receive(:respond_to).and_yield(format) get 'path/to/file', :format => 'json' That seems a bit implementation heavy, but it might give you the feeling of confidence you're looking for. HTH, David > > I guess where this strategy falls down is if I forgot to put a > responds_to in my controller. Then, no matter the format, I'll still > render 'foo/show' (assuming I do indeed have that template) > > Thanks for your help, > > > Seth > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt at mattberther.com Tue Mar 25 12:46:47 2008 From: matt at mattberther.com (Matt Berther) Date: Tue, 25 Mar 2008 10:46:47 -0600 Subject: [rspec-users] Testing Controllers with respond_to? In-Reply-To: <64f07e2c0803250938y72b0c93fod4638ee03a1f82b@mail.gmail.com> References: <64f07e2c0803242335i2d3a9bbbo48d31e9285e1a359@mail.gmail.com> <64f07e2c0803250006q33f5174eyf1fe2d4adb02a208@mail.gmail.com> <57c63afe0803250435x132f3447qe7215518bd9c7782@mail.gmail.com> <64f07e2c0803250938y72b0c93fod4638ee03a1f82b@mail.gmail.com> Message-ID: <0461D482-9179-4F3C-9BC4-1C6FBFFDFFF3@mattberther.com> Hi Seth, To get around this, are you able to test the response.headers collection? This tests the code that you wrote, rather than the template logic performed by rails. response.headers['Content-Type'].should == "text/html" Untested, of course... but it may work :) -- Matt Berther http://www.mattberther.com On Mar 25, 2008, at 10:38 AM, Seth Ladd wrote: >> There is a guideline in TDD that you should test your code and not >> other people's code. The behaviour you're interested in testing is >> that of ActionController::Base, not of your code. > > I, of course, do not want to test Rails. I do, however, want to > ensure that I have a block to handle the correct MIME type and I have > a template for that MIME type. I suppose checking for the template > "foo/show" is good enough in this case. If there was an error, I'd > get a nil there. > > I guess where this strategy falls down is if I forgot to put a > responds_to in my controller. Then, no matter the format, I'll still > render 'foo/show' (assuming I do indeed have that template) > > Thanks for your help, > Seth > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From coreyhaines at gmail.com Tue Mar 25 12:56:11 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Tue, 25 Mar 2008 12:56:11 -0400 Subject: [rspec-users] Plaint Text Stories Comments in output? Message-ID: <6bdacb70803250956i403d5b06n62e3689a545103c4@mail.gmail.com> Is there an easy way to get a story output that includes comment text inside the Scenario? For example, I have a scenario like Scenario: User tries to log in with invalid credentials Card: 5732 Given a visitor And username: invalid Then, be able to get a summary/output that includes the Card: 5732 line. Right now, they aren't output, as they are ignored by the runner. Thanks. -Corey -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080325/5fc17909/attachment.html From tim at pivotib.com Tue Mar 25 13:15:32 2008 From: tim at pivotib.com (Tim Glen) Date: Tue, 25 Mar 2008 13:15:32 -0400 Subject: [rspec-users] Testing Controllers with respond_to? In-Reply-To: <0461D482-9179-4F3C-9BC4-1C6FBFFDFFF3@mattberther.com> References: <64f07e2c0803242335i2d3a9bbbo48d31e9285e1a359@mail.gmail.com> <64f07e2c0803250006q33f5174eyf1fe2d4adb02a208@mail.gmail.com> <57c63afe0803250435x132f3447qe7215518bd9c7782@mail.gmail.com> <64f07e2c0803250938y72b0c93fod4638ee03a1f82b@mail.gmail.com> <0461D482-9179-4F3C-9BC4-1C6FBFFDFFF3@mattberther.com> Message-ID: <29368F27-C988-428F-8EBA-B24B68B49E47@pivotib.com> To do this, I've typically just add the HTTP_ACCEPT header. I can't remember where I picked this up, but it's does specify a format in your respond_to block: Here's the do_request (and a sample spec) for one of my specs where I'm checking for a generated csv file: def do_request @request.env["HTTP_ACCEPT"] = "text/csv" get :show, :id => "1" end it "should return a csv download" do @controller.should_receive(:send_file).with(@file, {:filename => "report-#{@report.id }.csv", :type => 'text/csv', :disposition => 'attachment'}) do_get end Now my assumption is that your mime-type would need to be registered in rails for this to work (if you have need of one outside of the norm), which arguably has the added benefit of ensuring you added it into your environment initializers... -- Tim Glen On 25-Mar-08, at 12:46 PM, Matt Berther wrote: > Hi Seth, > > To get around this, are you able to test the response.headers > collection? This tests the code that you wrote, rather than the > template logic performed by rails. > > response.headers['Content-Type'].should == "text/html" > > Untested, of course... but it may work :) > > -- > Matt Berther > http://www.mattberther.com > > > > > On Mar 25, 2008, at 10:38 AM, Seth Ladd wrote: > >>> There is a guideline in TDD that you should test your code and not >>> other people's code. The behaviour you're interested in testing is >>> that of ActionController::Base, not of your code. >> >> I, of course, do not want to test Rails. I do, however, want to >> ensure that I have a block to handle the correct MIME type and I have >> a template for that MIME type. I suppose checking for the template >> "foo/show" is good enough in this case. If there was an error, I'd >> get a nil there. >> >> I guess where this strategy falls down is if I forgot to put a >> responds_to in my controller. Then, no matter the format, I'll still >> render 'foo/show' (assuming I do indeed have that template) >> >> Thanks for your help, >> Seth >> _______________________________________________ >> 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 Tue Mar 25 14:00:06 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 25 Mar 2008 19:00:06 +0100 Subject: [rspec-users] Plaint Text Stories Comments in output? In-Reply-To: <6bdacb70803250956i403d5b06n62e3689a545103c4@mail.gmail.com> References: <6bdacb70803250956i403d5b06n62e3689a545103c4@mail.gmail.com> Message-ID: <8d961d900803251100v51f6e204p8532695f0f7f7cee@mail.gmail.com> On Tue, Mar 25, 2008 at 5:56 PM, Corey Haines wrote: > Is there an easy way to get a story output that includes comment text inside > the Scenario? > Plain text stories are parsed and turn into objects, then written out again. There is no way to capture "unknown" lines for now unless you patch it. Aslak > For example, I have a scenario like > > Scenario: User tries to log in with invalid credentials > Card: 5732 > Given a visitor > And username: invalid > > > Then, be able to get a summary/output that includes the Card: 5732 line. > Right now, they aren't output, as they are ignored by the runner. > > Thanks. > -Corey > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dave at textgoeshere.org.uk Tue Mar 25 14:08:59 2008 From: dave at textgoeshere.org.uk (David Nolan) Date: Tue, 25 Mar 2008 18:08:59 +0000 Subject: [rspec-users] HOWTO: RSpec integration with Rails Message-ID: Hi, I've hacked together a setup to load an RSpec backtrace into jEdit (in other words, you'll be able to click the relevant failed behaviour or error to go straight the relevant file and line). More info here: http://textgoeshere.org.uk/articles/2008/03/howto-integrate-rspec-on-rails-with-jedit/ -- Dave Nolan http://textgoeshere.org.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080325/cbc37490/attachment.html From coreyhaines at gmail.com Tue Mar 25 14:57:59 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Tue, 25 Mar 2008 14:57:59 -0400 Subject: [rspec-users] Plaint Text Stories Comments in output? In-Reply-To: <8d961d900803251100v51f6e204p8532695f0f7f7cee@mail.gmail.com> References: <6bdacb70803250956i403d5b06n62e3689a545103c4@mail.gmail.com> <8d961d900803251100v51f6e204p8532695f0f7f7cee@mail.gmail.com> Message-ID: <6bdacb70803251157r651ade48l348e842bf78244b5@mail.gmail.com> On Tue, Mar 25, 2008 at 2:00 PM, aslak hellesoy wrote: > On Tue, Mar 25, 2008 at 5:56 PM, Corey Haines > wrote: > > Is there an easy way to get a story output that includes comment text > inside > > the Scenario? > > > > Plain text stories are parsed and turn into objects, then written out > again. There is no way to capture "unknown" lines for now unless you > patch it. > Okay, thanks. After a bit more thought, I realized that listing out the contents of the story is the pretty output that I'm looking for. :) -Corey -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080325/b1098a2f/attachment.html From coreyhaines at gmail.com Tue Mar 25 16:54:10 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Tue, 25 Mar 2008 16:54:10 -0400 Subject: [rspec-users] pending plain text story step Message-ID: <6bdacb70803251354o31076546k251ac594d36962a4@mail.gmail.com> #pending works when creating a step for a plain text story, but adding text to the method call doesn't spit it out in the output. Is this a bug, or are we doing something wrong? Then("blah") do pending "waiting for implementation details" end -corey -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080325/8a0fd078/attachment.html From gbs at panix.com Tue Mar 25 16:45:13 2008 From: gbs at panix.com (Eric Harris-Braun) Date: Tue, 25 Mar 2008 16:45:13 -0400 Subject: [rspec-users] newbie first run question Message-ID: Hi folks, RSpec 1.1.3 is failing for me out of the box. I installed both rspec and rspec_on_rails using svn following the instructions on the site. Then I used the rspec generate script, created a very simple test example and run rspec with: rake spec. What I get back is: /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require': no such file to load -- spec/rails (MissingSourceFile) (full error stack at: http://pastie.caboo.se/170502) Any help greatly appreciated. Thanks, -Eric -- My weight is perfect for my height -- which varies. From dchelimsky at gmail.com Wed Mar 26 08:23:14 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 26 Mar 2008 08:23:14 -0400 Subject: [rspec-users] pending plain text story step In-Reply-To: <6bdacb70803251354o31076546k251ac594d36962a4@mail.gmail.com> References: <6bdacb70803251354o31076546k251ac594d36962a4@mail.gmail.com> Message-ID: <57c63afe0803260523t2f056b07s175839d6079bcee1@mail.gmail.com> On Tue, Mar 25, 2008 at 4:54 PM, Corey Haines wrote: > #pending works when creating a step for a plain text story, but adding text > to the method call doesn't spit it out in the output. Is this a bug, or are > we doing something wrong? Let's call it a missing feature :) > > Then("blah") do > pending "waiting for implementation details" > end > > -corey > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From coreyhaines at gmail.com Wed Mar 26 11:07:22 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 26 Mar 2008 11:07:22 -0400 Subject: [rspec-users] pending plain text story step In-Reply-To: <57c63afe0803260523t2f056b07s175839d6079bcee1@mail.gmail.com> References: <6bdacb70803251354o31076546k251ac594d36962a4@mail.gmail.com> <57c63afe0803260523t2f056b07s175839d6079bcee1@mail.gmail.com> Message-ID: <6bdacb70803260807n5b4ce06eh5e8c1c365442b1a1@mail.gmail.com> On Wed, Mar 26, 2008 at 8:23 AM, David Chelimsky wrote: > On Tue, Mar 25, 2008 at 4:54 PM, Corey Haines > wrote: > > #pending works when creating a step for a plain text story, but adding > text > > to the method call doesn't spit it out in the output. Is this a bug, or > are > > we doing something wrong? > > Let's call it a missing feature :) > > Sounds good. That shouldn't be too hard to patch. I'll look into adding it to my list (now consisting of two things) to look at. Thanks. -Corey -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080326/c79c51b3/attachment.html From toastkid.williams at gmail.com Wed Mar 26 12:17:02 2008 From: toastkid.williams at gmail.com (Max Williams) Date: Wed, 26 Mar 2008 16:17:02 +0000 Subject: [rspec-users] newbie first run question In-Reply-To: References: Message-ID: I had a similar problem with rake: try ruby script/spec On 25/03/2008, Eric Harris-Braun wrote: > > Hi folks, > > RSpec 1.1.3 is failing for me out of the box. I installed both rspec > and rspec_on_rails using svn following the instructions on the site. > Then I used the rspec generate script, created a very simple test > example and run rspec with: > > rake spec. > > What I get back is: > > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `gem_original_require': no such file to load -- spec/rails > (MissingSourceFile) > > > (full error stack at: http://pastie.caboo.se/170502) > > Any help greatly appreciated. > > Thanks, > > -Eric > > -- > My weight is perfect for my height -- which varies. > _______________________________________________ > 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/20080326/cfbc0c91/attachment.html From joe at pinkpucker.net Wed Mar 26 13:35:43 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Wed, 26 Mar 2008 10:35:43 -0700 Subject: [rspec-users] story runner output Message-ID: Is it possible to optionally reduce the story runner output to just dots or something? Lots of stories makes it difficult to see previous test results. Joe From aslak.hellesoy at gmail.com Wed Mar 26 13:45:02 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 26 Mar 2008 18:45:02 +0100 Subject: [rspec-users] story runner output In-Reply-To: References: Message-ID: <8d961d900803261045v556994eeo5024f08344ccab6c@mail.gmail.com> On Wed, Mar 26, 2008 at 6:35 PM, Joe Van Dyk wrote: > Is it possible to optionally reduce the story runner output to just > dots or something? Lots of stories makes it difficult to see previous > test results. > Anything is possible, but you have to implement a progress_bar_formatter. See spec/runner/formatter/story Unfortunately, the formatters for examples and stories are not the same, but you can look at spec/runner/formatter/progress_bar_formatter.rb for inspiration. And finally you have to make the command line able to understand you want that formatter. See spec/runner/options.rb STORY_FORMATTERS Patches are welcome as always. Aslak > Joe > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From philodespotos at gmail.com Wed Mar 26 15:08:56 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Wed, 26 Mar 2008 14:08:56 -0500 Subject: [rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot Message-ID: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> Hello everyone, A few weeks ago, I put together a little project that provides a have_tag() matcher look-alike that can be used outside of Rails projects, backed by Hpricot, which I very creatively named rspec_hpricot_matchers. It's not a drop-in replacement for rspec_on_rails' have_tag(): no substitution values, Hpricot's CSS selectors aren't identical to assert_select's, and with_tag() has been replaced by nested calls to have_tag(). But it's pretty close and even enjoys a few benefits over the standard implementation. I finally got around to registering a project on RubyForge and pushing a gem, so it is now available with just: gem install rspec_hpricot_matchers If you're interested, the source is hosted on github at: http://github.com/pd/rspec_hpricot_matchers I'm using this both in isolated XML-related libraries and in my Rails projects, and I haven't come up with any features I want lately, so it's reasonably stable in my experience. Usage examples are available in the README, and the specs are simple enough to be another good set of examples. Suggestions, patches and angry flames about list spamming are all welcome. Thanks Kyle From glenn at aldenta.com Wed Mar 26 17:02:32 2008 From: glenn at aldenta.com (Glenn Ford) Date: Wed, 26 Mar 2008 17:02:32 -0400 Subject: [rspec-users] Trouble with my first Story In-Reply-To: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> References: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> Message-ID: Hi all! I've been through the RSpec Stories PeepCode and some various other readings online, and now I'm trying to build a dummy application of the traditional style: log in, make posts, add comments. So I've run the scaffold for posts/comments and the script for RestfulAuthentication so I have the users and SessionController and all that set up in this project. Now I've written this story: http://pastie.caboo.se/pastes/171140 In it I'm trying to do a post to "/session/create" in order to log in. I figure I want to be able to call this from an Story so that I can reuse it for different scenarios when I want to test things requiring login. What am I doing wrong here? Thanks! Glenn From jahrel at gmail.com Wed Mar 26 17:29:03 2008 From: jahrel at gmail.com (Fahr Jahrel) Date: Wed, 26 Mar 2008 18:29:03 -0300 Subject: [rspec-users] Testing controller without integrate views Message-ID: Hello, I'm new to RSpec and I'm having some trouble testing controllers. After a lot of testing without coming any closer to a solution, I figured I should try describing the problem here. Any help will be appreciated. :-) I'm testing controllers and view separately, but something strange seems to be happening. When I omit integrate_views, all controllers return a 200 OK status even if the view doesn't actually exist. That's seems to be OK because even so RSpec seems to be using some internal information and find the correct status. But, for some reason, some actions are not following this pattern. The status is incorrect even if the template doesn't exist. That's messing with the tests, because things like response.should be_success and response.render_template("controller/template"). So, if I implement the test to expect a failure, it doesn't actual fail and I'm unsure about the tests now. And if I use integrate_views, the tests fail correctly with the right status code. Has anybody seem anything like that? What are the best practices when not using integrate_views? Thanks for all the help, Ronaldo From win at wincent.com Wed Mar 26 17:34:17 2008 From: win at wincent.com (Wincent Colaiuta) Date: Wed, 26 Mar 2008 22:34:17 +0100 Subject: [rspec-users] How to spec controller whose route has a different name? Message-ID: <34AF5914-A19F-440A-900A-29D1CB5A2EDC@wincent.com> Perhaps I am missing something extremely obvious, but I am unable to get my specs to work for an ArticlesController which is accessed using URLs like "/wiki/foo". Here's the corresponding line from config/routes.rb: map.resources :wiki, :controller => 'articles' This is Rails 2.0.2, but in the next release that will be: map.resources :articles, :as => :wiki And here is a very short excerpt from the specs: describe ArticlesController do describe 'GET /wiki/new' do before do @article = mock_model Article Article.stub!(:new).and_return(@article) end def do_get get :new # doesn't work #get 'new' # doesn't work either #get '/wiki/new' # doesn't work either end it 'should succeed' do do_get response.should be_success end end end In specs where the controller uses totally "normal" routing, RSpec seems to correctly infer that when I "describe ThingController" and then do "get :new" then I am talking about doing a GET of "/thing/ new". But that doesn't seem to be happening in this case (all the specs fail) and I can't seem to figure out how to make it work. I tried setting an explicit controller_name but it didn't help. Any suggestions? Cheers, Wincent From cremes.devlist at mac.com Wed Mar 26 18:28:06 2008 From: cremes.devlist at mac.com (Chuck Remes) Date: Wed, 26 Mar 2008 17:28:06 -0500 Subject: [rspec-users] Trouble with my first Story In-Reply-To: References: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> Message-ID: On Mar 26, 2008, at 4:02 PM, Glenn Ford wrote: > Hi all! I've been through the RSpec Stories PeepCode and some various > other readings online, and now I'm trying to build a dummy application > of the traditional style: log in, make posts, add comments. > > So I've run the scaffold for posts/comments and the script for > RestfulAuthentication so I have the users and SessionController and > all that set up in this project. Now I've written this story: > > http://pastie.caboo.se/pastes/171140 > > In it I'm trying to do a post to "/session/create" in order to log > in. I figure I want to be able to call this from an Story so that I > can reuse it for different scenarios when I want to test things > requiring login. > > What am I doing wrong here? Glenn, please include a pastie that shows the error you are getting or the behavior that isn't working. cr From mvanholstyn at gmail.com Wed Mar 26 19:45:56 2008 From: mvanholstyn at gmail.com (Mark Van Holstyn) Date: Wed, 26 Mar 2008 19:45:56 -0400 Subject: [rspec-users] story runner output In-Reply-To: <8d961d900803261045v556994eeo5024f08344ccab6c@mail.gmail.com> References: <8d961d900803261045v556994eeo5024f08344ccab6c@mail.gmail.com> Message-ID: brynary has done this work already ( http://github.com/brynary/rspec/tree/master). David was getting failures when merging it in though. I looked into it one day, but nothing failed for me. David, have you had a chance to give it another look? I would love to get this in. Mark On Wed, Mar 26, 2008 at 1:45 PM, aslak hellesoy wrote: > On Wed, Mar 26, 2008 at 6:35 PM, Joe Van Dyk wrote: > > Is it possible to optionally reduce the story runner output to just > > dots or something? Lots of stories makes it difficult to see previous > > test results. > > > > Anything is possible, but you have to implement a > progress_bar_formatter. See spec/runner/formatter/story > Unfortunately, the formatters for examples and stories are not the > same, but you can look at > spec/runner/formatter/progress_bar_formatter.rb for inspiration. > > And finally you have to make the command line able to understand you > want that formatter. See spec/runner/options.rb STORY_FORMATTERS > > Patches are welcome as always. > > Aslak > > > Joe > > _______________________________________________ > > 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 > -- Mark Van Holstyn, Partner / Software Developer mvanholstyn at mutuallyhuman.com, (616) 706-6842 Mutually Human Software, http://mutuallyhuman.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080326/f0a30277/attachment.html From ashley.moran at patchspace.co.uk Wed Mar 26 19:50:49 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 26 Mar 2008 23:50:49 +0000 Subject: [rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot In-Reply-To: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> References: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> Message-ID: <6BF6965A-5B63-499F-8BC8-E636E5CBFCC1@patchspace.co.uk> On 26 Mar 2008, at 19:08, Kyle Hargraves wrote: > I finally got around to registering a project on RubyForge and pushing > a gem, so it is now available with just: > > gem install rspec_hpricot_matchers Hi Kyle Thanks for releasing this as a gem, makes it much easier to get hold of. The only deficiency in it that bugs me is the poor error reporting for nested specs, but that would be pretty tough to fix. (I'd love to think I could add that but not sure I will get time.) I still think this should be in RSpec core though, hint hint David ;o) Is there any chance it will make it in? Making assertions about XML data is pretty common doing both web-based and non-web-based apps. Plus of course there is the little issue that Rails' assert_select doesn't *actually work*, which is generally considered a requirement for a testing library. Ashley From glenn at aldenta.com Wed Mar 26 19:51:04 2008 From: glenn at aldenta.com (Glenn Ford) Date: Wed, 26 Mar 2008 19:51:04 -0400 Subject: [rspec-users] Trouble with my first Story In-Reply-To: References: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> Message-ID: <87F8070D-8615-44FB-A12C-BFDB605760FC@aldenta.com> On Mar 26, 2008, at 6:28 PM, Chuck Remes wrote: > > On Mar 26, 2008, at 4:02 PM, Glenn Ford wrote: >> Hi all! I've been through the RSpec Stories PeepCode and some >> various >> other readings online, and now I'm trying to build a dummy >> application >> of the traditional style: log in, make posts, add comments. >> >> So I've run the scaffold for posts/comments and the script for >> RestfulAuthentication so I have the users and SessionController and >> all that set up in this project. Now I've written this story: >> >> http://pastie.caboo.se/pastes/171140 >> >> In it I'm trying to do a post to "/session/create" in order to log >> in. I figure I want to be able to call this from an Story so that I >> can reuse it for different scenarios when I want to test things >> requiring login. >> >> What am I doing wrong here? > > Glenn, > > please include a pastie that shows the error you are getting or the > behavior that isn't working. > > cr Oh sorry about that... it was there before I promise :) FAILURES: 1) User Stuff (Create a new user) FAILED Spec::Expectations::ExpectationNotMetError: expected redirect? to return true, got false stories/user_story.rb:34:in `I should be logged in' stories/user_story.rb:31 stories/user_story.rb:3 From matt at mattberther.com Wed Mar 26 20:19:40 2008 From: matt at mattberther.com (Matt Berther) Date: Wed, 26 Mar 2008 18:19:40 -0600 Subject: [rspec-users] Trouble with my first Story In-Reply-To: <87F8070D-8615-44FB-A12C-BFDB605760FC@aldenta.com> References: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> <87F8070D-8615-44FB-A12C-BFDB605760FC@aldenta.com> Message-ID: Hi Glen, I do not mean to insult you, but is /session/create actually doing a redirect? A similar rspec test works for me. -- Matt Berther http://www.mattberther.com On Mar 26, 2008, at 5:51 PM, Glenn Ford wrote: > On Mar 26, 2008, at 6:28 PM, Chuck Remes wrote: > >> >> On Mar 26, 2008, at 4:02 PM, Glenn Ford wrote: >>> Hi all! I've been through the RSpec Stories PeepCode and some >>> various >>> other readings online, and now I'm trying to build a dummy >>> application >>> of the traditional style: log in, make posts, add comments. >>> >>> So I've run the scaffold for posts/comments and the script for >>> RestfulAuthentication so I have the users and SessionController and >>> all that set up in this project. Now I've written this story: >>> >>> http://pastie.caboo.se/pastes/171140 >>> >>> In it I'm trying to do a post to "/session/create" in order to log >>> in. I figure I want to be able to call this from an Story so that I >>> can reuse it for different scenarios when I want to test things >>> requiring login. >>> >>> What am I doing wrong here? >> >> Glenn, >> >> please include a pastie that shows the error you are getting or the >> behavior that isn't working. >> >> cr > > Oh sorry about that... it was there before I promise :) > > FAILURES: > 1) User Stuff (Create a new user) FAILED > Spec::Expectations::ExpectationNotMetError: expected redirect? to > return true, got false > stories/user_story.rb:34:in `I should be logged in' > stories/user_story.rb:31 > stories/user_story.rb:3 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From glenn at aldenta.com Wed Mar 26 21:20:35 2008 From: glenn at aldenta.com (Glenn Ford) Date: Wed, 26 Mar 2008 21:20:35 -0400 Subject: [rspec-users] Trouble with my first Story In-Reply-To: References: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> <87F8070D-8615-44FB-A12C-BFDB605760FC@aldenta.com> Message-ID: <3D0DB7A1-7676-4265-BC30-A3EEEF083311@aldenta.com> It actually should do a redirect, but checking for response.should be_success also fails. The request isn't actually being made. I just can't figure out why. Glenn On Mar 26, 2008, at 8:19 PM, Matt Berther wrote: > Hi Glen, > > I do not mean to insult you, but is /session/create actually doing a > redirect? A similar rspec test works for me. > > -- > Matt Berther > http://www.mattberther.com > > > > > On Mar 26, 2008, at 5:51 PM, Glenn Ford wrote: > >> On Mar 26, 2008, at 6:28 PM, Chuck Remes wrote: >> >>> >>> On Mar 26, 2008, at 4:02 PM, Glenn Ford wrote: >>>> Hi all! I've been through the RSpec Stories PeepCode and some >>>> various >>>> other readings online, and now I'm trying to build a dummy >>>> application >>>> of the traditional style: log in, make posts, add comments. >>>> >>>> So I've run the scaffold for posts/comments and the script for >>>> RestfulAuthentication so I have the users and SessionController and >>>> all that set up in this project. Now I've written this story: >>>> >>>> http://pastie.caboo.se/pastes/171140 >>>> >>>> In it I'm trying to do a post to "/session/create" in order to log >>>> in. I figure I want to be able to call this from an Story so >>>> that I >>>> can reuse it for different scenarios when I want to test things >>>> requiring login. >>>> >>>> What am I doing wrong here? >>> >>> Glenn, >>> >>> please include a pastie that shows the error you are getting or the >>> behavior that isn't working. >>> >>> cr >> >> Oh sorry about that... it was there before I promise :) >> >> FAILURES: >> 1) User Stuff (Create a new user) FAILED >> Spec::Expectations::ExpectationNotMetError: expected redirect? to >> return true, got false >> stories/user_story.rb:34:in `I should be logged in' >> stories/user_story.rb:31 >> stories/user_story.rb:3 >> >> _______________________________________________ >> 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 Mar 26 22:13:05 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 26 Mar 2008 22:13:05 -0400 Subject: [rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot In-Reply-To: <6BF6965A-5B63-499F-8BC8-E636E5CBFCC1@patchspace.co.uk> References: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> <6BF6965A-5B63-499F-8BC8-E636E5CBFCC1@patchspace.co.uk> Message-ID: <57c63afe0803261913y6f4d9953pa1ecdb7c561de778@mail.gmail.com> On Wed, Mar 26, 2008 at 7:50 PM, Ashley Moran wrote: > > On 26 Mar 2008, at 19:08, Kyle Hargraves wrote: > > > I finally got around to registering a project on RubyForge and pushing > > a gem, so it is now available with just: > > > > gem install rspec_hpricot_matchers > > > Hi Kyle > > Thanks for releasing this as a gem, makes it much easier to get hold > of. The only deficiency in it that bugs me is the poor error > reporting for nested specs, but that would be pretty tough to fix. > (I'd love to think I could add that but not sure I will get time.) > > I still think this should be in RSpec core though, hint hint > David ;o) Is there any chance it will make it in? Not likely. Not because it isn't awesome. I'll probably be using it myself. But every good idea for a matcher library doesn't belong in rspec. In fact, the whole point of creating such a simple protocol for matchers was to encourage external libraries. I think it's fine just as it is. FWIW, David > Making assertions > about XML data is pretty common doing both web-based and non-web-based > apps. Plus of course there is the little issue that Rails' > assert_select doesn't *actually work*, which is generally considered a > requirement for a testing library. > > Ashley > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Mar 26 22:15:09 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 26 Mar 2008 22:15:09 -0400 Subject: [rspec-users] Trouble with my first Story In-Reply-To: References: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> Message-ID: <57c63afe0803261915l55a6059ck3fcb9a82831f7434@mail.gmail.com> On Wed, Mar 26, 2008 at 5:02 PM, Glenn Ford wrote: > Hi all! I've been through the RSpec Stories PeepCode and some various > other readings online, and now I'm trying to build a dummy application > of the traditional style: log in, make posts, add comments. > > So I've run the scaffold for posts/comments and the script for > RestfulAuthentication so I have the users and SessionController and > all that set up in this project. Now I've written this story: > > http://pastie.caboo.se/pastes/171140 Shouldn't that be a post to "/sessons/"? > > In it I'm trying to do a post to "/session/create" in order to log > in. I figure I want to be able to call this from an Story so that I > can reuse it for different scenarios when I want to test things > requiring login. > > What am I doing wrong here? > > Thanks! > Glenn > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From glenn at aldenta.com Wed Mar 26 22:25:55 2008 From: glenn at aldenta.com (Glenn Ford) Date: Wed, 26 Mar 2008 22:25:55 -0400 Subject: [rspec-users] Trouble with my first Story In-Reply-To: <57c63afe0803261915l55a6059ck3fcb9a82831f7434@mail.gmail.com> References: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> <57c63afe0803261915l55a6059ck3fcb9a82831f7434@mail.gmail.com> Message-ID: <9A09445F-2497-473F-AD9D-CD839C352503@aldenta.com> That was it, thank you! Must have been a long day, I can't believe I didn't spot that :) On Mar 26, 2008, at 10:15 PM, David Chelimsky wrote: > On Wed, Mar 26, 2008 at 5:02 PM, Glenn Ford wrote: >> Hi all! I've been through the RSpec Stories PeepCode and some >> various >> other readings online, and now I'm trying to build a dummy >> application >> of the traditional style: log in, make posts, add comments. >> >> So I've run the scaffold for posts/comments and the script for >> RestfulAuthentication so I have the users and SessionController and >> all that set up in this project. Now I've written this story: >> >> http://pastie.caboo.se/pastes/171140 > > Shouldn't that be a post to "/sessons/"? > >> >> In it I'm trying to do a post to "/session/create" in order to log >> in. I figure I want to be able to call this from an Story so that I >> can reuse it for different scenarios when I want to test things >> requiring login. >> >> What am I doing wrong here? >> >> Thanks! >> Glenn >> _______________________________________________ >> 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 loop at superinfinite.com Thu Mar 27 07:08:58 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Thu, 27 Mar 2008 12:08:58 +0100 Subject: [rspec-users] Checking for response => head :ok in a story Message-ID: <6A0E50F2-28D6-428D-9013-F20DFBB3E9F7@superinfinite.com> Hey gang, I'm writing a story in which I update a model via XML. So far, so good. But, I want to test the outcome of the controller, namely the following code: format.xml { head :ok } How can I test this in a story? thanks, bartz From dchelimsky at gmail.com Thu Mar 27 08:50:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 27 Mar 2008 08:50:53 -0400 Subject: [rspec-users] Checking for response => head :ok in a story In-Reply-To: <6A0E50F2-28D6-428D-9013-F20DFBB3E9F7@superinfinite.com> References: <6A0E50F2-28D6-428D-9013-F20DFBB3E9F7@superinfinite.com> Message-ID: <57c63afe0803270550y932dd48wf92cfbb70d0409f8@mail.gmail.com> On Thu, Mar 27, 2008 at 7:08 AM, Bart Zonneveld wrote: > Hey gang, > > I'm writing a story in which I update a model via XML. So far, so > good. But, I want to test the outcome of the controller, namely the > following code: > > format.xml { head :ok } > > How can I test this in a story? Same as in a controller example: response.should be_success response.body.should == "" Cheers, David > > thanks, > bartz > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Mar 27 08:53:00 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 27 Mar 2008 08:53:00 -0400 Subject: [rspec-users] Checking for response => head :ok in a story In-Reply-To: <57c63afe0803270550y932dd48wf92cfbb70d0409f8@mail.gmail.com> References: <6A0E50F2-28D6-428D-9013-F20DFBB3E9F7@superinfinite.com> <57c63afe0803270550y932dd48wf92cfbb70d0409f8@mail.gmail.com> Message-ID: <57c63afe0803270553u665e95a7u341da9447188a4ee@mail.gmail.com> On Thu, Mar 27, 2008 at 8:50 AM, David Chelimsky wrote: > On Thu, Mar 27, 2008 at 7:08 AM, Bart Zonneveld wrote: > > Hey gang, > > > > I'm writing a story in which I update a model via XML. So far, so > > good. But, I want to test the outcome of the controller, namely the > > following code: > > > > format.xml { head :ok } > > > > How can I test this in a story? > > Same as in a controller example: > > response.should be_success > response.body.should == "" Or - for the latter ... response.should be_blank Just a matter of preference, but perhaps that's more readable. > > Cheers, > David > > > > > > > thanks, > > bartz > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From loop at superinfinite.com Thu Mar 27 08:56:40 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Thu, 27 Mar 2008 13:56:40 +0100 Subject: [rspec-users] Checking for response => head :ok in a story In-Reply-To: <57c63afe0803270553u665e95a7u341da9447188a4ee@mail.gmail.com> References: <6A0E50F2-28D6-428D-9013-F20DFBB3E9F7@superinfinite.com> <57c63afe0803270550y932dd48wf92cfbb70d0409f8@mail.gmail.com> <57c63afe0803270553u665e95a7u341da9447188a4ee@mail.gmail.com> Message-ID: <575BB64B-74EA-4FF5-B7F9-7344169CC08B@superinfinite.com> On 27 mrt 2008, at 13:53, David Chelimsky wrote: > On Thu, Mar 27, 2008 at 8:50 AM, David Chelimsky > wrote: >> On Thu, Mar 27, 2008 at 7:08 AM, Bart Zonneveld > > wrote: >>> Hey gang, >>> >>> I'm writing a story in which I update a model via XML. So far, so >>> good. But, I want to test the outcome of the controller, namely the >>> following code: >>> >>> format.xml { head :ok } >>> >>> How can I test this in a story? >> >> Same as in a controller example: >> >> response.should be_success >> response.body.should == "" > > Or - for the latter ... > > response.should be_blank > > Just a matter of preference, but perhaps that's more readable. Thanks. I was hoping for a specific test of the head :ok, but this'll do more than fine :). gr, bartz From ashley.moran at patchspace.co.uk Thu Mar 27 12:27:36 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 27 Mar 2008 16:27:36 +0000 Subject: [rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot In-Reply-To: <57c63afe0803261913y6f4d9953pa1ecdb7c561de778@mail.gmail.com> References: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> <6BF6965A-5B63-499F-8BC8-E636E5CBFCC1@patchspace.co.uk> <57c63afe0803261913y6f4d9953pa1ecdb7c561de778@mail.gmail.com> Message-ID: On 27/03/2008, David Chelimsky wrote: > > Not likely. Not because it isn't awesome. I'll probably be using it > myself. But every good idea for a matcher library doesn't belong in > rspec. In fact, the whole point of creating such a simple protocol for > matchers was to encourage external libraries. > > I think it's fine just as it is. In that case, would a central repository of re-usable matchers be a good idea? (Maybe just a page on rspec.info?) Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080327/503b8bb9/attachment.html From ashley.moran at patchspace.co.uk Thu Mar 27 12:30:27 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 27 Mar 2008 16:30:27 +0000 Subject: [rspec-users] Why does nesting this spec fail? Message-ID: Hi, This fails: describe UsersController::QuickSearch do controller_name "users" describe "created with search text" do before(:each) do @quick_search = UsersController::QuickSearch.new("quick_search[search_text]" => "search_text") end it "should turn search text into a search on the first name, surname, username and secondary email" do @quick_search.to_conditions.should == { :conditions => "..." } end end end with this error: ArgumentError in 'UsersController::QuickSearch created with search text should turn search text into a search on the first name, surname, username and secondary email' wrong number of arguments (0 for 1) script/spec:4: But if I comment out the nested describe # describe "created with search text" do before(:each) do @quick_search = ... # it works fine. Anyone got any ideas? I must be doing something stupid, I've got a nearly identical one immediately below. Thanks Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080327/c75f64bd/attachment.html From ashley.moran at patchspace.co.uk Thu Mar 27 12:35:51 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 27 Mar 2008 16:35:51 +0000 Subject: [rspec-users] Why does nesting this spec fail? In-Reply-To: References: Message-ID: On 27/03/2008, Ashley Moran wrote: > > I must be doing something stupid, I've got a nearly identical one > immediately below. I lied, it was not identical, but when I nest another one where I have to specify the controller it warns me. Adding this to the NESTED describe block fixes it: controller_name "users" Don't know why it gives such a mysterious error instead of "You have to declare the controller name in controller specs." though. Known bug, or in need of a LH ticket? Desirable behaviour would seem to be that inner blocks inherit the controller. Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080327/ff3f537d/attachment-0001.html From coreyhaines at gmail.com Thu Mar 27 12:49:21 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Thu, 27 Mar 2008 12:49:21 -0400 Subject: [rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot In-Reply-To: References: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> <6BF6965A-5B63-499F-8BC8-E636E5CBFCC1@patchspace.co.uk> <57c63afe0803261913y6f4d9953pa1ecdb7c561de778@mail.gmail.com> Message-ID: <6bdacb70803270949l81171c0ycf5b05defed68bc3@mail.gmail.com> +1 On Thu, Mar 27, 2008 at 12:27 PM, Ashley Moran < ashley.moran at patchspace.co.uk> wrote: > On 27/03/2008, David Chelimsky wrote: > > > Not likely. Not because it isn't awesome. I'll probably be using it > > myself. But every good idea for a matcher library doesn't belong in > > rspec. In fact, the whole point of creating such a simple protocol for > > matchers was to encourage external libraries. > > > > I think it's fine just as it is. > > > > In that case, would a central repository of re-usable matchers be a good > idea? (Maybe just a page on rspec.info?) > > > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://www.coreyhaines.com The Internet's Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080327/b7685dfb/attachment.html From pergesu at gmail.com Thu Mar 27 13:16:03 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 27 Mar 2008 10:16:03 -0700 Subject: [rspec-users] Why does nesting this spec fail? In-Reply-To: References: Message-ID: <810a540e0803271016j55cecaabi69712859a755e3e6@mail.gmail.com> On Thu, Mar 27, 2008 at 9:35 AM, Ashley Moran wrote: > > > > On 27/03/2008, Ashley Moran wrote: > > I must be doing something stupid, I've got a nearly identical one > immediately below. > > > I lied, it was not identical, but when I nest another one where I have to > specify the controller it warns me. Adding this to the NESTED describe > block fixes it: > controller_name "users" > > Don't know why it gives such a mysterious error instead of "You have to > declare the controller name in controller specs." though. > > Known bug, or in need of a LH ticket? Desirable behaviour would seem to be > that inner blocks inherit the controller. This is fixed in trunk. Pat From ashley.moran at patchspace.co.uk Thu Mar 27 13:45:23 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 27 Mar 2008 17:45:23 +0000 Subject: [rspec-users] Why does nesting this spec fail? In-Reply-To: <810a540e0803271016j55cecaabi69712859a755e3e6@mail.gmail.com> References: <810a540e0803271016j55cecaabi69712859a755e3e6@mail.gmail.com> Message-ID: On 27/03/2008, Pat Maddox wrote: > > > This is fixed in trunk. Ok cool, as it happens I just updated to trunk to get the nested shared example groups. Ta Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080327/ccb3fd8c/attachment.html From dchelimsky at gmail.com Thu Mar 27 15:24:00 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 27 Mar 2008 15:24:00 -0400 Subject: [rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot In-Reply-To: References: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> <6BF6965A-5B63-499F-8BC8-E636E5CBFCC1@patchspace.co.uk> <57c63afe0803261913y6f4d9953pa1ecdb7c561de778@mail.gmail.com> Message-ID: On Mar 27, 2008, at 12:27 PM, "Ashley Moran" wrote: > On 27/03/2008, David Chelimsky wrote: > Not likely. Not because it isn't awesome. I'll probably be using it > myself. But every good idea for a matcher library doesn't belong in > rspec. In fact, the whole point of creating such a simple protocol for > matchers was to encourage external libraries. > > I think it's fine just as it is. > > > In that case, would a central repository of re-usable matchers be a > good idea? (Maybe just a page on rspec.info?) Definitely. We're going to set up a wiki or some such. I'm interested in a place to list matcher libs, plugins, and projects that are using rspec as well. Soon! Maybe ;) Cheers, David > > > > Ashley > _______________________________________________ > 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/20080327/5d01e561/attachment.html From j at jonathanleighton.com Thu Mar 27 14:18:17 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Thu, 27 Mar 2008 18:18:17 +0000 Subject: [rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot In-Reply-To: <6bdacb70803270949l81171c0ycf5b05defed68bc3@mail.gmail.com> References: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> <6BF6965A-5B63-499F-8BC8-E636E5CBFCC1@patchspace.co.uk> <57c63afe0803261913y6f4d9953pa1ecdb7c561de778@mail.gmail.com> <6bdacb70803270949l81171c0ycf5b05defed68bc3@mail.gmail.com> Message-ID: <1206641897.6806.6.camel@tybalt> +2.74 On Thu, 2008-03-27 at 12:49 -0400, Corey Haines wrote: > +1 > > On Thu, Mar 27, 2008 at 12:27 PM, Ashley Moran > wrote: > On 27/03/2008, David Chelimsky wrote: > Not likely. Not because it isn't awesome. I'll > probably be using it > myself. But every good idea for a matcher library > doesn't belong in > rspec. In fact, the whole point of creating such a > simple protocol for > matchers was to encourage external libraries. > > I think it's fine just as it is. > > > In that case, would a central repository of re-usable matchers > be a good idea? (Maybe just a page on rspec.info?) > > > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > http://www.coreyhaines.com > The Internet's Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- Jonathan Leighton http://jonathanleighton.com/ From dchelimsky at gmail.com Fri Mar 28 11:01:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 28 Mar 2008 11:01:53 -0400 Subject: [rspec-users] help Steven Baker get to Scotland on Rails Message-ID: <57c63afe0803280801x2fc513b0h86199cc58c43b460@mail.gmail.com> Hi all, Warning - this is a request for money to help do something nice for someone. If this offends you in any way, please stop reading now and just delete this email. Steven Baker, the guy who actually wrote RSpec to begin with (just think of a world in which the only BDD frameworks were in C++ and Java), needs help getting to Scotland on Rails next week. I've set up a fundraiser at http://www.fundable.com/groupactions/groupaction.2008-03-28.7509751339. If you feel so inclined, please do kick in a few bucks to help out. Cheers, David ps - if you actually do feel this is completely inappropriate for this list, please let me know. From ashley.moran at patchspace.co.uk Fri Mar 28 12:48:47 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 28 Mar 2008 16:48:47 +0000 Subject: [rspec-users] Wrong story step running Message-ID: Hi I have three steps like this: Given 'a user called "$name" of type $user_type and status $user_state in organisation "$organisation_name"' do |name, user_type, user_state, organisation_name| $runs ||= 1 puts "MOO #{$runs}" $runs += 1 # ... end Given 'a user called "$name" with username "$username" of type $user_type and status $user_state in organisation "$organisation_name"' do |name, username, user_type, user_state, organisation_name| # ... end Given 'a user called "$name" with secondary email "$secondary_email" of type $user_type and status $user_state in organisation "$organisation_name"' do |name, secondary_email, user_type, user_state, organisation_name| # ... end When I run a story containing these step calls: And a user called "Mr Kameron Friesen" of type END_USER and status APPROVED in organisation "My Infant School" And a user called "Mr Adam Kameron" of type END_USER and status APPROVED in organisation "My Infant School" And a user called "Mr Matching Username" with username " kameron_is_cool at technophobia.com" of type END_USER and status APPROVED in organisation "My Infant School" And a user called "Mrs Matching SecondaryEmail" with secondary email " kameron99 at technophobia.com" of type END_USER and status APPROVED in organisation "My Infant School" And a user called "Miss NotMe Kovacek" of type END_USER and status APPROVED in organisation "My Infant School" And a user called "Mr No Match" of type END_USER and status APPROVED in organisation "Kameron's School Should Not Match" It always runs the body of the FIRST step, and not the ones that allow passing a username or email. I know this because of the debugging output I left in the step above. Anyone got an idea why this is happening? I'm gonna have to work around it for now, if I can figure out how. Thanks Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080328/0be2f705/attachment.html From ashley.moran at patchspace.co.uk Fri Mar 28 12:53:00 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 28 Mar 2008 16:53:00 +0000 Subject: [rspec-users] Wrong story step running In-Reply-To: References: Message-ID: Found this: if I change the other steps to And a user called "Mr Matching Username" with username " kameron_is_cool at technophobia.com" of typex END_USER and status APPROVED in organisation "My Infant School" And a user called "Mrs Matching SecondaryEmail" with secondary email " kameron99 at technophobia.com" of typex END_USER and status APPROVED in organisation "My Infant School" then the "typex" makes it work again. Is story runner having trouble matching stories when they are of the following pattern? A + B A + X + B A + Y + B Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080328/ddc584e6/attachment-0001.html From cremes.devlist at mac.com Fri Mar 28 13:38:15 2008 From: cremes.devlist at mac.com (Chuck Remes) Date: Fri, 28 Mar 2008 12:38:15 -0500 Subject: [rspec-users] [Q] bug in mocks or user error? Message-ID: <39271E46-48CF-4885-B47E-430FB933A523@mac.com> I'm trying to use a mock to return a hash so that #each_pair can process it. I can't get it to work. Whatever I return to #each_pair is ignored and the block never gets executed. Here's an example illustrating the problem. require File.join(File.dirname(__FILE__), %w[spec_helper]) class MyExample attr_reader :result def example(data) data.each_pair do |key, value| @result = {key => value} end end end describe MyExample, "mock#each_pair fails" do it "should return a hash after processing the mock using each_pair" do sample_mock = mock("sample") real_hash = {:key => :value} sample_mock.should_receive(:each_pair).once.and_return(real_hash) obj = MyExample.new obj.example(sample_mock) obj.result.should == real_hash end end I tried returning different things in case the hash was the wrong intermediate. I tried: #and_return([:key, :value]) #and_return([[:key, :value]]) #and_return(:key, :value) None worked. Is this a bug or am I misusing mocks? cr From george at benevolentcode.com Fri Mar 28 13:47:41 2008 From: george at benevolentcode.com (George Anderson) Date: Fri, 28 Mar 2008 13:47:41 -0400 Subject: [rspec-users] [Q] bug in mocks or user error? In-Reply-To: <39271E46-48CF-4885-B47E-430FB933A523@mac.com> References: <39271E46-48CF-4885-B47E-430FB933A523@mac.com> Message-ID: <782d66f30803281047t30b45ea8q6dce02cd66d44a11@mail.gmail.com> What's the output (or error?) you're getting? /g On Fri, Mar 28, 2008 at 1:38 PM, Chuck Remes wrote: > I'm trying to use a mock to return a hash so that #each_pair can > process it. I can't get it to work. Whatever I return to #each_pair is > ignored and the block never gets executed. Here's an example > illustrating the problem. > > require File.join(File.dirname(__FILE__), %w[spec_helper]) > > class MyExample > attr_reader :result > > def example(data) > data.each_pair do |key, value| > @result = {key => value} > end > end > end > > describe MyExample, "mock#each_pair fails" do > it "should return a hash after processing the mock using each_pair" > do > sample_mock = mock("sample") > real_hash = {:key => :value} > sample_mock.should_receive(:each_pair).once.and_return(real_hash) > obj = MyExample.new > obj.example(sample_mock) > obj.result.should == real_hash > end > end > > I tried returning different things in case the hash was the wrong > intermediate. I tried: > #and_return([:key, :value]) > #and_return([[:key, :value]]) > #and_return(:key, :value) > > None worked. Is this a bug or am I misusing mocks? > > cr > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- George Anderson BenevolentCode LLC O: (410) 461-7553 C: (410) 218-5185 george at benevolentcode.com From cremes.devlist at mac.com Fri Mar 28 14:16:21 2008 From: cremes.devlist at mac.com (Chuck Remes) Date: Fri, 28 Mar 2008 13:16:21 -0500 Subject: [rspec-users] [Q] bug in mocks or user error? In-Reply-To: <782d66f30803281047t30b45ea8q6dce02cd66d44a11@mail.gmail.com> References: <39271E46-48CF-4885-B47E-430FB933A523@mac.com> <782d66f30803281047t30b45ea8q6dce02cd66d44a11@mail.gmail.com> Message-ID: <39FBE62D-C916-4F82-B831-93B3CEF51D07@mac.com> It ends up comparing nil to real_hash. This happens because the #result accessor never gets initialized due to the block never getting executed. cr On Mar 28, 2008, at 12:47 PM, George Anderson wrote: > What's the output (or error?) you're getting? > > /g > > On Fri, Mar 28, 2008 at 1:38 PM, Chuck Remes > wrote: >> I'm trying to use a mock to return a hash so that #each_pair can >> process it. I can't get it to work. Whatever I return to #each_pair >> is >> ignored and the block never gets executed. Here's an example >> illustrating the problem. >> >> require File.join(File.dirname(__FILE__), %w[spec_helper]) >> >> class MyExample >> attr_reader :result >> >> def example(data) >> data.each_pair do |key, value| >> @result = {key => value} >> end >> end >> end >> >> describe MyExample, "mock#each_pair fails" do >> it "should return a hash after processing the mock using each_pair" >> do >> sample_mock = mock("sample") >> real_hash = {:key => :value} >> sample_mock.should_receive(:each_pair).once.and_return(real_hash) >> obj = MyExample.new >> obj.example(sample_mock) >> obj.result.should == real_hash >> end >> end >> >> I tried returning different things in case the hash was the wrong >> intermediate. I tried: >> #and_return([:key, :value]) >> #and_return([[:key, :value]]) >> #and_return(:key, :value) >> >> None worked. Is this a bug or am I misusing mocks? >> >> cr >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > > George Anderson > > BenevolentCode LLC > O: (410) 461-7553 > C: (410) 218-5185 > > george at benevolentcode.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dbitsolutions at gmail.com Fri Mar 28 14:25:47 2008 From: dbitsolutions at gmail.com (David Beckwith) Date: Fri, 28 Mar 2008 11:25:47 -0700 Subject: [rspec-users] How do you mock an object that you don't have access to? Message-ID: <93ddac20803281125y7111ad48g8dff470c348d96d2@mail.gmail.com> Hi, How can I mock the "go" method of class B so that it returns the string "fudge" in this situation? class A private def start @b = B.new end end class B def go puts "This is fun." end end Also, is it possible to do the mocha-like any_instance thing with RSpec? Thank you, David :) From luislavena at gmail.com Fri Mar 28 14:32:57 2008 From: luislavena at gmail.com (Luis Lavena) Date: Fri, 28 Mar 2008 15:32:57 -0300 Subject: [rspec-users] How do you mock an object that you don't have access to? In-Reply-To: <93ddac20803281125y7111ad48g8dff470c348d96d2@mail.gmail.com> References: <93ddac20803281125y7111ad48g8dff470c348d96d2@mail.gmail.com> Message-ID: <71166b3b0803281132t500b615chcf26e30bc3405d4b@mail.gmail.com> On Fri, Mar 28, 2008 at 3:25 PM, David Beckwith wrote: > Hi, > > How can I mock the "go" method of class B so that it returns the > string "fudge" in this situation? > > class A > private > def start > @b = B.new > end > end > > class B > def go > puts "This is fun." > end > end > What about: mock_b = mock(B) mock_b.stub!(:go).and_return(true) B.stub!(:new).and_return(mock_b) Something like that? -- Luis Lavena Multimedia systems - Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. Douglas Adams From dbitsolutions at gmail.com Fri Mar 28 14:35:22 2008 From: dbitsolutions at gmail.com (David Beckwith) Date: Fri, 28 Mar 2008 11:35:22 -0700 Subject: [rspec-users] What is SpecServer? In-Reply-To: <07767F96-D97F-407A-AF0D-0104218D2E77@railsnewbie.com> References: <57a815bf0803122117t6c16754bqfa3b5eea94598221@mail.gmail.com> <07767F96-D97F-407A-AF0D-0104218D2E77@railsnewbie.com> Message-ID: <93ddac20803281135s1e80637ehf85d65656e52361e@mail.gmail.com> I guess I could just try it, but does spec_server work with autotest too? ie. ruby script/spec_server & autotest ? On Wed, Mar 12, 2008 at 9:36 PM, Scott Taylor wrote: > > On Mar 13, 2008, at 12:17 AM, Mikel Lindsaar wrote: > > > I have looked through the docs, looked at the code, even gave a > > cursory (2 page) glance at google, and it is not clear to me what > > SpecServer is or what it is for. > > > > Is it meant to speed up the execution of specs in a rails environment > > by doing some magic on the database? > > The spec server does no magic. It load the rails environment, and the > runs the specs through Drb (look up the rdoc for Drb/Rinda). > > > > Or I am thinking it keeps a copy of Rails running to avoid the rails > > reload delay... > > Yep - that's pretty much it. It usually takes a few seconds to load > up the rails environment, and if you are running your specs every few > seconds, that can shave off a lot of time from your dev cycle over time. > > > > > > Is there any documentation on this so I can go find out instead of > > bugging the list? :) > > No - not really. All you need to do is start the spec_server: > > ruby script/spec_server > > The specs can then be run through the server with --drb (put it in > spec.opts, if you always want to use it). > > Scott > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- SMS/Text: +63 905 220 2207 Skype: dbit_solutions From dchelimsky at gmail.com Fri Mar 28 14:46:43 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 28 Mar 2008 14:46:43 -0400 Subject: [rspec-users] [Q] bug in mocks or user error? In-Reply-To: <39271E46-48CF-4885-B47E-430FB933A523@mac.com> References: <39271E46-48CF-4885-B47E-430FB933A523@mac.com> Message-ID: <57c63afe0803281146t42bd995k322456c89ae4987b@mail.gmail.com> On Fri, Mar 28, 2008 at 1:38 PM, Chuck Remes wrote: > I'm trying to use a mock to return a hash so that #each_pair can > process it. I can't get it to work. Whatever I return to #each_pair is > ignored and the block never gets executed. Here's an example > illustrating the problem. > > require File.join(File.dirname(__FILE__), %w[spec_helper]) > > class MyExample > attr_reader :result > > def example(data) > data.each_pair do |key, value| > @result = {key => value} > end > end > end > > describe MyExample, "mock#each_pair fails" do > it "should return a hash after processing the mock using each_pair" > do > sample_mock = mock("sample") > real_hash = {:key => :value} > sample_mock.should_receive(:each_pair).once.and_return(real_hash) > obj = MyExample.new > obj.example(sample_mock) > obj.result.should == real_hash > end > end each_pair does not return the hash, it yields it to a block. Try this: sample_mock.should_receive(:each_pair).once.and_yield(real_hash) > > I tried returning different things in case the hash was the wrong > intermediate. I tried: > #and_return([:key, :value]) > #and_return([[:key, :value]]) > #and_return(:key, :value) > > None worked. Is this a bug or am I misusing mocks? > > cr > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cremes.devlist at mac.com Fri Mar 28 15:01:47 2008 From: cremes.devlist at mac.com (Chuck Remes) Date: Fri, 28 Mar 2008 14:01:47 -0500 Subject: [rspec-users] [Q] bug in mocks or user error? In-Reply-To: <57c63afe0803281146t42bd995k322456c89ae4987b@mail.gmail.com> References: <39271E46-48CF-4885-B47E-430FB933A523@mac.com> <57c63afe0803281146t42bd995k322456c89ae4987b@mail.gmail.com> Message-ID: On Mar 28, 2008, at 1:46 PM, David Chelimsky wrote: > On Fri, Mar 28, 2008 at 1:38 PM, Chuck Remes > wrote: >> I'm trying to use a mock to return a hash so that #each_pair can >> process it. I can't get it to work. Whatever I return to #each_pair >> is >> ignored and the block never gets executed. Here's an example >> illustrating the problem. >> >> require File.join(File.dirname(__FILE__), %w[spec_helper]) >> >> class MyExample >> attr_reader :result >> >> def example(data) >> data.each_pair do |key, value| >> @result = {key => value} >> end >> end >> end >> >> describe MyExample, "mock#each_pair fails" do >> it "should return a hash after processing the mock using each_pair" >> do >> sample_mock = mock("sample") >> real_hash = {:key => :value} >> sample_mock.should_receive(:each_pair).once.and_return(real_hash) >> obj = MyExample.new >> obj.example(sample_mock) >> obj.result.should == real_hash >> end >> end > > each_pair does not return the hash, it yields it to a block. Try this: > > sample_mock.should_receive(:each_pair).once.and_yield(real_hash) Dave, thanks for the hint. That almost worked but I got this error: Spec::Mocks::MockExpectationError in 'MyExample mock#each_pair fails should return a hash after processing the mock using each_pair' Mock 'sample' yielded |{:key=>:value}| to block with arity of 2 Changing it slightly allowed it to work correctly: describe MyExample, "mock#each_pair fails" do it "should return a hash after processing the mock using each_pair" do sample_mock = mock("sample") real_hash = {:key => :value} sample_mock .should_receive(:each_pair).once.and_yield(real_hash.keys.first, real_hash.values.first) obj = MyExample.new obj.example(sample_mock) obj.result.should == real_hash end end Thanks for your help. SrBaker has been enriched as a result. :-) cr From pergesu at gmail.com Fri Mar 28 15:12:44 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 28 Mar 2008 12:12:44 -0700 Subject: [rspec-users] How do you mock an object that you don't have access to? In-Reply-To: <71166b3b0803281132t500b615chcf26e30bc3405d4b@mail.gmail.com> References: <93ddac20803281125y7111ad48g8dff470c348d96d2@mail.gmail.com> <71166b3b0803281132t500b615chcf26e30bc3405d4b@mail.gmail.com> Message-ID: <810a540e0803281212m3d20fbd6u6352e30fd8701b6c@mail.gmail.com> On Fri, Mar 28, 2008 at 11:32 AM, Luis Lavena wrote: > On Fri, Mar 28, 2008 at 3:25 PM, David Beckwith wrote: > > Hi, > > > > How can I mock the "go" method of class B so that it returns the > > string "fudge" in this situation? > > > > class A > > private > > def start > > @b = B.new > > end > > end > > > > class B > > def go > > puts "This is fun." > > end > > end > > > > What about: > > mock_b = mock(B) > mock_b.stub!(:go).and_return(true) > > B.stub!(:new).and_return(mock_b) > > Something like that? Stubbing the #new method on the class is one way to do it, as Luis mentioned. Another approach is to pass the object in through the constructor. Doing so will help you achieve looser coupling between the classes. Pat From aslak.hellesoy at gmail.com Fri Mar 28 15:17:56 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 28 Mar 2008 20:17:56 +0100 Subject: [rspec-users] How do you mock an object that you don't have access to? In-Reply-To: <810a540e0803281212m3d20fbd6u6352e30fd8701b6c@mail.gmail.com> References: <93ddac20803281125y7111ad48g8dff470c348d96d2@mail.gmail.com> <71166b3b0803281132t500b615chcf26e30bc3405d4b@mail.gmail.com> <810a540e0803281212m3d20fbd6u6352e30fd8701b6c@mail.gmail.com> Message-ID: <8d961d900803281217yc24aa4cx34a7c590f3756996@mail.gmail.com> On Fri, Mar 28, 2008 at 8:12 PM, Pat Maddox wrote: > On Fri, Mar 28, 2008 at 11:32 AM, Luis Lavena wrote: > > On Fri, Mar 28, 2008 at 3:25 PM, David Beckwith wrote: > > > Hi, > > > > > > How can I mock the "go" method of class B so that it returns the > > > string "fudge" in this situation? > > > > > > class A > > > private > > > def start > > > @b = B.new > > > end > > > end > > > > > > class B > > > def go > > > puts "This is fun." > > > end > > > end > > > > > > > What about: > > > > mock_b = mock(B) > > mock_b.stub!(:go).and_return(true) > > > > B.stub!(:new).and_return(mock_b) > > > > Something like that? > > Stubbing the #new method on the class is one way to do it, as Luis mentioned. > > Another approach is to pass the object in through the constructor. > Doing so will help you achieve looser coupling between the classes. > AKA Dependency Injection (http://martinfowler.com/articles/injection.html) Aslak > Pat > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Fri Mar 28 15:33:56 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 28 Mar 2008 14:33:56 -0500 Subject: [rspec-users] How do you mock an object that you don't have access to? In-Reply-To: <8d961d900803281217yc24aa4cx34a7c590f3756996@mail.gmail.com> References: <93ddac20803281125y7111ad48g8dff470c348d96d2@mail.gmail.com> <71166b3b0803281132t500b615chcf26e30bc3405d4b@mail.gmail.com> <810a540e0803281212m3d20fbd6u6352e30fd8701b6c@mail.gmail.com> <8d961d900803281217yc24aa4cx34a7c590f3756996@mail.gmail.com> Message-ID: <85d99afe0803281233k2575fi1b8b2f64f774d7ba@mail.gmail.com> http://atomicobjectrb.rubyforge.org/injection/ Zach On Fri, Mar 28, 2008 at 2:17 PM, aslak hellesoy wrote: > > On Fri, Mar 28, 2008 at 8:12 PM, Pat Maddox wrote: > > On Fri, Mar 28, 2008 at 11:32 AM, Luis Lavena wrote: > > > On Fri, Mar 28, 2008 at 3:25 PM, David Beckwith wrote: > > > > Hi, > > > > > > > > How can I mock the "go" method of class B so that it returns the > > > > string "fudge" in this situation? > > > > > > > > class A > > > > private > > > > def start > > > > @b = B.new > > > > end > > > > end > > > > > > > > class B > > > > def go > > > > puts "This is fun." > > > > end > > > > end > > > > > > > > > > What about: > > > > > > mock_b = mock(B) > > > mock_b.stub!(:go).and_return(true) > > > > > > B.stub!(:new).and_return(mock_b) > > > > > > Something like that? > > > > Stubbing the #new method on the class is one way to do it, as Luis mentioned. > > > > Another approach is to pass the object in through the constructor. > > Doing so will help you achieve looser coupling between the classes. > > > > AKA Dependency Injection (http://martinfowler.com/articles/injection.html) > > Aslak > > > > > Pat > > > > > > _______________________________________________ > > 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 > -- Zach Dennis http://www.continuousthinking.com From joe at pinkpucker.net Fri Mar 28 16:03:26 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Fri, 28 Mar 2008 13:03:26 -0700 Subject: [rspec-users] getting autotest to monitor changes in lib directory Message-ID: Autotest monitors changes in app/models. How can I get autotest to monitor changes in lib? So that whenever something changes in lib or specs/lib, it runs the appropriate spec? Joe From dbitsolutions at gmail.com Fri Mar 28 23:44:03 2008 From: dbitsolutions at gmail.com (David Beckwith) Date: Fri, 28 Mar 2008 20:44:03 -0700 Subject: [rspec-users] How do you mock an object that you don't have access to? In-Reply-To: <71166b3b0803281132t500b615chcf26e30bc3405d4b@mail.gmail.com> References: <93ddac20803281125y7111ad48g8dff470c348d96d2@mail.gmail.com> <71166b3b0803281132t500b615chcf26e30bc3405d4b@mail.gmail.com> Message-ID: <93ddac20803282044o27b9496anba6f03fb98aea703@mail.gmail.com> Awesome. Thank you. David :) On Fri, Mar 28, 2008 at 11:32 AM, Luis Lavena wrote: > On Fri, Mar 28, 2008 at 3:25 PM, David Beckwith wrote: > > Hi, > > > > How can I mock the "go" method of class B so that it returns the > > string "fudge" in this situation? > > > > class A > > private > > def start > > @b = B.new > > end > > end > > > > class B > > def go > > puts "This is fun." > > end > > end > > > > What about: > > mock_b = mock(B) > mock_b.stub!(:go).and_return(true) > > B.stub!(:new).and_return(mock_b) > > Something like that? > > -- > Luis Lavena > Multimedia systems > - > Human beings, who are almost unique in having the ability to learn from > the experience of others, are also remarkable for their apparent > disinclination to do so. > Douglas Adams > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- SMS/Text: +63 905 220 2207 Skype: dbit_solutions From mailing_lists at railsnewbie.com Fri Mar 28 23:22:25 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 28 Mar 2008 23:22:25 -0400 Subject: [rspec-users] help Steven Baker get to Scotland on Rails In-Reply-To: <57c63afe0803280801x2fc513b0h86199cc58c43b460@mail.gmail.com> References: <57c63afe0803280801x2fc513b0h86199cc58c43b460@mail.gmail.com> Message-ID: <4254D1AB-CC15-4F8C-9D2A-E154898B0AE2@railsnewbie.com> On Mar 28, 2008, at 11:01 AM, David Chelimsky wrote: > Hi all, > > Warning - this is a request for money to help do something nice for > someone. If this offends you in any way, please stop reading now and > just delete this email. > > Steven Baker, the guy who actually wrote RSpec to begin with (just > think of a world in which the only BDD frameworks were in C++ and > Java), needs help getting to Scotland on Rails next week. I've set up > a fundraiser at > http://www.fundable.com/groupactions/groupaction. > 2008-03-28.7509751339. > > If you feel so inclined, please do kick in a few bucks to help out. > > Cheers, > David > > ps - if you actually do feel this is completely inappropriate for this > list, please let me know. I don't - but out of curiosity, why does he need the money? Scott From mailing_lists at railsnewbie.com Sat Mar 29 00:17:58 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 29 Mar 2008 00:17:58 -0400 Subject: [rspec-users] What is SpecServer? In-Reply-To: <93ddac20803281135s1e80637ehf85d65656e52361e@mail.gmail.com> References: <57a815bf0803122117t6c16754bqfa3b5eea94598221@mail.gmail.com> <07767F96-D97F-407A-AF0D-0104218D2E77@railsnewbie.com> <93ddac20803281135s1e80637ehf85d65656e52361e@mail.gmail.com> Message-ID: <91DA343E-35E6-4A59-8625-622BDDA9F3B4@railsnewbie.com> On Mar 28, 2008, at 2:35 PM, David Beckwith wrote: > I guess I could just try it, but does spec_server work with > autotest too? > > ie. > ruby script/spec_server & > autotest > Sure. Autotest is a pretty stupid program (and I mean that in a good way). All it does is periodically run a spec command in a subshell. Scott > ? > > > On Wed, Mar 12, 2008 at 9:36 PM, Scott Taylor > wrote: >> >> On Mar 13, 2008, at 12:17 AM, Mikel Lindsaar wrote: >> >>> I have looked through the docs, looked at the code, even gave a >>> cursory (2 page) glance at google, and it is not clear to me what >>> SpecServer is or what it is for. >>> >>> Is it meant to speed up the execution of specs in a rails >>> environment >>> by doing some magic on the database? >> >> The spec server does no magic. It load the rails environment, and the >> runs the specs through Drb (look up the rdoc for Drb/Rinda). >> >> >>> Or I am thinking it keeps a copy of Rails running to avoid the rails >>> reload delay... >> >> Yep - that's pretty much it. It usually takes a few seconds to load >> up the rails environment, and if you are running your specs every few >> seconds, that can shave off a lot of time from your dev cycle over >> time. >> >> >>> >>> Is there any documentation on this so I can go find out instead of >>> bugging the list? :) >> >> No - not really. All you need to do is start the spec_server: >> >> ruby script/spec_server >> >> The specs can then be run through the server with --drb (put it in >> spec.opts, if you always want to use it). >> >> Scott >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > SMS/Text: +63 905 220 2207 > Skype: dbit_solutions > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sat Mar 29 08:18:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 29 Mar 2008 07:18:53 -0500 Subject: [rspec-users] getting autotest to monitor changes in lib directory In-Reply-To: References: Message-ID: <57c63afe0803290518y55b6358cwea593bbf66c958cd@mail.gmail.com> On Fri, Mar 28, 2008 at 3:03 PM, Joe Van Dyk wrote: > Autotest monitors changes in app/models. How can I get autotest to > monitor changes in lib? So that whenever something changes in lib or > specs/lib, it runs the appropriate spec? This might help you: http://tinyurl.com/25xdey > > Joe > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nick.curry+rspec-users at gmail.com Sat Mar 29 14:36:02 2008 From: nick.curry+rspec-users at gmail.com (Nick C) Date: Sat, 29 Mar 2008 18:36:02 +0000 Subject: [rspec-users] parameterized shared specs: good or bad idea? Message-ID: Hi, I've come across a couple of cases recently in which I was wishing it was possible to parameterize shared specs. An example: I have defined a number of rails resources, and it seems wasteful to have tens of generated 'xxx_controller_spec' 'xxx_controller_routing' specs that check the same mechanisms, but with different parameters (in this case, the parameters would be the controller class name, and the path the route should map to for instance). It doesn't seem DRY, and it adds a cognitive overhead of dealing with a large number of very similar files in a project that essentially do the same thing. Ideally, I'd have wanted to do something like this: it_should_behave_like 'a standard rails routed resource', :controller => UserController, :path => 'users' I realise that the intention of the generated specs is to be evolved as the underlying controllers do; however, for the routing or some actions such as 'destroy', it's unlikely there will be much variation across controllers implementing the functionality, and it seems a shame to have dozens of generated specs that look copy-and-pasted. Any thoughts? Thanks, Nick From nick.curry+rspec-users at gmail.com Sat Mar 29 16:03:10 2008 From: nick.curry+rspec-users at gmail.com (Nick C) Date: Sat, 29 Mar 2008 20:03:10 +0000 Subject: [rspec-users] parameterized shared specs: good or bad idea? In-Reply-To: References: Message-ID: Hmm, after investigating a little more, this doesn't sound feasible. Instance variables are already shared between shared specs and their callers, but I was thinking of the spec names themselves also being parameterised, so that the following would be possible: it "should map { :controller => '', :action => 'new' } to /admin//new" do ... end This would mean one of two things: class variables for and , which wouldn't work as these would be redefined by successive specs as they get loaded; or some sort of templating or preprocessing, which doesn't sound like a good idea at all. Ah well - Cheers, Nick On Sat, Mar 29, 2008 at 6:36 PM, Nick C wrote: > Hi, > > I've come across a couple of cases recently in which I was wishing it > was possible to parameterize shared specs. An example: I have defined > a number of rails resources, and it seems wasteful to have tens of > generated 'xxx_controller_spec' 'xxx_controller_routing' specs that > check the same mechanisms, but with different parameters (in this > case, the parameters would be the controller class name, and the path > the route should map to for instance). It doesn't seem DRY, and it > adds a cognitive overhead of dealing with a large number of very > similar files in a project that essentially do the same thing. > > Ideally, I'd have wanted to do something like this: > it_should_behave_like 'a standard rails routed resource', :controller > => UserController, :path => 'users' > > I realise that the intention of the generated specs is to be evolved > as the underlying controllers do; however, for the routing or some > actions such as 'destroy', it's unlikely there will be much variation > across controllers implementing the functionality, and it seems a > shame to have dozens of generated specs that look copy-and-pasted. > > Any thoughts? > > Thanks, > Nick > From dchelimsky at gmail.com Sat Mar 29 17:41:02 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 29 Mar 2008 16:41:02 -0500 Subject: [rspec-users] parameterized shared specs: good or bad idea? In-Reply-To: References: Message-ID: <57c63afe0803291441q354cf1a4l48b2b431af918682@mail.gmail.com> On Sat, Mar 29, 2008 at 3:03 PM, Nick C wrote: > Hmm, after investigating a little more, this doesn't sound feasible. > Instance variables are already shared between shared specs and their > callers, but I was thinking of the spec names themselves also being > parameterised, so that the following would be possible: > > it "should map { :controller => '', :action => 'new' } to > /admin//new" do > ... > end > > This would mean one of two things: class variables for and > , which wouldn't work as these would be redefined by > successive specs as they get loaded; or some sort of templating or > preprocessing, which doesn't sound like a good idea at all. There is a strategy you can use for this. Define method in a helper and use the included hook to extend the example group. To see a working example of this, which actually may solve the exact problem you're trying to solve already, check out http://github.com/technoweenie/rspec_on_rails_on_crack. Cheers, David > > Ah well - > > Cheers, > Nick > > > > On Sat, Mar 29, 2008 at 6:36 PM, Nick C > wrote: > > Hi, > > > > I've come across a couple of cases recently in which I was wishing it > > was possible to parameterize shared specs. An example: I have defined > > a number of rails resources, and it seems wasteful to have tens of > > generated 'xxx_controller_spec' 'xxx_controller_routing' specs that > > check the same mechanisms, but with different parameters (in this > > case, the parameters would be the controller class name, and the path > > the route should map to for instance). It doesn't seem DRY, and it > > adds a cognitive overhead of dealing with a large number of very > > similar files in a project that essentially do the same thing. > > > > Ideally, I'd have wanted to do something like this: > > it_should_behave_like 'a standard rails routed resource', :controller > > => UserController, :path => 'users' > > > > I realise that the intention of the generated specs is to be evolved > > as the underlying controllers do; however, for the routing or some > > actions such as 'destroy', it's unlikely there will be much variation > > across controllers implementing the functionality, and it seems a > > shame to have dozens of generated specs that look copy-and-pasted. > > > > Any thoughts? > > > > Thanks, > > Nick > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dbitsolutions at gmail.com Sat Mar 29 22:23:01 2008 From: dbitsolutions at gmail.com (David Beckwith) Date: Sat, 29 Mar 2008 19:23:01 -0700 (PDT) Subject: [rspec-users] My argument constraints are not working. Message-ID: describe "pretending to crawl craigslist." do before do @html_start = File.read( RAILS_ROOT + "/spec/fixtures/feeds/ start_page.html" ) @response_start = mock_model( Net::HTTP, :body => @html_start, :nil? => false ) @hawlee_start = Hawlee.new(@uri_start, nil, 0) @htgrep = Hawler.new end it "my get method get_it should be called at least once and return a fake response." do @htgrep.hawler.should_receive(:get_it).with(anything(), @hawlee_start).and_return(@response_start) end Here is the Error I'm getting (reformatted for easier reading): Spec::Mocks::MockExpectationError in 'Htgrep Define a blacklist function that inputs a url and returns true or false. If true, the page is on the blacklist and shouldn't be crawled: Hawler's get_it method should be called with okay.html at least once.' Mock 'Hawler' expected :get_it with (#, #, @harvest=false, @depth=0, @get=false, @head=false>) but received it with (#, #, @harvest=false, @depth=0, @get=false, @head=false>) ----------------- I think argument constraints use "==" to see if the argument expectation works. Is that right? So, I made a method called "==" for Hawlee which just compares the enclosed URI object. And I tested to make sure this == operator works as expected. Anyway, my argument constraint is not matching but I'm pretty sure it's being called correctly. Does anybody have an idea of what is going wrong here? Thank you for your suggestions, David :) From dbitsolutions at gmail.com Sat Mar 29 23:11:25 2008 From: dbitsolutions at gmail.com (David Beckwith) Date: Sat, 29 Mar 2008 20:11:25 -0700 (PDT) Subject: [rspec-users] What is SpecServer? In-Reply-To: <91DA343E-35E6-4A59-8625-622BDDA9F3B4@railsnewbie.com> References: <57a815bf0803122117t6c16754bqfa3b5eea94598221@mail.gmail.com> <07767F96-D97F-407A-AF0D-0104218D2E77@railsnewbie.com> <93ddac20803281135s1e80637ehf85d65656e52361e@mail.gmail.com> <91DA343E-35E6-4A59-8625-622BDDA9F3B4@railsnewbie.com> Message-ID: <69bfcbdf-b948-4084-86a3-73485ed61b93@s13g2000prd.googlegroups.com> Just to help clarify for the newbies like me. script/spec_server runs in conjunction with script/spec but not ruby your_spec.rb. It seems like the way to use script/spec_server is to have 2 console programs open: ruby script/spec_server That will have the spec_server running in the background and your entire application loaded into memory at the time of execution, and since it's on top of once console it will be easy to kill and restart when you need to. If you make changes to your application that are loaded up only in the beginning (like installing a new plugin), then you'll have to restart spec_server. (Q: What about the following cases: make a database schema change, add another user-defined model, add another controller, edit an existing controller, edit an existing model make changes to your routes.rb file, edit a plugin. For which of those cases do you have to restart spec_server and which cases don't you? ) And in another console run the spec you're working on: ruby script/spec spec/models/your_spec.rb --drb -c I've noticed that autotest doesn't send commands to the spec_server. Instead it reloads the entire Rails environment and your application's plugins everytime it executes. This causes autotest to run significantly slower than script server, because when you run the script/spec command the specs are sent to the spec_server which already has your Rails environment fired up and ready to go. If you happen to install a new plugin or something like that, then you'll have to restart the spec_server. Feel free to correct me, if I'm wrong. I'm just trying to shed some light for new users, hopefully without saying anything that's not right. I'm just learning all this stuff. David :) On Mar 28, 9:17 pm, Scott Taylor wrote: > On Mar 28, 2008, at 2:35 PM, David Beckwith wrote: > > > I guess I could just try it, but does spec_server work with > > autotest too? > > > ie. > > ruby script/spec_server & > > autotest > > Sure. > > Autotest is a pretty stupid program (and I mean that in a good way). > All it does is periodically run a spec command in a subshell. > > Scott > > > > > ? > > > On Wed, Mar 12, 2008 at 9:36 PM, Scott Taylor > > wrote: > > >> On Mar 13, 2008, at 12:17 AM, Mikel Lindsaar wrote: > > >>> I have looked through the docs, looked at the code, even gave a > >>> cursory (2 page) glance at google, and it is not clear to me what > >>> SpecServer is or what it is for. > > >>> Is it meant to speed up the execution of specs in a rails > >>> environment > >>> by doing some magic on the database? > > >> The spec server does no magic. It load the rails environment, and the > >> runs the specs through Drb (look up the rdoc for Drb/Rinda). > > >>> Or I am thinking it keeps a copy of Rails running to avoid the rails > >>> reload delay... > > >> Yep - that's pretty much it. It usually takes a few seconds to load > >> up the rails environment, and if you are running your specs every few > >> seconds, that can shave off a lot of time from your dev cycle over > >> time. > > >>> Is there any documentation on this so I can go find out instead of > >>> bugging the list? :) > > >> No - not really. All you need to do is start the spec_server: > > >> ruby script/spec_server > > >> The specs can then be run through the server with --drb (put it in > >> spec.opts, if you always want to use it). > > >> Scott > > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.org > >>http://rubyforge.org/mailman/listinfo/rspec-users > > > -- > > SMS/Text: +63 905 220 2207 > > Skype: dbit_solutions > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sun Mar 30 00:39:48 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 29 Mar 2008 23:39:48 -0500 Subject: [rspec-users] My argument constraints are not working. In-Reply-To: References: Message-ID: <57c63afe0803292139y7d3cbae8p70d3eb48e7038802@mail.gmail.com> On Sat, Mar 29, 2008 at 9:23 PM, David Beckwith wrote: > describe "pretending to crawl craigslist." do > > before do > @html_start = File.read( RAILS_ROOT + "/spec/fixtures/feeds/ > start_page.html" ) > @response_start = mock_model( Net::HTTP, :body => > @html_start, :nil? => false ) > @hawlee_start = Hawlee.new(@uri_start, nil, 0) > @htgrep = Hawler.new > end > > it "my get method get_it should be called at least once and return a > fake response." do > @htgrep.hawler.should_receive(:get_it).with(anything(), > @hawlee_start).and_return(@response_start) > end > > Here is the Error I'm getting (reformatted for easier reading): > > Spec::Mocks::MockExpectationError in 'Htgrep Define a blacklist > function that inputs a url and returns true or false. If true, the > page is on the blacklist and shouldn't be crawled: Hawler's get_it > method should be called with okay.html at least once.' > > Mock 'Hawler' expected :get_it with > > (#, > > # 0x1784640 URL:http://sfbay.craigslist.org/start_page.html>, > @harvest=false, @depth=0, @get=false, @head=false>) > > but received it with > > (# start_page.html>, > > # 0x177ad66 URL:http://sfbay.craigslist.org/start_page.html>, > @harvest=false, @depth=0, @get=false, @head=false>) > > ----------------- > > I think argument constraints use "==" to see if the argument > expectation works. Is that right? So, I made a method called "==" > for Hawlee which just compares the enclosed URI object. And I tested > to make sure this == operator works as expected. Can you please post that test? > > Anyway, my argument constraint is not matching but I'm pretty sure > it's being called correctly. Does anybody have an idea of what is > going wrong here? > > Thank you for your suggestions, > David :) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Sun Mar 30 02:40:08 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 30 Mar 2008 02:40:08 -0400 Subject: [rspec-users] What is SpecServer? In-Reply-To: <69bfcbdf-b948-4084-86a3-73485ed61b93@s13g2000prd.googlegroups.com> References: <57a815bf0803122117t6c16754bqfa3b5eea94598221@mail.gmail.com> <07767F96-D97F-407A-AF0D-0104218D2E77@railsnewbie.com> <93ddac20803281135s1e80637ehf85d65656e52361e@mail.gmail.com> <91DA343E-35E6-4A59-8625-622BDDA9F3B4@railsnewbie.com> <69bfcbdf-b948-4084-86a3-73485ed61b93@s13g2000prd.googlegroups.com> Message-ID: <86FFC826-DCCC-4157-947A-376DF61E581A@railsnewbie.com> On Mar 29, 2008, at 11:11 PM, David Beckwith wrote: > Just to help clarify for the newbies like me. script/spec_server runs > in conjunction with script/spec but not ruby your_spec.rb. It seems > like the way to use script/spec_server is to have 2 console programs > open: > > ruby script/spec_server > > That will have the spec_server running in the background and your > entire application loaded into memory at the time of execution, and > since it's on top of once console it will be easy to kill and restart > when you need to. If you make changes to your application that are > loaded up only in the beginning (like installing a new plugin), then > you'll have to restart spec_server. (Q: What about the following > cases: > make a database schema change, > add another user-defined model, > add another controller, > edit an existing controller, > edit an existing model > make changes to your routes.rb file, > edit a plugin. > For which of those cases do you have to restart spec_server and which > cases don't you? ) > > And in another console run the spec you're working on: > > ruby script/spec spec/models/your_spec.rb --drb -c > > I've noticed that autotest doesn't send commands to the spec_server. > Instead it reloads the entire Rails environment and your application's > plugins everytime it executes. This causes autotest to run > significantly slower than script server, because when you run the > script/spec command the specs are sent to the spec_server which > already has your Rails environment fired up and ready to go. If you > happen to install a new plugin or something like that, then you'll > have to restart the spec_server. No - It should work - Remember: Autotest is DUMB. Dumb, dumb, dumb. It's a great tool, but it was written before rspec. It has nothing to do with rspec. All it does is watch a series of files, and reruns a certain command when one of those files changes. So - Autotest has no knowledge of the internals of Rspec. The BUG was that if you put the --drb (or the equivalent -X) flag in your spec.opts file, Rspec would not run them with the drb server. This bug has been fixed in trunk (as far as I know). Scott From mailing_lists at railsnewbie.com Sun Mar 30 02:56:06 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 30 Mar 2008 02:56:06 -0400 Subject: [rspec-users] What is SpecServer? In-Reply-To: <69bfcbdf-b948-4084-86a3-73485ed61b93@s13g2000prd.googlegroups.com> References: <57a815bf0803122117t6c16754bqfa3b5eea94598221@mail.gmail.com> <07767F96-D97F-407A-AF0D-0104218D2E77@railsnewbie.com> <93ddac20803281135s1e80637ehf85d65656e52361e@mail.gmail.com> <91DA343E-35E6-4A59-8625-622BDDA9F3B4@railsnewbie.com> <69bfcbdf-b948-4084-86a3-73485ed61b93@s13g2000prd.googlegroups.com> Message-ID: <3F0EDE9F-9BE8-44FD-BF4C-9EC11AA7F15B@railsnewbie.com> On Mar 29, 2008, at 11:11 PM, David Beckwith wrote: > Just to help clarify for the newbies like me. script/spec_server runs > in conjunction with script/spec but not ruby your_spec.rb. It seems > like the way to use script/spec_server is to have 2 console programs > open: > > ruby script/spec_server > > That will have the spec_server running in the background and your > entire application loaded into memory at the time of execution, and > since it's on top of once console it will be easy to kill and restart > when you need to. If you make changes to your application that are > loaded up only in the beginning (like installing a new plugin), then > you'll have to restart spec_server. (Q: What about the following > cases: > make a database schema change, > add another user-defined model, > add another controller, > edit an existing controller, > edit an existing model > make changes to your routes.rb file, > edit a plugin. > For which of those cases do you have to restart spec_server and which > cases don't you? ) I'm replying in chunks here, but: AFAIK, anything which is required will need to be reloaded (if it changes). Also - any change to rails itself. Schema changes will require you to reload the server. Not sure about a new model, but, if you say, added a new column to a table, you would most certainly need to reload the spec_server (as rails actually caches ActiveRecord::Base.columns, much to my chagrin the other day in a migration). Anything which is loaded with Kernel#load (or load_once, or whatever rails does) shouldn't cause you to reload the spec server. So - this means changes to the code of a model or a controller should be safe, since they are load'ed, not required (as require does nothing but return false the second time it is called). I'm not sure about the routes or the plugin scenario. I would assume for the plugin that it depends on how the code is internally loaded up. If it is require'd instead of load'ed, I'd bet that you need to change the spec_server. Also - just a tip for those who might be using (or thinking of using) the spec_server: I've noticed that shared example groups aren't being reloaded properly. This is a bug in rspec which I've yet to file a ticket for, mainly out of lack of time. Next time I run across it, I'll report it. Scott From dbitsolutions at gmail.com Sun Mar 30 14:13:04 2008 From: dbitsolutions at gmail.com (David Beckwith) Date: Sun, 30 Mar 2008 11:13:04 -0700 Subject: [rspec-users] My argument constraints are not working. In-Reply-To: <57c63afe0803292139y7d3cbae8p70d3eb48e7038802@mail.gmail.com> References: <57c63afe0803292139y7d3cbae8p70d3eb48e7038802@mail.gmail.com> Message-ID: <93ddac20803301113i241c8d3exc0827d54fcbf6534@mail.gmail.com> Here is the test. I'm kind of a newbie at writing tests, so it could just be a newbie mistake. (FYI, "bawal" means "prohibited" in Tagalog c.f. bawal.html below): describe "Define a blacklist function that inputs a url and returns true or false. If true, the page is on the blacklist and shouldn't be crawled: " do before do # Create the fake webpages @html_start = File.read( RAILS_ROOT + "/spec/fixtures/feeds/start_page.html" ) @html_okay = File.read( RAILS_ROOT + "/spec/fixtures/feeds/okay.html" ) @html_bawal = File.read( RAILS_ROOT + "/spec/fixtures/feeds/bawal.html" ) # Create the fake HTTP response objects for each webpage. @response_start = mock_model( Net::HTTP, :body => @html_start, :nil? => false ) @response_okay = mock_model( Net::HTTP, :body => @html_okay, :nil? => false ) @response_bawal = mock_model( Net::HTTP, :body => @html_bawal, :nil? => false ) # Create fake URL strings as names of the webpages. @url_start = "http://sfbay.craigslist.org/start_page.html" @url_okay = "http://sfbay.craigslist.org/okay.html" @url_bawal = "http://sfbay.craigslist.org/bawal.html" # Create the Ruby URI versions of the string URLs @uri_start = URI.parse(@url_start) @uri_okay = URI.parse(@url_okay) @uri_bawal = URI.parse(@url_bawal) # Create fake Hawlee instances for each page. @hawlee_start = Hawlee.new(@uri_start, nil, 0) @hawlee_okay = Hawlee.new(@uri_okay, nil, 0) @hawlee_bawal = Hawlee.new(@uri_bawal, nil, 0) # @hawlee_start = mock_model( Hawlee, :uri => @uri_start, :referer => nil) # @hawlee_okay = mock_model( Hawlee, :uri => @uri_okay, :referer => @hawlee_start) # @hawlee_bawal = mock_model( Hawlee, :uri => @uri_bawal, :referer => @hawlee_start) # Create the fake Htgrep instance @htgrep = Htgrep.new(@url_start.to_s) # Create the Hawler instance that will be used by @htgrep @hawler = Hawler.new(@url_start, @htgrep.method(:process_page), @htgrep.method(:blacklist?)) @hawler.stub!(:uri).and_return(@url_start) # @hawler.stub!(:get_it).and_return(@response_start) @hawler.stub!(:get_it).with(anything(), @hawlee_start).and_return(@response_start) @hawler.stub!(:get_it).with(anything(), @hawlee_okay).and_return(@response_okay) @hawler.stub!(:get_it).with(anything(), @hawlee_bawal).and_return(@response_bawal) # Assign the partial Hawler mock to be contained by the Htgrep instance @htgrep.hawler = @hawler # Make sure that they pages are always considered to be onsite. HawlerHelper.stub!(:offsite?).and_return(false) # Make Hawler.new return the hawler stub that we created. # If we don't do this, a new Hawler will be created in Htgrep#start for every site in site_list. Hawler.stub!(:new).and_return(@hawler) # Skip peeking at it with HEAD. @hawler.stub!(:peek_at_it).and_return(true) # Make sure that the HARVEST step is not skipped. Net::HTTPSuccess.stub!("===".to_sym).and_return(true) end it "Hawler's get_it method should be called with okay.html at least once." do @htgrep.hawler.should_receive(:get_it).with(anything(), @hawlee_start).and_return(@response_start) @htgrep.start end end Spec::Mocks::MockExpectationError in 'Htgrep Define a blacklist function that inputs a url and returns true or false. If true, the page is on the blacklist and shouldn't be crawled: Hawler's get_it method should be called with okay.html at least once.' Mock 'Hawler' expected :get_it with (#, #, @get=false, @analyze=false, @head=false, @referer=nil>) but received it with (#, #, @get=false, @analyze=false, @head=false, @referer=nil>) /Users/dbit/Sites/scraper/vendor/plugins/hawler/lib/hawler.rb:84:in `hawl' /Users/dbit/Sites/scraper/vendor/plugins/hawler/lib/hawler.rb:129:in `start' /Users/dbit/Sites/scraper/app/models/htgrep.rb:47:in `start' /Users/dbit/Sites/scraper/app/models/htgrep.rb:43:in `each' /Users/dbit/Sites/scraper/app/models/htgrep.rb:43:in `start' ./spec/models/htgrep_spec.rb:197: ./script/spec:4: From dchelimsky at gmail.com Sun Mar 30 14:17:46 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 30 Mar 2008 13:17:46 -0500 Subject: [rspec-users] My argument constraints are not working. In-Reply-To: <93ddac20803301113i241c8d3exc0827d54fcbf6534@mail.gmail.com> References: <57c63afe0803292139y7d3cbae8p70d3eb48e7038802@mail.gmail.com> <93ddac20803301113i241c8d3exc0827d54fcbf6534@mail.gmail.com> Message-ID: <57c63afe0803301117p49ea9affy364c352edd26d55f@mail.gmail.com> On Sun, Mar 30, 2008 at 1:13 PM, David Beckwith wrote: > Here is the test. I just meant the test for this: "And I tested to make sure this == operator works as expected." That's the one I want to see. From dbitsolutions at gmail.com Sun Mar 30 14:57:29 2008 From: dbitsolutions at gmail.com (David Beckwith) Date: Sun, 30 Mar 2008 11:57:29 -0700 Subject: [rspec-users] My argument constraints are not working. In-Reply-To: <57c63afe0803301117p49ea9affy364c352edd26d55f@mail.gmail.com> References: <57c63afe0803292139y7d3cbae8p70d3eb48e7038802@mail.gmail.com> <93ddac20803301113i241c8d3exc0827d54fcbf6534@mail.gmail.com> <57c63afe0803301117p49ea9affy364c352edd26d55f@mail.gmail.com> Message-ID: <93ddac20803301157j5330aa46h222b9693f45145a4@mail.gmail.com> Well, it turns out I was right..... it was a newbie error. As soon as I wrote the test that you suggested: describe Hawlee, "make sure the == works" do it "Two Hawlees should be the same if their uri is the same." do @hawlee1 = Hawlee.new( URI.parse("http://www.google.com"), nil, 0) @hawlee2 = Hawlee.new( URI.parse("http://www.google.com"), "stuff", 1) @hawlee1.should ==(@hawlee2) end end .....I found my error. I didn't write my Hawlee#== function correctly. I thought I had tested it, but I didn't. So, we were both right: I'm a newbie, and Chelim-baby is the man. Thanks! David :) On Sun, Mar 30, 2008 at 11:17 AM, David Chelimsky wrote: > On Sun, Mar 30, 2008 at 1:13 PM, David Beckwith wrote: > > Here is the test. > > I just meant the test for this: "And I tested to make sure this == > operator works as expected." > > That's the one I want to see. > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- SMS/Text: +63 905 220 2207 Skype: dbit_solutions From dchelimsky at gmail.com Sun Mar 30 15:00:07 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 30 Mar 2008 14:00:07 -0500 Subject: [rspec-users] My argument constraints are not working. In-Reply-To: <93ddac20803301157j5330aa46h222b9693f45145a4@mail.gmail.com> References: <57c63afe0803292139y7d3cbae8p70d3eb48e7038802@mail.gmail.com> <93ddac20803301113i241c8d3exc0827d54fcbf6534@mail.gmail.com> <57c63afe0803301117p49ea9affy364c352edd26d55f@mail.gmail.com> <93ddac20803301157j5330aa46h222b9693f45145a4@mail.gmail.com> Message-ID: <57c63afe0803301200p4a926db4wc822331ee030ebd8@mail.gmail.com> On Sun, Mar 30, 2008 at 1:57 PM, David Beckwith wrote: > Well, it turns out I was right..... it was a newbie error. > > As soon as I wrote the test that you suggested: > > describe Hawlee, "make sure the == works" do > it "Two Hawlees should be the same if their uri is the same." do > @hawlee1 = Hawlee.new( URI.parse("http://www.google.com"), nil, 0) > @hawlee2 = Hawlee.new( URI.parse("http://www.google.com"), "stuff", 1) > @hawlee1.should ==(@hawlee2) > end > end > > .....I found my error. I didn't write my Hawlee#== function > correctly. I thought I had tested it, but I didn't. Did you fix that and get it all working? > > So, we were both right: I'm a newbie, and Chelim-baby is the man. > > Thanks! > > David :) > > > > > On Sun, Mar 30, 2008 at 11:17 AM, David Chelimsky wrote: > > On Sun, Mar 30, 2008 at 1:13 PM, David Beckwith wrote: > > > Here is the test. > > > > I just meant the test for this: "And I tested to make sure this == > > operator works as expected." > > > > That's the one I want to see. > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > SMS/Text: +63 905 220 2207 > Skype: dbit_solutions > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Sun Mar 30 16:11:35 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 30 Mar 2008 21:11:35 +0100 Subject: [rspec-users] parameterized shared specs: good or bad idea? In-Reply-To: <57c63afe0803291441q354cf1a4l48b2b431af918682@mail.gmail.com> References: <57c63afe0803291441q354cf1a4l48b2b431af918682@mail.gmail.com> Message-ID: On 29 Mar 2008, at 21:41, David Chelimsky wrote: > There is a strategy you can use for this. Define method in a helper > and use the included hook to extend the example group. To see a > working example of this, which actually may solve the exact problem > you're trying to solve already, check out > http://github.com/technoweenie/rspec_on_rails_on_crack. I had a look through the code for this and it looks like it does some really cool stuff. But there isn't one spec file to be found (a bit unusual for an extension to a testing lib...), so I'd be more than a little anxious using it in a real project. Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080330/e3a9b767/attachment.html From nick.curry+rspec-users at gmail.com Sun Mar 30 16:47:08 2008 From: nick.curry+rspec-users at gmail.com (Nick C) Date: Sun, 30 Mar 2008 21:47:08 +0100 Subject: [rspec-users] parameterized shared specs: good or bad idea? In-Reply-To: <57c63afe0803291441q354cf1a4l48b2b431af918682@mail.gmail.com> References: <57c63afe0803291441q354cf1a4l48b2b431af918682@mail.gmail.com> Message-ID: Thanks David, that looks like exactly what I was looking for - I'm just sorry I didn't think of it myself! Cheers, Nick On Sat, Mar 29, 2008 at 10:41 PM, David Chelimsky wrote: > On Sat, Mar 29, 2008 at 3:03 PM, Nick C > > wrote: > > > Hmm, after investigating a little more, this doesn't sound feasible. > > Instance variables are already shared between shared specs and their > > callers, but I was thinking of the spec names themselves also being > > parameterised, so that the following would be possible: > > > > it "should map { :controller => '', :action => 'new' } to > > /admin//new" do > > ... > > end > > > > This would mean one of two things: class variables for and > > , which wouldn't work as these would be redefined by > > successive specs as they get loaded; or some sort of templating or > > preprocessing, which doesn't sound like a good idea at all. > > There is a strategy you can use for this. Define method in a helper > and use the included hook to extend the example group. To see a > working example of this, which actually may solve the exact problem > you're trying to solve already, check out > http://github.com/technoweenie/rspec_on_rails_on_crack. > > Cheers, > David > > > > > > > Ah well - > > > > Cheers, > > Nick > > > > > > > > On Sat, Mar 29, 2008 at 6:36 PM, Nick C > > wrote: > > > Hi, > > > > > > I've come across a couple of cases recently in which I was wishing it > > > was possible to parameterize shared specs. An example: I have defined > > > a number of rails resources, and it seems wasteful to have tens of > > > generated 'xxx_controller_spec' 'xxx_controller_routing' specs that > > > check the same mechanisms, but with different parameters (in this > > > case, the parameters would be the controller class name, and the path > > > the route should map to for instance). It doesn't seem DRY, and it > > > adds a cognitive overhead of dealing with a large number of very > > > similar files in a project that essentially do the same thing. > > > > > > Ideally, I'd have wanted to do something like this: > > > it_should_behave_like 'a standard rails routed resource', :controller > > > => UserController, :path => 'users' > > > > > > I realise that the intention of the generated specs is to be evolved > > > as the underlying controllers do; however, for the routing or some > > > actions such as 'destroy', it's unlikely there will be much variation > > > across controllers implementing the functionality, and it seems a > > > shame to have dozens of generated specs that look copy-and-pasted. > > > > > > Any thoughts? > > > > > > Thanks, > > > Nick > > > > > _______________________________________________ > > 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 tastapod at gmail.com Sun Mar 30 16:53:45 2008 From: tastapod at gmail.com (Dan North) Date: Sun, 30 Mar 2008 21:53:45 +0100 Subject: [rspec-users] My argument constraints are not working. In-Reply-To: <93ddac20803301157j5330aa46h222b9693f45145a4@mail.gmail.com> References: <57c63afe0803292139y7d3cbae8p70d3eb48e7038802@mail.gmail.com> <93ddac20803301113i241c8d3exc0827d54fcbf6534@mail.gmail.com> <57c63afe0803301117p49ea9affy364c352edd26d55f@mail.gmail.com> <93ddac20803301157j5330aa46h222b9693f45145a4@mail.gmail.com> Message-ID: Devs, can we update the website and change all references to "David Chelimsky" to be "Chelim-baby" please? Should I post a ticket? On 30/03/2008, David Beckwith wrote: > > Well, it turns out I was right..... it was a newbie error. > > As soon as I wrote the test that you suggested: > > describe Hawlee, "make sure the == works" do > it "Two Hawlees should be the same if their uri is the same." do > @hawlee1 = Hawlee.new( URI.parse("http://www.google.com"), nil, 0) > @hawlee2 = Hawlee.new( URI.parse("http://www.google.com"), "stuff", > 1) > @hawlee1.should ==(@hawlee2) > end > end > > .....I found my error. I didn't write my Hawlee#== function > correctly. I thought I had tested it, but I didn't. > > So, we were both right: I'm a newbie, and Chelim-baby is the man. > > Thanks! > > David :) > > > > On Sun, Mar 30, 2008 at 11:17 AM, David Chelimsky > wrote: > > On Sun, Mar 30, 2008 at 1:13 PM, David Beckwith > wrote: > > > Here is the test. > > > > I just meant the test for this: "And I tested to make sure this == > > operator works as expected." > > > > That's the one I want to see. > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > -- > SMS/Text: +63 905 220 2207 > Skype: dbit_solutions > > _______________________________________________ > 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/20080330/0042a2bc/attachment.html From dbitsolutions at gmail.com Sun Mar 30 23:37:15 2008 From: dbitsolutions at gmail.com (David Beckwith) Date: Sun, 30 Mar 2008 20:37:15 -0700 Subject: [rspec-users] My argument constraints are not working. In-Reply-To: <57c63afe0803301200p4a926db4wc822331ee030ebd8@mail.gmail.com> References: <57c63afe0803292139y7d3cbae8p70d3eb48e7038802@mail.gmail.com> <93ddac20803301113i241c8d3exc0827d54fcbf6534@mail.gmail.com> <57c63afe0803301117p49ea9affy364c352edd26d55f@mail.gmail.com> <93ddac20803301157j5330aa46h222b9693f45145a4@mail.gmail.com> <57c63afe0803301200p4a926db4wc822331ee030ebd8@mail.gmail.com> Message-ID: <93ddac20803302037y4071f8c6jdee68627d55cc6fa@mail.gmail.com> Yeah, I think so. The test that wasn't passing passed. I'll look at it in more detail later. Thanks for asking. D :) On Sun, Mar 30, 2008 at 12:00 PM, David Chelimsky wrote: > On Sun, Mar 30, 2008 at 1:57 PM, David Beckwith wrote: > > Well, it turns out I was right..... it was a newbie error. > > > > As soon as I wrote the test that you suggested: > > > > describe Hawlee, "make sure the == works" do > > it "Two Hawlees should be the same if their uri is the same." do > > @hawlee1 = Hawlee.new( URI.parse("http://www.google.com"), nil, 0) > > @hawlee2 = Hawlee.new( URI.parse("http://www.google.com"), "stuff", 1) > > @hawlee1.should ==(@hawlee2) > > end > > end > > > > .....I found my error. I didn't write my Hawlee#== function > > correctly. I thought I had tested it, but I didn't. > > Did you fix that and get it all working? > > > > > > > So, we were both right: I'm a newbie, and Chelim-baby is the man. > > > > Thanks! > > > > David :) > > > > > > > > > > On Sun, Mar 30, 2008 at 11:17 AM, David Chelimsky wrote: > > > On Sun, Mar 30, 2008 at 1:13 PM, David Beckwith wrote: > > > > Here is the test. > > > > > > I just meant the test for this: "And I tested to make sure this == > > > operator works as expected." > > > > > > That's the one I want to see. > > > > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > SMS/Text: +63 905 220 2207 > > Skype: dbit_solutions > > > > > > _______________________________________________ > > 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 > -- SMS/Text: +63 905 220 2207 Skype: dbit_solutions From ashley.moran at patchspace.co.uk Mon Mar 31 08:03:29 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 31 Mar 2008 13:03:29 +0100 Subject: [rspec-users] Netbeans and .story files Message-ID: Hi Is anyone here using NetBeans and story runner? NB doesn't recognise .story files so I can't even do simple things like block commenting lines (and the regex replace is temperamental). I tried adding .story to the list of Ruby file extensions, but then it just hides everything in the story folders (even the .rb files!). Any tips on how to get the two working together would be much appreciated. I've lost count of the times I've said "I could do this in TextMate"... Ta Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080331/5319e89d/attachment.html From ashley.moran at patchspace.co.uk Mon Mar 31 09:10:17 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 31 Mar 2008 14:10:17 +0100 Subject: [rspec-users] Wrong story step running In-Reply-To: References: Message-ID: On 28/03/2008, Ashley Moran wrote: > > Is story runner having trouble matching stories when they are of the > following pattern? > A + B > A + X + B > A + Y + B Came across this again, it also causes problems when the steps are of the form A A + X However, I found a (slightly better) workaround, which is to put the most specific steps first. I filed a ticket here: http://rspec.lighthouseapp.com/projects/5645/tickets/353-story-runner-step-matches-are-order-dependent Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080331/2f29b5e2/attachment-0001.html From srogers1 at gmail.com Mon Mar 31 10:40:40 2008 From: srogers1 at gmail.com (Steve Rogers) Date: Mon, 31 Mar 2008 09:40:40 -0500 Subject: [rspec-users] Netbeans and .story files In-Reply-To: References: Message-ID: On Mar 31, 2008, at 7:03 AM, Ashley Moran wrote: > Hi > > Is anyone here using NetBeans and story runner? NB doesn't > recognise .story files so I can't even do simple things like block > commenting lines (and the regex replace is temperamental). I tried > adding .story to the list of Ruby file extensions, but then it just > hides everything in the story folders (even the .rb files!). > > Any tips on how to get the two working together would be much > appreciated. I've lost count of the times I've said "I could do > this in TextMate"... I have a stories folder with files named blah_story.rb - and NetBeans doesn't seem any stranger with those than it usually is. SR From glenn at aldenta.com Mon Mar 31 11:16:29 2008 From: glenn at aldenta.com (Glenn Ford) Date: Mon, 31 Mar 2008 11:16:29 -0400 Subject: [rspec-users] Confusing error with GivenStory Message-ID: <26B3AF86-3EDD-4121-8593-C123D1192668@aldenta.com> Hey all! I'm loving Stories so far, but I ran across a difficult error today that I felt should have resulted in a "PENDING" message. Here's what I got: /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/ rails/../../../../rspec/lib/spec/story/runner/scenario_runner.rb:11:in `run': You have a nil object when you didn't expect it! (NoMethodError) The error occurred while evaluating nil.story from /Users/Malohkan/ Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/rails/ story_adapter.rb:69:in `perform' from /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/ spec/rails/../../../../rspec/lib/spec/story/world.rb:52:in `run_given_scenario_with_suspended_listeners' from /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/ spec/rails/../../../../rspec/lib/spec/story/world.rb:101:in `GivenScenario' from /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/ spec/rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb: 115:in `send' from /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/ spec/rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb: 115:in `to_proc' from /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/ spec/rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb: 95:in `instance_eval' from /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/ spec/rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb: 95:in `to_proc' from /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/ spec/rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb: 95:in `each' ... 6 levels... from /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/ spec/rails/../../../../rspec/lib/spec/story/runner/story_runner.rb: 39:in `each' from /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/ spec/rails/../../../../rspec/lib/spec/story/runner/story_runner.rb: 39:in `run_stories' from /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/ spec/rails/../../../../rspec/lib/spec/story/runner.rb:44:in `register_exit_hook' The only thing I could deduce was that it had something to do with GivenScenario. The problem was that I had misspelled the name of the Scenario I was trying to run with GivenScenario. However if you misspell a Step, you get it marked as PENDING and the ones below it as FAILED. Once I realize this my first thought was, "Great! A chance to write my own patch!" Unfortunately I think my rails-fu is still too weak. I hacked around with it for a while but couldn't duplicate the behavior like I was hoping. So the best I can do for now is to try to point those who can in the right direction. I think that the exception should be caught on line 52 of "world.rb". The one with "scenario.perform(world, name)" on it. Below in the following method I see where "step.perform(world, *args)" gets called and is wrapped with begin/rescue. If catching the exception isn't the right way to go, then check line 66 of "story_adapter.rb" which has "StoryRunner.scenario_from_current_story". This call does a .find() and returns nil. That's the first place it's made known that this Scenario doesn't exist. I hope this helps! Glenn -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080331/4503a9de/attachment.html From ashley.moran at patchspace.co.uk Mon Mar 31 11:28:14 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 31 Mar 2008 16:28:14 +0100 Subject: [rspec-users] Netbeans and .story files In-Reply-To: References: Message-ID: On 31/03/2008, Steve Rogers wrote: > I have a stories folder with files named blah_story.rb - and NetBeans > doesn't seem any stranger with those than it usually is. Steve, Sorry, I wasn't clear. It's not the my_story.rb file that's the problem, it's the my_story.story file (the plain text part). Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080331/2ed2eeb6/attachment.html From ashley.moran at patchspace.co.uk Mon Mar 31 11:32:56 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 31 Mar 2008 16:32:56 +0100 Subject: [rspec-users] Anyone seen weird autotest behaviour on trunk? Message-ID: Hi I'm running RSpec and RSpec on Rails r3333, and autotest frequently - but not consistently - fails on my after I change an individual model code file file. The error I get is this: /usr/local/bin/ruby -S script/spec -O spec/spec.opts spec/models/user_spec.rb /home/amoran/Documents/becta/apps/Backend/app/models/user.rb /home/amoran/Documents/becta/apps/Backend/app/models/user.rb:4: uninitialized constant ActiveRecord (NameError) Any idea what could be going wrong? Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080331/a4044000/attachment.html From dchelimsky at gmail.com Mon Mar 31 11:34:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 31 Mar 2008 11:34:53 -0400 Subject: [rspec-users] Confusing error with GivenStory In-Reply-To: <26B3AF86-3EDD-4121-8593-C123D1192668@aldenta.com> References: <26B3AF86-3EDD-4121-8593-C123D1192668@aldenta.com> Message-ID: <57c63afe0803310834w40e6b4f3mdb45aeadfe6868fb@mail.gmail.com> On Mon, Mar 31, 2008 at 11:16 AM, Glenn Ford wrote: > Hey all! I'm loving Stories so far, but I ran across a difficult error > today that I felt should have resulted in a "PENDING" message. Here's what > I got: > > > /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/runner/scenario_runner.rb:11:in > `run': You have a nil object when you didn't expect it! (NoMethodError) > The error occurred while evaluating nil.story from > /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/rails/story_adapter.rb:69:in > `perform' > from > /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/world.rb:52:in > `run_given_scenario_with_suspended_listeners' > from > /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/world.rb:101:in > `GivenScenario' > from > /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb:115:in > `send' > from > /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb:115:in > `to_proc' > from > /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb:95:in > `instance_eval' > from > /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb:95:in > `to_proc' > from > /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb:95:in > `each' > ... 6 levels... > from > /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/runner/story_runner.rb:39:in > `each' > from > /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/runner/story_runner.rb:39:in > `run_stories' > from > /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/rails/../../../../rspec/lib/spec/story/runner.rb:44:in > `register_exit_hook' > > The only thing I could deduce was that it had something to do with > GivenScenario. The problem was that I had misspelled the name of the > Scenario I was trying to run with GivenScenario. However if you misspell a > Step, you get it marked as PENDING and the ones below it as FAILED. > > Once I realize this my first thought was, "Great! A chance to write my own > patch!" Unfortunately I think my rails-fu is still too weak. I hacked > around with it for a while but couldn't duplicate the behavior like I was > hoping. So the best I can do for now is to try to point those who can in > the right direction. > > I think that the exception should be caught on line 52 of "world.rb". The > one with "scenario.perform(world, name)" on it. Below in the following > method I see where "step.perform(world, *args)" gets called and is wrapped > with begin/rescue. > > If catching the exception isn't the right way to go, then check line 66 of > "story_adapter.rb" which has "StoryRunner.scenario_from_current_story". > This call does a .find() and returns nil. That's the first place it's made > known that this Scenario doesn't exist. > > I hope this helps! Please post this to http://rspec.lighthouseapp.com. Thanks, David From loop at superinfinite.com Mon Mar 31 11:40:28 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Mon, 31 Mar 2008 17:40:28 +0200 Subject: [rspec-users] Anyone seen weird autotest behaviour on trunk? In-Reply-To: References: Message-ID: <9050B030-F61B-4375-A44D-B0374901FC58@superinfinite.com> On 31-mrt-2008, at 17:32, Ashley Moran wrote: > Hi > > I'm running RSpec and RSpec on Rails r3333, and autotest frequently > - but not consistently - fails on my after I change an individual > model code file file. > > The error I get is this: > /usr/local/bin/ruby -S script/spec -O spec/spec.opts spec/models/ > user_spec.rb /home/amoran/Documents/becta/apps/Backend/app/models/ > user.rb > /home/amoran/Documents/becta/apps/Backend/app/models/user.rb:4: > uninitialized constant ActiveRecord (NameError) I'm having the same problem, also with controllers. Weird part is, I mostly have it at work, running OS 10.4, but not at home, running 10.5. My environment is the same, except for the OS... gr, bartz From glenn at aldenta.com Mon Mar 31 11:55:39 2008 From: glenn at aldenta.com (Glenn Ford) Date: Mon, 31 Mar 2008 11:55:39 -0400 Subject: [rspec-users] Confusing error with GivenStory In-Reply-To: <57c63afe0803310834w40e6b4f3mdb45aeadfe6868fb@mail.gmail.com> References: <26B3AF86-3EDD-4121-8593-C123D1192668@aldenta.com> <57c63afe0803310834w40e6b4f3mdb45aeadfe6868fb@mail.gmail.com> Message-ID: <6FE5F633-A77D-44B6-B826-0D00525D800A@aldenta.com> I sent a reply just a couple minutes later... to myself only :P Sorry about that. Here what was I sent: Here's a lighthouse ticket: http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/354-confusing-error-with-givenscenario By the way I just realized I typo'd GivenStory in the subject which should have been GivenScenario. I guess I'm full of typos today! Glenn On Mar 31, 2008, at 11:34 AM, David Chelimsky wrote: > On Mon, Mar 31, 2008 at 11:16 AM, Glenn Ford > wrote: >> Hey all! I'm loving Stories so far, but I ran across a difficult >> error >> today that I felt should have resulted in a "PENDING" message. >> Here's what >> I got: >> >> >> /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/ >> rails/../../../../rspec/lib/spec/story/runner/scenario_runner.rb: >> 11:in >> `run': You have a nil object when you didn't expect it! >> (NoMethodError) >> The error occurred while evaluating nil.story from >> /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/ >> rails/story_adapter.rb:69:in >> `perform' >> from >> /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/ >> rails/../../../../rspec/lib/spec/story/world.rb:52:in >> `run_given_scenario_with_suspended_listeners' >> from >> /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/ >> rails/../../../../rspec/lib/spec/story/world.rb:101:in >> `GivenScenario' >> from >> /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/ >> rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb: >> 115:in >> `send' >> from >> /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/ >> rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb: >> 115:in >> `to_proc' >> from >> /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/ >> rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb:95:in >> `instance_eval' >> from >> /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/ >> rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb:95:in >> `to_proc' >> from >> /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/ >> rails/../../../../rspec/lib/spec/story/runner/story_mediator.rb:95:in >> `each' >> ... 6 levels... >> from >> /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/ >> rails/../../../../rspec/lib/spec/story/runner/story_runner.rb:39:in >> `each' >> from >> /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/ >> rails/../../../../rspec/lib/spec/story/runner/story_runner.rb:39:in >> `run_stories' >> from >> /Users/Malohkan/Sites/blog/vendor/plugins/rspec_on_rails/lib/spec/ >> rails/../../../../rspec/lib/spec/story/runner.rb:44:in >> `register_exit_hook' >> >> The only thing I could deduce was that it had something to do with >> GivenScenario. The problem was that I had misspelled the name of the >> Scenario I was trying to run with GivenScenario. However if you >> misspell a >> Step, you get it marked as PENDING and the ones below it as FAILED. >> >> Once I realize this my first thought was, "Great! A chance to >> write my own >> patch!" Unfortunately I think my rails-fu is still too weak. I >> hacked >> around with it for a while but couldn't duplicate the behavior like >> I was >> hoping. So the best I can do for now is to try to point those who >> can in >> the right direction. >> >> I think that the exception should be caught on line 52 of >> "world.rb". The >> one with "scenario.perform(world, name)" on it. Below in the >> following >> method I see where "step.perform(world, *args)" gets called and is >> wrapped >> with begin/rescue. >> >> If catching the exception isn't the right way to go, then check >> line 66 of >> "story_adapter.rb" which has >> "StoryRunner.scenario_from_current_story". >> This call does a .find() and returns nil. That's the first place >> it's made >> known that this Scenario doesn't exist. >> >> I hope this helps! > > Please post this to http://rspec.lighthouseapp.com. > > 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/20080331/d7c5badb/attachment-0001.html From ashley.moran at patchspace.co.uk Mon Mar 31 12:22:33 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 31 Mar 2008 17:22:33 +0100 Subject: [rspec-users] Anyone seen weird autotest behaviour on trunk? In-Reply-To: <9050B030-F61B-4375-A44D-B0374901FC58@superinfinite.com> References: <9050B030-F61B-4375-A44D-B0374901FC58@superinfinite.com> Message-ID: On 31/03/2008, Bart Zonneveld wrote: > I'm having the same problem, also with controllers. Weird part is, I > mostly have it at work, running OS 10.4, but not at home, running > 10.5. My environment is the same, except for the OS... > > gr, > bartz > Hi bartz What version of RSpec are you using at work and home? (I am using Ubuntu at work BTW.) Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080331/87cb167d/attachment.html From ashley.moran at patchspace.co.uk Mon Mar 31 12:25:26 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 31 Mar 2008 17:25:26 +0100 Subject: [rspec-users] Can you add simple argument-baesd logic to stubs? Message-ID: Hi Is there any way to do the following with stubs? template.should_receive(:formatted_last_login). with(duck_type(:last_login_date)). any_number_of_times. and_return { |user| "last-login-#{user.id}" } If I change "should_receive" to "stub!", Ruby complains that 0 args are being passed in for 1 to the block. But a quick look through the RSpec code makes it look like stub call args are passed to the and_return block. I can live with the above, I just don't need it auto-verified (I'm doing that with should have_tag) Thanks Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080331/843a07ff/attachment.html From tmhaines at gmail.com Mon Mar 31 14:27:37 2008 From: tmhaines at gmail.com (Tim Haines) Date: Tue, 1 Apr 2008 07:27:37 +1300 Subject: [rspec-users] Netbeans and .story files In-Reply-To: References: Message-ID: Hi Ashley, I don't think Netbeans has support for plain text stories yet - but I'm not certain (I was using it with frustration last night too). Probably better to ask in the netbeans forum? Cheers, tim. On 01/04/2008, Ashley Moran wrote: > > On 31/03/2008, Steve Rogers wrote: > > > I have a stories folder with files named blah_story.rb - and NetBeans > > doesn't seem any stranger with those than it usually is. > > > Steve, > > Sorry, I wasn't clear. It's not the my_story.rb file that's the problem, > it's the my_story.story file (the plain text part). > > Ashley > > > _______________________________________________ > 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/20080401/ae81ceab/attachment.html From ashley.moran at patchspace.co.uk Mon Mar 31 14:52:32 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 31 Mar 2008 19:52:32 +0100 Subject: [rspec-users] Netbeans and .story files In-Reply-To: References: Message-ID: <640B8B11-D2E0-4B69-9858-7E96EC0E2AB6@patchspace.co.uk> On 31 Mar 2008, at 19:27, Tim Haines wrote: > I don't think Netbeans has support for plain text stories yet - but > I'm not certain (I was using it with frustration last night too). > Probably better to ask in the netbeans forum? Hi Tim I noticed it didn't have any out of the box support, just wondered if anyone had hacked around that. I had a feeling it might be a bit OT for this list, but I figured there's a higher percentage of NetBeans users here than the percentage of story runner users in the NB forums... I've got a way round its stupid regex bug (/^/ doesn't match the start of a line!) so I can comment out stories semi-automatically at least. Cheers Ashley From tmhaines at gmail.com Mon Mar 31 17:53:53 2008 From: tmhaines at gmail.com (Tim Haines) Date: Tue, 1 Apr 2008 10:53:53 +1300 Subject: [rspec-users] Given .. and .. - And requires capitalisation Message-ID: Hi Guys, Just writing out a plain English story and was surprised to see one of my steps wasn't listed as pending. It turned out it was because I had started the line with and instead of And. Is there any reason why and shouldn't be an alias for And? Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080401/71ac495c/attachment.html From cremes.devlist at mac.com Mon Mar 31 18:06:37 2008 From: cremes.devlist at mac.com (Chuck Remes) Date: Mon, 31 Mar 2008 17:06:37 -0500 Subject: [rspec-users] Given .. and .. - And requires capitalisation In-Reply-To: References: Message-ID: <27D7FA76-BE66-452D-BD73-488A648EA353@mac.com> On Mar 31, 2008, at 4:53 PM, Tim Haines wrote: > Hi Guys, > > Just writing out a plain English story and was surprised to see one > of my steps wasn't listed as pending. It turned out it was because > I had started the line with and instead of And. Is there any reason > why and shouldn't be an alias for And? Tim, I would get it is because 'and' (lower case) is a reserved word in Ruby. Note that all of these commands are uppercase. I don't think they can alias 'and' without potentially breaking lots of valid ruby code (not everyone uses '&&' for 'and' exclusively). cr From dchelimsky at gmail.com Mon Mar 31 18:15:33 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 31 Mar 2008 18:15:33 -0400 Subject: [rspec-users] Given .. and .. - And requires capitalisation In-Reply-To: <27D7FA76-BE66-452D-BD73-488A648EA353@mac.com> References: <27D7FA76-BE66-452D-BD73-488A648EA353@mac.com> Message-ID: <57c63afe0803311515h7000e0a1n51bd73f2960c2f52@mail.gmail.com> On Mon, Mar 31, 2008 at 6:06 PM, Chuck Remes wrote: > On Mar 31, 2008, at 4:53 PM, Tim Haines wrote: > > Hi Guys, > > > > Just writing out a plain English story and was surprised to see one > > of my steps wasn't listed as pending. It turned out it was because > > I had started the line with and instead of And. Is there any reason > > why and shouldn't be an alias for And? > > I would get it is because 'and' (lower case) is a reserved word in > Ruby. Note that all of these commands are uppercase. I don't think > they can alias 'and' without potentially breaking lots of valid ruby > code (not everyone uses '&&' for 'and' exclusively). Additionally, 'when' and 'then' are Ruby keywords. This is the reason that all the methods are uppercase in Ruby, and they are the same in plain text for consistency. From tmhaines at gmail.com Mon Mar 31 18:17:05 2008 From: tmhaines at gmail.com (Tim Haines) Date: Tue, 1 Apr 2008 11:17:05 +1300 Subject: [rspec-users] Given .. and .. - And requires capitalisation In-Reply-To: <27D7FA76-BE66-452D-BD73-488A648EA353@mac.com> References: <27D7FA76-BE66-452D-BD73-488A648EA353@mac.com> Message-ID: Cool. I didn't know about and and Ruby. :-) thanks! On 01/04/2008, Chuck Remes wrote: > > > On Mar 31, 2008, at 4:53 PM, Tim Haines wrote: > > > Hi Guys, > > > > Just writing out a plain English story and was surprised to see one > > of my steps wasn't listed as pending. It turned out it was because > > I had started the line with and instead of And. Is there any reason > > why and shouldn't be an alias for And? > > > Tim, > > I would get it is because 'and' (lower case) is a reserved word in > Ruby. Note that all of these commands are uppercase. I don't think > they can alias 'and' without potentially breaking lots of valid ruby > code (not everyone uses '&&' for 'and' exclusively). > > cr > > _______________________________________________ > 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/20080401/3126e807/attachment.html From tmhaines at gmail.com Mon Mar 31 18:29:50 2008 From: tmhaines at gmail.com (Tim Haines) Date: Tue, 1 Apr 2008 11:29:50 +1300 Subject: [rspec-users] Given .. and .. - And requires capitalisation In-Reply-To: <57c63afe0803311515h7000e0a1n51bd73f2960c2f52@mail.gmail.com> References: <27D7FA76-BE66-452D-BD73-488A648EA353@mac.com> <57c63afe0803311515h7000e0a1n51bd73f2960c2f52@mail.gmail.com> Message-ID: I don't know how the plain text stories are parsed, but would it be reasonable to expect that if they are "plain text" rather than ruby, then lower case 'and' could be used interchangeably? Is consistency really required here? I'm thinking I would like other people writing stories for me in the future, and this seems like it would just be another PITA thing to fix after receiving stories from them.. And at the moment if not fixed, they'll just be silently ignored (v1.1.3) - which seems baaad. Tim. On 01/04/2008, David Chelimsky wrote: > > On Mon, Mar 31, 2008 at 6:06 PM, Chuck Remes > wrote: > > On Mar 31, 2008, at 4:53 PM, Tim Haines wrote: > > > Hi Guys, > > > > > > Just writing out a plain English story and was surprised to see one > > > of my steps wasn't listed as pending. It turned out it was because > > > I had started the line with and instead of And. Is there any reason > > > why and shouldn't be an alias for And? > > > > > I would get it is because 'and' (lower case) is a reserved word in > > Ruby. Note that all of these commands are uppercase. I don't think > > they can alias 'and' without potentially breaking lots of valid ruby > > code (not everyone uses '&&' for 'and' exclusively). > > > Additionally, 'when' and 'then' are Ruby keywords. This is the reason > that all the methods are uppercase in Ruby, and they are the same in > plain text for consistency. > > _______________________________________________ > 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/20080401/b6133cc7/attachment-0001.html From dchelimsky at gmail.com Mon Mar 31 20:00:52 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 31 Mar 2008 20:00:52 -0400 Subject: [rspec-users] Given .. and .. - And requires capitalisation In-Reply-To: References: <27D7FA76-BE66-452D-BD73-488A648EA353@mac.com> <57c63afe0803311515h7000e0a1n51bd73f2960c2f52@mail.gmail.com> Message-ID: <7E4681E0-4128-4719-92F0-CB7F0674C812@gmail.com> On Mar 31, 2008, at 6:29 PM, "Tim Haines" wrote: > I don't know how the plain text stories are parsed, but would it be > reasonable to expect that if they are "plain text" rather than ruby, > then lower case 'and' could be used interchangeably? Is > consistency really required here? I'm thinking I would like other > people writing stories for me in the future, and this seems like it > would just be another PITA thing to fix after receiving stories from > them.. And at the moment if not fixed, they'll just be silently > ignored (v1.1.3) - which seems baaad. Agreed that silent ignorance (tm) is bad but before we address this there are a few other issues that we need to adress first. Formal means of identifying commentary and multiline text to name two. Please feel free to put a ticket in at http://rspec.lighthouseapp.com if you want to ensure this stays ok the radar. Cheers, David > > > Tim. > > On 01/04/2008, David Chelimsky wrote: > On Mon, Mar 31, 2008 at 6:06 PM, Chuck Remes > wrote: > > On Mar 31, 2008, at 4:53 PM, Tim Haines wrote: > > > Hi Guys, > > > > > > Just writing out a plain English story and was surprised to see > one > > > of my steps wasn't listed as pending. It turned out it was > because > > > I had started the line with and instead of And. Is there any > reason > > > why and shouldn't be an alias for And? > > > > > I would get it is because 'and' (lower case) is a reserved word in > > Ruby. Note that all of these commands are uppercase. I don't think > > they can alias 'and' without potentially breaking lots of valid > ruby > > code (not everyone uses '&&' for 'and' exclusively). > > > Additionally, 'when' and 'then' are Ruby keywords. This is the reason > that all the methods are uppercase in Ruby, and they are the same in > plain text for consistency. > > _______________________________________________ > 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/20080331/7862890f/attachment.html From tmhaines at gmail.com Mon Mar 31 20:21:25 2008 From: tmhaines at gmail.com (Tim Haines) Date: Tue, 1 Apr 2008 13:21:25 +1300 Subject: [rspec-users] spec'ing models Message-ID: Hi there, A couple of complete newb questions here. Should I be spec'ing the existence of attributes on models? While reading through the docs and googling I haven't seen any example that checks if attributes exist on a model. i.e. Game.Description. Likewise, what I've seen on spec'ing associations seems light. What spec should I be writing before I add a belongs_to :genre to my game model? The closest I've seen is probably this -> http://blog.imperialdune.com/2007/2/27/rspec-ing-model-associations Cheers, Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080401/2c263b4b/attachment.html From matt at mattberther.com Mon Mar 31 20:25:32 2008 From: matt at mattberther.com (Matt Berther) Date: Mon, 31 Mar 2008 18:25:32 -0600 Subject: [rspec-users] spec'ing models In-Reply-To: References: Message-ID: <186CCD68-3C2D-4D3F-924F-2A1C9005F860@mattberther.com> Hi Tim, I'm just a newb too, but as I understand it, you should only spec code you write. In the case of attributes on models, it's ActiveRecord code. You shouldnt need to test that. I have not been doing this. That said, I'd love to get the word from some people that have been doing it for a while. -- Matt Berther http://www.mattberther.com On Mar 31, 2008, at 6:21 PM, Tim Haines wrote: > Hi there, > > A couple of complete newb questions here. > > Should I be spec'ing the existence of attributes on models? While > reading through the docs and googling I haven't seen any example > that checks if attributes exist on a model. i.e. Game.Description. > > Likewise, what I've seen on spec'ing associations seems light. What > spec should I be writing before I add a belongs_to :genre to my game > model? The closest I've seen is probably this -> http://blog.imperialdune.com/2007/2/27/rspec-ing-model-associations > > Cheers, > > Tim. > _______________________________________________ > 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/20080331/7129f577/attachment.html From tmhaines at gmail.com Mon Mar 31 20:31:57 2008 From: tmhaines at gmail.com (Tim Haines) Date: Tue, 1 Apr 2008 13:31:57 +1300 Subject: [rspec-users] spec'ing models In-Reply-To: <186CCD68-3C2D-4D3F-924F-2A1C9005F860@mattberther.com> References: <186CCD68-3C2D-4D3F-924F-2A1C9005F860@mattberther.com> Message-ID: Hey Matt, Cheers for that. Yeah - I'm not speccing methods like save, valid?, errors etc.. I am writing "belongs_to" though, so figure that should be specced somehow. I guess when I'm adding a "description" field to something, I might be writing a migration for it, but no other model code. I guess if there's no model code for it, then it kinda makes sense that it doesn't need to be in the model spec. Tim.. On 01/04/2008, Matt Berther wrote: > > Hi Tim, > I'm just a newb too, but as I understand it, you should only spec code you > write. In the case of attributes on models, it's ActiveRecord code. You > shouldnt need to test that. I have not been doing this. > > That said, I'd love to get the word from some people that have been doing > it for a while. > > -- > Matt Berther > http://www.mattberther.com > > > > > On Mar 31, 2008, at 6:21 PM, Tim Haines wrote: > > Hi there, > > A couple of complete newb questions here. > > Should I be spec'ing the existence of attributes on models? While reading > through the docs and googling I haven't seen any example that checks if > attributes exist on a model. i.e. Game.Description. > > Likewise, what I've seen on spec'ing associations seems light. What spec > should I be writing before I add a belongs_to :genre to my game model? The > closest I've seen is probably this -> > http://blog.imperialdune.com/2007/2/27/rspec-ing-model-associations > > Cheers, > > Tim. > _______________________________________________ > 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/20080401/eeaefdfd/attachment.html From abroad-crawford at within3.com Mon Mar 31 20:33:50 2008 From: abroad-crawford at within3.com (Anthony Broad-Crawford) Date: Mon, 31 Mar 2008 20:33:50 -0400 Subject: [rspec-users] spec'ing models In-Reply-To: References: Message-ID: I have been using the following approach. Looking forward to see if anyone else does something better to test associations ... describe "Profile Associations" do it "should belong to ..." do Profile.should_receive(:belongs_to).with(:account) load "profile.rb" end end Anthony Broad-Crawford On Mar 31, 2008, at 8:21 PM, Tim Haines wrote: > Hi there, > > A couple of complete newb questions here. > > Should I be spec'ing the existence of attributes on models? While > reading through the docs and googling I haven't seen any example > that checks if attributes exist on a model. i.e. Game.Description. > > Likewise, what I've seen on spec'ing associations seems light. What > spec should I be writing before I add a belongs_to :genre to my game > model? The closest I've seen is probably this -> http://blog.imperialdune.com/2007/2/27/rspec-ing-model-associations > > Cheers, > > Tim. > _______________________________________________ > 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/20080331/2f4d34a4/attachment-0001.html From tmhaines at gmail.com Mon Mar 31 20:36:42 2008 From: tmhaines at gmail.com (Tim Haines) Date: Tue, 1 Apr 2008 13:36:42 +1300 Subject: [rspec-users] spec'ing models In-Reply-To: References: <186CCD68-3C2D-4D3F-924F-2A1C9005F860@mattberther.com> Message-ID: And just to argue with myself a little - the spec output is a pretty nice of how a model works. Perhaps I'm thinking that something for the description should be specced so that it appears in the spec output.. Looking forward to taking this newb hat off sometime soon - I'm definitely spending way too much time on google at the moment. Tim.. On 01/04/2008, Tim Haines wrote: > > Hey Matt, > > Cheers for that. Yeah - I'm not speccing methods like save, valid?, > errors etc.. I am writing "belongs_to" though, so figure that should be > specced somehow. I guess when I'm adding a "description" field to > something, I might be writing a migration for it, but no other model code. > I guess if there's no model code for it, then it kinda makes sense that it > doesn't need to be in the model spec. > > Tim.. > > On 01/04/2008, Matt Berther wrote: > > > > Hi Tim, > > I'm just a newb too, but as I understand it, you should only spec code > > you write. In the case of attributes on models, it's ActiveRecord code. You > > shouldnt need to test that. I have not been doing this. > > > > That said, I'd love to get the word from some people that have been > > doing it for a while. > > > > -- > > Matt Berther > > http://www.mattberther.com > > > > > > > > > > On Mar 31, 2008, at 6:21 PM, Tim Haines wrote: > > > > Hi there, > > > > A couple of complete newb questions here. > > > > Should I be spec'ing the existence of attributes on models? While > > reading through the docs and googling I haven't seen any example that checks > > if attributes exist on a model. i.e. Game.Description. > > > > Likewise, what I've seen on spec'ing associations seems light. What > > spec should I be writing before I add a belongs_to :genre to my game model? > > The closest I've seen is probably this -> > > http://blog.imperialdune.com/2007/2/27/rspec-ing-model-associations > > > > Cheers, > > > > Tim. > > _______________________________________________ > > 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/20080401/5171c459/attachment.html From abroad-crawford at within3.com Mon Mar 31 20:40:03 2008 From: abroad-crawford at within3.com (Anthony Broad-Crawford) Date: Mon, 31 Mar 2008 20:40:03 -0400 Subject: [rspec-users] spec'ing models Message-ID: <56B5B8E7-0E3E-41D3-9363-B0DBCE79E393@within3.com> It looks like my first note didn't go through ... so I apologize if it is delayed and this is a duplicate. My colleagues and I have been testing associations like this ... it "should have one account" do Profile.should_receive(:has_one).with(:account) load "profile.rb" end We like this as we are only testing the code we write and not testing ActiveRecord. If anyone has a better approach I know we would be interested in learning about it. Anthony Broad-Crawford -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080331/9c4e627e/attachment-0001.html From jonathan at parkerhill.com Mon Mar 31 20:41:00 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Mon, 31 Mar 2008 20:41:00 -0400 Subject: [rspec-users] spec'ing models In-Reply-To: References: Message-ID: <962E97F2-6011-486E-8B05-E5BD8579A40C@parkerhill.com> for associations, among other things, i've been using http://rspec-on- rails-matchers.googlecode.com/svn/trunk/README linoj On Mar 31, 2008, at 8:33 PM, Anthony Broad-Crawford wrote: > I have been using the following approach. Looking forward to see > if anyone else does something better to test associations ... > > describe "Profile Associations" do > > it "should belong to ..." do > Profile.should_receive(:belongs_to).with(:account) > > load "profile.rb" > end > > end > > Anthony Broad-Crawford > > > On Mar 31, 2008, at 8:21 PM, Tim Haines wrote: >> Hi there, >> >> A couple of complete newb questions here. >> >> Should I be spec'ing the existence of attributes on models? While >> reading through the docs and googling I haven't seen any example >> that checks if attributes exist on a model. i.e. Game.Description. >> >> Likewise, what I've seen on spec'ing associations seems light. >> What spec should I be writing before I add a belongs_to :genre to >> my game model? The closest I've seen is probably this -> http:// >> blog.imperialdune.com/2007/2/27/rspec-ing-model-associations >> >> Cheers, >> >> Tim. >> _______________________________________________ >> 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/20080331/d9472122/attachment.html From jed.hurt at gmail.com Mon Mar 31 21:23:13 2008 From: jed.hurt at gmail.com (Jed Hurt) Date: Mon, 31 Mar 2008 19:23:13 -0600 Subject: [rspec-users] Stub an instance method for every new instance of a class Message-ID: Is there an easy way to stub an instance method for every new instance of a given class? I suppose I could just redefine the method, but I'm wondering if the RSpec mocking framework has this built in. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080331/eadaf6aa/attachment.html From cunheise at gmail.com Mon Mar 24 06:24:51 2008 From: cunheise at gmail.com (nathan.wu) Date: Mon, 24 Mar 2008 03:24:51 -0700 (PDT) Subject: [rspec-users] how should i test this code with rspec Message-ID: ids = Category.find(:all).map(&:id) ids = mock('ids') Category.should_receive(:find).with(all).and_return(??) and what's the difference between mock and mock_model when should i use mock and mock_model From hangfei at gmail.com Fri Mar 28 10:17:58 2008 From: hangfei at gmail.com (Andrew Chen) Date: Fri, 28 Mar 2008 07:17:58 -0700 (PDT) Subject: [rspec-users] How to loadby by alphabetical order, not mtime Message-ID: <4a663eb5-a4f0-49f6-bb0a-07364b9bcafd@s19g2000prg.googlegroups.com> Hi, I'm writing my requirements in rspec, however, I can not figure out a way to execute all specs according to alphabetical order, not by last modified time. According to the documentation, it seems like the default is by alphabetical order, I just can not get that to work. In the unit tests with the rspec package, seems like only mtime was tested. Can anyone tell me how to run specs by name order ? spec spec/* This will printout -L, --loadby STRATEGY Specify the strategy by which spec files should be loaded. STRATEGY can currently only be 'mtime' (File modification time) By default, spec files are loaded in alphabetical order if --loadby is not specified. Thanks ~Andrew Chen From hangfei at gmail.com Sun Mar 30 22:53:35 2008 From: hangfei at gmail.com (Andrew Chen) Date: Sun, 30 Mar 2008 22:53:35 -0400 Subject: [rspec-users] How to loadby by alphabetical order, not mtime In-Reply-To: <4a663eb5-a4f0-49f6-bb0a-07364b9bcafd@s19g2000prg.googlegroups.com> References: <4a663eb5-a4f0-49f6-bb0a-07364b9bcafd@s19g2000prg.googlegroups.com> Message-ID: <9619ddc90803301953k55707509se2c657a5111ddb77@mail.gmail.com> Hi, I'm writing my requirements in rspec, however, I can not figure out a way to execute all specs according to alphabetical order, not by last modified time. According to the documentation, it seems like the default is by alphabetical order, I just can not get that to work. In the unit tests with the rspec package, seems like only mtime was tested. Can anyone tell me how to run specs by name order ? spec spec/* This will printout -L, --loadby STRATEGY Specify the strategy by which spec files should be loaded. STRATEGY can currently only be 'mtime' (File modification time) By default, spec files are loaded in alphabetical order if --loadby is not specified. Thanks ~Andrew Chen From hangfei at gmail.com Mon Mar 31 12:07:31 2008 From: hangfei at gmail.com (Andrew Chen) Date: Mon, 31 Mar 2008 09:07:31 -0700 (PDT) Subject: [rspec-users] Is loadby file name order not implemented or not working? - want to run tests in file name order, not mtime order Message-ID: <5f516e06-d910-492c-960e-d11b5e3a7299@59g2000hsb.googlegroups.com> Hi, I'm writing my requirements in rspec, however, I can not figure out a way to execute all specs according to alphabetical order, not by last modified time. According to the documentation, it seems like the default is by alphabetical order, I just can not get that to work. In the unit tests with the rspec package, seems like only mtime was tested. Can anyone tell me how to run specs by name order ? spec spec/* This will printout -L, --loadby STRATEGY Specify the strategy by which spec files should be loaded. STRATEGY can currently only be 'mtime' (File modification time) By default, spec files are loaded in alphabetical order if --loadby is not specified. Thanks ~Andrew Chen From joe at faithfulgeek.org Mon Mar 24 12:38:26 2008 From: joe at faithfulgeek.org (Joe Fiorini) Date: Mon, 24 Mar 2008 12:38:26 -0400 Subject: [rspec-users] Using Haml for view tests Message-ID: I'm writing a view test and I render index.html.haml. However, autotest does not pick up changes to this file, but more importantly, when the tests do run I get my Haml source displayed in the "actual" result, instead of rendered Html. Does rspec support Haml in this way? Is there another way to test Haml views? Thanks all! Joe From joe at faithfulgeek.org Wed Mar 26 01:38:17 2008 From: joe at faithfulgeek.org (Joe Fiorini) Date: Wed, 26 Mar 2008 01:38:17 -0400 Subject: [rspec-users] Testing Plugins + Lib Code In-Reply-To: <810a540e0803031646l2ff666bcj28b1523e54e3d4d6@mail.gmail.com> References: <546d58d7c0adaac217a4c2e783bd61ad@ruby-forum.com> <810a540e0803031646l2ff666bcj28b1523e54e3d4d6@mail.gmail.com> Message-ID: Thanks for this! I came across your message while writing my first plugin. You allowed me to take 20 lines of lib code and turn it into a fully tested plugin in 30 minutes! Thanks man! Joe On Mar 3, 2008, at 7:46 PM, Pat Maddox wrote: > On Mon, Mar 3, 2008 at 3:17 PM, Mark Dodwell > wrote: >> Hi, >> >> I'm quite new to Rspec and I'm embarking on a new project. One >> thing I'm >> really not sure about is how to test plugins and code in your 'lib/' >> folder. Where would these specs actually live in the dir structure? >> >> Should you test plugins by creating specs within the plugin's dir? >> Or by >> adding a spec to the main '/specs' folder - and if so where? >> >> Any info/best practice advice greatly appreciated. >> >> ~ Mark >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > For stuff in lib, I create a spec/lib dir and put my specs in there. > > For plugins, I use my nifty > http://evang.eli.st/blog/2007/4/4/rspec_plugin-generator > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users