From loop at superinfinite.com Tue Apr 1 03:40:29 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Tue, 1 Apr 2008 09:40:29 +0200 Subject: [rspec-users] Anyone seen weird autotest behaviour on trunk? In-Reply-To: References: <9050B030-F61B-4375-A44D-B0374901FC58@superinfinite.com> Message-ID: <43B4A0DE-4CA8-459A-A341-140A6E6F7C4C@superinfinite.com> On 31-mrt-2008, at 18:22, Ashley Moran wrote: > > 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.) According to 'svn up', it's revision 3333 for both rspec and rspec_on_rails. Both at home and at work. From ashley.moran at patchspace.co.uk Tue Apr 1 03:48:01 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 1 Apr 2008 08:48:01 +0100 Subject: [rspec-users] Anyone seen weird autotest behaviour on trunk? In-Reply-To: <43B4A0DE-4CA8-459A-A341-140A6E6F7C4C@superinfinite.com> References: <9050B030-F61B-4375-A44D-B0374901FC58@superinfinite.com> <43B4A0DE-4CA8-459A-A341-140A6E6F7C4C@superinfinite.com> Message-ID: On 01/04/2008, Bart Zonneveld wrote: > > > According to 'svn up', it's revision 3333 for both rspec and > rspec_on_rails. Both at home and at work. Hmm, exact same revision as me. Are we the only one s having problems? I've also noticed errors along the lines of "ActionController not found" and "expected XXX to respond to respond_to?" (or something - that from the developer that sits behind me). Would love to know what's going on... Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080401/96eadb69/attachment.html From ashley.moran at patchspace.co.uk Tue Apr 1 03:50:31 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 1 Apr 2008 08:50:31 +0100 Subject: [rspec-users] Stub an instance method for every new instance of a class In-Reply-To: References: Message-ID: On 01/04/2008, Jed Hurt wrote: > > 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. Hi Jed I hate it when other people ask this, but I can't help :) How come you need to do this? I've always wondered what the use case for this "mocking" strategy is Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080401/38d11038/attachment-0001.html From glenn at aldenta.com Tue Apr 1 08:21:42 2008 From: glenn at aldenta.com (Glenn Ford) Date: Tue, 1 Apr 2008 08:21:42 -0400 Subject: [rspec-users] Stub an instance method for every new instance of a class In-Reply-To: References: Message-ID: <5819CE97-1342-41D1-AFDC-A26FA377319A@aldenta.com> I think the general consensus is that if you need this feature, then you have ugly code that needs cleaning up :) If you're in a situation like me, where you're too noob to figure out a better solution for some legacy code that you inherited, go to this url and find the instructions for installing Mocha: http://wiki.rubyonrails.org/rails/pages/Testing+Plugins With it you can do: ModelName.any_instance.stubs(:the_method).returns(happy_times) However, I strongly encourage you to stare at your current code for a while and try to find a cleaner MVC-supportive solution. The general rule of thumb is that if it's difficult to write a spec for, then your code is ugly :) Hopefully in this case you can take this as an opportunity to improve your code. If not, Mocha works fairly well! Glenn On Apr 1, 2008, at 3:50 AM, Ashley Moran wrote: > On 01/04/2008, Jed Hurt wrote: > 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. > > Hi Jed > > I hate it when other people ask this, but I can't help :) How come > you need to do this? I've always wondered what the use case for > this "mocking" strategy is > > 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/d65e1f0f/attachment.html From oliver.saunders at gmail.com Tue Apr 1 10:53:53 2008 From: oliver.saunders at gmail.com (Ollie Saunders) Date: Tue, 1 Apr 2008 15:53:53 +0100 Subject: [rspec-users] Tabs in the TextMate Bundle Message-ID: <13d820710804010753i3d58c941rd3b5591c52a2cfab@mail.gmail.com> I tried to post this to the devel list but it never seemed to get through. So I'm posting it here in the hope that someone from the development team will notice: Hello, I noticed that you are using spaces in all the snippets in the TextMate bundle. I have TM set to 4 spaces and when I use the RSpec bundle I get all these 3-spaced things that are inconsistent and difficult to work with. If you change all the spaces in the snippets to tabs they are expanded to the users preference as they are used. So users wanting 2, 3 or 4 spaces or actual tabs get what they want. I'm using revision 3333 btw. Second thing: I experienced some problems getting the correct version of ruby to work with RSpec (it was refusing to use the one that had all the gems installed), this isn't really your issue at all but I wondered if it might be nice to put a note about the issue in the README. Especially considering you can run these two lines of bash to make the problem magically vanish: mkdir ~/.MacOSX echo "{ PATH = \"$PATH\"; }" > ~/.MacOSX/environment.plist -- Ollie http://olliesaunders.net/ From dchelimsky at gmail.com Tue Apr 1 11:07:51 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 1 Apr 2008 11:07:51 -0400 Subject: [rspec-users] Tabs in the TextMate Bundle In-Reply-To: <13d820710804010753i3d58c941rd3b5591c52a2cfab@mail.gmail.com> References: <13d820710804010753i3d58c941rd3b5591c52a2cfab@mail.gmail.com> Message-ID: <57c63afe0804010807r9308334q3afdbf303ea2f97e@mail.gmail.com> On Tue, Apr 1, 2008 at 10:53 AM, Ollie Saunders wrote: > I tried to post this to the devel list but it never seemed to get > through. So I'm posting it here in the hope that someone from the > development team will notice: If you want the dev team to notice, please post a ticket to http://rspec.lighthouseapp.com. Cheers, David > > Hello, > > I noticed that you are using spaces in all the snippets in the > TextMate bundle. I have TM set to 4 spaces and when I use the RSpec > bundle I get all these 3-spaced things that are inconsistent and > difficult to work with. > > If you change all the spaces in the snippets to tabs they are expanded > to the users preference as they are used. So users wanting 2, 3 or 4 > spaces or actual tabs get what they want. I'm using revision 3333 btw. > > Second thing: I experienced some problems getting the correct version > of ruby to work with RSpec (it was refusing to use the one that had > all the gems installed), this isn't really your issue at all but I > wondered if it might be nice to put a note about the issue in the > README. Especially considering you can run these two lines of bash to > make the problem magically vanish: > > mkdir ~/.MacOSX > echo "{ PATH = \"$PATH\"; }" > ~/.MacOSX/environment.plist > > -- > Ollie > http://olliesaunders.net/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jed.hurt at gmail.com Tue Apr 1 13:19:47 2008 From: jed.hurt at gmail.com (Jed Hurt) Date: Tue, 1 Apr 2008 11:19:47 -0600 Subject: [rspec-users] Stub an instance method for every new instance of a class In-Reply-To: References: Message-ID: Haha, that's about the response I was expecting; I asked with some trepidation. I'm just looking for a quick hack to short-circuit Merb's render method to do some view/controller isolation testing until Merb officially supports it. I can't just stub methods on @controller (like in Rails) because the controller is instantiated after calling dispatch. I suppose I could whip up a different sort of hack to accomplish the isolation in the meantime, but now I'm not so sure; apparently I'm quite a noob ;) On Tue, Apr 1, 2008 at 1:50 AM, Ashley Moran wrote: > On 01/04/2008, Jed Hurt wrote: > > > 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. > > > Hi Jed > > I hate it when other people ask this, but I can't help :) How come you > need to do this? I've always wondered what the use case for this "mocking" > strategy is > > 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/891520b2/attachment.html From coreyhaines at gmail.com Tue Apr 1 14:11:23 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Tue, 1 Apr 2008 14:11:23 -0400 Subject: [rspec-users] Stub an instance method for every new instance of a class In-Reply-To: References: Message-ID: <6bdacb70804011111m620acba1r34eb9f4f2e7ed5a2@mail.gmail.com> Could you stub out Controller.new and return your mock? On Tue, Apr 1, 2008 at 1:19 PM, Jed Hurt wrote: > Haha, that's about the response I was expecting; I asked with some > trepidation. I'm just looking for a quick hack to short-circuit Merb's > render method to do some view/controller isolation testing until Merb > officially supports it. I can't just stub methods on @controller (like in > Rails) because the controller is instantiated after calling dispatch. > I suppose I could whip up a different sort of hack to accomplish the > isolation in the meantime, but now I'm not so sure; apparently I'm quite a > noob ;) > > On Tue, Apr 1, 2008 at 1:50 AM, Ashley Moran < > ashley.moran at patchspace.co.uk> wrote: > > > On 01/04/2008, Jed Hurt wrote: > > > > > 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. > > > > > > Hi Jed > > > > I hate it when other people ask this, but I can't help :) How come you > > need to do this? I've always wondered what the use case for this "mocking" > > strategy is > > > > Ashley > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- 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/20080401/53ada359/attachment.html From dchelimsky at gmail.com Tue Apr 1 14:12:24 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 1 Apr 2008 14:12:24 -0400 Subject: [rspec-users] Stub an instance method for every new instance of a class In-Reply-To: <6bdacb70804011111m620acba1r34eb9f4f2e7ed5a2@mail.gmail.com> References: <6bdacb70804011111m620acba1r34eb9f4f2e7ed5a2@mail.gmail.com> Message-ID: <57c63afe0804011112i2d501dcw3f43644c6e7894f9@mail.gmail.com> On Tue, Apr 1, 2008 at 2:11 PM, Corey Haines wrote: > Could you stub out Controller.new and return your mock? Bingo. > > > > On Tue, Apr 1, 2008 at 1:19 PM, Jed Hurt wrote: > > Haha, that's about the response I was expecting; I asked with some > trepidation. I'm just looking for a quick hack to short-circuit Merb's > render method to do some view/controller isolation testing until Merb > officially supports it. I can't just stub methods on @controller (like in > Rails) because the controller is instantiated after calling dispatch. > > > > > > I suppose I could whip up a different sort of hack to accomplish the > isolation in the meantime, but now I'm not so sure; apparently I'm quite a > noob ;) > > > > > > > > > > > > On Tue, Apr 1, 2008 at 1:50 AM, Ashley Moran > wrote: > > > > > > > > > > > > > > > > > On 01/04/2008, Jed Hurt wrote: > > > > > > > > > > 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. > > > > > > > > > Hi Jed > > > > > > I hate it when other people ask this, but I can't help :) How come you > need to do this? I've always wondered what the use case for this "mocking" > strategy is > > > > > > Ashley > > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > 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 tmhaines at gmail.com Tue Apr 1 22:31:47 2008 From: tmhaines at gmail.com (Tim Haines) Date: Wed, 2 Apr 2008 15:31:47 +1300 Subject: [rspec-users] problem rendering template with story Message-ID: Hi y'all The problem is probably because I'm a newb. I have a home controller in the admin namespace. My controller spec is working as expected, and the following example is passing: it "should show the home page if logged in" do controller.send("current_user=", User.new) get :index response.should render_template('admin/home/index') end But my story is failing on the "then" step: When "I view the home page" do get admin_url end Then "I see the home page" do response.should_not be_redirect # this passes response.code.should == "200" # this passes response.should have_text(/"Client Administration."/) #this fails, as response.body is nil response.should render_template("admin/home/index") #this fails, with actual being nil. end It's as though the template isn't actually being rendered for some reason. Any clues as to why this might be? My login story uses render_template in a similar way and it works successfully.. Cheers, Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080402/71c8201c/attachment-0001.html From tmhaines at gmail.com Wed Apr 2 00:06:40 2008 From: tmhaines at gmail.com (Tim Haines) Date: Wed, 2 Apr 2008 17:06:40 +1300 Subject: [rspec-users] problem rendering template with story In-Reply-To: References: Message-ID: Hi, Made a little progress here. In one of my "given" steps I was posting to the login action. when I take this post out (and make other changes required), the should render_template works correctly. It's as though the earlier post in the given step is meaning that the response isn't set correctly after the later post.. Tim. On 02/04/2008, Tim Haines wrote: > > Hi y'all > > The problem is probably because I'm a newb. I have a home controller in > the admin namespace. > > My controller spec is working as expected, and the following example is > passing: > > it "should show the home page if logged in" do > controller.send("current_user=", User.new) > get :index > response.should render_template('admin/home/index') > end > > > But my story is failing on the "then" step: > > When "I view the home page" do > get admin_url > end > > Then "I see the home page" do > response.should_not be_redirect # this passes > response.code.should == "200" # this passes > > response.should have_text(/"Client Administration."/) #this fails, as > response.body is nil > response.should render_template("admin/home/index") #this fails, with > actual being nil. > end > > It's as though the template isn't actually being rendered for some > reason. Any clues as to why this might be? My login story uses > render_template in a similar way and it works successfully.. > > Cheers, > > Tim. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080402/8d9a0ff5/attachment.html From jed.hurt at gmail.com Wed Apr 2 00:22:27 2008 From: jed.hurt at gmail.com (Jed Hurt) Date: Tue, 1 Apr 2008 22:22:27 -0600 Subject: [rspec-users] Stub an instance method for every new instance of a class In-Reply-To: <57c63afe0804011112i2d501dcw3f43644c6e7894f9@mail.gmail.com> References: <6bdacb70804011111m620acba1r34eb9f4f2e7ed5a2@mail.gmail.com> <57c63afe0804011112i2d501dcw3f43644c6e7894f9@mail.gmail.com> Message-ID: I'm not sure how that would work. For controller specs, I want to keep most of the controller intact so that I can verify its actual behavior. Am I missing something? On Tue, Apr 1, 2008 at 12:12 PM, David Chelimsky wrote: > On Tue, Apr 1, 2008 at 2:11 PM, Corey Haines > wrote: > > Could you stub out Controller.new and return your mock? > > Bingo. > > > > > > > > > On Tue, Apr 1, 2008 at 1:19 PM, Jed Hurt wrote: > > > Haha, that's about the response I was expecting; I asked with some > > trepidation. I'm just looking for a quick hack to short-circuit Merb's > > render method to do some view/controller isolation testing until Merb > > officially supports it. I can't just stub methods on @controller (like > in > > Rails) because the controller is instantiated after calling dispatch. > > > > > > > > > I suppose I could whip up a different sort of hack to accomplish the > > isolation in the meantime, but now I'm not so sure; apparently I'm quite > a > > noob ;) > > > > > > > > > > > > > > > > > > On Tue, Apr 1, 2008 at 1:50 AM, Ashley Moran > > wrote: > > > > > > > > > > > > > > > > > > > > > > > On 01/04/2008, Jed Hurt wrote: > > > > > > > > > > > > > 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. > > > > > > > > > > > > Hi Jed > > > > > > > > I hate it when other people ask this, but I can't help :) How come > you > > need to do this? I've always wondered what the use case for this > "mocking" > > strategy is > > > > > > > > Ashley > > > > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > -- > > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080401/7e954f23/attachment.html From tmhaines at gmail.com Wed Apr 2 00:55:36 2008 From: tmhaines at gmail.com (Tim Haines) Date: Wed, 2 Apr 2008 17:55:36 +1300 Subject: [rspec-users] problem rendering template with story In-Reply-To: References: Message-ID: And I suspect this is because @first_render isn't being set for subsequent renders.... but it's time to go home now. On 02/04/2008, Tim Haines wrote: > > Hi, > > Made a little progress here. In one of my "given" steps I was posting to > the login action. when I take this post out (and make other changes > required), the should render_template works correctly. It's as though the > earlier post in the given step is meaning that the response isn't set > correctly after the later post.. > > Tim. > > On 02/04/2008, Tim Haines wrote: > > > > Hi y'all > > > > The problem is probably because I'm a newb. I have a home controller in > > the admin namespace. > > > > My controller spec is working as expected, and the following example is > > passing: > > > > it "should show the home page if logged in" do > > controller.send("current_user=", User.new) > > get :index > > response.should render_template('admin/home/index') > > end > > > > > > But my story is failing on the "then" step: > > > > When "I view the home page" do > > get admin_url > > end > > > > Then "I see the home page" do > > response.should_not be_redirect # this passes > > response.code.should == "200" # this passes > > > > response.should have_text(/"Client Administration."/) #this fails, > > as response.body is nil > > response.should render_template("admin/home/index") #this fails, > > with actual being nil. > > end > > > > It's as though the template isn't actually being rendered for some > > reason. Any clues as to why this might be? My login story uses > > render_template in a similar way and it works successfully.. > > > > Cheers, > > > > Tim. > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080402/4aff76f9/attachment.html From tmhaines at gmail.com Wed Apr 2 01:16:26 2008 From: tmhaines at gmail.com (Tim Haines) Date: Wed, 2 Apr 2008 18:16:26 +1300 Subject: [rspec-users] Given Logged In Message-ID: Hi there, Given my recent problems with .should render_template after a second post, I'm wondering if there's a way I set the state as logged in inside a given step without posting to sessions/create? I can't seem to directly set sessions[:user_id]. I'm using restful_authentication. This is a story as opposed to a spec.. Cheers, Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080402/bba6eb55/attachment.html From dchelimsky at gmail.com Wed Apr 2 01:22:08 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Apr 2008 01:22:08 -0400 Subject: [rspec-users] Given Logged In In-Reply-To: References: Message-ID: <57c63afe0804012222q2e10aed3q9158e33a6692fa7d@mail.gmail.com> On Wed, Apr 2, 2008 at 1:16 AM, Tim Haines wrote: > Hi there, > > Given my recent problems with .should render_template after a second post, > I'm wondering if there's a way I set the state as logged in inside a given > step without posting to sessions/create? Why not just post to sessions/create? That works, doesn't it? > I can't seem to directly set > sessions[:user_id]. I'm using restful_authentication. > > This is a story as opposed to a spec.. > > Cheers, > > Tim. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tmhaines at gmail.com Wed Apr 2 01:37:49 2008 From: tmhaines at gmail.com (Tim Haines) Date: Wed, 2 Apr 2008 18:37:49 +1300 Subject: [rspec-users] Given Logged In In-Reply-To: <57c63afe0804012222q2e10aed3q9158e33a6692fa7d@mail.gmail.com> References: <57c63afe0804012222q2e10aed3q9158e33a6692fa7d@mail.gmail.com> Message-ID: Hi David. That does the login. So - yes - probably. I had thought it was breaking the "should render_template" that I make after the subsequent post, but maybe something else is causing that to break.. Tim. On 02/04/2008, David Chelimsky wrote: > > On Wed, Apr 2, 2008 at 1:16 AM, Tim Haines wrote: > > Hi there, > > > > Given my recent problems with .should render_template after a second > post, > > I'm wondering if there's a way I set the state as logged in inside a > given > > step without posting to sessions/create? > > > Why not just post to sessions/create? That works, doesn't it? > > > > I can't seem to directly set > > sessions[:user_id]. I'm using restful_authentication. > > > > This is a story as opposed to a spec.. > > > > 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/20080402/da56daa9/attachment-0001.html From lists at ruby-forum.com Wed Apr 2 04:13:12 2008 From: lists at ruby-forum.com (Juanma Cervera) Date: Wed, 2 Apr 2008 10:13:12 +0200 Subject: [rspec-users] spec'ing validates_uniqueness_of :whatever Message-ID: <0dd0eba5dd691ba9190d0abf31407fd1@ruby-forum.com> Hello I am learning rspec and trying to especify the activerecord validations of my models. How would I make a require_uniqueness_of specification for a field. Can I make this with mocks, without touching the database? Can somebody point me to some information or plugin for this issue. Thank you very much. Juan M. Cervera -- Posted via http://www.ruby-forum.com/. From court3nay at gmail.com Wed Apr 2 04:19:26 2008 From: court3nay at gmail.com (Courtenay) Date: Wed, 2 Apr 2008 01:19:26 -0700 Subject: [rspec-users] spec'ing validates_uniqueness_of :whatever In-Reply-To: <0dd0eba5dd691ba9190d0abf31407fd1@ruby-forum.com> References: <0dd0eba5dd691ba9190d0abf31407fd1@ruby-forum.com> Message-ID: IMO this function should be tested using the database, since it relies heavily on the data. ________________ Courtenay @(o..O)@ On Apr 2, 2008, at 1:13 AM, Juanma Cervera wrote: > Hello > > I am learning rspec and trying to especify the activerecord > validations > of my models. > > How would I make a require_uniqueness_of specification for a field. > Can I make this with mocks, without touching the database? > Can somebody point me to some information or plugin for this issue. > > Thank you very much. > > Juan M. Cervera > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Wed Apr 2 04:58:00 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 2 Apr 2008 01:58:00 -0700 Subject: [rspec-users] spec'ing validates_uniqueness_of :whatever In-Reply-To: References: <0dd0eba5dd691ba9190d0abf31407fd1@ruby-forum.com> Message-ID: <810a540e0804020158t3f42648fx111e51ea2becc3e2@mail.gmail.com> On Wed, Apr 2, 2008 at 1:19 AM, Courtenay wrote: > IMO this function should be tested using the database, since it relies > heavily on the data. Agreed. Create a record, then create another record with duplicate data, and verify that the second record is invalid. Pat From coreyhaines at gmail.com Wed Apr 2 10:18:19 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 2 Apr 2008 10:18:19 -0400 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: <6bdacb70804020718v6cdba515qf209a0439eaf0d4b@mail.gmail.com> Just thought I'd send out a little update on using this library. Great! We converted our tests over to using it, and I'm very happy with it. Good job, Kyle! Keep up the good work. It did take a bit of time to convert (using @ in attributes, for example), but it was well worth it. -Corey On Wed, Mar 26, 2008 at 3:08 PM, Kyle Hargraves wrote: > 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 > _______________________________________________ > 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/20080402/8a4b2761/attachment.html From coreyhaines at gmail.com Wed Apr 2 10:19:40 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Wed, 2 Apr 2008 10:19:40 -0400 Subject: [rspec-users] Stub an instance method for every new instance of a class In-Reply-To: References: <6bdacb70804011111m620acba1r34eb9f4f2e7ed5a2@mail.gmail.com> <57c63afe0804011112i2d501dcw3f43644c6e7894f9@mail.gmail.com> Message-ID: <6bdacb70804020719q4da82c38u691ae4689fab0e73@mail.gmail.com> Create an instance of the controller contr = MyController.new MyController.stub!(:new).and_return contr contr.stub!(:method_i_want_to_stub).and_return 'sweetness' Something like this? -Corey On Wed, Apr 2, 2008 at 12:22 AM, Jed Hurt wrote: > I'm not sure how that would work. For controller specs, I want to keep > most of the controller intact so that I can verify its actual behavior. Am I > missing something? > > > On Tue, Apr 1, 2008 at 12:12 PM, David Chelimsky > wrote: > > > On Tue, Apr 1, 2008 at 2:11 PM, Corey Haines > > wrote: > > > Could you stub out Controller.new and return your mock? > > > > Bingo. > > > > > > > > > > > > > > On Tue, Apr 1, 2008 at 1:19 PM, Jed Hurt wrote: > > > > Haha, that's about the response I was expecting; I asked with some > > > trepidation. I'm just looking for a quick hack to short-circuit Merb's > > > render method to do some view/controller isolation testing until Merb > > > officially supports it. I can't just stub methods on @controller (like > > in > > > Rails) because the controller is instantiated after calling dispatch. > > > > > > > > > > > > I suppose I could whip up a different sort of hack to accomplish the > > > isolation in the meantime, but now I'm not so sure; apparently I'm > > quite a > > > noob ;) > > > > > > > > > > > > > > > > > > > > > > > > On Tue, Apr 1, 2008 at 1:50 AM, Ashley Moran > > > wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On 01/04/2008, Jed Hurt wrote: > > > > > > > > > > > > > > > > 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. > > > > > > > > > > > > > > > Hi Jed > > > > > > > > > > I hate it when other people ask this, but I can't help :) How > > come you > > > need to do this? I've always wondered what the use case for this > > "mocking" > > > strategy is > > > > > > > > > > Ashley > > > > > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > -- > > > 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 > > > > > _______________________________________________ > 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/20080402/9e2fa221/attachment.html From smingins at elctech.com Wed Apr 2 16:20:32 2008 From: smingins at elctech.com (Shane Mingins) Date: Thu, 3 Apr 2008 09:20:32 +1300 Subject: [rspec-users] Given Logged In In-Reply-To: References: Message-ID: Hi Tim I haven't had a chance to look at stories yet ... but can u not use the AuthenticatedTestHelper login_as method? Cheers Shane On 2/04/2008, at 6:16 PM, Tim Haines wrote: > Hi there, > > Given my recent problems with .should render_template after a second > post, I'm wondering if there's a way I set the state as logged in > inside a given step without posting to sessions/create? I can't > seem to directly set sessions[:user_id]. I'm using > restful_authentication. > > This is a story as opposed to a spec.. > > Cheers, > > Tim. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From tmhaines at gmail.com Wed Apr 2 19:09:05 2008 From: tmhaines at gmail.com (Tim Haines) Date: Thu, 3 Apr 2008 12:09:05 +1300 Subject: [rspec-users] newb q: Can story steps report a view rendering error? Message-ID: Hi'ya I have a When step that calls get game_url. It turns out that calling this page is resulting in a render error, which explains my failing Then steps. It would help me if the story told me there was a problem rendering the response. Is there any way to get the story steps to automatically raise an error if such a problem occurs? For now I can add response.code.should == "200" or something similar.. Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080403/8e40cd9f/attachment.html From philodespotos at gmail.com Wed Apr 2 20:31:38 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Wed, 2 Apr 2008 19:31:38 -0500 Subject: [rspec-users] newb q: Can story steps report a view rendering error? In-Reply-To: References: Message-ID: <60f3810c0804021731t6117892due4e12dae7f8e41cf@mail.gmail.com> On Wed, Apr 2, 2008 at 6:09 PM, Tim Haines wrote: > Hi'ya > > I have a When step that calls get game_url. It turns out that calling this > page is resulting in a render error, which explains my failing Then steps. > It would help me if the story told me there was a problem rendering the > response. Is there any way to get the story steps to automatically raise an > error if such a problem occurs? > > For now I can add response.code.should == "200" or something similar.. I just rely on test.log, inside of which you will find the typical stacktrace produced by errors that occur while rendering a template. So that will explain the problem; to catch the explosion before your stories move on, you are right that you have to check the response code. Your code check, or the equivalent 'response.should be_success', should suffice. webrat, for example, wraps its requests in a method 'request_page()', and after every request it calls 'assert_response :success' so that the story will fail fast. Kyle From tmhaines at gmail.com Wed Apr 2 20:38:03 2008 From: tmhaines at gmail.com (Tim Haines) Date: Thu, 3 Apr 2008 13:38:03 +1300 Subject: [rspec-users] problem rendering template with story In-Reply-To: References: Message-ID: I got this way wrong. It was due to pages not rendering due to there being an error in the view (that I wasn't aware of). The problem in the view was due to the test database not being up to date with the latest migrations... (so page was rendering correctly in dev mode) I'm happy I've persisted with it and now finally have a bunch of working stories... Tim. On 02/04/2008, Tim Haines wrote: > > And I suspect this is because @first_render isn't being set for subsequent > renders.... but it's time to go home now. > > On 02/04/2008, Tim Haines wrote: > > > > Hi, > > > > Made a little progress here. In one of my "given" steps I was posting > > to the login action. when I take this post out (and make other changes > > required), the should render_template works correctly. It's as though the > > earlier post in the given step is meaning that the response isn't set > > correctly after the later post.. > > > > Tim. > > > > On 02/04/2008, Tim Haines wrote: > > > > > > Hi y'all > > > > > > The problem is probably because I'm a newb. I have a home controller > > > in the admin namespace. > > > > > > My controller spec is working as expected, and the following example > > > is passing: > > > > > > it "should show the home page if logged in" do > > > controller.send("current_user=", User.new) > > > get :index > > > response.should render_template('admin/home/index') > > > end > > > > > > > > > But my story is failing on the "then" step: > > > > > > When "I view the home page" do > > > get admin_url > > > end > > > > > > Then "I see the home page" do > > > response.should_not be_redirect # this passes > > > response.code.should == "200" # this passes > > > > > > response.should have_text(/"Client Administration."/) #this > > > fails, as response.body is nil > > > response.should render_template("admin/home/index") #this fails, > > > with actual being nil. > > > end > > > > > > It's as though the template isn't actually being rendered for some > > > reason. Any clues as to why this might be? My login story uses > > > render_template in a similar way and it works successfully.. > > > > > > Cheers, > > > > > > Tim. > > > > > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080403/53d59eec/attachment.html From jed.hurt at gmail.com Thu Apr 3 00:29:53 2008 From: jed.hurt at gmail.com (Jed Hurt) Date: Wed, 2 Apr 2008 22:29:53 -0600 Subject: [rspec-users] Stub an instance method for every new instance of a class In-Reply-To: <6bdacb70804020719q4da82c38u691ae4689fab0e73@mail.gmail.com> References: <6bdacb70804011111m620acba1r34eb9f4f2e7ed5a2@mail.gmail.com> <57c63afe0804011112i2d501dcw3f43644c6e7894f9@mail.gmail.com> <6bdacb70804020719q4da82c38u691ae4689fab0e73@mail.gmail.com> Message-ID: Ahhh, clever. I see the light On Wed, Apr 2, 2008 at 8:19 AM, Corey Haines wrote: > Create an instance of the controller > > contr = MyController.new > > MyController.stub!(:new).and_return contr > > contr.stub!(:method_i_want_to_stub).and_return 'sweetness' > > Something like this? > > -Corey > > On Wed, Apr 2, 2008 at 12:22 AM, Jed Hurt wrote: > > > I'm not sure how that would work. For controller specs, I want to keep > > most of the controller intact so that I can verify its actual behavior. Am I > > missing something? > > > > > > On Tue, Apr 1, 2008 at 12:12 PM, David Chelimsky > > wrote: > > > > > On Tue, Apr 1, 2008 at 2:11 PM, Corey Haines > > > wrote: > > > > Could you stub out Controller.new and return your mock? > > > > > > Bingo. > > > > > > > > > > > > > > > > > > > On Tue, Apr 1, 2008 at 1:19 PM, Jed Hurt wrote: > > > > > Haha, that's about the response I was expecting; I asked with some > > > > trepidation. I'm just looking for a quick hack to short-circuit > > > Merb's > > > > render method to do some view/controller isolation testing until > > > Merb > > > > officially supports it. I can't just stub methods on @controller > > > (like in > > > > Rails) because the controller is instantiated after calling > > > dispatch. > > > > > > > > > > > > > > > I suppose I could whip up a different sort of hack to accomplish > > > the > > > > isolation in the meantime, but now I'm not so sure; apparently I'm > > > quite a > > > > noob ;) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On Tue, Apr 1, 2008 at 1:50 AM, Ashley Moran > > > > wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On 01/04/2008, Jed Hurt wrote: > > > > > > > > > > > > > > > > > > > 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. > > > > > > > > > > > > > > > > > > Hi Jed > > > > > > > > > > > > I hate it when other people ask this, but I can't help :) How > > > come you > > > > need to do this? I've always wondered what the use case for this > > > "mocking" > > > > strategy is > > > > > > > > > > > > Ashley > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > -- > > > > 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 > > > > > > > > > _______________________________________________ > > 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/20080402/6a9b6bed/attachment.html From grail at goldweb.com.au Wed Apr 2 20:37:53 2008 From: grail at goldweb.com.au (Alex Satrapa) Date: Thu, 3 Apr 2008 11:37:53 +1100 Subject: [rspec-users] newb q: Can story steps report a view rendering error? In-Reply-To: References: Message-ID: <2AED31C1-B529-45E6-8F1E-11FC4C79ED8D@goldweb.com.au> On 03/04/2008, at 10:09 , Tim Haines wrote: > For now I can add response.code.should == "200" or something similar.. The page returned by Rails to provide you with the stack trace and stuff? That is a valid HTML page, and it comes along with a HTTP 200 OK response. What you need to do is look for stuff that you expect to see or not see on the page: # This will complain when your page isn't rendered using the expected template response.should have_tag('title', 'This is the title I expect to see') There used to be an article on using the have_tag matcher here: http://rubypond.com/articles/2008/03/31/using-rspec-have_tag/ ... however at the time of writing this email, I get a page stating only, "The page you are looking for is temporarily unavailable. Please try again later." Hopefully it comes back, I go back to read it for a refresher every now and then. Hope this helps! Alex From matt at mattberther.com Thu Apr 3 02:14:59 2008 From: matt at mattberther.com (Matt Berther) Date: Thu, 3 Apr 2008 00:14:59 -0600 Subject: [rspec-users] spec'ing validates_uniqueness_of :whatever In-Reply-To: <0dd0eba5dd691ba9190d0abf31407fd1@ruby-forum.com> References: <0dd0eba5dd691ba9190d0abf31407fd1@ruby-forum.com> Message-ID: <38602246-DB07-4A2C-8FE8-0581DA35FDDE@mattberther.com> Hi Juanma, I do this this way: describe Model do def create(options={}) Model.create(options) end it "should not allow duplicate names" do model = create(:name => "name") new_model = create(:name => "name") new_model.should have_error_on(:name, :taken) end end -- Matt Berther http://www.mattberther.com On Apr 2, 2008, at 2:13 AM, Juanma Cervera wrote: > Hello > > I am learning rspec and trying to especify the activerecord > validations > of my models. > > How would I make a require_uniqueness_of specification for a field. > Can I make this with mocks, without touching the database? > Can somebody point me to some information or plugin for this issue. > > Thank you very much. > > Juan M. Cervera > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ashley.moran at patchspace.co.uk Thu Apr 3 04:56:52 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 3 Apr 2008 09:56:52 +0100 Subject: [rspec-users] Anyone experienced RSpec/Autotest forgetting models? Message-ID: Hi Saving a controller spec frequently gives me this error: 52) LoadError in 'UsersController GET /users with basic request params should find all the user types' Expected /home/amoran/Documents/becta/apps/Backend/app/models/user_type.rb to define UserType ./spec/controllers/users_controller_spec.rb:299: script/spec:4: I have to Ctrl-C autotest before it will load again. Anyone else seen this? Is it a known issue? I am on trunk r3333. Thanks Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080403/f5058091/attachment.html From joe at eshopworks.co.uk Thu Apr 3 05:15:04 2008 From: joe at eshopworks.co.uk (joseph) Date: Thu, 03 Apr 2008 10:15:04 +0100 Subject: [rspec-users] Advice / Turning a Usecase into a Rspec Story / Granularity ofstories In-Reply-To: <64B3E556-6A7C-4298-A9A9-C4BE941565F4@superinfinite.com> References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <64B3E556-6A7C-4298-A9A9-C4BE941565F4@superinfinite.com> Message-ID: <1207214104.6571.23.camel@esw023.esw.eshopworks.co.uk> Hello, I'm having some trouble working out what the granularity of stories should be. I have a use-case 'manage page', for a blogging system (like wordpress) I'm building. The single use-case covers - add page,delete page,edit page,preview page actions. With the use-case we avoided getting too fine a level of granularity (i.e. add page use-case, delete page use-case...), to keep the clients and us sane. I tried to maintain a convention of converting a use-case into a rspec story. Mainly to make it easier for the client to engage in the stories. Example Story (High level): Story: Web admin manages pages within the admin system Scenario: Add page Scenario: edit page. Scenario: delete page. I'm unsure if this granularity is productive for a rspec story. Whether it will lead to a bloated story and if the scenarios become less obviously link to the title/narrative. I have a nagging doubt that perhaps it should be: Example Story (Low level) Story: Web admin adds a page Scenario: without some special fields Scenario: Setting publish dates Have people experienced this issue before? Does anyone have any comments or suggestions? Thanks, Joseph Wilk http://www.joesniff.co.uk On Mon, 2008-03-17 at 09:40 +0100, Bart Zonneveld wrote: > 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 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Latest News:- * www.phaidon.com launch their new site on WORKSsitebuilder * www.pukkaherbs.com are experts in all things Ayurvedic. They have launched their new store on WORKSsitebuilder ------------------------------------------------------------------- This email was obviously intended for the people nnotremed in the message. It may be confidential and/or legally privileged. If you have received it by mistake, please take no action based on it, copy it, or show it to anyone - just delete it and let us know about the error. Also, we should point out that any opinions expressed are not necessarily those of eShopworks. Unfortunately email cannot be guaranteed to be secure or error-free and thus this email should not be construed as a solicitation for, or offer of contract. If verification is required please ask us for a hard-copy. And finally, while we've scanned this email on 3/4/2008 to make sure it is virus free to be on the safe side we recommend that you also scan it with your own antivirus software. ------------------------------------------------------------------- From ashley.moran at patchspace.co.uk Thu Apr 3 05:34:10 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 3 Apr 2008 10:34:10 +0100 Subject: [rspec-users] Advice / Turning a Usecase into a Rspec Story / Granularity ofstories In-Reply-To: <1207214104.6571.23.camel@esw023.esw.eshopworks.co.uk> References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <64B3E556-6A7C-4298-A9A9-C4BE941565F4@superinfinite.com> <1207214104.6571.23.camel@esw023.esw.eshopworks.co.uk> Message-ID: On 03/04/2008, joseph wrote: > > > Example Story (High level): > > Story: Web admin manages pages within the admin system > Scenario: Add page > Scenario: edit page. > Scenario: delete page. > > I'm unsure if this granularity is productive for a rspec story. Hi Jospeh This seems too coarse to me. The controller I'm working on now will end up with a corresponding story for each of your scenarios. My scenarios are along the lines of "User edits page with valid details", "User edits page with missing details", "User edits page and clicks cancel", "User with insufficient priveleges tries to delete page" etc. I try to make a scenario for each common or complex thing that changes the state of the system - they would never fit in one story. Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080403/be4d86bc/attachment.html From lists at ruby-forum.com Thu Apr 3 07:38:41 2008 From: lists at ruby-forum.com (Juanma Cervera) Date: Thu, 3 Apr 2008 13:38:41 +0200 Subject: [rspec-users] spec'ing validates_uniqueness_of :whatever In-Reply-To: <38602246-DB07-4A2C-8FE8-0581DA35FDDE@mattberther.com> References: <0dd0eba5dd691ba9190d0abf31407fd1@ruby-forum.com> <38602246-DB07-4A2C-8FE8-0581DA35FDDE@mattberther.com> Message-ID: Thanks to all for your answers. I also have found a plugin with matchers for active record validations, associations and even useful matchers for views. It has a matcher for validates_uniqueness_of that doesn't got to the database. The url is http://code.google.com/p/rspec-on-rails-matchers/ ?What do you think of using this plugin? Juanma Cervera. -- Posted via http://www.ruby-forum.com/. From rick.denatale at gmail.com Thu Apr 3 08:03:21 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 3 Apr 2008 08:03:21 -0400 Subject: [rspec-users] newb q: Can story steps report a view rendering error? In-Reply-To: References: Message-ID: On Wed, Apr 2, 2008 at 7:09 PM, Tim Haines wrote: > Hi'ya > > I have a When step that calls get game_url. It turns out that calling this > page is resulting in a render error, which explains my failing Then steps. > It would help me if the story told me there was a problem rendering the > response. Is there any way to get the story steps to automatically raise an > error if such a problem occurs? > > For now I can add response.code.should == "200" or something similar.. I can't help but think that this level would more properly be covered by having good controller and view specs in addition to stories. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From rick.denatale at gmail.com Thu Apr 3 08:12:57 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 3 Apr 2008 08:12:57 -0400 Subject: [rspec-users] Advice / Turning a Usecase into a Rspec Story / Granularity ofstories In-Reply-To: References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <64B3E556-6A7C-4298-A9A9-C4BE941565F4@superinfinite.com> <1207214104.6571.23.camel@esw023.esw.eshopworks.co.uk> Message-ID: On Thu, Apr 3, 2008 at 5:34 AM, Ashley Moran wrote: > On 03/04/2008, joseph wrote: > > > > > Example Story (High level): > > > > Story: Web admin manages pages within the admin system > > Scenario: Add page > > Scenario: edit page. > > Scenario: delete page. > This seems too coarse to me. The controller I'm working on now will end up > with a corresponding story for each of your scenarios. My scenarios are > along the lines of "User edits page with valid details", "User edits page > with missing details", "User edits page and clicks cancel", "User with > insufficient priveleges tries to delete page" etc. I try to make a scenario > for each common or complex thing that changes the state of the system - they > would never fit in one story. On the other hand. Keeping these finer grained scenarios within a single story allows branching using GivenScenario which only works with scenarios within the same story. Story: Web admin manages pages within the admin system Scenario: Add page Scenario: edit page with valid details GivenScenario: Add page Scenario: edit page with missing details GivenScenario: Add page Scenario: user with sufficient privileges deletes page GivenScenario: Add page Scenario: user with insufficient privileges deletes page GivenScenario: Add page -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From loop at superinfinite.com Thu Apr 3 08:25:22 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Thu, 3 Apr 2008 14:25:22 +0200 Subject: [rspec-users] Advice / Turning a Usecase into a Rspec Story / Granularity ofstories In-Reply-To: References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <64B3E556-6A7C-4298-A9A9-C4BE941565F4@superinfinite.com> <1207214104.6571.23.camel@esw023.esw.eshopworks.co.uk> Message-ID: <10B4C604-ACB3-4E30-8DA1-20246DFDD135@superinfinite.com> On 3-apr-2008, at 14:12, Rick DeNatale wrote: > On Thu, Apr 3, 2008 at 5:34 AM, Ashley Moran > wrote: >> On 03/04/2008, joseph wrote: >> >>> >>> Example Story (High level): >>> >>> Story: Web admin manages pages within the admin system >>> Scenario: Add page >>> Scenario: edit page. >>> Scenario: delete page. > >> This seems too coarse to me. The controller I'm working on now >> will end up >> with a corresponding story for each of your scenarios. My >> scenarios are >> along the lines of "User edits page with valid details", "User >> edits page >> with missing details", "User edits page and clicks cancel", "User >> with >> insufficient priveleges tries to delete page" etc. I try to make >> a scenario >> for each common or complex thing that changes the state of the >> system - they >> would never fit in one story. > > On the other hand. Keeping these finer grained scenarios within a > single story allows branching using GivenScenario which only works > with scenarios within the same story. I am having the same struggles with the granularity. Is there a good "sample" app out there on the interweb? Or perhaps someone from the list wants to share their story? :) gr, bartz From dchelimsky at gmail.com Thu Apr 3 08:31:54 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 3 Apr 2008 08:31:54 -0400 Subject: [rspec-users] Advice / Turning a Usecase into a Rspec Story / Granularity ofstories In-Reply-To: <10B4C604-ACB3-4E30-8DA1-20246DFDD135@superinfinite.com> References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <64B3E556-6A7C-4298-A9A9-C4BE941565F4@superinfinite.com> <1207214104.6571.23.camel@esw023.esw.eshopworks.co.uk> <10B4C604-ACB3-4E30-8DA1-20246DFDD135@superinfinite.com> Message-ID: <57c63afe0804030531i49dcc4es58a2277128872aed@mail.gmail.com> On Thu, Apr 3, 2008 at 8:25 AM, Bart Zonneveld wrote: > > > On 3-apr-2008, at 14:12, Rick DeNatale wrote: > > On Thu, Apr 3, 2008 at 5:34 AM, Ashley Moran > > wrote: > >> On 03/04/2008, joseph wrote: > >> > >>> > >>> Example Story (High level): > >>> > >>> Story: Web admin manages pages within the admin system > >>> Scenario: Add page > >>> Scenario: edit page. > >>> Scenario: delete page. > > > >> This seems too coarse to me. The controller I'm working on now > >> will end up > >> with a corresponding story for each of your scenarios. My > >> scenarios are > >> along the lines of "User edits page with valid details", "User > >> edits page > >> with missing details", "User edits page and clicks cancel", "User > >> with > >> insufficient priveleges tries to delete page" etc. I try to make > >> a scenario > >> for each common or complex thing that changes the state of the > >> system - they > >> would never fit in one story. > > > > On the other hand. Keeping these finer grained scenarios within a > > single story allows branching using GivenScenario which only works > > with scenarios within the same story. > > I am having the same struggles with the granularity. Is there a good > "sample" app out there on the interweb? > Or perhaps someone from the list wants to share their story? :) I addressed this in my talk at ETEC last week. Slides are here: http://www.chariotsolutions.com/slides/pdfs/ete2008-IntegrationTestingWithRSpec.pdf Cheers, David From mark.ryall at gmail.com Thu Apr 3 08:48:19 2008 From: mark.ryall at gmail.com (Mark Ryall) Date: Thu, 3 Apr 2008 23:48:19 +1100 Subject: [rspec-users] tags/categories for specs Message-ID: <43769a4a0804030548v22f67c5fs69a5c3437c705a3f@mail.gmail.com> Many thanks to David Chelimsky for answering my question about :type & :behaviour_type hash key: http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/4b76e2c5a1a8918d It has made me curious to know whether tagging specs is a feature anyone has requested before. The current project i'm working on has a vast number of specs - most using selenium - and consequently a very long build (cruisecontrol). We have a few of different independant streams of development, all working on the same codebase, each having an associated 'precheckin' build. We try to make sure these only take up to 10-15 mins by running a relevant subset of the specs. We'd ideally run the full build locally before every commit but we optimistically commit when the relevant precheckin build passes just so we can check in more frequently (the build server always runs the full build). There's effort going into reduing the overall build time (selenium grid and various other ideas) but this is a reasonable option right now. Currently we achieve this crudely by having a custom spec runner that loads specs according to whether the filename matches a set of inclusion regular expressions and doesn't match a set of exclusion regular expressions (each stream has a set of filters). A simpler method might have just been to put the specs in different directories but it's convenient to be able to include the same spec in more than one of these precheckin builds. It would be really cool to have just been able to write specs like this: describe 'some piece of functionality', :tags => [:ui, :search] do ... end describe 'some other piece of functionality', :tags => [:ui] do ... end and then execute only the first spec as a result of launching something like 'spec --tags search' - all of the specs can be loaded but only those that match the specified tag would be executed. Having poked around the code a little, it doesn't seem impossibly difficult to implement. Does the idea have any appeal to anyone? It doesn't seem an especially original idea so I wonder if anyone has already had a go at implementing it? Mark. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080403/b654804f/attachment.html From dchelimsky at gmail.com Thu Apr 3 08:56:17 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 3 Apr 2008 08:56:17 -0400 Subject: [rspec-users] Anyone experienced RSpec/Autotest forgetting models? In-Reply-To: References: Message-ID: <57c63afe0804030556h549c5b4t926dbe97006e5969@mail.gmail.com> On Thu, Apr 3, 2008 at 4:56 AM, Ashley Moran wrote: > Hi > > Saving a controller spec frequently gives me this error: > > 52) > LoadError in 'UsersController GET /users with basic request params should > find all the user types' > Expected /home/amoran/Documents/becta/apps/Backend/app/models/user_type.rb > to define UserType > ./spec/controllers/users_controller_spec.rb:299: > script/spec:4: > > I have to Ctrl-C autotest before it will load again. > > Anyone else seen this? Is it a known issue? This question comes up a lot. Please search at http://rspec.lighthouseapp.com for a ticket. If you don't find something, consider it "not known" and add a ticket. Thanks, David > I am on trunk r3333. > > Thanks > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Apr 3 08:58:54 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 3 Apr 2008 08:58:54 -0400 Subject: [rspec-users] newb q: Can story steps report a view rendering error? In-Reply-To: References: Message-ID: <57c63afe0804030558m5e7f9fd9u66b3ecc2a52531ca@mail.gmail.com> On Thu, Apr 3, 2008 at 8:03 AM, Rick DeNatale wrote: > On Wed, Apr 2, 2008 at 7:09 PM, Tim Haines wrote: > > > Hi'ya > > > > I have a When step that calls get game_url. It turns out that calling this > > page is resulting in a render error, which explains my failing Then steps. > > It would help me if the story told me there was a problem rendering the > > response. Is there any way to get the story steps to automatically raise an > > error if such a problem occurs? > > > > For now I can add response.code.should == "200" or something similar.. > > I can't help but think that this level would more properly be covered > by having good controller and view specs in addition to stories. I can't help agreeing with you Rick. > > -- > 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 philodespotos at gmail.com Thu Apr 3 10:58:09 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Thu, 3 Apr 2008 09:58:09 -0500 Subject: [rspec-users] Command line story runner Message-ID: <60f3810c0804030758s654af605q4cf06714a556fcf9@mail.gmail.com> Hullo all, It sucks to write wrapper .rb files just so stories/all.rb can find and run them. So I am trawling for feedback on a small project I pushed to github a day or two ago; it provides a 'story' executable that can be used to run your plain text stories from the command line, akin to the 'spec' command. It's based on Bryan Helmkamp's script/story command that he posted to this list -- http://rubyforge.org/pipermail/rspec-users/2007-December/005194.html -- and is still pretty much all his code. The project is available on github at http://github.com/pd/story and can be installed by cloning it, `rake gem`, then installing the gem in pkg/whatever.gem. I won't be pushing a gem of this to rubyforge for a while. The repository includes a brief readme detailing the features: - Options can be specified in stories/story.opts, which is automatically loaded if present (unlike spec, but I am too lazy to type -O so often) - Allows you to specify a single .story file, a directory full of them, nothing at all to run ./stories/stories/**/*.story, etc. - It works for both rails and non-rails projects, by allowing a --rails option to specify that stories should be run as a RailsStory - Step group definitions which should be accessible in every story can be listed using --global-steps - Deduces the default step groups to include by using the .story file's pathname. - Step groups to be included which could not be deduced from the story filename can be listed at the top of the file, eg: # +steps: foo, bar/baz, and a really long step group name - 'and a really long step group name' is a valid name; I prefer strings to symbols here (tho symbols will still work). This allows the story at stories/stories/foo/bar.story to include the 'foo/bar' step group, and also permits step group names such as 'data creation'. One achingly missing feature at the moment is hooking into the config options for Spec::Story::Runner, but I didn't have any immediate use for it so I didn't bother. But I will probably do so soon enough. (Also, specs =) This is very tied to the layout of my own projects, and I'd be surprised if it works out of the box for most people. Right now it does mostly everything I need, so I'm curious what would be necessary to make it a viable tool for others to use. ty Kyle From ashley.moran at patchspace.co.uk Thu Apr 3 10:59:16 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 3 Apr 2008 15:59:16 +0100 Subject: [rspec-users] Advice / Turning a Usecase into a Rspec Story / Granularity ofstories In-Reply-To: References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <64B3E556-6A7C-4298-A9A9-C4BE941565F4@superinfinite.com> <1207214104.6571.23.camel@esw023.esw.eshopworks.co.uk> Message-ID: On 03/04/2008, Rick DeNatale wrote: > > > On the other hand. Keeping these finer grained scenarios within a > single story allows branching using GivenScenario which only works > with scenarios within the same story. Hi Rick I've never used GivenScenario - is there any documentation about it available? Google only returns answers about JBehave. Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080403/d5c21e37/attachment.html From pergesu at gmail.com Thu Apr 3 12:06:27 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 3 Apr 2008 09:06:27 -0700 Subject: [rspec-users] tags/categories for specs In-Reply-To: <43769a4a0804030548v22f67c5fs69a5c3437c705a3f@mail.gmail.com> References: <43769a4a0804030548v22f67c5fs69a5c3437c705a3f@mail.gmail.com> Message-ID: <810a540e0804030906u2db786dbw59b45d0ac3909435@mail.gmail.com> On Thu, Apr 3, 2008 at 5:48 AM, Mark Ryall wrote: > Many thanks to David Chelimsky for answering my question about :type & > :behaviour_type hash key: > > http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/4b76e2c5a1a8918d > > It has made me curious to know whether tagging specs is a feature anyone has > requested before. I've heard this mentioned a couple times before. I don't think I've ever heard arguments against it...probably just that it's never itched bad enough for someone to scratch it. You should search the ticket tracking system (http://rspec.lighthouseapp.com/projects/5645-rspec/overview) for anything like that, and submit a feature request if you don't find anything. Ooh, a patch would be good too :) Pat From rick.denatale at gmail.com Thu Apr 3 14:43:29 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 3 Apr 2008 14:43:29 -0400 Subject: [rspec-users] newb q: Can story steps report a view rendering error? In-Reply-To: <57c63afe0804030558m5e7f9fd9u66b3ecc2a52531ca@mail.gmail.com> References: <57c63afe0804030558m5e7f9fd9u66b3ecc2a52531ca@mail.gmail.com> Message-ID: On Thu, Apr 3, 2008 at 8:58 AM, David Chelimsky wrote: > On Thu, Apr 3, 2008 at 8:03 AM, Rick DeNatale wrote: > > I can't help but think that this level would more properly be covered > > by having good controller and view specs in addition to stories. > > I can't help agreeing with you Rick. Great minds think alike! Or as an English friend of mine liked to say in reply. Fools fail to differ! -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From me at danielfischer.com Thu Apr 3 20:17:29 2008 From: me at danielfischer.com (Fischer, Daniel) Date: Thu, 3 Apr 2008 17:17:29 -0700 Subject: [rspec-users] Autotest RSpec Not Running on Model Save's? Message-ID: <7e565b5c0804031717l15f63d57w17c57a2cd6657817@mail.gmail.com> If I save my model while autotest is running, autotest doesn't run the model's specs, all I get in my window is /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S script/spec -O spec/spec.opts However if I go to the spec and save that, it'll automatically run that spec... it just won't do it from the model itself. If I remember correctly, autotest used to automatically map the model to the spec, didn't it? Or at least automatically run all specs everytime you save? Anyway, any help would be appreciated, thanks! -Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080403/f8fff78b/attachment.html From kamal.fariz at gmail.com Thu Apr 3 22:20:35 2008 From: kamal.fariz at gmail.com (Kamal Fariz) Date: Fri, 4 Apr 2008 10:20:35 +0800 Subject: [rspec-users] Command line story runner In-Reply-To: <60f3810c0804030758s654af605q4cf06714a556fcf9@mail.gmail.com> References: <60f3810c0804030758s654af605q4cf06714a556fcf9@mail.gmail.com> Message-ID: <63FD493A-2D1D-4EE8-B67B-E7209B6773D3@gmail.com> > It sucks to write wrapper .rb files just so stories/all.rb can find > and run them. Very nice. I was considering moving over to the Rubyesque stories so that I don't have to have .story files around and the wrapper like you mentioned. The wrapper is the story. http://continuousthinking.com/2008/3/5/trying-rspec-s-rubyesque-stories I'm gonna give this a try. Regards, kamal From phlip2005 at gmail.com Fri Apr 4 00:19:48 2008 From: phlip2005 at gmail.com (Phlip) Date: Thu, 03 Apr 2008 21:19:48 -0700 Subject: [rspec-users] [ANN] rspec_hpricot_matchers 1.0: have_tag on hpricot In-Reply-To: <6bdacb70804020718v6cdba515qf209a0439eaf0d4b@mail.gmail.com> References: <60f3810c0803261208p4b3ea029xbeccec4f8fe5a52@mail.gmail.com> <6bdacb70804020718v6cdba515qf209a0439eaf0d4b@mail.gmail.com> Message-ID: Corey Haines wrote: > 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. I bet it can easily do something like this (if you rspeckers will excuse the dreaded word "assert"!): def assert_all_embedded_images assert_any_xpath :img do |img| assert_public_image_file img[:src] false # :keep looping! end end def test_find_all_embedded_images get :some_action # a Rails functional test assert_all_embedded_images end def assert_public_image_file(src, line = nil) src.sub!(/^\//, '') # RailsRoot = Pathname.new(RAILS_ROOT) image_file = RailsRoot + 'public' + src # this file must be where the server and browser can see it assert_file(line){ image_file } end Those assertions scan every image in a page and ensure a file with the correct name appears in ./public/images/. (Our artists have recently been sending us new assets, and I didn't feel like manually checking we copied in all the right images...) The :img is a shortcut for the XPathic 'descendent-or-self::img', and the img[:src] is naturally a shortcut for the attribute. Those assertions - assert_xpath, assert_any_xpath, etc - work interchangeably with REXML, Hpricot, or Libxml for their parser. You just pick the one you want by adding to your setup() a call like invoke_rexml, invoke_hpricot, or invoke_libxml. Each provides various trades-off, but at work we have fixated on Libxml, naturally, because we use hundreds of these assertions, so we need its speed. Also, Libxml strictly enforces the Transitional XHTML type that appears in all our DOCTYPEs. (gem install assert_xpath, but I haven't documented the libxml variant yet...) My little trick with the image files is only the start of assert_xpath's abilities. You can also call it from inside an rspec; you just have to include its modules. And, like any of my assertions, it provides a detailed, comprehensive diagnostic if it fails. -- Phlip From court3nay at gmail.com Fri Apr 4 01:03:16 2008 From: court3nay at gmail.com (Courtenay) Date: Thu, 3 Apr 2008 22:03:16 -0700 Subject: [rspec-users] spec'ing validates_uniqueness_of :whatever In-Reply-To: References: <0dd0eba5dd691ba9190d0abf31407fd1@ruby-forum.com> <38602246-DB07-4A2C-8FE8-0581DA35FDDE@mattberther.com> Message-ID: <4b430c8f0804032203r3daecdb7n59179063e5c2610e@mail.gmail.com> On Thu, Apr 3, 2008 at 4:38 AM, Juanma Cervera wrote: > Thanks to all for your answers. > I also have found a plugin with matchers for active record validations, > associations and even useful matchers for views. > > It has a matcher for validates_uniqueness_of that doesn't got to the > database. > The test asserts that you call validates_uniqueness_of, but it doesn't actually test your logic. So it's useful to see if someone accidentally deletes your code, but if you have validates_uniqueness_of :user, :scope => :project_id or something more complex, it won't test this behavior. From steven at stevenrbaker.com Fri Apr 4 01:41:23 2008 From: steven at stevenrbaker.com (Steven Baker) Date: Fri, 4 Apr 2008 01:41:23 -0400 Subject: [rspec-users] spec'ing validates_uniqueness_of :whatever In-Reply-To: <4b430c8f0804032203r3daecdb7n59179063e5c2610e@mail.gmail.com> References: <0dd0eba5dd691ba9190d0abf31407fd1@ruby-forum.com> <38602246-DB07-4A2C-8FE8-0581DA35FDDE@mattberther.com> <4b430c8f0804032203r3daecdb7n59179063e5c2610e@mail.gmail.com> Message-ID: >> > The test asserts that you call validates_uniqueness_of, but it doesn't > actually test your logic. > So it's useful to see if someone accidentally deletes your code, but > if you have > > validates_uniqueness_of :user, :scope => :project_id > > or something more complex, it won't test this behavior. One of the rules that I learned with TDD, that I brought with me to BDD, is that you only specify or test what you write. Everything else is assumed to behave as intended. This rule is, among other things, intended to keep us productive: we can't write a test suite for an entire framework every time we use that framework to implement an application. At some point, we have to trust that the frameworky bits work as intended. I don't exactly assume that the code I'm depending on is well tested, just that it's not my job to specify its behaviour. If you were to write an example that creates two models, and ensures that the duplicate errored appropriately, my "rule" is violated. Each of your examples is then specifying the behaviour of the validates_uniqueness_of method, which you didn't write. Doing this with mocks ensures that you called validates_uniqueness_of, and doesn't test the behaviour of the method which, since you didn't write it, get to assume behaves as expected. This is where my "rule" falls down: mocking the call prevents you from changing the implementation without changing the behaviour. That is to say that you may want to, in the future, roll your own uniqueness validation that is called in a different way than ActiveRecord's, but behaves in the same way. If you mocked, you could change the implementation without changing the behaviour, and still have a failing example. This is where the line is drawn for me: I need to be able to change the implementation, and only have my examples fail when I've changed the behaviour. So, in this case, using mocks and expecting Rails' built-in validation is fragile. But in general, I try to stick to the "rule" (let's say guideline from now on) that I outlined above. -Steven From pergesu at gmail.com Fri Apr 4 02:02:57 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 3 Apr 2008 23:02:57 -0700 Subject: [rspec-users] spec'ing validates_uniqueness_of :whatever In-Reply-To: References: <0dd0eba5dd691ba9190d0abf31407fd1@ruby-forum.com> <38602246-DB07-4A2C-8FE8-0581DA35FDDE@mattberther.com> <4b430c8f0804032203r3daecdb7n59179063e5c2610e@mail.gmail.com> Message-ID: <810a540e0804032302x2a266689n2a23d25685011eb7@mail.gmail.com> On Thu, Apr 3, 2008 at 10:41 PM, Steven Baker wrote: > If you were to write an example that creates two models, and ensures > that the duplicate errored appropriately, my "rule" is violated. Each > of your examples is then specifying the behaviour of the > validates_uniqueness_of method, which you didn't write. I don't really agree with this. The desired behavior is to disallow two records with the same data. v_u_o is simply a quick and easy means to that end. Pat From steven at stevenrbaker.com Fri Apr 4 02:12:47 2008 From: steven at stevenrbaker.com (Steven Baker) Date: Fri, 4 Apr 2008 02:12:47 -0400 Subject: [rspec-users] spec'ing validates_uniqueness_of :whatever In-Reply-To: <810a540e0804032302x2a266689n2a23d25685011eb7@mail.gmail.com> References: <0dd0eba5dd691ba9190d0abf31407fd1@ruby-forum.com> <38602246-DB07-4A2C-8FE8-0581DA35FDDE@mattberther.com> <4b430c8f0804032203r3daecdb7n59179063e5c2610e@mail.gmail.com> <810a540e0804032302x2a266689n2a23d25685011eb7@mail.gmail.com> Message-ID: <18B17D42-B151-4169-86EF-7A7F3597E923@stevenrbaker.com> >> If you were to write an example that creates two models, and ensures >> that the duplicate errored appropriately, my "rule" is violated. >> Each >> of your examples is then specifying the behaviour of the >> validates_uniqueness_of method, which you didn't write. > > I don't really agree with this. The desired behavior is to disallow > two records with the same data. v_u_o is simply a quick and easy > means to that end. Right. As I said (or intended to) that particular example was so simple that it was a grey area. But it did cause me to think about the problem, and I found it interesting. -Steven From rick.denatale at gmail.com Fri Apr 4 07:31:51 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 4 Apr 2008 07:31:51 -0400 Subject: [rspec-users] spec'ing validates_uniqueness_of :whatever In-Reply-To: <18B17D42-B151-4169-86EF-7A7F3597E923@stevenrbaker.com> References: <0dd0eba5dd691ba9190d0abf31407fd1@ruby-forum.com> <38602246-DB07-4A2C-8FE8-0581DA35FDDE@mattberther.com> <4b430c8f0804032203r3daecdb7n59179063e5c2610e@mail.gmail.com> <810a540e0804032302x2a266689n2a23d25685011eb7@mail.gmail.com> <18B17D42-B151-4169-86EF-7A7F3597E923@stevenrbaker.com> Message-ID: On Fri, Apr 4, 2008 at 2:12 AM, Steven Baker wrote: > >> If you were to write an example that creates two models, and ensures > >> that the duplicate errored appropriately, my "rule" is violated. > >> Each > >> of your examples is then specifying the behaviour of the > >> validates_uniqueness_of method, which you didn't write. > > > > I don't really agree with this. The desired behavior is to disallow > > two records with the same data. v_u_o is simply a quick and easy > > means to that end. > > Right. As I said (or intended to) that particular example was so > simple that it was a grey area. But it did cause me to think about > the problem, and I found it interesting. While I certainly subscribe to the "don't test what you didn't write" philosophy for the most part. I do think that there are gray areas. Quoting Steven from a bit earlier in this thread: > I don't exactly assume that the code I'm depending on is well tested, > just that it's not my job to specify its behavior. One of the gray areas is that despite all good intentions, sometimes the specification of that behavior isn't entirely clear, even if that specification is written down somewhere as specs, or traditional documentation. Problems can creep in when my understanding doesn't exactly match the writer's intent. In these cases, it seems to me that writing a spec which proves that my interpretation of an interface by specifying the results rather than just the presence of the call, just MIGHT be a reasonable thing to do, and might protect against the possibility that the writer's interpretation changes due either to evolution or a 'bug-fix.' -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From kamal.fariz at gmail.com Fri Apr 4 08:02:32 2008 From: kamal.fariz at gmail.com (Kamal Fariz) Date: Fri, 4 Apr 2008 20:02:32 +0800 Subject: [rspec-users] Command line story runner In-Reply-To: <63FD493A-2D1D-4EE8-B67B-E7209B6773D3@gmail.com> References: <60f3810c0804030758s654af605q4cf06714a556fcf9@mail.gmail.com> <63FD493A-2D1D-4EE8-B67B-E7209B6773D3@gmail.com> Message-ID: <0361EA29-6DD7-415A-8671-F5AE89A12432@gmail.com> Hi Kyle, I tried the story runner against a story. Unfortunately, it had problems executing webrat methods like 'visits'. Kindly check out this pastie: http://pastie.org/175204 I tried running it with the normal ruby wrapper and it works fine. Regards, Kamal From dchelimsky at gmail.com Fri Apr 4 09:23:01 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 4 Apr 2008 09:23:01 -0400 Subject: [rspec-users] Welcome Pat Maddox Message-ID: <57c63afe0804040623k6fb1fe02v3eca214773424bf4@mail.gmail.com> Hi all, I'm pleased to announce that Pat Maddox is joining the RSpec Development Team. As you may already know, Pat has been contributing great patches and participation on the rspec-users and rspec-devel mailing lists for quite some time. He has demonstrated a deep understanding of BDD in general, and specifically as it applies to Rails, which has certainly posed some of the more interesting questions on our mailing lists. We are all excited to have Pat on board and look forward to his continued contribution. Cheers, David From bryansray at gmail.com Fri Apr 4 10:30:55 2008 From: bryansray at gmail.com (Bryan Ray) Date: Fri, 4 Apr 2008 09:30:55 -0500 Subject: [rspec-users] [rspec-devel] Welcome Pat Maddox In-Reply-To: <57c63afe0804040623k6fb1fe02v3eca214773424bf4@mail.gmail.com> References: <57c63afe0804040623k6fb1fe02v3eca214773424bf4@mail.gmail.com> Message-ID: <29a0119e0804040730o54af6663m4466a85ad7d3bb0d@mail.gmail.com> Congratulations, man. On Fri, Apr 4, 2008 at 8:23 AM, David Chelimsky wrote: > Hi all, > > I'm pleased to announce that Pat Maddox is joining the RSpec Development > Team. > > As you may already know, Pat has been contributing great patches and > participation on the rspec-users and rspec-devel mailing lists for > quite some time. He has demonstrated a deep understanding of BDD in > general, and specifically as it applies to Rails, which has certainly > posed some of the more interesting questions on our mailing lists. > > We are all excited to have Pat on board and look forward to his > continued contribution. > > Cheers, > David > _______________________________________________ > rspec-devel mailing list > rspec-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-devel > -- 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/20080404/823e2219/attachment.html From infernalsirius at gmail.com Fri Apr 4 10:35:50 2008 From: infernalsirius at gmail.com (Patrick Meunier) Date: Fri, 4 Apr 2008 10:35:50 -0400 Subject: [rspec-users] Welcome Pat Maddox In-Reply-To: <57c63afe0804040623k6fb1fe02v3eca214773424bf4@mail.gmail.com> References: <57c63afe0804040623k6fb1fe02v3eca214773424bf4@mail.gmail.com> Message-ID: This is a great news! Congratulations Pat. On 4-Apr-08, at 9:23 AM, David Chelimsky wrote: > Hi all, > > I'm pleased to announce that Pat Maddox is joining the RSpec > Development Team. > > As you may already know, Pat has been contributing great patches and > participation on the rspec-users and rspec-devel mailing lists for > quite some time. He has demonstrated a deep understanding of BDD in > general, and specifically as it applies to Rails, which has certainly > posed some of the more interesting questions on our mailing lists. > > We are all excited to have Pat on board and look forward to his > continued contribution. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From luislavena at gmail.com Fri Apr 4 10:50:54 2008 From: luislavena at gmail.com (Luis Lavena) Date: Fri, 4 Apr 2008 11:50:54 -0300 Subject: [rspec-users] Welcome Pat Maddox In-Reply-To: References: <57c63afe0804040623k6fb1fe02v3eca214773424bf4@mail.gmail.com> Message-ID: <71166b3b0804040750j54cec670v8e4b5065df725268@mail.gmail.com> On Fri, Apr 4, 2008 at 11:35 AM, Patrick Meunier wrote: > This is a great news! Congratulations Pat. > +1 on that, The bdd-force within Pat is strong, and is good to see he is joining the good side of the force :-) -- 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 aslak.hellesoy at gmail.com Fri Apr 4 13:26:44 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 4 Apr 2008 19:26:44 +0200 Subject: [rspec-users] Welcome Pat Maddox In-Reply-To: <71166b3b0804040750j54cec670v8e4b5065df725268@mail.gmail.com> References: <57c63afe0804040623k6fb1fe02v3eca214773424bf4@mail.gmail.com> <71166b3b0804040750j54cec670v8e4b5065df725268@mail.gmail.com> Message-ID: <8d961d900804041026o273c30b2qc194a26a4981427f@mail.gmail.com> On 4/4/08, Luis Lavena wrote: > On Fri, Apr 4, 2008 at 11:35 AM, Patrick Meunier > wrote: > > This is a great news! Congratulations Pat. > > > > +1 on that, The bdd-force within Pat is strong, and is good to see he > is joining the good side of the force :-) > Pat is a much needed and welcome member to the core team. I expect we'll see a lot of great contribs from him in the time to come. Welcome onboard, Pat! Aslak > -- > 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 > From pergesu at gmail.com Fri Apr 4 14:34:53 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 4 Apr 2008 11:34:53 -0700 Subject: [rspec-users] Welcome Pat Maddox In-Reply-To: <8d961d900804041026o273c30b2qc194a26a4981427f@mail.gmail.com> References: <57c63afe0804040623k6fb1fe02v3eca214773424bf4@mail.gmail.com> <71166b3b0804040750j54cec670v8e4b5065df725268@mail.gmail.com> <8d961d900804041026o273c30b2qc194a26a4981427f@mail.gmail.com> Message-ID: <810a540e0804041134x11df6594m891b48817cdd56a7@mail.gmail.com> On Fri, Apr 4, 2008 at 10:26 AM, aslak hellesoy wrote: > On 4/4/08, Luis Lavena wrote: > > On Fri, Apr 4, 2008 at 11:35 AM, Patrick Meunier > > wrote: > > > This is a great news! Congratulations Pat. > > > > > > > +1 on that, The bdd-force within Pat is strong, and is good to see he > > is joining the good side of the force :-) > > > > Pat is a much needed and welcome member to the core team. I expect > we'll see a lot of great contribs from him in the time to come. > > Welcome onboard, Pat! Thank you for the kind words, everyone. Pat From brian.takita at gmail.com Fri Apr 4 14:42:53 2008 From: brian.takita at gmail.com (Brian Takita) Date: Fri, 4 Apr 2008 11:42:53 -0700 Subject: [rspec-users] Welcome Pat Maddox In-Reply-To: <8d961d900804041026o273c30b2qc194a26a4981427f@mail.gmail.com> References: <57c63afe0804040623k6fb1fe02v3eca214773424bf4@mail.gmail.com> <71166b3b0804040750j54cec670v8e4b5065df725268@mail.gmail.com> <8d961d900804041026o273c30b2qc194a26a4981427f@mail.gmail.com> Message-ID: <1d7ddd110804041142s1314d081t37090d98f95d85c2@mail.gmail.com> On Fri, Apr 4, 2008 at 10:26 AM, aslak hellesoy wrote: > On 4/4/08, Luis Lavena wrote: > > On Fri, Apr 4, 2008 at 11:35 AM, Patrick Meunier > > wrote: > > > This is a great news! Congratulations Pat. > > > > > > > +1 on that, The bdd-force within Pat is strong, and is good to see he > > is joining the good side of the force :-) > > > > Pat is a much needed and welcome member to the core team. I expect > we'll see a lot of great contribs from him in the time to come. > > Welcome onboard, Pat! Welcome Pat. > > Aslak > > > -- > > > > 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 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From omen.king at gmail.com Fri Apr 4 14:52:38 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Fri, 4 Apr 2008 14:52:38 -0400 Subject: [rspec-users] Welcome Pat Maddox In-Reply-To: <1d7ddd110804041142s1314d081t37090d98f95d85c2@mail.gmail.com> References: <57c63afe0804040623k6fb1fe02v3eca214773424bf4@mail.gmail.com> <71166b3b0804040750j54cec670v8e4b5065df725268@mail.gmail.com> <8d961d900804041026o273c30b2qc194a26a4981427f@mail.gmail.com> <1d7ddd110804041142s1314d081t37090d98f95d85c2@mail.gmail.com> Message-ID: Gooble Goble, Gooble Goble, One of Us! One of Us! On Fri, Apr 4, 2008 at 2:42 PM, Brian Takita wrote: > On Fri, Apr 4, 2008 at 10:26 AM, aslak hellesoy > wrote: > > On 4/4/08, Luis Lavena wrote: > > > On Fri, Apr 4, 2008 at 11:35 AM, Patrick Meunier > > > wrote: > > > > This is a great news! Congratulations Pat. > > > > > > > > > > +1 on that, The bdd-force within Pat is strong, and is good to see he > > > is joining the good side of the force :-) > > > > > > > Pat is a much needed and welcome member to the core team. I expect > > we'll see a lot of great contribs from him in the time to come. > > > > Welcome onboard, Pat! > Welcome Pat. > > > > Aslak > > > > > -- > > > > > > > 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 > > > > > _______________________________________________ > > 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/20080404/b4474a07/attachment-0001.html From joe at pinkpucker.net Fri Apr 4 18:18:02 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Fri, 4 Apr 2008 15:18:02 -0700 Subject: [rspec-users] webrat bugs Message-ID: Where do I report webrat bugs? Seems that when there's a parenthesis in the link text, doing: session.clicks_link("link with (parens)") fails to find the link text. From joe at pinkpucker.net Fri Apr 4 18:21:53 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Fri, 4 Apr 2008 15:21:53 -0700 Subject: [rspec-users] Command line story runner In-Reply-To: <60f3810c0804030758s654af605q4cf06714a556fcf9@mail.gmail.com> References: <60f3810c0804030758s654af605q4cf06714a556fcf9@mail.gmail.com> Message-ID: On Thu, Apr 3, 2008 at 7:58 AM, Kyle Hargraves wrote: > Hullo all, > > It sucks to write wrapper .rb files just so stories/all.rb can find > and run them. Here's what my stories/all.rb looks like: require File.dirname(__FILE__) + '/helper' Dir[File.dirname(__FILE__) + '/../steps/*.rb'].each { |f| require f } with_steps_for(:general, :sessions, :blogs, :game_moderation, :user_completed_games, :searching, :puzzles, :user_media) do run_local_story "blog_story" run_local_story "user_completed_games_story" run_local_story "searching_story" run_local_story "puzzle_story" run_local_story "picathon_uploads_story" #run_local_story "game_moderation_story" end Last one is commented out, since I just added a bunch of ajaxy stuff to the pages and haven't converted the stories over to ajax yet (if that's possible). Each one of the steps corresponds to a controller step file that's in /steps. Works pretty well, not much of a hassle running stories. This is for http://tanga.com. Joe From timcharper at gmail.com Fri Apr 4 18:48:53 2008 From: timcharper at gmail.com (Tim Harper) Date: Fri, 4 Apr 2008 16:48:53 -0600 Subject: [rspec-users] changes to RSpec Bundle Message-ID: <19527F20-C4E2-4B9D-888E-2CC8980F26B2@gmail.com> Hi, I forked the rspec bundle on github and added a new command to it (an Update RSpec Bundle command). I sent a pull request, but haven't heard back from anyone on it. David, did you get my pull request? Or did it get lost in the black whole of cyberspace? (if you were too busy to respond, that's fine, just wanted to follow up) Thanks, Tim From joe at pinkpucker.net Fri Apr 4 19:10:59 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Fri, 4 Apr 2008 16:10:59 -0700 Subject: [rspec-users] Attachment-fu + Story Runner In-Reply-To: <57c63afe0803210546q314323b4g63d5029a71d64291@mail.gmail.com> References: <14291797.post@talk.nabble.com> <57c63afe0712120554j147ffbe6lcff9faf8d5af743f@mail.gmail.com> <57c63afe0803210546q314323b4g63d5029a71d64291@mail.gmail.com> Message-ID: On Fri, Mar 21, 2008 at 5:46 AM, David Chelimsky wrote: > > 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. Because I can't upgrade to edge rails. And I want to be able to test file uploads. I've applied the 8978 changeset to my stable rails -- but I'm still unsure of how to test file uploads in the context of a rspec story. Normally, I'd use fixture_file_upload, but that method doesn't seem to be available in rspec. Do I need to do anything special? Is anyone testing file uploads with rspec stories? From ben at benmabey.com Fri Apr 4 19:21:39 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 04 Apr 2008 17:21:39 -0600 Subject: [rspec-users] webrat bugs In-Reply-To: References: Message-ID: <47F6B803.1090009@benmabey.com> Joe Van Dyk wrote: > Where do I report webrat bugs? > > Seems that when there's a parenthesis in the link text, doing: > > session.clicks_link("link with (parens)") > > fails to find the link text. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Hey, Brian relasesed webrat: http://www.brynary.com/2007/12/8/webrat-0-1-0-released But AFAIK there is no project page for it.... I would suggest this: Fix the issue and send him the patch. OR Clone it on github: http://github.com/brynary/webrat/tree/master fork the repo, fix it, and make a pull request on github Chances are the problem will get fixed a lot sooner that way. :) -Ben From joe at pinkpucker.net Fri Apr 4 19:33:58 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Fri, 4 Apr 2008 16:33:58 -0700 Subject: [rspec-users] Attachment-fu + Story Runner In-Reply-To: References: <14291797.post@talk.nabble.com> <57c63afe0712120554j147ffbe6lcff9faf8d5af743f@mail.gmail.com> <57c63afe0803210546q314323b4g63d5029a71d64291@mail.gmail.com> Message-ID: On Fri, Apr 4, 2008 at 4:10 PM, Joe Van Dyk wrote: > On Fri, Mar 21, 2008 at 5:46 AM, David Chelimsky wrote: > > > > 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. > > Because I can't upgrade to edge rails. And I want to be able to test > file uploads. > > I've applied the 8978 changeset to my stable rails -- but I'm still > unsure of how to test file uploads in the context of a rspec story. > Normally, I'd use fixture_file_upload, but that method doesn't seem to > be available in rspec. Do I need to do anything special? > > Is anyone testing file uploads with rspec stories? Think I got it working, here's an example step: When("$username uploads a picathon image") do |username| params = { :media => ActionController::TestUploadedFile.new(RAILS_ROOT + '/test/fixtures/files/image.jpg') } @sessions[username].post user_uploads_path(@users[username]), params @sessions[username].visits user_uploads_path(@users[username]) end From pergesu at gmail.com Fri Apr 4 19:48:08 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 4 Apr 2008 16:48:08 -0700 Subject: [rspec-users] changes to RSpec Bundle In-Reply-To: <19527F20-C4E2-4B9D-888E-2CC8980F26B2@gmail.com> References: <19527F20-C4E2-4B9D-888E-2CC8980F26B2@gmail.com> Message-ID: <810a540e0804041648w8b578aesa0f0a9aea3724aa9@mail.gmail.com> On Fri, Apr 4, 2008 at 3:48 PM, Tim Harper wrote: > Hi, > > I forked the rspec bundle on github and added a new command to it (an > Update RSpec Bundle command). I sent a pull request, but haven't > heard back from anyone on it. > > David, did you get my pull request? Or did it get lost in the black > whole of cyberspace? (if you were too busy to respond, that's fine, > just wanted to follow up) > > Thanks, > Tim > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I think the preferred method is to file a ticket on lighthouse with a link to the relevant commit. Pat From ben at benmabey.com Fri Apr 4 19:54:40 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 04 Apr 2008 17:54:40 -0600 Subject: [rspec-users] changes to RSpec Bundle In-Reply-To: <19527F20-C4E2-4B9D-888E-2CC8980F26B2@gmail.com> References: <19527F20-C4E2-4B9D-888E-2CC8980F26B2@gmail.com> Message-ID: <47F6BFC0.6090405@benmabey.com> Tim Harper wrote: > Hi, > > I forked the rspec bundle on github and added a new command to it (an > Update RSpec Bundle command). I sent a pull request, but haven't > heard back from anyone on it. > > David, did you get my pull request? Or did it get lost in the black > whole of cyberspace? (if you were too busy to respond, that's fine, > just wanted to follow up) > > Thanks, > Tim > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Hey Tim, I just asked about the use of pull request vs patches on the dev list. According to David things should still be added to the project tracker: http://rspec.lighthouseapp.com/ So you can either upload a patch there or just give the commit link on github he could pull from. Either way they want to keep track of this stuff on lighthouse I think. Also, there was some talk of moving the bundle in a separate bundle and using git modules... I don't think that has happened yet though... -Ben From pergesu at gmail.com Fri Apr 4 20:05:53 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 4 Apr 2008 17:05:53 -0700 Subject: [rspec-users] changes to RSpec Bundle In-Reply-To: <47F6BFC0.6090405@benmabey.com> References: <19527F20-C4E2-4B9D-888E-2CC8980F26B2@gmail.com> <47F6BFC0.6090405@benmabey.com> Message-ID: <810a540e0804041705j7c834dcbh2323b31657716687@mail.gmail.com> On Fri, Apr 4, 2008 at 4:54 PM, Ben Mabey wrote: > > Tim Harper wrote: > > Hi, > > > > I forked the rspec bundle on github and added a new command to it (an > > Update RSpec Bundle command). I sent a pull request, but haven't > > heard back from anyone on it. > > > > David, did you get my pull request? Or did it get lost in the black > > whole of cyberspace? (if you were too busy to respond, that's fine, > > just wanted to follow up) > > > > Thanks, > > Tim > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > Hey Tim, > I just asked about the use of pull request vs patches on the dev list. > According to David things should still be added to the project tracker: > http://rspec.lighthouseapp.com/ > > So you can either upload a patch there or just give the commit link on > github he could pull from. Either way they want to keep track of this > stuff on lighthouse I think. Ideal way is to give a commit link. > Also, there was some talk of moving the bundle in a separate bundle and > using git modules... I don't think that has happened yet though... David actually made all these changes last night. If you go to http://github.com/dchelimsky you can see all the repositories. To get the latest and greatest version of the code, do git clone git://github.com/dchelimsky/rspec-dev.git cd rspec-dev git submodule init git submodule update And you're all set. So Tim, you should check out the latest code (or perhaps just the TM bundle, if you want), create your patch, and then submit a ticket on lighthouse with a link to the commit. Pat From philodespotos at gmail.com Fri Apr 4 21:19:20 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Fri, 4 Apr 2008 20:19:20 -0500 Subject: [rspec-users] Command line story runner In-Reply-To: References: <60f3810c0804030758s654af605q4cf06714a556fcf9@mail.gmail.com> Message-ID: <60f3810c0804041819v47293792qf4c0935f736f6ae7@mail.gmail.com> On Fri, Apr 4, 2008 at 5:21 PM, Joe Van Dyk wrote: > On Thu, Apr 3, 2008 at 7:58 AM, Kyle Hargraves wrote: > > Hullo all, > > > > It sucks to write wrapper .rb files just so stories/all.rb can find > > and run them. > > Here's what my stories/all.rb looks like: > > require File.dirname(__FILE__) + '/helper' > Dir[File.dirname(__FILE__) + '/../steps/*.rb'].each { |f| require f } > > with_steps_for(:general, :sessions, :blogs, :game_moderation, > :user_completed_games, :searching, :puzzles, :user_media) do > run_local_story "blog_story" > run_local_story "user_completed_games_story" > run_local_story "searching_story" > run_local_story "puzzle_story" > run_local_story "picathon_uploads_story" > #run_local_story "game_moderation_story" > end > > Last one is commented out, since I just added a bunch of ajaxy stuff > to the pages and haven't converted the stories over to ajax yet (if > that's possible). > > Each one of the steps corresponds to a controller step file that's in > /steps. Works pretty well, not much of a hassle running stories. > This is for http://tanga.com. > > Joe This works for a while, and it's what I started with. But it didn't scale in my experience. Firstly, I started using the same wording for steps, but they had different meanings by context; you can no longer just include everything, or you can end up running the wrong step. Moreover, one of my current suites has about 180 scenarios, which takes a minute and a half or so to run all the way through. When I'm working on a single feature, I don't want to run 90% of the scenarios, just one or two of the stories surrounding that feature. all.rb makes that impossible, AFAIK. So you start writing individual .rb files you can run separately, which all.rb just sources. I ended up spending a lot of time managing the infrastructure instead of getting work done. brynary's script/story relieved that headache for me. BTW, what is run_local_story? k From philodespotos at gmail.com Fri Apr 4 21:22:52 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Fri, 4 Apr 2008 20:22:52 -0500 Subject: [rspec-users] Command line story runner In-Reply-To: <0361EA29-6DD7-415A-8671-F5AE89A12432@gmail.com> References: <60f3810c0804030758s654af605q4cf06714a556fcf9@mail.gmail.com> <63FD493A-2D1D-4EE8-B67B-E7209B6773D3@gmail.com> <0361EA29-6DD7-415A-8671-F5AE89A12432@gmail.com> Message-ID: <60f3810c0804041822q4a9ba1acu52a4371c6253d051@mail.gmail.com> On Fri, Apr 4, 2008 at 7:02 AM, Kamal Fariz wrote: > Hi Kyle, > > I tried the story runner against a story. Unfortunately, it had > problems executing webrat methods like 'visits'. > > Kindly check out this pastie: http://pastie.org/175204 > > I tried running it with the normal ruby wrapper and it works fine. Eh, dunno. Did you use --rails? That's the same as my helper.rb, except I don't require webrat (it's a plugin, so it's loaded automatically by rails). Ding me in #rspec at freenode if --rails fixes it, or doesn't for that matter. My nick is pd. kyle From timcharper at gmail.com Fri Apr 4 22:58:43 2008 From: timcharper at gmail.com (Tim Harper) Date: Fri, 4 Apr 2008 20:58:43 -0600 Subject: [rspec-users] changes to RSpec Bundle In-Reply-To: <810a540e0804041705j7c834dcbh2323b31657716687@mail.gmail.com> References: <19527F20-C4E2-4B9D-888E-2CC8980F26B2@gmail.com> <47F6BFC0.6090405@benmabey.com> <810a540e0804041705j7c834dcbh2323b31657716687@mail.gmail.com> Message-ID: Created: http://rspec.lighthouseapp.com/projects/5645/tickets/365-feature-rspec-bundle-update-rspec-bundle Thanks everyone! Tim On Fri, Apr 4, 2008 at 6:05 PM, Pat Maddox wrote: > On Fri, Apr 4, 2008 at 4:54 PM, Ben Mabey wrote: > > > > Tim Harper wrote: > > > Hi, > > > > > > I forked the rspec bundle on github and added a new command to it (an > > > Update RSpec Bundle command). I sent a pull request, but haven't > > > heard back from anyone on it. > > > > > > David, did you get my pull request? Or did it get lost in the black > > > whole of cyberspace? (if you were too busy to respond, that's fine, > > > just wanted to follow up) > > > > > > Thanks, > > > Tim > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > Hey Tim, > > I just asked about the use of pull request vs patches on the dev list. > > According to David things should still be added to the project tracker: > > http://rspec.lighthouseapp.com/ > > > > So you can either upload a patch there or just give the commit link on > > github he could pull from. Either way they want to keep track of this > > stuff on lighthouse I think. > > Ideal way is to give a commit link. > > > > > Also, there was some talk of moving the bundle in a separate bundle and > > using git modules... I don't think that has happened yet though... > > David actually made all these changes last night. If you go to > http://github.com/dchelimsky you can see all the repositories. > > To get the latest and greatest version of the code, do > git clone git://github.com/dchelimsky/rspec-dev.git > cd rspec-dev > git submodule init > git submodule update > > And you're all set. > > So Tim, you should check out the latest code (or perhaps just the TM > bundle, if you want), create your patch, and then submit a ticket on > lighthouse with a link to the commit. > > Pat > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From will.sargent at gmail.com Fri Apr 4 23:45:33 2008 From: will.sargent at gmail.com (Will Sargent) Date: Fri, 4 Apr 2008 20:45:33 -0700 Subject: [rspec-users] laziness plugin Message-ID: Just for general entertainment, apparently you can get Rails to write your unit tests now: "Laziness isn't just helpful in development mode, though - it also comes into play in production. If you've installed the exception_notification plugin (and you really should have - if not, go ahead; I'll wait), then laziness will add its generated test to the email you receive whenever your production app throws an unexpected exception." http://www.culann.com/2008/03/and-the-greatest-of-these-is-laziness Looks interesting, although it doesn't seem to handle rspec. Will. From peter.fitzgibbons at gmail.com Sat Apr 5 00:28:00 2008 From: peter.fitzgibbons at gmail.com (Peter Fitzgibbons) Date: Fri, 4 Apr 2008 23:28:00 -0500 Subject: [rspec-users] Newbie : how to require to lib from spec under autotest? Message-ID: <670a00380804042128r77bcf723v2f9546f6d2399ec8@mail.gmail.com> Hello all, I have the RSpec sample in ./rspec_bowling, with... ./rspec_bowling/lib/bowling.rb ./rspec_bowling/spec/spec.opts ./rspec_bowling/spec/bowling_spec.rb when I autotest, I get this: $autotest loading autotest/rspec /usr/local/bin/ruby -S /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.3/bin/spec -O spec/spec.opts spec/spec_helper.rb spec/bowling_spec.rb F 1) ArgumentError in 'Bowling should score 0 for gutter game' wrong number of arguments (1 for 0) [..snip..] Finished in 0.254 seconds 1 example, 1 failure /usr/local/bin/ruby -S /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.3/bin/spec -O spec/spec.opts spec/bowling_spec.rb *./spec/bowling_spec.rb:3:in `require': no such file to load -- bowling (LoadError) * from ./spec/bowling_spec.rb:3 My RUBYPATH = ../lib:./lib:$PATH, which caused autotest to load the 1st run correctly. Could someone help me understand how to correctly set the search path for repeated loading under autotest ? Thanks! -- Peter Fitzgibbons ------------------------------ iPhone -- "IT"-ness. href= http://www.macdailynews.com/index.php/weblog/comments/apples_iphone_could_become_iconic_it_object ------------------------------ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080404/bdcff836/attachment.html From dchelimsky at gmail.com Sat Apr 5 00:38:23 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 5 Apr 2008 00:38:23 -0400 Subject: [rspec-users] Newbie : how to require to lib from spec under autotest? In-Reply-To: <670a00380804042128r77bcf723v2f9546f6d2399ec8@mail.gmail.com> References: <670a00380804042128r77bcf723v2f9546f6d2399ec8@mail.gmail.com> Message-ID: <1BBF8573-C053-47A0-82E5-4376085D58C5@gmail.com> On Apr 5, 2008, at 12:28 AM, "Peter Fitzgibbons" wrote: > Hello all, > > I have the RSpec sample in ./rspec_bowling, with... > ./rspec_bowling/lib/bowling.rb > ./rspec_bowling/spec/spec.opts > ./rspec_bowling/spec/bowling_spec.rb > > when I autotest, I get this: > $autotest > loading autotest/rspec > /usr/local/bin/ruby -S /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.3/ > bin/spec -O spec/spec.opts spec/spec_helper.rb spec/bowling_spec.rb > F > > 1) > ArgumentError in 'Bowling should score 0 for gutter game' > wrong number of arguments (1 for 0) > [..snip..] This is the error - no path problem. There is a method expecting no arguments that is being called with one. HTH, David > > Finished in 0.254 seconds > > 1 example, 1 failure > /usr/local/bin/ruby -S /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.3/ > bin/spec -O spec/spec.opts spec/bowling_spec.rb > ./spec/bowling_spec.rb:3:in `require': no such file to load -- > bowling (LoadError) > from ./spec/bowling_spec.rb:3 > > My RUBYPATH = ../lib:./lib:$PATH, which caused autotest to load the > 1st run correctly. > > Could someone help me understand how to correctly set the search > path for repeated loading under autotest ? > > Thanks! > > > -- > Peter Fitzgibbons > ------------------------------ > iPhone -- "IT"-ness. > href=http://www.macdailynews.com/index.php/weblog/comments/apples_iphone_could_become_iconic_it_object > ------------------------------ > _______________________________________________ > 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/20080405/893beee1/attachment.html From cwdinfo at gmail.com Sat Apr 5 00:46:58 2008 From: cwdinfo at gmail.com (s.ross) Date: Fri, 4 Apr 2008 21:46:58 -0700 Subject: [rspec-users] laziness plugin In-Reply-To: References: Message-ID: On Apr 4, 2008, at 8:45 PM, Will Sargent wrote: > Just for general entertainment, apparently you can get Rails to write > your unit tests now: > > "Laziness isn't just helpful in development mode, though - it also > comes into play in production. If you've installed the > exception_notification plugin (and you really should have - if not, go > ahead; I'll wait), then laziness will add its generated test to the > email you receive whenever your production app throws an unexpected > exception." > > http://www.culann.com/2008/03/and-the-greatest-of-these-is-laziness > > Looks interesting, although it doesn't seem to handle rspec. > > Will. This looks pretty slick. Just browsing the source on github, it looks like the code checks for RAILS_ROOT/spec/spec_helper.rb and uses that to decide whether to emit rSpec or Test::Unit tests. From mailing_lists at railsnewbie.com Sat Apr 5 01:00:57 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 5 Apr 2008 01:00:57 -0400 Subject: [rspec-users] webrat bugs In-Reply-To: References: Message-ID: <095E5A13-D6CF-4BDD-BFCF-41AC6B3C5DAE@railsnewbie.com> On Apr 4, 2008, at 6:18 PM, Joe Van Dyk wrote: > Where do I report webrat bugs? > > Seems that when there's a parenthesis in the link text, doing: > > session.clicks_link("link with (parens)") > > fails to find the link text. I believe (with my limited experience with webrat) that this is occurring because it expects a regex. I bet if you escaped the parents "\(parens\)" it would start to work. Scott From mailing_lists at railsnewbie.com Sat Apr 5 01:03:41 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 5 Apr 2008 01:03:41 -0400 Subject: [rspec-users] Newbie : how to require to lib from spec under autotest? In-Reply-To: <1BBF8573-C053-47A0-82E5-4376085D58C5@gmail.com> References: <670a00380804042128r77bcf723v2f9546f6d2399ec8@mail.gmail.com> <1BBF8573-C053-47A0-82E5-4376085D58C5@gmail.com> Message-ID: <4E8255A1-3C94-4E13-B6C5-FA0DCF086FE5@railsnewbie.com> On Apr 5, 2008, at 12:38 AM, David Chelimsky wrote: > On Apr 5, 2008, at 12:28 AM, "Peter Fitzgibbons" > wrote: > >> Hello all, >> >> I have the RSpec sample in ./rspec_bowling, with... >> ./rspec_bowling/lib/bowling.rb >> ./rspec_bowling/spec/spec.opts >> ./rspec_bowling/spec/bowling_spec.rb >> >> when I autotest, I get this: >> $autotest >> loading autotest/rspec >> /usr/local/bin/ruby -S /usr/local/lib/ruby/gems/1.8/gems/ >> rspec-1.1.3/bin/spec -O spec/spec.opts spec/spec_helper.rb spec/ >> bowling_spec.rb >> F >> >> 1) >> ArgumentError in 'Bowling should score 0 for gutter game' >> wrong number of arguments (1 for 0) >> [..snip..] > > This is the error - no path problem. There is a method expecting no > arguments that is being called with one. > > HTH, > David Sure - that test fails - but why do we see the next result? (see below) What is rails doing in the background? Scott > > > >> >> Finished in 0.254 seconds >> >> 1 example, 1 failure >> /usr/local/bin/ruby -S /usr/local/lib/ruby/gems/1.8/gems/ >> rspec-1.1.3/bin/spec -O spec/spec.opts spec/bowling_spec.rb >> ./spec/bowling_spec.rb:3:in `require': no such file to load -- >> bowling (LoadError) >> from ./spec/bowling_spec.rb:3 >> >> My RUBYPATH = ../lib:./lib:$PATH, which caused autotest to load the >> 1st run correctly. >> >> Could someone help me understand how to correctly set the search >> path for repeated loading under autotest ? >> >> Thanks! >> >> >> -- >> Peter Fitzgibbons >> ------------------------------ >> iPhone -- "IT"-ness. >> href=http://www.macdailynews.com/index.php/weblog/comments/apples_iphone_could_become_iconic_it_object >> ------------------------------ >> _______________________________________________ >> 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/20080405/cf7be1f9/attachment-0001.html From peter.fitzgibbons at gmail.com Sat Apr 5 07:08:54 2008 From: peter.fitzgibbons at gmail.com (Peter Fitzgibbons) Date: Sat, 5 Apr 2008 06:08:54 -0500 Subject: [rspec-users] Newbie : how to require to lib from spec under autotest? In-Reply-To: <4E8255A1-3C94-4E13-B6C5-FA0DCF086FE5@railsnewbie.com> References: <670a00380804042128r77bcf723v2f9546f6d2399ec8@mail.gmail.com> <1BBF8573-C053-47A0-82E5-4376085D58C5@gmail.com> <4E8255A1-3C94-4E13-B6C5-FA0DCF086FE5@railsnewbie.com> Message-ID: <670a00380804050408m1bfd9978xf02ccd21d6045350@mail.gmail.com> On Sat, Apr 5, 2008 at 12:03 AM, Scott Taylor wrote: > > On Apr 5, 2008, at 12:38 AM, David Chelimsky wrote: > > On Apr 5, 2008, at 12:28 AM, "Peter Fitzgibbons" < > peter.fitzgibbons at gmail.com> wrote: > > Hello all, > > I have the RSpec sample in ./rspec_bowling, with... > ./rspec_bowling/lib/bowling.rb > ./rspec_bowling/spec/spec.opts > ./rspec_bowling/spec/bowling_spec.rb > > when I autotest, I get this: > $autotest > loading autotest/rspec > /usr/local/bin/ruby -S > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.3/bin/spec -O spec/spec.opts > spec/spec_helper.rb spec/bowling_spec.rb > F > > 1) > ArgumentError in 'Bowling should score 0 for gutter game' > wrong number of arguments (1 for 0) > [..snip..] > > > This is the error - no path problem. There is a method expecting no > arguments that is being called with one. > > HTH, > David > > > Sure - that test fails - but why do we see the next result? (see below) > What is rails doing in the background? > > Scott > This is not a rails app, it's standalone ruby. And yes, as I highlighted,the interesting bit is the second run where instead 'require' fails. Thanks in advance for further discussion! Peter -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080405/8cfff371/attachment.html From zach.dennis at gmail.com Sat Apr 5 11:21:53 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sat, 5 Apr 2008 11:21:53 -0400 Subject: [rspec-users] Welcome Pat Maddox In-Reply-To: <810a540e0804041134x11df6594m891b48817cdd56a7@mail.gmail.com> References: <57c63afe0804040623k6fb1fe02v3eca214773424bf4@mail.gmail.com> <71166b3b0804040750j54cec670v8e4b5065df725268@mail.gmail.com> <8d961d900804041026o273c30b2qc194a26a4981427f@mail.gmail.com> <810a540e0804041134x11df6594m891b48817cdd56a7@mail.gmail.com> Message-ID: <85d99afe0804050821s445e0519sc6c4dfc8eeb0a1e3@mail.gmail.com> Congrats pat! Zach On Fri, Apr 4, 2008 at 2:34 PM, Pat Maddox wrote: > On Fri, Apr 4, 2008 at 10:26 AM, aslak hellesoy > wrote: > > > On 4/4/08, Luis Lavena wrote: > > > On Fri, Apr 4, 2008 at 11:35 AM, Patrick Meunier > > > wrote: > > > > This is a great news! Congratulations Pat. > > > > > > > > > > +1 on that, The bdd-force within Pat is strong, and is good to see he > > > is joining the good side of the force :-) > > > > > > > Pat is a much needed and welcome member to the core team. I expect > > we'll see a lot of great contribs from him in the time to come. > > > > Welcome onboard, Pat! > > Thank you for the kind words, everyone. > > Pat > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com From peter.fitzgibbons at gmail.com Sat Apr 5 11:42:06 2008 From: peter.fitzgibbons at gmail.com (Peter Fitzgibbons) Date: Sat, 5 Apr 2008 10:42:06 -0500 Subject: [rspec-users] Newbie : how to require to lib from spec under autotest? In-Reply-To: <670a00380804050408m1bfd9978xf02ccd21d6045350@mail.gmail.com> References: <670a00380804042128r77bcf723v2f9546f6d2399ec8@mail.gmail.com> <1BBF8573-C053-47A0-82E5-4376085D58C5@gmail.com> <4E8255A1-3C94-4E13-B6C5-FA0DCF086FE5@railsnewbie.com> <670a00380804050408m1bfd9978xf02ccd21d6045350@mail.gmail.com> Message-ID: <670a00380804050842jca74295n75288f5a16ace37f@mail.gmail.com> On Sat, Apr 5, 2008 at 6:08 AM, Peter Fitzgibbons < peter.fitzgibbons at gmail.com> wrote: > > On Sat, Apr 5, 2008 at 12:03 AM, Scott Taylor < > mailing_lists at railsnewbie.com> wrote: > > > > > On Apr 5, 2008, at 12:38 AM, David Chelimsky wrote: > > > > On Apr 5, 2008, at 12:28 AM, "Peter Fitzgibbons" < > > peter.fitzgibbons at gmail.com> wrote: > > > > Hello all, > > > > I have the RSpec sample in ./rspec_bowling, with... > > ./rspec_bowling/lib/bowling.rb > > ./rspec_bowling/spec/spec.opts > > ./rspec_bowling/spec/bowling_spec.rb > > > > when I autotest, I get this: > > $autotest > > loading autotest/rspec > > /usr/local/bin/ruby -S > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.3/bin/spec -O spec/spec.opts > > spec/spec_helper.rb spec/bowling_spec.rb > > F > > > > 1) > > ArgumentError in 'Bowling should score 0 for gutter game' > > wrong number of arguments (1 for 0) > > [..snip..] > > > > > > This is the error - no path problem. There is a method expecting no > > arguments that is being called with one. > > > > HTH, > > David > > > > > > Sure - that test fails - but why do we see the next result? (see below) > > What is rails doing in the background? > > > > Scott > > > > > This is not a rails app, it's standalone ruby. > > And yes, as I highlighted,the interesting bit is the second run where > instead 'require' fails. > > Thanks in advance for further discussion! > > Peter > > Hello All, Thanks for your tips. In the end, what I needed was a lesson on Ruby Load Path. Pickaxe 2 pp172 "Where Ruby finds its modules" gave me the answer. I needed to set environment variable RUBYLIB export RUBYLIB=./lib:../lib so that $ruby -e 'puts $:' ./lib ../lib /usr/local/lib/ruby/site_ruby/1.8 /usr/local/lib/ruby/site_ruby/1.8/i386-cygwin /usr/local/lib/ruby/site_ruby /usr/local/lib/ruby/1.8 /usr/local/lib/ruby/1.8/i386-cygwin . Now autotest gets the proper require twice in a row, when the spec file reads : require 'bowling' Hope this helps you, next grasshopper of the RSpec FU! -- Peter Fitzgibbons ------------------------------ iPhone -- "IT"-ness. href= http://www.macdailynews.com/index.php/weblog/comments/apples_iphone_could_become_iconic_it_object ------------------------------ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080405/cd015626/attachment.html From pergesu at gmail.com Sat Apr 5 11:57:40 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 5 Apr 2008 08:57:40 -0700 Subject: [rspec-users] Newbie : how to require to lib from spec under autotest? In-Reply-To: <670a00380804050842jca74295n75288f5a16ace37f@mail.gmail.com> References: <670a00380804042128r77bcf723v2f9546f6d2399ec8@mail.gmail.com> <1BBF8573-C053-47A0-82E5-4376085D58C5@gmail.com> <4E8255A1-3C94-4E13-B6C5-FA0DCF086FE5@railsnewbie.com> <670a00380804050408m1bfd9978xf02ccd21d6045350@mail.gmail.com> <670a00380804050842jca74295n75288f5a16ace37f@mail.gmail.com> Message-ID: <810a540e0804050857n6bab793w48feff90f4dedd57@mail.gmail.com> On Sat, Apr 5, 2008 at 8:42 AM, Peter Fitzgibbons wrote: > "Where Ruby finds its modules" gave me the answer. I needed to set > environment variable RUBYLIB > > export RUBYLIB=./lib:../lib Instead of setting an environment variable before running the app, you can modify the load path in your code with: $:.unshift(*['./lib', '../lib']) Pat From tastapod at gmail.com Sat Apr 5 17:39:29 2008 From: tastapod at gmail.com (Dan North) Date: Sat, 5 Apr 2008 22:39:29 +0100 Subject: [rspec-users] Welcome Pat Maddox In-Reply-To: <85d99afe0804050821s445e0519sc6c4dfc8eeb0a1e3@mail.gmail.com> References: <57c63afe0804040623k6fb1fe02v3eca214773424bf4@mail.gmail.com> <71166b3b0804040750j54cec670v8e4b5065df725268@mail.gmail.com> <8d961d900804041026o273c30b2qc194a26a4981427f@mail.gmail.com> <810a540e0804041134x11df6594m891b48817cdd56a7@mail.gmail.com> <85d99afe0804050821s445e0519sc6c4dfc8eeb0a1e3@mail.gmail.com> Message-ID: Let me join everyone else in welcoming you to the rspec developer team. As a notorious non-completer-finisher I can't begin to tell you how pleased I am to see you joining the team, especially given the clarity and high quality of your contributions on this list. Cheers, Dan On 05/04/2008, Zach Dennis wrote: > > Congrats pat! > > Zach > > > On Fri, Apr 4, 2008 at 2:34 PM, Pat Maddox wrote: > > On Fri, Apr 4, 2008 at 10:26 AM, aslak hellesoy > > wrote: > > > > > On 4/4/08, Luis Lavena wrote: > > > > On Fri, Apr 4, 2008 at 11:35 AM, Patrick Meunier > > > > wrote: > > > > > This is a great news! Congratulations Pat. > > > > > > > > > > > > > +1 on that, The bdd-force within Pat is strong, and is good to see > he > > > > is joining the good side of the force :-) > > > > > > > > > > Pat is a much needed and welcome member to the core team. I expect > > > we'll see a lot of great contribs from him in the time to come. > > > > > > Welcome onboard, Pat! > > > > Thank you for the kind words, everyone. > > > > Pat > > > > > > _______________________________________________ > > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080405/52e8e9e7/attachment.html From coreyhaines at gmail.com Sat Apr 5 17:47:58 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Sat, 5 Apr 2008 17:47:58 -0400 Subject: [rspec-users] Newbie : how to require to lib from spec under autotest? In-Reply-To: <670a00380804050842jca74295n75288f5a16ace37f@mail.gmail.com> References: <670a00380804042128r77bcf723v2f9546f6d2399ec8@mail.gmail.com> <1BBF8573-C053-47A0-82E5-4376085D58C5@gmail.com> <4E8255A1-3C94-4E13-B6C5-FA0DCF086FE5@railsnewbie.com> <670a00380804050408m1bfd9978xf02ccd21d6045350@mail.gmail.com> <670a00380804050842jca74295n75288f5a16ace37f@mail.gmail.com> Message-ID: <6bdacb70804051447g44bbeeb2t830925c6291589f1@mail.gmail.com> Sweet! That's a cool command. Thanks for posting! On Sat, Apr 5, 2008 at 11:42 AM, Peter Fitzgibbons < peter.fitzgibbons at gmail.com> wrote: > > > On Sat, Apr 5, 2008 at 6:08 AM, Peter Fitzgibbons < > peter.fitzgibbons at gmail.com> wrote: > > > > > On Sat, Apr 5, 2008 at 12:03 AM, Scott Taylor < > > mailing_lists at railsnewbie.com> wrote: > > > > > > > > On Apr 5, 2008, at 12:38 AM, David Chelimsky wrote: > > > > > > On Apr 5, 2008, at 12:28 AM, "Peter Fitzgibbons" < > > > peter.fitzgibbons at gmail.com> wrote: > > > > > > Hello all, > > > > > > I have the RSpec sample in ./rspec_bowling, with... > > > ./rspec_bowling/lib/bowling.rb > > > ./rspec_bowling/spec/spec.opts > > > ./rspec_bowling/spec/bowling_spec.rb > > > > > > when I autotest, I get this: > > > $autotest > > > loading autotest/rspec > > > /usr/local/bin/ruby -S > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.3/bin/spec -O spec/spec.opts > > > spec/spec_helper.rb spec/bowling_spec.rb > > > F > > > > > > 1) > > > ArgumentError in 'Bowling should score 0 for gutter game' > > > wrong number of arguments (1 for 0) > > > [..snip..] > > > > > > > > > This is the error - no path problem. There is a method expecting no > > > arguments that is being called with one. > > > > > > HTH, > > > David > > > > > > > > > Sure - that test fails - but why do we see the next result? (see > > > below) What is rails doing in the background? > > > > > > Scott > > > > > > > > > This is not a rails app, it's standalone ruby. > > > > And yes, as I highlighted,the interesting bit is the second run where > > instead 'require' fails. > > > > Thanks in advance for further discussion! > > > > Peter > > > > > Hello All, > > Thanks for your tips. > In the end, what I needed was a lesson on Ruby Load Path. Pickaxe 2 pp172 > "Where Ruby finds its modules" gave me the answer. I needed to set > environment variable RUBYLIB > > export RUBYLIB=./lib:../lib > > so that > > $ruby -e 'puts $:' > ./lib > ../lib > /usr/local/lib/ruby/site_ruby/1.8 > /usr/local/lib/ruby/site_ruby/1.8/i386-cygwin > /usr/local/lib/ruby/site_ruby > /usr/local/lib/ruby/1.8 > /usr/local/lib/ruby/1.8/i386-cygwin > . > Now autotest gets the proper require twice in a row, when the spec file > reads : > > require 'bowling' > > Hope this helps you, next grasshopper of the RSpec FU! > > > -- > Peter Fitzgibbons > ------------------------------ > iPhone -- "IT"-ness. > href= > http://www.macdailynews.com/index.php/weblog/comments/apples_iphone_could_become_iconic_it_object > ------------------------------ > > _______________________________________________ > 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/20080405/bf76d21a/attachment-0001.html From raasdnil at gmail.com Sat Apr 5 21:55:19 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Sun, 6 Apr 2008 11:55:19 +1000 Subject: [rspec-users] Getting to the session from Stories Message-ID: <57a815bf0804051855l7274c2f4re0f7ff4996b08f78@mail.gmail.com> Hey all, In a story I want to say Given "A logged in user" do sesson[:logged_in] = true etc... end But the session method doesn't have anything to bind to, I get the error '... while evaluating nil.session...' Any ideas? The fact that the user is logged in or not, doesn't matter to this story, so I just want to stub it out. The other way is stubbing out all the authentication methods, but that is more typing :) (less than this message to find out how to do it the short way, but you know, once you think you need to do something, doing it the longer way just seems wrong :D Regards Mikel From dchelimsky at gmail.com Sat Apr 5 23:00:56 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 5 Apr 2008 23:00:56 -0400 Subject: [rspec-users] Getting to the session from Stories In-Reply-To: <57a815bf0804051855l7274c2f4re0f7ff4996b08f78@mail.gmail.com> References: <57a815bf0804051855l7274c2f4re0f7ff4996b08f78@mail.gmail.com> Message-ID: <57c63afe0804052000r5f478290x81b1ba30cf6125ca@mail.gmail.com> On Sat, Apr 5, 2008 at 9:55 PM, Mikel Lindsaar wrote: > Hey all, > > In a story I want to say > > Given "A logged in user" do > sesson[:logged_in] = true > etc... > end > > But the session method doesn't have anything to bind to, I get the > error '... while evaluating nil.session...' > > Any ideas? This is not supported by Rails' ActionController::IntegrationTest, from which RailsStory is derived. The intention of ActionController::IntegrationTest is to provide an environment for testing through routers. What you're trying to do is really the domain of RSpec controller specs or Rails functional tests. What I'd recommend is that you actually log in and go from there: > The fact that the user is logged in or not, doesn't matter to this > story, so I just want to stub it out. Stubbing in stories should be avoided except for stubbing external services. HTH, David > The other way is stubbing out all the authentication methods, but that > is more typing :) (less than this message to find out how to do it > the short way, but you know, once you think you need to do something, > doing it the longer way just seems wrong :D > > Regards > > Mikel > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From backslash451 at yahoo.it Sun Apr 6 07:20:53 2008 From: backslash451 at yahoo.it (roberto belardo) Date: Sun, 6 Apr 2008 13:20:53 +0200 (CEST) Subject: [rspec-users] Rspecing this simple controller it is driving me mad... Message-ID: <340206.62605.qm@web27004.mail.ukl.yahoo.com> Hi all, here i am again with this stupid problem in rspecing this controller action: ------------------------------------ CommentsController def create @comment = Comment.new(params[:comment]) @user = User.find(params[:user_id]) [16] @comment.author = @user @comment.save end ------------------------------------ CommentsController Spec describe CommentsController, "handling POST /comments" do before(:each) do @user = mock_model(User, :to_param => "2") @comment = mock_model(Comment, :to_param => "1", :author => @user) User.should_receive(:find).at_least(1).times.and_return(@user) Comment.stub!(:new).and_return(@comment) end def post_with_successful_save @comment.should_receive(:save).and_return(true) [34]post :create, :user_id => @user_id, :comment => {} end it "should create a new comment" do Comment.should_receive(:new).with({ }).and_return(@comment) [47]post_with_successful_save @comment.author.should be(@user) end end The frustrating error Rspec gave to me is this: Spec::Mocks::MockExpectationError in 'CommentsController handling POST /comments should create a new comment' Mock 'Comment_1002' received unexpected message :author= with (#) comments_controller.rb:16:in `create' comments_controller_spec.rb:34:in `post_with_successful_save' comments_controller_spec.rb:47: I have tried to google for something like this but i resolved nothing. Could someone help me understanding my fault? Thanks in advance, Roberto. Inviato da Yahoo! Mail. La casella di posta intelligente. http://it.docs.yahoo.com/mail/overview/index.html From jarkko at jlaine.net Sun Apr 6 08:00:48 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Sun, 6 Apr 2008 15:00:48 +0300 Subject: [rspec-users] Rspecing this simple controller it is driving me mad... In-Reply-To: <340206.62605.qm@web27004.mail.ukl.yahoo.com> References: <340206.62605.qm@web27004.mail.ukl.yahoo.com> Message-ID: <8556DEF6-0CD1-423E-8639-D1F5975F8109@jlaine.net> On 6.4.2008, at 14.20, roberto belardo wrote: > Hi all, > here i am again with this stupid problem in rspecing > this controller action: > > ------------------------------------ > CommentsController > def create > @comment = Comment.new(params[:comment]) > @user = User.find(params[:user_id]) > > [16] @comment.author = @user > > @comment.save > end > > ------------------------------------ > CommentsController Spec > describe CommentsController, "handling POST /comments" > do > > before(:each) do > @user = mock_model(User, :to_param => "2") > @comment = mock_model(Comment, :to_param => "1", > :author => @user) > > > User.should_receive(:find).at_least(1).times.and_return(@user) > > Comment.stub!(:new).and_return(@comment) > > end > > def post_with_successful_save > @comment.should_receive(:save).and_return(true) > > [34]post :create, :user_id => @user_id, :comment => {} > > end > > it "should create a new comment" do > Comment.should_receive(:new).with({ > }).and_return(@comment) > [47]post_with_successful_save > @comment.author.should be(@user) > end > > end > > The frustrating error Rspec gave to me is this: > > Spec::Mocks::MockExpectationError in > 'CommentsController handling POST /comments should > create a new comment' > Mock 'Comment_1002' received unexpected message > :author= with (# @name="User_1000">) > comments_controller.rb:16:in `create' > comments_controller_spec.rb:34:in > `post_with_successful_save' > comments_controller_spec.rb:47: > > > I have tried to google for something like this but i > resolved nothing. Could someone help me understanding > my fault? Short answer: you haven't stubbed the author= method for the comment mock, only author. A bit longer answer: Are you sure you can trust the user to only submit valid user ids? With your current code, anyone can change the user_id parameter in the call and fake any user id she wants. This might be intentional (if there are only admin users in your app), just pointing it out. You can also simplify your action by just saying @user.comments.create(params[:comment]) once you have the user fetched. Cheers, //jarkko > > Thanks in advance, > Roberto. > > > Inviato da Yahoo! Mail. > La casella di posta intelligente. > 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 -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available Url : http://rubyforge.org/pipermail/rspec-users/attachments/20080406/fbb04287/attachment.bin From backslash451 at yahoo.it Sun Apr 6 10:03:40 2008 From: backslash451 at yahoo.it (roberto belardo) Date: Sun, 6 Apr 2008 16:03:40 +0200 (CEST) Subject: [rspec-users] Rspecing this simple controller it is driving me mad... In-Reply-To: <8556DEF6-0CD1-423E-8639-D1F5975F8109@jlaine.net> Message-ID: <941287.3194.qm@web27005.mail.ukl.yahoo.com> Thank you very much for you quick answer! Naturally now it works. Thanks for the long version note too. I already know that, and my code is just a test to play with rspec, but i really appreciate your note. Thank you for your help, see you the next problem, Roberto. :-) --- Jarkko Laine ha scritto: > > On 6.4.2008, at 14.20, roberto belardo wrote: > > > Hi all, > > here i am again with this stupid problem in > rspecing > > this controller action: > > > > ------------------------------------ > > CommentsController > > def create > > @comment = Comment.new(params[:comment]) > > @user = User.find(params[:user_id]) > > > > [16] @comment.author = @user > > > > @comment.save > > end > > > > ------------------------------------ > > CommentsController Spec > > describe CommentsController, "handling POST > /comments" > > do > > > > before(:each) do > > @user = mock_model(User, :to_param => "2") > > @comment = mock_model(Comment, :to_param => > "1", > > :author => @user) > > > > > > > User.should_receive(:find).at_least(1).times.and_return(@user) > > > > Comment.stub!(:new).and_return(@comment) > > > > end > > > > def post_with_successful_save > > @comment.should_receive(:save).and_return(true) > > > > [34]post :create, :user_id => @user_id, :comment > => {} > > > > end > > > > it "should create a new comment" do > > Comment.should_receive(:new).with({ > > }).and_return(@comment) > > [47]post_with_successful_save > > @comment.author.should be(@user) > > end > > > > end > > > > The frustrating error Rspec gave to me is this: > > > > Spec::Mocks::MockExpectationError in > > 'CommentsController handling POST /comments should > > create a new comment' > > Mock 'Comment_1002' received unexpected message > > :author= with (# > @name="User_1000">) > > comments_controller.rb:16:in `create' > > comments_controller_spec.rb:34:in > > `post_with_successful_save' > > comments_controller_spec.rb:47: > > > > > > I have tried to google for something like this but > i > > resolved nothing. Could someone help me > understanding > > my fault? > > Short answer: you haven't stubbed the author= method > for the comment > mock, only author. > > A bit longer answer: Are you sure you can trust the > user to only > submit valid user ids? With your current code, > anyone can change the > user_id parameter in the call and fake any user id > she wants. This > might be intentional (if there are only admin users > in your app), just > pointing it out. You can also simplify your action > by just saying > @user.comments.create(params[:comment]) once you > have the user fetched. > > Cheers, > //jarkko > > > > > Thanks in advance, > > Roberto. > > > > > > Inviato da Yahoo! Mail. > > La casella di posta intelligente. > > 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 > > -- > Jarkko Laine > http://jlaine.net > http://dotherightthing.com > http://www.railsecommerce.com > http://odesign.fi > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Inviato da Yahoo! Mail. La casella di posta intelligente. http://it.docs.yahoo.com/mail/overview/index.html From lists at ruby-forum.com Sun Apr 6 15:36:14 2008 From: lists at ruby-forum.com (=?utf-8?Q?Willem_K=c3=a4llman?=) Date: Sun, 6 Apr 2008 21:36:14 +0200 Subject: [rspec-users] Autotest RSpec Not Running on Model Save's? In-Reply-To: <7e565b5c0804031717l15f63d57w17c57a2cd6657817@mail.gmail.com> References: <7e565b5c0804031717l15f63d57w17c57a2cd6657817@mail.gmail.com> Message-ID: <004d96df9231df88906e1dbfdeac64d6@ruby-forum.com> Same problem here, but I guess it has nothing to do with RSpec or the fact that you are testing a model. Instead, Autotest seems to misbehave. Say we have a project directory with these contents: lib/script.rb spec/spec_script.rb spec/spec.opts The following is what Autotest does on my system: After running '$ autotest' and changing the contents of spec_script.rb, Autotest invokes //ruby -S //rspec-1.1.3/bin/spec -O spec/spec.opts spec/spec_script.rb Which is perfectly fine. However, when I edit and save script.rb, Autotest will call 'spec' without specifying a file: //ruby -S //rspec-1.1.3/bin/spec -O Just as you described it. I'd really love to hear some ideas on how to fix this. Thank you! -- Posted via http://www.ruby-forum.com/. From loop at superinfinite.com Mon Apr 7 09:30:50 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Mon, 7 Apr 2008 15:30:50 +0200 Subject: [rspec-users] Advice / Turning a Usecase into a Rspec Story / Granularity ofstories In-Reply-To: <57c63afe0804030531i49dcc4es58a2277128872aed@mail.gmail.com> References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <64B3E556-6A7C-4298-A9A9-C4BE941565F4@superinfinite.com> <1207214104.6571.23.camel@esw023.esw.eshopworks.co.uk> <10B4C604-ACB3-4E30-8DA1-20246DFDD135@superinfinite.com> <57c63afe0804030531i49dcc4es58a2277128872aed@mail.gmail.com> Message-ID: On 3-apr-2008, at 14:31, David Chelimsky wrote: > On Thu, Apr 3, 2008 at 8:25 AM, Bart Zonneveld > wrote: >> >> >> On 3-apr-2008, at 14:12, Rick DeNatale wrote: >>> On Thu, Apr 3, 2008 at 5:34 AM, Ashley Moran >>> wrote: >>>> On 03/04/2008, joseph wrote: >>>> >>>>> >>>>> Example Story (High level): >>>>> >>>>> Story: Web admin manages pages within the admin system >>>>> Scenario: Add page >>>>> Scenario: edit page. >>>>> Scenario: delete page. >>> >>>> This seems too coarse to me. The controller I'm working on now >>>> will end up >>>> with a corresponding story for each of your scenarios. My >>>> scenarios are >>>> along the lines of "User edits page with valid details", "User >>>> edits page >>>> with missing details", "User edits page and clicks cancel", "User >>>> with >>>> insufficient priveleges tries to delete page" etc. I try to make >>>> a scenario >>>> for each common or complex thing that changes the state of the >>>> system - they >>>> would never fit in one story. >>> >>> On the other hand. Keeping these finer grained scenarios within a >>> single story allows branching using GivenScenario which only works >>> with scenarios within the same story. >> >> I am having the same struggles with the granularity. Is there a good >> "sample" app out there on the interweb? >> Or perhaps someone from the list wants to share their story? :) > > I addressed this in my talk at ETEC last week. Slides are here: > http://www.chariotsolutions.com/slides/pdfs/ete2008- > IntegrationTestingWithRSpec.pdf Dang. Until The Book comes out, this is probably the best best- practices source for plain text stories with rspec. This should be on the wiki... gr, bartz From lists at ruby-forum.com Mon Apr 7 09:34:40 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Mon, 7 Apr 2008 15:34:40 +0200 Subject: [rspec-users] How can you delete unused view helper files? Message-ID: I would like to delete most of the view helper files from my project. Unfortunately, when I try to run my tests it throws an error saying that one of the files is missing. I find that all the non-required helper files clutter things up. Is there any way to remove them and still have your tests pass? Thanks. -- Posted via http://www.ruby-forum.com/. From mailing_lists at railsnewbie.com Mon Apr 7 09:42:49 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 7 Apr 2008 09:42:49 -0400 Subject: [rspec-users] How can you delete unused view helper files? In-Reply-To: References: Message-ID: On Apr 7, 2008, at 9:34 AM, Chris Olsen wrote: > I would like to delete most of the view helper files from my project. > Unfortunately, when I try to run my tests it throws an error saying > that > one of the files is missing. Warning? What does it say? Are you throwing away the helper *AND* the spec for that helper? Scott > > > I find that all the non-required helper files clutter things up. Is > there any way to remove them and still have your tests pass? > > Thanks. > -- > 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 Apr 7 09:51:27 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Mon, 7 Apr 2008 15:51:27 +0200 Subject: [rspec-users] How can you delete unused view helper files? In-Reply-To: References: Message-ID: Scott Taylor wrote: > On Apr 7, 2008, at 9:34 AM, Chris Olsen wrote: > >> I would like to delete most of the view helper files from my project. >> Unfortunately, when I try to run my tests it throws an error saying >> that >> one of the files is missing. > > Warning? What does it say? > > Are you throwing away the helper *AND* the spec for that helper? > > Scott Sorry I never posted back in time. I had a helper file hiding on me in the spec/helpers dir which was what was trying to load the corresponding app/helpers file. I had deleted them all a while ago, but it seems that one got re-created on a generate script. This is what happens when you are out of coffee grounds. :) Thanks for the help. -- Posted via http://www.ruby-forum.com/. From alen198 at gmail.com Sun Apr 6 15:17:44 2008 From: alen198 at gmail.com (newbie) Date: Sun, 6 Apr 2008 12:17:44 -0700 (PDT) Subject: [rspec-users] how to stub the :current_user and any methods associated with it Message-ID: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> I'm new to Rspec and I'm having a bit of trouble with this controller that I'm testing. I think I'm doing it right but I guess my syntax is wrong. I'm currently using the "acts_as_authenticated" plug in. What I want to test out is EventController on entering the tickets_page - should show the tickets_page if the current_user has NOT entered this page today ----------------------------------------------------- Below is my event controller ----------------------------------------------------- class EventController < ApplicationController before_filter :login_required def tickets_page if current_user.has_already_entered_today? flash[:notice] = 'Come back tomorrow' redirect_to :action => 'home' else flash[:notice] = 'Welcome' end end end ----------------------------------------------------- Below is my rspec for this controller ----------------------------------------------------- require File.dirname(__FILE__) + '/../spec_helper' describe EventController do before(:each) do @current_user = mock_model(User, :id => 1) controller.stub!(:current_user).and_return(@current_user) controller.stub!(:login_required).and_return(:true) end fixtures :users describe "on entering the tickets page" do it "should show the tickets_page if the current_user has NOT entered this page today" do controller.current_user.stub! (:has_already_entered_today?).and_return(:false) get :tickets_page controller.current_user.should_receive(:has_already_entered_today?).with(:false).and_return(:false) response.should render_template(:tickets_page) end end end ----------------------------------------------------- My errors ----------------------------------------------------- Mock 'User_1001' received unexpected message :has_already_entered_today? with (no args) Anyone can help with any direction of what I might be doing wrong? From chad.humphries at gmail.com Fri Apr 4 16:41:42 2008 From: chad.humphries at gmail.com (Chad Humphries) Date: Fri, 4 Apr 2008 16:41:42 -0400 Subject: [rspec-users] Welcome Pat Maddox In-Reply-To: References: <57c63afe0804040623k6fb1fe02v3eca214773424bf4@mail.gmail.com> <71166b3b0804040750j54cec670v8e4b5065df725268@mail.gmail.com> <8d961d900804041026o273c30b2qc194a26a4981427f@mail.gmail.com> <1d7ddd110804041142s1314d081t37090d98f95d85c2@mail.gmail.com> Message-ID: <16f722280804041341i65390fcdw516253780e620794@mail.gmail.com> Congrats Pat! -- Chad On Fri, Apr 4, 2008 at 2:52 PM, Andrew WC Brown wrote: > Gooble Goble, Gooble Goble, One of Us! One of Us! > > > > On Fri, Apr 4, 2008 at 2:42 PM, Brian Takita wrote: > > On Fri, Apr 4, 2008 at 10:26 AM, aslak hellesoy > > wrote: > > > On 4/4/08, Luis Lavena wrote: > > > > On Fri, Apr 4, 2008 at 11:35 AM, Patrick Meunier > > > > wrote: > > > > > This is a great news! Congratulations Pat. > > > > > > > > > > > > > +1 on that, The bdd-force within Pat is strong, and is good to see he > > > > is joining the good side of the force :-) > > > > > > > > > > Pat is a much needed and welcome member to the core team. I expect > > > we'll see a lot of great contribs from him in the time to come. > > > > > > Welcome onboard, Pat! > > Welcome Pat. > > > > > > Aslak > > > > > > > -- > > > > > > > > > > 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 > > > > > > > _______________________________________________ > > > 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 ryan at thinkrefresh.com Sun Apr 6 16:33:04 2008 From: ryan at thinkrefresh.com (Rare) Date: Sun, 6 Apr 2008 13:33:04 -0700 (PDT) Subject: [rspec-users] Comparing new models Message-ID: <00db40c5-1017-4416-b6b0-7c4944280c6a@h1g2000prh.googlegroups.com> Hi all, I am trying to test that a view file in Rails is being sent a new empty model (Product.new) in my rspec test, below is my code. I've tried comparing them with ==, ===, equal, eql none work. I just get an error (see below code). I guess it's the condition tester (e.g. ==) that is incorrect, can anyone help? Code: it "should assign the new product for the view" do do_get assigns[:product].should == Product.new end Error: 'ProductsController handling GET /products/new should assign the new product for the view' FAILED expected: #, got: # (using ==) ./spec/controllers/products_controller_spec.rb:118: From jacob.basham at gmail.com Fri Apr 4 12:46:31 2008 From: jacob.basham at gmail.com (Jacob) Date: Fri, 4 Apr 2008 09:46:31 -0700 (PDT) Subject: [rspec-users] Error testing rails controller Message-ID: I am trying to test my controllers with RSpec and from the examples I have found it is as easy as this: describe SessionsController do it "should render login template" do get 'new' response.should render_template(:login) end end However both get and post raise "wrong number of arguments (2 for 1)". I am working with 1.1.3, I rolled back to 1.1.2 and still suffer the same fate. Any thoughts onto what may be causing this issue? Thanks From Martin.Krauskopf at Sun.COM Tue Apr 1 03:34:10 2008 From: Martin.Krauskopf at Sun.COM (Martin Krauskopf) Date: Tue, 01 Apr 2008 09:34:10 +0200 Subject: [rspec-users] Netbeans and .story files In-Reply-To: References: Message-ID: <47F1E572.70600@sun.com> Tim Haines wrote: > 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? Hi, yes, the .story extension is not supported out-of-the box. Unfortunately it is not possible to extend Ruby file-type now: http://www.netbeans.org/issues/show_bug.cgi?id=116563 But easy to fix inside of NetBeans. I've just fixed it on my local machine. I'll commit in few hours. I've filed: http://www.netbeans.org/nonav/issues/show_bug.cgi?id=131684 Will not go into 6.1 (code-frozen), but you might grab it through the continuous builds when the issue above is marked fixed http://wiki.netbeans.org/RubyInstallation#section-RubyInstallation-HowDoIGetTheContinuousBuilds BTW is the .story extension kind of "official" one? I saw in some tutorials using .rb extension. Regards, m. From dchelimsky at gmail.com Mon Apr 7 10:40:41 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 7 Apr 2008 10:40:41 -0400 Subject: [rspec-users] Using Haml for view tests In-Reply-To: References: Message-ID: <57c63afe0804070740j916bcecw9aee8d5348e1b72c@mail.gmail.com> On Mon, Mar 24, 2008 at 12:38 PM, Joe Fiorini wrote: > 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? RSpec sets up mappings only for rhtml and html.erb views. You can add your own mappings to deal w/ haml if you like. Check this out: http://tinyurl.com/25xdey Cheers, David From rick.denatale at gmail.com Mon Apr 7 10:51:06 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 7 Apr 2008 10:51:06 -0400 Subject: [rspec-users] Advice / Turning a Usecase into a Rspec Story / Granularity ofstories In-Reply-To: References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <64B3E556-6A7C-4298-A9A9-C4BE941565F4@superinfinite.com> <1207214104.6571.23.camel@esw023.esw.eshopworks.co.uk> Message-ID: On Thu, Apr 3, 2008 at 10:59 AM, Ashley Moran wrote: > On 03/04/2008, Rick DeNatale wrote: > > > > > On the other hand. Keeping these finer grained scenarios within a > > single story allows branching using GivenScenario which only works > > with scenarios within the same story. > > Hi Rick > > I've never used GivenScenario - is there any documentation about it > available? Google only returns answers about JBehave. The only documentation I've seen was the answer which Dave C. gave here when I asked about nesting scenarios. That and the source code of course. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From dchelimsky at gmail.com Mon Apr 7 10:51:06 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 7 Apr 2008 10:51:06 -0400 Subject: [rspec-users] Comparing new models In-Reply-To: <00db40c5-1017-4416-b6b0-7c4944280c6a@h1g2000prh.googlegroups.com> References: <00db40c5-1017-4416-b6b0-7c4944280c6a@h1g2000prh.googlegroups.com> Message-ID: <57c63afe0804070751l3d3e6f56h749664dc87feb057@mail.gmail.com> On Sun, Apr 6, 2008 at 4:33 PM, Rare wrote: > Hi all, > > I am trying to test that a view file in Rails is being sent a new > empty model (Product.new) in my rspec test, below is my code. I've > tried comparing them with ==, ===, equal, eql none work. I just get an > error (see below code). I guess it's the condition tester (e.g. ==) > that is incorrect, can anyone help? > > Code: > > it "should assign the new product for the view" do > do_get > assigns[:product].should == Product.new > end Try this in irb: Product.new == Product.new => false This is why what you have is failing. What will work is something like this: it "should assign the new product for the view" do product = Object.new Product.should_receive(:new).and_return(product) do_get assigns[:product].should equal(product) end You can use product = Product.new for the first line, but I'm pretty sure Object.new is cheaper. HTH, David > > Error: > > 'ProductsController handling GET /products/new should assign the new > product for the view' FAILED > expected: # nil, price: nil, is_enabled: nil, created_at: nil, updated_at: nil, > manufacturer_id: nil>, > got: # nil, price: nil, is_enabled: nil, created_at: nil, updated_at: nil, > manufacturer_id: nil> (using ==) > ./spec/controllers/products_controller_spec.rb:118: > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Mon Apr 7 11:01:24 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 7 Apr 2008 16:01:24 +0100 Subject: [rspec-users] Netbeans and .story files In-Reply-To: <47F1E572.70600@sun.com> References: <47F1E572.70600@sun.com> Message-ID: On 01/04/2008, Martin Krauskopf wrote: > > Hi, > > yes, the .story extension is not supported out-of-the box. Unfortunately > it is not possible to extend Ruby file-type now: > > http://www.netbeans.org/issues/show_bug.cgi?id=116563 > > But easy to fix inside of NetBeans. I've just fixed it on my local > machine. I'll commit in few hours. Hi Martin Sounds good. As it happens I will be working from home for a while so I get to use my MacBook instead of Ubuntu, yay :D But I'm sure I will have to use NetBeans again soon so I'll appreciate your patch. BTW is the .story extension kind of "official" one? I saw in some > tutorials using .rb extension. Actually I've never been clear on this. I'd love a page on rspec.info that says This Is How You Should Name Your Files. Ashley -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080407/834a4a2d/attachment.html From pergesu at gmail.com Mon Apr 7 11:08:00 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 7 Apr 2008 08:08:00 -0700 Subject: [rspec-users] how should i test this code with rspec In-Reply-To: References: Message-ID: <810a540e0804070808u5ecc1cc8t9f034ef1593f087b@mail.gmail.com> On Mon, Mar 24, 2008 at 3:24 AM, nathan.wu wrote: > 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 categories = [mock_model(Category, :id => 1), mock_model(Category, :id => 2)] Category.should_receive(:find).with(:all).and_return categories mock just creates a mock object for you. mock_model makes it simulate the class name you pass it, and creates a default unique ID. Pat From bryansray at gmail.com Mon Apr 7 11:31:43 2008 From: bryansray at gmail.com (Bryan Ray) Date: Mon, 7 Apr 2008 10:31:43 -0500 Subject: [rspec-users] how to stub the :current_user and any methods associated with it In-Reply-To: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> References: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> Message-ID: <29a0119e0804070831v5198bff7qcc6f4a757578af4e@mail.gmail.com> Responses shown below... Sorry this isn't extremely informative ... in a bit of a rush. Hopefully it will point you in the appropriate direction. On Sun, Apr 6, 2008 at 2:17 PM, newbie wrote: > I'm new to Rspec and I'm having a bit of trouble with this controller > that I'm testing. I think I'm doing it right but I guess my syntax is > wrong. > I'm currently using the "acts_as_authenticated" plug in. > > What I want to test out is > > EventController on entering the tickets_page > - should show the tickets_page if the current_user has NOT entered > this page today > > > ----------------------------------------------------- > Below is my event controller > ----------------------------------------------------- > > class EventController < ApplicationController > > before_filter :login_required > > def tickets_page > if current_user.has_already_entered_today? > flash[:notice] = 'Come back tomorrow' > redirect_to :action => 'home' > else > flash[:notice] = 'Welcome' > end > end > end > > > ----------------------------------------------------- > Below is my rspec for this controller > ----------------------------------------------------- > > require File.dirname(__FILE__) + '/../spec_helper' > describe EventController do > > before(:each) do > @current_user = mock_model(User, :id => 1) > controller.stub!(:current_user).and_return(@current_user) > controller.stub!(:login_required).and_return(:true) > end > > fixtures :users > > > describe "on entering the tickets page" do > it "should show the tickets_page if the current_user has NOT > entered this page today" do > controller.current_user.stub! > (:has_already_entered_today?).and_return(:false) > get :tickets_page > > > controller.current_user.should_receive(:has_already_entered_today?).with(:false).and_return(:false) > response.should render_template(:tickets_page) > end > end > > end > > ----------------------------------------------------- > My errors > ----------------------------------------------------- > Mock 'User_1001' received unexpected > message :has_already_entered_today? with (no args) So this is a good start ... it means that the controller action is actually being mocked out ... you just need to keep moving forward mocking/stubbing out the rest of your controller actions. it's complaining that it doesn't know what to do on your *current_user.has_already_entered_today?* method. @current_user.stub!(:has_already_entered_today?).and_return() > > > > Anyone can help with any direction of what I might be doing wrong? > > > > > > _______________________________________________ > 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/20080407/3fc1fc06/attachment.html From lists at ruby-forum.com Mon Apr 7 12:17:34 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Mon, 7 Apr 2008 18:17:34 +0200 Subject: [rspec-users] Haml and View tests Message-ID: <7c162fe641a7ec2be29b82fc9d1620a8@ruby-forum.com> Does Rspec work nicely with Haml for controller integrated view tests? I am getting the following error: =================== ActionView::TemplateError in 'Admin::ListingsController index should get a 200 OK' undefined method `photo' for true:TrueClass On line #2 of admin/listings/_listing.html.haml 1: %tr 2: %td.photo= image_tag(listing.photo.url(:thumb), :class => :photo) Both photo and the photo.url are stubbed out. Thanks for the help. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Apr 7 15:14:50 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 7 Apr 2008 15:14:50 -0400 Subject: [rspec-users] Error testing rails controller In-Reply-To: References: Message-ID: <57c63afe0804071214h799eb3a5t363d83e2190bdeea@mail.gmail.com> On Fri, Apr 4, 2008 at 12:46 PM, Jacob wrote: > I am trying to test my controllers with RSpec and from the examples I > have found it is as easy as this: > > describe SessionsController do > > it "should render login template" do > get 'new' > response.should render_template(:login) > end Try 'login'. > > end > > > However both get and post raise "wrong number of arguments (2 for 1)". > I am working with 1.1.3, I rolled back to 1.1.2 and still suffer the > same fate. Any thoughts onto what may be causing this issue? > > Thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Apr 7 15:18:09 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 7 Apr 2008 15:18:09 -0400 Subject: [rspec-users] Netbeans and .story files In-Reply-To: References: <47F1E572.70600@sun.com> Message-ID: <57c63afe0804071218x70bbd500gd6889437abe249fb@mail.gmail.com> On Mon, Apr 7, 2008 at 11:01 AM, Ashley Moran wrote: > On 01/04/2008, Martin Krauskopf wrote: > > > Hi, > > > > yes, the .story extension is not supported out-of-the box. Unfortunately > > it is not possible to extend Ruby file-type now: > > > > http://www.netbeans.org/issues/show_bug.cgi?id=116563 > > > > But easy to fix inside of NetBeans. I've just fixed it on my local > > machine. I'll commit in few hours. > > > Hi Martin > > Sounds good. As it happens I will be working from home for a while so I get > to use my MacBook instead of Ubuntu, yay :D But I'm sure I will have to use > NetBeans again soon so I'll appreciate your patch. > > > > > BTW is the .story extension kind of "official" one? I saw in some > > tutorials using .rb extension. > > Actually I've never been clear on this. I'd love a page on rspec.info that > says This Is How You Should Name Your Files. There's a reason such a page does not exist. We are letting convention emerge rather than dictating it. That said, the convention that I see emerging is .rb for stories expressed in ruby and either no extension or .story for those expressed in plain text. HTH, David > > Ashley > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Mon Apr 7 15:55:51 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 7 Apr 2008 20:55:51 +0100 Subject: [rspec-users] Netbeans and .story files In-Reply-To: <57c63afe0804071218x70bbd500gd6889437abe249fb@mail.gmail.com> References: <47F1E572.70600@sun.com> <57c63afe0804071218x70bbd500gd6889437abe249fb@mail.gmail.com> Message-ID: On 7 Apr 2008, at 20:18, David Chelimsky wrote: > That said, the convention that I see emerging is .rb for stories > expressed in ruby and either no extension or .story for those > expressed in plain text. That's what I do - .story for the plain text file and .rb for the corresponding runner (not tried Kyle's runner yet) Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Mon Apr 7 16:01:09 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 7 Apr 2008 21:01:09 +0100 Subject: [rspec-users] Why do I have to require_dependency here? Message-ID: <7ABB3588-7FB7-497D-BBFD-663EBF43B525@patchspace.co.uk> Hi This was bugging the hell out of me until I found a fix just. I have been getting reams and reams of errors from reference to one model class in a controller spec. Here's one of the 57 that go wrong: 20) LoadError in 'UsersController PUT /users/:id when the model is invalid and there is no primary user issue and the user clicked Save should not assign the primary user issue to the view' Expected /Users/ashleymoran/Documents/TechnoPhobia/becta/apps/Backend/ app/models/user_state.rb to define UserState ./spec/controllers/users_controller_spec.rb:343: script/spec:4: But the weird thing is it ONLY happens when you run the spec in isolation. As part of a full autotest run, it's fine. The fix is to put this at the top of the controller file: require_dependency "user_state" Any idea what could be going wrong? It's not the first class loader issue I've hit, when I see a pattern I'll file a ticket. Just wondered if this was new to everyone here. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Mon Apr 7 16:08:11 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 7 Apr 2008 21:08:11 +0100 Subject: [rspec-users] Why do I have to require_dependency here? In-Reply-To: <7ABB3588-7FB7-497D-BBFD-663EBF43B525@patchspace.co.uk> References: <7ABB3588-7FB7-497D-BBFD-663EBF43B525@patchspace.co.uk> Message-ID: <26E5A3D9-A380-4746-ABFA-6A15E453D9FC@patchspace.co.uk> On 7 Apr 2008, at 21:01, Ashley Moran wrote: > The fix is to put this at the top of the controller file: > require_dependency "user_state" I spoke to soon :( This fixes it for a single controller run, but still breaks when autotest re-runs the one controller after making a change. Something's really wrong with class loading and I'm pretty sure it was introduced between 1.1.3 and r3333. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From dchelimsky at gmail.com Mon Apr 7 16:09:50 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 7 Apr 2008 16:09:50 -0400 Subject: [rspec-users] Why do I have to require_dependency here? In-Reply-To: <26E5A3D9-A380-4746-ABFA-6A15E453D9FC@patchspace.co.uk> References: <7ABB3588-7FB7-497D-BBFD-663EBF43B525@patchspace.co.uk> <26E5A3D9-A380-4746-ABFA-6A15E453D9FC@patchspace.co.uk> Message-ID: <57c63afe0804071309x371a5b4fnf94cfa8bfae0ee03@mail.gmail.com> On Mon, Apr 7, 2008 at 4:08 PM, Ashley Moran wrote: > > On 7 Apr 2008, at 21:01, Ashley Moran wrote: > > > The fix is to put this at the top of the controller file: > > require_dependency "user_state" > > > I spoke to soon :( > > This fixes it for a single controller run, but still breaks when > autotest re-runs the one controller after making a change. > Something's really wrong with class loading and I'm pretty sure it was > introduced between 1.1.3 and r3333. Did anything else change in your setup? Rails version? Autotest version? Just checking :) > > > > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Mon Apr 7 16:28:57 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 7 Apr 2008 21:28:57 +0100 Subject: [rspec-users] Why do I have to require_dependency here? In-Reply-To: <57c63afe0804071309x371a5b4fnf94cfa8bfae0ee03@mail.gmail.com> References: <7ABB3588-7FB7-497D-BBFD-663EBF43B525@patchspace.co.uk> <26E5A3D9-A380-4746-ABFA-6A15E453D9FC@patchspace.co.uk> <57c63afe0804071309x371a5b4fnf94cfa8bfae0ee03@mail.gmail.com> Message-ID: On 7 Apr 2008, at 21:09, David Chelimsky wrote: > Did anything else change in your setup? Rails version? Autotest > version? Just checking :) Hmm, can't think of anything. Rails has been 2.0.2 since I started, don't remember ever upgrading Autotest, at the very most it was 3.9.1 to 3.9.2 (but I think I always had 3.9.2 at work). I'm really puzzled what's going on... Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From lists at ruby-forum.com Mon Apr 7 17:14:06 2008 From: lists at ruby-forum.com (chris anderson) Date: Mon, 7 Apr 2008 23:14:06 +0200 Subject: [rspec-users] Need some help with a simple Message-ID: <0c608acab4afe5e9c06905621980a88a@ruby-forum.com> I can't figure out why this is failing. It seems to have a hard time assigning the @account. I have spent way too long trying to figure this out. Thanks for any help. ------- NoMethodError in 'StaffMembersController GET index should allow anonymous users' You have a nil object when you didn't expect it! The error occurred while evaluating nil.staff_members ------- ++++++++++++++++ describe StaffMembersController do describe "GET index" do before :each do @account = mock_model(Account, :staff_members => [mock_model(StaffMember)]) controller.stub!(:find_account_by_subdomain_or_url).and_return(@account) end # Authorization it "should allow anonymous users" do get :index response.should render_template(:index) end end end ++++++++++++++++ StaffMembersController ++++++++++++++++ class StaffMembersController < ApplicationController before_filter :find_account_by_subdomain_or_url def index @staff_members = @account.staff_members end end +++++++++++++++ -- Posted via http://www.ruby-forum.com/. From glenn at aldenta.com Mon Apr 7 17:31:23 2008 From: glenn at aldenta.com (Glenn Ford) Date: Mon, 7 Apr 2008 17:31:23 -0400 Subject: [rspec-users] Need some help with a simple In-Reply-To: <0c608acab4afe5e9c06905621980a88a@ruby-forum.com> References: <0c608acab4afe5e9c06905621980a88a@ruby-forum.com> Message-ID: I'm guessing the key is inside "find_account_by_subdomain_or_url". Do you have that defined somewhere? It probably calls something like: @account = Account.find_by_subdomain(blah) or Account.find_by_url(blah) In which case that's probably what you need to stub. Nothing is actually checking for the return value of the controller method or assigning it to @account. In other words, you probably should do Account.stub! instead of controller.stub! Check what's in that method and see if that gets you closer to the solution. Good luck! Glenn On Apr 7, 2008, at 5:14 PM, chris anderson wrote: > I can't figure out why this is failing. It seems to have a hard time > assigning the @account. I have spent way too long trying to figure > this > out. > > Thanks for any help. > > ------- > NoMethodError in 'StaffMembersController GET index should allow > anonymous users' > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.staff_members > ------- > > ++++++++++++++++ > describe StaffMembersController do > > describe "GET index" do > > before :each do > @account = mock_model(Account, :staff_members => > [mock_model(StaffMember)]) > controller.stub! > (:find_account_by_subdomain_or_url).and_return(@account) > end > > # Authorization > it "should allow anonymous users" do > get :index > response.should render_template(:index) > end > > end > end > ++++++++++++++++ > > StaffMembersController > ++++++++++++++++ > class StaffMembersController < ApplicationController > before_filter :find_account_by_subdomain_or_url > > def index > @staff_members = @account.staff_members > end > > end > +++++++++++++++ > -- > 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 Apr 7 17:54:48 2008 From: lists at ruby-forum.com (chris anderson) Date: Mon, 7 Apr 2008 23:54:48 +0200 Subject: [rspec-users] Need some help with a simple In-Reply-To: References: <0c608acab4afe5e9c06905621980a88a@ruby-forum.com> Message-ID: <52c2285df27ef59ca3e351720db50ed4@ruby-forum.com> Glenn Ford wrote: > I'm guessing the key is inside "find_account_by_subdomain_or_url". Do > you have that defined somewhere? It probably calls something like: > > @account = Account.find_by_subdomain(blah) or Account.find_by_url(blah) > > In which case that's probably what you need to stub. Nothing is > actually checking for the return value of the controller method or > assigning it to @account. In other words, you probably should do > Account.stub! instead of controller.stub! Check what's in that method > and see if that gets you closer to the solution. > > Good luck! > Glenn That worked. I was under the impression that there would be no subdomain available when testing, which is why I was stubbing the controller method. After it working I actually checked what the request.domain was and saw that it is test.host :) Thanks Glenn -- Posted via http://www.ruby-forum.com/. From tmhaines at gmail.com Mon Apr 7 19:11:17 2008 From: tmhaines at gmail.com (Tim Haines) Date: Tue, 8 Apr 2008 08:11:17 +0900 Subject: [rspec-users] Netbeans and .story files In-Reply-To: References: <47F1E572.70600@sun.com> <57c63afe0804071218x70bbd500gd6889437abe249fb@mail.gmail.com> Message-ID: I sent the netbeans guys a list of features for story support in netbeans. With luck they'll make it into the next version after 6.1. Feel free to go check it out and add to the list. :-) Cheers, Tim. On 8/04/2008, at 4:55, Ashley Moran wrote: > > On 7 Apr 2008, at 20:18, David Chelimsky wrote: > >> That said, the convention that I see emerging is .rb for stories >> expressed in ruby and either no extension or .story for those >> expressed in plain text. > > > That's what I do - .story for the plain text file and .rb for the > corresponding runner (not tried Kyle's runner yet) > > Ashley > > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From loop at superinfinite.com Tue Apr 8 06:25:59 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Tue, 8 Apr 2008 12:25:59 +0200 Subject: [rspec-users] rSpec, Selenium and screenshots Message-ID: Hey list, I'm currently playing with the selenium acceptance test-thingies, and I want to build something that saves a screenshot when a test fails. However, I have no clue whatsoever where to implement this. I'm thinking it should be along the line of: - apply a general after_each, in which we - check whether we were using selenium (no idea how yet), and - if an error occured, take a screenshot, and save it somewhere Any ideas? thanks a bunch, bartz From omen.king at gmail.com Tue Apr 8 06:29:39 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Tue, 8 Apr 2008 06:29:39 -0400 Subject: [rspec-users] rSpec, Selenium and screenshots In-Reply-To: References: Message-ID: Doesn't Selenium already do that? Mine takes screenshots on failure. On Tue, Apr 8, 2008 at 6:25 AM, Bart Zonneveld wrote: > Hey list, > > I'm currently playing with the selenium acceptance test-thingies, and > I want to build something that saves a screenshot when a test fails. > However, I have no clue whatsoever where to implement this. I'm > thinking it should be along the line of: > - apply a general after_each, in which we > - check whether we were using selenium (no idea how yet), and > - if an error occured, take a screenshot, and save it somewhere > > Any ideas? > thanks a bunch, > bartz > _______________________________________________ > 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/20080408/c7853e23/attachment.html From dchelimsky at gmail.com Tue Apr 8 07:27:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 8 Apr 2008 07:27:21 -0400 Subject: [rspec-users] rSpec, Selenium and screenshots In-Reply-To: References: Message-ID: <57c63afe0804080427t70a7634ck4b3e6403697f19de@mail.gmail.com> On Tue, Apr 8, 2008 at 6:29 AM, Andrew WC Brown wrote: > On Tue, Apr 8, 2008 at 6:25 AM, Bart Zonneveld > wrote: > > > Hey list, > > > > I'm currently playing with the selenium acceptance test-thingies, and > > I want to build something that saves a screenshot when a test fails. > > However, I have no clue whatsoever where to implement this. I'm > > thinking it should be along the line of: > > - apply a general after_each, in which we > > - check whether we were using selenium (no idea how yet), and > > - if an error occured, take a screenshot, and save it somewhere > > > > Any ideas? > > thanks a bunch, > > bartz > Doesn't Selenium already do that? > Mine takes screenshots on failure. Selenium does support this but I don't think it's automatic. spec_ui (part of rspec-exts at rubyforge) automates this, but it's quite dated and doesn't work w/ the current rspec. I know Aslak has something working with WATIR and the current RSpec, but has yet to open source it. All this to say that we will be supporting this, likely in an updated spec_ui. Just a matter of when. Cheers, David From lists at ruby-forum.com Tue Apr 8 07:36:21 2008 From: lists at ruby-forum.com (Phillip Koebbe) Date: Tue, 8 Apr 2008 13:36:21 +0200 Subject: [rspec-users] rspec controller action list In-Reply-To: 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: I'm a complete rSpec newbie, so I might be stepping in somewhere that I don't belong, but... Namatra, you said earlier that you were stubbing during setup, and you shared the before_post method. In the spec, though, you are going a :get. I'm not familiar with testing controllers yet (just getting into that today, in fact), so I don't know if there is a before_get. Could that be part of your problem: confusing GETs and POSTs? Peace, Phillip -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Apr 8 07:37:19 2008 From: lists at ruby-forum.com (Phillip Koebbe) Date: Tue, 8 Apr 2008 13:37:19 +0200 Subject: [rspec-users] rspec controller action list In-Reply-To: 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: Phillip Koebbe wrote: > > Namatra, Sorry, I spelled your name wrong. Namrata Peace, Phillip -- Posted via http://www.ruby-forum.com/. From mark.ryall at gmail.com Tue Apr 8 07:49:15 2008 From: mark.ryall at gmail.com (Mark Ryall) Date: Tue, 8 Apr 2008 21:49:15 +1000 Subject: [rspec-users] rSpec, Selenium and screenshots In-Reply-To: <57c63afe0804080427t70a7634ck4b3e6403697f19de@mail.gmail.com> References: <57c63afe0804080427t70a7634ck4b3e6403697f19de@mail.gmail.com> Message-ID: <43769a4a0804080449s26022e57o4200bf43da626677@mail.gmail.com> If you're using mac os x, you could give http://mosquito.the.tool.googlepages.com a try. On Tue, Apr 8, 2008 at 9:27 PM, David Chelimsky wrote: > On Tue, Apr 8, 2008 at 6:29 AM, Andrew WC Brown > wrote: > > > On Tue, Apr 8, 2008 at 6:25 AM, Bart Zonneveld > > wrote: > > > > > Hey list, > > > > > > I'm currently playing with the selenium acceptance test-thingies, and > > > I want to build something that saves a screenshot when a test fails. > > > However, I have no clue whatsoever where to implement this. I'm > > > thinking it should be along the line of: > > > - apply a general after_each, in which we > > > - check whether we were using selenium (no idea how yet), and > > > - if an error occured, take a screenshot, and save it somewhere > > > > > > Any ideas? > > > thanks a bunch, > > > bartz > > > Doesn't Selenium already do that? > > Mine takes screenshots on failure. > > Selenium does support this but I don't think it's automatic. spec_ui > (part of rspec-exts at rubyforge) automates this, but it's quite dated > and doesn't work w/ the current rspec. I know Aslak has something > working with WATIR and the current RSpec, but has yet to open source > it. > > All this to say that we will be supporting this, likely in an updated > spec_ui. Just a matter of when. > > Cheers, > 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/20080408/b0b4c15d/attachment.html From omen.king at gmail.com Tue Apr 8 08:03:37 2008 From: omen.king at gmail.com (Andrew WC Brown) Date: Tue, 8 Apr 2008 08:03:37 -0400 Subject: [rspec-users] rSpec, Selenium and screenshots In-Reply-To: <43769a4a0804080449s26022e57o4200bf43da626677@mail.gmail.com> References: <57c63afe0804080427t70a7634ck4b3e6403697f19de@mail.gmail.com> <43769a4a0804080449s26022e57o4200bf43da626677@mail.gmail.com> Message-ID: I used Selenium with Rpsec less than a month ago.Could you not just roll back a few version? On Tue, Apr 8, 2008 at 7:49 AM, Mark Ryall wrote: > If you're using mac os x, you could give > http://mosquito.the.tool.googlepages.com a try. > > On Tue, Apr 8, 2008 at 9:27 PM, David Chelimsky > wrote: > > > On Tue, Apr 8, 2008 at 6:29 AM, Andrew WC Brown > > wrote: > > > > > On Tue, Apr 8, 2008 at 6:25 AM, Bart Zonneveld > > > > > wrote: > > > > > > > Hey list, > > > > > > > > I'm currently playing with the selenium acceptance test-thingies, > > and > > > > I want to build something that saves a screenshot when a test fails. > > > > However, I have no clue whatsoever where to implement this. I'm > > > > thinking it should be along the line of: > > > > - apply a general after_each, in which we > > > > - check whether we were using selenium (no idea how yet), and > > > > - if an error occured, take a screenshot, and save it somewhere > > > > > > > > Any ideas? > > > > thanks a bunch, > > > > bartz > > > > > Doesn't Selenium already do that? > > > Mine takes screenshots on failure. > > > > Selenium does support this but I don't think it's automatic. spec_ui > > (part of rspec-exts at rubyforge) automates this, but it's quite dated > > and doesn't work w/ the current rspec. I know Aslak has something > > working with WATIR and the current RSpec, but has yet to open source > > it. > > > > All this to say that we will be supporting this, likely in an updated > > spec_ui. Just a matter of when. > > > > 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/20080408/6c627d98/attachment.html From loop at superinfinite.com Tue Apr 8 08:09:28 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Tue, 8 Apr 2008 14:09:28 +0200 Subject: [rspec-users] rSpec, Selenium and screenshots In-Reply-To: References: <57c63afe0804080427t70a7634ck4b3e6403697f19de@mail.gmail.com> <43769a4a0804080449s26022e57o4200bf43da626677@mail.gmail.com> Message-ID: <5188511E-DB59-4AAB-BE59-F653BCD72FEF@superinfinite.com> On 8-apr-2008, at 14:03, Andrew WC Brown wrote: > I used Selenium with Rpsec less than a month ago. > Could you not just roll back a few version? Nah, I'd rather ditch selenium altogether. It doesn't play that very nice with Safari, and Firefox needs too much time to start up. I guess I'll stick to webrat and a irl QA dude (me, mostly) for the time being. thanks though, bartz > > On Tue, Apr 8, 2008 at 7:49 AM, Mark Ryall > wrote: > If you're using mac os x, you could give http:// > mosquito.the.tool.googlepages.com a try. > > On Tue, Apr 8, 2008 at 9:27 PM, David Chelimsky > wrote: > On Tue, Apr 8, 2008 at 6:29 AM, Andrew WC Brown > wrote: > > > On Tue, Apr 8, 2008 at 6:25 AM, Bart Zonneveld > > > wrote: > > > > > Hey list, > > > > > > I'm currently playing with the selenium acceptance test- > thingies, and > > > I want to build something that saves a screenshot when a test > fails. > > > However, I have no clue whatsoever where to implement this. I'm > > > thinking it should be along the line of: > > > - apply a general after_each, in which we > > > - check whether we were using selenium (no idea how yet), and > > > - if an error occured, take a screenshot, and save it somewhere > > > > > > Any ideas? > > > thanks a bunch, > > > bartz > > > Doesn't Selenium already do that? > > Mine takes screenshots on failure. > > Selenium does support this but I don't think it's automatic. spec_ui > (part of rspec-exts at rubyforge) automates this, but it's quite dated > and doesn't work w/ the current rspec. I know Aslak has something > working with WATIR and the current RSpec, but has yet to open source > it. > > All this to say that we will be supporting this, likely in an updated > spec_ui. Just a matter of when. > > 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 From somanyfishes at gmail.com Tue Apr 8 09:06:04 2008 From: somanyfishes at gmail.com (SoManyFishes) Date: Tue, 08 Apr 2008 09:06:04 -0400 Subject: [rspec-users] TextMate bundle not using environment variable to find Ruby library Message-ID: <47FB6DBC.90304@gmail.com> Something is going on in my TextMate bundle--it's calling the wrong lib for Ruby. I have the environment variables set like this: > > TM_RSPEC_HOME /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.3 > TM_RUBY /usr/local/bin/ruby When I run these queries in a TextMate window I get this: > which ruby > /usr/local/bin/ruby > which rails > /usr/local/bin/rails But still when I try to run a spec in TextMate, I get this: > /usr/lib/ruby/site_ruby/1.8/rubygems.rb:377:in > `report_activate_error': Could not find RubyGem rails (>= 0) > (Gem::LoadError) from > /usr/lib/ruby/site_ruby/1.8/rubygems.rb:309:in `activate' from > /usr/lib/ruby/site_ruby/1.8/rubygems.rb:76:in > `active_gem_with_options' from > /usr/lib/ruby/site_ruby/1.8/rubygems.rb:50:in `gem' from > /Users/lisasawin/Rails Web Applications/CHC/config/boot.rb:39 from > /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `gem_original_require' from > /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' > from /Users/lisasawin/Rails Web Applications > /CHC/config/environment.rb:11 from > /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `gem_original_require' ... 15 levels... from > /Users/lisasawin/Library/Application > Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/runner.rb:31:in > `chdir' from > /Users/lisasawin/Library/Application > Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/runner.rb:31:in > `run' from > /Users/lisasawin/Library/Application > Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/runner.rb:14:in > `run_file' from /tmp/temp_textmate.zQ2Hv1:4 How can I get TextMate to use the library in usr/local/bin/ruby instead of looking in usr/local/bin/ruby? Thanks so much for any help! Lisa From lists at ruby-forum.com Tue Apr 8 10:03:13 2008 From: lists at ruby-forum.com (Giuseppe Bertini) Date: Tue, 8 Apr 2008 16:03:13 +0200 Subject: [rspec-users] how to mock/stub restful_authenticated and acl2-ized actions Message-ID: Dear all, I am wondering how to properly mock/stub out the preliminary steps to actions protected by restful_authentication and acl_system2 (role-based authorization to execute actions). Here's my setup: class User < ActiveRecord::Base has_and_belongs_to_many :roles has_many :tasks [snip] end class Task < ActiveRecord::Base belongs_to :user end I also have a Role class that habtm :users Now, for the controller that I need to spec: class TasksController < ApplicationController before_filter :login_required access_control :DEFAULT => 'operator' def index @tasks = current_user.tasks end end Two interesting things happen here. First, access to the index action is only granted after checking that the user is logged-in *and* that she is an 'operator'. Second, the tasks method is called on current_user, which is available to all controllers that include AuthenticatedSystem. I can easily write a few specs for this controller if I use a fixture_scenario and login_as (see below). On the other hand, I am trying to learn to abide to the "hey, dont touch that!" database thing. As a novice, the task of setting up examples in which authentication & authorization are satisfied, and where current_user still responds properly appears daunting. But then again, I *am* a novice! Thank you all in advance, Giuseppe ############### # my current specs ############### include AuthenticatedTestHelper describe TasksController, "with a logged-in user having 'operator' privileges" do scenario :users_and_roles before(:each) do login_as :giuseppe # based on the fixtures, giuseppe is now a logged-in operator end describe "getting the index" do before(:each) do @tasks = mock_model(Task) Task.stub!(:find).and_return([@tasks]) end it "should render index" do get :index response.should render_template('index') end it "should assign to the @tasks instance variable" do get :index assigns[:tasks].should ==[@tasks] end end end -- Posted via http://www.ruby-forum.com/. From pluskid at gmail.com Tue Apr 8 11:53:14 2008 From: pluskid at gmail.com (Chiyuan Zhang) Date: Tue, 8 Apr 2008 23:53:14 +0800 Subject: [rspec-users] Can you add an option to select the ruby interpreter for rake task? Message-ID: Hi all, My problem is that I've installed both ruby 1.8 (as ruby) and ruby 1.9 (as ruby1.9) on my system. I use spec/rake/spectask for my Rakefile. But the generated command is ruby -I.. blabla it should be "ruby1.9 -I... blabla", but after look at the code of spectask.rb, I found this line: ==> cmd = "ruby " rb_opts = ruby_opts.clone rb_opts << "-I\"#{lib_path}\"" rb_opts << "-S rcov" if rcov rb_opts << "-w" if warning The "ruby" is hard-coded into it. May I request this to be an customizable option so that I can set it to "ruby1.9"? -- pluskid From glenn at aldenta.com Tue Apr 8 12:13:00 2008 From: glenn at aldenta.com (Glenn Ford) Date: Tue, 8 Apr 2008 12:13:00 -0400 Subject: [rspec-users] how to mock/stub restful_authenticated and acl2-ized actions In-Reply-To: References: Message-ID: While my approach might not be the best, since I don't stub :login_required, it still serves me well. I would do something like this: user = mock_model(User, :operator => true) controller.stub!(:current_user).and_return(user) login_required will find the 'current_user' and be happy. I don't know if the :operator => true thing will cut it for your other check, but that should get you on the right track. I hope that helps! Glenn On Apr 8, 2008, at 10:03 AM, Giuseppe Bertini wrote: > Dear all, > > I am wondering how to properly mock/stub out the preliminary steps to > actions protected by restful_authentication and acl_system2 (role- > based > authorization to execute actions). Here's my setup: > > class User < ActiveRecord::Base > has_and_belongs_to_many :roles > has_many :tasks > [snip] > end > > class Task < ActiveRecord::Base > belongs_to :user > end > > I also have a Role class that habtm :users > > Now, for the controller that I need to spec: > > class TasksController < ApplicationController > before_filter :login_required > access_control :DEFAULT => 'operator' > > def index > @tasks = current_user.tasks > end > end > > Two interesting things happen here. First, access to the index > action is > only granted after checking that the user is logged-in *and* that > she is > an 'operator'. Second, the tasks method is called on current_user, > which > is available to all controllers that include AuthenticatedSystem. > > I can easily write a few specs for this controller if I use a > fixture_scenario and login_as (see below). On the other hand, I am > trying to learn to abide to the "hey, dont touch that!" database > thing. > As a novice, the task of setting up examples in which authentication & > authorization are satisfied, and where current_user still responds > properly appears daunting. But then again, I *am* a novice! > > Thank you all in advance, > Giuseppe > > > ############### > # my current specs > ############### > include AuthenticatedTestHelper > describe TasksController, "with a logged-in user having 'operator' > privileges" do > scenario :users_and_roles > before(:each) do > login_as :giuseppe # based on the fixtures, giuseppe is now a > logged-in operator > end > > describe "getting the index" do > > before(:each) do > @tasks = mock_model(Task) > Task.stub!(:find).and_return([@tasks]) > end > > it "should render index" do > get :index > response.should render_template('index') > end > > it "should assign to the @tasks instance variable" do > get :index > assigns[:tasks].should ==[@tasks] > end > end > end > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Tue Apr 8 12:21:50 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 8 Apr 2008 09:21:50 -0700 Subject: [rspec-users] Can you add an option to select the ruby interpreter for rake task? In-Reply-To: References: Message-ID: <810a540e0804080921i3b456635q3d8c67a80f6d2305@mail.gmail.com> On Tue, Apr 8, 2008 at 8:53 AM, Chiyuan Zhang wrote: > The "ruby" is hard-coded into it. May I request this to be an > customizable option so that I can set it to "ruby1.9"? Please file a ticket at http://rspec.lighthouseapp.com Pat From pluskid at gmail.com Tue Apr 8 12:36:46 2008 From: pluskid at gmail.com (Chiyuan Zhang) Date: Wed, 9 Apr 2008 00:36:46 +0800 Subject: [rspec-users] Can you add an option to select the ruby interpreter for rake task? In-Reply-To: <810a540e0804080921i3b456635q3d8c67a80f6d2305@mail.gmail.com> References: <810a540e0804080921i3b456635q3d8c67a80f6d2305@mail.gmail.com> Message-ID: OK, done: http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/370-add-an-option-for-rake-task-to-select-ruby-interpreter On Wed, Apr 9, 2008 at 12:21 AM, Pat Maddox wrote: > On Tue, Apr 8, 2008 at 8:53 AM, Chiyuan Zhang wrote: > > The "ruby" is hard-coded into it. May I request this to be an > > customizable option so that I can set it to "ruby1.9"? > > Please file a ticket at http://rspec.lighthouseapp.com > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- pluskid From coreyhaines at gmail.com Tue Apr 8 14:51:08 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Tue, 8 Apr 2008 14:51:08 -0400 Subject: [rspec-users] Advice / Turning a Usecase into a Rspec Story / Granularity ofstories In-Reply-To: <57c63afe0804030531i49dcc4es58a2277128872aed@mail.gmail.com> References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <64B3E556-6A7C-4298-A9A9-C4BE941565F4@superinfinite.com> <1207214104.6571.23.camel@esw023.esw.eshopworks.co.uk> <10B4C604-ACB3-4E30-8DA1-20246DFDD135@superinfinite.com> <57c63afe0804030531i49dcc4es58a2277128872aed@mail.gmail.com> Message-ID: <6bdacb70804081151l3da8d577g2c673fc59ae413c@mail.gmail.com> +1 on sheer awesomeness of this presentation! Thanks for sending the slides out! We are struggling/actively discussing our use of plain text stories, and this really adds a lot to our conversation. thanks. -Corey On Thu, Apr 3, 2008 at 8:31 AM, David Chelimsky wrote: > On Thu, Apr 3, 2008 at 8:25 AM, Bart Zonneveld > wrote: > > > > > > On 3-apr-2008, at 14:12, Rick DeNatale wrote: > > > On Thu, Apr 3, 2008 at 5:34 AM, Ashley Moran > > > wrote: > > >> On 03/04/2008, joseph wrote: > > >> > > >>> > > >>> Example Story (High level): > > >>> > > >>> Story: Web admin manages pages within the admin system > > >>> Scenario: Add page > > >>> Scenario: edit page. > > >>> Scenario: delete page. > > > > > >> This seems too coarse to me. The controller I'm working on now > > >> will end up > > >> with a corresponding story for each of your scenarios. My > > >> scenarios are > > >> along the lines of "User edits page with valid details", "User > > >> edits page > > >> with missing details", "User edits page and clicks cancel", "User > > >> with > > >> insufficient priveleges tries to delete page" etc. I try to make > > >> a scenario > > >> for each common or complex thing that changes the state of the > > >> system - they > > >> would never fit in one story. > > > > > > On the other hand. Keeping these finer grained scenarios within a > > > single story allows branching using GivenScenario which only works > > > with scenarios within the same story. > > > > I am having the same struggles with the granularity. Is there a good > > "sample" app out there on the interweb? > > Or perhaps someone from the list wants to share their story? :) > > I addressed this in my talk at ETEC last week. Slides are here: > > http://www.chariotsolutions.com/slides/pdfs/ete2008-IntegrationTestingWithRSpec.pdf > > Cheers, > David > _______________________________________________ > 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/20080408/ff07eed9/attachment.html From backslash451 at yahoo.it Tue Apr 8 16:06:19 2008 From: backslash451 at yahoo.it (roberto belardo) Date: Tue, 8 Apr 2008 22:06:19 +0200 (CEST) Subject: [rspec-users] Rspecing this simple controller it is driving me mad... In-Reply-To: <8556DEF6-0CD1-423E-8639-D1F5975F8109@jlaine.net> Message-ID: <105928.11359.qm@web27013.mail.ukl.yahoo.com> Everything seemed so fine, but when i tried to investigate a little i discovered this tremendous behaviour of the spec: ------------------------------- CommentsController def create @comment = Comment.new(params[:comment]) @user = User.find(params[:user_id]) @comment.author = 'foooooobar' @comment.save end ------------------------------- CommentsController Spec describe CommentsController, "handling POST/comments" do before(:each) do @user = mock_model(User, :to_param => "2") @comment = mock_model(Comment, :to_param => "1", :author => @user) User.should_receive(:find).at_least(1).times.and_return(@user) Comment.stub!(:new).and_return(@comment) @comment.stub!(:author=) end def post_with_successful_save @comment.should_receive(:save).and_return(true) @comment.should_receive(:author=) post :create, :user_id => @user_id, :comment => {} end it "should create a new comment" do Comment.should_receive(:new).with({}).and_return(@comment) post_with_successful_save @comment.author.should be(@user) end end ------------------------------- Autotest: ... 0 failures How can the spec pass if i test that @comment.author should be @user but in the controller i set a fooooobar string in the @comment.author? Better question: wich is the right way to test that create action to be sure, it will set the author of the comment? --- Jarkko Laine ha scritto: ... > Short answer: you haven't stubbed the author= method > for the comment > mock, only author. > > A bit longer answer: Are you sure you can trust the > user to only > submit valid user ids? With your current code, > anyone can change the > user_id parameter in the call and fake any user id > she wants. This > might be intentional (if there are only admin users > in your app), just > pointing it out. You can also simplify your action > by just saying > @user.comments.create(params[:comment]) once you > have the user fetched. > > Cheers, > //jarkko > > > > > Thanks in advance, > > Roberto. > > > > > > Inviato da Yahoo! Mail. > > La casella di posta intelligente. > > 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 > > -- > Jarkko Laine > http://jlaine.net > http://dotherightthing.com > http://www.railsecommerce.com > http://odesign.fi > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Inviato da Yahoo! Mail. La casella di posta intelligente. http://it.docs.yahoo.com/mail/overview/index.html From lists at ruby-forum.com Tue Apr 8 16:17:02 2008 From: lists at ruby-forum.com (Giuseppe Bertini) Date: Tue, 8 Apr 2008 22:17:02 +0200 Subject: [rspec-users] how to mock/stub restful_authenticated and acl2-ized act In-Reply-To: References: Message-ID: <5681966a8f890d45135ef4cf6cbdd47a@ruby-forum.com> Hi Glenn, thanks for the response. > I would do something like this: > > user = mock_model(User, :operator => true) > controller.stub!(:current_user).and_return(user) OK, so, :operator is not a User attribute. Rather, a user is an operator, so to speak, if a habtm relationship exists between the user and the role titled 'operator'. If I modify your code like this: role = mock_model(Role, :title => 'operator') user = mock_model(User, :roles => [role]) controller.stub!(:current_user).and_return(user) things appear to be working well. Thank you again for your help! Giuseppe -- Posted via http://www.ruby-forum.com/. From jarkko at jlaine.net Tue Apr 8 16:35:08 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Tue, 8 Apr 2008 23:35:08 +0300 Subject: [rspec-users] Rspecing this simple controller it is driving me mad... In-Reply-To: <105928.11359.qm@web27013.mail.ukl.yahoo.com> References: <105928.11359.qm@web27013.mail.ukl.yahoo.com> Message-ID: <228A8C93-70E7-40DD-B70D-77DA656D5D32@jlaine.net> On 8.4.2008, at 23.06, roberto belardo wrote: > Everything seemed so fine, but when i tried to > investigate a little i discovered this tremendous > behaviour of the spec: > > ------------------------------- CommentsController > def create > @comment = Comment.new(params[:comment]) > @user = User.find(params[:user_id]) > @comment.author = 'foooooobar' > @comment.save > end > > ------------------------------- CommentsController > Spec > describe CommentsController, "handling POST/comments" > do > before(:each) do > @user = mock_model(User, :to_param => "2") > @comment = mock_model(Comment, :to_param => "1", > :author => @user) > > User.should_receive(:find).at_least(1).times.and_return(@user) > Comment.stub!(:new).and_return(@comment) > @comment.stub!(:author=) > end > > def post_with_successful_save > @comment.should_receive(:save).and_return(true) > @comment.should_receive(:author=) > post :create, :user_id => @user_id, :comment => {} > end > > it "should create a new comment" do > > Comment.should_receive(:new).with({}).and_return(@comment) > post_with_successful_save > @comment.author.should be(@user) > end > end > > ------------------------------- Autotest: > ... 0 failures > > How can the spec pass if i test that @comment.author > should be @user but in the controller i set a > fooooobar string in the @comment.author? Because @comment.should_receive(:author=) stubs the method so it has no effect after that. I would advice against using it in a general purpose helper such as post_with_successful_save and instead use it in an actual spec if needed. > > Better question: wich is the right way to test that > create action to be sure, it will set the author of > the comment? Since you're testing that "@comment.author.should be(@user)", I see no reason to explicitly have "@comment.should_receive(:author=)". The former correctly tests the behaviour, whereas the latter checks the actual implementation, which in this case is superfluous. I hardly ever use should_receive with a setter method such as author=, but it might just be me. Cheers, //jarkko > > > > --- Jarkko Laine ha scritto: > > ... > >> Short answer: you haven't stubbed the author= method >> for the comment >> mock, only author. >> >> A bit longer answer: Are you sure you can trust the >> user to only >> submit valid user ids? With your current code, >> anyone can change the >> user_id parameter in the call and fake any user id >> she wants. This >> might be intentional (if there are only admin users >> in your app), just >> pointing it out. You can also simplify your action >> by just saying >> @user.comments.create(params[:comment]) once you >> have the user fetched. >> >> Cheers, >> //jarkko >> >>> >>> Thanks in advance, >>> Roberto. >>> >>> >>> Inviato da Yahoo! Mail. >>> La casella di posta intelligente. >>> 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 >> >> -- >> Jarkko Laine >> http://jlaine.net >> http://dotherightthing.com >> http://www.railsecommerce.com >> http://odesign.fi >> >> >>> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > Inviato da Yahoo! Mail. > La casella di posta intelligente. > 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 -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available Url : http://rubyforge.org/pipermail/rspec-users/attachments/20080408/3b54af44/attachment.bin From jarkko at jlaine.net Tue Apr 8 16:40:20 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Tue, 8 Apr 2008 23:40:20 +0300 Subject: [rspec-users] how to mock/stub restful_authenticated and acl2-ized act In-Reply-To: <5681966a8f890d45135ef4cf6cbdd47a@ruby-forum.com> References: <5681966a8f890d45135ef4cf6cbdd47a@ruby-forum.com> Message-ID: <14784D57-7E86-4789-B970-0D2DF0E5157A@jlaine.net> On 8.4.2008, at 23.17, Giuseppe Bertini wrote: > Hi Glenn, thanks for the response. > >> I would do something like this: >> >> user = mock_model(User, :operator => true) >> controller.stub!(:current_user).and_return(user) > > OK, so, :operator is not a User attribute. Rather, a user is an > operator, so to speak, if a habtm relationship exists between the user > and the role titled 'operator'. If I modify your code like this: > > role = mock_model(Role, :title => 'operator') > user = mock_model(User, :roles => [role]) > controller.stub!(:current_user).and_return(user) > > things appear to be working well. > Thank you again for your help! You might want to take that one step further and create a method such as has_role?(:operator) for the user class. That way you don't have to stub arrays like roles in your specs, you just stub that method to return true or false and you're done. That way you make your code more easily "speccable": def has_role?(role) roles.map(&:title).include?(role.to_s) end //jarkko > > > Giuseppe > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available Url : http://rubyforge.org/pipermail/rspec-users/attachments/20080408/a432b19c/attachment.bin From lists at ruby-forum.com Tue Apr 8 17:42:27 2008 From: lists at ruby-forum.com (Giuseppe Bertini) Date: Tue, 8 Apr 2008 23:42:27 +0200 Subject: [rspec-users] how to mock/stub restful_authenticated and acl2-ized act In-Reply-To: <14784D57-7E86-4789-B970-0D2DF0E5157A@jlaine.net> References: <5681966a8f890d45135ef4cf6cbdd47a@ruby-forum.com> <14784D57-7E86-4789-B970-0D2DF0E5157A@jlaine.net> Message-ID: Hi Jarkko, I see your point. However, checking the user's roles in order to authorize access to the action is done behind the scenes by the acl_system2 plugin, which would not know what to do with has_role?, unless I am missing something. Thanks! Giuseppe > You might want to take that one step further and create a method such > as has_role?(:operator) for the user class. That way you don't have to > stub arrays like roles in your specs, you just stub that method to > return true or false and you're done. That way you make your code more > easily "speccable": > > def has_role?(role) > roles.map(&:title).include?(role.to_s) > end > > //jarkko -- Posted via http://www.ruby-forum.com/. From me at danielfischer.com Tue Apr 8 21:20:46 2008 From: me at danielfischer.com (Fischer, Daniel) Date: Tue, 8 Apr 2008 18:20:46 -0700 Subject: [rspec-users] Autotest RSpec Not Running on Model Save's? In-Reply-To: <004d96df9231df88906e1dbfdeac64d6@ruby-forum.com> References: <7e565b5c0804031717l15f63d57w17c57a2cd6657817@mail.gmail.com> <004d96df9231df88906e1dbfdeac64d6@ruby-forum.com> Message-ID: <7e565b5c0804081820w7d6b2d16q88c9eb53e3cb3495@mail.gmail.com> Yea a fix would be amazing. This is knda annoying because now I have to press ctrl-c or something to run that spec. On Sun, Apr 6, 2008 at 12:36 PM, Willem K?llman wrote: > Same problem here, but I guess it has nothing to do with RSpec or the > fact that you are testing a model. Instead, Autotest seems to misbehave. > > Say we have a project directory with these contents: > lib/script.rb > spec/spec_script.rb > spec/spec.opts > > The following is what Autotest does on my system: > After running '$ autotest' > and changing the contents of spec_script.rb, Autotest invokes > //ruby -S //rspec-1.1.3/bin/spec -O > spec/spec.opts spec/spec_script.rb > Which is perfectly fine. > However, when I edit and save script.rb, Autotest will call 'spec' > without specifying a file: //ruby -S > //rspec-1.1.3/bin/spec -O > Just as you described it. > > I'd really love to hear some ideas on how to fix this. Thank you! > -- > 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/20080408/bd6004ab/attachment.html From cflipse at gmail.com Tue Apr 8 22:03:00 2008 From: cflipse at gmail.com (Chris Flipse) Date: Tue, 8 Apr 2008 22:03:00 -0400 Subject: [rspec-users] how to mock/stub restful_authenticated and acl2-ized actions In-Reply-To: References: Message-ID: On Tue, Apr 8, 2008 at 10:03 AM, Giuseppe Bertini wrote: > Dear all, > > I am wondering how to properly mock/stub out the preliminary steps to > actions protected by restful_authentication and acl_system2 (role-based > authorization to execute actions). Here's my setup: > I use a different authorization plugin, so you might have to adapt, but I've got the following in my spec_helper: def as_role(roles = []) returning User.new do |user| # This will become stub_model whenever 1.1.4 comes out ... user.id = 2000 user.stub!(:new_record?).and_return false user.stub!(:valid?).and_return true if @controller @controller.stub!(:login_required).and_return true @controller.stub!(:current_user).and_return true @controller.stub!(:logged_in?).and_return true end user.stub!(:has_role?).and_return false # because has_role? hits the DB [*roles].map(&:to_s).each do |role| user.stub!("is_#{role}?").and_return true user.stub!(:has_role?).with(role).and_return true end end end alias :logged_in :as_role This returns a User, and can be used in either the controller or in model specs, to deal with various aspects of a roled user. You can call it with an array of roles, or a single role; it deals with it either way. The last alias is because logged_in looks better than as_role without any arguments. -- // anything worth taking seriously is worth making fun of // http://blog.devcaffeine.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080408/386d7bbd/attachment-0001.html From george at benevolentcode.com Tue Apr 8 22:16:39 2008 From: george at benevolentcode.com (George Anderson) Date: Tue, 8 Apr 2008 22:16:39 -0400 Subject: [rspec-users] i can haz buk? Message-ID: <782d66f30804081916w78a71c3em33f9bf0ff71ce6af@mail.gmail.com> David, Aslak, Any word on the most eagerly anticipated book ever? /g -- George Anderson BenevolentCode LLC From dchelimsky at gmail.com Tue Apr 8 22:21:03 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 8 Apr 2008 22:21:03 -0400 Subject: [rspec-users] i can haz buk? In-Reply-To: <782d66f30804081916w78a71c3em33f9bf0ff71ce6af@mail.gmail.com> References: <782d66f30804081916w78a71c3em33f9bf0ff71ce6af@mail.gmail.com> Message-ID: <57c63afe0804081921r35af27a4ne5a16428b8508d2d@mail.gmail.com> On Tue, Apr 8, 2008 at 10:16 PM, George Anderson wrote: > David, Aslak, > > Any word on the most eagerly anticipated book ever? Close to beta where: two.weeks < close < three.months I know it's a wide range, but everyone involved is quite busy. Getting closer though. Cheers, David From george at benevolentcode.com Tue Apr 8 22:31:41 2008 From: george at benevolentcode.com (George Anderson) Date: Tue, 8 Apr 2008 22:31:41 -0400 Subject: [rspec-users] i can haz buk? In-Reply-To: <57c63afe0804081921r35af27a4ne5a16428b8508d2d@mail.gmail.com> References: <782d66f30804081916w78a71c3em33f9bf0ff71ce6af@mail.gmail.com> <57c63afe0804081921r35af27a4ne5a16428b8508d2d@mail.gmail.com> Message-ID: <782d66f30804081931s2be3ba7ap50f3cf1eb05a2716@mail.gmail.com> Thx. Remember, when you think "Beta Book," set your expectations low. We're motivated consumers; we'll buy an "Alpha Book." Sorry to distract you from writing. /g On Tue, Apr 8, 2008 at 10:21 PM, David Chelimsky wrote: > On Tue, Apr 8, 2008 at 10:16 PM, George Anderson > wrote: > > David, Aslak, > > > > Any word on the most eagerly anticipated book ever? > > Close to beta where: > > two.weeks < close < three.months > > I know it's a wide range, but everyone involved is quite busy. Getting > closer though. > > Cheers, > David > _______________________________________________ > 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 smingins at elctech.com Tue Apr 8 22:38:33 2008 From: smingins at elctech.com (Shane Mingins) Date: Wed, 9 Apr 2008 14:38:33 +1200 Subject: [rspec-users] i can haz buk? In-Reply-To: <782d66f30804081931s2be3ba7ap50f3cf1eb05a2716@mail.gmail.com> References: <782d66f30804081916w78a71c3em33f9bf0ff71ce6af@mail.gmail.com> <57c63afe0804081921r35af27a4ne5a16428b8508d2d@mail.gmail.com> <782d66f30804081931s2be3ba7ap50f3cf1eb05a2716@mail.gmail.com> Message-ID: <4E63F088-4699-4BEC-BBD6-74726EFC2777@elctech.com> +1 .... just ship it ;-) On 9/04/2008, at 2:31 PM, George Anderson wrote: > Thx. Remember, when you think "Beta Book," set your expectations low. > We're motivated consumers; we'll buy an "Alpha Book." > > Sorry to distract you from writing. > > /g > > On Tue, Apr 8, 2008 at 10:21 PM, David Chelimsky > wrote: >> On Tue, Apr 8, 2008 at 10:16 PM, George Anderson >> wrote: >>> David, Aslak, >>> >>> Any word on the most eagerly anticipated book ever? >> >> Close to beta where: >> >> two.weeks < close < three.months >> >> I know it's a wide range, but everyone involved is quite busy. >> Getting >> closer though. >> >> Cheers, >> David >> _______________________________________________ >> 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 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 lists at ruby-forum.com Wed Apr 9 01:12:06 2008 From: lists at ruby-forum.com (Win Lockwood) Date: Wed, 9 Apr 2008 07:12:06 +0200 Subject: [rspec-users] rspec SQLException problem Message-ID: <6cd54d772608e3e01de7aad17aa1d1c0@ruby-forum.com> hello: I just installed rspec 1.1.3 by doing this: gem install rspec and then in the root of my project, I did this: ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails And now, when I run a unit test (that worked before the rspec installation), I'm getting the following errors: SQLException: near 'of': syntax error: DELETE FROM Copy of assignments WHERE 1=1 and SQLException: SQL logic error or missing database I tried running rake db:test:clone, but that didn't fix it. Here's the unit test file: require File.dirname(__FILE__) + '/../test_helper' class StudentTest < ActiveSupport::TestCase def test_truth assert true end end I'm on Windows XP; ruby is version 1.8.6; rails is version 2.0.2; db is sqlite3, version 3.5.6. Any help here would be greatly appreciated! thanks Win -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Apr 9 01:25:00 2008 From: lists at ruby-forum.com (Andy Croll) Date: Wed, 9 Apr 2008 07:25:00 +0200 Subject: [rspec-users] Testing with has_many associations Message-ID: <8a6140f761480ca777632ea81ca4d68e@ruby-forum.com> Hi I'm trying to be good and practice full BDD on my current project, and don't want to abandon it as I have previously (expediency triumphed unfortunately). So expect me to be making frequent 'noob' style posts... My current issue is with testing assignation across a has_many relationship. I'm aware I shouldn't be testing the functionality of Rails, but this is behaviour of my code. cart_spec.rb: describe Cart do before(:each) do @product = mock "Trousers" @product.stub!(:class).and_return("Product") @product.stub!(:name).and_return("Brown Trousers") @product.stub!(:price).and_return(23.99) @cart = Cart.new end it "should have 1 item after adding a Product" do @cart.add_product(@product) @cart.items.should have(1).item end it "should have 1 item but with quantity 2 after adding the same product twice" do @cart.add_product(@product) @cart.add_product(@product) @cart.items.should have(1).item end end cart.rb: class Cart < ActiveRecord::Base has_many :items, :class_name => "CartItem", :dependent => :destroy def add_product(product) current = self.items.find_by_name(product.name) if current current.increment_quantity else self.items << CartItem.new_from_product(product) end end end fails with: 'Cart should have 1 item but with quantity 2 after adding the same product twice' FAILED expected 1 item, got 2 ***** Can anyone explain to me what I'm missing? -- Posted via http://www.ruby-forum.com/. From ben at benmabey.com Wed Apr 9 01:29:50 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 08 Apr 2008 23:29:50 -0600 Subject: [rspec-users] What is the best way to verify that yield is called? Message-ID: <47FC544E.3070702@benmabey.com> Hello all, What is the best way to verify that a method yields a block that is passed in? Before I added any 'yield' to my method I created this spec: it "should yield a message_delivery object" do create_message_in_factory do |message_delivery| message_delivery.should be_instance_of(MessageDelivery) end end This passed without me modifying my method which is not what I was hoping for. So I tried this spec and it gave me red: it "should yield the given block" do @block_yieled = false create_message_in_factory do |message_delivery| @block_yieled = true end @block_yieled.should be_true end Seems kinda hackish, but it did work. Is this the best way to spec this or is there already a matcher for this? If there isn't currently a matcher would be the above way be a good way to create a custom matcher? Thanks for your thoughts, Ben From chris at edendevelopment.co.uk Wed Apr 9 05:30:17 2008 From: chris at edendevelopment.co.uk (Chris Parsons) Date: Wed, 9 Apr 2008 10:30:17 +0100 Subject: [rspec-users] Testing with has_many associations In-Reply-To: <8a6140f761480ca777632ea81ca4d68e@ruby-forum.com> References: <8a6140f761480ca777632ea81ca4d68e@ruby-forum.com> Message-ID: <86D766C3-E4D0-4C4C-8B81-1CE82AD925C5@edendevelopment.co.uk> On 9 Apr 2008, at 06:25, Andy Croll wrote: > current = self.items.find_by_name(product.name) You're finding by the CartItem name and passing the product name - it looks like that's drawing a blank match when you're expecting it not to. How about a cart_item_spec.rb: describe CartItem do it "should be created successfully from a new product" do CartItem.new_from_product(mock_model(Product, :name => "name" )) CartItem.find_by_name("name").should_not be_nil end end I'm guessing this spec will fail with your current code as I don't think CartItem::new_from_product is working. I'd also probably break down the specs differently and wrap the call to items and make the specs more contained: class Cart def self.find_items_by_name(name) items.find_by_name(name) end end ...and mock this method when testing add_product: it "should add the product when it doesn't already exist in the cart" do @cart.should_receive(:find_items_by_name).with("name").and return(nil) @cart.add_product(@product) @cart.items.should have(1).item end it "should increment quantity when it does find a product" do @cart.should_receive(:find_items_by_name).with("name").and return(@product) @cart.add_product(@product) @cart.items.should have(1).item end HTH, Chris From lists at ruby-forum.com Wed Apr 9 05:57:22 2008 From: lists at ruby-forum.com (Andy Croll) Date: Wed, 9 Apr 2008 11:57:22 +0200 Subject: [rspec-users] Testing with has_many associations In-Reply-To: <86D766C3-E4D0-4C4C-8B81-1CE82AD925C5@edendevelopment.co.uk> References: <8a6140f761480ca777632ea81ca4d68e@ruby-forum.com> <86D766C3-E4D0-4C4C-8B81-1CE82AD925C5@edendevelopment.co.uk> Message-ID: <6d5b5165fcdb8dc161d86e02d53f41c1@ruby-forum.com> Chris Parsons wrote: > I'm guessing this spec will fail with your current code as I don't > think CartItem::new_from_product is working. Wow. I've never had code I hadn't posted correctly debugged before. You were absolutely right, thanks! Seems my testing approach in that spec was somehow faking out the all the tests I made. > I'd also probably break down the specs differently and wrap the call > to items and make the specs more contained: I think this is where I'm going wrong, I keep letting my tests get too big. Even when I think they are small. Another good rule I've picked up from this is to always try and use less than two dots to abstract the models... Big help thanks Chris. -- Posted via http://www.ruby-forum.com/. From ashley.moran at patchspace.co.uk Wed Apr 9 06:03:41 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 9 Apr 2008 11:03:41 +0100 Subject: [rspec-users] Multi-line steps Message-ID: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> Hi I just wondered what the plan was for multi-line steps. Is anyone working on it? I've just come across a real use for it (including small text files in the story). Cheers Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From tmhaines at gmail.com Wed Apr 9 06:31:40 2008 From: tmhaines at gmail.com (Tim Haines) Date: Wed, 9 Apr 2008 19:31:40 +0900 Subject: [rspec-users] Multi-line steps In-Reply-To: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> Message-ID: Hi Ashley, What's your use case? I'm curious... Tim. On 09/04/2008, Ashley Moran wrote: > > Hi > > I just wondered what the plan was for multi-line steps. Is anyone > working on it? I've just come across a real use for it (including > small text files in the story). > > Cheers > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > > > _______________________________________________ > 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/20080409/b98f4c92/attachment-0001.html From lists at ruby-forum.com Wed Apr 9 07:22:32 2008 From: lists at ruby-forum.com (Andy Croll) Date: Wed, 9 Apr 2008 13:22:32 +0200 Subject: [rspec-users] Testing with has_many associations In-Reply-To: <86D766C3-E4D0-4C4C-8B81-1CE82AD925C5@edendevelopment.co.uk> References: <8a6140f761480ca777632ea81ca4d68e@ruby-forum.com> <86D766C3-E4D0-4C4C-8B81-1CE82AD925C5@edendevelopment.co.uk> Message-ID: Chris Parsons wrote: > it "should increment quantity when it does find a product" do > @cart.should_receive(:find_items_by_name).with("name").and > return(@product) > @cart.add_product(@product) > @cart.items.should have(1).item > end My final solution for this was to write... describe Cart do before(:each) do @product1 = mock_model Product, :name => "Brown Trousers", :price => 23.99 @product2 = mock_model Product, :name => "Yellow Shirt", :price => 15.74 @cart_item1 = mock_model CartItem, :name => "Brown Trousers", :price => 23.99, :quantity => 1 @cart = Cart.new end it "should increment quantity when it does find a product" do @cart_item1.should_receive(:increment_quantity).once.with(:no_args).and_return(2) @cart.should_receive(:find_item_by_name).twice.with("Brown Trousers").and_return(nil, @cart_item1) @cart.add_product(@product1) @cart.add_product(@product1) @cart.items.should have(1).item end end Which seems to work. I'm right? -- Posted via http://www.ruby-forum.com/. From aslak.hellesoy at gmail.com Wed Apr 9 08:13:19 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 9 Apr 2008 14:13:19 +0200 Subject: [rspec-users] Multi-line steps In-Reply-To: References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> Message-ID: <8d961d900804090513r562d0fbalc76bcfb0b55f279f@mail.gmail.com> On Wed, Apr 9, 2008 at 12:31 PM, Tim Haines wrote: > Hi Ashley, > > What's your use case? I'm curious... > > Tim. > > I'm working on a Treetop (http://treetop.rubyforge.org/) implementation of the Story parser. Please file any suggestions for improvements to the story format to lighthouse and tag with story_grammar Aslak > > On 09/04/2008, Ashley Moran wrote: > > Hi > > > > I just wondered what the plan was for multi-line steps. Is anyone > > working on it? I've just come across a real use for it (including > > small text files in the story). > > > > Cheers > > Ashley > > > > -- > > http://www.patchspace.co.uk/ > > http://aviewfromafar.net/ > > > > > > > > _______________________________________________ > > 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 Apr 9 08:41:51 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 9 Apr 2008 08:41:51 -0400 Subject: [rspec-users] External Dependencies (was Multi-line steps) In-Reply-To: <8d961d900804090513r562d0fbalc76bcfb0b55f279f@mail.gmail.com> References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090513r562d0fbalc76bcfb0b55f279f@mail.gmail.com> Message-ID: <61E6DF41-31AE-447B-980A-CD3FFB39B27A@gmail.com> On Apr 9, 2008, at 8:13 AM, aslak hellesoy wrote: > I'm working on a Treetop (http://treetop.rubyforge.org/) > implementation of the Story parser. Hey Aslak, while I love the idea of exploiting treetop for this, this would be our first external dependency for end users. That was one of the reasons I didn't use treetop in the first place - it had just been released and Brian suggested exporing it when I was working on Plain Text Stories. Personally, I'm in support of external dependencies, especially in light of recent improvements to Rubygems that make it even easier for a gem to manage its own dependencies. But thus far we've had an only slightly-less-than-official policy of no external dependencies. Has your thinking on this issue shifted as well? From rick.denatale at gmail.com Wed Apr 9 08:50:13 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 9 Apr 2008 08:50:13 -0400 Subject: [rspec-users] What is the best way to verify that yield is called? In-Reply-To: <47FC544E.3070702@benmabey.com> References: <47FC544E.3070702@benmabey.com> Message-ID: On Wed, Apr 9, 2008 at 1:29 AM, Ben Mabey wrote: > Hello all, > What is the best way to verify that a method yields a block that is > passed in? > > Before I added any 'yield' to my method I created this spec: > > it "should yield a message_delivery object" do > create_message_in_factory do |message_delivery| > message_delivery.should be_instance_of(MessageDelivery) > end > end > > This passed without me modifying my method which is not what I was > hoping for. So I tried this spec and it gave me red: > > it "should yield the given block" do > @block_yieled = false > create_message_in_factory do |message_delivery| > @block_yieled = true > end > @block_yieled.should be_true > end > > > Seems kinda hackish, but it did work. Is this the best way to spec this > or is there already a matcher for this? Another approach might be: it "should yield the given block" do block_body = mock("block body") block_body.should_receive(:got_here) create_message_in_factory_do | message_delivery | block_body.got_here end end -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From rick.denatale at gmail.com Wed Apr 9 08:59:48 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 9 Apr 2008 08:59:48 -0400 Subject: [rspec-users] Multi-line steps In-Reply-To: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> Message-ID: On Wed, Apr 9, 2008 at 6:03 AM, Ashley Moran wrote: > Hi > > I just wondered what the plan was for multi-line steps. Is anyone > working on it? I've just come across a real use for it (including > small text files in the story). It' might be a little clunky, but I've recently done something like this in a story involving uploading a csv file .... When Fred creates a csv file And the csv file has a record with "first_name", "last_name" And the csv file has a record with "Bilbo", "Baggins" And the csv file has a record with "Arwen", "Evenstar" And Fred uploads the csv file The step for the first line creates an empty string object, and the next three append to it. The final step does whatever is needed to turn the string into a TestUploadFile or whatever is needed. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From aslak.hellesoy at gmail.com Wed Apr 9 09:11:02 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 9 Apr 2008 15:11:02 +0200 Subject: [rspec-users] External Dependencies (was Multi-line steps) In-Reply-To: <61E6DF41-31AE-447B-980A-CD3FFB39B27A@gmail.com> References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090513r562d0fbalc76bcfb0b55f279f@mail.gmail.com> <61E6DF41-31AE-447B-980A-CD3FFB39B27A@gmail.com> Message-ID: <8d961d900804090611p56ae0934n797b43a20e2d3307@mail.gmail.com> On Wed, Apr 9, 2008 at 2:41 PM, David Chelimsky wrote: > On Apr 9, 2008, at 8:13 AM, aslak hellesoy wrote: > > > I'm working on a Treetop (http://treetop.rubyforge.org/) > > implementation of the Story parser. > > Hey Aslak, while I love the idea of exploiting treetop for this, this > would be our first external dependency for end users. That was one of > the reasons I didn't use treetop in the first place - it had just been > released and Brian suggested exporing it when I was working on Plain > Text Stories. > > Personally, I'm in support of external dependencies, especially in > light of recent improvements to Rubygems that make it even easier for > a gem to manage its own dependencies. But thus far we've had an only > slightly-less-than-official policy of no external dependencies. Has > your thinking on this issue shifted as well? I realize it will introduce a dependency on treetop, but now that rubygems are ubiquotous and has largely improved with 1.1.0 I think it's ok. It would only be needed for stories. A treetop based parser has several benefits: * Much simpler codebase * Much better error messages for users. Line numbers and conflict detection. * Easier integration with other tools (including rspec core) * Simpler setup for story running (I have a vague plan for that in my head). I haven't committed the code yet - for now it will live in a separate repo on GitHub. Here is a teaser for the grammar: grammar Story rule story header narrative scenario* end rule header 'Story: ' sentence_line end rule narrative 'As a' sentence_line end rule scenario 'Scenario: ' sentence_line step* end rule step # The various step rules are generated dynamically 'Given ' (step_1 / step_2) end # Dynamically generated rule rule step_1 'I am ' word ' and ' word end # Dynamically generated rule rule step_2 'I was ' word ' and ' word end rule word ([\w])* end rule sentence_line (!eol .)* eol end rule eol "\n" / eof end rule eof !. end end Basically, each run will be based on a core grammar which is extended by the user, creating extra rules for each parameterised step. The treetop based parser would create the grammar dynamically, compile it in-memory and use it to parse plain text stories. My first benchmarks are pretty good - 0.03 secs to parse/compile the grammar and less than 0.0001 secs to parse a simple story. This is fun! Aslak > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Wed Apr 9 09:14:16 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 9 Apr 2008 15:14:16 +0200 Subject: [rspec-users] Multi-line steps In-Reply-To: References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> Message-ID: <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> On Wed, Apr 9, 2008 at 2:59 PM, Rick DeNatale wrote: > On Wed, Apr 9, 2008 at 6:03 AM, Ashley Moran > > wrote: > > > Hi > > > > I just wondered what the plan was for multi-line steps. Is anyone > > working on it? I've just come across a real use for it (including > > small text files in the story). > > It' might be a little clunky, but I've recently done something like > this in a story involving uploading a csv file > > .... > When Fred creates a csv file > And the csv file has a record with "first_name", "last_name" > And the csv file has a record with "Bilbo", "Baggins" > And the csv file has a record with "Arwen", "Evenstar" > And Fred uploads the csv file > Just a style comment: I usually strive for a single When (in this case Fred uploads the csv file). The other ones are Givens. > The step for the first line creates an empty string object, and the > next three append to it. The final step does whatever is needed to > turn the string into a TestUploadFile or whatever is needed. > Still interested in seeing how a multiline step would look. I'm also interested in how we can do more FIT-like things using tables. But maybe that belongs in a different tool... Aslak > -- > 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 chris at edendevelopment.co.uk Wed Apr 9 09:25:15 2008 From: chris at edendevelopment.co.uk (Chris Parsons) Date: Wed, 9 Apr 2008 14:25:15 +0100 Subject: [rspec-users] Testing with has_many associations In-Reply-To: References: <8a6140f761480ca777632ea81ca4d68e@ruby-forum.com> <86D766C3-E4D0-4C4C-8B81-1CE82AD925C5@edendevelopment.co.uk> Message-ID: <3AE07D69-D91A-456A-ACF9-45829ABB29AF@edendevelopment.co.uk> On 9 Apr 2008, at 12:22, Andy Croll wrote: > it "should increment quantity when it does find a product" do > > @cart_item1 > .should_receive(:increment_quantity).once.with(:no_args).and_return(2) > @cart.should_receive(:find_item_by_name).twice.with("Brown > Trousers").and_return(nil, @cart_item1) > @cart.add_product(@product1) > @cart.add_product(@product1) > @cart.items.should have(1).item > end > end > > Which seems to work. I'm right? Looks good. Don't forget that with that extra mocking your coverage has dropped on CartItem so you'll need to ensure that it's correctly tested also. Cheers Chris From dchelimsky at gmail.com Wed Apr 9 09:33:13 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 9 Apr 2008 09:33:13 -0400 Subject: [rspec-users] Multi-line steps In-Reply-To: <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> Message-ID: <57c63afe0804090633w740bd0c5h7d1a0c7926592fda@mail.gmail.com> On Wed, Apr 9, 2008 at 9:14 AM, aslak hellesoy wrote: > I'm also interested in how we can do more FIT-like things using > tables. But maybe that belongs in a different tool... Like, uh .... FIT? I've been thinking of resurrecting the Ruby FIT project which seems to have no commits since 2006. I can definitely see an RSpec-FIT bridge (separate library) that allows you to run FIT pages and RSpec scenarios with unified reporting. Of course, this will have to wait for RSpec 1.2, the book, and maybe a vacation or two ... Cheers, David From aslak.hellesoy at gmail.com Wed Apr 9 09:56:00 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 9 Apr 2008 15:56:00 +0200 Subject: [rspec-users] Multi-line steps In-Reply-To: <57c63afe0804090633w740bd0c5h7d1a0c7926592fda@mail.gmail.com> References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> <57c63afe0804090633w740bd0c5h7d1a0c7926592fda@mail.gmail.com> Message-ID: <8d961d900804090656l1959f65bj1a6c163afdce8a9b@mail.gmail.com> On Wed, Apr 9, 2008 at 3:33 PM, David Chelimsky wrote: > On Wed, Apr 9, 2008 at 9:14 AM, aslak hellesoy wrote: > > I'm also interested in how we can do more FIT-like things using > > tables. But maybe that belongs in a different tool... > > Like, uh .... FIT? Exactly. I have tried RubyFIT - it's OK, but dead as you mentioned. It would be nice with a more recent RubyFIT implementation that leverages all the goodies in the RSpec code (and community). Aslak > > I've been thinking of resurrecting the Ruby FIT project which seems to > have no commits since 2006. I can definitely see an RSpec-FIT bridge > (separate library) that allows you to run FIT pages and RSpec > scenarios with unified reporting. > > Of course, this will have to wait for RSpec 1.2, the book, and maybe a > vacation or two ... > > Cheers, > David > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Wed Apr 9 10:29:12 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 9 Apr 2008 10:29:12 -0400 Subject: [rspec-users] Multi-line steps In-Reply-To: <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> Message-ID: On Wed, Apr 9, 2008 at 9:14 AM, aslak hellesoy wrote: > On Wed, Apr 9, 2008 at 2:59 PM, Rick DeNatale wrote: > > On Wed, Apr 9, 2008 at 6:03 AM, Ashley Moran > > > > wrote: > > > > > Hi > > > > > > I just wondered what the plan was for multi-line steps. Is anyone > > > working on it? I've just come across a real use for it (including > > > small text files in the story). > > > > It' might be a little clunky, but I've recently done something like > > this in a story involving uploading a csv file > > > > .... > > When Fred creates a csv file > > And the csv file has a record with "first_name", "last_name" > > And the csv file has a record with "Bilbo", "Baggins" > > And the csv file has a record with "Arwen", "Evenstar" > > And Fred uploads the csv file > > > > Just a style comment: I usually strive for a single When (in this case > > Fred uploads the csv file). > The other ones are Givens. Yes, that's how I actually wrote it, just checked. I was working from memory from a machine which didn't have the actual code, and with too little coffee in my system for that hour of the morning to boot! -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From ben at benmabey.com Wed Apr 9 10:59:10 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 09 Apr 2008 08:59:10 -0600 Subject: [rspec-users] What is the best way to verify that yield is called? In-Reply-To: References: <47FC544E.3070702@benmabey.com> Message-ID: <47FCD9BE.6010400@benmabey.com> >> >> it "should yield the given block" do >> @block_yieled = false >> create_message_in_factory do |message_delivery| >> @block_yieled = true >> end >> @block_yieled.should be_true >> end >> >> >> Seems kinda hackish, but it did work. Is this the best way to spec this >> or is there already a matcher for this? >> > > Another approach might be: > > it "should yield the given block" do > block_body = mock("block body") > block_body.should_receive(:got_here) > create_message_in_factory_do | message_delivery | > block_body.got_here > end > end > > > > > > Thanks Rick! Both of these way work but I think they are both too ugly and should be created into a more expressive matcher. Given the above two options can anyone see an advantage to one way or the other? Or maybe another option is out there that is better? Thanks, Ben From dchelimsky at gmail.com Wed Apr 9 11:54:18 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 9 Apr 2008 11:54:18 -0400 Subject: [rspec-users] What is the best way to verify that yield is called? In-Reply-To: <47FCD9BE.6010400@benmabey.com> References: <47FC544E.3070702@benmabey.com> <47FCD9BE.6010400@benmabey.com> Message-ID: <57c63afe0804090854kcefb8c8x6007b2e052d78e95@mail.gmail.com> On Wed, Apr 9, 2008 at 10:59 AM, Ben Mabey wrote: > > >> > >> it "should yield the given block" do > >> @block_yieled = false > >> create_message_in_factory do |message_delivery| > >> @block_yieled = true > >> end > >> @block_yieled.should be_true > >> end > >> > >> > >> Seems kinda hackish, but it did work. Is this the best way to spec this > >> or is there already a matcher for this? > >> > > > > Another approach might be: > > > > it "should yield the given block" do > > block_body = mock("block body") > > block_body.should_receive(:got_here) > > create_message_in_factory_do | message_delivery | > > block_body.got_here > > end > > end > > > > > > > > > > > > > Thanks Rick! > Both of these way work but I think they are both too ugly and should be > created into a more expressive matcher. What are you looking to specify and how do you envision the syntax? I'm thinking something like: obj.should yield_with(no_args).on(:message) def message yield end list.should yield_with(1).then(2).then(3).on(:each) def each yield 1 yield 2 yield 3 end That all make sense? > Given the above two options can anyone see an advantage to one way or > the other? Or maybe another option is out there that is better? > > Thanks, > Ben > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Wed Apr 9 12:33:32 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 9 Apr 2008 12:33:32 -0400 Subject: [rspec-users] What is the best way to verify that yield is called? In-Reply-To: <57c63afe0804090854kcefb8c8x6007b2e052d78e95@mail.gmail.com> References: <47FC544E.3070702@benmabey.com> <47FCD9BE.6010400@benmabey.com> <57c63afe0804090854kcefb8c8x6007b2e052d78e95@mail.gmail.com> Message-ID: On Wed, Apr 9, 2008 at 11:54 AM, David Chelimsky wrote: > What are you looking to specify and how do you envision the syntax? > > I'm thinking something like: > > obj.should yield_with(no_args).on(:message) > > def message > yield > end > > list.should yield_with(1).then(2).then(3).on(:each) > > def each > yield 1 > yield 2 > yield 3 > end > > That all make sense? Sorta, but what about arguments to the message? def message(x, y, z) yield x+y+z end obj.receiving(:message).with(1,2,3).should yield(6) (1..3).receiving(:each_with_index).should yield_with([1,0]).then([2,1]).then([3,2]) or (1..3).receiving(:each_with_index).should yield_with([1,0],([2,1],[3,2]) (1..3).receiving(:inject).with(0).should yield_with ??????? Now it gets tricky since the sequence of yielded values depends on the block . I don't know that I like where this is going. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From dchelimsky at gmail.com Wed Apr 9 12:46:56 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 9 Apr 2008 12:46:56 -0400 Subject: [rspec-users] What is the best way to verify that yield is called? In-Reply-To: References: <47FC544E.3070702@benmabey.com> <47FCD9BE.6010400@benmabey.com> <57c63afe0804090854kcefb8c8x6007b2e052d78e95@mail.gmail.com> Message-ID: <57c63afe0804090946v59e66114qba151441de415584@mail.gmail.com> On Wed, Apr 9, 2008 at 12:33 PM, Rick DeNatale wrote: > On Wed, Apr 9, 2008 at 11:54 AM, David Chelimsky wrote: > > > What are you looking to specify and how do you envision the syntax? > > > > I'm thinking something like: > > > > obj.should yield_with(no_args).on(:message) > > > > def message > > yield > > end > > > > list.should yield_with(1).then(2).then(3).on(:each) > > > > def each > > yield 1 > > yield 2 > > yield 3 > > end > > > > That all make sense? > > Sorta, but what about arguments to the message? > > def message(x, y, z) > yield x+y+z > end > > obj.receiving(:message).with(1,2,3).should yield(6) > > (1..3).receiving(:each_with_index).should > yield_with([1,0]).then([2,1]).then([3,2]) > > or > > (1..3).receiving(:each_with_index).should yield_with([1,0],([2,1],[3,2]) > > (1..3).receiving(:inject).with(0).should yield_with ??????? > > Now it gets tricky since the sequence of yielded values depends on the block . > > I don't know that I like where this is going. Agreed, this could get hairy. Perhaps we should chalk this up to implementation detail? Looking back at the OP: it "should yield a message_delivery object" do create_message_in_factory do |message_delivery| message_delivery.should be_instance_of(MessageDelivery) end end How about something more like this as an idiom: it "should yield a message_delivery object" do create_message_in_factory do |message_delivery| return message_delivery end.should be_instance_of(MessageDelivery) end This still uses the contents of the blog to set an expectation, but is perhaps more expressive about the fact that we're not really interested in the contents of the block as much as we are what the end result is. WDYT? From dchelimsky at gmail.com Wed Apr 9 13:43:57 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 9 Apr 2008 13:43:57 -0400 Subject: [rspec-users] rspec at github Message-ID: <57c63afe0804091043o2c1347b6ld23d7246fb73b37@mail.gmail.com> It's official: http://tinyurl.com/5npxxb Git some happiness! Cheers, David From ben at benmabey.com Wed Apr 9 14:01:50 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 09 Apr 2008 12:01:50 -0600 Subject: [rspec-users] What is the best way to verify that yield is called? In-Reply-To: References: <47FC544E.3070702@benmabey.com> <47FCD9BE.6010400@benmabey.com> <57c63afe0804090854kcefb8c8x6007b2e052d78e95@mail.gmail.com> Message-ID: <47FD048E.9080104@benmabey.com> Rick DeNatale wrote: > On Wed, Apr 9, 2008 at 11:54 AM, David Chelimsky wrote: > > >> What are you looking to specify and how do you envision the syntax? >> >> I'm thinking something like: >> >> obj.should yield_with(no_args).on(:message) >> >> def message >> yield >> end >> >> list.should yield_with(1).then(2).then(3).on(:each) >> >> def each >> yield 1 >> yield 2 >> yield 3 >> end >> Hmmm.. I didn't think about multiple yields... >> That all make sense? >> > > Sorta, but what about arguments to the message? > > def message(x, y, z) > yield x+y+z > end > > obj.receiving(:message).with(1,2,3).should yield(6) > Or maybe: obj.when_sent(:message, 1,2,3).should yield(6) I don't know if the extra 'with' layer is needed since the sending of messages to objects is a very commonly used idiom in ruby. To keep the rspec syntax consistent your suggestion may be better so I could see it either way. > (1..3).receiving(:each_with_index).should > yield_with([1,0]).then([2,1]).then([3,2]) > > or > > (1..3).receiving(:each_with_index).should yield_with([1,0], [2,1],[3,2]) > The multiple args in the yield/yield_with call is more consistent with the way rspec's mocking of return values work (i.e. mock.shou..and_return([1,2],[0,4]) ) than the 'then' syntax suggested above. I guess I could go either way on this one as well. > (1..3).receiving(:inject).with(0).should yield_with ??????? > > Now it gets tricky since the sequence of yielded values depends on the block . > > I don't know that I like where this is going. > > My original goal was only to ease the pain on my eyes for the the simple cases. I never considered the more involved cases, so you make a good point. I can't think of an eloquent way of handling this. I don't think a matcher could ever handle all of the cases. Hmmm... -Ben From george at benevolentcode.com Wed Apr 9 14:12:09 2008 From: george at benevolentcode.com (George Anderson) Date: Wed, 9 Apr 2008 14:12:09 -0400 Subject: [rspec-users] rspec at github In-Reply-To: <57c63afe0804091043o2c1347b6ld23d7246fb73b37@mail.gmail.com> References: <57c63afe0804091043o2c1347b6ld23d7246fb73b37@mail.gmail.com> Message-ID: <782d66f30804091112h31f1ca32gf02c97e36f0faf2@mail.gmail.com> I see your tinyurl and raise you a rubyurl: http://rubyurl.com/xAod "Using git submodules to track vendor/rails" in which the author uses rspec (despite the title) in his well-written exposition on using submodules to track external dependencies. In the comments for that post you'll see Fran?ois Beausoleil is updating Piston to work with SVN and git. I've had no luck getting a recent Piston beta to track a SVN repo (rspec/_on_rails) in the context of a git repo, but YMMV. /g On Wed, Apr 9, 2008 at 1:43 PM, David Chelimsky wrote: > It's official: http://tinyurl.com/5npxxb > > Git some happiness! > > Cheers, > David > _______________________________________________ > 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 ben at benmabey.com Wed Apr 9 14:15:31 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 09 Apr 2008 12:15:31 -0600 Subject: [rspec-users] What is the best way to verify that yield is called? In-Reply-To: <57c63afe0804090946v59e66114qba151441de415584@mail.gmail.com> References: <47FC544E.3070702@benmabey.com> <47FCD9BE.6010400@benmabey.com> <57c63afe0804090854kcefb8c8x6007b2e052d78e95@mail.gmail.com> <57c63afe0804090946v59e66114qba151441de415584@mail.gmail.com> Message-ID: <47FD07C3.2010803@benmabey.com> David Chelimsky wrote: > On Wed, Apr 9, 2008 at 12:33 PM, Rick DeNatale wrote: > >> On Wed, Apr 9, 2008 at 11:54 AM, David Chelimsky wrote: >> >> > What are you looking to specify and how do you envision the syntax? >> > >> > I'm thinking something like: >> > >> > obj.should yield_with(no_args).on(:message) >> > >> > def message >> > yield >> > end >> > >> > list.should yield_with(1).then(2).then(3).on(:each) >> > >> > def each >> > yield 1 >> > yield 2 >> > yield 3 >> > end >> > >> > That all make sense? >> >> Sorta, but what about arguments to the message? >> >> def message(x, y, z) >> yield x+y+z >> end >> >> obj.receiving(:message).with(1,2,3).should yield(6) >> >> (1..3).receiving(:each_with_index).should >> yield_with([1,0]).then([2,1]).then([3,2]) >> >> or >> >> (1..3).receiving(:each_with_index).should yield_with([1,0],([2,1],[3,2]) >> >> (1..3).receiving(:inject).with(0).should yield_with ??????? >> >> Now it gets tricky since the sequence of yielded values depends on the block . >> >> I don't know that I like where this is going. >> > > Agreed, this could get hairy. Perhaps we should chalk this up to > implementation detail? > > Looking back at the OP: > > it "should yield a message_delivery object" do > create_message_in_factory do |message_delivery| > message_delivery.should be_instance_of(MessageDelivery) > end > end > > How about something more like this as an idiom: > > it "should yield a message_delivery object" do > create_message_in_factory do |message_delivery| > return message_delivery > end.should be_instance_of(MessageDelivery) > end > That makes sense for the cases when an object is yielded but what would you do if no object is yielded and the block is just suppose to execute? I guess you could do: it "should yield the given block" do some_method do return 42 end.should == 42 end But this does not look any better than the two previously suggested ways IMO. > This still uses the contents of the blog to set an expectation, but is > perhaps more expressive about the fact that we're not really > interested in the contents of the block as much as we are what the end > result is. > > WDYT? > In the case where the an object is yielded I do like you suggestion because it covers everything. I just don't know about when no object is yielded. I guess if a matcher is not possible I will have to settle for one of the approaches above when no object is yielded. Any more thoughts on the subject? Thanks, Ben From luislavena at gmail.com Wed Apr 9 14:24:58 2008 From: luislavena at gmail.com (Luis Lavena) Date: Wed, 9 Apr 2008 15:24:58 -0300 Subject: [rspec-users] rspec at github In-Reply-To: <57c63afe0804091043o2c1347b6ld23d7246fb73b37@mail.gmail.com> References: <57c63afe0804091043o2c1347b6ld23d7246fb73b37@mail.gmail.com> Message-ID: <71166b3b0804091124x14a453b3r541cfd23137f13a8@mail.gmail.com> On Wed, Apr 9, 2008 at 2:43 PM, David Chelimsky wrote: > It's official: http://tinyurl.com/5npxxb > > Git some happiness! > Yay!, good news! BTW, there is a doc or something to help you get the correct environment to spec RSpec? I saw your pre-commit stuff, but never managed to replicate the environment to try it. Regards, -- 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 dchelimsky at gmail.com Wed Apr 9 14:48:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 9 Apr 2008 14:48:53 -0400 Subject: [rspec-users] rspec at github In-Reply-To: <71166b3b0804091124x14a453b3r541cfd23137f13a8@mail.gmail.com> References: <57c63afe0804091043o2c1347b6ld23d7246fb73b37@mail.gmail.com> <71166b3b0804091124x14a453b3r541cfd23137f13a8@mail.gmail.com> Message-ID: <57c63afe0804091148ia63bb65k997b93949da83d01@mail.gmail.com> On Wed, Apr 9, 2008 at 2:24 PM, Luis Lavena wrote: > BTW, there is a doc or something to help you get the correct > environment to spec RSpec? I saw your pre-commit stuff, but never > managed to replicate the environment to try it. The pre_commit is not working correctly right now. We're working on it though. From ashley.moran at patchspace.co.uk Wed Apr 9 16:49:11 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 9 Apr 2008 21:49:11 +0100 Subject: [rspec-users] Multi-line steps In-Reply-To: References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> Message-ID: On 9 Apr 2008, at 11:31, Tim Haines wrote: > Hi Ashley, > > What's your use case? I'm curious... > > Tim. Hi Tim I've finally started writing a tool I've wanted for ages: a REAL database migration system, that works on a patch system with dependency tracking (like darcs), not a borked^H^H^H^H^H^H linear scheme like AR Migrations. So I started writing the story and I wanted to write something this: Scenario: two steps depend on third Given a file "db/migrate/a.migrate.rb": migration "migration A" do |m| m.depends_on "migration X" end And a file "db/migrate/b.migrate.rb": migration "migration B" do m.depends_on "migration X" end And a file "db/migrate/x.migrate.rb": migration "migration X" do end When ... In the end I did it like the way Rick's mate Fred builds CSVs, but breaking down a single step can be cumbersome. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Wed Apr 9 16:49:14 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 9 Apr 2008 21:49:14 +0100 Subject: [rspec-users] Multi-line steps In-Reply-To: <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> Message-ID: <95107E12-A30F-4217-B1CD-EA12925B5F17@patchspace.co.uk> On 9 Apr 2008, at 14:14, aslak hellesoy wrote: > Just a style comment: I usually strive for a single When (in this case > Fred uploads the csv file). > The other ones are Givens. Hmm, I've written a lot of Selenium stories lately, and they look like this: Given ... When the user visits /my_page And clicks on "Edit" And types "Cow" in the favourite_animal text field And clicks the save button Then ... Is that bad? Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Wed Apr 9 16:51:41 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 9 Apr 2008 21:51:41 +0100 Subject: [rspec-users] Advice / Turning a Usecase into a Rspec Story / Granularity ofstories In-Reply-To: <6bdacb70804081151l3da8d577g2c673fc59ae413c@mail.gmail.com> References: <94382B88-1DD2-44B0-8600-5DA6E5ADB5F8@superinfinite.com> <64B3E556-6A7C-4298-A9A9-C4BE941565F4@superinfinite.com> <1207214104.6571.23.camel@esw023.esw.eshopworks.co.uk> <10B4C604-ACB3-4E30-8DA1-20246DFDD135@superinfinite.com> <57c63afe0804030531i49dcc4es58a2277128872aed@mail.gmail.com> <6bdacb70804081151l3da8d577g2c673fc59ae413c@mail.gmail.com> Message-ID: On 8 Apr 2008, at 19:51, Corey Haines wrote: > +1 on sheer awesomeness of this presentation! Thanks for sending the > slides out! We are struggling/actively discussing our use of plain > text stories, and this really adds a lot to our conversation. No only is that presentation excellent from a business value perspective, but it's got some really cool step examples too. I've done all mine as $variable strings so far but they can be made much nicer with regexes. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Wed Apr 9 16:56:01 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 9 Apr 2008 21:56:01 +0100 Subject: [rspec-users] Command line story runner In-Reply-To: <60f3810c0804030758s654af605q4cf06714a556fcf9@mail.gmail.com> References: <60f3810c0804030758s654af605q4cf06714a556fcf9@mail.gmail.com> Message-ID: <383B261D-C8FD-410F-98EB-B68339022811@patchspace.co.uk> On 3 Apr 2008, at 15:58, Kyle Hargraves wrote: > This is very tied to the layout of my own projects, and I'd be > surprised if it works out of the box for most people. Right now it > does mostly everything I need, so I'm curious what would be necessary > to make it a viable tool for others to use. Hi Kyle Worked great out of the box for my little migration tool and its one story :) I will be able to provide better feedback when I've got more functionality under test, only spent a day on this project so far. Thanks for assembling the story command in a tidy package Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From pergesu at gmail.com Wed Apr 9 17:04:33 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 9 Apr 2008 14:04:33 -0700 Subject: [rspec-users] Multi-line steps In-Reply-To: <95107E12-A30F-4217-B1CD-EA12925B5F17@patchspace.co.uk> References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> <95107E12-A30F-4217-B1CD-EA12925B5F17@patchspace.co.uk> Message-ID: <810a540e0804091404n73dc7482k9201234306629a5f@mail.gmail.com> On 4/9/08, Ashley Moran wrote: > > On 9 Apr 2008, at 14:14, aslak hellesoy wrote: > > > Just a style comment: I usually strive for a single When (in this case > > Fred uploads the csv file). > > The other ones are Givens. > > Hmm, I've written a lot of Selenium stories lately, and they look like > this: > > Given ... > > When the user visits /my_page > And clicks on "Edit" > And types "Cow" in the favourite_animal text field > And clicks the save button > > Then ... > > Is that bad? Not bad, but perhaps misleading. Given is used to express preconditions, wheras When is for an action. Her you are expressing preconditions, even if those preconditions are action-based instead of state-based (e.g. the known state of the work is that the user has performed these actions) Does that make any sense? Pat From ashley.moran at patchspace.co.uk Wed Apr 9 17:37:16 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 9 Apr 2008 22:37:16 +0100 Subject: [rspec-users] Multi-line steps In-Reply-To: <810a540e0804091404n73dc7482k9201234306629a5f@mail.gmail.com> References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> <95107E12-A30F-4217-B1CD-EA12925B5F17@patchspace.co.uk> <810a540e0804091404n73dc7482k9201234306629a5f@mail.gmail.com> Message-ID: On 9 Apr 2008, at 22:04, Pat Maddox wrote: > Not bad, but perhaps misleading. Given is used to express > preconditions, wheras When is for an action. Her you are expressing > preconditions, even if those preconditions are action-based instead of > state-based (e.g. the known state of the work is that the user has > performed these actions) > > Does that make any sense? I knew you would say that :) It just seems unclear, I mean you could turn When the user vists /my_page And clicks the do_something button into either Given the user is on /my_page When he clicks the do_something button or When the user clicks the do_something button on /my_page The first solution looks better, but I guess it depends how atomic you want to make the steps. You could always write this, if you were so inclined... Given the user has a browser And they have typed "http://www.mysite.com" into the address bar And pressed enter And moved the mouse over the do_something button And pressed the mouse button ... Wouldn't wanna write that as one step... Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From win at wincent.com Wed Apr 9 19:04:35 2008 From: win at wincent.com (Wincent Colaiuta) Date: Thu, 10 Apr 2008 01:04:35 +0200 Subject: [rspec-users] rspec at github In-Reply-To: References: Message-ID: El 9/4/2008, a las 20:15, "David Chelimsky" escribi?: > > It's official: http://tinyurl.com/5npxxb > > Git some happiness! > > Cheers, > David One thing, on the wiki you say: > The easiest way to create a clean history is to make a new branch > that tracks RSpec?s master branch, and then cherry-pick your own > commits to it. For example, say you had a commit whose sha is abc123 > that you?d like to contribute to RSpec. However you made a previous > commit to your repo that would be irrelevant, but that would get > pulled in when we pull from your repo. Although it _may_ be the "easiest" way, I think there are better ways which should probably be mentioned for any patch series which has more than one commit in it (and breaking changes up into logical steps certainly makes reviewing changes much easier). So I think you should probably also mention the utility of topic branches and using "git rebase" to keep them up-to-date eg: # make sure we have the latest changes git fetch # create a new topic branch git checkout -b my_topic origin/master # hack, hack, hack, committing along the way ... # make sure we have the latest changes git fetch # prepare branch for submission git rebase --interactive # make a patch series for attachment to a lighthouse ticket git format-patch That's the basic idea. There are some shortcuts that can be taken (for example, if you are already on your master branch and it is set up to track the remote origin -- and it will be if you did a standard "git clone" of the RSpec repo -- then you can just do "git checkout -b my_topic", preceded by a "git pull" if you want to pull down and merge in the latest changes from the remote). "git rebase --interactive" is a really amazing tool that you just have to try out. It allows you to: 1. "rebase" the commits so that they always appear to be "on top" of the HEAD of the master branch, instead of several commits back; this makes the history cleaner because things look like linear development (technically a "fast-forward" merge) rather than a merge - this rebasing happens automatically when you run "git rebase" 2. skip commits; for those times when you realize that a change doesn't really belong in a particular series 3. "squash" multiple commits into one - perhaps you got a bit commit- happy and there are multiple changes that should logically be grouped into a single commit 4. edit or amend commits; either just tweaking the commit messages or actually changing the contents of the commit (for example, you can split a commit into a series of commits, or you can add completely new content to a commit) 5. reorder commits: it's amazing how easily this is done (just by reordering the commits in a list), and it can allow you to put a series into a more logical order that will be more easily reviewed In short it is an incredibly powerful tool, and you simply must try it in order to see how amazingly easy it is to do all this stuff which you would never dream of doing with Subversion... Go and try it now, really! And best of all, it leads to better code and a better RSpec, because the more reviewable your code is, the higher the quality of the stuff that ends up getting integrated. Cheers, Wincent From tmhaines at gmail.com Wed Apr 9 21:32:22 2008 From: tmhaines at gmail.com (Tim Haines) Date: Thu, 10 Apr 2008 10:32:22 +0900 Subject: [rspec-users] Netbeans and .story files In-Reply-To: References: <47F1E572.70600@sun.com> <57c63afe0804071218x70bbd500gd6889437abe249fb@mail.gmail.com> Message-ID: Here's the url - http://www.netbeans.org/issues/show_bug.cgi?id=131684 On 08/04/2008, Tim Haines wrote: > > I sent the netbeans guys a list of features for story support in netbeans. > With luck they'll make it into the next version after 6.1. Feel free to go > check it out and add to the list. :-) > > Cheers, > > Tim. > > On 8/04/2008, at 4:55, Ashley Moran wrote: > > > > On 7 Apr 2008, at 20:18, David Chelimsky wrote: > > > > That said, the convention that I see emerging is .rb for stories > > > expressed in ruby and either no extension or .story for those > > > expressed in plain text. > > > > > > > > > That's what I do - .story for the plain text file and .rb for the > > corresponding runner (not tried Kyle's runner yet) > > > > Ashley > > > > > > -- > > http://www.patchspace.co.uk/ > > http://aviewfromafar.net/ > > > > > > > > _______________________________________________ > > 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/20080410/a0551d0c/attachment-0001.html From pergesu at gmail.com Wed Apr 9 21:54:59 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 9 Apr 2008 18:54:59 -0700 Subject: [rspec-users] rspec at github In-Reply-To: References: Message-ID: <810a540e0804091854n272d5eddv5dd5a83e3545413@mail.gmail.com> On Wed, Apr 9, 2008 at 4:04 PM, Wincent Colaiuta wrote: > El 9/4/2008, a las 20:15, "David Chelimsky" > escribi?: > > > > > It's official: http://tinyurl.com/5npxxb > > > > Git some happiness! > > > > Cheers, > > David > > > One thing, on the wiki you say: > > > The easiest way to create a clean history is to make a new branch > > that tracks RSpec's master branch, and then cherry-pick your own > > commits to it. For example, say you had a commit whose sha is abc123 > > that you'd like to contribute to RSpec. However you made a previous > > commit to your repo that would be irrelevant, but that would get > > pulled in when we pull from your repo. > > Although it _may_ be the "easiest" way, I think there are better ways > which should probably be mentioned for any patch series which has more > than one commit in it (and breaking changes up into logical steps > certainly makes reviewing changes much easier). So I think you should > probably also mention the utility of topic branches and using "git > rebase" to keep them up-to-date eg: > > # make sure we have the latest changes > git fetch > > # create a new topic branch > git checkout -b my_topic origin/master > > # hack, hack, hack, committing along the way > ... > > # make sure we have the latest changes > git fetch > > # prepare branch for submission > git rebase --interactive > > # make a patch series for attachment to a lighthouse ticket > git format-patch > > That's the basic idea. There are some shortcuts that can be taken (for > example, if you are already on your master branch and it is set up to > track the remote origin -- and it will be if you did a standard "git > clone" of the RSpec repo -- then you can just do "git checkout -b > my_topic", preceded by a "git pull" if you want to pull down and merge > in the latest changes from the remote). > > "git rebase --interactive" is a really amazing tool that you just have > to try out. It allows you to: > > 1. "rebase" the commits so that they always appear to be "on top" of > the HEAD of the master branch, instead of several commits back; this > makes the history cleaner because things look like linear development > (technically a "fast-forward" merge) rather than a merge - this > rebasing happens automatically when you run "git rebase" > > 2. skip commits; for those times when you realize that a change > doesn't really belong in a particular series > > 3. "squash" multiple commits into one - perhaps you got a bit commit- > happy and there are multiple changes that should logically be grouped > into a single commit > > 4. edit or amend commits; either just tweaking the commit messages or > actually changing the contents of the commit (for example, you can > split a commit into a series of commits, or you can add completely new > content to a commit) > > 5. reorder commits: it's amazing how easily this is done (just by > reordering the commits in a list), and it can allow you to put a > series into a more logical order that will be more easily reviewed > > In short it is an incredibly powerful tool, and you simply must try it > in order to see how amazingly easy it is to do all this stuff which > you would never dream of doing with Subversion... Go and try it now, > really! > > And best of all, it leads to better code and a better RSpec, because > the more reviewable your code is, the higher the quality of the stuff > that ends up getting integrated. Thanks for that. I wrote what's up on the wiki... and to be perfectly honest, I only care about the end goal of having clean histories to merge into RSpec core. I also don't fully understand everything you wrote. If you had some time, perhaps you could take the existing content, add some concrete examples of your techniques, and extract all of that to a new page. I would certainly be very grateful :) Pat From lists at ruby-forum.com Wed Apr 9 22:36:22 2008 From: lists at ruby-forum.com (Win Lockwood) Date: Thu, 10 Apr 2008 04:36:22 +0200 Subject: [rspec-users] rspec SQLException problem In-Reply-To: <6cd54d772608e3e01de7aad17aa1d1c0@ruby-forum.com> References: <6cd54d772608e3e01de7aad17aa1d1c0@ruby-forum.com> Message-ID: <6f635f9f59c78f772f4ae1051a490445@ruby-forum.com> call off the hounds this happened because I had a file named "Copy of assignments.yml" in my fixtures directory -Win -- Posted via http://www.ruby-forum.com/. From tmhaines at gmail.com Wed Apr 9 22:37:34 2008 From: tmhaines at gmail.com (Tim Haines) Date: Thu, 10 Apr 2008 11:37:34 +0900 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? Message-ID: Hi there, Just want to confirm I have this right. Writing a story, assigns[:games].length.should == 30 fails for me complaining assigns[:games] is nil. It seems assigns isn't set for story steps? I've changed this to response.should have_tag(".game", 30). Is this correct? Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080410/e4021bd4/attachment.html From pergesu at gmail.com Wed Apr 9 22:55:25 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 9 Apr 2008 19:55:25 -0700 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: References: Message-ID: <810a540e0804091955l1e65f865o2bd75e4bf9ca67ae@mail.gmail.com> On Wed, Apr 9, 2008 at 7:37 PM, Tim Haines wrote: > Hi there, > > Just want to confirm I have this right. Writing a story, > assigns[:games].length.should == 30 fails for me complaining assigns[:games] > is nil. It seems assigns isn't set for story steps? I've changed this to > response.should have_tag(".game", 30). Is this correct? I would say that you shouldn't be trying to test that sort of thing in a story. The fact that Rails assigns stuff as instance variables in views is a framework implementation detail, not externally visible behavior. Pat From dchelimsky at gmail.com Wed Apr 9 23:09:43 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 9 Apr 2008 23:09:43 -0400 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: References: Message-ID: <6C799D99-38DA-4C1D-A2B6-EA2195895B45@gmail.com> On Apr 9, 2008, at 10:37 PM, "Tim Haines" wrote: > Hi there, > > Just want to confirm I have this right. Writing a story, assigns > [:games].length.should == 30 fails for me complaining assigns > [:games] is nil. It seems assigns isn't set for story steps? I've > changed this to response.should have_tag(".game", 30). Is this > correct? Yep! The step has no access to intervals of the request. > > > Tim. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From tmhaines at gmail.com Wed Apr 9 23:20:45 2008 From: tmhaines at gmail.com (Tim Haines) Date: Thu, 10 Apr 2008 12:20:45 +0900 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: <810a540e0804091955l1e65f865o2bd75e4bf9ca67ae@mail.gmail.com> References: <810a540e0804091955l1e65f865o2bd75e4bf9ca67ae@mail.gmail.com> Message-ID: Thanks Pat and David. I'm implementing paging (via will_paginate) and thought I should start with a story. I think I grok what you're saying Pat - the stories should only be looking at "externally" visible stuff - i.e. what a real user can see or do.. That's why you consider controller.send("current_user=",..) a bit hacky right? So to make sure I only have 30 records showing when there's 40 in the db I should definitely be using have_tag.. Tim. On 10/04/2008, Pat Maddox wrote: > > On Wed, Apr 9, 2008 at 7:37 PM, Tim Haines wrote: > > Hi there, > > > > Just want to confirm I have this right. Writing a story, > > assigns[:games].length.should == 30 fails for me complaining > assigns[:games] > > is nil. It seems assigns isn't set for story steps? I've changed this > to > > response.should have_tag(".game", 30). Is this correct? > > > I would say that you shouldn't be trying to test that sort of thing in > a story. The fact that Rails assigns stuff as instance variables in > views is a framework implementation detail, not externally visible > behavior. > > Pat > _______________________________________________ > 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/20080410/c338cf4a/attachment.html From jarkko at jlaine.net Wed Apr 9 23:55:58 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Thu, 10 Apr 2008 06:55:58 +0300 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: References: <810a540e0804091955l1e65f865o2bd75e4bf9ca67ae@mail.gmail.com> Message-ID: <7BFD87AA-E93B-40B8-8D7A-B1B3EC08F6FB@jlaine.net> On 10.4.2008, at 6.20, Tim Haines wrote: > Thanks Pat and David. I'm implementing paging (via will_paginate) > and thought I should start with a story. I think I grok what you're > saying Pat - the stories should only be looking at "externally" > visible stuff - i.e. what a real user can see or do.. That's why > you consider controller.send("current_user=",..) a bit hacky right? Yes. Just create a given that goes through the normal logging process. You can parameterize it so that you can reuse it with different roles. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available Url : http://rubyforge.org/pipermail/rspec-users/attachments/20080410/2e4eb79b/attachment.bin From ashley.moran at patchspace.co.uk Thu Apr 10 02:52:50 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 10 Apr 2008 07:52:50 +0100 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: References: <810a540e0804091955l1e65f865o2bd75e4bf9ca67ae@mail.gmail.com> Message-ID: On 10 Apr 2008, at 04:20, Tim Haines wrote: > Thanks Pat and David. I'm implementing paging (via will_paginate) > and thought I should start with a story. I think I grok what you're > saying Pat - the stories should only be looking at "externally" > visible stuff - i.e. what a real user can see or do.. That's why > you consider controller.send("current_user=",..) a bit hacky right? > > So to make sure I only have 30 records showing when there's 40 in > the db I should definitely be using have_tag.. > > Tim. Hi Tim I've just done *exactly* this. In fact, the way it works out, your view spec doesn't have anything to do with how many items you have displayed, that's a controller/model issue with the call to Model.paginate. In fact my view spec actually just had 3 model mocks to render, while the controller spec checked the call to Model.paginate(:per_page => 10) (is it :per_page?) and the story checked that the correct number got displayed. The view was dumb, just the way it should be. And also I had a login step like Jarkko - in fact the first step of every story was "Given a signed in admin user". Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Thu Apr 10 02:56:32 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 10 Apr 2008 07:56:32 +0100 Subject: [rspec-users] Netbeans and .story files In-Reply-To: References: <47F1E572.70600@sun.com> <57c63afe0804071218x70bbd500gd6889437abe249fb@mail.gmail.com> Message-ID: <73A1894D-C752-44CE-A762-967936EB84F2@patchspace.co.uk> On 10 Apr 2008, at 02:32, Tim Haines wrote: > Here's the url - http://www.netbeans.org/issues/show_bug.cgi?id=131684 Looks good! I like this bit: priority 1b - In the project pane, allow stories to sit as the first "folder" in the list, and "rspec" as the second - both above controllers. The theory is you should write stories first, then your specs, then the app code.. Oh, and did you give "stories" a capital "S" at last? :D Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080410/9e9a5dbe/attachment.html From pergesu at gmail.com Thu Apr 10 11:20:53 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 10 Apr 2008 08:20:53 -0700 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: References: <810a540e0804091955l1e65f865o2bd75e4bf9ca67ae@mail.gmail.com> Message-ID: <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> On Wed, Apr 9, 2008 at 8:20 PM, Tim Haines wrote: > Thanks Pat and David. I'm implementing paging (via will_paginate) and > thought I should start with a story. I think I grok what you're saying Pat > - the stories should only be looking at "externally" visible stuff - i.e. > what a real user can see or do.. That's why you consider > controller.send("current_user=",..) a bit hacky right? I don't actually think that that's hacky. Let's say you've got a story that covers logging in. Does _every single_ other story require you to cover that same basic functionality? I don't think so. The tradeoff in this case is between purity and speed. Testing the exact path the user takes is certainly more robust. otoh, how likely is the authentication behavior going to fail? Not that likely. I think it's reasonable to skip that part, cutting down on the number of requests that your stories make, in order to keep your story suite faster. Pat From dchelimsky at gmail.com Thu Apr 10 12:00:08 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Apr 2008 12:00:08 -0400 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> References: <810a540e0804091955l1e65f865o2bd75e4bf9ca67ae@mail.gmail.com> <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> Message-ID: <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> On Apr 10, 2008, at 11:20 AM, Pat Maddox wrote: > On Wed, Apr 9, 2008 at 8:20 PM, Tim Haines wrote: >> Thanks Pat and David. I'm implementing paging (via will_paginate) >> and >> thought I should start with a story. I think I grok what you're >> saying Pat >> - the stories should only be looking at "externally" visible stuff >> - i.e. >> what a real user can see or do.. That's why you consider >> controller.send("current_user=",..) a bit hacky right? > > I don't actually think that that's hacky. Let's say you've got a > story that covers logging in. Does _every single_ other story require > you to cover that same basic functionality? I don't think so. The > tradeoff in this case is between purity and speed. Testing the exact > path the user takes is certainly more robust. otoh, how likely is the > authentication behavior going to fail? Not that likely. I think it's > reasonable to skip that part, cutting down on the number of requests > that your stories make, in order to keep your story suite faster. otooh - having some scenarios logging in using a post and some by poking around under the hood creates an untested logical binding between the post and the poking. This has the same risk associated with it that raises so much concern about mocks without integration tests that don't use mocks. I'm not saying that there should be a visible log-in step in every scenario. I would just use a request (or series of requests) instead of controller.send("current_user=",...). FWIW, David > Pat From ashley.moran at patchspace.co.uk Thu Apr 10 12:21:52 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 10 Apr 2008 17:21:52 +0100 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> References: <810a540e0804091955l1e65f865o2bd75e4bf9ca67ae@mail.gmail.com> <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> Message-ID: On 10 Apr 2008, at 17:00, David Chelimsky wrote: > otooh - having some scenarios logging in using a post and some by > poking around under the hood creates an untested logical binding > between the post and the poking. This has the same risk associated > with it that raises so much concern about mocks without integration > tests that don't use mocks. > > I'm not saying that there should be a visible log-in step in every > scenario. I would just use a request (or series of requests) instead > of controller.send("current_user=",...). Recently I've done a load of selenium-based stories and every single one had to log in, except the one that checks you can't do anything when you are not logged in. There was no way round the login process, so I had to put it in. But there were other stories that I couldn't do purely through the browser (eg those that needed users created and attached to organisations) because not all of the required GUI had not been built first*. For these I resorted to database access. My questions are: - is this acceptable as a bootstrapping processes (direct DB creation of data until the GUI exists) - is this acceptable in the long run, if you write a story that shows that the database changes produce the corresponding user-visible changes? Ashley * it was not an agile project -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From pergesu at gmail.com Thu Apr 10 12:48:37 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 10 Apr 2008 09:48:37 -0700 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: References: <810a540e0804091955l1e65f865o2bd75e4bf9ca67ae@mail.gmail.com> <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> Message-ID: <810a540e0804100948s7623579dk9e03223576aa73c4@mail.gmail.com> On Thu, Apr 10, 2008 at 9:21 AM, Ashley Moran wrote: > > On 10 Apr 2008, at 17:00, David Chelimsky wrote: > > > otooh - having some scenarios logging in using a post and some by > > poking around under the hood creates an untested logical binding > > between the post and the poking. This has the same risk associated > > with it that raises so much concern about mocks without integration > > tests that don't use mocks. > > > > I'm not saying that there should be a visible log-in step in every > > scenario. I would just use a request (or series of requests) instead > > of controller.send("current_user=",...). > > Recently I've done a load of selenium-based stories and every single > one had to log in, except the one that checks you can't do anything > when you are not logged in. There was no way round the login process, > so I had to put it in. But there were other stories that I couldn't > do purely through the browser (eg those that needed users created and > attached to organisations) because not all of the required GUI had not > been built first*. For these I resorted to database access. > > My questions are: > - is this acceptable as a bootstrapping processes (direct DB creation > of data until the GUI exists) I think so. Keep in mind that not every step of every story needs to be a round-trip request. It's even good to write some stories that don't make requests at all! In any test, you need to control the state of the word - the test fixture. If your test requires a bit of bootstrapping in order to get there, that's fine. The only thing that matters is that your test gives you confidence in the behavior you're testing. > - is this acceptable in the long run, if you write a story that shows > that the database changes produce the corresponding user-visible > changes? I'm not entirely sure what you mean here. But generally if I'm testing that the user sees something, then I also want to include the step where they initiate that chain of events. Pat From dchelimsky at gmail.com Thu Apr 10 12:59:42 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Apr 2008 12:59:42 -0400 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: <810a540e0804100948s7623579dk9e03223576aa73c4@mail.gmail.com> References: <810a540e0804091955l1e65f865o2bd75e4bf9ca67ae@mail.gmail.com> <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> <810a540e0804100948s7623579dk9e03223576aa73c4@mail.gmail.com> Message-ID: <54EA445F-B39E-4685-8C77-D2AB51EF87A4@gmail.com> On Apr 10, 2008, at 12:48 PM, Pat Maddox wrote: > Keep in mind that not every step of every story needs to > be a round-trip request. It's even good to write some stories that > don't make requests at all! I definitely agree with this, however I do see a difference between accessing models directly through their API (which I do) and accessing the internals of the request cycle (which I don't). > In any test, you need to control the state of the world - the test > fixture. If your test requires a bit of bootstrapping in order to get > there, that's fine. The only thing that matters is that your test > gives you confidence in the behavior you're testing. This is the ultimate bottom line. Tests are about confidence. From glenn at aldenta.com Thu Apr 10 13:28:07 2008 From: glenn at aldenta.com (Glenn Ford) Date: Thu, 10 Apr 2008 13:28:07 -0400 Subject: [rspec-users] Multi-line steps In-Reply-To: <810a540e0804091404n73dc7482k9201234306629a5f@mail.gmail.com> References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> <95107E12-A30F-4217-B1CD-EA12925B5F17@patchspace.co.uk> <810a540e0804091404n73dc7482k9201234306629a5f@mail.gmail.com> Message-ID: On Apr 9, 2008, at 5:04 PM, Pat Maddox wrote: > On 4/9/08, Ashley Moran wrote: >> >> On 9 Apr 2008, at 14:14, aslak hellesoy wrote: >> >>> Just a style comment: I usually strive for a single When (in this >>> case >>> Fred uploads the csv file). >>> The other ones are Givens. >> >> Hmm, I've written a lot of Selenium stories lately, and they look >> like >> this: >> >> Given ... >> >> When the user visits /my_page >> And clicks on "Edit" >> And types "Cow" in the favourite_animal text field >> And clicks the save button >> >> Then ... >> >> Is that bad? > > Not bad, but perhaps misleading. Given is used to express > preconditions, wheras When is for an action. Her you are expressing > preconditions, even if those preconditions are action-based instead of > state-based (e.g. the known state of the work is that the user has > performed these actions) > > Does that make any sense? > > Pat This actually sounds more confusing to me when viewed in the context of my own stories, and it seems similar to what's going on here. I write a lot about the user's interaction with the site and what should happen, so I have a lot of stories that look like: Given database is in this state When user does this stuff in browser Then database should be in this new state If the point of the Story is to see what happens when a user clicks buttons while the app is in a certain state, then moving those to a "Given" means you have no more actions left. If all the action happened in the "Given", then there won't be a When statement at all. Glenn From abroad-crawford at within3.com Thu Apr 10 13:30:51 2008 From: abroad-crawford at within3.com (Anthony Broad-Crawford) Date: Thu, 10 Apr 2008 13:30:51 -0400 Subject: [rspec-users] mock_model Message-ID: <3F5576A7-6698-4978-9AC5-6264D2AEFE1F@within3.com> Our company just had an interesting conversation around mock_model and I want to ask the same question to this audience. When creating mock_models what is the purpose of passing in the class constant? user = mock_model(User) To the best that we can tell the method mock_model doesn't actually use the class for anything. Please correct us if we are wrong. Secondly, we also typically after a mock_model stub the necessary properties (attributes) that are accessed off of the model. For example .... user = mock_model(User) user.stub!(:username) ... user.stub!(:password) .... Why doesn't mock model interrogate the attributes and generate these mocks for me? Thanks for taking the time to answer. Anthony Broad-Crawford -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080410/c79ea9ae/attachment-0001.html From pergesu at gmail.com Thu Apr 10 13:54:21 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 10 Apr 2008 10:54:21 -0700 Subject: [rspec-users] mock_model In-Reply-To: <3F5576A7-6698-4978-9AC5-6264D2AEFE1F@within3.com> References: <3F5576A7-6698-4978-9AC5-6264D2AEFE1F@within3.com> Message-ID: <810a540e0804101054o1857a0e6h20faa3093a60fa9b@mail.gmail.com> On Thu, Apr 10, 2008 at 10:30 AM, Anthony Broad-Crawford wrote: > Our company just had an interesting conversation around mock_model and I > want to ask the same question to this audience. When creating mock_models > what is the purpose of passing in the class constant? > > user = mock_model(User) > > To the best that we can tell the method mock_model doesn't actually use the > class for anything. Please correct us if we are wrong. Secondly, we also > typically after a mock_model stub the necessary properties (attributes) that > are accessed off of the model. For example .... > > user = mock_model(User) > > user.stub!(:username) ... > user.stub!(:password) .... > > Why doesn't mock model interrogate the attributes and generate these mocks > for me? Thanks for taking the time to answer. mock_model does a little bit of stuff for you. It generates a unique ID for the object, sets new_record? to false, and gives it an empty errors array. Not much else though. stub_model, available in RSpec trunk, may be more to your liking. You can read about it at http://rubyforge.org/pipermail/rspec-devel/2008-March/004782.html Pat From ashley.moran at patchspace.co.uk Thu Apr 10 16:55:06 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 10 Apr 2008 21:55:06 +0100 Subject: [rspec-users] mock_model In-Reply-To: <810a540e0804101054o1857a0e6h20faa3093a60fa9b@mail.gmail.com> References: <3F5576A7-6698-4978-9AC5-6264D2AEFE1F@within3.com> <810a540e0804101054o1857a0e6h20faa3093a60fa9b@mail.gmail.com> Message-ID: <80758095-9870-4922-A10A-8899B0CFA23A@patchspace.co.uk> On 10 Apr 2008, at 18:54, Pat Maddox wrote: > stub_model, available in RSpec trunk, may be more to your liking. You > can read about it at > http://rubyforge.org/pipermail/rspec-devel/2008-March/004782.html From the linked post: > Also - right now it checks the hash against the model's attributes. If > the model has a matching attribute it gets assigned, otherwise a stub > is created. It occurs to me that, with some modification, this *could* > be used as a bit of an auditing/red-flagging tool. So let's say you do > this: > > stub_model(Person, :attrs => {:last_name => 'Name'}, :stubs => > {:full_name => 'Full Name'}) > > In this case it would fail if the Person model changed :last_name to > :given_name, for example. I have very mixed feelings about that, and > might never use it myself, but it would serve to alleviate the fear of > false positives. On my last job I extended my client's Factory class so you could create either real or mock objects with a stub list. The syntax was (uses method missing for the "model_name" bit): Factory.mock_model_name(:name => "Fred", :age => 25) This was against a pure mock (generated from mock_model) so there was no issue with attrs vs stubs. What it did do, however, was something like (from memory): raise "Useful error message" unless model_class.new.respond_to?(stub) I also created another version, Factory.mock_model_name!(attrs) which printed to STDERR instead of raising an exception. (The ! implying "unsafe" rather than "raises an exception.) While I was using it I found the stub checking REALLY useful (I never used the ! version myself) - it caught a few cases where I had changed or not added a model method. David: +1 for stub_model, but could you make it autodetect if the stub is for an attribute or a method? It would be nice to do away with the :attr and :stub distinction. I have to say, though, I don't see the advantage of using a real object as the basis for the mock as long as one is used as a sanity check for the stubs (maybe I am missing a benefit). Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Thu Apr 10 17:04:21 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 10 Apr 2008 22:04:21 +0100 Subject: [rspec-users] Multi-line steps In-Reply-To: References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> <95107E12-A30F-4217-B1CD-EA12925B5F17@patchspace.co.uk> <810a540e0804091404n73dc7482k9201234306629a5f@mail.gmail.com> Message-ID: <5F027667-45F6-4506-9FFB-31BFEAEB9609@patchspace.co.uk> On 10 Apr 2008, at 18:28, Glenn Ford wrote: > Given database is in this state > When user does this stuff in browser > Then database should be in this new state I like the way you phrased this Glenn. Maybe the distinction is that Given is everything outside the control of the user, or, if the user set up the Given themself, all the stuff they *completed* in a previous session (no transition states). What erked me about Pat's earlier suggestion was it felt like half the stuff the user did was in Given, which left the end of the Given section describing a state that a user could not find the system in. I don't see that Given or Then has to be restricted to the database though - it could refer to the pre- or post-When state of an external web services, the contents in the browser, files read or written. Anything really. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From aslak.hellesoy at gmail.com Thu Apr 10 17:25:14 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 10 Apr 2008 23:25:14 +0200 Subject: [rspec-users] Multi-line steps In-Reply-To: References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> <95107E12-A30F-4217-B1CD-EA12925B5F17@patchspace.co.uk> <810a540e0804091404n73dc7482k9201234306629a5f@mail.gmail.com> Message-ID: <8d961d900804101425s78f661c2k17afd06257588159@mail.gmail.com> On Thu, Apr 10, 2008 at 7:28 PM, Glenn Ford wrote: > > On Apr 9, 2008, at 5:04 PM, Pat Maddox wrote: > > > On 4/9/08, Ashley Moran wrote: > >> > >> On 9 Apr 2008, at 14:14, aslak hellesoy wrote: > >> > >>> Just a style comment: I usually strive for a single When (in this > >>> case > >>> Fred uploads the csv file). > >>> The other ones are Givens. > >> > >> Hmm, I've written a lot of Selenium stories lately, and they look > >> like > >> this: > >> > >> Given ... > >> > >> When the user visits /my_page > >> And clicks on "Edit" > >> And types "Cow" in the favourite_animal text field > >> And clicks the save button > >> > >> Then ... > >> > >> Is that bad? > > > > Not bad, but perhaps misleading. Given is used to express > > preconditions, wheras When is for an action. Her you are expressing > > preconditions, even if those preconditions are action-based instead of > > state-based (e.g. the known state of the work is that the user has > > performed these actions) > > > > Does that make any sense? > > > > Pat > > This actually sounds more confusing to me when viewed in the context > of my own stories, and it seems similar to what's going on here. I > write a lot about the user's interaction with the site and what should > happen, so I have a lot of stories that look like: > > Given database is in this state > When user does this stuff in browser > Then database should be in this new state > This is a very "technical" way to express a scenario. It wouldn't make much sense to a typical domain expert (unless they know about databases). I generally try to write scenarios using the domain language, focussing on outcomes for users (not computers). Example: Given the customers joe, paul and lisa are registered users When a user signs up as lisa Then the user should be informed that the name is taken And the user lisa should not be able to log in Aslak > If the point of the Story is to see what happens when a user clicks > buttons while the app is in a certain state, then moving those to a > "Given" means you have no more actions left. If all the action > happened in the "Given", then there won't be a When statement at all. > > Glenn > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Apr 10 17:28:15 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 10 Apr 2008 17:28:15 -0400 Subject: [rspec-users] mock_model In-Reply-To: <80758095-9870-4922-A10A-8899B0CFA23A@patchspace.co.uk> References: <3F5576A7-6698-4978-9AC5-6264D2AEFE1F@within3.com> <810a540e0804101054o1857a0e6h20faa3093a60fa9b@mail.gmail.com> <80758095-9870-4922-A10A-8899B0CFA23A@patchspace.co.uk> Message-ID: <57c63afe0804101428w28c46cb8t30aa61053ff21252@mail.gmail.com> On Thu, Apr 10, 2008 at 4:55 PM, Ashley Moran wrote: > David: +1 for stub_model, but could you make it autodetect if the stub > is for an attribute or a method? It would be nice to do away with > the :attr and :stub distinction. Not sure what you mean here - that is handled transparently by stub_model so you don't have to make any such distinction. Take a look at http://github.com/dchelimsky/rspec-rails/tree/master/lib/spec/rails/example/rails_example_group.rb and see if it sheds some light. > I have to say, though, I don't see > the advantage of using a real object as the basis for the mock as long > as one is used as a sanity check for the stubs (maybe I am missing a > benefit). Not sure what you mean here either. Can you elaborate? From ashley.moran at patchspace.co.uk Thu Apr 10 17:57:17 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 10 Apr 2008 22:57:17 +0100 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: <54EA445F-B39E-4685-8C77-D2AB51EF87A4@gmail.com> References: <810a540e0804091955l1e65f865o2bd75e4bf9ca67ae@mail.gmail.com> <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> <810a540e0804100948s7623579dk9e03223576aa73c4@mail.gmail.com> <54EA445F-B39E-4685-8C77-D2AB51EF87A4@gmail.com> Message-ID: <18352AFD-71F3-4A19-921D-4FBD78C84C8C@patchspace.co.uk> On 10 Apr 2008, at 17:59, David Chelimsky wrote: > I definitely agree with this, however I do see a difference between > accessing models directly through their API (which I do) and accessing > the internals of the request cycle (which I don't). Ok that's what I was doing - not interfering with anything, just using a lower-level API in the same story as a high-level API. Perhaps it wouldn't have felt as strange if I was using a web service request instead of ORM calls? and Pat wrote: >> - is this acceptable in the long run, if you write a story that shows >> that the database changes produce the corresponding user-visible >> changes? > > I'm not entirely sure what you mean here. But generally if I'm > testing that the user sees something, then I also want to include the > step where they initiate that chain of events. Sorry wasn't clear what I meant. I was thinking something like Given ... When I run User.create!(:foo => "bar") Then the Users page should have a row with "bar" in the "foo" column etc... Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From rick.denatale at gmail.com Thu Apr 10 18:01:27 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 10 Apr 2008 18:01:27 -0400 Subject: [rspec-users] Multi-line steps In-Reply-To: <8d961d900804101425s78f661c2k17afd06257588159@mail.gmail.com> References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> <95107E12-A30F-4217-B1CD-EA12925B5F17@patchspace.co.uk> <810a540e0804091404n73dc7482k9201234306629a5f@mail.gmail.com> <8d961d900804101425s78f661c2k17afd06257588159@mail.gmail.com> Message-ID: On Thu, Apr 10, 2008 at 5:25 PM, aslak hellesoy wrote: > > This is a very "technical" way to express a scenario. It wouldn't make > much sense to a typical domain expert (unless they know about > databases). > I generally try to write scenarios using the domain language, > focussing on outcomes for users (not computers). Example: > > Given the customers joe, paul and lisa are registered users > When a user signs up as lisa > Then the user should be informed that the name is taken > And the user lisa should not be able to log in I'm not sure which of the two lisas I should feel sorry for. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From ashley.moran at patchspace.co.uk Thu Apr 10 18:04:31 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 10 Apr 2008 23:04:31 +0100 Subject: [rspec-users] mock_model In-Reply-To: <57c63afe0804101428w28c46cb8t30aa61053ff21252@mail.gmail.com> References: <3F5576A7-6698-4978-9AC5-6264D2AEFE1F@within3.com> <810a540e0804101054o1857a0e6h20faa3093a60fa9b@mail.gmail.com> <80758095-9870-4922-A10A-8899B0CFA23A@patchspace.co.uk> <57c63afe0804101428w28c46cb8t30aa61053ff21252@mail.gmail.com> Message-ID: <668B86DA-1CE2-4CC6-848B-B1EA0DAEAE32@patchspace.co.uk> On 10 Apr 2008, at 22:28, David Chelimsky wrote: > Not sure what you mean here - that is handled transparently by > stub_model so you don't have to make any such distinction. Take a look > at http://github.com/dchelimsky/rspec-rails/tree/master/lib/spec/rails/example/rails_example_group.rb > and see if it sheds some light. So it does - the code in the previous post was this, however: stub_model(Person, :attrs => {:last_name => 'Name'}, :stubs => {:full_name => 'Full Name'}) Where did :attrs and :stubs go? (or come from?) >> I have to say, though, I don't see >> the advantage of using a real object as the basis for the mock as >> long >> as one is used as a sanity check for the stubs (maybe I am missing a >> benefit). > > Not sure what you mean here either. Can you elaborate? Just that you have the line model_class.new do |model| Where I did mock_model(model_class) then later when stubbing did something like stubs.each { |msg, ret| ... raise unless model_class.new.respond_to?(msg) } This gives you the advantage of checking the stubs against a real model but on a "pure" mock. I just wasn't sure what the advantage of using a partial mock was, in this case. As for the comment: > #-- > # TODO - Shouldn't this just be an extension of stub! ?? > # - object.stub!(:method => return_value, :method2 => > return_value2, :etc => etc) > #++ +1 on that too. I've wanted that for so long :D Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From pergesu at gmail.com Thu Apr 10 18:06:02 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 10 Apr 2008 15:06:02 -0700 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: <18352AFD-71F3-4A19-921D-4FBD78C84C8C@patchspace.co.uk> References: <810a540e0804091955l1e65f865o2bd75e4bf9ca67ae@mail.gmail.com> <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> <810a540e0804100948s7623579dk9e03223576aa73c4@mail.gmail.com> <54EA445F-B39E-4685-8C77-D2AB51EF87A4@gmail.com> <18352AFD-71F3-4A19-921D-4FBD78C84C8C@patchspace.co.uk> Message-ID: <810a540e0804101506h722ba176s88136afa1ac0c22e@mail.gmail.com> On Thu, Apr 10, 2008 at 2:57 PM, Ashley Moran wrote: > Sorry wasn't clear what I meant. I was thinking something like > Given ... > When I run User.create!(:foo => "bar") > Then the Users page should have a row with "bar" in the "foo" column Gah, that looks hideous. When I create a user with foo="bar" is better because it doesn't expose the implementation. Just the model concept and any relevant attributes. If possible, I like to write it in a very narrative form: Given a user named Pat And the user is 22 years old When I view the user list Then I should see the user's name and age Your implementation of the steps can be at any level you want, for the most part. But the stories should only be in business terms. Pat From glenn at aldenta.com Thu Apr 10 18:10:23 2008 From: glenn at aldenta.com (Glenn Ford) Date: Thu, 10 Apr 2008 18:10:23 -0400 Subject: [rspec-users] Multi-line steps In-Reply-To: <8d961d900804101425s78f661c2k17afd06257588159@mail.gmail.com> References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> <95107E12-A30F-4217-B1CD-EA12925B5F17@patchspace.co.uk> <810a540e0804091404n73dc7482k9201234306629a5f@mail.gmail.com> <8d961d900804101425s78f661c2k17afd06257588159@mail.gmail.com> Message-ID: >> This actually sounds more confusing to me when viewed in the context >> of my own stories, and it seems similar to what's going on here. I >> write a lot about the user's interaction with the site and what >> should >> happen, so I have a lot of stories that look like: >> >> Given database is in this state >> When user does this stuff in browser >> Then database should be in this new state >> > > This is a very "technical" way to express a scenario. It wouldn't make > much sense to a typical domain expert (unless they know about > databases). > I generally try to write scenarios using the domain language, > focussing on outcomes for users (not computers). Example: > > Given the customers joe, paul and lisa are registered users > When a user signs up as lisa > Then the user should be informed that the name is taken > And the user lisa should not be able to log in > > Aslak You're right, and I don't literally write them in this format. But if you interpret the business logic that's in them into what they actually mean technically, it really just is the state of the database and I guess we can also add the session/cookies/flash. Even in the example you just gave, you express in your "Given" that in the Users table of your db there are 3 entries. For your "When" there is a user interacting with the web app. "Then" shows that an error is in the response. You could also check to ensure that the number of Users in the database did not change. This, I know, is more of a technical way to look at it, but I've personally found use for this when realizing a tricky view was passing bad data to a controller and my Story caught it. It was getting the right flash message in the end... but there were too many entities being created in the db. I didn't catch this until the Story spec so I still think there's a use for this! You could even break apart "And the user..." into: When a user tries to log in as lisa Then the user should be informed that no such customer exists Because really the current statement includes multiple steps. Going to the login page, filling out the data, submitting it, and then checking the response/redirect. If there were an error in your "Then the user $lisa should not be able to log in" step, it would be untested and it's actually not quite trivial since it's not a single step. That's probably more nit-picky since I'm sure the step would be used in many other places to give you added confidence, but since you mentioned "When" is for actions and your example "And Then" has an action, I still think it's interesting to look at :) Glenn From ashley.moran at patchspace.co.uk Thu Apr 10 18:30:23 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 10 Apr 2008 23:30:23 +0100 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: <810a540e0804101506h722ba176s88136afa1ac0c22e@mail.gmail.com> References: <810a540e0804091955l1e65f865o2bd75e4bf9ca67ae@mail.gmail.com> <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> <810a540e0804100948s7623579dk9e03223576aa73c4@mail.gmail.com> <54EA445F-B39E-4685-8C77-D2AB51EF87A4@gmail.com> <18352AFD-71F3-4A19-921D-4FBD78C84C8C@patchspace.co.uk> <810a540e0804101506h722ba176s88136afa1ac0c22e@mail.gmail.com> Message-ID: On 10 Apr 2008, at 23:06, Pat Maddox wrote: >> Given ... >> When I run User.create!(:foo => "bar") >> Then the Users page should have a row with "bar" in the "foo" >> column > > Gah, that looks hideous. I think you misunderstood the point - it's supposed to look hideous :) What I meant was if you have a load of steps like Given a user named Pat And the user is 22 years old When I view the user list Then I should see the user's name and age But say that actually, "Given a user named Pat" and "Given the user is 22 years old" are implemented as DB API calls - in this case is there merit to having a special set of stories on one side, just to verify that your low-level steps actually produce the user-facing data you expect, as if they used the GUI to create the data? I sometimes write "assumption" specs for third party code, if I am relying on behaviour I'm unsure about, just so if the lib API changes it gets flagged. I saw this as an extension of the idea, not a suggestion to send ActiveRecord method calls to a client's marketing director!!! (I'm sure there's some bizarre political situation somewhere where that might have an advantage though...) Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From pergesu at gmail.com Thu Apr 10 18:38:07 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 10 Apr 2008 15:38:07 -0700 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: References: <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> <810a540e0804100948s7623579dk9e03223576aa73c4@mail.gmail.com> <54EA445F-B39E-4685-8C77-D2AB51EF87A4@gmail.com> <18352AFD-71F3-4A19-921D-4FBD78C84C8C@patchspace.co.uk> <810a540e0804101506h722ba176s88136afa1ac0c22e@mail.gmail.com> Message-ID: <810a540e0804101538u57b144ccr638f87c27dd33373@mail.gmail.com> On Thu, Apr 10, 2008 at 3:30 PM, Ashley Moran wrote: > > On 10 Apr 2008, at 23:06, Pat Maddox wrote: > > >> Given ... > >> When I run User.create!(:foo => "bar") > >> Then the Users page should have a row with "bar" in the "foo" > >> column > > > > Gah, that looks hideous. > > > I think you misunderstood the point - it's supposed to look hideous :) Yes, I am thoroughly confused. > What I meant was if you have a load of steps like > > > Given a user named Pat > And the user is 22 years old > When I view the user list > Then I should see the user's name and age > > But say that actually, "Given a user named Pat" and "Given the user > is 22 years old" are implemented as DB API calls - in this case is > there merit to having a special set of stories on one side, just to > verify that your low-level steps actually produce the user-facing data > you expect, as if they used the GUI to create the data? I don't know what you mean by a special set of stories. In the example I gave, the Given steps would most likely be implemented as AR calls - not as separate requests. The When and Then would likely be implemented as an HTTP request and an assertion on the returned HTML. But there's no way to tell that from the story narrative. And sometimes if the logic is complex and will take a couple iterations, I might first implement the When and Then steps as AR calls, and then as we build up the HTML pages around that infrastructure, I'd convert the step implementations to go through the web request. Are we somewhat getting on the same page by now? :) > I sometimes write "assumption" specs for third party code, if I am > relying on behaviour I'm unsure about, just so if the lib API changes > it gets flagged. I saw this as an extension of the idea, not a > suggestion to send ActiveRecord method calls to a client's marketing > director!!! (I'm sure there's some bizarre political situation > somewhere where that might have an advantage though...) Michael Feathers, in Working Effectively with Legacy Code, calls these characterization tests. They can certainly be very useful. Pat From ashley.moran at patchspace.co.uk Thu Apr 10 19:33:19 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 11 Apr 2008 00:33:19 +0100 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: <810a540e0804101538u57b144ccr638f87c27dd33373@mail.gmail.com> References: <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> <810a540e0804100948s7623579dk9e03223576aa73c4@mail.gmail.com> <54EA445F-B39E-4685-8C77-D2AB51EF87A4@gmail.com> <18352AFD-71F3-4A19-921D-4FBD78C84C8C@patchspace.co.uk> <810a540e0804101506h722ba176s88136afa1ac0c22e@mail.gmail.com> <810a540e0804101538u57b144ccr638f87c27dd33373@mail.gmail.com> Message-ID: <55BA1EB5-8BD4-48FD-81F9-923D5EDF70FD@patchspace.co.uk> On 10 Apr 2008, at 23:38, Pat Maddox wrote: > I don't know what you mean by a special set of stories. In the > example I gave, the Given steps would most likely be implemented as AR > calls - not as separate requests. The When and Then would likely be > implemented as an HTTP request and an assertion on the returned HTML. > But there's no way to tell that from the story narrative. This is the key to me. Ultimately there's no way to prove that the story does anything until someone sees it run - at least on a real browser. Arguably even webrat etc don't demonstrably prove that the app works. That was my feeling with using DB calls, they aren't demonstrable enough. I had a handover meeting with my client today, and for the functionality I built he was most interested in seeing the stories, first in text and then actually run. And actually it was satisfying for me to run them, knowing there's no disputing something you can see running in front of your eyes. But I felt the need to apologise for steps that "cheated", such as those that inspected the database for model states, instead of pages for content keywords. > And > sometimes if the logic is complex and will take a couple iterations, I > might first implement the When and Then steps as AR calls, and then as > we build up the HTML pages around that infrastructure, I'd convert the > step implementations to go through the web request. > > Are we somewhat getting on the same page by now? :) Uhuh :D That's what I meant by "bootstrapping" - writing DB API steps to get yourself going. Then you have two choices - "upgrade" them to "real" steps like you say above, or write "characterization tests" like you say below. I was just wondering what people thought of the two opinions. Sorry for taking so long to get my point across... typing posts at 100mph in between coding, and expecting everyone to read my mind... > Michael Feathers, in Working Effectively with Legacy Code, calls these > characterization tests. They can certainly be very useful. Thanks for the book recommendation, I've forwarded it to some people I know that haven't had the luxury of using Ruby full time. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From tmhaines at gmail.com Thu Apr 10 20:40:02 2008 From: tmhaines at gmail.com (Tim Haines) Date: Fri, 11 Apr 2008 09:40:02 +0900 Subject: [rspec-users] Creating stories for the second resource. Very wet approach Message-ID: Hi y'all I'm about to start writing up the stories for my second resource. The second resource is so similar to the first that I feel a good way for me to start might be to copy and paste the stories and edit from there. This seems very anti-dry though. Am I missing something obvious, or would you expect (and be happy with) a lot of duplication between stories? Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080411/402af3e0/attachment.html From tmhaines at gmail.com Thu Apr 10 20:46:17 2008 From: tmhaines at gmail.com (Tim Haines) Date: Fri, 11 Apr 2008 09:46:17 +0900 Subject: [rspec-users] newbq: Organizing your stories Message-ID: Hi, I'm a little unhappy with how my stories are organised, and am wondering if anyone has found any particular method nicest. I'm working within an admin namespace, and currently have a plain text story file for each controller in the admin folder. I also have a steps subfolder, with one step file per controller. I'm thinking it would be nicer to add a little more granularity here, and to break the plain text story files down further into "actions" on each controller so there's fewer stories per story file. This could be done either in the one folder, or by adding a bunch of subfolders. I figure this is pretty common though, and that there will be one or two approaches that have evolved to work pretty well? Cheers, Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080411/86c8e197/attachment.html From pergesu at gmail.com Thu Apr 10 21:34:56 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 10 Apr 2008 18:34:56 -0700 Subject: [rspec-users] newbq: Organizing your stories In-Reply-To: References: Message-ID: <810a540e0804101834uf6cbe28x70eb4d586e285a1c@mail.gmail.com> On Thu, Apr 10, 2008 at 5:46 PM, Tim Haines wrote: > Hi, > > I'm a little unhappy with how my stories are organised, and am wondering if > anyone has found any particular method nicest. I'm working within an admin > namespace, and currently have a plain text story file for each controller in > the admin folder. I also have a steps subfolder, with one step file per > controller. > > I'm thinking it would be nicer to add a little more granularity here, and to > break the plain text story files down further into "actions" on each > controller so there's fewer stories per story file. This could be done > either in the one folder, or by adding a bunch of subfolders. I tend to have one story file per action, because one action is more or less an atomic unit of functionality. Pat From alen198 at gmail.com Thu Apr 10 21:57:03 2008 From: alen198 at gmail.com (newbie) Date: Thu, 10 Apr 2008 18:57:03 -0700 (PDT) Subject: [rspec-users] how to stub the :current_user and any methods associated with it In-Reply-To: <29a0119e0804070831v5198bff7qcc6f4a757578af4e@mail.gmail.com> References: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> <29a0119e0804070831v5198bff7qcc6f4a757578af4e@mail.gmail.com> Message-ID: <691ed0f1-88cc-4225-88bf-f7065a0ae157@24g2000hsh.googlegroups.com> Thanks for the direction. I'm glad to hear that I'm going in the right direction. I just have a final question and I seem to be hitting a stub/mocking road block at the moment. In my controller I have this... def index @entries = current_user.entries end How would I rspec this out correctly? This is what I have but it looks wrong. before(:each) do @current_user = mock_model(User, :id => 1) @entry = mock_model(Entry, :user_id => 1) controller.stub!(:current_user).and_return(@current_user) controller.stub!(:entries).and_return(@entry) end describe "on the index page" do it "should show all of the current_users entries" do @current_user.should_receive(:entries).with(@entry).and_return(true) end end On Apr 7, 11:31?am, "Bryan Ray" wrote: > Responses shown below... > > Sorry this isn't extremely informative ... in a bit of a rush. Hopefully it > will point you in the appropriate direction. > > > > On Sun, Apr 6, 2008 at 2:17 PM, newbie wrote: > > I'm new to Rspec and I'm having a bit of trouble with this controller > > that I'm testing. I think I'm doing it right but I guess my syntax is > > wrong. > > I'm currently using the "acts_as_authenticated" plug in. > > > What I want to test out is > > > EventController on entering the tickets_page > > - should show the tickets_page ?if the current_user has NOT entered > > this page today > > > ----------------------------------------------------- > > Below is my event controller > > ----------------------------------------------------- > > > class EventController < ApplicationController > > > ?before_filter :login_required > > > ?def tickets_page > > ? ? ?if current_user.has_already_entered_today? > > ? ? ? ?flash[:notice] = 'Come back tomorrow' > > ? ? ? ?redirect_to :action => 'home' > > ? ? ?else > > ? ? ? ?flash[:notice] = 'Welcome' > > ? ? ?end > > ?end > > end > > > ----------------------------------------------------- > > Below is my rspec for this controller > > ----------------------------------------------------- > > > require File.dirname(__FILE__) + '/../spec_helper' > > describe EventController do > > > ?before(:each) do > > ? ?@current_user = mock_model(User, :id => 1) > > ? ?controller.stub!(:current_user).and_return(@current_user) > > ? ?controller.stub!(:login_required).and_return(:true) > > ?end > > > ?fixtures :users > > > ?describe "on entering the tickets page" do > > ? ?it "should show the tickets_page ?if the current_user has NOT > > entered this page today" do > > ? ? controller.current_user.stub! > > (:has_already_entered_today?).and_return(:false) > > ? ? get :tickets_page > > > controller.current_user.should_receive(:has_already_entered_today?).with(:f alse).and_return(:false) > > ? ? response.should render_template(:tickets_page) > > ? ?end > > end > > > end > > > ----------------------------------------------------- > > My errors > > ----------------------------------------------------- > > Mock 'User_1001' received unexpected > > message :has_already_entered_today? with (no args) > > So this is a good start ... it means that the controller action is actually > being mocked out ... you just need to keep moving forward mocking/stubbing > out the rest of your controller actions. it's complaining that it doesn't > know what to do on your *current_user.has_already_entered_today?* method. > > @current_user.stub!(:has_already_entered_today?).and_return( false here>) > > > > > Anyone can help with any direction of what I might be doing wrong? > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > -- > Bryan Rayhttp://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." > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From rick.denatale at gmail.com Thu Apr 10 22:03:38 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 10 Apr 2008 22:03:38 -0400 Subject: [rspec-users] Multi-line steps In-Reply-To: References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> <95107E12-A30F-4217-B1CD-EA12925B5F17@patchspace.co.uk> <810a540e0804091404n73dc7482k9201234306629a5f@mail.gmail.com> <8d961d900804101425s78f661c2k17afd06257588159@mail.gmail.com> Message-ID: On Thu, Apr 10, 2008 at 6:10 PM, Glenn Ford wrote: Quoting Aslak > > Given the customers joe, paul and lisa are registered users > > When a user signs up as lisa > > Then the user should be informed that the name is taken > > And the user lisa should not be able to log in > You're right, and I don't literally write them in this format. But if > you interpret the business logic that's in them into what they > actually mean technically, it really just is the state of the database > and I guess we can also add the session/cookies/flash. > > Even in the example you just gave, you express in your "Given" that in > the Users table of your db there are 3 entries. For your "When" there > is a user interacting with the web app. "Then" shows that an error is > in the response. Actually, that there are three users with specific user names. > You could also check to ensure that the number of Users in the > database did not change. This, I know, is more of a technical way to > look at it, but I've personally found use for this when realizing a > tricky view was passing bad data to a controller and my Story caught > it. It was getting the right flash message in the end... but there > were too many entities being created in the db. I didn't catch this > until the Story spec so I still think there's a use for this! > > You could even break apart "And the user..." into: > > When a user tries to log in as lisa > Then the user should be informed that no such customer exists Which if you step back and look at the whole story is problematic, because, as I tried to point out, perhaps a bit too tongue in cheek, 'Lisa' here is ambiguous. There is one Lisa who is already a registered user, and a second one who tries to use the name which is already taken. And I wouldn't think that most reasonable systems would disable Lisa1's account because some Lisa2 tried and failed to use the same name. > Because really the current statement includes multiple steps. Going > to the login page, filling out the data, submitting it, and then > checking the response/redirect. If there were an error in your "Then > the user $lisa should not be able to log in" step, it would be > untested and it's actually not quite trivial since it's not a single > step. That's probably more nit-picky since I'm sure the step would be > used in many other places to give you added confidence, but since you > mentioned "When" is for actions and your example "And Then" has an > action, I still think it's interesting to look at :) And to make the distinction between Given's, When's and Then's fuzzier, there's GivenScenario, which effectively converts all of a scenario's Givens, When's and I guess Then's into a Given for a subsequent scenario. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From rick.denatale at gmail.com Thu Apr 10 22:14:01 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 10 Apr 2008 22:14:01 -0400 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: <810a540e0804101538u57b144ccr638f87c27dd33373@mail.gmail.com> References: <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> <810a540e0804100948s7623579dk9e03223576aa73c4@mail.gmail.com> <54EA445F-B39E-4685-8C77-D2AB51EF87A4@gmail.com> <18352AFD-71F3-4A19-921D-4FBD78C84C8C@patchspace.co.uk> <810a540e0804101506h722ba176s88136afa1ac0c22e@mail.gmail.com> <810a540e0804101538u57b144ccr638f87c27dd33373@mail.gmail.com> Message-ID: On Thu, Apr 10, 2008 at 6:38 PM, Pat Maddox wrote: > On Thu, Apr 10, 2008 at 3:30 PM, Ashley Moran > > But say that actually, "Given a user named Pat" and "Given the user > > is 22 years old" are implemented as DB API calls - in this case is > > there merit to having a special set of stories on one side, just to > > verify that your low-level steps actually produce the user-facing data > > you expect, as if they used the GUI to create the data? > > I don't know what you mean by a special set of stories. In the > example I gave, the Given steps would most likely be implemented as AR > calls - not as separate requests. The When and Then would likely be > implemented as an HTTP request and an assertion on the returned HTML. > But there's no way to tell that from the story narrative. And > sometimes if the logic is complex and will take a couple iterations, I > might first implement the When and Then steps as AR calls, and then as > we build up the HTML pages around that infrastructure, I'd convert the > step implementations to go through the web request. I'm working on a project right now in which the business rules and logic took some time to discover via iteration and experimentation. The UI work started later and overlapped somewhat. I started by writing a plain text story, and steps which worked at the AR level. I've done the UI work mostly with specs and not stories. I'm now at the point of converting the steps into the equivalent of a 'traditional' Rails integration test. BUT I'm thinking that I might just write a whole new xxx_steps.rb file which would run the same story but at the real user interaction level, and keep the model level steps also. I still haven't convinced myself one way or the other. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From kamal.fariz at gmail.com Thu Apr 10 22:16:16 2008 From: kamal.fariz at gmail.com (Kamal Fariz) Date: Fri, 11 Apr 2008 10:16:16 +0800 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: <810a540e0804101506h722ba176s88136afa1ac0c22e@mail.gmail.com> References: <810a540e0804091955l1e65f865o2bd75e4bf9ca67ae@mail.gmail.com> <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> <810a540e0804100948s7623579dk9e03223576aa73c4@mail.gmail.com> <54EA445F-B39E-4685-8C77-D2AB51EF87A4@gmail.com> <18352AFD-71F3-4A19-921D-4FBD78C84C8C@patchspace.co.uk> <810a540e0804101506h722ba176s88136afa1ac0c22e@mail.gmail.com> Message-ID: <2E879B0F-CA79-4BD1-9F1D-9CF7834C9823@gmail.com> > When I create a user with foo="bar" > > is better because it doesn't expose the implementation. Just the > model concept and any relevant attributes. I hide model details from Stories by using webrat and form field labels. When I create a user with Username: kamal, Password: test And click submit Seems safer that way as the views get tested at the same time. Regards, kamal From tmhaines at gmail.com Thu Apr 10 22:51:17 2008 From: tmhaines at gmail.com (Tim Haines) Date: Fri, 11 Apr 2008 11:51:17 +0900 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: <2E879B0F-CA79-4BD1-9F1D-9CF7834C9823@gmail.com> References: <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> <810a540e0804100948s7623579dk9e03223576aa73c4@mail.gmail.com> <54EA445F-B39E-4685-8C77-D2AB51EF87A4@gmail.com> <18352AFD-71F3-4A19-921D-4FBD78C84C8C@patchspace.co.uk> <810a540e0804101506h722ba176s88136afa1ac0c22e@mail.gmail.com> <2E879B0F-CA79-4BD1-9F1D-9CF7834C9823@gmail.com> Message-ID: I read about webrat and stories 30 mins ago - http://www.benmabey.com/2008/02/04/rspec-plain-text-stories-webrat-chunky-bacon/- good article. Tim. On 11/04/2008, Kamal Fariz wrote: > > > When I create a user with foo="bar" > > > > is better because it doesn't expose the implementation. Just the > > model concept and any relevant attributes. > > > I hide model details from Stories by using webrat and form field labels. > > When I create a user with Username: kamal, Password: test > And click submit > > Seems safer that way as the views get tested at the same time. > > > Regards, > > kamal > > _______________________________________________ > 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/20080411/6602a5fe/attachment.html From zach.dennis at gmail.com Fri Apr 11 00:16:54 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 11 Apr 2008 00:16:54 -0400 Subject: [rspec-users] newbq: Organizing your stories In-Reply-To: References: Message-ID: <85d99afe0804102116i7397ac00n3ddd1da909b91ab7@mail.gmail.com> On Thu, Apr 10, 2008 at 8:46 PM, Tim Haines wrote: > Hi, > > I'm a little unhappy with how my stories are organised, and am wondering > if anyone has found any particular method nicest. I'm working within an > admin namespace, and currently have a plain text story file for each > controller in the admin folder. I also have a steps subfolder, with one > step file per controller. > > I'm thinking it would be nicer to add a little more granularity here, and > to break the plain text story files down further into "actions" on each > controller so there's fewer stories per story file. This could be done > either in the one folder, or by adding a bunch of subfolders. > > I figure this is pretty common though, and that there will be one or two > approaches that have evolved to work pretty well? > I organize my stories based on related behavior usually as defined by the customer. For example: - stories/ - projects/ - a_user_creating_a_project_story - a_project_manager_adding_users_to_a_project_story - admin/ - an_admin_removing_users_story I use stories as system level integration tests, so they usually cover a broader scope than a controller/action. -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080411/d2f1f77d/attachment.html From jarkko at jlaine.net Fri Apr 11 03:21:04 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Fri, 11 Apr 2008 10:21:04 +0300 Subject: [rspec-users] how to stub the :current_user and any methods associated with it In-Reply-To: <691ed0f1-88cc-4225-88bf-f7065a0ae157@24g2000hsh.googlegroups.com> References: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> <29a0119e0804070831v5198bff7qcc6f4a757578af4e@mail.gmail.com> <691ed0f1-88cc-4225-88bf-f7065a0ae157@24g2000hsh.googlegroups.com> Message-ID: <1D4C8509-001E-4187-8119-0483C8E4A367@jlaine.net> On 11.4.2008, at 4.57, newbie wrote: > Thanks for the direction. I'm glad to hear that I'm going in the right > direction. I just have a final question and I seem to be hitting a > stub/mocking road block at the moment. In my controller I have this... > > def index > @entries = current_user.entries > end > > How would I rspec this out correctly? This is what I have but it looks > wrong. > > before(:each) do > @current_user = mock_model(User, :id => 1) > @entry = mock_model(Entry, :user_id => 1) > controller.stub!(:current_user).and_return(@current_user) > controller.stub!(:entries).and_return(@entry) > end > > > describe "on the index page" do > it "should show all of the current_users entries" do > > @current_user.should_receive(:entries).with(@entry).and_return(true) This is wrong. The with method means parameters the expected method call receives. In your case it gets no parameters. Besides, since you stub the entries method anyway, you can just specify the behaviour. What you probably want with the code above is this: assigns[:entries].should == @entry //jarkko > > end > end > > > > > > > > > > > On Apr 7, 11:31 am, "Bryan Ray" wrote: >> Responses shown below... >> >> Sorry this isn't extremely informative ... in a bit of a rush. >> Hopefully it >> will point you in the appropriate direction. >> >> >> >> On Sun, Apr 6, 2008 at 2:17 PM, newbie wrote: >>> I'm new to Rspec and I'm having a bit of trouble with this >>> controller >>> that I'm testing. I think I'm doing it right but I guess my syntax >>> is >>> wrong. >>> I'm currently using the "acts_as_authenticated" plug in. >> >>> What I want to test out is >> >>> EventController on entering the tickets_page >>> - should show the tickets_page if the current_user has NOT entered >>> this page today >> >>> ----------------------------------------------------- >>> Below is my event controller >>> ----------------------------------------------------- >> >>> class EventController < ApplicationController >> >>> before_filter :login_required >> >>> def tickets_page >>> if current_user.has_already_entered_today? >>> flash[:notice] = 'Come back tomorrow' >>> redirect_to :action => 'home' >>> else >>> flash[:notice] = 'Welcome' >>> end >>> end >>> end >> >>> ----------------------------------------------------- >>> Below is my rspec for this controller >>> ----------------------------------------------------- >> >>> require File.dirname(__FILE__) + '/../spec_helper' >>> describe EventController do >> >>> before(:each) do >>> @current_user = mock_model(User, :id => 1) >>> controller.stub!(:current_user).and_return(@current_user) >>> controller.stub!(:login_required).and_return(:true) >>> end >> >>> fixtures :users >> >>> describe "on entering the tickets page" do >>> it "should show the tickets_page if the current_user has NOT >>> entered this page today" do >>> controller.current_user.stub! >>> (:has_already_entered_today?).and_return(:false) >>> get :tickets_page >> >>> controller >>> .current_user.should_receive(:has_already_entered_today?).with(:f >>> alse).and_return(:false) >>> response.should render_template(:tickets_page) >>> end >>> end >> >>> end >> >>> ----------------------------------------------------- >>> My errors >>> ----------------------------------------------------- >>> Mock 'User_1001' received unexpected >>> message :has_already_entered_today? with (no args) >> >> So this is a good start ... it means that the controller action is >> actually >> being mocked out ... you just need to keep moving forward mocking/ >> stubbing >> out the rest of your controller actions. it's complaining that it >> doesn't >> know what to do on your *current_user.has_already_entered_today?* >> method. >> >> @current_user.stub!(:has_already_entered_today?).and_return(> true or >> false here>) >> >> >> >>> Anyone can help with any direction of what I might be doing wrong? >> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> -- >> Bryan Rayhttp://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." >> >> _______________________________________________ >> 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 -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available Url : http://rubyforge.org/pipermail/rspec-users/attachments/20080411/1b9e1afb/attachment-0001.bin From ashley.moran at patchspace.co.uk Fri Apr 11 04:24:07 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 11 Apr 2008 09:24:07 +0100 Subject: [rspec-users] Multi-line steps In-Reply-To: References: <3E8754BB-C762-410B-B433-B3D52C1E7D8D@patchspace.co.uk> <8d961d900804090614gfdd1e5fvddda5a4abc911e4e@mail.gmail.com> <95107E12-A30F-4217-B1CD-EA12925B5F17@patchspace.co.uk> <810a540e0804091404n73dc7482k9201234306629a5f@mail.gmail.com> <8d961d900804101425s78f661c2k17afd06257588159@mail.gmail.com> Message-ID: On 11 Apr 2008, at 03:03, Rick DeNatale wrote: > And I wouldn't think that most reasonable systems would disable > Lisa1's account because some Lisa2 tried and failed to use the same > name. Somebody, somewhere has built a system that does this. You know it. -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Fri Apr 11 04:43:36 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 11 Apr 2008 09:43:36 +0100 Subject: [rspec-users] newbq: Organizing your stories In-Reply-To: <85d99afe0804102116i7397ac00n3ddd1da909b91ab7@mail.gmail.com> References: <85d99afe0804102116i7397ac00n3ddd1da909b91ab7@mail.gmail.com> Message-ID: <39E9D1EE-0C61-45DB-A114-25EAA72D8125@patchspace.co.uk> On 11 Apr 2008, at 05:16, Zach Dennis wrote: > - stories/ > - projects/ > - a_user_creating_a_project_story > - a_project_manager_adding_users_to_a_project_story > - admin/ > - an_admin_removing_users_story > > I use stories as system level integration tests, so they usually > cover a broader scope than a controller/action. > Same here: I write all my stories from the point of view of a system user trying to perform a task, with no regard for what code was being executed to let them do so. In Zach's example, I imagine a_project_manager_adding_users_to_a_project_story might touch StoryController and UsersController if you go on to the user's page to check that the project is on his list of users, etc... Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Fri Apr 11 04:44:41 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 11 Apr 2008 09:44:41 +0100 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: References: <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> <810a540e0804100948s7623579dk9e03223576aa73c4@mail.gmail.com> <54EA445F-B39E-4685-8C77-D2AB51EF87A4@gmail.com> <18352AFD-71F3-4A19-921D-4FBD78C84C8C@patchspace.co.uk> <810a540e0804101506h722ba176s88136afa1ac0c22e@mail.gmail.com> <810a540e0804101538u57b144ccr638f87c27dd33373@mail.gmail.com> Message-ID: <27BEF39C-E3C0-4AFE-8DD9-D7C9D31B0719@patchspace.co.uk> On 11 Apr 2008, at 03:14, Rick DeNatale wrote: > I'm thinking that I might just write a whole new xxx_steps.rb file > which would run the same story but at the real user interaction level, > and keep the model level steps also. I still haven't convinced myself > one way or the other. Wow, I had never thought of this. Could you really write a story that could be executed in two different environments based on the steps file that got loaded? Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From philodespotos at gmail.com Fri Apr 11 08:02:32 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Fri, 11 Apr 2008 07:02:32 -0500 Subject: [rspec-users] newbq: Organizing your stories In-Reply-To: <39E9D1EE-0C61-45DB-A114-25EAA72D8125@patchspace.co.uk> References: <85d99afe0804102116i7397ac00n3ddd1da909b91ab7@mail.gmail.com> <39E9D1EE-0C61-45DB-A114-25EAA72D8125@patchspace.co.uk> Message-ID: <60f3810c0804110502n6ffaf8d4m7e567974f32e5a39@mail.gmail.com> On Fri, Apr 11, 2008 at 3:43 AM, Ashley Moran wrote: > > On 11 Apr 2008, at 05:16, Zach Dennis wrote: > > > - stories/ > > - projects/ > > - a_user_creating_a_project_story > > - a_project_manager_adding_users_to_a_project_story > > - admin/ > > - an_admin_removing_users_story > > > > I use stories as system level integration tests, so they usually > > cover a broader scope than a controller/action. > > > > > Same here: I write all my stories from the point of view of a system > user trying to perform a task, with no regard for what code was being > executed to let them do so. In Zach's example, I imagine > a_project_manager_adding_users_to_a_project_story might touch > StoryController and UsersController if you go on to the user's page to > check that the project is on his list of users, etc... Add one more 'me too' to the pile. I tend to use a directory named after the feature, with .story files inside breaking that feature into smaller chunks/paths through the application. Not real examples, but say, stories/shop/product_listing.story, shop/featured_products.story, etc. But if the story is simpler, and really just demonstrates basic crud functionality, that's exactly what I've been naming it: stories/users/crud.story walks through adding new users, viewing the index, viewing a user, editing them, and removing them. Anything that does more interesting work is then done separately (users/reports.story, perhaps), but often relies on the steps for users/crud to walk through the application and set up the data. Though, as mentioned in the other thread, sometimes I just use AR directly to create the right preconditions. Kyle From dchelimsky at gmail.com Fri Apr 11 08:12:36 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Apr 2008 08:12:36 -0400 Subject: [rspec-users] newbq: Organizing your stories In-Reply-To: <39E9D1EE-0C61-45DB-A114-25EAA72D8125@patchspace.co.uk> References: <85d99afe0804102116i7397ac00n3ddd1da909b91ab7@mail.gmail.com> <39E9D1EE-0C61-45DB-A114-25EAA72D8125@patchspace.co.uk> Message-ID: <5FAB1E2A-F1F3-4C91-A27D-D3CEF4A31607@gmail.com> On Apr 11, 2008, at 4:43 AM, Ashley Moran wrote: > > On 11 Apr 2008, at 05:16, Zach Dennis wrote: > >> - stories/ >> - projects/ >> - a_user_creating_a_project_story >> - a_project_manager_adding_users_to_a_project_story >> - admin/ >> - an_admin_removing_users_story >> >> I use stories as system level integration tests, so they usually >> cover a broader scope than a controller/action. >> > > > Same here: I write all my stories from the point of view of a system > user trying to perform a task, with no regard for what code was being > executed to let them do so. In Zach's example, I imagine > a_project_manager_adding_users_to_a_project_story might touch > StoryController and UsersController I try not to think about what controllers I'm hitting in a story when thinking about the scenarios or steps. Clearly that comes up sooner or later, but it is secondary to the 'story' expressed by the story. FWIW, David > if you go on to the user's page to > check that the project is on his list of users, etc... > > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Apr 11 08:15:24 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Apr 2008 08:15:24 -0400 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: <27BEF39C-E3C0-4AFE-8DD9-D7C9D31B0719@patchspace.co.uk> References: <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> <810a540e0804100948s7623579dk9e03223576aa73c4@mail.gmail.com> <54EA445F-B39E-4685-8C77-D2AB51EF87A4@gmail.com> <18352AFD-71F3-4A19-921D-4FBD78C84C8C@patchspace.co.uk> <810a540e0804101506h722ba176s88136afa1ac0c22e@mail.gmail.com> <810a540e0804101538u57b144ccr638f87c27dd33373@mail.gmail.com> <27BEF39C-E3C0-4AFE-8DD9-D7C9D31B0719@patchspace.co.uk> Message-ID: On Apr 11, 2008, at 4:44 AM, Ashley Moran wrote: > > On 11 Apr 2008, at 03:14, Rick DeNatale wrote: > >> I'm thinking that I might just write a whole new xxx_steps.rb file >> which would run the same story but at the real user interaction >> level, >> and keep the model level steps also. I still haven't convinced >> myself >> one way or the other. > > Wow, I had never thought of this. Could you really write a story that > could be executed in two different environments based on the steps > file that got loaded? Absolutely. That is, in fact, one benefit of plain text stories that we don't have with ruby stories ... Yet. > > > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Apr 11 10:18:13 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Apr 2008 10:18:13 -0400 Subject: [rspec-users] Stories - Use view matchers rather than assigns[].should? In-Reply-To: References: <810a540e0804100820l65c145ccw4ebf98bf23a4e566@mail.gmail.com> <3761F713-54D9-424D-AE7D-2CA25D210CFE@gmail.com> <810a540e0804100948s7623579dk9e03223576aa73c4@mail.gmail.com> <54EA445F-B39E-4685-8C77-D2AB51EF87A4@gmail.com> <18352AFD-71F3-4A19-921D-4FBD78C84C8C@patchspace.co.uk> <810a540e0804101506h722ba176s88136afa1ac0c22e@mail.gmail.com> <810a540e0804101538u57b144ccr638f87c27dd33373@mail.gmail.com> <27BEF39C-E3C0-4AFE-8DD9-D7C9D31B0719@patchspace.co.uk> Message-ID: <6E19D348-DA1F-426F-8586-E4CB97D0EB03@gmail.com> On Apr 11, 2008, at 8:15 AM, David Chelimsky wrote: > On Apr 11, 2008, at 4:44 AM, Ashley Moran > wrote: > >> >> On 11 Apr 2008, at 03:14, Rick DeNatale wrote: >> >>> I'm thinking that I might just write a whole new xxx_steps.rb file >>> which would run the same story but at the real user interaction >>> level, >>> and keep the model level steps also. I still haven't convinced >>> myself >>> one way or the other. >> >> Wow, I had never thought of this. Could you really write a story >> that >> could be executed in two different environments based on the steps >> file that got loaded? > > Absolutely. That is, in fact, one benefit of plain text stories that > we don't have with ruby stories ... Yet. This is also a motivating factor in my own choice to keep the steps worded at high levels of abstraction. For example: Given I am filling in my profile When I enter nothing for E-Mail Address And I submit my info Then I should receive an error message telling me that E-Mail Address is required This scenario does not say "page" or "screen." It could run against a web system, desktop, command line, or even a batch system, though that might be a bit of a stretch. Of course, there are going to be cases when more granularity is required. If there is a requirement for a very specific user experience, something ajaxy for example, but these should be separated out as UI specific stories. Cheers, David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080411/a647381d/attachment.html From lists at ruby-forum.com Fri Apr 11 11:16:02 2008 From: lists at ruby-forum.com (Andy Orahood) Date: Fri, 11 Apr 2008 17:16:02 +0200 Subject: [rspec-users] autotest only passing spec files to rspec once Message-ID: <9adb5a83daf8fec81cd55225200e5433@ruby-forum.com> When I run autotest it works fine the first time, generating the command line: /usr/bin/ruby1.8 -S script/spec -O spec/spec.opts spec/models/timespan_spec.rb spec/models/article_spec.rb ... and all my specs get run. After the first runthrough, however, autotest pauses for a second and then, without me saving any files, generates another command line without any of the spec files: /usr/bin/ruby1.8 -S script/spec -O spec/spec.opts Then whenever I save a file or its associated spec file autotest produces this command line so no more specs get run until I press Ctrl-C or stop and restart autotest, when it again generates the correct command line with all the spec files included. I have the Zentest gem 3.9.2 and the rspec gem 1.1.3, and the latest rspec_on_rails and rspec plugins installed in my project. Does anyone have any ideas why this is happening? Thanks, Andy -- Posted via http://www.ruby-forum.com/. From esmith at 8thlight.com Fri Apr 11 10:56:49 2008 From: esmith at 8thlight.com (Eric Smith) Date: Fri, 11 Apr 2008 09:56:49 -0500 Subject: [rspec-users] mock_model outside of rails Message-ID: Hello all. I have a quick mock_model question. Is there a way to use it when doing ActiveRecord testing outside of rails? What I want to be able to do with my ActiveRecord is this: class Child belongs_to :parent end child.parent = mock_model(Parent) Now in rails I can do this, because mock_model does enough to fool ActiveRecord into think the relationship is valid, but to do this outside of rails I have to stub! the parent method to return the mock and only use the stubbed method in it. That's not particularly safe, and I bet there's a simple solution to this problem. Eric Smith From dchelimsky at gmail.com Fri Apr 11 11:45:16 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Apr 2008 11:45:16 -0400 Subject: [rspec-users] mock_model outside of rails In-Reply-To: References: Message-ID: On Apr 11, 2008, at 10:56 AM, Eric Smith wrote: > Hello all. I have a quick mock_model question. Is there a way to > use it when doing ActiveRecord testing outside of rails? Right now you can't because it's defined in the RailsExampleGroup. Why don't you put in a feature request to have it extracted from there so that it can be used in isolation? Cheers, David > What I want > to be able to do with my ActiveRecord is this: > > class Child > belongs_to :parent > end > > child.parent = mock_model(Parent) > > Now in rails I can do this, because mock_model does enough to fool > ActiveRecord into think the relationship is valid, but to do this > outside of rails I have to stub! the parent method to return the mock > and only use the stubbed method in it. That's not particularly safe, > and I bet there's a simple solution to this problem. > > Eric Smith > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rick.denatale at gmail.com Fri Apr 11 14:29:01 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 11 Apr 2008 14:29:01 -0400 Subject: [rspec-users] Does Ctrl-Shift-V in Textmate ever annoy you as an RSpec user? Message-ID: I love the TextMate feature of syntax checking ruby source with ^V. But often when I use it in an RSpec example group or a story steps file, I run into the problem that, although the file is syntactically correct, I get all kinds of warnings like: line 44: warning: useless use of '==' in void context which can produce a rather large tooltip, forcing me to scan to the end to see the Syntax OK I'm looking for, and worse, causing TextMate to scroll to the first line with a warning. Here's how to fix this: 1) Open the bundle editor, look at the Validate Syntax command in the Ruby bundle. You want to create a similar command in the RSpec bundle. Copy the text of this command, go to the RSpec bundle, add a new command, and paste the text in. Make sure that the options save: nothing, input:entire document, output: show as tooltip, and activation: key equivalent are selected. Click in the input field next to key equivalent and type ^-shift-v. Set the scope to rspec.ruby.source 2) Now look at the text for the command, change the line result = `"${TM_RUBY:=ruby}" -wc 2>&1` to result = `"${TM_RUBY:=ruby}" -c -W1 2>&1` which kicks the warning level down a notch. 3) Now look at the language definition in the RSpec bundle The first two lines should look like this: { scopeName = 'source.ruby.rspec'; fileTypes = ( 'spec.rb' ); change that second line to: fileTypes = ( 'spec.rb', 'steps.rb' ); This should let the bundle 'claim' story files as well. You'll get a few snippets that aren't really appropriate, but having those expectation snippets in a steps file is nice. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From dchelimsky at gmail.com Fri Apr 11 14:39:16 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Apr 2008 14:39:16 -0400 Subject: [rspec-users] Does Ctrl-Shift-V in Textmate ever annoy you as an RSpec user? In-Reply-To: References: Message-ID: On Apr 11, 2008, at 2:29 PM, Rick DeNatale wrote: > I love the TextMate feature of syntax checking ruby source with ^V. > But often when I use it in an RSpec example group or a story steps > file, I run into the problem that, although the file is syntactically > correct, I get all kinds of warnings like: > > > line 44: warning: useless use of '==' in void context > > > which can produce a rather large tooltip, forcing me to scan to the > end to see the Syntax OK I'm looking for, and worse, causing TextMate > to scroll to the first line with a warning. > > > Here's how to fix this: > > > 1) Open the bundle editor, look at the Validate Syntax command in the > Ruby bundle. You want to create a similar command in the RSpec > bundle. Copy the text of this command, go to the RSpec bundle, add a > new command, and paste the text in. Make sure that the options save: > nothing, input:entire document, output: show as tooltip, and > activation: key equivalent are selected. Click in the input field > next to key equivalent and type ^-shift-v. Set the scope to > rspec.ruby.source > > > 2) Now look at the text for the command, change the line > > result = `"${TM_RUBY:=ruby}" -wc 2>&1` > > to > > result = `"${TM_RUBY:=ruby}" -c -W1 2>&1` > > > which kicks the warning level down a notch. > > > 3) Now look at the language definition in the RSpec bundle > > The first two lines should look like this: > > { scopeName = 'source.ruby.rspec'; > fileTypes = ( 'spec.rb' ); > > > change that second line to: > > > fileTypes = ( 'spec.rb', 'steps.rb' ); > > > This should let the bundle 'claim' story files as well. You'll get a > few snippets that aren't really appropriate, but having those > expectation snippets in a steps file is nice. Wanna make a patch? From will.sargent at gmail.com Fri Apr 11 14:47:16 2008 From: will.sargent at gmail.com (Will Sargent) Date: Fri, 11 Apr 2008 11:47:16 -0700 Subject: [rspec-users] Easy way to specify protocol for a controller spec? Message-ID: Hi all, I'd like to add some controller specs that use HTTPS rather than HTTP. I've poked a bit into the get() and post() methods that are provided by ControllerTestCase, but it doesn't seem as though there's an easy way to specify that it should be using SSL from there. In ActionController, I can specify request.ssl! to force the request to be over HTTPS, but it looks like the request object provided by ControllerTestCase is using ActionController::TestRequest... and to do that, you'd usually do ths: @request.env['HTTPS'] = 'on' # from http://snippets.dzone.com/posts/show/467 But when I try this in a controller spec, this gives me a 302 redirect: request.env['HTTPS'] = 'on' get :foo So I must be missing something. Anyone know how to do this? Will. From olivierdupuis at gmail.com Fri Apr 11 15:21:31 2008 From: olivierdupuis at gmail.com (Olivier Dupuis) Date: Fri, 11 Apr 2008 15:21:31 -0400 Subject: [rspec-users] request.params causing errors Message-ID: <745312bd0804111221n1730eca6ic33996f07b5d1c30@mail.gmail.com> Hello, I have a rhtml file that goes through the request.params. One of my test generates that file, but rspec pops an error saying : undefined method 'params' for ... I'm not sure what to do with this, since request.params actually works with rails. Any idea? Thank you Olivier Dupuis -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080411/e61f03cf/attachment.html From dchelimsky at gmail.com Fri Apr 11 15:26:44 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Apr 2008 15:26:44 -0400 Subject: [rspec-users] request.params causing errors In-Reply-To: <745312bd0804111221n1730eca6ic33996f07b5d1c30@mail.gmail.com> References: <745312bd0804111221n1730eca6ic33996f07b5d1c30@mail.gmail.com> Message-ID: <1C357537-02EF-4814-B1F4-44E935FD1A78@gmail.com> Please post spec, code and error message. On Apr 11, 2008, at 3:21 PM, Olivier Dupuis wrote: > Hello, > > I have a rhtml file that goes through the request.params. One of my > test generates that file, but rspec pops an error saying : > > undefined method 'params' for ... > > I'm not sure what to do with this, since request.params actually > works with rails. > > Any idea? > > Thank you > > Olivier Dupuis > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From olivierdupuis at gmail.com Fri Apr 11 15:53:39 2008 From: olivierdupuis at gmail.com (Olivier Dupuis) Date: Fri, 11 Apr 2008 15:53:39 -0400 Subject: [rspec-users] request.params causing errors In-Reply-To: <1C357537-02EF-4814-B1F4-44E935FD1A78@gmail.com> References: <745312bd0804111221n1730eca6ic33996f07b5d1c30@mail.gmail.com> <1C357537-02EF-4814-B1F4-44E935FD1A78@gmail.com> Message-ID: <745312bd0804111253l72169280paee839fa0a28da8@mail.gmail.com> Sorry about that. Here goes... Spec: *describe "/search/index" do it "should have option to login" do render "/search/index" response.should have_text(/Login/) end end* Code for index.rhtml *
* Code for footer.rhtml *<% listOfParameters = "" %> <% request.params.each do |param| %> <% if param[0].to_s != "lang" %> <% listOfParameters = listOfParameters + "&" + param[0].to_s + "=" + param[1].to_s %> <% end %> <% end %> ...* Now the error message: *ActionView::TemplateError in '/search/index should have option to login' undefined method 'params' for # On line #7 of app/views/components/footer.rhtml **6: <% listOfParameters = "" %> 7: <% request.params.each do |param| %> 8: <% if param[0].to_s != "lang" %> 9: <% listOfParameters = listOfParameters + "&" + param[0].to_s + "=" + param[1].to_s %> 10: <% end %> 11: <% end %> *Thanks again Olivier Dupuis On Fri, Apr 11, 2008 at 3:26 PM, David Chelimsky wrote: > Please post spec, code and error message. > > On Apr 11, 2008, at 3:21 PM, Olivier Dupuis wrote: > > > Hello, > > > > I have a rhtml file that goes through the request.params. One of my > > test generates that file, but rspec pops an error saying : > > > > undefined method 'params' for ... > > > > I'm not sure what to do with this, since request.params actually > > works with rails. > > > > Any idea? > > > > Thank you > > > > Olivier Dupuis > > _______________________________________________ > > 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/20080411/a109433b/attachment.html From dchelimsky at gmail.com Fri Apr 11 16:05:31 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Apr 2008 16:05:31 -0400 Subject: [rspec-users] request.params causing errors In-Reply-To: <745312bd0804111253l72169280paee839fa0a28da8@mail.gmail.com> References: <745312bd0804111221n1730eca6ic33996f07b5d1c30@mail.gmail.com> <1C357537-02EF-4814-B1F4-44E935FD1A78@gmail.com> <745312bd0804111253l72169280paee839fa0a28da8@mail.gmail.com> Message-ID: <117B315B-FF38-4B84-826C-36D5ACC360A1@gmail.com> On Apr 11, 2008, at 3:53 PM, Olivier Dupuis wrote: > Sorry about that. Here goes... > > Spec: > > describe "/search/index" do > it "should have option to login" do > render "/search/index" > response.should have_text(/Login/) > end > end > > Code for index.rhtml > > >
> >
> > > Code for footer.rhtml > > <% listOfParameters = "" %> > <% request.params.each do |param| %> > <% if param[0].to_s != "lang" %> > <% listOfParameters = listOfParameters + "&" + param[0].to_s > + "=" + param[1].to_s %> > <% end %> > <% end %> > > ... > > Now the error message: > > ActionView::TemplateError in '/search/index should have option to > login' > undefined method 'params' for # 0x46a044c> > On line #7 of app/views/components/footer.rhtml > > 6: <% listOfParameters = "" %> > 7: <% request.params.each do |param| %> Try just params (not request.params) - does that work? > > 8: <% if param[0].to_s != "lang" %> > 9: <% listOfParameters = listOfParameters + "&" + > param[0].to_s + "=" + param[1].to_s %> > 10: <% end %> > 11: <% end %> > > > Thanks again > > Olivier Dupuis > > > On Fri, Apr 11, 2008 at 3:26 PM, David Chelimsky > wrote: > Please post spec, code and error message. > > On Apr 11, 2008, at 3:21 PM, Olivier Dupuis wrote: > > > Hello, > > > > I have a rhtml file that goes through the request.params. One of my > > test generates that file, but rspec pops an error saying : > > > > undefined method 'params' for ... > > > > I'm not sure what to do with this, since request.params actually > > works with rails. > > > > Any idea? > > > > Thank you > > > > Olivier Dupuis > > _______________________________________________ > > 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/20080411/d9bd0c09/attachment-0001.html From ashley.moran at patchspace.co.uk Sat Apr 12 04:54:53 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sat, 12 Apr 2008 09:54:53 +0100 Subject: [rspec-users] Inspect STDERR in a story Message-ID: Hi I have a story step that looks like this: When /(the user|then) runs "migrate (.*)"/ do |_, args| cd project_dir do @output = `#{migrate} #{args}` end @output_lines = @output.split("\n") end Which is fine for testing STDOUT but not STDERR. I don't want to redirect STDERR to STDOUT because then the story can't prove that error messages are displayed separately (although the specs would) Any hints? :) Thanks Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From olivierdupuis at gmail.com Sat Apr 12 06:09:53 2008 From: olivierdupuis at gmail.com (Olivier Dupuis) Date: Sat, 12 Apr 2008 06:09:53 -0400 Subject: [rspec-users] request.params causing errors In-Reply-To: <117B315B-FF38-4B84-826C-36D5ACC360A1@gmail.com> References: <745312bd0804111221n1730eca6ic33996f07b5d1c30@mail.gmail.com> <1C357537-02EF-4814-B1F4-44E935FD1A78@gmail.com> <745312bd0804111253l72169280paee839fa0a28da8@mail.gmail.com> <117B315B-FF38-4B84-826C-36D5ACC360A1@gmail.com> Message-ID: <745312bd0804120309s25701dev168903a18f6313fa@mail.gmail.com> It unfortunately access the wrong parameters. Instead of accessing the parameters from my url request, it access the parameters from my render_component. For example, my request is * http://localhost:4000/search/results?author=&keyword=&page=1&publisher=&title=agile * In that results view, I render this component *<%= render_component :controller => "components", :action => "footer", :params => { :lang => @language } %>* So in the footer component, when I execute *<% request.params.each do |param| %>* it goes through the params from * http://localhost:4000/search/results?author=&keyword=&page=1&publisher=&title=agile *But if I execute *<% params.each do |param| %> *it goes through the params from *<%= render_component :controller => "components", :action => "footer", :params => { :lang => @language } %> *My test passes when I use only *params.each* but not when I use * request.params.each *Thanks again Olivier Dupuis On Fri, Apr 11, 2008 at 4:05 PM, David Chelimsky wrote: > On Apr 11, 2008, at 3:53 PM, Olivier Dupuis wrote: > > Sorry about that. Here goes... > > Spec: > > *describe "/search/index" do > it "should have option to login" do > render "/search/index" > response.should have_text(/Login/) > end > end* > > Code for index.rhtml > > * >
> >
> * > > Code for footer.rhtml > > *<% listOfParameters = "" %> > <% request.params.each do |param| %> > <% if param[0].to_s != "lang" %> > <% listOfParameters = listOfParameters + "&" + param[0].to_s + "=" > + param[1].to_s %> > <% end %> > <% end %> > > ...* > > Now the error message: > > *ActionView::TemplateError in '/search/index should have option to login' > undefined method 'params' for # > On line #7 of app/views/components/footer.rhtml > > **6: <% listOfParameters = "" %> > 7: <% request.params.each do |param| %>* > > > Try just params (not request.params) - does that work? > > * > 8: <% if param[0].to_s != "lang" %> > 9: <% listOfParameters = listOfParameters + "&" + param[0].to_s + > "=" + param[1].to_s %> > 10: <% end %> > 11: <% end %> > > > *Thanks again > > Olivier Dupuis > > > On Fri, Apr 11, 2008 at 3:26 PM, David Chelimsky > wrote: > > > Please post spec, code and error message. > > > > On Apr 11, 2008, at 3:21 PM, Olivier Dupuis wrote: > > > > > Hello, > > > > > > I have a rhtml file that goes through the request.params. One of my > > > test generates that file, but rspec pops an error saying : > > > > > > undefined method 'params' for ... > > > > > > I'm not sure what to do with this, since request.params actually > > > works with rails. > > > > > > Any idea? > > > > > > Thank you > > > > > > Olivier Dupuis > > > _______________________________________________ > > > 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/20080412/b91f9533/attachment.html From edvard at majakari.net Sat Apr 12 06:51:10 2008 From: edvard at majakari.net (Edvard Majakari) Date: Sat, 12 Apr 2008 13:51:10 +0300 Subject: [rspec-users] Inspect STDERR in a story In-Reply-To: References: Message-ID: On Sat, Apr 12, 2008 at 11:54 AM, Ashley Moran wrote: > Hi > > I have a story step that looks like this: > > When /(the user|then) runs "migrate (.*)"/ do |_, args| > cd project_dir do > @output = `#{migrate} #{args}` > end > @output_lines = @output.split("\n") > end > > Which is fine for testing STDOUT but not STDERR. I don't want to > redirect STDERR to STDOUT because then the story can't prove that > error messages are displayed separately (although the specs would) How about something along the lines cd project_dir do @stdout, @stdterr = capture_outputs("#{migrate} #{args}") end ... def capture_outputs(cmd) stderr_log = "/tmp" + "/#{$0}-{$$}.log" out = `cmd 2> #{stderr_log}` err = File.read(stderr_log) if File.exist? stderr_log [out, err] end Totally untested, but hopefully you get the idea? -- "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 backslash451 at yahoo.it Sat Apr 12 07:06:34 2008 From: backslash451 at yahoo.it (roberto belardo) Date: Sat, 12 Apr 2008 13:06:34 +0200 (CEST) Subject: [rspec-users] Rspecing this simple controller it is driving me mad... In-Reply-To: <228A8C93-70E7-40DD-B70D-77DA656D5D32@jlaine.net> Message-ID: <767154.41743.qm@web27012.mail.ukl.yahoo.com> Uhm ok, i understood your answer but autotest did not. Better, this do not solves the problem. If i simply remove the "stub" and the "should_receive" for the author field, autotest will complain like this: Spec::Mocks::MockExpectationError in 'CommentsController handling POST /comments should create a new comment' Mock 'Comment_1008' received unexpected message :author= with (#) and this was the reason why i put the "should_receive" and the "stub" on "author=" method, as someone told previously on this ml. :( Is there someone who knows how to spec this? Help needed. --- Jarkko Laine ha scritto: > > On 8.4.2008, at 23.06, roberto belardo wrote: > > > Everything seemed so fine, but when i tried to > > investigate a little i discovered this tremendous > > behaviour of the spec: > > > > ------------------------------- CommentsController > > def create > > @comment = Comment.new(params[:comment]) > > @user = User.find(params[:user_id]) > > @comment.author = 'foooooobar' > > @comment.save > > end > > > > ------------------------------- CommentsController > > Spec > > describe CommentsController, "handling > POST/comments" > > do > > before(:each) do > > @user = mock_model(User, :to_param => "2") > > @comment = mock_model(Comment, :to_param => > "1", > > :author => @user) > > > > > User.should_receive(:find).at_least(1).times.and_return(@user) > > Comment.stub!(:new).and_return(@comment) > > @comment.stub!(:author=) > > end > > > > def post_with_successful_save > > @comment.should_receive(:save).and_return(true) > > @comment.should_receive(:author=) > > post :create, :user_id => @user_id, :comment => > {} > > end > > > > it "should create a new comment" do > > > > > Comment.should_receive(:new).with({}).and_return(@comment) > > post_with_successful_save > > @comment.author.should be(@user) > > end > > end > > > > ------------------------------- Autotest: > > ... 0 failures > > > > How can the spec pass if i test that > @comment.author > > should be @user but in the controller i set a > > fooooobar string in the @comment.author? > > Because @comment.should_receive(:author=) stubs the > method so it has > no effect after that. I would advice against using > it in a general > purpose helper such as post_with_successful_save and > instead use it in > an actual spec if needed. > > > > > > Better question: wich is the right way to test > that > > create action to be sure, it will set the author > of > > the comment? > > Since you're testing that "@comment.author.should > be(@user)", I see no > reason to explicitly have > "@comment.should_receive(:author=)". The > former correctly tests the behaviour, whereas the > latter checks the > actual implementation, which in this case is > superfluous. I hardly > ever use should_receive with a setter method such as > author=, but it > might just be me. > > Cheers, > //jarkko > > > > > > > > > --- Jarkko Laine ha scritto: > > > > ... > > > >> Short answer: you haven't stubbed the author= > method > >> for the comment > >> mock, only author. > >> > >> A bit longer answer: Are you sure you can trust > the > >> user to only > >> submit valid user ids? With your current code, > >> anyone can change the > >> user_id parameter in the call and fake any user > id > >> she wants. This > >> might be intentional (if there are only admin > users > >> in your app), just > >> pointing it out. You can also simplify your > action > >> by just saying > >> @user.comments.create(params[:comment]) once you > >> have the user fetched. > >> > >> Cheers, > >> //jarkko > >> > >>> > >>> Thanks in advance, > >>> Roberto. > >>> > >>> > >>> Inviato da Yahoo! Mail. > >>> La casella di posta intelligente. > >>> > 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 > >> > >> -- > >> Jarkko Laine > >> http://jlaine.net > >> http://dotherightthing.com > >> http://www.railsecommerce.com > >> http://odesign.fi > >> > >> > >>> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > Inviato da Yahoo! Mail. > > La casella di posta intelligente. > > 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 > > -- > Jarkko Laine > http://jlaine.net > http://dotherightthing.com > http://www.railsecommerce.com > http://odesign.fi > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Inviato da Yahoo! Mail. La casella di posta intelligente. http://it.docs.yahoo.com/mail/overview/index.html From ashley.moran at patchspace.co.uk Sat Apr 12 09:17:34 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sat, 12 Apr 2008 14:17:34 +0100 Subject: [rspec-users] Inspect STDERR in a story In-Reply-To: References: Message-ID: On 12 Apr 2008, at 11:51, Edvard Majakari wrote: > How about something along the lines > > cd project_dir do > @stdout, @stdterr = capture_outputs("#{migrate} #{args}") > end > > ... > def capture_outputs(cmd) > stderr_log = "/tmp" + "/#{$0}-{$$}.log" > out = `cmd 2> #{stderr_log}` > err = File.read(stderr_log) if File.exist? stderr_log > [out, err] > end > > Totally untested, but hopefully you get the idea? Yeah! Don't know why I didn't think of just sending stderr to a log file myself... Thanks Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From alen198 at gmail.com Sat Apr 12 15:24:22 2008 From: alen198 at gmail.com (newbie) Date: Sat, 12 Apr 2008 12:24:22 -0700 (PDT) Subject: [rspec-users] how to stub the :current_user and any methods associated with it In-Reply-To: <1D4C8509-001E-4187-8119-0483C8E4A367@jlaine.net> References: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> <29a0119e0804070831v5198bff7qcc6f4a757578af4e@mail.gmail.com> <691ed0f1-88cc-4225-88bf-f7065a0ae157@24g2000hsh.googlegroups.com> <1D4C8509-001E-4187-8119-0483C8E4A367@jlaine.net> Message-ID: Hey Jarkko, Thanks for the feedback. I tried your suggestion and it doesn't seem to work. To quickly recap I'm just testing in my controller that this works def index @entries = current_user.entries end describe "on the main page" do it "should show all the current entries for the user" do get :index assigns[:entries].should == @entries end From jarkko at jlaine.net Sun Apr 13 13:01:27 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Sun, 13 Apr 2008 20:01:27 +0300 Subject: [rspec-users] Rspecing this simple controller it is driving me mad... In-Reply-To: <767154.41743.qm@web27012.mail.ukl.yahoo.com> References: <767154.41743.qm@web27012.mail.ukl.yahoo.com> Message-ID: <06704A9B-AAEA-4C44-B2C3-02C9D3BE3E28@jlaine.net> On 12.4.2008, at 14.06, roberto belardo wrote: > Uhm ok, i understood your answer but autotest did not. > Better, this do not solves the problem. > If i simply remove the "stub" and the "should_receive" > for the author field, autotest will complain like > this: > > Spec::Mocks::MockExpectationError in > 'CommentsController handling POST /comments should > create a new comment' > Mock 'Comment_1008' received unexpected message > :author= with (# @name="User_1006">) > > and this was the reason why i put the "should_receive" > and the "stub" on "author=" method, as someone told > previously on this ml. > :( > > Is there someone who knows how to spec this? Help > needed. Two ways: 1) either use Comment.new instead of mock_model(Comment) in your before block. This way your comment object has the ability to assign its author. 2) Use the mock model and your should_receive test. However, after that you cannot test that @comment.author.should be(@user) because you have stubbed author= and it doesn't really do anything. So you just have to rely on that it works (like you should since it's Rails code which you shouldn't really be testing). //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available Url : http://rubyforge.org/pipermail/rspec-users/attachments/20080413/80699141/attachment-0001.bin From jarkko at jlaine.net Sun Apr 13 13:03:29 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Sun, 13 Apr 2008 20:03:29 +0300 Subject: [rspec-users] how to stub the :current_user and any methods associated with it In-Reply-To: References: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> <29a0119e0804070831v5198bff7qcc6f4a757578af4e@mail.gmail.com> <691ed0f1-88cc-4225-88bf-f7065a0ae157@24g2000hsh.googlegroups.com> <1D4C8509-001E-4187-8119-0483C8E4A367@jlaine.net> Message-ID: On 12.4.2008, at 22.24, newbie wrote: > Hey Jarkko, > > Thanks for the feedback. I tried your suggestion and it doesn't seem > to work. What doesn't work? > > > To quickly recap I'm just testing in my controller that this works > > def index > @entries = current_user.entries > end > > describe "on the main page" do > it "should show all the current entries for the user" do > get :index > assigns[:entries].should == @entries > end I don't see you logging in a user anywhere. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available Url : http://rubyforge.org/pipermail/rspec-users/attachments/20080413/c5ab6e24/attachment.bin From smingins at elctech.com Sun Apr 13 16:50:25 2008 From: smingins at elctech.com (Shane Mingins) Date: Mon, 14 Apr 2008 08:50:25 +1200 Subject: [rspec-users] how to stub the :current_user and any methods associated with it In-Reply-To: References: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> <29a0119e0804070831v5198bff7qcc6f4a757578af4e@mail.gmail.com> <691ed0f1-88cc-4225-88bf-f7065a0ae157@24g2000hsh.googlegroups.com> <1D4C8509-001E-4187-8119-0483C8E4A367@jlaine.net> Message-ID: <853CB107-2A96-45D8-927F-851D9C3725BC@elctech.com> Looking at yr earlier post ... controller.stub!(:entries).and_return(@entry) Not sure why you are stubbing entries on the controller ... entries is called on the current user ... I tend to do this ... @current_user = mock_model(User, :id => 1, :entries => [@entry]) HTH Shane On 13/04/2008, at 7:24 AM, newbie wrote: > Hey Jarkko, > > Thanks for the feedback. I tried your suggestion and it doesn't seem > to work. > > To quickly recap I'm just testing in my controller that this works > > def index > @entries = current_user.entries > end > > describe "on the main page" do > it "should show all the current entries for the user" do > get :index > assigns[:entries].should == @entries > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From edvard at majakari.net Mon Apr 14 09:36:02 2008 From: edvard at majakari.net (Edvard Majakari) Date: Mon, 14 Apr 2008 16:36:02 +0300 Subject: [rspec-users] Inspect STDERR in a story In-Reply-To: References: Message-ID: On Sat, Apr 12, 2008 at 4:17 PM, Ashley Moran wrote: > Yeah! Don't know why I didn't think of just sending stderr to a log > file myself... ..because you're likely smart enough to avoid using file as a temporary variable whenever possible :) First off, using the method similar to above would break bad if you run tests in parallel inside the same process. But that's easy enough to fix (eg. add some random stuff). No, I don't run stuff in parallel yet because deep_test is not ready for RSpec yet, but in the future, I hope I'll be able to. -- "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 ashley.moran at patchspace.co.uk Mon Apr 14 15:07:30 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 14 Apr 2008 20:07:30 +0100 Subject: [rspec-users] Inspect STDERR in a story In-Reply-To: References: Message-ID: On 14 Apr 2008, at 14:36, Edvard Majakari wrote: > ..because you're likely smart enough to avoid using file as a > temporary variable whenever possible :) Ha, I don't know... I haven't checked Daily WTF lately to see if any of my code has made it on there :) > First off, using the method similar to above would break bad if you > run tests in parallel inside the same process. But > that's easy enough to fix (eg. add some random stuff). No, I don't run > stuff in parallel yet because deep_test is not ready for RSpec yet, > but in the future, I hope I'll be able to. Well I'm already using something similar - the stories make a temporary directory with a random name to run the tool inside, so I guess a statically named stderr.out file would be ok in there. It's just that using a file to capture half the output of a command seems really ugly. I had checked out deeptest and it looks pretty cool. Fingers crossed it will support RSpec soon Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From tastapod at gmail.com Mon Apr 14 16:57:19 2008 From: tastapod at gmail.com (Dan North) Date: Mon, 14 Apr 2008 21:57:19 +0100 Subject: [rspec-users] newbq: Organizing your stories In-Reply-To: <39E9D1EE-0C61-45DB-A114-25EAA72D8125@patchspace.co.uk> References: <85d99afe0804102116i7397ac00n3ddd1da909b91ab7@mail.gmail.com> <39E9D1EE-0C61-45DB-A114-25EAA72D8125@patchspace.co.uk> Message-ID: I like this. It's pretty much one folder per stakeholder. If you have a question about a story or if a scenario starts failing, you immediately know who to ask whether it matters. I'm more and more coming round to this model on an ideological level. It seems a more natural grouping (and more tangible) than "functional area" or "feature set". Having said that I don't use rspec in anger on my day-to-day projects so I am happy to defer to those who do. Cheers, Dan On 11/04/2008, Ashley Moran wrote: > > > On 11 Apr 2008, at 05:16, Zach Dennis wrote: > > > - stories/ > > - projects/ > > - a_user_creating_a_project_story > > - a_project_manager_adding_users_to_a_project_story > > - admin/ > > - an_admin_removing_users_story > > > > I use stories as system level integration tests, so they usually > > cover a broader scope than a controller/action. > > > > > > Same here: I write all my stories from the point of view of a system > user trying to perform a task, with no regard for what code was being > executed to let them do so. In Zach's example, I imagine > a_project_manager_adding_users_to_a_project_story might touch > StoryController and UsersController if you go on to the user's page to > check that the project is on his list of users, etc... > > Ashley > > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > > > > _______________________________________________ > 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/20080414/78cb48a7/attachment.html From jam5t3r.lists at gmail.com Mon Apr 14 21:58:58 2008 From: jam5t3r.lists at gmail.com (Jamie D) Date: Mon, 14 Apr 2008 18:58:58 -0700 Subject: [rspec-users] rspec test for converting a hash to a URL string Message-ID: <9acc822c0804141858o2894231cyadb58d345ea2f83d@mail.gmail.com> Hi all, I've written an expectation for a method that converts a hash into a url string of name/value pairs. The problem is that the hash is not traversed in the same order as it is defined so I can not work out how to test for the correct returned string. The operation of the code does not require and specific order so I am not going to add a specific order to my method. # test def mappings_data { :shell => true, :ftp => 10, :sql => 11, :email => 12, :subdomains => 13, :parkeddomains => 14, :addondomains => 15, :transfer => 16 } end it "should map arguments to a url" do @whm.map_args_to_url(mappings_data).should eql("?shell=true&ftp=10&sql=11&email=12&subdomains=13&parkeddomains=14&addondomains=15&transfer=16") end # implementation def map_args_to_url(args={}) '?' + args.map { |k,v| "%s=%s" % [URI.encode(k.to_s), URI.encode(v.to_s)] }.join('&') unless args.blank? end # string that is returned "?parkeddomains=14&shell=true&email=12&addondomains=15&ftp=10&subdomains=13&transfer=16&sql=11" From pergesu at gmail.com Mon Apr 14 22:33:10 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 14 Apr 2008 19:33:10 -0700 Subject: [rspec-users] rspec test for converting a hash to a URL string In-Reply-To: <9acc822c0804141858o2894231cyadb58d345ea2f83d@mail.gmail.com> References: <9acc822c0804141858o2894231cyadb58d345ea2f83d@mail.gmail.com> Message-ID: <810a540e0804141933v5a63b460j3eae6ed3f2c83b11@mail.gmail.com> On Mon, Apr 14, 2008 at 6:58 PM, Jamie D wrote: > Hi all, I've written an expectation for a method that converts a hash > into a url string of name/value pairs. The problem is that the hash is > not traversed in the same order as it is defined so I can not work out > how to test for the correct returned string. The operation of the code > does not require and specific order so I am not going to add a > specific order to my method. > > > # test > def mappings_data > { > :shell => true, > :ftp => 10, > :sql => 11, > :email => 12, > :subdomains => 13, > :parkeddomains => 14, > :addondomains => 15, > :transfer => 16 > } > end > > it "should map arguments to a url" do > @whm.map_args_to_url(mappings_data).should > eql("?shell=true&ftp=10&sql=11&email=12&subdomains=13&parkeddomains=14&addondomains=15&transfer=16") > end > > # implementation > def map_args_to_url(args={}) > '?' + args.map { |k,v| "%s=%s" % [URI.encode(k.to_s), > URI.encode(v.to_s)] }.join('&') unless args.blank? > end > > # string that is returned > "?parkeddomains=14&shell=true&email=12&addondomains=15&ftp=10&subdomains=13&transfer=16&sql=11" > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > You can use the CGI library to parse the query string, and verify that the hashes are equal. params = {:foo => true, :bar => 12} params_as_strings = {} params.each_key {|key| params_as_strings[key.to_s] = params[key].to_s } query_string = map_args_to_url params CGI.parse(query_string.delete("?")).should == params_as_strings (completely untested, so you'll have to mess with it I'm sure) That's a bit ugly and verbose, so it may be a good candidate for a custom matcher query_string.should equal_query_string("?foo=true&bar=12") The matcher would call CGI.parse on the actual and expected strings and verify that they are equal. Another thing that jumps out at me is that there may be a chance to build a QueryParams abstraction. So instead of the above expectation, you might do query_params.should == QueryParams.new(:foo => true, :bar => 12) (you would still have to write a spec verifying the QueryParams#to_s hash->string conversion of course) If all you're doing at this point is building that string, then a QueryParams object is probably overkill. But I would be ready to move to it as soon as I started to do any more logic with the query string, such as asserting that it contains a certain key-value pair. Like I said at the beginning, this is probably a good situation for a custom expectation matcher to hide some of the messy details. Just keep in mind that the thresholds for creating a custom matcher and creating a new object are not that far apart, and creating a new object is generally way more valuable. (that was almost certainly a lot longer than you wanted, sorry. I've just been sick the last couple days and needed to scratch my list-writing itch :) Pat From lists at ruby-forum.com Tue Apr 15 11:20:59 2008 From: lists at ruby-forum.com (Giuseppe Bertini) Date: Tue, 15 Apr 2008 17:20:59 +0200 Subject: [rspec-users] textmate => pass, autotest => failing specs ??? Message-ID: <95465ccc9f23aaa52cd0e17f356c14b0@ruby-forum.com> Hi all, I hope I can get a quick pointer about the following problem: I have a controller spec with 38 examples, all green if run from *within* TextMate. >From the shell, however (through either rake or autotest) I get a handful of pink errors. For example, I get a few TypeErrors ("can't convert Note into Array") that appear to be raised while my index action is paginating records, but I am obviously NOT asking help on the specific issue. Rather, I'd like to know in general how to address such a discrepancy between environments in the outcome of my tests. Thanks heaps! Giuseppe -- Posted via http://www.ruby-forum.com/. From matt at mattberther.com Tue Apr 15 13:02:10 2008 From: matt at mattberther.com (Matt Berther) Date: Tue, 15 Apr 2008 11:02:10 -0600 Subject: [rspec-users] textmate => pass, autotest => failing specs ??? In-Reply-To: <95465ccc9f23aaa52cd0e17f356c14b0@ruby-forum.com> References: <95465ccc9f23aaa52cd0e17f356c14b0@ruby-forum.com> Message-ID: HI Giuseppe, I had a similar situation, only reversed. All ran with autotest, but failed in Textmate. I found the problem was in how I was including some helper modules and correcting that solved the problem. On Tue, Apr 15, 2008 at 9:20 AM, Giuseppe Bertini wrote: > Hi all, > I hope I can get a quick pointer about the following problem: > > I have a controller spec with 38 examples, all green if run from > *within* TextMate. > > >From the shell, however (through either rake or autotest) I get a > handful of pink errors. > > For example, I get a few TypeErrors ("can't convert Note into Array") > that appear to be raised while my index action is paginating records, > but I am obviously NOT asking help on the specific issue. > > Rather, I'd like to know in general how to address such a discrepancy > between environments in the outcome of my tests. > > Thanks heaps! > Giuseppe > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Matt Berther http://www.mattberther.com From eirik at imap.cc Tue Apr 15 13:10:13 2008 From: eirik at imap.cc (Eirik Dentz Sinclair) Date: Tue, 15 Apr 2008 10:10:13 -0700 Subject: [rspec-users] Mocking and stubbing Rails' has_many association Message-ID: <2F8FC3B4-49EE-498F-A43C-4738542797A8@imap.cc> I'm somewhat new to testing and rspec. And I'm struggling a bit with the application of Mocks and Stubs in a Rails application. I think I'm beginning to grasp it, but I'm stuck on how to spec the following: I have a User model which has a has_many relationship to Trip models, and the implementation is taken from http://railscasts.com/episodes/75 So I have the following methods in my User model to handle the nested Trip attributes that are passed to the User model: def new_trip_attributes=(trip_attributes) trip_attributes.each do |attributes| trips.build(attributes) end end def existing_trip_attributes=(trip_attributes) trips.reject(&:new_record?).each do |trip| attributes = trip_attributes[trip.id.to_s] if attributes trip.attributes = attributes else trips.delete(trip) end end end Part of my problem is probably that I'm not doing true T/B driven development, but trying to spec Ryan's implmentation. Anyway for the new_trip_attributes= method I've come up with the following spec: it "should use new trip attributes to add Trips to the trips association" do @user.stub_association!(:trips, :build => mock_model(Trip, :save => true)) @user.new_trip_attributes = trip_attributes end (I found the stub_association! method here: http://www.ruby-forum.com/topic/126993) This seems to work, though I'm not sure that the single example is sufficient coverage for that method... But where I'm really running into trouble is with the existing_trip_attributes= method. I've been trying to puzzle through it using this thread as a guideline: http://www.ruby-forum.com/topic/138342 These are the examples I came up with to cover the method it "should ignore new associated trip records" it "should update the associated existing trip" it "should delete the associated existing trip, if there are no attributes for it" I'm really not sure what to mock, what to stub or even if my confusion is an indication that the method implementation should be different. Beyond my specific implementation question, It would be great to hear from more experienced Rspec users on how to discern the difference between ones capability with the tool (Rspec), vs. the tool's feedback that the implementation needs to be changed. I have studied the first three peepcode rspec episodes as well as the altered beast specs http://git.caboo.se/?p=altered_beast.git;a=summary and done a bit of searching and reading through the list archives. The Altered beast specs are enlightening, but they make use of some extensions to Rspec and I would rather not confuse myself with trying to learn those extensions at the same time. Any other suggestions for open source rails projects with good specs to learn from would be appreciated as well. Thanks in advance for any suggestions you might have. ________________________ Eirik Dentz Sinclair http://dentz.net From lists at ruby-forum.com Tue Apr 15 13:34:27 2008 From: lists at ruby-forum.com (Giuseppe Bertini) Date: Tue, 15 Apr 2008 19:34:27 +0200 Subject: [rspec-users] textmate => pass, autotest => failing specs ??? In-Reply-To: References: <95465ccc9f23aaa52cd0e17f356c14b0@ruby-forum.com> Message-ID: <2425956da1217247fbdfdfd6d9bfedc3@ruby-forum.com> Hi Matt, > I had a similar situation, only reversed. All ran with autotest, but > failed in Textmate. I found the problem was in how I was including > some helper modules and correcting that solved the problem. right, I've heard about that before, and I thought that my problem may be similar in nature, but I am currently at a loss. Thanks, Giuseppe -- Posted via http://www.ruby-forum.com/. From ben at benmabey.com Tue Apr 15 14:08:20 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 15 Apr 2008 12:08:20 -0600 Subject: [rspec-users] textmate => pass, autotest => failing specs ??? In-Reply-To: <2425956da1217247fbdfdfd6d9bfedc3@ruby-forum.com> References: <95465ccc9f23aaa52cd0e17f356c14b0@ruby-forum.com> <2425956da1217247fbdfdfd6d9bfedc3@ruby-forum.com> Message-ID: <4804EF14.7000707@benmabey.com> Giuseppe Bertini wrote: > Hi Matt, > > >> I had a similar situation, only reversed. All ran with autotest, but >> failed in Textmate. I found the problem was in how I was including >> some helper modules and correcting that solved the problem. >> > > right, I've heard about that before, and I thought that my problem may > be similar in nature, but I am currently at a loss. > > Thanks, > Giuseppe > Giuseppe, autotest will run your tests in different order. It does this to catch any dependencies your tests may have on each other in order to reveal brittle tests. For more info see: http://blog.zenspider.com/archives/2008/01/zentest_390_now_with_more_evil.html -Ben From lists at ruby-forum.com Tue Apr 15 15:27:03 2008 From: lists at ruby-forum.com (Giuseppe Bertini) Date: Tue, 15 Apr 2008 21:27:03 +0200 Subject: [rspec-users] textmate => pass, autotest => failing specs ??? In-Reply-To: <4804EF14.7000707@benmabey.com> References: <95465ccc9f23aaa52cd0e17f356c14b0@ruby-forum.com> <2425956da1217247fbdfdfd6d9bfedc3@ruby-forum.com> <4804EF14.7000707@benmabey.com> Message-ID: <6f396aa06c1d2bcb46d074710776877d@ruby-forum.com> > catch any dependencies your tests may have on each other > in order to reveal brittle tests. Following Ben's hint, I took out examples from the controller spec until I isolated the culprit. Briefly, I am switching from RSpec's built in mocking framework to Mocha and fixture_scenarios when necessary. I had forgotten to modify one of the examples, which still had this construct: object.should_receive(:method).and_return(:a_mock) instead of Mocha's: object.expects(:method).returns(:a_mock) So I have empirically learned that enabling config.mock_with :mocha in /spec/spec_helper.rb and then mixing Mocha with RSpec's own mocking/stubbing messes things up in a nasty way, in the sense that failures occur all over the place with error messages that did not help me finding the bug. And again, these errors were not raised by TextMate's environment. Tricky. Thanks for the feedback! Giuseppe -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Apr 15 18:05:54 2008 From: lists at ruby-forum.com (Zubin Henner) Date: Wed, 16 Apr 2008 00:05:54 +0200 Subject: [rspec-users] before_validation callbacks bypassed when stubbing :valid? Message-ID: <3399554dc93b4c860fe69a5d40f9217b@ruby-forum.com> I'm testing an ActiveRecord model using rspec and mocha, and found that if I stub out the :valid? method, all before_validation callbacks are also skipped! Not ideal - I still want the callbacks to execute, but the validation to return true. Anyone know how to achieve this? class Item < ActiveRecord::Base before_validation :do_something def do_something raise "hell" end end Item.any_instance.stubs(:valid?).returns(true) item = Item.new item.valid? -- Posted via http://www.ruby-forum.com/. From bryansray at gmail.com Tue Apr 15 18:23:33 2008 From: bryansray at gmail.com (Bryan Ray) Date: Tue, 15 Apr 2008 17:23:33 -0500 Subject: [rspec-users] textmate => pass, autotest => failing specs ??? In-Reply-To: <6f396aa06c1d2bcb46d074710776877d@ruby-forum.com> References: <95465ccc9f23aaa52cd0e17f356c14b0@ruby-forum.com> <2425956da1217247fbdfdfd6d9bfedc3@ruby-forum.com> <4804EF14.7000707@benmabey.com> <6f396aa06c1d2bcb46d074710776877d@ruby-forum.com> Message-ID: <29a0119e0804151523s431dbc77gb19f09ab44c34951@mail.gmail.com> That'll learn ya to use Mocha over rSpec ;) On Tue, Apr 15, 2008 at 2:27 PM, Giuseppe Bertini wrote: > > catch any dependencies your tests may have on each other > > in order to reveal brittle tests. > > Following Ben's hint, I took out examples from the controller spec until > I isolated the culprit. > > Briefly, I am switching from RSpec's built in mocking framework to Mocha > and fixture_scenarios when necessary. I had forgotten to modify one of > the examples, which still had this construct: > > object.should_receive(:method).and_return(:a_mock) > > instead of Mocha's: > > object.expects(:method).returns(:a_mock) > > So I have empirically learned that enabling > > config.mock_with :mocha > > in /spec/spec_helper.rb and then mixing Mocha with RSpec's own > mocking/stubbing messes things up in a nasty way, in the sense that > failures occur all over the place with error messages that did not help > me finding the bug. > And again, these errors were not raised by TextMate's environment. > Tricky. > > > Thanks for the feedback! > Giuseppe > -- > 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/20080415/896704e0/attachment.html From ashley.moran at patchspace.co.uk Tue Apr 15 18:39:30 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 15 Apr 2008 23:39:30 +0100 Subject: [rspec-users] before_validation callbacks bypassed when stubbing :valid? In-Reply-To: <3399554dc93b4c860fe69a5d40f9217b@ruby-forum.com> References: <3399554dc93b4c860fe69a5d40f9217b@ruby-forum.com> Message-ID: <447BF540-228B-4044-BA83-05D83018258C@patchspace.co.uk> On 15 Apr 2008, at 23:05, Zubin Henner wrote: > Item.any_instance.stubs(:valid?).returns(true) > item = Item.new > item.valid? Any reason why you are not using pure mocks here? I assume it's not Item you are testing, but some other model that is associated with it? Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From lists at ruby-forum.com Tue Apr 15 19:01:31 2008 From: lists at ruby-forum.com (Zubin Henner) Date: Wed, 16 Apr 2008 01:01:31 +0200 Subject: [rspec-users] before_validation callbacks bypassed when stubbing :vali In-Reply-To: <447BF540-228B-4044-BA83-05D83018258C@patchspace.co.uk> References: <3399554dc93b4c860fe69a5d40f9217b@ruby-forum.com> <447BF540-228B-4044-BA83-05D83018258C@patchspace.co.uk> Message-ID: <8491e12d1085548685b4690eff2e71e1@ruby-forum.com> Ashley Moran wrote: > Any reason why you are not using pure mocks here? I assume it's not > Item you are testing, but some other model that is associated with it? Hi Ashley, yes, you're spot on - I'm using other associated models. I just simplified it for illustration. Here's what I'm really testing: -- # order.rb has_one :freight_selection def calculate_freight_cost(freight_method) # ... (based on order total and freight method) end # freight_selection.rb belongs_to :order belongs_to :freight_method before_validation :set_freight_price def set_freight_price self.price = order.calculate_freight_cost(freight_method) end def validate # ... (confirms that freight_method is valid for order's shipping address) end -- I don't need to validate the freight selection since that's handled elsewhere - I just want it to be valid. But I expected the before_validation filter to run. I've found a workaround, but I guess I'd like to understand this behaviour more, cause it had me stuck for a while. Is Mocha causing this or Rails? -- Posted via http://www.ruby-forum.com/. From alen198 at gmail.com Tue Apr 15 19:08:45 2008 From: alen198 at gmail.com (newbie) Date: Tue, 15 Apr 2008 16:08:45 -0700 (PDT) Subject: [rspec-users] how to stub the :current_user and any methods associated with it In-Reply-To: <853CB107-2A96-45D8-927F-851D9C3725BC@elctech.com> References: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> <29a0119e0804070831v5198bff7qcc6f4a757578af4e@mail.gmail.com> <691ed0f1-88cc-4225-88bf-f7065a0ae157@24g2000hsh.googlegroups.com> <1D4C8509-001E-4187-8119-0483C8E4A367@jlaine.net> <853CB107-2A96-45D8-927F-851D9C3725BC@elctech.com> Message-ID: > Not sure why you are stubbing entries on the controller ... entries is > called on the current user ... I have this method. I want to use this variable to loop the users @entries. So I'm testing to see that this variable is tested and works correctly. def main @entries = current_user.entries end I tried your suggestion @current_user = mock_model(User, :id => 1, :entries => [@entry]) My error "Mock 'User_1010' received unexpected message :entries with (no args)" Maybe this is overtesting or not really necessary to test. Let me know. ---------------------------------- I'm testing this out ---------------------------------- def main @entries = current_user.entries end ------------------------------------------ Using this spec ------------------------------------------ before(:each) do @current_user = mock_model(User, :id => 1) @entry = mock_model(Entry, :user_id => 1) controller.stub!(:current_user).and_return(@current_user) controller.stub!(:login_required).and_return(:true) controller.stub!(:entries).and_return(@entry) end describe "on the main page" do it "should show all the current entries for the user" do @current_user = mock_model(User, :id => 1, :entries => [@entry]) get :main end end From dchelimsky at gmail.com Tue Apr 15 19:18:37 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 15 Apr 2008 19:18:37 -0400 Subject: [rspec-users] how to stub the :current_user and any methods associated with it In-Reply-To: References: <39d18f69-e278-40b2-94c3-dc11372718e6@m3g2000hsc.googlegroups.com> <29a0119e0804070831v5198bff7qcc6f4a757578af4e@mail.gmail.com> <691ed0f1-88cc-4225-88bf-f7065a0ae157@24g2000hsh.googlegroups.com> <1D4C8509-001E-4187-8119-0483C8E4A367@jlaine.net> <853CB107-2A96-45D8-927F-851D9C3725BC@elctech.com> Message-ID: On Apr 15, 2008, at 7:08 PM, newbie wrote: >> Not sure why you are stubbing entries on the controller ... entries >> is >> called on the current user ... > > I have this method. I want to use this variable to loop the users > @entries. So I'm testing to see that this variable is tested and works > correctly. > > def main > @entries = current_user.entries > end > > I tried your suggestion > @current_user = mock_model(User, :id => 1, :entries => [@entry]) > > My error > "Mock 'User_1010' received unexpected message :entries with (no args)" > > Maybe this is overtesting or not really necessary to test. Let me > know. > > ---------------------------------- > I'm testing this out > ---------------------------------- > def main > @entries = current_user.entries > end > > > ------------------------------------------ > Using this spec > ------------------------------------------ > > before(:each) do > @current_user = mock_model(User, :id => 1) > @entry = mock_model(Entry, :user_id => 1) > controller.stub!(:current_user).and_return(@current_user) > controller.stub!(:login_required).and_return(:true) > controller.stub!(:entries).and_return(@entry) > end > > describe "on the main page" do > it "should show all the current entries for the user" do > @current_user = mock_model(User, :id => 1, :entries => [@entry]) > get :main > end > end @current_user is being assigned values twice - once in before(:each) and once in describe "on the main page". The mock that is raising the error is the one defined in before(:each), which is the one that is NOT told to expect :entries, and is the one that is returned by controller.current_user (per the 3rd line of before(:each)). That all make sense? Not really a mock or rspec problem but really just understanding how assignments work in Ruby. HTH, David From joe at pinkpucker.net Tue Apr 15 21:09:06 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Tue, 15 Apr 2008 18:09:06 -0700 Subject: [rspec-users] Writing a story for logging in with OpenID Message-ID: So I added OpenID to my application (via the openid plugin). But I'm having troubles writing the story for it -- specifically, how to mock the openid calls. Anyone got any quick pointers? From korny at sietsma.com Wed Apr 16 00:02:03 2008 From: korny at sietsma.com (Korny Sietsma) Date: Wed, 16 Apr 2008 14:02:03 +1000 Subject: [rspec-users] getting storyrunner success/failure status in rake task Message-ID: <8e15872b0804152102g63fe93a8o5fc359af2ded7550@mail.gmail.com> Hi folks - I'm trying to build a rake task to run our plain-text stories, both from a normal build and from our continuous integration server. However, I'm having a problem - running all.rb doesn't return any sort of success/failure - so a broken story doesn't indicate to Cruise Control that the build is broken. Currently the rake task is: desc "Run all stories" task :stories do output = "#{ARTIFACT_DIR}/doc/rspec/story_results.txt" ruby "#{RAILS_ROOT}/stories/all.rb" end and all.rb calls story files which do the standard sort of thing: ---- require File.dirname(__FILE__) + "/helper" with_steps_for(:stuff, :morestuff) do run_local_story "my_first_story", :type => RailsStory end ---- I'm going to try switching to Kyle Hargrave's story runner stuff - but it's unclear to me if this has any sort of success/fail indicator either... Any suggestions on how to get the above to return a failure code, or throw an exception? I've seen stuff in the code relating to Spec::Story::World.errors() - but I can't seem to work out how to access this. (Oh, and I'm very new to rspec stories, and somewhat new to rake tasks, so forgive me if I'm missing something obvious) - Korny -- 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" From bryansray at gmail.com Wed Apr 16 00:50:29 2008 From: bryansray at gmail.com (Bryan Ray) Date: Tue, 15 Apr 2008 23:50:29 -0500 Subject: [rspec-users] Writing a story for logging in with OpenID In-Reply-To: References: Message-ID: <7AE932E7-6B50-4F5A-B04C-16FCBB93960D@gmail.com> This is a rather open ended question, Joe. You might want to get a little more detailed. Would you happen to have any code to paste or a specific problem? I think you might have a tough time finding someone who has written specific mocks around the openid calls. On Apr 15, 2008, at 8:09 PM, Joe Van Dyk wrote: > So I added OpenID to my application (via the openid plugin). But I'm > having troubles writing the story for it -- specifically, how to mock > the openid calls. > > Anyone got any quick pointers? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ben at benmabey.com Wed Apr 16 01:53:11 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 15 Apr 2008 23:53:11 -0600 Subject: [rspec-users] getting storyrunner success/failure status in rake task In-Reply-To: <8e15872b0804152102g63fe93a8o5fc359af2ded7550@mail.gmail.com> References: <8e15872b0804152102g63fe93a8o5fc359af2ded7550@mail.gmail.com> Message-ID: <48059447.6040006@benmabey.com> Korny Sietsma wrote: > Hi folks - I'm trying to build a rake task to run our plain-text > stories, both from a normal build and from our continuous integration > server. > > However, I'm having a problem - running all.rb doesn't return any sort > of success/failure - so a broken story doesn't indicate to Cruise > Control that the build is broken. > > Currently the rake task is: > desc "Run all stories" > task :stories do > output = "#{ARTIFACT_DIR}/doc/rspec/story_results.txt" > ruby "#{RAILS_ROOT}/stories/all.rb" > end > > and all.rb calls story files which do the standard sort of thing: > ---- > require File.dirname(__FILE__) + "/helper" > > with_steps_for(:stuff, :morestuff) do > run_local_story "my_first_story", :type => RailsStory > end > ---- > > I'm going to try switching to Kyle Hargrave's story runner stuff - but > it's unclear to me if this has any sort of success/fail indicator > either... > > Any suggestions on how to get the above to return a failure code, or > throw an exception? I've seen stuff in the code relating to > Spec::Story::World.errors() - but I can't seem to work out how to > access this. > > (Oh, and I'm very new to rspec stories, and somewhat new to rake > tasks, so forgive me if I'm missing something obvious) > > - Korny > > Korny, The exit code for the story runner does not work in the current (1.1.3) version. I made a patch to add that functionality so our CI would be happy and it is already in rspec edge and will be in 1.1.4. You can either grab my patch or switch to edge rspec. My patch is here: http://rspec.lighthouseapp.com/projects/5645/tickets/228-story-runner-exit-code -Ben From korny at sietsma.com Wed Apr 16 03:17:31 2008 From: korny at sietsma.com (Korny Sietsma) Date: Wed, 16 Apr 2008 17:17:31 +1000 Subject: [rspec-users] getting storyrunner success/failure status in rake task In-Reply-To: <48059447.6040006@benmabey.com> References: <8e15872b0804152102g63fe93a8o5fc359af2ded7550@mail.gmail.com> <48059447.6040006@benmabey.com> Message-ID: <8e15872b0804160017n7f174600t3d6094cc6d0aab9d@mail.gmail.com> Sweet! We're on an r&d project, so we'll probably move to edge... - Korny On Wed, Apr 16, 2008 at 3:53 PM, Ben Mabey wrote: > > Korny Sietsma wrote: > > Hi folks - I'm trying to build a rake task to run our plain-text > > stories, both from a normal build and from our continuous integration > > server. > > > > However, I'm having a problem - running all.rb doesn't return any sort > > of success/failure - so a broken story doesn't indicate to Cruise > > Control that the build is broken. > > > > Currently the rake task is: > > desc "Run all stories" > > task :stories do > > output = "#{ARTIFACT_DIR}/doc/rspec/story_results.txt" > > ruby "#{RAILS_ROOT}/stories/all.rb" > > end > > > > and all.rb calls story files which do the standard sort of thing: > > ---- > > require File.dirname(__FILE__) + "/helper" > > > > with_steps_for(:stuff, :morestuff) do > > run_local_story "my_first_story", :type => RailsStory > > end > > ---- > > > > I'm going to try switching to Kyle Hargrave's story runner stuff - but > > it's unclear to me if this has any sort of success/fail indicator > > either... > > > > Any suggestions on how to get the above to return a failure code, or > > throw an exception? I've seen stuff in the code relating to > > Spec::Story::World.errors() - but I can't seem to work out how to > > access this. > > > > (Oh, and I'm very new to rspec stories, and somewhat new to rake > > tasks, so forgive me if I'm missing something obvious) > > > > - Korny > > > > > > > Korny, > The exit code for the story runner does not work in the current (1.1.3) > version. I made a patch to add that functionality so our CI would be > happy and it is already in rspec edge and will be in 1.1.4. You can > either grab my patch or switch to edge rspec. My patch is here: > http://rspec.lighthouseapp.com/projects/5645/tickets/228-story-runner-exit-code > > -Ben > _______________________________________________ > 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" From lists at ruby-forum.com Wed Apr 16 03:45:38 2008 From: lists at ruby-forum.com (Juanma Cervera) Date: Wed, 16 Apr 2008 09:45:38 +0200 Subject: [rspec-users] rspec 1.1.4 Message-ID: <3325136c7c5fe0992be85801f2ef4cc2@ruby-forum.com> Hello. I have some troubles with rails edge and decide to try rspec-1.1.4. I have installed the plugins downloading the tarballs from github, and I have this error message when I run autotest. /home/jmcervera/work/chapado2/vendor/plugins/rspec_on_rails/lib/spec/rails/version.rb:11: (RuntimeError) ############################################################################ Your RSpec on Rails plugin is incompatible with your installed RSpec. RSpec : 20080328014754 RSpec on Rails : 20080414041511 Make sure your RSpec on Rails plugin is compatible with your RSpec gem. See http://rspec.rubyforge.org/documentation/rails/install.html for details. ############################################################################ from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require' from /home/jmcervera/work/chapado2/vendor/plugins/rspec_on_rails/lib/spec/rails.rb:13 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' ... 30 levels... from /home/jmcervera/work/chapado2/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:13:in `load_files' from /home/jmcervera/work/chapado2/vendor/plugins/rspec/lib/spec/runner/options.rb:86:in `run_examples' from /home/jmcervera/work/chapado2/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run' from script/spec:4 I have downloaded both tarballs from hithub today. Which is the best way from installing the plugins from git. Thanks Juan M. Cervera -- Posted via http://www.ruby-forum.com/. From zeljko.filipin at gmail.com Wed Apr 16 04:04:49 2008 From: zeljko.filipin at gmail.com (=?UTF-8?Q?=C5=BDeljko_Filipin?=) Date: Wed, 16 Apr 2008 10:04:49 +0200 Subject: [rspec-users] Story Framework Message-ID: I want to use story framework for driving my (functional) Watir tests. I want to start with something simple, like logging in. I had an hour today to try it, and I did not get very far. (I have found http://rspec.info/documentation/stories.html and I will take a look at it tomorrow.) I have found basic information about story framework at rspec.info and modified example from there. Am I on the right track? login.txt: Story: login user As registered user I want to log in So I can use the application Scenario: user name and password are correct Given my user name and password are correct When I enter user name and password at login page and click login button I should be logged in define.rb: steps_for(:user) do Given("my $username and $password are correct") do |username, password| member = User.new(username, password) end When("I enter $username and $password at login page and click login button") do |member| member.log_in end Then("I should be logged in") do |member| member.should be_logged_in end end run.rb: with_steps_for :user do run 'rspec' end ?eljko Filipin -- ZeljkoFilipin.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080416/1d99a267/attachment.html From pergesu at gmail.com Wed Apr 16 04:08:57 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 16 Apr 2008 01:08:57 -0700 Subject: [rspec-users] rspec 1.1.4 In-Reply-To: <3325136c7c5fe0992be85801f2ef4cc2@ruby-forum.com> References: <3325136c7c5fe0992be85801f2ef4cc2@ruby-forum.com> Message-ID: <810a540e0804160108i392fa677s5c0f9e3721a58a0c@mail.gmail.com> On Wed, Apr 16, 2008 at 12:45 AM, Juanma Cervera wrote: > Hello. > I have some troubles with rails edge and decide to try rspec-1.1.4. > > I have installed the plugins downloading the tarballs from github, and I > have this error message when I run autotest. > > /home/jmcervera/work/chapado2/vendor/plugins/rspec_on_rails/lib/spec/rails/version.rb:11: > (RuntimeError) > ############################################################################ > Your RSpec on Rails plugin is incompatible with your installed RSpec. > > RSpec : 20080328014754 > RSpec on Rails : 20080414041511 > > Make sure your RSpec on Rails plugin is compatible with your RSpec gem. > See http://rspec.rubyforge.org/documentation/rails/install.html for > details. Hi Juanma, Short reply: it's fixed, you can download the latest changes and it should work fine. Slightly longer reply: at http://rubyforge.org/pipermail/rspec-devel/2008-April/004869.html you can find how to correct the problem yourself in case we make this same mistake in the future. Pat From ashley.moran at patchspace.co.uk Wed Apr 16 04:15:10 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 16 Apr 2008 09:15:10 +0100 Subject: [rspec-users] Story Framework In-Reply-To: References: Message-ID: <526C3013-5D69-4AD5-954B-F94C07014884@patchspace.co.uk> On 16 Apr 2008, at 09:04, ?eljko Filipin wrote: > with_steps_for :user do > run 'rspec' > end Hi ?eljko Did you mean: "run 'login.txt'" here? Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Wed Apr 16 04:30:03 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 16 Apr 2008 09:30:03 +0100 Subject: [rspec-users] before_validation callbacks bypassed when stubbing :vali In-Reply-To: <8491e12d1085548685b4690eff2e71e1@ruby-forum.com> References: <3399554dc93b4c860fe69a5d40f9217b@ruby-forum.com> <447BF540-228B-4044-BA83-05D83018258C@patchspace.co.uk> <8491e12d1085548685b4690eff2e71e1@ruby-forum.com> Message-ID: <1E5C7B28-A3D4-48E9-86F0-AF55AE6A63F6@patchspace.co.uk> On 16 Apr 2008, at 00:01, Zubin Henner wrote: > I don't need to validate the freight selection since that's handled > elsewhere - I just want it to be valid. But I expected the > before_validation filter to run. I've found a workaround, but I guess > I'd like to understand this behaviour more, cause it had me stuck > for a > while. Is Mocha causing this or Rails? It's simply because the :valid? method is what triggers the filter, and you are overriding it. (There's nothing in the runtime sitting and watching for you to *send* the message, it's handled when it's *received*). I suggest you take one of two approaches: * If you are trying to build a suite of database-backed specs to prove the model layer works, then actually create a valid FreightSelection - whatever that entails. (Actually, better to use a story here, I think. * If you are trying to spec the Order class, then use a pure Mocha mock that stubs :id, :valid?, and whatever else ActiveRecord needs to keep it happy (look at rails_example_group.rb in the RSpec on Rails plugin for inspiration). This way you have full control over the second object. Hope this helps Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From lists at ruby-forum.com Wed Apr 16 05:38:15 2008 From: lists at ruby-forum.com (Juanma Cervera) Date: Wed, 16 Apr 2008 11:38:15 +0200 Subject: [rspec-users] rspec 1.1.4 In-Reply-To: <810a540e0804160108i392fa677s5c0f9e3721a58a0c@mail.gmail.com> References: <3325136c7c5fe0992be85801f2ef4cc2@ruby-forum.com> <810a540e0804160108i392fa677s5c0f9e3721a58a0c@mail.gmail.com> Message-ID: <21beb34669c7d3d18684ea6f7992f164@ruby-forum.com> Thanks Pat -- Posted via http://www.ruby-forum.com/. From edvard at majakari.net Wed Apr 16 07:34:42 2008 From: edvard at majakari.net (Edvard Majakari) Date: Wed, 16 Apr 2008 14:34:42 +0300 Subject: [rspec-users] before_validation callbacks bypassed when stubbing :valid? In-Reply-To: <3399554dc93b4c860fe69a5d40f9217b@ruby-forum.com> References: <3399554dc93b4c860fe69a5d40f9217b@ruby-forum.com> Message-ID: On Wed, Apr 16, 2008 at 1:05 AM, Zubin Henner wrote: > I'm testing an ActiveRecord model using rspec and mocha, and found that > if I stub out the :valid? method, all before_validation callbacks are > also skipped! Naturally, as it is AR's valid method which triggers those callbacks, and you just stubbed it. Not a straight answer to your question, but hopefully helpful nevertheless: you could consider implementing class method new_valid for each of your objects, so that whenever the concept of a valid object changes, there's only one place you have to fix. However, as Ashley suggested, it might be that you'd rather want to resort to pure mock objects instead. -- "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 ashley.moran at patchspace.co.uk Wed Apr 16 07:54:44 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 16 Apr 2008 12:54:44 +0100 Subject: [rspec-users] before_validation callbacks bypassed when stubbing :valid? In-Reply-To: References: <3399554dc93b4c860fe69a5d40f9217b@ruby-forum.com> Message-ID: On 16 Apr 2008, at 12:34, Edvard Majakari wrote: > you could consider implementing > class method new_valid for each of your objects, so that whenever the > concept of a valid object changes, there's > only one place you have to fix. Or equally, you could have a Factory class that knows how to create valid objects. This can be handy for generating test data, and separates it from the class under test. (Some metaprogramming would let you define that in one class and still have it available as MyModel.new_valid.) Zubin - I am still leaning towards the mock approach though, unless you don't have integration tests for your app, in which case having a model-layer test suite would add value. (But full-stack integration tests + model unit tests would be better). Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From lists at ruby-forum.com Wed Apr 16 07:57:52 2008 From: lists at ruby-forum.com (Andy Croll) Date: Wed, 16 Apr 2008 13:57:52 +0200 Subject: [rspec-users] Testing Layout Message-ID: Is there a way to specify which layout an action should use in a controller? Andy -- Posted via http://www.ruby-forum.com/. From edvard at majakari.net Wed Apr 16 09:10:10 2008 From: edvard at majakari.net (Edvard Majakari) Date: Wed, 16 Apr 2008 16:10:10 +0300 Subject: [rspec-users] before_validation callbacks bypassed when stubbing :valid? In-Reply-To: References: <3399554dc93b4c860fe69a5d40f9217b@ruby-forum.com> Message-ID: On Wed, Apr 16, 2008 at 2:54 PM, Ashley Moran wrote: > Or equally, you could have a Factory class that knows how to create > valid objects. This can be handy for generating test data, and > separates it from the class under test. (Some metaprogramming would > let you define that in one class and still have it available as > MyModel.new_valid.) Yep, that's better. This is very similar to what I just recently did: I created a factory which creates pure stub objects for all more complex models I needed in tests. However, I mostly do just fine having all the stubs/mocks in the spec file concerned; that's the approach I like the most, as then I have everything I need in a single file. -- "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 loop at superinfinite.com Wed Apr 16 09:40:45 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Wed, 16 Apr 2008 15:40:45 +0200 Subject: [rspec-users] Testing Layout In-Reply-To: References: Message-ID: On 16-apr-2008, at 13:57, Andy Croll wrote: > Is there a way to specify which layout an action should use in a > controller? Off the top of my head, not tested: describe MyController do it "should use the foo layout" do MyController.should_receive(:layout).with("foo") load("app/controllers/my_controller") end end but I'm sure there's a more BDD way to do it (TIMTOWTDI goes BDDWTDI ?). greetz, bartz From lists at ruby-forum.com Wed Apr 16 10:53:04 2008 From: lists at ruby-forum.com (Andy Croll) Date: Wed, 16 Apr 2008 16:53:04 +0200 Subject: [rspec-users] Testing Layout In-Reply-To: References: Message-ID: Bart Zonneveld wrote: > On 16-apr-2008, at 13:57, Andy Croll wrote: >> Is there a way to specify which layout an action should use in a >> controller? > > Off the top of my head, not tested: > > describe MyController do > it "should use the foo layout" do > MyController.should_receive(:layout).with("foo") > load("app/controllers/my_controller") > end > end > > but I'm sure there's a more BDD way to do it (TIMTOWTDI goes BDDWTDI ?). > > greetz, > bartz Tried it. No dice it seems So I then tried: it "should use the admin layout" do controller.should_receive(:layout).with("admin") end And I get... 1) Spec::Mocks::MockExpectationError in 'Admin::ProductsController should use the admin layout' Mock 'Admin::ProductsController' expected :layout with ("admin") once, but received it 0 times I'm not doing the load ... command you suggested. What is the thinking behind that? I'm finding that testing using RSpec demands you understand a lot more of what is going on inside the framework! Cheers Andy -- Posted via http://www.ruby-forum.com/. From loop at superinfinite.com Wed Apr 16 11:20:00 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Wed, 16 Apr 2008 17:20:00 +0200 Subject: [rspec-users] Testing Layout In-Reply-To: References: Message-ID: <78842167-6483-40BA-89B9-8D0A2DBBBF70@superinfinite.com> On 16-apr-2008, at 16:53, Andy Croll wrote: > Bart Zonneveld wrote: >> On 16-apr-2008, at 13:57, Andy Croll wrote: >>> Is there a way to specify which layout an action should use in a >>> controller? >> >> Off the top of my head, not tested: >> >> describe MyController do >> it "should use the foo layout" do >> MyController.should_receive(:layout).with("foo") >> load("app/controllers/my_controller") >> end >> end >> >> but I'm sure there's a more BDD way to do it (TIMTOWTDI goes >> BDDWTDI ?). >> >> greetz, >> bartz > > > Tried it. No dice it seems > > So I then tried: > > it "should use the admin layout" do > controller.should_receive(:layout).with("admin") > end > > And I get... > > 1) > Spec::Mocks::MockExpectationError in 'Admin::ProductsController should > use the admin layout' > Mock 'Admin::ProductsController' expected :layout with ("admin") once, > but received it 0 times > > I'm not doing the load ... command you suggested. What is the thinking > behind that? I'm finding that testing using RSpec demands you > understand > a lot more of what is going on inside the framework! That kind of makes sense, since should_receive's should be defined *before* something happens. So, slightly diverting here, but say a Post should receive find(:all) when you go to index/, it would look something like: describe PostsController do it "should find all posts" do Post.should_receive(:find).with(:all) get "index" end end The "trick" I gave you above was based on this one: http:// www.nabble.com/Testing-that-a-model-helper-method-is-called- td15856651.html Perhaps you should try giving the full path to load, eg. load (RAILS_ROOT + "/app/controllers/my_controller.rb"). greetz, bartz From pergesu at gmail.com Wed Apr 16 12:44:44 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 16 Apr 2008 09:44:44 -0700 Subject: [rspec-users] Has anyone pulled from the repo recently, but not on/after 4/16? Message-ID: <810a540e0804160944l2e954e25sd9ae0cb088138760@mail.gmail.com> I screwed up the repo on github and a bunch of commits are missing. So I'm hoping that there are a couple people out there that have pulled fairly recently (ideally on 4/15), but not today. If so, can you please tar up your entire rspec-dev project and email it to me so I can try to fix this? Please do NOT update your repo to get the latest changes at this point. Pat From ben at benmabey.com Wed Apr 16 12:49:22 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 16 Apr 2008 10:49:22 -0600 Subject: [rspec-users] Has anyone pulled from the repo recently, but not on/after 4/16? In-Reply-To: <810a540e0804160944l2e954e25sd9ae0cb088138760@mail.gmail.com> References: <810a540e0804160944l2e954e25sd9ae0cb088138760@mail.gmail.com> Message-ID: <48062E12.5070107@benmabey.com> Pat Maddox wrote: > I screwed up the repo on github and a bunch of commits are missing. > So I'm hoping that there are a couple people out there that have > pulled fairly recently (ideally on 4/15), but not today. If so, can > you please tar up your entire rspec-dev project and email it to me so > I can try to fix this? > > Please do NOT update your repo to get the latest changes at this point. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Pat, I forked the rspec repos on git hub. The last time I synced up with the official ones was on 4-12-08. You can my tars from git hub: http://github.com/bmabey You will have to cherrypick certain commits up until 4-15. You will also need to remove one of my commits (rspec-rails only), but that should be pretty easy. If you want help with this using my repos let me know, I'd be glad to help. -Ben From steven at stevenrbaker.com Wed Apr 16 13:03:36 2008 From: steven at stevenrbaker.com (Steven Baker) Date: Wed, 16 Apr 2008 13:03:36 -0400 Subject: [rspec-users] Has anyone pulled from the repo recently, but not on/after 4/16? In-Reply-To: <810a540e0804160944l2e954e25sd9ae0cb088138760@mail.gmail.com> References: <810a540e0804160944l2e954e25sd9ae0cb088138760@mail.gmail.com> Message-ID: <19A8CC8F-9691-471E-B96F-F4BDCFF2C05D@stevenrbaker.com> > I screwed up the repo on github and a bunch of commits are missing. > So I'm hoping that there are a couple people out there that have > pulled fairly recently (ideally on 4/15), but not today. If so, can > you please tar up your entire rspec-dev project and email it to me so > I can try to fix this? Pat, please don't accept blame for this. You didn't screw up the repo: git screwed up the repo by rewriting history when it shouldn't. -Steven From dchelimsky at gmail.com Wed Apr 16 13:15:51 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 16 Apr 2008 13:15:51 -0400 Subject: [rspec-users] Has anyone pulled from the repo recently, but not on/after 4/16? In-Reply-To: <19A8CC8F-9691-471E-B96F-F4BDCFF2C05D@stevenrbaker.com> References: <810a540e0804160944l2e954e25sd9ae0cb088138760@mail.gmail.com> <19A8CC8F-9691-471E-B96F-F4BDCFF2C05D@stevenrbaker.com> Message-ID: <6D152652-00ED-4A8C-AEA7-924EE80D6D8F@gmail.com> On Apr 16, 2008, at 1:03 PM, Steven Baker wrote: >> I screwed up the repo on github and a bunch of commits are missing. >> So I'm hoping that there are a couple people out there that have >> pulled fairly recently (ideally on 4/15), but not today. If so, can >> you please tar up your entire rspec-dev project and email it to me so >> I can try to fix this? > > Pat, please don't accept blame for this. You didn't screw up the > repo: git screwed up the repo by rewriting history when it shouldn't. Absolutely. +1000 > > > -Steven > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Wed Apr 16 13:38:50 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 16 Apr 2008 10:38:50 -0700 Subject: [rspec-users] Has anyone pulled from the repo recently, but not on/after 4/16? In-Reply-To: <19A8CC8F-9691-471E-B96F-F4BDCFF2C05D@stevenrbaker.com> References: <810a540e0804160944l2e954e25sd9ae0cb088138760@mail.gmail.com> <19A8CC8F-9691-471E-B96F-F4BDCFF2C05D@stevenrbaker.com> Message-ID: <810a540e0804161038x4ae4cfedw26f13ea32257e383@mail.gmail.com> On Wed, Apr 16, 2008 at 10:03 AM, Steven Baker wrote: > > I screwed up the repo on github and a bunch of commits are missing. > > So I'm hoping that there are a couple people out there that have > > pulled fairly recently (ideally on 4/15), but not today. If so, can > > you please tar up your entire rspec-dev project and email it to me so > > I can try to fix this? > > Pat, please don't accept blame for this. You didn't screw up the > repo: git screwed up the repo by rewriting history when it shouldn't. Blame is irrelevant here. Code and commit history is gone, and we need to get it back. We also need to figure out how to prevent this from happening again. That's all. Pat From bryansray at gmail.com Wed Apr 16 15:15:30 2008 From: bryansray at gmail.com (Bryan Ray) Date: Wed, 16 Apr 2008 14:15:30 -0500 Subject: [rspec-users] Has anyone pulled from the repo recently, but not on/after 4/16? In-Reply-To: <810a540e0804161038x4ae4cfedw26f13ea32257e383@mail.gmail.com> References: <810a540e0804160944l2e954e25sd9ae0cb088138760@mail.gmail.com> <19A8CC8F-9691-471E-B96F-F4BDCFF2C05D@stevenrbaker.com> <810a540e0804161038x4ae4cfedw26f13ea32257e383@mail.gmail.com> Message-ID: <29a0119e0804161215g7578ab93yfb65f22eebce00c0@mail.gmail.com> I might be of some help ... The last time I pulled the rspec was like Saturday or Sunday. I will tar up my rspec directory and send it over when I get home in a few hours. On 4/16/08, Pat Maddox wrote: > On Wed, Apr 16, 2008 at 10:03 AM, Steven Baker > wrote: > > > I screwed up the repo on github and a bunch of commits are missing. > > > So I'm hoping that there are a couple people out there that have > > > pulled fairly recently (ideally on 4/15), but not today. If so, can > > > you please tar up your entire rspec-dev project and email it to me so > > > I can try to fix this? > > > > Pat, please don't accept blame for this. You didn't screw up the > > repo: git screwed up the repo by rewriting history when it shouldn't. > > Blame is irrelevant here. Code and commit history is gone, and we > need to get it back. We also need to figure out how to prevent this > from happening again. That's all. > > Pat > _______________________________________________ > 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." From pergesu at gmail.com Wed Apr 16 15:23:16 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 16 Apr 2008 12:23:16 -0700 Subject: [rspec-users] Has anyone pulled from the repo recently, but not on/after 4/16? In-Reply-To: <810a540e0804160944l2e954e25sd9ae0cb088138760@mail.gmail.com> References: <810a540e0804160944l2e954e25sd9ae0cb088138760@mail.gmail.com> Message-ID: <810a540e0804161223k3045b6b1w30c5f191d6829a9a@mail.gmail.com> Actually, if you updated the repo after 4/16, please send it to me. Also include any winning lotto numbers for the date of your last pull. In fact, screw the repo, I just want the lotto numbers. From jonathan at parkerhill.com Wed Apr 16 15:45:27 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Wed, 16 Apr 2008 15:45:27 -0400 Subject: [rspec-users] Has anyone pulled from the repo recently, but not on/after 4/16? In-Reply-To: <810a540e0804161223k3045b6b1w30c5f191d6829a9a@mail.gmail.com> References: <810a540e0804160944l2e954e25sd9ae0cb088138760@mail.gmail.com> <810a540e0804161223k3045b6b1w30c5f191d6829a9a@mail.gmail.com> Message-ID: You might try here http://www.google.com.au/intl/en/gday/index.html Jonathan On Apr 16, 2008, at 3:23 PM, Pat Maddox wrote: > Actually, if you updated the repo after 4/16, please send it to me. > Also include any winning lotto numbers for the date of your last pull. > In fact, screw the repo, I just want the lotto numbers. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From andywatts at yahoo.com Wed Apr 16 15:57:53 2008 From: andywatts at yahoo.com (Andy Watts) Date: Wed, 16 Apr 2008 12:57:53 -0700 (PDT) Subject: [rspec-users] Story runner + selenium-rc + wait_for_xxxx Message-ID: <16732279.post@talk.nabble.com> Hi, I've got a story working with selenium-rc, but am stuck writing ajax-aware steps. How are people coding their story steps to wait for an Ajax event to complete? Here's what I've looked at so far. $browser.wait_for_element_present Looks Ideal, but not in selenium-ruby-client-drivers for some reason. def wait_for_ajax $browser.wait_for_condition("selenium.browserbot.getCurrentWindow().ServerConnection.isPending() == false", 2000) end This helper looked promising, but it returns SeleniumCommandError: selenium.browserbot.getCurrentWindow().ServerConnection has no properties Many Thanks Andy -- View this message in context: http://www.nabble.com/Story-runner-%2B-selenium-rc-%2B-wait_for_xxxx-tp16732279p16732279.html Sent from the rspec-users mailing list archive at Nabble.com. From aslak.hellesoy at gmail.com Wed Apr 16 16:01:53 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 16 Apr 2008 22:01:53 +0200 Subject: [rspec-users] Story runner + selenium-rc + wait_for_xxxx In-Reply-To: <16732279.post@talk.nabble.com> References: <16732279.post@talk.nabble.com> Message-ID: <8d961d900804161301r167fea04q444eb82f9ed7dbe1@mail.gmail.com> On Wed, Apr 16, 2008 at 9:57 PM, Andy Watts wrote: > > Hi, > > I've got a story working with selenium-rc, but am stuck writing ajax-aware > steps. > > How are people coding their story steps to wait for an Ajax event to > complete? > Have you asked the selenium list about this? Aslak > > Here's what I've looked at so far. > > $browser.wait_for_element_present > Looks Ideal, but not in selenium-ruby-client-drivers for some reason. > > def wait_for_ajax > > $browser.wait_for_condition("selenium.browserbot.getCurrentWindow().ServerConnection.isPending() > == false", 2000) > end > This helper looked promising, but it returns > SeleniumCommandError: > selenium.browserbot.getCurrentWindow().ServerConnection has no properties > > Many Thanks > Andy > > > > > -- > View this message in context: http://www.nabble.com/Story-runner-%2B-selenium-rc-%2B-wait_for_xxxx-tp16732279p16732279.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 > From mvanholstyn at gmail.com Wed Apr 16 17:13:21 2008 From: mvanholstyn at gmail.com (Mark Van Holstyn) Date: Wed, 16 Apr 2008 17:13:21 -0400 Subject: [rspec-users] Story runner + selenium-rc + wait_for_xxxx In-Reply-To: <16732279.post@talk.nabble.com> References: <16732279.post@talk.nabble.com> Message-ID: I have done this in the past... def wait_for_ajax(timeout = 30000) wait_for_condition "window.Ajax.activeRequestCount == 0", timeout end def wait_for_effects(timeout = 30000) wait_for_condition "window.Effect.Queue.size() == 0", timeout end Mark On Wed, Apr 16, 2008 at 3:57 PM, Andy Watts wrote: > > Hi, > > I've got a story working with selenium-rc, but am stuck writing ajax-aware > steps. > > How are people coding their story steps to wait for an Ajax event to > complete? > > > Here's what I've looked at so far. > > $browser.wait_for_element_present > Looks Ideal, but not in selenium-ruby-client-drivers for some reason. > > def wait_for_ajax > > > $browser.wait_for_condition("selenium.browserbot.getCurrentWindow().ServerConnection.isPending() > == false", 2000) > end > This helper looked promising, but it returns > SeleniumCommandError: > selenium.browserbot.getCurrentWindow().ServerConnection has no properties > > Many Thanks > Andy > > > > > -- > View this message in context: > http://www.nabble.com/Story-runner-%2B-selenium-rc-%2B-wait_for_xxxx-tp16732279p16732279.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 > -- 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/20080416/689ce617/attachment.html From joe at pinkpucker.net Wed Apr 16 18:22:31 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Wed, 16 Apr 2008 15:22:31 -0700 Subject: [rspec-users] setup for stories Message-ID: I've got some code that should run before any stories execute. Where's a good place to put that? (need to create a @sessions and @users hash) Joe From dchelimsky at gmail.com Wed Apr 16 18:44:41 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 16 Apr 2008 18:44:41 -0400 Subject: [rspec-users] setup for stories In-Reply-To: References: Message-ID: <1CE429D1-DD60-41E0-9E69-68D50D0163D3@gmail.com> On Apr 16, 2008, at 6:22 PM, Joe Van Dyk wrote: > I've got some code that should run before any stories execute. > Where's a good place to put that? (need to create a @sessions and > @users hash) The story framework has as simple listener API (not documented, but otherwise nice): class StorySetupListener def run_started(num_scenarios) # do your stuff here end def method_missing(method, *args) # no-op end end Spec::Story::Runner.register_listener(StorySetupListener.new) Give that a whirl. Cheers, David From ashley.moran at patchspace.co.uk Wed Apr 16 18:59:40 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 16 Apr 2008 23:59:40 +0100 Subject: [rspec-users] setup for stories In-Reply-To: References: Message-ID: <13B5B3F2-532D-4F77-8B52-7EDEE9A36124@patchspace.co.uk> On 16 Apr 2008, at 23:22, Joe Van Dyk wrote: > I've got some code that should run before any stories execute. > Where's a good place to put that? (need to create a @sessions and > @users hash) Ha, just before I got this reply out I noticed David had written the exact same email as me but pressed send first... Here's a template listener that includes all the hooks I'm aware of: class MyStoryListener def run_started(number_of_scenarios); end def story_started(story, narrative); end def story_ended(story, narrative); end def scenario_started(story, scenario); end def scenario_succeeded(story, scenario); end def scenario_pending(story, scenario, error); end def scenario_failed(story, scenario, error); end def run_ended; end def method_missing(*args); end end (method_missing only useful if you remove some - it also highlights unimplemented hooks) Spec::Story::Runner.register_listener(MyStoryListener.new) BTW does that count as documentation? :) Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From dchelimsky at gmail.com Wed Apr 16 22:39:39 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 16 Apr 2008 22:39:39 -0400 Subject: [rspec-users] rspec + github == !submodules Message-ID: <57c63afe0804161939k12ce1652x2b5fe7d79be2d47a@mail.gmail.com> Hey all, We ran into some problems last night with the repos up at github. We initially thought it was a git-submodules bug. We learned that it was something else, but in the process of trying to find the source of the bug, we learned a few things about git-submodules and have decided that it creates an unfortunate set of complications and dependencies for a development effort like ours. To that end, we have simplified. No more submodules. To update, do the following: cd rspec-dev git pull rake git:update See http://github.com/dchelimsky/rspec-dev/wikis/contributingpatches for more info. Cheers, David From lists at ruby-forum.com Thu Apr 17 01:38:06 2008 From: lists at ruby-forum.com (Andy Croll) Date: Thu, 17 Apr 2008 07:38:06 +0200 Subject: [rspec-users] Testing Layout In-Reply-To: <78842167-6483-40BA-89B9-8D0A2DBBBF70@superinfinite.com> References: <78842167-6483-40BA-89B9-8D0A2DBBBF70@superinfinite.com> Message-ID: > Perhaps you should try giving the full path to load, eg. load > (RAILS_ROOT + "/app/controllers/my_controller.rb"). That seemed to do it... was perhaps a typo originally. My bad. Thanks. -- Posted via http://www.ruby-forum.com/. From korny at sietsma.com Thu Apr 17 04:08:15 2008 From: korny at sietsma.com (Korny Sietsma) Date: Thu, 17 Apr 2008 18:08:15 +1000 Subject: [rspec-users] getting storyrunner success/failure status in rake task In-Reply-To: <8e15872b0804160017n7f174600t3d6094cc6d0aab9d@mail.gmail.com> References: <8e15872b0804152102g63fe93a8o5fc359af2ded7550@mail.gmail.com> <48059447.6040006@benmabey.com> <8e15872b0804160017n7f174600t3d6094cc6d0aab9d@mail.gmail.com> Message-ID: <8e15872b0804170108u5b6e37cau11303ce854bdf899@mail.gmail.com> Argh! I *finally* got this going, but only with much pain. I had a problem that on my cruise box I was running: "ruby stories/all.rb | tee #{output}" But the call to 'tee' was hiding the return code from the ruby call... This was all complicated by the fact that stories are actually run by an at_exit handler - it took me quite a lot of digging to work out what *actually* kicked off the stories! - Korny On Wed, Apr 16, 2008 at 5:17 PM, Korny Sietsma wrote: > Sweet! We're on an r&d project, so we'll probably move to edge... > > - Korny > > > > On Wed, Apr 16, 2008 at 3:53 PM, Ben Mabey wrote: > > > > Korny Sietsma wrote: > > > Hi folks - I'm trying to build a rake task to run our plain-text > > > stories, both from a normal build and from our continuous integration > > > server. > > > > > > However, I'm having a problem - running all.rb doesn't return any sort > > > of success/failure - so a broken story doesn't indicate to Cruise > > > Control that the build is broken. > > > > > > Currently the rake task is: > > > desc "Run all stories" > > > task :stories do > > > output = "#{ARTIFACT_DIR}/doc/rspec/story_results.txt" > > > ruby "#{RAILS_ROOT}/stories/all.rb" > > > end > > > > > > and all.rb calls story files which do the standard sort of thing: > > > ---- > > > require File.dirname(__FILE__) + "/helper" > > > > > > with_steps_for(:stuff, :morestuff) do > > > run_local_story "my_first_story", :type => RailsStory > > > end > > > ---- > > > > > > I'm going to try switching to Kyle Hargrave's story runner stuff - but > > > it's unclear to me if this has any sort of success/fail indicator > > > either... > > > > > > Any suggestions on how to get the above to return a failure code, or > > > throw an exception? I've seen stuff in the code relating to > > > Spec::Story::World.errors() - but I can't seem to work out how to > > > access this. > > > > > > (Oh, and I'm very new to rspec stories, and somewhat new to rake > > > tasks, so forgive me if I'm missing something obvious) > > > > > > - Korny > > > > > > > > > > > > Korny, > > The exit code for the story runner does not work in the current (1.1.3) > > version. I made a patch to add that functionality so our CI would be > > happy and it is already in rspec edge and will be in 1.1.4. You can > > either grab my patch or switch to edge rspec. My patch is here: > > http://rspec.lighthouseapp.com/projects/5645/tickets/228-story-runner-exit-code > > > > -Ben > > _______________________________________________ > > 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" > -- 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" From josephwilk at joesniff.co.uk Thu Apr 17 05:08:09 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Thu, 17 Apr 2008 10:08:09 +0100 Subject: [rspec-users] Stories / Pending / Suggestion Message-ID: Hello, I have a suggestion on plain text stories and how unimplemented Scenarios are regarded. When a Scenario has no Give/When/Body mark it as 'pending' rather than 'completed' as it does now. This would mean it would work like spec's 'it': Example: -------------------------------------------------- it "eat" it "sleep" it "be merry" -------------------------------------------------- 3 pending/ Yet to be implemented How I think Stories should work -------------------------------------------------- Story: monkeys Scenario: eat Scenario: sleep Scenario: be merry -------------------------------------------------- What I think it should output: >3 scenarios: 0 succeeded, 0 failed, 3 pending (Perhaps like specs a 'Yet to be implemented' is shown aswell) What is actually outputs: >3 scenarios: 3 succeeded, 0 failed, 0 pending When I write a new story I first create all the Scenarios names and then go through implementing the most important (as dictated by the client). Often I leave scenarios not deemed important by the client yet, but do provided potential further work. It would be very useful if those where marked as pending. I'm happy to put a patch together but wanted to check with the community that what I'm saying is sound. What do people think? Was there a particular reason why empty scenarios are marked as success? Thanks, Joseph Wilk http://www.joesniff.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080417/f9c7e7fe/attachment.html From j at jonathanleighton.com Thu Apr 17 05:20:39 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Thu, 17 Apr 2008 10:20:39 +0100 Subject: [rspec-users] rspec + github == !submodules In-Reply-To: <57c63afe0804161939k12ce1652x2b5fe7d79be2d47a@mail.gmail.com> References: <57c63afe0804161939k12ce1652x2b5fe7d79be2d47a@mail.gmail.com> Message-ID: <1208424039.7094.0.camel@tybalt> Hi David, Is there any chance you could elaborate on the problems please, so that other projects can make an informed decision whether to use submodules or not? Cheers, Jon On Wed, 2008-04-16 at 22:39 -0400, David Chelimsky wrote: > Hey all, > > We ran into some problems last night with the repos up at github. We > initially thought it was a git-submodules bug. We learned that it was > something else, but in the process of trying to find the source of the > bug, we learned a few things about git-submodules and have decided > that it creates an unfortunate set of complications and dependencies > for a development effort like ours. > > To that end, we have simplified. No more submodules. To update, do the > following: > > cd rspec-dev > git pull > rake git:update > > See http://github.com/dchelimsky/rspec-dev/wikis/contributingpatches > for more info. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- Jonathan Leighton http://jonathanleighton.com/ From jari.bakken at finntech.no Thu Apr 17 05:45:38 2008 From: jari.bakken at finntech.no (Bakken Jari) Date: Thu, 17 Apr 2008 11:45:38 +0200 Subject: [rspec-users] abstract test runner? Message-ID: Hi, We have a quite large test suite built on Watir (and eventually moving to our soon-to-be-released JRuby wrapper for HtmlUnit). Currently the tests are written using Test::Unit, but we are looking at other solutions - rspec, both spec and story frameworks, and RubyFIT. I suspect that we will have tests written using more than one solution (at least initiallly, while still undecided), and I think for some scenarios (i.e. lots of similar but different input data going through the exact same testing process) FIT could work really well. But if we're using more than one framwork, we don't want to look at seperate reports from each framework. What I'd like to have is some kind of abstract TestRunner that could execute tests, and provide a common interface to results from the different frameworks for a reporting tool. This of course limits what kind of result data is recorded - but at a minimum could be just passed/failed + the ?test name?. This would allow us to build up some infrastructure around running tests and storing/presenting (non-detailed) results, without being bound to one framework. So maybe something like this, using strategies: t = TestRunner.new(RSpecRunner.new) t.run_file("my_spec.rb") (or it could figure out what kind of runner to use from the file name). Perhaps also with an output strategy: t = TestRunner.new(RSpecRunner.new, DatabaseOutputter.new) etc... Having this, we'll also be able to play with future frameworks and easily plug them into our ?simple reports? by just writing a ?NewFramework?Runner class. Any interest in this? Perhaps a solution already exists that I'm not aware of. Jari From dchelimsky at gmail.com Thu Apr 17 07:11:54 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 17 Apr 2008 07:11:54 -0400 Subject: [rspec-users] rspec + github == !submodules In-Reply-To: <1208424039.7094.0.camel@tybalt> References: <57c63afe0804161939k12ce1652x2b5fe7d79be2d47a@mail.gmail.com> <1208424039.7094.0.camel@tybalt> Message-ID: <88035FD5-2D44-488A-A502-90E709AB8296@gmail.com> On Apr 17, 2008, at 5:20 AM, Jonathan Leighton wrote: > Hi David, > > Is there any chance you could elaborate on the problems please, so > that > other projects can make an informed decision whether to use submodules > or not? There is always a chance :) I'll be at a computer slightly bigger than my phone in a little while and will follow up. > Cheers, > Jon > > On Wed, 2008-04-16 at 22:39 -0400, David Chelimsky wrote: >> Hey all, >> >> We ran into some problems last night with the repos up at github. We >> initially thought it was a git-submodules bug. We learned that it was >> something else, but in the process of trying to find the source of >> the >> bug, we learned a few things about git-submodules and have decided >> that it creates an unfortunate set of complications and dependencies >> for a development effort like ours. >> >> To that end, we have simplified. No more submodules. To update, do >> the >> following: >> >> cd rspec-dev >> git pull >> rake git:update >> >> See http://github.com/dchelimsky/rspec-dev/wikis/contributingpatches >> for more info. >> >> Cheers, >> David From dchelimsky at gmail.com Thu Apr 17 08:49:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 17 Apr 2008 08:49:53 -0400 Subject: [rspec-users] rspec + github == !submodules In-Reply-To: <88035FD5-2D44-488A-A502-90E709AB8296@gmail.com> References: <57c63afe0804161939k12ce1652x2b5fe7d79be2d47a@mail.gmail.com> <1208424039.7094.0.camel@tybalt> <88035FD5-2D44-488A-A502-90E709AB8296@gmail.com> Message-ID: <3DEEE25E-42DB-48BA-8EB8-33477C269B53@gmail.com> On Apr 17, 2008, at 7:11 AM, David Chelimsky wrote: > On Apr 17, 2008, at 5:20 AM, Jonathan Leighton > wrote: > >> Hi David, >> >> Is there any chance you could elaborate on the problems please, so >> that >> other projects can make an informed decision whether to use >> submodules >> or not? > > There is always a chance :) What I learned was that submodules are great for things like consuming plugins in your rails projects, but not so great for a development effort in multiple people are pushing and pulling to multiple repositories with dependencies and no multi-project transaction support. The parent repository depends on specific versions of the subs. As you're making changes in your local repos, the last thing you do is commit the parent with the references to the new versions of the subs. Every time you make a change to any of the subs you have to commit a change to the parent. These changes are useful as documentation if you're updating a plugin to the latest release. Not that useful if the log is polluted with these for every commit to every submodule. When you pull, you pull the parent first, and then use git-submodule to pull the correct versions of the subs. The parent is in control of the situation and it somewhat guarantees that you're getting all the right stuff. This is GREAT for consumers, but problematic for contributors. And even then, if consumers are pulling from a development branch while developers are pushing to it, then consumers might run into problems. Let's say you're doing a pull while I'm doing a push. If I push the parent first, and I push it before you do, there is a chance that when you go to pull the subs those versions of the subs might not be there yet. Conversely, if I push the subs first and you grab an old parent, you'll be pulling old subs. No problem when you're pulling, but it's going to create problems when you go to push because you're that much further down the history. Of course, these problems exist even when you're dealing with a single repository on a team that believes in frequent commits, continuous integration, etc. And just by virtue of the fact that we have several repos with dependencies means that we're going to run into conflicts now and then. It just seems that the explicit references from parent to children adds a layer of complexity to this for both consumers and developers. This all make sense? >> Cheers, >> Jon >> >> On Wed, 2008-04-16 at 22:39 -0400, David Chelimsky wrote: >>> Hey all, >>> >>> We ran into some problems last night with the repos up at github. We >>> initially thought it was a git-submodules bug. We learned that it >>> was >>> something else, but in the process of trying to find the source of >>> the >>> bug, we learned a few things about git-submodules and have decided >>> that it creates an unfortunate set of complications and dependencies >>> for a development effort like ours. >>> >>> To that end, we have simplified. No more submodules. To update, do >>> the >>> following: >>> >>> cd rspec-dev >>> git pull >>> rake git:update >>> >>> See http://github.com/dchelimsky/rspec-dev/wikis/contributingpatches >>> for more info. >>> >>> Cheers, >>> David From lists at ruby-forum.com Thu Apr 17 09:44:03 2008 From: lists at ruby-forum.com (Joseph Wilk) Date: Thu, 17 Apr 2008 15:44:03 +0200 Subject: [rspec-users] Creating stories for the second resource. Very wet appro In-Reply-To: References: Message-ID: <11e1c34a425fa8e36143b30f1d7c68d0@ruby-forum.com> Hello, I've come across a similar problem. Sharing the steps is the easy bit. And I've started to create a 'useful_steps.rb' for storing very common steps. I have just copy and pasted the plain text stories before but since they use the same steps, there was little new steps to write. It feels like the steps are where you want to keep it dry but the stories are the domain specific language to writing acceptance/integration tests. So it is similar problem to saying that models contain lots of 'has_ones' and hence are not dry. Well thats the conclusions I've been coming to after using stories for a while. -- Joseph Wilk http://www.joesniff.co.uk Tim Haines wrote: > Hi y'all > > I'm about to start writing up the stories for my second resource. The > second resource is so similar to the first that I feel a good way for me > to > start might be to copy and paste the stories and edit from there. This > seems very anti-dry though. Am I missing something obvious, or would > you > expect (and be happy with) a lot of duplication between stories? > > Tim. -- Posted via http://www.ruby-forum.com/. From bryansray at gmail.com Thu Apr 17 10:28:12 2008 From: bryansray at gmail.com (Bryan Ray) Date: Thu, 17 Apr 2008 09:28:12 -0500 Subject: [rspec-users] rspec + github == !submodules In-Reply-To: <3DEEE25E-42DB-48BA-8EB8-33477C269B53@gmail.com> References: <57c63afe0804161939k12ce1652x2b5fe7d79be2d47a@mail.gmail.com> <1208424039.7094.0.camel@tybalt> <88035FD5-2D44-488A-A502-90E709AB8296@gmail.com> <3DEEE25E-42DB-48BA-8EB8-33477C269B53@gmail.com> Message-ID: <29a0119e0804170728p456f487fr339758c876019d8d@mail.gmail.com> Great information, David. Sounds like a useful blog post! On Thu, Apr 17, 2008 at 7:49 AM, David Chelimsky wrote: > On Apr 17, 2008, at 7:11 AM, David Chelimsky wrote: > > > On Apr 17, 2008, at 5:20 AM, Jonathan Leighton > > wrote: > > > >> Hi David, > >> > >> Is there any chance you could elaborate on the problems please, so > >> that > >> other projects can make an informed decision whether to use > >> submodules > >> or not? > > > > There is always a chance :) > > What I learned was that submodules are great for things like consuming > plugins in your rails projects, but not so great for a development > effort in multiple people are pushing and pulling to multiple > repositories with dependencies and no multi-project transaction support. > > The parent repository depends on specific versions of the subs. As > you're making changes in your local repos, the last thing you do is > commit the parent with the references to the new versions of the subs. > Every time you make a change to any of the subs you have to commit a > change to the parent. These changes are useful as documentation if > you're updating a plugin to the latest release. Not that useful if the > log is polluted with these for every commit to every submodule. > > When you pull, you pull the parent first, and then use git-submodule > to pull the correct versions of the subs. The parent is in control of > the situation and it somewhat guarantees that you're getting all the > right stuff. This is GREAT for consumers, but problematic for > contributors. And even then, if consumers are pulling from a > development branch while developers are pushing to it, then consumers > might run into problems. > > Let's say you're doing a pull while I'm doing a push. If I push the > parent first, and I push it before you do, there is a chance that when > you go to pull the subs those versions of the subs might not be there > yet. Conversely, if I push the subs first and you grab an old parent, > you'll be pulling old subs. No problem when you're pulling, but it's > going to create problems when you go to push because you're that much > further down the history. > > Of course, these problems exist even when you're dealing with a single > repository on a team that believes in frequent commits, continuous > integration, etc. And just by virtue of the fact that we have several > repos with dependencies means that we're going to run into conflicts > now and then. It just seems that the explicit references from parent > to children adds a layer of complexity to this for both consumers and > developers. > > This all make sense? > > > >> Cheers, > >> Jon > >> > >> On Wed, 2008-04-16 at 22:39 -0400, David Chelimsky wrote: > >>> Hey all, > >>> > >>> We ran into some problems last night with the repos up at github. We > >>> initially thought it was a git-submodules bug. We learned that it > >>> was > >>> something else, but in the process of trying to find the source of > >>> the > >>> bug, we learned a few things about git-submodules and have decided > >>> that it creates an unfortunate set of complications and dependencies > >>> for a development effort like ours. > >>> > >>> To that end, we have simplified. No more submodules. To update, do > >>> the > >>> following: > >>> > >>> cd rspec-dev > >>> git pull > >>> rake git:update > >>> > >>> See http://github.com/dchelimsky/rspec-dev/wikis/contributingpatches > >>> for more info. > >>> > >>> Cheers, > >>> David > > _______________________________________________ > 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/20080417/f8af287a/attachment.html From j at jonathanleighton.com Thu Apr 17 12:01:55 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Thu, 17 Apr 2008 17:01:55 +0100 Subject: [rspec-users] rspec + github == !submodules In-Reply-To: <3DEEE25E-42DB-48BA-8EB8-33477C269B53@gmail.com> References: <57c63afe0804161939k12ce1652x2b5fe7d79be2d47a@mail.gmail.com> <1208424039.7094.0.camel@tybalt> <88035FD5-2D44-488A-A502-90E709AB8296@gmail.com> <3DEEE25E-42DB-48BA-8EB8-33477C269B53@gmail.com> Message-ID: <1208448115.6992.6.camel@tybalt> On Thu, 2008-04-17 at 08:49 -0400, David Chelimsky wrote: > This all make sense? Ok, I have to confess I haven't been paying that much attention to the way things are or were set out on github, so let me see if I'm fully understanding what you're saying... Was "rspec" previously split up into several repositories, with a "parent" repository which contained the other repositories as submodules? So you are essentially saying that it is a bad idea to split one single project into a number of pieces and manage that project through submodules? However, you do consider submodules to be a good idea if you are using and wish to track third-party upstream code, for example plugins in a Rails project? Cheers -- Jonathan Leighton http://jonathanleighton.com/ From joe at pinkpucker.net Thu Apr 17 14:13:38 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Thu, 17 Apr 2008 11:13:38 -0700 Subject: [rspec-users] Writing a story for logging in with OpenID In-Reply-To: <7AE932E7-6B50-4F5A-B04C-16FCBB93960D@gmail.com> References: <7AE932E7-6B50-4F5A-B04C-16FCBB93960D@gmail.com> Message-ID: I found this on the internet somewhere, forgot where: odule OpenIdAuthentication EXTENSION_FIELDS = {'email' => 'user at somedomain.com', 'nickname' => 'cool_user', 'country' => 'US', 'postcode' => '12345', 'fullname' => 'Cool User', 'dob' => '1970-04-01', 'language' => 'en', 'timezone' => 'America/New_York'} protected def authenticate_with_open_id(identity_url = params[:openid_url], fields = {}) #:doc: identity_url = normalize_url(identity_url) if User.find_by_identity_url(identity_url) || identity_url.include?('good') # Don't process registration fields unless it is requested. unless identity_url.include?('blank') || (fields[:required].nil? && fields[:optional].nil?) extension_response_fields = {} # fields[:required].each do |field| # extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s] # end fields[:optional].each do |field| extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s] end end yield Result[:successful], identity_url , extension_response_fields else logger.info "OpenID authentication failed: #{identity_url}" yield Result[:failed], identity_url, nil end end private def add_simple_registration_fields(open_id_response, fields) open_id_response.add_extension_arg('sreg', 'required', [ fields[:required] ].flatten * ',') if fields[:required] open_id_response.add_extension_arg('sreg', 'optional', [ fields[:optional] ].flatten * ',') if fields[:optional] end end Seemed to do the trick. On Tue, Apr 15, 2008 at 9:50 PM, Bryan Ray wrote: > This is a rather open ended question, Joe. You might want to get a > little more detailed. > > Would you happen to have any code to paste or a specific problem? I > think you might have a tough time finding someone who has written > specific mocks around the openid calls. > > > > On Apr 15, 2008, at 8:09 PM, Joe Van Dyk wrote: > > > So I added OpenID to my application (via the openid plugin). But I'm > > having troubles writing the story for it -- specifically, how to mock > > the openid calls. > > > > Anyone got any quick pointers? > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Thu Apr 17 23:43:44 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 17 Apr 2008 20:43:44 -0700 Subject: [rspec-users] rspec + github == !submodules In-Reply-To: <1208448115.6992.6.camel@tybalt> References: <57c63afe0804161939k12ce1652x2b5fe7d79be2d47a@mail.gmail.com> <1208424039.7094.0.camel@tybalt> <88035FD5-2D44-488A-A502-90E709AB8296@gmail.com> <3DEEE25E-42DB-48BA-8EB8-33477C269B53@gmail.com> <1208448115.6992.6.camel@tybalt> Message-ID: <810a540e0804172043v2aaa54d7m714b4ab528f14b38@mail.gmail.com> On Thu, Apr 17, 2008 at 9:01 AM, Jonathan Leighton wrote: > On Thu, 2008-04-17 at 08:49 -0400, David Chelimsky wrote: > > This all make sense? > > Ok, I have to confess I haven't been paying that much attention to the > way things are or were set out on github, so let me see if I'm fully > understanding what you're saying... > > Was "rspec" previously split up into several repositories, with a > "parent" repository which contained the other repositories as > submodules? So you are essentially saying that it is a bad idea to split > one single project into a number of pieces and manage that project > through submodules? However, you do consider submodules to be a good > idea if you are using and wish to track third-party upstream code, for > example plugins in a Rails project? RSpec was split into four repos...and it still is actually. But originally the rspec-dev project was a superproject that included the other three as submodules. The problem with submodules is if two people are making changes to the submodules at the same time. Let's say I work on the rspec submodule, and my final commit is abc123. You work on the rspec submodule as well and your final commit is def456. The superproject tracks the head of each submodule, meaning we each need to commit a reference to the heads of rspec. At some point you pull from my...and the incoming commits say that the head is abc123, but you say def456. merge conflict. Not a big deal, since you have all the latest code, so you can safely point it at def456. But it's a bit of a hassle because you have to do that every single time. I don't actually know what all the potential problems are, but beyond just the hassle, it seems very easy for someone to make a mistake, causing a lot of headaches. We still have stuff split up, but we realized there's no reason for the rspec-dev repo to track the others as submodules. We wrote a rake task to check out all the other repos beneath the rspec-dev dir. It's basically the exact same setup, but without the submodule tracking. And it avoids any problems with submodules, because it's all just standard git push/pull/merge stuff. Pat From matt at mattberther.com Fri Apr 18 01:45:43 2008 From: matt at mattberther.com (Matt Berther) Date: Thu, 17 Apr 2008 23:45:43 -0600 Subject: [rspec-users] How much details is enough? Message-ID: Hi all, Long time lurker, first-time question. :) I've been going back and forth trying to decide how much detail is enough in my controller specs. I feel that if I put too much detail in them, then my tests become very brittle and do not allow me to refactor my code without significant effort on the tests. After all, I have tests so that I can refactor, right? So, let me show two ways that Ive done controller tests and gain insight from my enlightened colleagues on this list to help me make a decision about which way to go. The first is very general coverage that describes the outcome of the behavior: describe FeedsController, 'get /feeds/' do before(:each) do @request.env["HTTP_ACCEPT"] = "application/xml" Model.should_receive(:find).with(any_args).and_return mock_model(Model) end it "should return success" do get '/' response.should be_success end it "should return 405 (Method Not Allowed) if HTTP_ACCEPT is text/ html" do @request.env["HTTP_ACCEPT"] = "text/html" get '/' response.response_code.should == 405 end end The second one is much more detailed: describe FeedsController, 'get /feeds/' do before(:each) do @model = mock_model(Model) @request.env["HTTP_ACCEPT"] = "application/xml" Model.should_receive(:find).with(any_args).and_return @model end it "should assign to the model" do get '/' assigns[:model].should == model end it "should render feed template" do get '/' response.should render_template('feeds/model_feed.xml.erb') end end Obviously, both are very basic in their implementation, but still, I ask... If you were writing the specs, which way would you write them? Thanks for any guidance. -- Matt Berther http://www.mattberther.com From tastapod at gmail.com Fri Apr 18 03:43:06 2008 From: tastapod at gmail.com (Dan North) Date: Fri, 18 Apr 2008 08:43:06 +0100 Subject: [rspec-users] rspec + github == !submodules In-Reply-To: <810a540e0804172043v2aaa54d7m714b4ab528f14b38@mail.gmail.com> References: <57c63afe0804161939k12ce1652x2b5fe7d79be2d47a@mail.gmail.com> <1208424039.7094.0.camel@tybalt> <88035FD5-2D44-488A-A502-90E709AB8296@gmail.com> <3DEEE25E-42DB-48BA-8EB8-33477C269B53@gmail.com> <1208448115.6992.6.camel@tybalt> <810a540e0804172043v2aaa54d7m714b4ab528f14b38@mail.gmail.com> Message-ID: With mercurial I nearly did a similar thing, working on my own but committing from two different machines. Luckily mercurial gave me a warning that allowed me to make sense of what I was doing. Not sure how this works with git but here goes. 1. I push from laptop1 to my central server. All is good. 2. I push from laptop2 to my central server. Mercurial doesn't allow this and warns me that the remote repo will have two heads (which is allowed but probably not what I want). I can override this with --force. 3. Oh silly sod - of course I committed from the other machine. 4. I pull from the central server, merge locally and commit, creating a new single head representing the merge 5. I then push the result, meaning there is only ever a single head/tip/edge/whatever in the repository. 6. I realise that this is what I always do with subversion anyway - update, merge, [run tests], commit. It seems git doesn't protect you from yourself like hg does - which is understandable, it's designed for and used by scarier people! Could a pull-merge-commit before pushing have avoided this, and should we make that our endorsed way of working? Or am I missing something else about how dscm works? Cheers, Dan On 18/04/2008, Pat Maddox wrote: > > On Thu, Apr 17, 2008 at 9:01 AM, Jonathan Leighton > wrote: > > On Thu, 2008-04-17 at 08:49 -0400, David Chelimsky wrote: > > > This all make sense? > > > > Ok, I have to confess I haven't been paying that much attention to the > > way things are or were set out on github, so let me see if I'm fully > > understanding what you're saying... > > > > Was "rspec" previously split up into several repositories, with a > > "parent" repository which contained the other repositories as > > submodules? So you are essentially saying that it is a bad idea to > split > > one single project into a number of pieces and manage that project > > through submodules? However, you do consider submodules to be a good > > idea if you are using and wish to track third-party upstream code, for > > example plugins in a Rails project? > > > RSpec was split into four repos...and it still is actually. But > originally the rspec-dev project was a superproject that included the > other three as submodules. > > The problem with submodules is if two people are making changes to the > submodules at the same time. > > Let's say I work on the rspec submodule, and my final commit is > abc123. You work on the rspec submodule as well and your final commit > is def456. The superproject tracks the head of each submodule, > meaning we each need to commit a reference to the heads of rspec. At > some point you pull from my...and the incoming commits say that the > head is abc123, but you say def456. merge conflict. Not a big deal, > since you have all the latest code, so you can safely point it at > def456. But it's a bit of a hassle because you have to do that every > single time. I don't actually know what all the potential problems > are, but beyond just the hassle, it seems very easy for someone to > make a mistake, causing a lot of headaches. > > We still have stuff split up, but we realized there's no reason for > the rspec-dev repo to track the others as submodules. We wrote a rake > task to check out all the other repos beneath the rspec-dev dir. It's > basically the exact same setup, but without the submodule tracking. > And it avoids any problems with submodules, because it's all just > standard git push/pull/merge stuff. > > > Pat > > _______________________________________________ > 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/20080418/03b4f1c3/attachment-0001.html From pergesu at gmail.com Fri Apr 18 05:15:00 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 18 Apr 2008 02:15:00 -0700 Subject: [rspec-users] How much details is enough? In-Reply-To: References: Message-ID: <810a540e0804180215j64305969o458f2807ebd9c435@mail.gmail.com> Hey Matt, The ultimate test would be one that is focused on one thing such that the test would - break every time that thing broke - break only when that thing broke - give detailed feedback enabling you to focus on the thing's subpart necessary to identify and fix the problem The ultimate test suite would be the set of such tests that covered every single concern that exists in a project. Some of these are concerns are easier to test than others. Some are important and lend themselves to automation, thus enjoy great tool support. Others take something far more abstract like a person's aesthetic appeal. When considering a new test, I should ask myself what problem the test solves, and what problem I really want the test to solve. I try to write the test in terms of the second. For example, if I were to write the following test: it "should allow deposits and withdrawals" do @account.deposit 80 @account.withdraw 25 @account.balance.should == 55 end The test would be valuable when the problem is that you need to track how much money people have in their accounts. If you faced a problem such as "Make sure the user sees an error when they withdraw more than their balance," you would not want a test like: it "should have an overdraft error" do post :withdrawals, :amount => 1_000_000_000_000 # even bill can't do this! assigns[:withdrawal].should have_at_least(1).error_on(:amount) end If this test breaks at some point, we would make a change to the test or production code in order to make it pass. We wouldn't think of the problem it was intended to solve though, because we are absorbed in the problem that initiated the break-inducing change. The danger in this is that the test appears to be robustly covering something useful, but in effect can let problems leak through. Imagine that we remove an important partial from a view. This test, whose ultimate goal was to ensure that users see an error message, failed to catch the problem where the message wasn't displayed at all. So you should write tests expressing the same level abstraction as the problem you want them to solve. Somewhere you would need a test like: it "should have an overdraft error" do @page.should include("Can't withdraw more than your balance") end Now you would need some way to get @page. Perhaps you make a request to a controller, it hits a database, renders a response, and assigns the response body to @page. Or maybe you rendered a view using a fake @withdrawal, and you've got another test that verifies that you assign @withdrawal in the controller, and another test verifies that Withdrawal objects get an error when you try to create them for an amount greater than the target account balance. And you've got a test that you label an Integration test to signal the fact that it integrates all of these pieces. You should only write integration tests that check across valuable boundaries. This does not restrict it to stuff like company-specific code using an ORM framework, though. Because you should only write tests that are valuable, sets of layered tests forms a small subsystem requiring integration testing. It is sometimes useful to have layers of tests that enable you to localize problems. Other times the types of problems you solve will be trivial or obvious and won't require localization. As a simple rule, more tests == more overhead. But if you're missing certain tests then you will not notice certain problems when they appear. The art of all of this is identifying the set of tests that maximizes your confidence and ability to produce valuable software. With all that theory out of the way, what can we say about the tests you presented? > describe FeedsController, 'get /feeds/' do > before(:each) do > @request.env["HTTP_ACCEPT"] = "application/xml" > Model.should_receive(:find).with(any_args).and_return > mock_model(Model) > end > > it "should return success" do > get '/' > response.should be_success > end > > it "should return 405 (Method Not Allowed) if HTTP_ACCEPT is text/ > html" do > @request.env["HTTP_ACCEPT"] = "text/html" > get '/' > response.response_code.should == 405 > end > end This test would be good in a situation where we had published an API stating only XML requests were allowed. > The second one is much more detailed: > > describe FeedsController, 'get /feeds/' do > before(:each) do > @model = mock_model(Model) > @request.env["HTTP_ACCEPT"] = "application/xml" > Model.should_receive(:find).with(any_args).and_return @model > end > > it "should assign to the model" do > get '/' > assigns[:model].should == model > end > > it "should render feed template" do > get '/' > response.should render_template('feeds/model_feed.xml.erb') > end > end This test would be valuable in a context where the XML feed output is complex. In that case, testing the output directly might not sufficiently enable us to localize issues. If you could write tests that examine the response body, without reducing the clarity of the example group, you should do so. Fewer tests == less overhead. > Obviously, both are very basic in their implementation, but still, I > ask... If you were writing the specs, which way would you write them? > Thanks for any guidance. I hope that, despite the typical "it-all-depends-on-context", I was able to give you some insight into identifying and analyzing possible contexts. Pat From pergesu at gmail.com Fri Apr 18 05:24:43 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 18 Apr 2008 02:24:43 -0700 Subject: [rspec-users] rspec + github == !submodules In-Reply-To: References: <57c63afe0804161939k12ce1652x2b5fe7d79be2d47a@mail.gmail.com> <1208424039.7094.0.camel@tybalt> <88035FD5-2D44-488A-A502-90E709AB8296@gmail.com> <3DEEE25E-42DB-48BA-8EB8-33477C269B53@gmail.com> <1208448115.6992.6.camel@tybalt> <810a540e0804172043v2aaa54d7m714b4ab528f14b38@mail.gmail.com> Message-ID: <810a540e0804180224r6867286cre03c6a0668fbd35@mail.gmail.com> On Fri, Apr 18, 2008 at 12:43 AM, Dan North wrote: > Could a pull-merge-commit before pushing have avoided this, and should we > make that our endorsed way of working? Or am I missing something else about > how dscm works? I'm still fuzzy on the details of exactly what happened. I believe it was the result of a "commit -f" which forced the remote repository to rewrite the history when there was branched histories that needed resolving. I believe that pull-merge-commit would work fine, I experimented locally to understand the effects of handling submodule reference merge conflicts. As I mentioned before, it is just a bit of a hassle to have to do. David also pointed out that even without the conflicts, you still have to commit the reference, leading to lots of "updated rspec-rails" type commits in rspec-dev. pull-merge-commit is probably a good workflow (and indeed the only one, because otherwise it's push-REJECTED-pull-merge-commit). The main advantage to not using submodules is that you'll only have to merge is when git can't intelligently merge the repos, rather than every time two repositories have different HEADs. Pat From lists at ruby-forum.com Fri Apr 18 05:32:41 2008 From: lists at ruby-forum.com (Andy Croll) Date: Fri, 18 Apr 2008 11:32:41 +0200 Subject: [rspec-users] redirect_to Message-ID: <2d8d15eb2038afc3620d1ca7fbbce9f6@ruby-forum.com> OK I'm back and surely missing stuff again... In my controller tests I'm checking for a redirect after a destroy action. First up it's a single resource ("map.resource :cart" in routes.rb) in CartsController.rb def destroy @cart = Cart.find(session[:cart], :include => :items) if session[:cart] if @cart Cart.delete(@cart.id) session[:cart] = nil end redirect_to :back end in the spec: (note I'm also testing the case where the is no session var) describe CartsController, "empty existing cart (destroy in db)" do before(:each) do @item1 = mock_model(CartItem, :id => 1) @item2 = mock_model(CartItem, :id => 2) @cart = mock_model(Cart, :id => 1) @cart.stub!(:items).and_return([@item1, @item2]) Cart.stub!(:find).and_return(@cart) session[:cart] = 1000 request.env["HTTP_REFERER"] = "/prev/page" end def do_delete delete :destroy end it "should look in the session for a cart" do Cart.should_receive(:find).with(session[:cart], {:include => :items}).and_return(@cart) do_delete end it "should delete the cart" do Cart.should_receive(:delete).with(1).and_return(true) do_delete end it "should delete the cart id from the session" do do_delete session[:cart].should == nil end it "should redirect to the previous page" do response.should be_redirect end end Unfortunately I'm getting this. 1) 'CartsController empty existing cart (destroy in db) should redirect to the previous page' FAILED expected redirect? to return true, got false Which just ain't true! Am I missing anything? I'd also like to hear any comment on my spec 'style' as I'm new! -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Fri Apr 18 05:35:13 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 18 Apr 2008 02:35:13 -0700 Subject: [rspec-users] redirect_to In-Reply-To: <2d8d15eb2038afc3620d1ca7fbbce9f6@ruby-forum.com> References: <2d8d15eb2038afc3620d1ca7fbbce9f6@ruby-forum.com> Message-ID: <810a540e0804180235l22f9c405s24c67964004d6852@mail.gmail.com> > it "should redirect to the previous page" do > response.should be_redirect > end > > > Am I missing anything? do_delete :) From lists at ruby-forum.com Fri Apr 18 05:39:18 2008 From: lists at ruby-forum.com (Andy Croll) Date: Fri, 18 Apr 2008 11:39:18 +0200 Subject: [rspec-users] redirect_to In-Reply-To: <810a540e0804180235l22f9c405s24c67964004d6852@mail.gmail.com> References: <2d8d15eb2038afc3620d1ca7fbbce9f6@ruby-forum.com> <810a540e0804180235l22f9c405s24c67964004d6852@mail.gmail.com> Message-ID: <1259464ccf82b578b15af7c0681f989c@ruby-forum.com> Pat Maddox wrote: > do_delete :) I do so love mistakes in public, don't you? -- Posted via http://www.ruby-forum.com/. From jarkko at jlaine.net Fri Apr 18 05:41:03 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Fri, 18 Apr 2008 12:41:03 +0300 Subject: [rspec-users] redirect_to In-Reply-To: <2d8d15eb2038afc3620d1ca7fbbce9f6@ruby-forum.com> References: <2d8d15eb2038afc3620d1ca7fbbce9f6@ruby-forum.com> Message-ID: <40A7F56F-EDAD-48BF-925B-2C700B8A17DF@jlaine.net> On 18.4.2008, at 12.32, Andy Croll wrote: > OK I'm back and surely missing stuff again... > > In my controller tests I'm checking for a redirect after a destroy > action. > > First up it's a single resource ("map.resource :cart" in routes.rb) > > in CartsController.rb > > def destroy > @cart = Cart.find(session[:cart], :include => :items) if > session[:cart] > if @cart > Cart.delete(@cart.id) > session[:cart] = nil > end > redirect_to :back > end > > in the spec: (note I'm also testing the case where the is no session > var) > > describe CartsController, "empty existing cart (destroy in db)" do > > before(:each) do > @item1 = mock_model(CartItem, :id => 1) > @item2 = mock_model(CartItem, :id => 2) > > @cart = mock_model(Cart, :id => 1) > @cart.stub!(:items).and_return([@item1, @item2]) > > Cart.stub!(:find).and_return(@cart) > session[:cart] = 1000 > > request.env["HTTP_REFERER"] = "/prev/page" > end > > def do_delete > delete :destroy > end > > it "should look in the session for a cart" do > Cart.should_receive(:find).with(session[:cart], {:include => > :items}).and_return(@cart) > do_delete > end > > it "should delete the cart" do > Cart.should_receive(:delete).with(1).and_return(true) > do_delete > end > > it "should delete the cart id from the session" do > do_delete > session[:cart].should == nil > end > > it "should redirect to the previous page" do > response.should be_redirect > end I would perhaps use > it "should redirect to the previous page" do > response.should redirect_to "/prev/page" > end since you're also interested in where the redirect goes, but dunno if it solves your problem. //jarkko > > > end > > Unfortunately I'm getting this. > > 1) > 'CartsController empty existing cart (destroy in db) should redirect > to > the previous page' FAILED > expected redirect? to return true, got false > > Which just ain't true! > > Am I missing anything? I'd also like to hear any comment on my spec > 'style' as I'm new! > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available Url : http://rubyforge.org/pipermail/rspec-users/attachments/20080418/d5b5c0b6/attachment.bin From chris at edendevelopment.co.uk Fri Apr 18 05:44:04 2008 From: chris at edendevelopment.co.uk (Chris Parsons) Date: Fri, 18 Apr 2008 10:44:04 +0100 Subject: [rspec-users] How much details is enough? In-Reply-To: <810a540e0804180215j64305969o458f2807ebd9c435@mail.gmail.com> References: <810a540e0804180215j64305969o458f2807ebd9c435@mail.gmail.com> Message-ID: Very nice reply Pat. This would make a great blog post if you get a chance. Thanks Chris On 18 Apr 2008, at 10:15, Pat Maddox wrote: > Hey Matt, > > The ultimate test would be one that is focused on one thing such that > the test would > - break every time that thing broke > - break only when that thing broke > - give detailed feedback enabling you to focus on the thing's > subpart necessary to identify and fix the problem > > The ultimate test suite would be the set of such tests that covered > every single concern that exists in a project. > > Some of these are concerns are easier to test than others. Some are > important and lend themselves to automation, thus enjoy great tool > support. Others take something far more abstract like a person's > aesthetic appeal. > > When considering a new test, I should ask myself what problem the > test solves, and what problem I really want the test to solve. I try > to write the test in terms of the second. For example, if I were to > write the following test: > > it "should allow deposits and withdrawals" do > @account.deposit 80 > @account.withdraw 25 > @account.balance.should == 55 > end > > The test would be valuable when the problem is that you need to track > how much money people have in their accounts. > > If you faced a problem such as "Make sure the user sees an error when > they withdraw more than their balance," you would not want a test > like: > > it "should have an overdraft error" do > post :withdrawals, :amount => 1_000_000_000_000 # even bill can't > do this! > assigns[:withdrawal].should have_at_least(1).error_on(:amount) > end > > If this test breaks at some point, we would make a change to the test > or production code in order to make it pass. We wouldn't think of the > problem it was intended to solve though, because we are absorbed in > the problem that initiated the break-inducing change. The danger in > this is that the test appears to be robustly covering something > useful, but in effect can let problems leak through. Imagine that we > remove an important partial from a view. This test, whose ultimate > goal was to ensure that users see an error message, failed to catch > the problem where the message wasn't displayed at all. > > So you should write tests expressing the same level abstraction as the > problem you want them to solve. Somewhere you would need a test like: > > it "should have an overdraft error" do > @page.should include("Can't withdraw more than your balance") > end > > Now you would need some way to get @page. Perhaps you make a request > to a controller, it hits a database, renders a response, and assigns > the response body to @page. > > Or maybe you rendered a view using a fake @withdrawal, and you've got > another test that verifies that you assign @withdrawal in the > controller, and another test verifies that Withdrawal objects get an > error when you try to create them for an amount greater than the > target account balance. And you've got a test that you label an > Integration test to signal the fact that it integrates all of these > pieces. > > You should only write integration tests that check across valuable > boundaries. This does not restrict it to stuff like company-specific > code using an ORM framework, though. Because you should only write > tests that are valuable, sets of layered tests forms a small subsystem > requiring integration testing. > > It is sometimes useful to have layers of tests that enable you to > localize problems. Other times the types of problems you solve will > be trivial or obvious and won't require localization. > > As a simple rule, more tests == more overhead. But if you're missing > certain tests then you will not notice certain problems when they > appear. The art of all of this is identifying the set of tests that > maximizes your confidence and ability to produce valuable software. > > With all that theory out of the way, what can we say about the tests > you presented? > > >> describe FeedsController, 'get /feeds/' do >> before(:each) do >> @request.env["HTTP_ACCEPT"] = "application/xml" >> Model.should_receive(:find).with(any_args).and_return >> mock_model(Model) >> end >> >> it "should return success" do >> get '/' >> response.should be_success >> end >> >> it "should return 405 (Method Not Allowed) if HTTP_ACCEPT is text/ >> html" do >> @request.env["HTTP_ACCEPT"] = "text/html" >> get '/' >> response.response_code.should == 405 >> end >> end > > This test would be good in a situation where we had published an API > stating only XML requests were allowed. > > >> The second one is much more detailed: >> >> describe FeedsController, 'get /feeds/' do >> before(:each) do >> @model = mock_model(Model) >> @request.env["HTTP_ACCEPT"] = "application/xml" >> Model.should_receive(:find).with(any_args).and_return @model >> end >> >> it "should assign to the model" do >> get '/' >> assigns[:model].should == model >> end >> >> it "should render feed template" do >> get '/' >> response.should render_template('feeds/model_feed.xml.erb') >> end >> end > > This test would be valuable in a context where the XML feed output is > complex. In that case, testing the output directly might not > sufficiently enable us to localize issues. > > If you could write tests that examine the response body, without > reducing the clarity of the example group, you should do so. Fewer > tests == less overhead. > > >> Obviously, both are very basic in their implementation, but still, I >> ask... If you were writing the specs, which way would you write them? >> Thanks for any guidance. > > I hope that, despite the typical "it-all-depends-on-context", I was > able to give you some insight into identifying and analyzing possible > contexts. > > Pat > _______________________________________________ > 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/20080418/e659d243/attachment-0001.html From pergesu at gmail.com Fri Apr 18 05:47:58 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 18 Apr 2008 02:47:58 -0700 Subject: [rspec-users] How much details is enough? In-Reply-To: References: <810a540e0804180215j64305969o458f2807ebd9c435@mail.gmail.com> Message-ID: <810a540e0804180247x1c68d684n446aeba4ecd66f8@mail.gmail.com> It seems like I'm constantly making long-winded replies that would be better off in a blog post or in a book. Pat On Fri, Apr 18, 2008 at 2:44 AM, Chris Parsons wrote: > Very nice reply Pat. This would make a great blog post if you get a chance. > > Thanks > Chris > > > > On 18 Apr 2008, at 10:15, Pat Maddox wrote: > > > Hey Matt, > > The ultimate test would be one that is focused on one thing such that > the test would > - break every time that thing broke > - break only when that thing broke > - give detailed feedback enabling you to focus on the thing's > subpart necessary to identify and fix the problem > > The ultimate test suite would be the set of such tests that covered > every single concern that exists in a project. > > Some of these are concerns are easier to test than others. Some are > important and lend themselves to automation, thus enjoy great tool > support. Others take something far more abstract like a person's > aesthetic appeal. > > When considering a new test, I should ask myself what problem the > test solves, and what problem I really want the test to solve. I try > to write the test in terms of the second. For example, if I were to > write the following test: > > it "should allow deposits and withdrawals" do > @account.deposit 80 > @account.withdraw 25 > @account.balance.should == 55 > end > > The test would be valuable when the problem is that you need to track > how much money people have in their accounts. > > If you faced a problem such as "Make sure the user sees an error when > they withdraw more than their balance," you would not want a test > like: > > it "should have an overdraft error" do > post :withdrawals, :amount => 1_000_000_000_000 # even bill can't do > this! > assigns[:withdrawal].should have_at_least(1).error_on(:amount) > end > > If this test breaks at some point, we would make a change to the test > or production code in order to make it pass. We wouldn't think of the > problem it was intended to solve though, because we are absorbed in > the problem that initiated the break-inducing change. The danger in > this is that the test appears to be robustly covering something > useful, but in effect can let problems leak through. Imagine that we > remove an important partial from a view. This test, whose ultimate > goal was to ensure that users see an error message, failed to catch > the problem where the message wasn't displayed at all. > > So you should write tests expressing the same level abstraction as the > problem you want them to solve. Somewhere you would need a test like: > > it "should have an overdraft error" do > @page.should include("Can't withdraw more than your balance") > end > > Now you would need some way to get @page. Perhaps you make a request > to a controller, it hits a database, renders a response, and assigns > the response body to @page. > > Or maybe you rendered a view using a fake @withdrawal, and you've got > another test that verifies that you assign @withdrawal in the > controller, and another test verifies that Withdrawal objects get an > error when you try to create them for an amount greater than the > target account balance. And you've got a test that you label an > Integration test to signal the fact that it integrates all of these > pieces. > > You should only write integration tests that check across valuable > boundaries. This does not restrict it to stuff like company-specific > code using an ORM framework, though. Because you should only write > tests that are valuable, sets of layered tests forms a small subsystem > requiring integration testing. > > It is sometimes useful to have layers of tests that enable you to > localize problems. Other times the types of problems you solve will > be trivial or obvious and won't require localization. > > As a simple rule, more tests == more overhead. But if you're missing > certain tests then you will not notice certain problems when they > appear. The art of all of this is identifying the set of tests that > maximizes your confidence and ability to produce valuable software. > > With all that theory out of the way, what can we say about the tests > you presented? > > > describe FeedsController, 'get /feeds/' do > before(:each) do > @request.env["HTTP_ACCEPT"] = "application/xml" > Model.should_receive(:find).with(any_args).and_return > mock_model(Model) > end > > it "should return success" do > get '/' > response.should be_success > end > > it "should return 405 (Method Not Allowed) if HTTP_ACCEPT is text/ > html" do > @request.env["HTTP_ACCEPT"] = "text/html" > get '/' > response.response_code.should == 405 > end > end > > This test would be good in a situation where we had published an API > stating only XML requests were allowed. > > > The second one is much more detailed: > > describe FeedsController, 'get /feeds/' do > before(:each) do > @model = mock_model(Model) > @request.env["HTTP_ACCEPT"] = "application/xml" > Model.should_receive(:find).with(any_args).and_return @model > end > > it "should assign to the model" do > get '/' > assigns[:model].should == model > end > > it "should render feed template" do > get '/' > response.should render_template('feeds/model_feed.xml.erb') > end > end > > This test would be valuable in a context where the XML feed output is > complex. In that case, testing the output directly might not > sufficiently enable us to localize issues. > > If you could write tests that examine the response body, without > reducing the clarity of the example group, you should do so. Fewer > tests == less overhead. > > > Obviously, both are very basic in their implementation, but still, I > ask... If you were writing the specs, which way would you write them? > Thanks for any guidance. > > I hope that, despite the typical "it-all-depends-on-context", I was > able to give you some insight into identifying and analyzing possible > contexts. > > 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 > From lists at ruby-forum.com Fri Apr 18 06:05:55 2008 From: lists at ruby-forum.com (Andy Croll) Date: Fri, 18 Apr 2008 12:05:55 +0200 Subject: [rspec-users] redirect_to In-Reply-To: <40A7F56F-EDAD-48BF-925B-2C700B8A17DF@jlaine.net> References: <2d8d15eb2038afc3620d1ca7fbbce9f6@ruby-forum.com> <40A7F56F-EDAD-48BF-925B-2C700B8A17DF@jlaine.net> Message-ID: <3a4fe70ba2d61053925199eb0bae8f9d@ruby-forum.com> Jarkko Laine wrote: > I would perhaps use > >> it "should redirect to the previous page" do >> response.should redirect_to "/prev/page" >> end Yeah, I'd pulled it back to see what *really* simple mistake I was making. :-) I reintroduced it in my next 'write test -> fail -> write code -> pass' cycle. Thanks to you both! -- Posted via http://www.ruby-forum.com/. From zeljko.filipin at gmail.com Fri Apr 18 06:14:13 2008 From: zeljko.filipin at gmail.com (=?UTF-8?Q?=C5=BDeljko_Filipin?=) Date: Fri, 18 Apr 2008 12:14:13 +0200 Subject: [rspec-users] Story Framework In-Reply-To: <526C3013-5D69-4AD5-954B-F94C07014884@patchspace.co.uk> References: <526C3013-5D69-4AD5-954B-F94C07014884@patchspace.co.uk> Message-ID: Hi Ashley, Thanks for the response and sorry for the delay, I did not have the time to play with rspec these days. On Wed, Apr 16, 2008 at 10:15 AM, Ashley Moran < ashley.moran at patchspace.co.uk> wrote: > Did you mean: "run 'login.txt'" here? No, I really got it wrong. :) I will take a look at the rest of the documentation today and hopefully have something running soon. ?eljko -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080418/1ae82c35/attachment.html From ashley.moran at patchspace.co.uk Fri Apr 18 06:16:00 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 18 Apr 2008 11:16:00 +0100 Subject: [rspec-users] redirect_to In-Reply-To: <1259464ccf82b578b15af7c0681f989c@ruby-forum.com> References: <2d8d15eb2038afc3620d1ca7fbbce9f6@ruby-forum.com> <810a540e0804180235l22f9c405s24c67964004d6852@mail.gmail.com> <1259464ccf82b578b15af7c0681f989c@ruby-forum.com> Message-ID: On 18 Apr 2008, at 10:39, Andy Croll wrote: >> do_delete :) > > I do so love mistakes in public, don't you? I do this SO often - hopefully I'm not alone :) - I am starting to wish RSpec would ask me "Didn't you mean to make a request in this example?" I'm used to it now though... it's usually the first thing I check in controller specs. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Fri Apr 18 06:23:49 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 18 Apr 2008 11:23:49 +0100 Subject: [rspec-users] How much details is enough? In-Reply-To: References: <810a540e0804180215j64305969o458f2807ebd9c435@mail.gmail.com> Message-ID: On 18 Apr 2008, at 10:44, Chris Parsons wrote: > Very nice reply Pat. This would make a great blog post if you get a > chance. +1 I especially like the line "The art of all of this is identifying the set of tests that maximizes your confidence and ability to produce valuable software." Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From win at wincent.com Fri Apr 18 06:49:08 2008 From: win at wincent.com (Wincent Colaiuta) Date: Fri, 18 Apr 2008 12:49:08 +0200 Subject: [rspec-users] rspec-users Digest, Vol 22, Issue 38 In-Reply-To: References: Message-ID: El 18/4/2008, a las 11:44, "Pat Maddox" escribi?: > I believe that pull-merge-commit would work fine, I experimented > locally to understand the effects of handling submodule reference > merge conflicts. As I mentioned before, it is just a bit of a hassle > to have to do. David also pointed out that even without the > conflicts, you still have to commit the reference, leading to lots of > "updated rspec-rails" type commits in rspec-dev. Yes, it sounds like the whole submodule approach was a poor match for RSpec's organizational structure. I think submodules are really intended for super-projects which aggregate other _independent_ projects for easy consumption by others. Note that the emphasis is on _consumption_. So as you've discovered, while cloning rspec-dev.git and getting all the submodules is nice, it's not so convenient when it comes to actually contributing back. Submodules are really optimized for situations where Project A includes Projects X, Y and Z as submodules, the developers of X, Y and Z mostly work _within_ those projects, and the super-project is only occasionally updated. When I started using Git the whole submodule thing wasn't exposed yet, so it wasn't something I had to consider, but it was already a problem I'd faced previously when I experimented with using SVK as a layer on top of SVN (I was just too sick of SVN's lack of merge tracking). SVK doesn't have svn:externals support, either, you see. I ended up going for the simplest possible solution: symlinks (you can't nest one SVK checkout within another so I really did need to keep them in separate locations). And when I moved to Git I just continued on with the same arrangement, which has worked fine. Although your end solution differs in the details (a rake task which effectively does a few nested clones), the end result is not all that different. The key point is that rspec-dev.git is not actually a "product" intended for consumption by anyone other than people actually working on RSpec itself. It's just a convenience for grouping together a bunch of other projects (which really _must_ belong in repositories of their own because they are consumed by end-users independently of one another) and doing stuff like running a "pre_commit" task to make sure that everything is working. > pull-merge-commit is probably a good workflow (and indeed the only > one, because otherwise it's push-REJECTED-pull-merge-commit). Or fetch-then-rebase-then-commit pull by itself is actually fetch-then-merge If you rebase often (and you probably should in a project like this were there are multiple contributors) then you can do "pull --rebase" as a shortcut for fetch-then-rebase with a recent-enough version of Git. Pat, did you get that email I sent you off-list with the more detailed explanation of rebase? Pasting it in below as it may be of use to others. Cheers, Wincent El 10/4/2008, a las 8:52, "Pat Maddox" escribi?: > > Thanks for that. I wrote what's up on the wiki... and to be perfectly > honest, I only care about the end goal of having clean histories to > merge into RSpec core. I also don't fully understand everything you > wrote. If you had some time, perhaps you could take the existing > content, add some concrete examples of your techniques, and extract > all of that to a new page. I would certainly be very grateful :) I don't have a github account at this stage but here folllows a write- up that you could use to start a new page. Cheers, Wincent Using topic branches when contributing patches A "topic" branch is a separate branch that you use when working on a single "topic" (a bug fix, a new feature, or an experimental idea). Working on a topic branch instead of directly on top of "master" is recommended because: - it allows you to work on multiple, separate topics simultaneously without having them all jumbled together in a single branch - topic branches are easily updated, which means that if the remote "master" evolves while you are working on your topic it is easy to incorporate those changes into your local topic branch before submitting (which in turn will make your topic apply cleanly on top of the current "master") - if you receive feedback on your patches, having all the related changes grouped together in a topic makes it easy to tweak them and resubmit - working on a topic branch makes it easy to refactor a patch series into a logical, clear, clean sequence, which in turn makes your contribution easier to review and more likely to be included So, for all of these reasons it's recommended to use a topic branch for preparing submissions even for simple contributions like single- commit bugfixes and the like. Basic topic branch workflow Let's assume you are working in a clone of the official repository. If you set this up using a standard "git clone" then your local "master" branch will be set up to track the remote "master" branch automatically. # make sure that you're on your local "master" branch git checkout master # integrate latest changes from upstream git pull # create and switch to new topic branch named "my_topic" # (obviously you'd pick a more descriptive name) git checkout -b my_topic # now work on your submission, committing along the way ... # when ready, make a patch series for attachment to a lighthouse ticket git format-patch master That last command will create a numbered series of patch files, one for each commit on your topic branch (ie. all the commits since you branched off from "master"). Advanced topic branch workflow If your topic is long-lived then you can use "git rebase" to keep it up to date and massage it into shape. Imagine that the remote master has three commits at the time you start working: A--B--C You make a topic branch with three new commits: A--B--C \ X--Y--Z Meanwhile, the remote "master" continues to evolve and has three commits of its own: A--B--C--D--E--F \ X--Y--Z Without "git rebase", the only way to get your changes into the "master" branch is for the integrator to perform a merge, creating a new merge commit, M: A--B--C--D--E--F--M \ / X--Y--Z- With "git rebase" your changes can be "rebased" on top of the current remote "master". Git actually removes your three commits (X, Y and Z), "fast forwards" your topic branch to incorporate the latest commits from upstream (D, E and F) and then replays your commits on top of the new HEAD. A--B--C--D--E--F \ X'--Y'--Z' In this way when you submit your patches they can be applied using a simple "fast forward" merge which yields a nice, linear history: A--B--C--D--E--F--X'--Y'--Z' The content of the commits is the same but I've used the X', Y', Z' notation to indicate that the SHA-1 hashes for them will be different (because any change in their ancestry will bubble up and change their identifying hashes). There is no merge, so your patches are guaranteed to apply without merge conflicts. If there are any merge conflicts you will have already resolved them when you ran "git rebase". (This appropriately shifts the burden of resolving merge conflicts away from the central integrator onto the contributor; in this way the project can scale to have many contributors without the integrator becoming a bottleneck.) To make use of all this, all you have to do is: # integrate the latest upstream changes into your "master" git checkout master git pull # make sure that you're on your topic branch git checkout my_topic # do the rebase git rebase master "git rebase" can do more than just keep your topic branch up-to-date. Given our example commits X, Y and Z you might want clean up the history to make it easier to review (because the easier to review, the more likely it is to be accepted, you'll receive better feedback, and bugs are more likely to be caught). By running "git rebase -- interactive" you can: - remove a commit from a series (you realize that commit "Y" doesn't really belong in the series) - amend a commit (you realize that the commit message for "X" isn't quite right) - insert a commit into the series (you realize that you actually need a "W" commit before "X") - "squash" several commits into one (you realize that "X" and "Y" just make the same change in two different files, and so they logically belong in a single commit) - re-order commits (you realize that the series will be easier to understand if "Z" comes before "X" and "Y") When you run "git rebase --interactive" you'll see an editor window that allows you to perform all of the above operations in a simple fashion; you are presented with a list of commits which you can transform as follows: - delete a line to drop that commit - use "pick" (the default) for commits which you want to appear in the rebased history - change "pick" to "edit" for each commit you wish to amend (or perform additional commits) along the way - change "pick" to "squash" for each commit which you want melded into the previous commit - reorder the lines to reorder the commits The rebase will stop automatically for all commits you've marked as "edit", and will provide you with an opportunity to edit the commit message for commits melded together with "squash". It will also stop if there are any merge conflicts to resolve. When you are ready to resume the rebase you just do: git rebase --continue From dchelimsky at gmail.com Fri Apr 18 08:16:52 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 18 Apr 2008 08:16:52 -0400 Subject: [rspec-users] rspec + github == !submodules In-Reply-To: References: <57c63afe0804161939k12ce1652x2b5fe7d79be2d47a@mail.gmail.com> <1208424039.7094.0.camel@tybalt> <88035FD5-2D44-488A-A502-90E709AB8296@gmail.com> <3DEEE25E-42DB-48BA-8EB8-33477C269B53@gmail.com> <1208448115.6992.6.camel@tybalt> <810a540e0804172043v2aaa54d7m714b4ab528f14b38@mail.gmail.com> Message-ID: On Apr 18, 2008, at 3:43 AM, Dan North wrote: > With mercurial I nearly did a similar thing, working on my own but > committing from two different machines. Luckily mercurial gave me a > warning that allowed me to make sense of what I was doing. Not sure > how this works with git but here goes. > > 1. I push from laptop1 to my central server. All is good. > 2. I push from laptop2 to my central server. Mercurial doesn't allow > this and warns me that the remote repo will have two heads (which is > allowed but probably not what I want). I can override this with -- > force. > 3. Oh silly sod - of course I committed from the other machine. This is actually what happened. Two people were doing work at the same time and one got the warning from the repo and did a "push --force." We've all learned a lesson from this and it won't happen again. In my opinion, even if you are allowed to force a push, the repo should maintain some reachable history somewhere of the commits that you are "hiding." So the public "view" removes those commits but they can be retrieved. > 4. I pull from the central server, merge locally and commit, > creating a new single head representing the merge > 5. I then push the result, meaning there is only ever a single head/ > tip/edge/whatever in the repository. > 6. I realise that this is what I always do with subversion anyway - > update, merge, [run tests], commit. > > It seems git doesn't protect you from yourself like hg does - which > is understandable, it's designed for and used by scarier people! It actually does in much the same way. You get a warning, but you can still force the push. > Could a pull-merge-commit before pushing have avoided this, and > should we make that our endorsed way of working? Or am I missing > something else about how dscm works? I do think this should be the way we do things. We have some rake tasks that manage these bits one step at a time. I'll add one that combines them. You'll still be able to do them one at a time, and you'll still need to pull/merge again if central repo warns you on commit. Cheers, David > Cheers, > Dan > > > On 18/04/2008, Pat Maddox wrote: > On Thu, Apr 17, 2008 at 9:01 AM, Jonathan Leighton > wrote: > > On Thu, 2008-04-17 at 08:49 -0400, David Chelimsky wrote: > > > This all make sense? > > > > Ok, I have to confess I haven't been paying that much attention > to the > > way things are or were set out on github, so let me see if I'm > fully > > understanding what you're saying... > > > > Was "rspec" previously split up into several repositories, with a > > "parent" repository which contained the other repositories as > > submodules? So you are essentially saying that it is a bad idea > to split > > one single project into a number of pieces and manage that project > > through submodules? However, you do consider submodules to be a > good > > idea if you are using and wish to track third-party upstream > code, for > > example plugins in a Rails project? > > > RSpec was split into four repos...and it still is actually. But > originally the rspec-dev project was a superproject that included the > other three as submodules. > > The problem with submodules is if two people are making changes to the > submodules at the same time. > > Let's say I work on the rspec submodule, and my final commit is > abc123. You work on the rspec submodule as well and your final commit > is def456. The superproject tracks the head of each submodule, > meaning we each need to commit a reference to the heads of rspec. At > some point you pull from my...and the incoming commits say that the > head is abc123, but you say def456. merge conflict. Not a big deal, > since you have all the latest code, so you can safely point it at > def456. But it's a bit of a hassle because you have to do that every > single time. I don't actually know what all the potential problems > are, but beyond just the hassle, it seems very easy for someone to > make a mistake, causing a lot of headaches. > > We still have stuff split up, but we realized there's no reason for > the rspec-dev repo to track the others as submodules. We wrote a rake > task to check out all the other repos beneath the rspec-dev dir. It's > basically the exact same setup, but without the submodule tracking. > And it avoids any problems with submodules, because it's all just > standard git push/pull/merge stuff. > > > 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080418/9874baca/attachment-0001.html From dchelimsky at gmail.com Fri Apr 18 08:20:17 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 18 Apr 2008 08:20:17 -0400 Subject: [rspec-users] redirect_to In-Reply-To: References: <2d8d15eb2038afc3620d1ca7fbbce9f6@ruby-forum.com> <810a540e0804180235l22f9c405s24c67964004d6852@mail.gmail.com> <1259464ccf82b578b15af7c0681f989c@ruby-forum.com> Message-ID: <710888F7-BB8C-4910-8D2B-72E0D6C0FF27@gmail.com> On Apr 18, 2008, at 6:16 AM, Ashley Moran wrote: > On 18 Apr 2008, at 10:39, Andy Croll wrote: >>> do_delete :) >> >> I do so love mistakes in public, don't you? > > I do this SO often - hopefully I'm not alone :) - I am starting to > wish RSpec would ask me "Didn't you mean to make a request in this > example?" That's actually been discussed recently - Pat - where did we leave that? > I'm used to it now though... it's usually the first thing I check in > controller specs. > > Ashley From dchelimsky at gmail.com Fri Apr 18 09:20:34 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 18 Apr 2008 09:20:34 -0400 Subject: [rspec-users] rspec-users Digest, Vol 22, Issue 38 In-Reply-To: References: Message-ID: <89103408-8D47-45D2-BD7D-2A98A85D92C8@gmail.com> On Apr 18, 2008, at 6:49 AM, Wincent Colaiuta wrote: > I don't have a github account at this stage but here folllows a write- > up that you could use to start a new page. > > Cheers, > Wincent > > Using topic branches when contributing patches Thanks Wincent - very nice writeup! Posted to the wiki at http://github.com/dchelimsky/rspec-dev/wikis/topic-branches Cheers, David From win at wincent.com Fri Apr 18 09:34:53 2008 From: win at wincent.com (Wincent Colaiuta) Date: Fri, 18 Apr 2008 15:34:53 +0200 Subject: [rspec-users] rspec + github == !submodules In-Reply-To: References: Message-ID: <0E36E370-00AD-4BAC-9EA6-3E0A86FB17CA@wincent.com> El 18/4/2008, a las 14:16, David Chelimsky escribi?: > On Apr 18, 2008, at 3:43 AM, Dan North wrote: > >> With mercurial I nearly did a similar thing, working on my own but >> committing from two different machines. Luckily mercurial gave me a >> warning that allowed me to make sense of what I was doing. Not sure >> how this works with git but here goes. >> >> 1. I push from laptop1 to my central server. All is good. >> 2. I push from laptop2 to my central server. Mercurial doesn't allow >> this and warns me that the remote repo will have two heads (which is >> allowed but probably not what I want). I can override this with -- >> force. >> 3. Oh silly sod - of course I committed from the other machine. > > This is actually what happened. Two people were doing work at the same > time and one got the warning from the repo and did a "push --force." > We've all learned a lesson from this and it won't happen again. > > In my opinion, even if you are allowed to force a push, the repo > should maintain some reachable history somewhere of the commits that > you are "hiding." So the public "view" removes those commits but they > can be retrieved. This is a potentially painful lesson that I think we all learn once we start using Git. If you're lucky, you learn it on an unimportant repo or one which you fully control and can dig around in. By way of counter-opinion, the ability to force a push like that may be considered a feature. Example case: you accidentally include confidential company files when you push to a remote repo; if you fix the mistake by altering the history in your local repo and then trying pushing again Git will correctly warn you that this won't be a fast- forward merge, but the ability to force the push anyway allows you to "remove" the unwanted history from the remote repo. Note that the history should still be there, it's just that it won't be "reachable" when someone clones the public repo. Does GitHub provide shell access so that you can get into the remote repo and run stuff like "git fsck" on it? The missing commits should still be in the object database, unless the GitHub crew are doing overly aggressive automatic repacking and pruning on the repos (or unless there is something about the way bare repos work which I don't know; quite possible!). In the case that GitHub doesn't provide shell access then it's really like pushing into a blackhole drop box, with no way to do any "archaeology" on the object database. >> Could a pull-merge-commit before pushing have avoided this, and >> should we make that our endorsed way of working? Or am I missing >> something else about how dscm works? > > I do think this should be the way we do things. We have some rake > tasks that manage these bits one step at a time. I'll add one that > combines them. You'll still be able to do them one at a time, and > you'll still need to pull/merge again if central repo warns you on > commit. If you get into the habit of rebasing before committing rather than merging you'll get a much nicer history. It will basically look linear: A--B--C--D--E--F--G--etc Rather than full of crisscrosses from multiple small merges: E'--F' / \ A--B--C--D--E--F--G--H--I--J \ / \ \ / B'--C' E''--F''--G'--H' Sure, Git can easily do the merges but the resulting history is harder to analyse and less "bisectable" (with "git bisect"). Cheers, Wincent From loop at superinfinite.com Fri Apr 18 14:16:44 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Fri, 18 Apr 2008 20:16:44 +0200 Subject: [rspec-users] Creating stories for the second resource. Very wet appro In-Reply-To: <11e1c34a425fa8e36143b30f1d7c68d0@ruby-forum.com> References: <11e1c34a425fa8e36143b30f1d7c68d0@ruby-forum.com> Message-ID: <2994B134-6817-4A2C-B400-7FA77BE2A93B@superinfinite.com> On 17 apr 2008, at 15:44, Joseph Wilk wrote: > Hello, > > I've come across a similar problem. Sharing the steps is the easy bit. > And I've started to create a 'useful_steps.rb' for storing very common > steps. So have I. I use a lot of "Given a number of flurps in the system", and "When I add a new zoink", most as as refactored and abstracted as possible in common_steps.rb. Also, a form_steps.rb for common webrat steps. > I have just copy and pasted the plain text stories before but since > they > use the same steps, there was little new steps to write. ..which isn't wrong per se imho. Steps for removing, and editing a post all start from the same initial state, "Given an existing post". > It feels like the steps are where you want to keep it dry but the > stories are the domain specific language to writing > acceptance/integration tests. Exactly. Stories may share steps, but the overal flow is always different. If not, your stories aren't 100% accurate. > So it is similar problem to saying that models contain lots of > 'has_ones' and hence are not dry. Nice analogy :) gr, bartz > Well thats the conclusions I've been coming to after using stories > for a > while. > > -- > Joseph Wilk > http://www.joesniff.co.uk > > > > Tim Haines wrote: >> Hi y'all >> >> I'm about to start writing up the stories for my second resource. >> The >> second resource is so similar to the first that I feel a good way >> for me >> to >> start might be to copy and paste the stories and edit from there. >> This >> seems very anti-dry though. Am I missing something obvious, or would >> you >> expect (and be happy with) a lot of duplication between stories? >> >> Tim. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at mattberther.com Fri Apr 18 14:29:00 2008 From: matt at mattberther.com (Matt Berther) Date: Fri, 18 Apr 2008 12:29:00 -0600 Subject: [rspec-users] How much details is enough? In-Reply-To: <810a540e0804180215j64305969o458f2807ebd9c435@mail.gmail.com> References: <810a540e0804180215j64305969o458f2807ebd9c435@mail.gmail.com> Message-ID: Hi Pat, Wow. Thank you for a very nice response. As others have said, this would be a stellar blog post. As you stated, it does all depend, but the theory that you provided will help me to determine what exactly I am trying to solve with the particular test. I am definitely saving this email, and I am sure that I'm going to be reading this a few times. Thank you again so much for your thoughts. They really did help me answer some of the questions that have been bothering me and have helped me look at testing differently, most specifically in that there is not a "silver bullet" pattern to writing tests. On Fri, Apr 18, 2008 at 3:15 AM, Pat Maddox wrote: > Hey Matt, > > The ultimate test would be one that is focused on one thing such that > the test would > - break every time that thing broke > - break only when that thing broke > - give detailed feedback enabling you to focus on the thing's > subpart necessary to identify and fix the problem > > The ultimate test suite would be the set of such tests that covered > every single concern that exists in a project. > > Some of these are concerns are easier to test than others. Some are > important and lend themselves to automation, thus enjoy great tool > support. Others take something far more abstract like a person's > aesthetic appeal. > > When considering a new test, I should ask myself what problem the > test solves, and what problem I really want the test to solve. I try > to write the test in terms of the second. For example, if I were to > write the following test: > > it "should allow deposits and withdrawals" do > @account.deposit 80 > @account.withdraw 25 > @account.balance.should == 55 > end > > The test would be valuable when the problem is that you need to track > how much money people have in their accounts. > > If you faced a problem such as "Make sure the user sees an error when > they withdraw more than their balance," you would not want a test > like: > > it "should have an overdraft error" do > post :withdrawals, :amount => 1_000_000_000_000 # even bill can't do this! > assigns[:withdrawal].should have_at_least(1).error_on(:amount) > end > > If this test breaks at some point, we would make a change to the test > or production code in order to make it pass. We wouldn't think of the > problem it was intended to solve though, because we are absorbed in > the problem that initiated the break-inducing change. The danger in > this is that the test appears to be robustly covering something > useful, but in effect can let problems leak through. Imagine that we > remove an important partial from a view. This test, whose ultimate > goal was to ensure that users see an error message, failed to catch > the problem where the message wasn't displayed at all. > > So you should write tests expressing the same level abstraction as the > problem you want them to solve. Somewhere you would need a test like: > > it "should have an overdraft error" do > @page.should include("Can't withdraw more than your balance") > end > > Now you would need some way to get @page. Perhaps you make a request > to a controller, it hits a database, renders a response, and assigns > the response body to @page. > > Or maybe you rendered a view using a fake @withdrawal, and you've got > another test that verifies that you assign @withdrawal in the > controller, and another test verifies that Withdrawal objects get an > error when you try to create them for an amount greater than the > target account balance. And you've got a test that you label an > Integration test to signal the fact that it integrates all of these > pieces. > > You should only write integration tests that check across valuable > boundaries. This does not restrict it to stuff like company-specific > code using an ORM framework, though. Because you should only write > tests that are valuable, sets of layered tests forms a small subsystem > requiring integration testing. > > It is sometimes useful to have layers of tests that enable you to > localize problems. Other times the types of problems you solve will > be trivial or obvious and won't require localization. > > As a simple rule, more tests == more overhead. But if you're missing > certain tests then you will not notice certain problems when they > appear. The art of all of this is identifying the set of tests that > maximizes your confidence and ability to produce valuable software. > > With all that theory out of the way, what can we say about the tests > you presented? > > > > > describe FeedsController, 'get /feeds/' do > > before(:each) do > > @request.env["HTTP_ACCEPT"] = "application/xml" > > Model.should_receive(:find).with(any_args).and_return > > mock_model(Model) > > end > > > > it "should return success" do > > get '/' > > response.should be_success > > end > > > > it "should return 405 (Method Not Allowed) if HTTP_ACCEPT is text/ > > html" do > > @request.env["HTTP_ACCEPT"] = "text/html" > > get '/' > > response.response_code.should == 405 > > end > > end > > This test would be good in a situation where we had published an API > stating only XML requests were allowed. > > > > > The second one is much more detailed: > > > > describe FeedsController, 'get /feeds/' do > > before(:each) do > > @model = mock_model(Model) > > @request.env["HTTP_ACCEPT"] = "application/xml" > > Model.should_receive(:find).with(any_args).and_return @model > > end > > > > it "should assign to the model" do > > get '/' > > assigns[:model].should == model > > end > > > > it "should render feed template" do > > get '/' > > response.should render_template('feeds/model_feed.xml.erb') > > end > > end > > This test would be valuable in a context where the XML feed output is > complex. In that case, testing the output directly might not > sufficiently enable us to localize issues. > > If you could write tests that examine the response body, without > reducing the clarity of the example group, you should do so. Fewer > tests == less overhead. > > > > > Obviously, both are very basic in their implementation, but still, I > > ask... If you were writing the specs, which way would you write them? > > Thanks for any guidance. > > I hope that, despite the typical "it-all-depends-on-context", I was > able to give you some insight into identifying and analyzing possible > contexts. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Matt Berther http://www.mattberther.com From rick.denatale at gmail.com Fri Apr 18 17:14:16 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 18 Apr 2008 17:14:16 -0400 Subject: [rspec-users] Debugging trick. Message-ID: Some have probably already discovered this but I've been working through some ui stories, using the rails integration test stuff. I had a story where one very used step was failing in one place. The failing expectation looked like this: response.should have_tag("tr.group_info_row td",group_title) I wanted to look at the response, but only for the case which was failing, so I changed this to: debugger unless have_tag("tr.group_info_row td",group_title).matches?(response) response.should have_tag("tr.group_info_row td",group_title) And rdebug broke right before the expectation would have thrown its exception, and I could see the problem, which was an earlier step which had checked that the request had redirected without following the redirect. I think that this pattern of using a matcher as a predicate might be useful in future debugging sessions. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From rick.denatale at gmail.com Fri Apr 18 18:37:17 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 18 Apr 2008 18:37:17 -0400 Subject: [rspec-users] Integration Test Uploading in Rails 2.0.2 was (Re: Attachment-fu + Story Runner) Message-ID: On Fri, Apr 4, 2008 at 7:10 PM, Joe Van Dyk wrote: > On Fri, Mar 21, 2008 at 5:46 AM, David Chelimsky wrote: > > 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. > > Because I can't upgrade to edge rails. And I want to be able to test > file uploads. Okay, I needed it at work, and enough folks have been asking, so I made a very small plugin which 'applies' via a monkey patch, the rails changeset of my integration upload patch to the gem version of Rails 2.0.2. It's available from github, and the details are at http://talklikeaduck.denhaven2.com/articles/2008/04/18/rails-integration-test-file-upload-plugin -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From mailing_lists at railsnewbie.com Fri Apr 18 22:13:10 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 18 Apr 2008 22:13:10 -0400 Subject: [rspec-users] Debugging trick. In-Reply-To: References: Message-ID: <14C01AAA-EFC4-4440-8F76-34B9BA7816BB@railsnewbie.com> On Apr 18, 2008, at 5:14 PM, Rick DeNatale wrote: > Some have probably already discovered this but I've been working > through some ui stories, using the rails integration test stuff. > > I had a story where one very used step was failing in one place. The > failing expectation looked like this: > > response.should have_tag("tr.group_info_row td",group_title) > > I wanted to look at the response, but only for the case which was > failing, so I changed this to: > > debugger unless have_tag("tr.group_info_row > td",group_title).matches?(response) > response.should have_tag("tr.group_info_row td",group_title) > > And rdebug broke right before the expectation would have thrown its > exception, and I could see the problem, which was an earlier step > which had checked that the request had redirected without following > the redirect. Yeah - I use this all the time. I have a textmate snippet called debug(tab) which inserts the following: require "rubygems"; require "ruby-debug"; debugger This allows me to use it in all sort of contexts - migrations, outside of rails projects, in failing test cases, etc. It should be noted that in other languages (like Smalltalk and lisp) the debugger pops up automatically when a test case fails. I don't know why this technique has never picked up and become popular. Scott From lists at ruby-forum.com Fri Apr 18 22:36:45 2008 From: lists at ruby-forum.com (Zubin Henner) Date: Sat, 19 Apr 2008 04:36:45 +0200 Subject: [rspec-users] before_validation callbacks bypassed when stubbing :vali In-Reply-To: References: <3399554dc93b4c860fe69a5d40f9217b@ruby-forum.com> Message-ID: <47152309889e71bc8636a5189f9afb3c@ruby-forum.com> Ashley, Edvard: Thank you both for your advice and comments. For now, I've implemented fixture_replacement. Perhaps a story would be better, but this is working well for now. Cheers, Zubin -- Posted via http://www.ruby-forum.com/. From jam5t3r.lists at gmail.com Sat Apr 19 02:10:28 2008 From: jam5t3r.lists at gmail.com (Jamie D) Date: Fri, 18 Apr 2008 23:10:28 -0700 Subject: [rspec-users] rspec test for converting a hash to a URL string In-Reply-To: <810a540e0804141933v5a63b460j3eae6ed3f2c83b11@mail.gmail.com> References: <9acc822c0804141858o2894231cyadb58d345ea2f83d@mail.gmail.com> <810a540e0804141933v5a63b460j3eae6ed3f2c83b11@mail.gmail.com> Message-ID: <9acc822c0804182310v207a4adcp37fbc4f19d8d5263@mail.gmail.com> Thanks Pat, I wrote my first custom matcher and its all working now. Jamie From jam5t3r.lists at gmail.com Sat Apr 19 02:23:12 2008 From: jam5t3r.lists at gmail.com (Jamie D) Date: Fri, 18 Apr 2008 23:23:12 -0700 Subject: [rspec-users] Stubbing class in controller Message-ID: <9acc822c0804182323y637a7d2cnbc6b34e9bdf7d826@mail.gmail.com> Hi, I am trying to stub a class in my controller and I can't get it to work, the controller code is: def show @server = Server.find(params[:id]) whm = Whm::Client.new @server @server_load = whm.loadavg end and my test code: before(:each) do @server = mock_model(Server) Server.stub!(:find).and_return(@server) end def do_get get :show, :id => "1" end it "should be successful" do Whm::Client.stub!(:new) Whm::Client.stub!(:loadavg) do_get response.should be_success end After running my tests I get a failure message: 'ServersController handling GET /servers/1 should be successful' FAILED expected success? to return true, got false ./spec/controllers/servers_controller_spec.rb:63: I'm not really sure how to stub this kind of class call. Thanks Jamie From ivo.dancet at gmail.com Sat Apr 19 04:22:15 2008 From: ivo.dancet at gmail.com (Ivo Dancet) Date: Sat, 19 Apr 2008 10:22:15 +0200 Subject: [rspec-users] Stubbing class in controller In-Reply-To: <9acc822c0804182323y637a7d2cnbc6b34e9bdf7d826@mail.gmail.com> References: <9acc822c0804182323y637a7d2cnbc6b34e9bdf7d826@mail.gmail.com> Message-ID: <5C32BEC5-E712-40AE-9452-E0435E10A591@gmail.com> Hi The 'loadavg' method is an instance method of 'whm', so the test should be: @whm = mock_model(Whm::Client) Whm::Client.stub!(:new).and_return(@whm) # make the new method to return a mock object @whm.stub!(:loadavg).and_return(3) # 3 is the dummy loadavg, maybe you can change it in something more meaningfull For now, there is no real reason to put this into the test itself. I think I would put this code in the before part. Regards Ivo Op 19-apr-08, om 08:23 heeft Jamie D het volgende geschreven: > Hi, > > I am trying to stub a class in my controller and I can't get it to > work, the controller code is: > > def show > @server = Server.find(params[:id]) > whm = Whm::Client.new @server > @server_load = whm.loadavg > end > > and my test code: > > before(:each) do > @server = mock_model(Server) > Server.stub!(:find).and_return(@server) > end > > def do_get > get :show, :id => "1" > end > > it "should be successful" do > Whm::Client.stub!(:new) > Whm::Client.stub!(:loadavg) > do_get > response.should be_success > end > > After running my tests I get a failure message: > > 'ServersController handling GET /servers/1 should be successful' > FAILED > expected success? to return true, got false > ./spec/controllers/servers_controller_spec.rb:63: > > I'm not really sure how to stub this kind of class call. > > Thanks > Jamie > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rick.denatale at gmail.com Sat Apr 19 09:43:50 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sat, 19 Apr 2008 09:43:50 -0400 Subject: [rspec-users] Debugging trick. In-Reply-To: <14C01AAA-EFC4-4440-8F76-34B9BA7816BB@railsnewbie.com> References: <14C01AAA-EFC4-4440-8F76-34B9BA7816BB@railsnewbie.com> Message-ID: On Fri, Apr 18, 2008 at 10:13 PM, Scott Taylor wrote: > > On Apr 18, 2008, at 5:14 PM, Rick DeNatale wrote: > > > Some have probably already discovered this but I've been working > > through some ui stories, using the rails integration test stuff. > > > > I had a story where one very used step was failing in one place. The > > failing expectation looked like this: > > > > response.should have_tag("tr.group_info_row td",group_title) > > > > I wanted to look at the response, but only for the case which was > > failing, so I changed this to: > > > > debugger unless have_tag("tr.group_info_row > > td",group_title).matches?(response) > > response.should have_tag("tr.group_info_row td",group_title) > > > > And rdebug broke right before the expectation would have thrown its > > exception, and I could see the problem, which was an earlier step > > which had checked that the request had redirected without following > > the redirect. > > Yeah - I use this all the time. I have a textmate snippet called > debug(tab) which inserts the following: > > require "rubygems"; require "ruby-debug"; debugger Well I wasn't really talking about just using the debugger, but using matcher.matches?(value) instead of value.should matcher as a way to trigger a conditional break. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From brian.takita at gmail.com Sat Apr 19 12:43:11 2008 From: brian.takita at gmail.com (Brian Takita) Date: Sat, 19 Apr 2008 09:43:11 -0700 Subject: [rspec-users] Debugging trick. In-Reply-To: <14C01AAA-EFC4-4440-8F76-34B9BA7816BB@railsnewbie.com> References: <14C01AAA-EFC4-4440-8F76-34B9BA7816BB@railsnewbie.com> Message-ID: <1d7ddd110804190943s6afd9b01kf0f3e0087b5d8022@mail.gmail.com> On Fri, Apr 18, 2008 at 7:13 PM, Scott Taylor wrote: > > On Apr 18, 2008, at 5:14 PM, Rick DeNatale wrote: > > > Some have probably already discovered this but I've been working > > through some ui stories, using the rails integration test stuff. > > > > I had a story where one very used step was failing in one place. The > > failing expectation looked like this: > > > > response.should have_tag("tr.group_info_row td",group_title) > > > > I wanted to look at the response, but only for the case which was > > failing, so I changed this to: > > > > debugger unless have_tag("tr.group_info_row > > td",group_title).matches?(response) > > response.should have_tag("tr.group_info_row td",group_title) > > > > And rdebug broke right before the expectation would have thrown its > > exception, and I could see the problem, which was an earlier step > > which had checked that the request had redirected without following > > the redirect. > > Yeah - I use this all the time. I have a textmate snippet called > debug(tab) which inserts the following: > > require "rubygems"; require "ruby-debug"; debugger > > This allows me to use it in all sort of contexts - migrations, outside > of rails projects, in failing test cases, etc. +1 Its awesome. I also use intellij Idea, which has a console. The console does IO with the debugger. Whats cool is I can click or use a shortcut to jump to the file + line link that the debugger gives. > > It should be noted that in other languages (like Smalltalk and lisp) > the debugger pops up automatically when a test case fails. > > I don't know why this technique has never picked up and become popular. > > Scott > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Sat Apr 19 13:03:46 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 19 Apr 2008 13:03:46 -0400 Subject: [rspec-users] Debugging trick. In-Reply-To: <1d7ddd110804190943s6afd9b01kf0f3e0087b5d8022@mail.gmail.com> References: <14C01AAA-EFC4-4440-8F76-34B9BA7816BB@railsnewbie.com> <1d7ddd110804190943s6afd9b01kf0f3e0087b5d8022@mail.gmail.com> Message-ID: <58B635D7-1D61-4B8D-AE78-BB8345AA11C8@railsnewbie.com> On Apr 19, 2008, at 12:43 PM, Brian Takita wrote: > On Fri, Apr 18, 2008 at 7:13 PM, Scott Taylor > wrote: >> >> On Apr 18, 2008, at 5:14 PM, Rick DeNatale wrote: >> >>> Some have probably already discovered this but I've been working >>> through some ui stories, using the rails integration test stuff. >>> >>> I had a story where one very used step was failing in one place. >>> The >>> failing expectation looked like this: >>> >>> response.should have_tag("tr.group_info_row td",group_title) >>> >>> I wanted to look at the response, but only for the case which was >>> failing, so I changed this to: >>> >>> debugger unless have_tag("tr.group_info_row >>> td",group_title).matches?(response) >>> response.should have_tag("tr.group_info_row td",group_title) >>> >>> And rdebug broke right before the expectation would have thrown its >>> exception, and I could see the problem, which was an earlier step >>> which had checked that the request had redirected without following >>> the redirect. >> >> Yeah - I use this all the time. I have a textmate snippet called >> debug(tab) which inserts the following: >> >> require "rubygems"; require "ruby-debug"; debugger >> >> This allows me to use it in all sort of contexts - migrations, >> outside >> of rails projects, in failing test cases, etc. > +1 Its awesome. > > I also use intellij Idea, which has a console. The console does IO > with the debugger. > Whats cool is I can click or use a shortcut to jump to the file + line > link that the debugger gives. Yeah - I often use ruby-debug's mate command, which will open up the file in textmate on the line and file you're currently on (it's incredibly convenient). > >> >> It should be noted that in other languages (like Smalltalk and lisp) >> the debugger pops up automatically when a test case fails. >> >> I don't know why this technique has never picked up and become >> popular. >> >> 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 jam5t3r.lists at gmail.com Sat Apr 19 17:04:45 2008 From: jam5t3r.lists at gmail.com (Jamie D) Date: Sat, 19 Apr 2008 14:04:45 -0700 Subject: [rspec-users] Stubbing class in controller In-Reply-To: <5C32BEC5-E712-40AE-9452-E0435E10A591@gmail.com> References: <9acc822c0804182323y637a7d2cnbc6b34e9bdf7d826@mail.gmail.com> <5C32BEC5-E712-40AE-9452-E0435E10A591@gmail.com> Message-ID: <9acc822c0804191404w1a2e6de6q57291d00857768b1@mail.gmail.com> Thanks Ivo, I was getting a bit confused with the stubs, thanks for the explanation. Jamie On 19/04/2008, Ivo Dancet wrote: > Hi > > The 'loadavg' method is an instance method of 'whm', so the test > should be: > > @whm = mock_model(Whm::Client) > Whm::Client.stub!(:new).and_return(@whm) # make the new method to > return a mock object > @whm.stub!(:loadavg).and_return(3) # 3 is the dummy loadavg, maybe you > can change it in something more meaningfull > > For now, there is no real reason to put this into the test itself. I > think I would put this code in the before part. > > Regards > Ivo From lists at ruby-forum.com Sat Apr 19 18:57:13 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Sun, 20 Apr 2008 00:57:13 +0200 Subject: [rspec-users] Is testing output within content_for possible? Message-ID: <72179a42801f2e58a1ea1c8d6e01c823@ruby-forum.com> I wanted to test that the links below were being rendered in the views. - content_for :sidebar do %ul.links %li= edit_link edit_admin_contact_url(@contact), "Contact" # view test it "should have the correct side bar links" do do_render response.should have_tag("ul.links") do with_tag("a[href=?]", edit_admin_account_url(accounts(:test))) end end The above doesn't work. Just to make sure my tests weren't the issue I removed the content_for block and the tests then passed. Is there something extra that has to be done to get the content_for contents to be rendered? Thanks for the help. -- Posted via http://www.ruby-forum.com/. From ben at benmabey.com Sat Apr 19 22:55:35 2008 From: ben at benmabey.com (Ben Mabey) Date: Sat, 19 Apr 2008 20:55:35 -0600 Subject: [rspec-users] Is testing output within content_for possible? In-Reply-To: <72179a42801f2e58a1ea1c8d6e01c823@ruby-forum.com> References: <72179a42801f2e58a1ea1c8d6e01c823@ruby-forum.com> Message-ID: <480AB0A7.4040202@benmabey.com> Chris Olsen wrote: > I wanted to test that the links below were being rendered in the views. > > - content_for :sidebar do > %ul.links > %li= edit_link edit_admin_contact_url(@contact), "Contact" > > > # view test > it "should have the correct side bar links" do > do_render > response.should have_tag("ul.links") do > with_tag("a[href=?]", edit_admin_account_url(accounts(:test))) > end > end > > The above doesn't work. Just to make sure my tests weren't the issue I > removed the content_for block and the tests then passed. > > Is there something extra that has to be done to get the content_for > contents to be rendered? > > Thanks for the help. > Hey Chris, AFAIK you can't test content_for's in the view specs. Someone may want to correct me on that. I usually test content_for stuff in my stories. If your not using stories then you could try integrating the views on certain controller specs and testing it there. Not the answer you were probably looking for, but I hope that helps. -Ben From bryansray at gmail.com Sun Apr 20 12:18:17 2008 From: bryansray at gmail.com (Bryan Ray) Date: Sun, 20 Apr 2008 11:18:17 -0500 Subject: [rspec-users] Is testing output within content_for possible? In-Reply-To: <480AB0A7.4040202@benmabey.com> References: <72179a42801f2e58a1ea1c8d6e01c823@ruby-forum.com> <480AB0A7.4040202@benmabey.com> Message-ID: <29a0119e0804200918g4bf92c10nd195385131ccfca6@mail.gmail.com> This might be of some use: http://rubyforge.org/pipermail/rspec-users/2007-June/001954.html On Sat, Apr 19, 2008 at 9:55 PM, Ben Mabey wrote: > Chris Olsen wrote: > > I wanted to test that the links below were being rendered in the views. > > > > - content_for :sidebar do > > %ul.links > > %li= edit_link edit_admin_contact_url(@contact), "Contact" > > > > > > # view test > > it "should have the correct side bar links" do > > do_render > > response.should have_tag("ul.links") do > > with_tag("a[href=?]", edit_admin_account_url(accounts(:test))) > > end > > end > > > > The above doesn't work. Just to make sure my tests weren't the issue I > > removed the content_for block and the tests then passed. > > > > Is there something extra that has to be done to get the content_for > > contents to be rendered? > > > > Thanks for the help. > > > > Hey Chris, > AFAIK you can't test content_for's in the view specs. Someone may want > to correct me on that. > > I usually test content_for stuff in my stories. If your not using > stories then you could try integrating the views on certain controller > specs and testing it there. > > Not the answer you were probably looking for, but I hope that helps. > > -Ben > _______________________________________________ > 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/20080420/8c253b2e/attachment-0001.html From lists at ruby-forum.com Sun Apr 20 13:00:01 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Sun, 20 Apr 2008 19:00:01 +0200 Subject: [rspec-users] Is testing output within content_for possible? In-Reply-To: <29a0119e0804200918g4bf92c10nd195385131ccfca6@mail.gmail.com> References: <72179a42801f2e58a1ea1c8d6e01c823@ruby-forum.com> <480AB0A7.4040202@benmabey.com> <29a0119e0804200918g4bf92c10nd195385131ccfca6@mail.gmail.com> Message-ID: <27102a9ba2e0f2c209f05fa5baa61852@ruby-forum.com> Bryan Ray wrote: > This might be of some use: > > http://rubyforge.org/pipermail/rspec-users/2007-June/001954.html > That should do it! Thanks Bryan -- Posted via http://www.ruby-forum.com/. From zach.dennis at gmail.com Sun Apr 20 16:09:27 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sun, 20 Apr 2008 16:09:27 -0400 Subject: [rspec-users] Is testing output within content_for possible? In-Reply-To: <27102a9ba2e0f2c209f05fa5baa61852@ruby-forum.com> References: <72179a42801f2e58a1ea1c8d6e01c823@ruby-forum.com> <480AB0A7.4040202@benmabey.com> <29a0119e0804200918g4bf92c10nd195385131ccfca6@mail.gmail.com> <27102a9ba2e0f2c209f05fa5baa61852@ruby-forum.com> Message-ID: <85d99afe0804201309ycdb1fdao14772e050dc946c0@mail.gmail.com> You can also render a testing layout which yields the content. IE: render "foo", :layout => "testing" In layouts/testing.html.erb: <%= yield :sidebar %> Zach On Sun, Apr 20, 2008 at 1:00 PM, Chris Olsen wrote: > Bryan Ray wrote: > > This might be of some use: > > > > http://rubyforge.org/pipermail/rspec-users/2007-June/001954.html > > > > That should do it! > > Thanks Bryan > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080420/c0b89ee6/attachment.html From jam5t3r.lists at gmail.com Mon Apr 21 02:03:21 2008 From: jam5t3r.lists at gmail.com (Jamie D) Date: Sun, 20 Apr 2008 23:03:21 -0700 Subject: [rspec-users] Mocking Net::SSH connections Message-ID: <9acc822c0804202303o48d2b6b3q77956f75c2939cda@mail.gmail.com> Hi, So I'm stuck again with creating a mock for Net::SSH, I've managed to mock the call to Net::SSH.start and yield the Net::SSH mock but I am totally stuck with mocking the session.shell.sync call and will also need to mock the shell.send_command call also. Any help much appreciated. When I run the following spec I get the error: Mock 'Net::SSH' received unexpected message :shell with (no args) I've tried things like @shell = mock(Net::SSH::Service::Shell) but this also gives an error complaining that Service doe snot exist. # test code @connection = Ssh::Remote.new @ssh = mock(Net::SSH) Net::SSH.should_receive(:start).and_yield(@ssh) Net::SSH.should_receive(:shell).and_return('something') # library code require 'net/ssh' module Ssh class Remote def remote_command(server, user, commands=[]) Net::SSH.start(server, user) do |session| shell = session.shell.sync commands.each do |command| out = shell.send_command command[:command] end end end end end From ashley.moran at patchspace.co.uk Mon Apr 21 02:55:33 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 21 Apr 2008 07:55:33 +0100 Subject: [rspec-users] Mocking Net::SSH connections In-Reply-To: <9acc822c0804202303o48d2b6b3q77956f75c2939cda@mail.gmail.com> References: <9acc822c0804202303o48d2b6b3q77956f75c2939cda@mail.gmail.com> Message-ID: <68893F28-06B4-49F8-96FE-A4BE0834AB49@patchspace.co.uk> On 21 Apr 2008, at 07:03, Jamie D wrote: > Net::SSH.should_receive(:shell).and_return('something') This should be @ssh.should_receive(:shell).and_return('something') But actually it will need to return a mock with :sync stubbed for the line: shell = session.shell.sync Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From aslak.hellesoy at gmail.com Mon Apr 21 03:18:11 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 21 Apr 2008 09:18:11 +0200 Subject: [rspec-users] Mocking Net::SSH connections In-Reply-To: <9acc822c0804202303o48d2b6b3q77956f75c2939cda@mail.gmail.com> References: <9acc822c0804202303o48d2b6b3q77956f75c2939cda@mail.gmail.com> Message-ID: <8d961d900804210018q54b5bffbhee3641eeba65d990@mail.gmail.com> On Mon, Apr 21, 2008 at 8:03 AM, Jamie D wrote: > Hi, > > So I'm stuck again with creating a mock for Net::SSH, I've managed to > mock the call to Net::SSH.start and yield the Net::SSH mock but I am > totally stuck with mocking the session.shell.sync call and will also > need to mock the shell.send_command call also. Any help much > appreciated. > Don't mock APIs you don't own. http://rubyurl.com/53Y6 Instead - create a thin API around such APIs and have your app use that instead. Now you have an easily mockable API. Also make sure you have end-to-end tests that use Net::SSH without any mocking. Aslak > When I run the following spec I get the error: > Mock 'Net::SSH' received unexpected message :shell with (no args) > > I've tried things like @shell = mock(Net::SSH::Service::Shell) but > this also gives an error complaining that Service doe snot exist. > > # test code > @connection = Ssh::Remote.new > @ssh = mock(Net::SSH) > Net::SSH.should_receive(:start).and_yield(@ssh) > Net::SSH.should_receive(:shell).and_return('something') > > # library code > require 'net/ssh' > > module Ssh > class Remote > > def remote_command(server, user, commands=[]) > Net::SSH.start(server, user) do |session| > shell = session.shell.sync > commands.each do |command| > out = shell.send_command command[:command] > end > end > end > end > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Mon Apr 21 03:19:51 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 21 Apr 2008 09:19:51 +0200 Subject: [rspec-users] Mocking Net::SSH connections In-Reply-To: <9acc822c0804202303o48d2b6b3q77956f75c2939cda@mail.gmail.com> References: <9acc822c0804202303o48d2b6b3q77956f75c2939cda@mail.gmail.com> Message-ID: <8d961d900804210019x29cc70c7l4c78f8c289c5ad60@mail.gmail.com> On Mon, Apr 21, 2008 at 8:03 AM, Jamie D wrote: > Hi, > > So I'm stuck again with creating a mock for Net::SSH, I've managed to > mock the call to Net::SSH.start and yield the Net::SSH mock but I am > totally stuck with mocking the session.shell.sync call and will also > need to mock the shell.send_command call also. Any help much > appreciated. > Don't mock APIs you don't own. http://rubyurl.com/53Y6 Instead - create a thin API around such APIs and have your app use that instead. Now you have an easily mockable API. Also make sure you have end-to-end tests that use Net::SSH without any mocking. Aslak > When I run the following spec I get the error: > Mock 'Net::SSH' received unexpected message :shell with (no args) > > I've tried things like @shell = mock(Net::SSH::Service::Shell) but > this also gives an error complaining that Service doe snot exist. > > # test code > @connection = Ssh::Remote.new > @ssh = mock(Net::SSH) > Net::SSH.should_receive(:start).and_yield(@ssh) > Net::SSH.should_receive(:shell).and_return('something') > > # library code > require 'net/ssh' > > module Ssh > class Remote > > def remote_command(server, user, commands=[]) > Net::SSH.start(server, user) do |session| > shell = session.shell.sync > commands.each do |command| > out = shell.send_command command[:command] > end > end > end > end > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From alexander.lystad at finntech.no Mon Apr 21 10:05:13 2008 From: alexander.lystad at finntech.no (alexander.lystad at finntech.no) Date: Mon, 21 Apr 2008 16:05:13 +0200 Subject: [rspec-users] JRuby, RSpec, rcov Message-ID: <6277CD5B4CC0294BA5E860050DB10C5805FA43E7@sch-mail-07.schibsted.no> Do you guys know of any working version combination of JRuby, RSpec and rcov? Doesn't look like rcov 0.8.1.2, RSpec 1.1.3, JRuby 1.1 is one of them. -- Alexander From aslak.hellesoy at gmail.com Mon Apr 21 10:34:34 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 21 Apr 2008 16:34:34 +0200 Subject: [rspec-users] JRuby, RSpec, rcov In-Reply-To: <6277CD5B4CC0294BA5E860050DB10C5805FA43E7@sch-mail-07.schibsted.no> References: <6277CD5B4CC0294BA5E860050DB10C5805FA43E7@sch-mail-07.schibsted.no> Message-ID: <8d961d900804210734t61fd8149o6fc58e785de35a67@mail.gmail.com> On Mon, Apr 21, 2008 at 4:05 PM, wrote: > Do you guys know of any working version combination of JRuby, RSpec and > rcov? Doesn't look like rcov 0.8.1.2, RSpec 1.1.3, JRuby 1.1 is one of > them. > Have you tried JRuby 1.1 + RCov 0.8.1.2 in pure mode (without RSpec?) Aslak > > -- > Alexander > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Apr 21 10:47:44 2008 From: lists at ruby-forum.com (Thijs Cadier) Date: Mon, 21 Apr 2008 16:47:44 +0200 Subject: [rspec-users] Fixtures in Jruby Mysql Message-ID: <134fe5f107a540df203f841825dce02c@ruby-forum.com> Hi, I've been developing a Rails frontend to a Java backend which is working great. I'm running into trouble now that I'm adding a few models though. All specs that use fixtures fail. Jruby gives this error message in the Rspec version of two weeks ago: java.sql.SQLException: Can't call rollback when autocommit=true I've just now updated to the newest CURRENT version of Rspec and the specs now fail silently. I can only assume it's still the same problem :-). I've tried adding ?autoCommit=false to the Jdbc url and I've set config.use_transactional_fixtures to false. Neither of these changes seem to have any effect. There seems to be extremely little information available about this issue through Google. Does anybody have any ideas? Thijs -- Posted via http://www.ruby-forum.com/. From mhennemeyer at googlemail.com Mon Apr 21 10:55:28 2008 From: mhennemeyer at googlemail.com (Matthias Hennemeyer) Date: Mon, 21 Apr 2008 16:55:28 +0200 Subject: [rspec-users] [ANN] StepSpecr Message-ID: <36F46B6F-7AEA-4255-AC42-C664FE93AC07@googlemail.com> Hi, I've written a micro-dsl to spec the step-implementations for rspec user stories. Here is a blog post about it: http://www.workunitgroup.com/2008/4/21/introducing-stepspecr It lives on github: http://github.com/mhennemeyer/stepspecr Some info (from the README) StepSpecr is a Rails plugin intended to be used with Rspec User Stories. It provides a 'testing' framework for speccing Given/When/Then steps within Rspec examples. This lets you implement GWT-steps the BDD way: describe "Given $count articles" do it "should create 1 articles for count=1" do StepSpecr.spec "Given 1 articles" do step_group :articles before do class Article end Article.should_receive(:create) end end end end Thanks matthias -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080421/4fd2bff9/attachment-0001.html From lists at ruby-forum.com Mon Apr 21 11:27:06 2008 From: lists at ruby-forum.com (Andy Croll) Date: Mon, 21 Apr 2008 17:27:06 +0200 Subject: [rspec-users] Spec the Application Controller application.rb Message-ID: <60d89ebca7081d20567f3aa4724a373b@ruby-forum.com> How would I go about writing specs for methods in the Application Controller: I'm thinking of simple methods that do authentication, through before filters or for example how might I spec this method in an application_spec.rb? def store_location session[:return_to] = request.request_uri end The trouble is I'm not generating a request object as the methods are to be used by all controllers... I've tried stubbing... request = mock_model(URI::HTTP, :request_uri => "something") ...or setting the variable in the spec itself... request.response_uri = "something" ...but I can't seem to get the approach right! -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Apr 21 11:30:05 2008 From: lists at ruby-forum.com (Thijs Cadier) Date: Mon, 21 Apr 2008 17:30:05 +0200 Subject: [rspec-users] Fixtures in Jruby Mysql In-Reply-To: <134fe5f107a540df203f841825dce02c@ruby-forum.com> References: <134fe5f107a540df203f841825dce02c@ruby-forum.com> Message-ID: I just realized I made a mistake in the description of the problem. The specs don't fail, but crash. Nothing after the fixtures line in the spec is executed. -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Mon Apr 21 17:06:25 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 21 Apr 2008 14:06:25 -0700 Subject: [rspec-users] Spec the Application Controller application.rb In-Reply-To: <60d89ebca7081d20567f3aa4724a373b@ruby-forum.com> References: <60d89ebca7081d20567f3aa4724a373b@ruby-forum.com> Message-ID: <810a540e0804211406n4fd10bb5g17085b5111bca63@mail.gmail.com> On Mon, Apr 21, 2008 at 8:27 AM, Andy Croll wrote: > How would I go about writing specs for methods in the Application > Controller: > > I'm thinking of simple methods that do authentication, through before > filters or for example how might I spec this method in an > application_spec.rb? > > def store_location > session[:return_to] = request.request_uri > end > > The trouble is I'm not generating a request object as the methods are to > be used by all controllers... I've tried stubbing... > > request = mock_model(URI::HTTP, :request_uri => "something") > > ...or setting the variable in the spec itself... > > request.response_uri = "something" > > ...but I can't seem to get the approach right! Hey Andy, You can define a controller method on the fly in order to test this out. I just did a quick experiment to demonstrate it...obviously modify to suit your needs. application_controller_spec.rb: require File.dirname(__FILE__) + '/../spec_helper' describe "a before_filter" do class FooController < ApplicationController def index; render :text => "foos"; end end controller_name :foo it "should work" do get :index assigns[:assigned].should_not be_blank end end application.rb: class ApplicationController < ActionController::Base before_filter :set_assigned def set_assigned @assigned = "yay" end end From jam5t3r.lists at gmail.com Mon Apr 21 17:22:40 2008 From: jam5t3r.lists at gmail.com (Jamie D) Date: Mon, 21 Apr 2008 14:22:40 -0700 Subject: [rspec-users] Mocking Net::SSH connections In-Reply-To: <8d961d900804210018q54b5bffbhee3641eeba65d990@mail.gmail.com> References: <9acc822c0804202303o48d2b6b3q77956f75c2939cda@mail.gmail.com> <8d961d900804210018q54b5bffbhee3641eeba65d990@mail.gmail.com> Message-ID: <9acc822c0804211422r5fcfc000u67cf01ed7f9490eb@mail.gmail.com> Thanks for the info Aslak, I have rewritten my code like you suggest but have one issue with raising an exception. When I try the code in the console an exception is raised correctly but in my test code I get a message "command did not return expected result" # test describe Ssh, "Remote" do before(:each) do @ssh = mock(Net::SSH) @response = mock(Net::SSH) @connection = Ssh::Remote.new @connection.should_receive(:start).with('server', 'root').and_return(@ssh) @connection.should_receive(:close) @ssh.should_receive(:send_command).with('ls /').and_return(@response) @response.should_receive(:stdout).and_return('a list') end it "should raise exception if response does not match expected" do @connection.remote_command('server', 'root', [{:command => 'ls /', :expects => /blah/}]). should raise_error(Ssh::CommandError, 'command did not return expected result') end end # code exception.rb module Ssh class CommandError < Exception end end # ssh.rb require 'net/ssh' require 'ssh/exception' module Ssh class Remote def remote_command(server, user, commands=[]) shell = start(server, user) commands.each do |command| out = shell.send_command command[:command] unless out.stdout =~ command[:expects] or command[:expects].blank? close raise(CommandError.new, 'command did not return expected result') end end close return true end def start(server, user) @session = Net::SSH.start(server, user) @session.shell.sync end def close() @session.close end end end Thanks Jamie From jam5t3r.lists at gmail.com Mon Apr 21 19:34:32 2008 From: jam5t3r.lists at gmail.com (Jamie D) Date: Mon, 21 Apr 2008 16:34:32 -0700 Subject: [rspec-users] Mocking Net::SSH connections In-Reply-To: <9acc822c0804211422r5fcfc000u67cf01ed7f9490eb@mail.gmail.com> References: <9acc822c0804202303o48d2b6b3q77956f75c2939cda@mail.gmail.com> <8d961d900804210018q54b5bffbhee3641eeba65d990@mail.gmail.com> <9acc822c0804211422r5fcfc000u67cf01ed7f9490eb@mail.gmail.com> Message-ID: <9acc822c0804211634n23a09be2ued682d89a12eb753@mail.gmail.com> Fixed it, I was missing the lambda: it "should raise exception if response does not match expected" do lambda{ @connection.remote_command('server', 'root', [{:command => 'ls /', :expects => /blah/}]) }. should raise_error(Ssh::CommandError, 'command did not return expected result') end On 21/04/2008, Jamie D wrote: > Thanks for the info Aslak, I have rewritten my code like you suggest > but have one issue with raising an exception. When I try the code in > the console an exception is raised correctly but in my test code I get > a message "command did not return expected result" > > # test > describe Ssh, "Remote" do > > before(:each) do > @ssh = mock(Net::SSH) > @response = mock(Net::SSH) > @connection = Ssh::Remote.new > @connection.should_receive(:start).with('server', 'root').and_return(@ssh) > @connection.should_receive(:close) > @ssh.should_receive(:send_command).with('ls /').and_return(@response) > @response.should_receive(:stdout).and_return('a list') > end > > it "should raise exception if response does not match expected" do > @connection.remote_command('server', 'root', [{:command => 'ls /', > :expects => /blah/}]). > should raise_error(Ssh::CommandError, 'command did not return > expected result') > end > > end > > # code exception.rb > module Ssh > class CommandError < Exception > end > end > > # ssh.rb > require 'net/ssh' > require 'ssh/exception' > > > module Ssh > class Remote > > def remote_command(server, user, commands=[]) > > shell = start(server, user) > > commands.each do |command| > out = shell.send_command command[:command] > > unless out.stdout =~ command[:expects] or command[:expects].blank? > close > raise(CommandError.new, 'command did not return expected result') > end > end > close > return true > end > > def start(server, user) > @session = Net::SSH.start(server, user) > @session.shell.sync > end > > def close() > @session.close > end > > end > end > > Thanks > > Jamie > From pezlists at gmail.com Tue Apr 22 09:36:58 2008 From: pezlists at gmail.com (Perryn Fowler) Date: Tue, 22 Apr 2008 23:36:58 +1000 Subject: [rspec-users] how do i remove duplication from my steps in story runner? Message-ID: <1c319b810804220636i50c74466p2af182c91a2e5c02@mail.gmail.com> OK, I'm probably being incredibly dense here I have some steps defined something like this (extremely contrived) example steps_for(:foo) do #snip Given and When steps Then("two nested divs and a image will be displayed") do response.should have_tag("div") do with_tag("div") end response.should have_tag("img") end Then("two nested divs and a table will be displayed") do response.should have_tag("div") do with_tag("div") end response.should have_tag("table") end end with_steps_for :foo do run 'stories/foo_story', :type => RailsStory end Now, I'd like to remove the duplication in there by extracting out a 'two_nested_divs_should_be_displayed' method so that my steps can read more like steps_for(:foo) do #snip Given and When steps Then("two nested divs and a image will be displayed") do two_nested_divs_should_be_displayed response.should have_tag("img") end Then("two nested divs and a table will be displayed") do two_nested_divs_should_be_displayed response.should have_tag("table") end end with_steps_for :foo do run 'stories/foo_story', :type => RailsStory end but the ruby magic going on is proving hard for me to untangle and I can't for the life of me get it to work. I either get method_missing looking for my method, or the method complains that 'with_tag' is undefined. any ideas? From rick.denatale at gmail.com Tue Apr 22 15:00:51 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 22 Apr 2008 15:00:51 -0400 Subject: [rspec-users] how do i remove duplication from my steps in story runner? In-Reply-To: <1c319b810804220636i50c74466p2af182c91a2e5c02@mail.gmail.com> References: <1c319b810804220636i50c74466p2af182c91a2e5c02@mail.gmail.com> Message-ID: On Tue, Apr 22, 2008 at 9:36 AM, Perryn Fowler wrote: > OK, I'm probably being incredibly dense here > > I have some steps defined something like this (extremely contrived) example > > > steps_for(:foo) do > > #snip Given and When steps > > Then("two nested divs and a image will be displayed") do > response.should have_tag("div") do > with_tag("div") > end > response.should have_tag("img") > end > > Then("two nested divs and a table will be displayed") do > response.should have_tag("div") do > with_tag("div") > end > response.should have_tag("table") > end > end > > with_steps_for :foo do > run 'stories/foo_story', :type => RailsStory > end > > > Now, I'd like to remove the duplication in there by extracting out a > 'two_nested_divs_should_be_displayed' method so that my steps can read > more like > > > > steps_for(:foo) do > > #snip Given and When steps > > Then("two nested divs and a image will be displayed") do > two_nested_divs_should_be_displayed > response.should have_tag("img") > end > > Then("two nested divs and a table will be displayed") do > two_nested_divs_should_be_displayed > response.should have_tag("table") > end > end > > with_steps_for :foo do > run 'stories/foo_story', :type => RailsStory > end > > but the ruby magic going on is proving hard for me to untangle and I > can't for the life of me get it to work. I either get method_missing > looking for my method, or the method complains that 'with_tag' is > undefined. > > any ideas? > _______________________________________________ Another attack. Then("two nested divs and an? $type will be displayed") do | type | response.should have_tag("div") do with_tag("div") end response.should have_tag(type == 'image' ? 'img' : type) end -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From pezlists at gmail.com Tue Apr 22 22:30:43 2008 From: pezlists at gmail.com (Perryn Fowler) Date: Wed, 23 Apr 2008 12:30:43 +1000 Subject: [rspec-users] how do i remove duplication from my steps in story runner? In-Reply-To: References: <1c319b810804220636i50c74466p2af182c91a2e5c02@mail.gmail.com> Message-ID: <1c319b810804221930t4e24fa97ge7d5c1488fbd8140@mail.gmail.com> > Another attack. > > Then("two nested divs and an? $type will be displayed") do | type | > > response.should have_tag("div") do > with_tag("div") > end > response.should have_tag(type == 'image' ? 'img' : type) > end > Thanks for the cool idea Rick, but unfortunately that only helps with my contrived little example - for my real app I really do need to be able to factor out some helper methods... From lists at ruby-forum.com Wed Apr 23 02:19:07 2008 From: lists at ruby-forum.com (Andy Croll) Date: Wed, 23 Apr 2008 08:19:07 +0200 Subject: [rspec-users] Spec the Application Controller application.rb In-Reply-To: <810a540e0804211406n4fd10bb5g17085b5111bca63@mail.gmail.com> References: <60d89ebca7081d20567f3aa4724a373b@ruby-forum.com> <810a540e0804211406n4fd10bb5g17085b5111bca63@mail.gmail.com> Message-ID: Pat Maddox wrote: > You can define a controller method on the fly in order to test this > out. I just did a quick experiment to demonstrate it...obviously > modify to suit your needs. Thanks Pat. I think I'm confusing two issues. 1) How to test before filters for something like authentication 2) How to test functions provided in the application controller I'm not putting the before filter in the application.rb, I'm likely to be using it to protect various actions in the app. Is there a way to to call methods directly within the application.rb, spec them there and then sub for functionality in the other controllers? Andy PS Your 'controller spec' blog post was the 'light-going-on-in-my-head' moment for RSpec. Thanks for that! -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Wed Apr 23 02:36:33 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 22 Apr 2008 23:36:33 -0700 Subject: [rspec-users] Spec the Application Controller application.rb In-Reply-To: References: <60d89ebca7081d20567f3aa4724a373b@ruby-forum.com> <810a540e0804211406n4fd10bb5g17085b5111bca63@mail.gmail.com> Message-ID: <810a540e0804222336y381d9c09p53417f9e806b09c3@mail.gmail.com> On Tue, Apr 22, 2008 at 11:19 PM, Andy Croll wrote: > Pat Maddox wrote: > > You can define a controller method on the fly in order to test this > > out. I just did a quick experiment to demonstrate it...obviously > > modify to suit your needs. > > Thanks Pat. > > I think I'm confusing two issues. > > 1) How to test before filters for something like authentication > 2) How to test functions provided in the application controller > > I'm not putting the before filter in the application.rb, I'm likely to > be using it to protect various actions in the app. You can still use the technique that I showed, you would just call before_filter in the fake controller. That would allow you to specify and implement the filter in isolation. > Is there a way to to call methods directly within the application.rb, > spec them there and then sub for functionality in the other > controllers? No to the first part, unfortunately. Rails' controller design isn't particularly test-friendly. As far as using them in other controllers, you can just use the real filter implementation if you want, or stub them if you prefer. Pat From zach.dennis at gmail.com Wed Apr 23 13:20:17 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 23 Apr 2008 13:20:17 -0400 Subject: [rspec-users] how do i remove duplication from my steps in story runner? In-Reply-To: <1c319b810804221930t4e24fa97ge7d5c1488fbd8140@mail.gmail.com> References: <1c319b810804220636i50c74466p2af182c91a2e5c02@mail.gmail.com> <1c319b810804221930t4e24fa97ge7d5c1488fbd8140@mail.gmail.com> Message-ID: <85d99afe0804231020h7200c12x49283e4c2309b3f0@mail.gmail.com> You should be able to make your own module of helpers and include it into Spec::Story::World module Spec::Story::World def your_helper_method # i should have access to everything I need end end Zach On Tue, Apr 22, 2008 at 10:30 PM, Perryn Fowler wrote: > > Another attack. > > > > Then("two nested divs and an? $type will be displayed") do | type | > > > > response.should have_tag("div") do > > with_tag("div") > > end > > response.should have_tag(type == 'image' ? 'img' : type) > > end > > > > Thanks for the cool idea Rick, but unfortunately that only helps with > my contrived little example - > for my real app I really do need to be able to factor out some helper > methods... > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080423/7d9475cb/attachment-0001.html From lists at ruby-forum.com Wed Apr 23 23:16:35 2008 From: lists at ruby-forum.com (Andy Croll) Date: Thu, 24 Apr 2008 05:16:35 +0200 Subject: [rspec-users] Spec the Application Controller application.rb In-Reply-To: <810a540e0804222336y381d9c09p53417f9e806b09c3@mail.gmail.com> References: <60d89ebca7081d20567f3aa4724a373b@ruby-forum.com> <810a540e0804211406n4fd10bb5g17085b5111bca63@mail.gmail.com> <810a540e0804222336y381d9c09p53417f9e806b09c3@mail.gmail.com> Message-ID: Pat Maddox wrote: > You can still use the technique that I showed, you would just call > before_filter in the fake controller. That would allow you to specify > and implement the filter in isolation. Aha! Success, although I needed to add in a little Route fixing to make it work. application_spec.rb: describe ApplicationController, "storing locations" do class FooController < ApplicationController before_filter :assign_var def index; render :text => "foos"; end end controller_name :foo before(:each) do ActionController::Routing::Routes.draw do |map| map.resources :foo end end it "should assign the current user" do get :index assigns[:var].should_not be_blank end end application.rb: class ApplicationController < ActionController::Base def assign_var @var = "Quantum Leap Rocks" end end Hooray. -- Posted via http://www.ruby-forum.com/. From pezlists at gmail.com Thu Apr 24 00:32:28 2008 From: pezlists at gmail.com (Perryn Fowler) Date: Thu, 24 Apr 2008 14:32:28 +1000 Subject: [rspec-users] how do i remove duplication from my steps in story runner? In-Reply-To: <85d99afe0804231020h7200c12x49283e4c2309b3f0@mail.gmail.com> References: <1c319b810804220636i50c74466p2af182c91a2e5c02@mail.gmail.com> <1c319b810804221930t4e24fa97ge7d5c1488fbd8140@mail.gmail.com> <85d99afe0804231020h7200c12x49283e4c2309b3f0@mail.gmail.com> Message-ID: <1c319b810804232132g3066bc1buc0f05d6808ad6f3f@mail.gmail.com> > You should be able to make your own module of helpers and include it into > Spec::Story::World > > module Spec::Story::World > def your_helper_method > # i should have access to everything I need > end >end brilliant, worked like a charm thanks :) If you will indulge a ruby newb question for a moment - how could I have worked this out for myself? From lists at ruby-forum.com Thu Apr 24 02:20:20 2008 From: lists at ruby-forum.com (Andy Croll) Date: Thu, 24 Apr 2008 08:20:20 +0200 Subject: [rspec-users] Spec the Application Controller application.rb In-Reply-To: References: <60d89ebca7081d20567f3aa4724a373b@ruby-forum.com> <810a540e0804211406n4fd10bb5g17085b5111bca63@mail.gmail.com> <810a540e0804222336y381d9c09p53417f9e806b09c3@mail.gmail.com> Message-ID: <0b50219a76dff452d27725113fabf0d8@ruby-forum.com> This bit however, replaces your other routes, so you cannot use them in your tests > before(:each) do > ActionController::Routing::Routes.draw do |map| > map.resources :foo > end > end Is there a sensible way to append to the routes.rb that I'm missing? Andy -- Posted via http://www.ruby-forum.com/. From alexander.lystad at finntech.no Thu Apr 24 04:20:49 2008 From: alexander.lystad at finntech.no (T. Alexander Lystad) Date: Thu, 24 Apr 2008 10:20:49 +0200 Subject: [rspec-users] JRuby, RSpec, rcov In-Reply-To: <6277CD5B4CC0294BA5E860050DB10C5805FA43E7@sch-mail-07.schibsted.no> References: <6277CD5B4CC0294BA5E860050DB10C5805FA43E7@sch-mail-07.schibsted.no> Message-ID: <481042E1.7040609@finntech.no> alexander.lystad at finntech.no skrev: > Do you guys know of any working version combination of JRuby, RSpec and > rcov? Doesn't look like rcov 0.8.1.2, RSpec 1.1.3, JRuby 1.1 is one of > them. I can confirm that this combination works like a charm. As Tobias Torkler posted 17.03.2008: 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) -- T. Alexander Lystad From james2mccarthy at gmail.com Thu Apr 24 05:09:30 2008 From: james2mccarthy at gmail.com (James McCarthy) Date: Thu, 24 Apr 2008 10:09:30 +0100 Subject: [rspec-users] (no subject) Message-ID: <0FF878C8-B2E7-49C0-BB0A-7B4E6442E6D7@gmail.com> James McCarthy http://thewerks.org.uk From mhennemeyer at googlemail.com Thu Apr 24 08:41:47 2008 From: mhennemeyer at googlemail.com (Matthias Hennemeyer) Date: Thu, 24 Apr 2008 14:41:47 +0200 Subject: [rspec-users] how do i remove duplication from my steps in story runner? In-Reply-To: <1c319b810804232132g3066bc1buc0f05d6808ad6f3f@mail.gmail.com> References: <1c319b810804220636i50c74466p2af182c91a2e5c02@mail.gmail.com> <1c319b810804221930t4e24fa97ge7d5c1488fbd8140@mail.gmail.com> <85d99afe0804231020h7200c12x49283e4c2309b3f0@mail.gmail.com> <1c319b810804232132g3066bc1buc0f05d6808ad6f3f@mail.gmail.com> Message-ID: <8AD56F2F-258C-4487-99D1-80F353BE6A8F@googlemail.com> Hi Perryn, maybe you'll find this interesting: http://www.workunitgroup.com/2008/4/23/crafting-rspec-steps-with- step_eval-and-drying-them-with-a-helper The DRYing thing begins at the middle of the second part of this series. matthias From mattlins at gmail.com Thu Apr 24 12:30:11 2008 From: mattlins at gmail.com (Matthew Lins) Date: Thu, 24 Apr 2008 11:30:11 -0500 Subject: [rspec-users] BDD/Rails/Shoulda Message-ID: This is a little off topic, but I use rSpec and I?m starting to question the quality of my specs. In my research and attempt to learn how to write better specs, I?ve came across a few things that I?d like to discuss. I?m having more and more difficulty understanding BDD. The more I read and the more I watch, the more questions I come up with. Let me just ask a couple of general questions to start this off. Is ?shoulda? actually following the principals of BDD? But, I guess that?s not really a good question. Is ?shoulda? encouraging it?s users to follow the principals of BDD? I see all of the macros like: should_belong_to should_require_attributes To me, that is not BDD. Basically that?s just testing whether or not your model contains a certain code fragment. But, that brings me to my next question. Is BDD even possible with Rails? (I think it is, but I ask myself that more and more lately) I just picked a random model in the application I?m currently working on. The ?Picture? model. I use the attachment_fu plugin, which helps this model handle pictures (it creates thumbnails, validates sizes, etc.) I wiped out all the code I had and all the specs I had. I started from scratch: ---------------------------------- class Picture < ActiveRecord::Base end ---------------------------------- The first piece of code I would write if I wasn?t using BDD, would be: ---------------------------------- class Picture < ActiveRecord::Base validates_as_attachment end ---------------------------------- Which basically handles all of my validation. So, from a BDD perspective, how do I spec that? I know, I know, I should be writing the specs first. But, what do I do about these helpers that come with plugins. Do I write a spec: ---------------------------------- describe Picture, ?with a blank filename? do before(:each) do @picture = Picture.new valid_picture_attributes.except(:filename) # This uses some rSpec helpers end it do @picture.should_not be_valid end end ----------------------------------- So, the most simple way to solve that would be (this is part of what ?validates_as_attachment? does): ---------------------------------- class Picture < ActiveRecord::Base validates_presence_of :filename end ---------------------------------- But, now what, I?m going to reverse engineer this plugin?s helper? I?ll just spec it all out and eventually refactor and put the ?validates_as_attachment? back? Or, maybe since this is a plugins helper I don?t even need to test any of this. It?s the author of the plugin?s responsibility. This is were my brain enters an infinite loop (one example anyway, hehe). I just can?t seem to nail down the workflow when specing rails apps. I also have a hard time determining what to spec. I know I asked a lot of questions, but basically I?m just trying to find out if people are actually following the BDD principals strictly when writing Rails apps. If you are can you give me some insight in the above example? Thanks, Matt Lins -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080424/b545dff3/attachment.html From jonathan at parkerhill.com Thu Apr 24 13:58:06 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Thu, 24 Apr 2008 13:58:06 -0400 Subject: [rspec-users] BDD/Rails/Shoulda In-Reply-To: References: Message-ID: <51538E8C-C42A-4AE0-9CE0-25D6560E3CE6@parkerhill.com> I'm not sure this answers your questions, but you prompted me to share my experience. Personally i consider BDD just one tool in my toolbox. And I consider rspec to be as much a testing tool as a (BD)Development one. So I often find myself just taking the path of least resistance. And iterating. In some cases it really 'feels right' to write the examples first and then implement the code, repeat... I love doing that, the 'BDD way' is fun. But half the time, I find myself working 'the old fashioned way' - I write down (often with pen and paper, omg!) a list of things my code needs to do, I implement it, test it manually in the browser or console. After a point (not too much later though) I then go back and write specs that verify my code and firm up my intent. I think this is because Ruby and Rails can be so expressive in themselves (like the plugins you mentioned). I've jokingly referred to this as DDB (development driven behavior). Importantly, when I code first, then spec, the spec phase is not an 'afterthought'. Rather, the code can be thought of a first pass or prototype, and the specs get me the firm up (or reevaluate) the behavior and/or refactor my code. Bottom line -- the process is iterative. In the end, both approaches leave me with quality code, expressive specs, edge test cases, and regression tests. Obviously I'm not speaking as a BDD priest, rather as a soldier in the trenches. linoj On Apr 24, 2008, at 12:30 PM, Matthew Lins wrote: > This is a little off topic, but I use rSpec and I?m starting to > question the quality of my specs. In my research and attempt to > learn how to write better specs, I?ve came across a few things that > I?d like to discuss. > > I?m having more and more difficulty understanding BDD. The more I > read and the more I watch, the more questions I come up with. Let > me just ask a couple of general questions to start this off. > > Is ?shoulda? actually following the principals of BDD? But, I > guess that?s not really a good question. Is ?shoulda? encouraging > it?s users to follow the principals of BDD? I see all of the > macros like: > > should_belong_to > > should_require_attributes > > To me, that is not BDD. Basically that?s just testing whether or > not your model contains a certain code fragment. But, that brings > me to my next question. > > Is BDD even possible with Rails? (I think it is, but I ask myself > that more and more lately) > > I just picked a random model in the application I?m currently > working on. The ?Picture? model. I use the attachment_fu plugin, > which helps this model handle pictures (it creates thumbnails, > validates sizes, etc.) I wiped out all the code I had and all the > specs I had. I started from scratch: > > ---------------------------------- > > class Picture < ActiveRecord::Base > > end > > ---------------------------------- > > The first piece of code I would write if I wasn?t using BDD, would be: > > > ---------------------------------- > > class Picture < ActiveRecord::Base > > validates_as_attachment > > end > > ---------------------------------- > > Which basically handles all of my validation. So, from a BDD > perspective, how do I spec that? I know, I know, I should be > writing the specs first. But, what do I do about these helpers > that come with plugins. Do I write a spec: > > ---------------------------------- > > describe Picture, ?with a blank filename? do > > before(:each) do > @picture = Picture.new valid_picture_attributes.except > (:filename) # This uses some rSpec helpers > end > > it do > @picture.should_not be_valid > end > > end > > ----------------------------------- > > So, the most simple way to solve that would be (this is part of > what ?validates_as_attachment? does): > > ---------------------------------- > > class Picture < ActiveRecord::Base > > validates_presence_of :filename > > end > > ---------------------------------- > > But, now what, I?m going to reverse engineer this plugin?s helper? > I?ll just spec it all out and eventually refactor and put the > ?validates_as_attachment? back? Or, maybe since this is a plugins > helper I don?t even need to test any of this. It?s the author of > the plugin?s responsibility. This is were my brain enters an > infinite loop (one example anyway, hehe). I just can?t seem to > nail down the workflow when specing rails apps. I also have a hard > time determining what to spec. > > I know I asked a lot of questions, but basically I?m just trying to > find out if people are actually following the BDD principals > strictly when writing Rails apps. If you are can you give me some > insight in the above example? > > Thanks, > > Matt Lins > > _______________________________________________ > 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/20080424/9415e2cb/attachment-0001.html From ashley.moran at patchspace.co.uk Thu Apr 24 18:57:51 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 24 Apr 2008 23:57:51 +0100 Subject: [rspec-users] BDD/Rails/Shoulda In-Reply-To: <51538E8C-C42A-4AE0-9CE0-25D6560E3CE6@parkerhill.com> References: <51538E8C-C42A-4AE0-9CE0-25D6560E3CE6@parkerhill.com> Message-ID: <7B749038-B6C8-42EE-8CAB-D92661D3C019@patchspace.co.uk> Hi Matthew/Jonathan On Apr 24, 2008, at 6:58 pm, Jonathan Linowes wrote: > I'm not sure this answers your questions, but you prompted me to > share my experience. And this has prompted mine... I was going to do a blow-by-blow response to Matthew's post but I can probably sum up my current thinking pretty quickly. > Personally i consider BDD just one tool in my toolbox. +1 > And I consider rspec to be as much a testing tool as a > (BD)Development one. So I often find myself just taking the path of > least resistance. And iterating. > > In some cases it really 'feels right' to write the examples first > and then implement the code, repeat... I love doing that, the 'BDD > way' is fun. +1 I think this is something to strive for, because if you get into this rhythm you can enter BDD Flow?, and there's nothing more productive than story-spec-code-spec-code-spec-code story-spec-code... > But half the time, I find myself working 'the old fashioned way' - I > write down (often with pen and paper, omg!) a list of things my code > needs to do, I implement it, test it manually in the browser or > console. I find this happens most often when I'm doing something completely new, or have no idea what the end result should be. > After a point (not too much later though) I then go back and write > specs that verify my code and firm up my intent. I think this is > because Ruby and Rails can be so expressive in themselves (like the > plugins you mentioned). I've jokingly referred to this as DDB > (development driven behavior). > > Importantly, when I code first, then spec, the spec phase is not an > 'afterthought'. Rather, the code can be thought of a first pass or > prototype, and the specs get me the firm up (or reevaluate) the > behavior and/or refactor my code. Bottom line -- the process is > iterative. When I do this I always comment out all the code I wrote, and write specs that let me uncomment them. This way I never stopped doing BDD, I merely had an irb session running in my app to play with ideas :) You should never ever ever leave code behind that you haven't seen is required by a spec, or you will slowly lull yourself into a false sense of security. > In the end, both approaches leave me with quality code, expressive > specs, edge test cases, and regression tests. > > Obviously I'm not speaking as a BDD priest, rather as a soldier in > the trenches. Well priests used to be allowed to fight, just only with blunt weapons :D Or a bit less opaquely, I don't think it's necessarily a Bad Thing when you don't apply every single BDD/OOP/agile principle in its textbook way. To do that in the face of Rails would involve you being side tracked into facading or rewriting large chunks of code. Coding with Rails is a bit like trying to get down a narrow corridor with a hobbling old man in front of you, who wobbles in front of you every time you try to squeeze past. The theory books didn't foresee this :) And in that sense the BDD theory doesn't apply, because BDD is supposed to make you MORE productive. When I wonder if I'm wasting time trying to get everything perfect (and I am a bit neurotic about my code, so that's my default state of mind), I ask myself: * is there any realistic thing I could change that would silently break my code? and * if I come back to this code later to change/add new features, will I spend more time understanding and refactoring it than doing the actual upgrade? If the answer is no then I feel like I've applied BDD well enough. I also liken it in my head to the tai chi saying "no shape, no form". This basically says that no matter how many years you spend doing the same training routines over and over, when you actually come to fight you use what you need, how you need to. I try and avoid saying things like this in front of people new to BDD because it could be taken (as it is with bad martial artists) to mean you don't need to spend years learning theories and good practice, and you can do what the hell you like. Well, take a look round most kung fu clubs and most tin pot development shops and you will see the exact same thing - people that believe "all that theory is a waste of time, we just do practical stuff here". I'm sure everyone on rspec-users knows what that really means. Ashley PS apparently I lied in my first line, I couldn't sum up my thoughts quickly - however an abridged version minus the vitriolic ranting is available on demand :D -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From brian.takita at gmail.com Thu Apr 24 19:59:56 2008 From: brian.takita at gmail.com (Brian Takita) Date: Thu, 24 Apr 2008 16:59:56 -0700 Subject: [rspec-users] BDD/Rails/Shoulda In-Reply-To: <7B749038-B6C8-42EE-8CAB-D92661D3C019@patchspace.co.uk> References: <51538E8C-C42A-4AE0-9CE0-25D6560E3CE6@parkerhill.com> <7B749038-B6C8-42EE-8CAB-D92661D3C019@patchspace.co.uk> Message-ID: <1d7ddd110804241659ne7701ddga476bd55cbb565b0@mail.gmail.com> On Thu, Apr 24, 2008 at 3:57 PM, Ashley Moran wrote: > Hi Matthew/Jonathan > > > On Apr 24, 2008, at 6:58 pm, Jonathan Linowes wrote: > > I'm not sure this answers your questions, but you prompted me to > > share my experience. > > And this has prompted mine... I was going to do a blow-by-blow > response to Matthew's post but I can probably sum up my current > thinking pretty quickly. > > > > Personally i consider BDD just one tool in my toolbox. > +1 > > > And I consider rspec to be as much a testing tool as a > > (BD)Development one. So I often find myself just taking the path of > > least resistance. And iterating. > > > > In some cases it really 'feels right' to write the examples first > > and then implement the code, repeat... I love doing that, the 'BDD > > way' is fun. > > +1 I think this is something to strive for, because if you get into > this rhythm you can enter BDD Flow?, and there's nothing more > productive than story-spec-code-spec-code-spec-code > story-spec-code... > > > > > But half the time, I find myself working 'the old fashioned way' - I > > write down (often with pen and paper, omg!) a list of things my code > > needs to do, I implement it, test it manually in the browser or > > console. > > I find this happens most often when I'm doing something completely > new, or have no idea what the end result should be. > > > > > After a point (not too much later though) I then go back and write > > specs that verify my code and firm up my intent. I think this is > > because Ruby and Rails can be so expressive in themselves (like the > > plugins you mentioned). I've jokingly referred to this as DDB > > (development driven behavior). > > > > Importantly, when I code first, then spec, the spec phase is not an > > 'afterthought'. Rather, the code can be thought of a first pass or > > prototype, and the specs get me the firm up (or reevaluate) the > > behavior and/or refactor my code. Bottom line -- the process is > > iterative. > > When I do this I always comment out all the code I wrote, and write > specs that let me uncomment them. This way I never stopped doing BDD, > I merely had an irb session running in my app to play with ideas :) > You should never ever ever leave code behind that you haven't seen is > required by a spec, or you will slowly lull yourself into a false > sense of security. > > > > > In the end, both approaches leave me with quality code, expressive > > specs, edge test cases, and regression tests. > > > > Obviously I'm not speaking as a BDD priest, rather as a soldier in > > the trenches. > > Well priests used to be allowed to fight, just only with blunt > weapons :D Or a bit less opaquely, I don't think it's necessarily a > Bad Thing when you don't apply every single BDD/OOP/agile principle in > its textbook way. To do that in the face of Rails would involve you > being side tracked into facading or rewriting large chunks of code. > Coding with Rails is a bit like trying to get down a narrow corridor > with a hobbling old man in front of you, who wobbles in front of you > every time you try to squeeze past. The theory books didn't foresee > this :) And in that sense the BDD theory doesn't apply, because BDD > is supposed to make you MORE productive. > > When I wonder if I'm wasting time trying to get everything perfect > (and I am a bit neurotic about my code, so that's my default state of > mind), I ask myself: > > * is there any realistic thing I could change that would silently > break my code? > and > * if I come back to this code later to change/add new features, will I > spend more time understanding and refactoring it than doing the actual > upgrade? > > If the answer is no then I feel like I've applied BDD well enough. > > I also liken it in my head to the tai chi saying "no shape, no form". > This basically says that no matter how many years you spend doing the > same training routines over and over, when you actually come to fight > you use what you need, how you need to. I try and avoid saying things > like this in front of people new to BDD because it could be taken (as > it is with bad martial artists) to mean you don't need to spend years > learning theories and good practice, and you can do what the hell you > like. Well, take a look round most kung fu clubs and most tin pot > development shops and you will see the exact same thing - people that > believe "all that theory is a waste of time, we just do practical > stuff here". I'm sure everyone on rspec-users knows what that really > means. This reminds me of Allister Cockburn's application of Shu Ha Ri in software development. http://alistair.cockburn.us/index.php/ASD_book_extract:_%22Unknowable_and_incommunicable%22 http://www.martinfowler.com/bliki/ShuHaRi.html http://c2.com/cgi/wiki?ShuHaRi > > > Ashley > > > PS apparently I lied in my first line, I couldn't sum up my thoughts > quickly - however an abridged version minus the vitriolic ranting is > available on demand :D > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Fri Apr 25 04:59:24 2008 From: lists at ruby-forum.com (James George) Date: Fri, 25 Apr 2008 10:59:24 +0200 Subject: [rspec-users] Net:SSH Message-ID: <22db52c810d3c7b7b569e35dcb2013a8@ruby-forum.com> Guys I'm having a problem with net-ssh, its kinda taking too long to execute a command and give me the results. It takes around 40 seonds to do it. And I have 3-4 commands to run on the remote box. Is there any possibility to speed up the process. Im using the commands to run on a CISCO BTS server. Is there any possibility that I cud keep channel or session open as long s i could and get the results. Each command I run depends on the result of the previous one I run. Since we have to send the exit command to get the ondata, its not helping much in speeding the whole process. Can anyone help me out there to speed this whole porcess. Thanks GUys, heres the code below : def execute_cmd(ssh_ssn, cmd_string) $cmd_rslt = "" $cmd_done = false puts "executing command: #{cmd_string} in session #{ssh_ssn}" begin ssh_ssn.open_channel do |channel| channel.on_success do puts "pty requested successfully!" channel.on_success do puts "shell started successfully!" channel.send_data cmd_string + "\n" channel.send_data "exit\n" end channel.on_data do |ch,data| #puts "rcvd #{data}" $cmd_rslt << data end channel.send_request "shell", nil, true end channel.on_failure do puts "shell could not be started!" end channel.on_close do puts "shell terminated" $cmd_done = true end channel.request_pty :want_reply => true end rescue Exception => myexp puts myexp $cmd_rslt = "" ensure $cmd_done = true end end -- Posted via http://www.ruby-forum.com/. From mhennemeyer at googlemail.com Fri Apr 25 08:50:15 2008 From: mhennemeyer at googlemail.com (Matthias Hennemeyer) Date: Fri, 25 Apr 2008 14:50:15 +0200 Subject: [rspec-users] Net:SSH In-Reply-To: <22db52c810d3c7b7b569e35dcb2013a8@ruby-forum.com> References: <22db52c810d3c7b7b569e35dcb2013a8@ruby-forum.com> Message-ID: <17C1137F-DB55-4A4C-BE55-D483A283A92F@googlemail.com> Hi James, i'm afraid this rspec user list is not the right list for your question. Matthias Am 25.04.2008 um 10:59 schrieb James George: > Guys I'm having a problem with net-ssh, its kinda taking too long to > execute a command and give me the results. It takes around 40 > seonds to > do it. And I have 3-4 commands to run on the remote box. Is there any > possibility to speed up the process. Im using the commands to run on a > CISCO BTS server. Is there any possibility that I cud keep channel or > session open as long s i could and get the results. Each command I run > depends on the result of the previous one I run. Since we have to send > the exit command to get the ondata, its not helping much in > speeding the > whole process. Can anyone help me out there to speed this whole > porcess. > > Thanks GUys, heres the code below : > > > def execute_cmd(ssh_ssn, cmd_string) > $cmd_rslt = "" > $cmd_done = false > puts "executing command: #{cmd_string} in session #{ssh_ssn}" > begin > ssh_ssn.open_channel do |channel| > > channel.on_success do > puts "pty requested successfully!" > > channel.on_success do > puts "shell started successfully!" > channel.send_data cmd_string + "\n" > channel.send_data "exit\n" > end > > channel.on_data do |ch,data| > #puts "rcvd #{data}" > $cmd_rslt << data > end > channel.send_request "shell", nil, true > end > > channel.on_failure do > puts "shell could not be started!" > end > > channel.on_close do > puts "shell terminated" > $cmd_done = true > end > > channel.request_pty :want_reply => true > end > > rescue Exception => myexp > puts myexp > $cmd_rslt = "" > ensure > $cmd_done = true > end > end > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From harm.aarts at innovationfactory.nl Fri Apr 25 08:57:14 2008 From: harm.aarts at innovationfactory.nl (Harm Aarts) Date: Fri, 25 Apr 2008 14:57:14 +0200 Subject: [rspec-users] Spec migrations? Message-ID: <59D07557-6442-4069-B1A0-2AF7ACDDE7BA@innovationfactory.nl> Dear list, I am in the process of writing on an app with is already running. I need to create a couple of structural database changes for which I use migrations. However I want to be absolutely sure I do not destroy any existing data. So RSpec is the way to go! Or so I thought. 1. dropped the test database. 2. create the database. 3. migrate to the version just before the critical migration 4. insert some stuff in the database 5. run the critical migration 6. see if the result is as I expected But I receive the following error: Mysql::Error: #HY000Lock wait timeout exceeded; try restarting transaction: ALTER TABLE `members` DROP `manager` And I do not know if this is the way forward. Does any one have any (relevant) thoughts on this? With kind regards, Harm PS the actual spec: describe Member, "should migrate properly" do it "should migrate correctly from a column manager to a role manager" do `rake db:drop` `rake db:create` `rake db:migrate VERSION=59` m1 = Member.new(:manager => true) m1.save_with_validation(false) m2 = Member.new(:manager => true) m2.save_with_validation(false) m3 = Member.new(:manager => true) m3.save_with_validation(false) `rake db:migrate VERSION=60` Member.find(m1.id).has_role?("manager").should be_true Member.find(m2.id).has_role?("manager").should be_true Member.find(m3.id).has_role?("manager").should be_true end end From tmhaines at gmail.com Fri Apr 25 10:46:18 2008 From: tmhaines at gmail.com (Tim Haines) Date: Fri, 25 Apr 2008 23:46:18 +0900 Subject: [rspec-users] Rspec output and unicode Message-ID: Hey there, Rspec output (1.1.3) doesn't seem to be handling unicode characters correctly. I'm expecting to see Japanese katakana (on winXP) and I'm getting numbers instead - the byte representation of the katakana or something.. Should it be producing unicode if I have my environment set right? Cheers, Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: From olivierdupuis at gmail.com Fri Apr 25 15:16:55 2008 From: olivierdupuis at gmail.com (Olivier Dupuis) Date: Fri, 25 Apr 2008 15:16:55 -0400 Subject: [rspec-users] Running spec_server Message-ID: <745312bd0804251216v2f8ca60dvff36297d92b12602@mail.gmail.com> Hello, I've been using rspec for a while now and just noticed spec_server. I would like to use it, but for some reason, it's not able to start. I have the latest versions of rspec and rspec_on_rails. I'm using WinXp. The specific error I get is the following: script/spec_server:9: undefined method '+' for nil:NilClass (NoMethodError) Any ideas? Thank you Olivier Dupuis -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Fri Apr 25 16:25:17 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 25 Apr 2008 16:25:17 -0400 Subject: [rspec-users] Spec the Application Controller application.rb In-Reply-To: <0b50219a76dff452d27725113fabf0d8@ruby-forum.com> References: <60d89ebca7081d20567f3aa4724a373b@ruby-forum.com> <810a540e0804211406n4fd10bb5g17085b5111bca63@mail.gmail.com> <810a540e0804222336y381d9c09p53417f9e806b09c3@mail.gmail.com> <0b50219a76dff452d27725113fabf0d8@ruby-forum.com> Message-ID: <85d99afe0804251325l6256f8e1lcd9095876135ee9a@mail.gmail.com> Do this... after do eval IO.read(RAILS_ROOT + "/config/routes.rb") end Zach On Thu, Apr 24, 2008 at 2:20 AM, Andy Croll wrote: > This bit however, replaces your other routes, so you cannot use them in > your tests > > > before(:each) do > > ActionController::Routing::Routes.draw do |map| > > map.resources :foo > > end > > end > > Is there a sensible way to append to the routes.rb that I'm missing? > > Andy > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashley.moran at patchspace.co.uk Fri Apr 25 17:50:18 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 25 Apr 2008 22:50:18 +0100 Subject: [rspec-users] BDD/Rails/Shoulda In-Reply-To: <1d7ddd110804241659ne7701ddga476bd55cbb565b0@mail.gmail.com> References: <51538E8C-C42A-4AE0-9CE0-25D6560E3CE6@parkerhill.com> <7B749038-B6C8-42EE-8CAB-D92661D3C019@patchspace.co.uk> <1d7ddd110804241659ne7701ddga476bd55cbb565b0@mail.gmail.com> Message-ID: On 25 Apr 2008, at 00:59, Brian Takita wrote: > This reminds me of Allister Cockburn's application of Shu Ha Ri in > software development. > http://alistair.cockburn.us/index.php/ASD_book_extract:_%22Unknowable_and_incommunicable%22 > http://www.martinfowler.com/bliki/ShuHaRi.html > http://c2.com/cgi/wiki?ShuHaRi Hadn't seen that before. I've only studied chinese arts so hadn't heard the expression before, the idea is the same though. Thanks for the links, the first one especially looks really interesting Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From adam at heroku.com Fri Apr 25 23:34:50 2008 From: adam at heroku.com (Adam Wiggins) Date: Fri, 25 Apr 2008 20:34:50 -0700 Subject: [rspec-users] restful controllers with different content types Message-ID: Simplified example of a controller which takes a POST with a non-xml and non-form-urlencoded content type: class PhotosController < ApplicationController def create Photo.create :binary_data => request.body.read, :content_type => 'image/jpg' head :ok end end How can I spec this? The way that I'd like to do it would be something like: it "creates a new photo from a posted image file" do Photo.should_receive(:create).with(:binary_data => 'the data', :content_type => 'image/jpg') post :create, :body => 'the data' end Adam From mailing_lists at railsnewbie.com Sat Apr 26 00:15:43 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 26 Apr 2008 00:15:43 -0400 Subject: [rspec-users] Running spec_server In-Reply-To: <745312bd0804251216v2f8ca60dvff36297d92b12602@mail.gmail.com> References: <745312bd0804251216v2f8ca60dvff36297d92b12602@mail.gmail.com> Message-ID: <50636E05-A1A1-426B-92A9-56737A67876F@railsnewbie.com> On Apr 25, 2008, at 3:16 PM, Olivier Dupuis wrote: > Hello, > > I've been using rspec for a while now and just noticed spec_server. > I would like to use it, but for some reason, it's not able to start. > > I have the latest versions of rspec and rspec_on_rails. I'm using > WinXp. > > The specific error I get is the following: > > script/spec_server:9: undefined method '+' for nil:NilClass > (NoMethodError) Have you tried running script/generate rspec ? What version of rspec/rspec_on_rails are you using? Scott From dchelimsky at gmail.com Sat Apr 26 04:33:06 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 26 Apr 2008 04:33:06 -0400 Subject: [rspec-users] restful controllers with different content types In-Reply-To: References: Message-ID: <6D68F55F-FA92-4609-823A-DF91C38A709E@gmail.com> On Apr 25, 2008, at 11:34 PM, "Adam Wiggins" wrote: > Simplified example of a controller which takes a POST with a non-xml > and non-form-urlencoded content type: > > class PhotosController < ApplicationController > def create > Photo.create :binary_data => request.body.read, :content_type => > 'image/jpg' > head :ok > end > end > > How can I spec this? The way that I'd like to do it would be > something like: > > it "creates a new photo from a posted image file" do > Photo.should_receive(:create).with(:binary_data => 'the data', > :content_type => 'image/jpg') > post :create, :body => 'the data' > end What happens when you try this? From shintaro.kakutani at gmail.com Sat Apr 26 12:19:40 2008 From: shintaro.kakutani at gmail.com (KAKUTANI Shintaro) Date: Sun, 27 Apr 2008 01:19:40 +0900 Subject: [rspec-users] Rspec output and unicode In-Reply-To: References: Message-ID: <7b4f11a30804260919o2db30188t184c31f1170c7e8c@mail.gmail.com> Hi, My environment, OS X Tiger, handles utf-8 katakana corrrectly w/ RSpec 1.1.3. Try following step If your're using DOS prompt: 1. Change Font to 'MS Gothic' on DOS prompt. 2. run command: "chcp 65001" 3. that's it. see also) http://www.mogya.com/blog/2007/11/utf8.html On Fri, Apr 25, 2008 at 11:46 PM, Tim Haines wrote: > Hey there, > > Rspec output (1.1.3) doesn't seem to be handling unicode characters > correctly. I'm expecting to see Japanese katakana (on winXP) and I'm > getting numbers instead - the byte representation of the katakana or > something.. > > Should it be producing unicode if I have my environment set right? > > Cheers, > > Tim. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- KAKUTANI Shintaro shintaro.kakutani at gmail.com From jacob.basham at gmail.com Sat Apr 26 14:39:10 2008 From: jacob.basham at gmail.com (Jacob) Date: Sat, 26 Apr 2008 11:39:10 -0700 (PDT) Subject: [rspec-users] Error testing rails controller In-Reply-To: <57c63afe0804071214h799eb3a5t363d83e2190bdeea@mail.gmail.com> References: <57c63afe0804071214h799eb3a5t363d83e2190bdeea@mail.gmail.com> Message-ID: <7a9f83f5-a31c-46b8-9cbf-cd38b06cde22@f36g2000hsa.googlegroups.com> It actually turned out to an invalid syntax in my controller, completely unrelated. Guess thats what I get for not checking my syntax before diving in. On Apr 7, 2:14?pm, "David Chelimsky" wrote: > On Fri, Apr 4, 2008 at 12:46 PM, Jacob wrote: > > I am trying to test my controllers with RSpec and from the examples I > > ?have found it is as easy as this: > > > ?describe SessionsController do > > > ? it "should render login template" do > > ? ? get 'new' > > ? ? response.should render_template(:login) > > ? end > > Try 'login'. > > > > > ?end > > > ?However both get and post raise "wrong number of arguments (2 for 1)". > > ?I am working with 1.1.3, I rolled back to 1.1.2 and still suffer the > > ?same fate. Any thoughts onto what may be causing this issue? > > > ?Thanks > > ?_______________________________________________ > > ?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 adam at heroku.com Sat Apr 26 18:35:09 2008 From: adam at heroku.com (Adam Wiggins) Date: Sat, 26 Apr 2008 15:35:09 -0700 Subject: [rspec-users] restful controllers with different content types In-Reply-To: <6D68F55F-FA92-4609-823A-DF91C38A709E@gmail.com> References: <6D68F55F-FA92-4609-823A-DF91C38A709E@gmail.com> Message-ID: On Sat, Apr 26, 2008 at 1:33 AM, David Chelimsky wrote: > On Apr 25, 2008, at 11:34 PM, "Adam Wiggins" wrote: > > it "creates a new photo from a posted image file" do > > Photo.should_receive(:create).with(:binary_data => 'the data', > > :content_type => 'image/jpg') > > post :create, :body => 'the data' > > end > > What happens when you try this? It treats :body as a regular urlencoded parameter. i.e., the body of the POST sent through to the controller is "body=the+data", when I want it to be "the data". There's the matter of content-type too; I left that out in hopes if simplifying the question. The more complete version might be: post :create, :content_type => 'image/jpg', :body => 'the data' But :content_type and :body are not treated as special parameters, so I was wondering if there is some other mechanism for doing this. Adam From tmhaines at gmail.com Sat Apr 26 20:23:41 2008 From: tmhaines at gmail.com (Tim Haines) Date: Sun, 27 Apr 2008 09:23:41 +0900 Subject: [rspec-users] Rspec output and unicode In-Reply-To: <7b4f11a30804260919o2db30188t184c31f1170c7e8c@mail.gmail.com> References: <7b4f11a30804260919o2db30188t184c31f1170c7e8c@mail.gmail.com> Message-ID: konichiwa Shintaro, Thank you for the suggestion. I've just tried it (on win xp English edition) and sadly it didn't work. I guess it's not too important - just a nice to have.. Tim. On Sun, Apr 27, 2008 at 1:19 AM, KAKUTANI Shintaro < shintaro.kakutani at gmail.com> wrote: > Hi, > > My environment, OS X Tiger, handles utf-8 katakana corrrectly w/ RSpec > 1.1.3. > Try following step If your're using DOS prompt: > > 1. Change Font to 'MS Gothic' on DOS prompt. > 2. run command: "chcp 65001" > 3. that's it. > see also) http://www.mogya.com/blog/2007/11/utf8.html > > On Fri, Apr 25, 2008 at 11:46 PM, Tim Haines wrote: > > Hey there, > > > > Rspec output (1.1.3) doesn't seem to be handling unicode characters > > correctly. I'm expecting to see Japanese katakana (on winXP) and I'm > > getting numbers instead - the byte representation of the katakana or > > something.. > > > > Should it be producing unicode if I have my environment set right? > > > > Cheers, > > > > Tim. > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > KAKUTANI Shintaro > shintaro.kakutani at gmail.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: From tastapod at gmail.com Sun Apr 27 09:05:53 2008 From: tastapod at gmail.com (Dan North) Date: Sun, 27 Apr 2008 14:05:53 +0100 Subject: [rspec-users] BDD/Rails/Shoulda In-Reply-To: References: Message-ID: Hi Matthew. I don't think it's off-topic at all. I would estimate around 80% of the traffic on this list is about "how do I test such-and-such with rails?". Rails is designed for a particular subset of web applications, namely ones that look a lot like basecamp. They mostly involve capturing, updating or presenting data, in a very two-tier, database-on-the-screen kind of way. The giveaway is having ActiveRecord as the persistence layer. The other clue is in the fact that you have to define a database before you can fire it up and get the "you're on rails" welcome page. All the examples and tutorials I've seen (outside of the rspec world) start by defining database tables and their corresponding ActiveRecord classes, and then building up the application from there. I describe these applications as being mostly surface area (i.e. front end and back end), with very little volume (i.e. interesting behaviour other than CRUD and presentation). Now don't get me wrong, you can do a lot with these kinds of applications, and they are incredibly useful. In fact most "enterprise" applications are simply variations on this theme. But the rails stack simply isn't geared up for outside-in development, or, I would venture to say, for many of the applications it is being targeted at. I presented rspec and rails in a session with David Chelimsky and Aslak at last year's RailsConf Europe and I was amazed at how brilliantly David and Aslak had beaten rails into submission in order to present an outside-in, view-first approach to developing an application. I would never have thought of the approach they came up with - I would have given up in despair long before that! The tight coupling between the domain object classes and the persistence mechanism means you either have to mock domain objects - which simply doesn't make any sense for anaemic data-only objects - or couple every example to your database, and life's too short to have a 30 minute build for a web app. So now you have one of two options. Firsly, you can accept that rails is designed for large surface area applications, and be prepared to compromise on testability and the ability to do outside-in development. The other is to use a different ruby web stack such as ramaze (http://ramaze.net) which allows you to start at the outside and work inwards, evolving separate views, controllers and models as you need to (and only when you need to). Side note: I just noticed that when you run ramaze --create blah, you get a spec directory with some simple "GET / should return 200" specs. And not a database in sight. Sweet! Cheers, Dan ps. I'll be turning this into a longer and more detailed rant on my blog soon :) 2008/4/24 Matthew Lins : > This is a little off topic, but I use rSpec and I'm starting to question > the quality of my specs. In my research and attempt to learn how to write > better specs, I've came across a few things that I'd like to discuss. > > I'm having more and more difficulty understanding BDD. The more I read > and the more I watch, the more questions I come up with. Let me just ask a > couple of general questions to start this off. > > Is 'shoulda' actually following the principals of BDD? But, I guess > that's not really a good question. Is 'shoulda' encouraging it's users to > follow the principals of BDD? I see all of the macros like: > > should_belong_to > > should_require_attributes > > To me, that is not BDD. Basically that's just testing whether or not your > model contains a certain code fragment. But, that brings me to my next > question. > > Is BDD even possible with Rails? (I think it is, but I ask myself that > more and more lately) > > I just picked a random model in the application I'm currently working on. > The 'Picture' model. I use the attachment_fu plugin, which helps this > model handle pictures (it creates thumbnails, validates sizes, etc.) I > wiped out all the code I had and all the specs I had. I started from > scratch: > > ---------------------------------- > > class Picture < ActiveRecord::Base > > end > > ---------------------------------- > > The first piece of code I would write if I *wasn't* using BDD, would be: > > > ---------------------------------- > > class Picture < ActiveRecord::Base > > validates_as_attachment > > end > > ---------------------------------- > > Which basically handles all of my validation. So, from a BDD perspective, > how do I spec that? I know, I know, I should be writing the specs first. > But, what do I do about these helpers that come with plugins. Do I write a > spec: > > ---------------------------------- > > describe Picture, 'with a blank filename' do > > before(:each) do > @picture = Picture.new valid_picture_attributes.except(:filename) # > This uses some rSpec helpers > end > > it do > @picture.should_not be_valid > end > > end > > ----------------------------------- > > So, the most simple way to solve that would be (this is part of what > 'validates_as_attachment' does): > > ---------------------------------- > > class Picture < ActiveRecord::Base > > validates_presence_of :filename > > end > > ---------------------------------- > > But, now what, I'm going to reverse engineer this plugin's helper? I'll > just spec it all out and eventually refactor and put the > 'validates_as_attachment' back? Or, maybe since this is a plugins helper I > don't even need to test any of this. It's the author of the plugin's > responsibility. This is were my brain enters an infinite loop (one example > anyway, hehe). I just can't seem to nail down the workflow when specing > rails apps. I also have a hard time determining what to spec. > > I know I asked a lot of questions, but basically I'm just trying to find > out if people are actually following the BDD principals strictly when > writing Rails apps. If you are can you give me some insight in the above > example? > > Thanks, > > Matt Lins > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From helder at gmail.com Sun Apr 27 13:42:59 2008 From: helder at gmail.com (Helder Ribeiro) Date: Sun, 27 Apr 2008 14:42:59 -0300 Subject: [rspec-users] BDD/Rails/Shoulda In-Reply-To: References: Message-ID: <9bb72e130804271042n549796b7n6fdaebd839817dc7@mail.gmail.com> On Sun, Apr 27, 2008 at 10:05 AM, Dan North wrote: > Hi Matthew. > > I don't think it's off-topic at all. I would estimate around 80% of the > traffic on this list is about "how do I test such-and-such with rails?". > > Rails is designed for a particular subset of web applications, namely ones > that look a lot like basecamp. They mostly involve capturing, updating or > presenting data, in a very two-tier, database-on-the-screen kind of way. The > giveaway is having ActiveRecord as the persistence layer. The other clue is > in the fact that you have to define a database before you can fire it up and > get the "you're on rails" welcome page. All the examples and tutorials I've > seen (outside of the rspec world) start by defining database tables and > their corresponding ActiveRecord classes, and then building up the > application from there. > > I describe these applications as being mostly surface area (i.e. front end > and back end), with very little volume (i.e. interesting behaviour other > than CRUD and presentation). Now don't get me wrong, you can do a lot with > these kinds of applications, and they are incredibly useful. In fact most > "enterprise" applications are simply variations on this theme. But the rails > stack simply isn't geared up for outside-in development, or, I would venture > to say, for many of the applications it is being targeted at. > > I presented rspec and rails in a session with David Chelimsky and Aslak at > last year's RailsConf Europe and I was amazed at how brilliantly David and > Aslak had beaten rails into submission in order to present an outside-in, > view-first approach to developing an application. I would never have thought > of the approach they came up with - I would have given up in despair long > before that! > > The tight coupling between the domain object classes and the persistence > mechanism means you either have to mock domain objects - which simply > doesn't make any sense for anaemic data-only objects - or couple every > example to your database, and life's too short to have a 30 minute build for > a web app. > > So now you have one of two options. Firsly, you can accept that rails is > designed for large surface area applications, and be prepared to compromise > on testability and the ability to do outside-in development. The other is to > use a different ruby web stack such as ramaze (http://ramaze.net) which > allows you to start at the outside and work inwards, evolving separate > views, controllers and models as you need to (and only when you need to). > Side note: I just noticed that when you run ramaze --create blah, you get a > spec directory with some simple "GET / should return 200" specs. And not a > database in sight. Sweet! > > Cheers, > Dan > > ps. I'll be turning this into a longer and more detailed rant on my blog > soon :) Please do. I'd especially like to know more about outside-in style you mentioned. Rails is my first experience with web development and I don't have a good intuitive notion of what that different approach would be. Send me (us?) the link when it's done :) Cheers, Helder > > > 2008/4/24 Matthew Lins : > > > > > > > This is a little off topic, but I use rSpec and I'm starting to question > the quality of my specs. In my research and attempt to learn how to write > better specs, I've came across a few things that I'd like to discuss. > > > > I'm having more and more difficulty understanding BDD. The more I read > and the more I watch, the more questions I come up with. Let me just ask a > couple of general questions to start this off. > > > > Is 'shoulda' actually following the principals of BDD? But, I guess > that's not really a good question. Is 'shoulda' encouraging it's users to > follow the principals of BDD? I see all of the macros like: > > > > should_belong_to > > > > should_require_attributes > > > > To me, that is not BDD. Basically that's just testing whether or not your > model contains a certain code fragment. But, that brings me to my next > question. > > > > Is BDD even possible with Rails? (I think it is, but I ask myself that > more and more lately) > > > > I just picked a random model in the application I'm currently working on. > The 'Picture' model. I use the attachment_fu plugin, which helps this model > handle pictures (it creates thumbnails, validates sizes, etc.) I wiped out > all the code I had and all the specs I had. I started from scratch: > > > > > > ---------------------------------- > > > > class Picture < ActiveRecord::Base > > > > end > > > > ---------------------------------- > > > > The first piece of code I would write if I wasn't using BDD, would be: > > > > > > ---------------------------------- > > > > class Picture < ActiveRecord::Base > > > > validates_as_attachment > > > > end > > > > ---------------------------------- > > > > Which basically handles all of my validation. So, from a BDD perspective, > how do I spec that? I know, I know, I should be writing the specs first. > But, what do I do about these helpers that come with plugins. Do I write a > spec: > > > > ---------------------------------- > > > > describe Picture, 'with a blank filename' do > > > > before(:each) do > > @picture = Picture.new valid_picture_attributes.except(:filename) # > This uses some rSpec helpers > > end > > > > it do > > @picture.should_not be_valid > > end > > > > end > > > > ----------------------------------- > > > > So, the most simple way to solve that would be (this is part of what > 'validates_as_attachment' does): > > > > ---------------------------------- > > > > class Picture < ActiveRecord::Base > > > > validates_presence_of :filename > > > > end > > > > ---------------------------------- > > > > But, now what, I'm going to reverse engineer this plugin's helper? I'll > just spec it all out and eventually refactor and put the > 'validates_as_attachment' back? Or, maybe since this is a plugins helper I > don't even need to test any of this. It's the author of the plugin's > responsibility. This is were my brain enters an infinite loop (one example > anyway, hehe). I just can't seem to nail down the workflow when specing > rails apps. I also have a hard time determining what to spec. > > > > I know I asked a lot of questions, but basically I'm just trying to find > out if people are actually following the BDD principals strictly when > writing Rails apps. If you are can you give me some insight in the above > example? > > > > Thanks, > > > > Matt Lins > > > > _______________________________________________ > > > > 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 > -- "If I have not seen as far as others, it is because giants were standing on my shoulders" -- Jeff Goll From dchelimsky at gmail.com Mon Apr 28 02:17:17 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 28 Apr 2008 01:17:17 -0500 Subject: [rspec-users] BDD/Rails/Shoulda In-Reply-To: <7B749038-B6C8-42EE-8CAB-D92661D3C019@patchspace.co.uk> References: <51538E8C-C42A-4AE0-9CE0-25D6560E3CE6@parkerhill.com> <7B749038-B6C8-42EE-8CAB-D92661D3C019@patchspace.co.uk> Message-ID: <04414D52-7044-4CC5-88AB-89F06FF57DE8@gmail.com> On Apr 24, 2008, at 5:57 PM, Ashley Moran wrote: > Hi Matthew/Jonathan > > On Apr 24, 2008, at 6:58 pm, Jonathan Linowes wrote: >> I'm not sure this answers your questions, but you prompted me to >> share my experience. > > And this has prompted mine... I was going to do a blow-by-blow > response to Matthew's post but I can probably sum up my current > thinking pretty quickly. > >> Personally i consider BDD just one tool in my toolbox. > +1 >> And I consider rspec to be as much a testing tool as a >> (BD)Development one. So I often find myself just taking the path of >> least resistance. And iterating. >> >> In some cases it really 'feels right' to write the examples first >> and then implement the code, repeat... I love doing that, the 'BDD >> way' is fun. > > +1 I think this is something to strive for, because if you get into > this rhythm you can enter BDD Flow?, and there's nothing more > productive than story-spec-code-spec-code-spec-code > story-spec-code... > > >> But half the time, I find myself working 'the old fashioned way' - I >> write down (often with pen and paper, omg!) a list of things my code >> needs to do, I implement it, test it manually in the browser or >> console. > > I find this happens most often when I'm doing something completely > new, or have no idea what the end result should be. > > >> After a point (not too much later though) I then go back and write >> specs that verify my code and firm up my intent. I think this is >> because Ruby and Rails can be so expressive in themselves (like the >> plugins you mentioned). I've jokingly referred to this as DDB >> (development driven behavior). >> >> Importantly, when I code first, then spec, the spec phase is not an >> 'afterthought'. Rather, the code can be thought of a first pass or >> prototype, and the specs get me the firm up (or reevaluate) the >> behavior and/or refactor my code. Bottom line -- the process is >> iterative. > > When I do this I always comment out all the code I wrote, and write > specs that let me uncomment them. This way I never stopped doing BDD, > I merely had an irb session running in my app to play with ideas :) TDD purists will tell you to delete the prototype code and start over once you've learned what you need to from the process of prototyping. One of the amazing benefits of TDD is that you generally end up with better APIs than you do backfilling tests against existing code. Commented prototype code is still code that was created before the tests and looses that benefit. Also, this approach increases the level of granularity from individual messages to complete statements. For example, let's say I have this line commented: # do_something if this_condition and that_condition If this_condition and that_condition always return the same boolean value, there is no need for a test for that_condition to exist. Nor should it exist without having been driven into existence by an example. So the approach of uncommenting prototype code still leaves you with code that is less clean, if only slightly, than code which is purely driven out by examples. Cheers, David > > You should never ever ever leave code behind that you haven't seen is > required by a spec, or you will slowly lull yourself into a false > sense of security. > > >> In the end, both approaches leave me with quality code, expressive >> specs, edge test cases, and regression tests. >> >> Obviously I'm not speaking as a BDD priest, rather as a soldier in >> the trenches. > > Well priests used to be allowed to fight, just only with blunt > weapons :D Or a bit less opaquely, I don't think it's necessarily a > Bad Thing when you don't apply every single BDD/OOP/agile principle in > its textbook way. To do that in the face of Rails would involve you > being side tracked into facading or rewriting large chunks of code. > Coding with Rails is a bit like trying to get down a narrow corridor > with a hobbling old man in front of you, who wobbles in front of you > every time you try to squeeze past. The theory books didn't foresee > this :) And in that sense the BDD theory doesn't apply, because BDD > is supposed to make you MORE productive. > > When I wonder if I'm wasting time trying to get everything perfect > (and I am a bit neurotic about my code, so that's my default state of > mind), I ask myself: > > * is there any realistic thing I could change that would silently > break my code? > and > * if I come back to this code later to change/add new features, will I > spend more time understanding and refactoring it than doing the actual > upgrade? > > If the answer is no then I feel like I've applied BDD well enough. > > I also liken it in my head to the tai chi saying "no shape, no form". > This basically says that no matter how many years you spend doing the > same training routines over and over, when you actually come to fight > you use what you need, how you need to. I try and avoid saying things > like this in front of people new to BDD because it could be taken (as > it is with bad martial artists) to mean you don't need to spend years > learning theories and good practice, and you can do what the hell you > like. Well, take a look round most kung fu clubs and most tin pot > development shops and you will see the exact same thing - people that > believe "all that theory is a waste of time, we just do practical > stuff here". I'm sure everyone on rspec-users knows what that really > means. > > > Ashley > > > PS apparently I lied in my first line, I couldn't sum up my thoughts > quickly - however an abridged version minus the vitriolic ranting is > available on demand :D > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ From dchelimsky at gmail.com Mon Apr 28 08:37:26 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 28 Apr 2008 07:37:26 -0500 Subject: [rspec-users] article on template for stories Message-ID: <6148CE91-029D-402D-8CC5-6FBB76042030@gmail.com> Mike Cohn just wrote a nice post justifying what has become the preferred template for stories in BDD: As a [ role ] I want [ feature ] So that [ benefit ] http://blog.mountaingoatsoftware.com/?p=24 From mattlins at gmail.com Mon Apr 28 08:49:06 2008 From: mattlins at gmail.com (Matthew Lins) Date: Mon, 28 Apr 2008 07:49:06 -0500 Subject: [rspec-users] BDD/Rails/Shoulda In-Reply-To: <04414D52-7044-4CC5-88AB-89F06FF57DE8@gmail.com> Message-ID: Thanks for all of the great replies! This thread answered a lot of my questions. -Matt > From: David Chelimsky > Reply-To: rspec-users > Date: Mon, 28 Apr 2008 01:17:17 -0500 > To: rspec-users > Subject: Re: [rspec-users] BDD/Rails/Shoulda > > > On Apr 24, 2008, at 5:57 PM, Ashley Moran wrote: > >> Hi Matthew/Jonathan >> >> On Apr 24, 2008, at 6:58 pm, Jonathan Linowes wrote: >>> I'm not sure this answers your questions, but you prompted me to >>> share my experience. >> >> And this has prompted mine... I was going to do a blow-by-blow >> response to Matthew's post but I can probably sum up my current >> thinking pretty quickly. >> >>> Personally i consider BDD just one tool in my toolbox. >> +1 >>> And I consider rspec to be as much a testing tool as a >>> (BD)Development one. So I often find myself just taking the path of >>> least resistance. And iterating. >>> >>> In some cases it really 'feels right' to write the examples first >>> and then implement the code, repeat... I love doing that, the 'BDD >>> way' is fun. >> >> +1 I think this is something to strive for, because if you get into >> this rhythm you can enter BDD Flow?, and there's nothing more >> productive than story-spec-code-spec-code-spec-code >> story-spec-code... >> >> >>> But half the time, I find myself working 'the old fashioned way' - I >>> write down (often with pen and paper, omg!) a list of things my code >>> needs to do, I implement it, test it manually in the browser or >>> console. >> >> I find this happens most often when I'm doing something completely >> new, or have no idea what the end result should be. >> >> >>> After a point (not too much later though) I then go back and write >>> specs that verify my code and firm up my intent. I think this is >>> because Ruby and Rails can be so expressive in themselves (like the >>> plugins you mentioned). I've jokingly referred to this as DDB >>> (development driven behavior). >>> >>> Importantly, when I code first, then spec, the spec phase is not an >>> 'afterthought'. Rather, the code can be thought of a first pass or >>> prototype, and the specs get me the firm up (or reevaluate) the >>> behavior and/or refactor my code. Bottom line -- the process is >>> iterative. >> >> When I do this I always comment out all the code I wrote, and write >> specs that let me uncomment them. This way I never stopped doing BDD, >> I merely had an irb session running in my app to play with ideas :) > > TDD purists will tell you to delete the prototype code and start over > once you've learned what you need to from the process of prototyping. > One of the amazing benefits of TDD is that you generally end up with > better APIs than you do backfilling tests against existing code. > Commented prototype code is still code that was created before the > tests and looses that benefit. > > Also, this approach increases the level of granularity from individual > messages to complete statements. For example, let's say I have this > line commented: > > # do_something if this_condition and that_condition > > If this_condition and that_condition always return the same boolean > value, there is no need for a test for that_condition to exist. Nor > should it exist without having been driven into existence by an example. > > So the approach of uncommenting prototype code still leaves you with > code that is less clean, if only slightly, than code which is purely > driven out by examples. > > Cheers, > David > >> >> You should never ever ever leave code behind that you haven't seen is >> required by a spec, or you will slowly lull yourself into a false >> sense of security. >> >> >>> In the end, both approaches leave me with quality code, expressive >>> specs, edge test cases, and regression tests. >>> >>> Obviously I'm not speaking as a BDD priest, rather as a soldier in >>> the trenches. >> >> Well priests used to be allowed to fight, just only with blunt >> weapons :D Or a bit less opaquely, I don't think it's necessarily a >> Bad Thing when you don't apply every single BDD/OOP/agile principle in >> its textbook way. To do that in the face of Rails would involve you >> being side tracked into facading or rewriting large chunks of code. >> Coding with Rails is a bit like trying to get down a narrow corridor >> with a hobbling old man in front of you, who wobbles in front of you >> every time you try to squeeze past. The theory books didn't foresee >> this :) And in that sense the BDD theory doesn't apply, because BDD >> is supposed to make you MORE productive. >> >> When I wonder if I'm wasting time trying to get everything perfect >> (and I am a bit neurotic about my code, so that's my default state of >> mind), I ask myself: >> >> * is there any realistic thing I could change that would silently >> break my code? >> and >> * if I come back to this code later to change/add new features, will I >> spend more time understanding and refactoring it than doing the actual >> upgrade? >> >> If the answer is no then I feel like I've applied BDD well enough. >> >> I also liken it in my head to the tai chi saying "no shape, no form". >> This basically says that no matter how many years you spend doing the >> same training routines over and over, when you actually come to fight >> you use what you need, how you need to. I try and avoid saying things >> like this in front of people new to BDD because it could be taken (as >> it is with bad martial artists) to mean you don't need to spend years >> learning theories and good practice, and you can do what the hell you >> like. Well, take a look round most kung fu clubs and most tin pot >> development shops and you will see the exact same thing - people that >> believe "all that theory is a waste of time, we just do practical >> stuff here". I'm sure everyone on rspec-users knows what that really >> means. >> >> >> Ashley >> >> >> PS apparently I lied in my first line, I couldn't sum up my thoughts >> quickly - however an abridged version minus the vitriolic ranting is >> available on demand :D >> >> -- >> http://www.patchspace.co.uk/ >> http://aviewfromafar.net/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From shingler at gmail.com Mon Apr 28 11:31:21 2008 From: shingler at gmail.com (steven shingler) Date: Mon, 28 Apr 2008 16:31:21 +0100 Subject: [rspec-users] story runner on restful_authentication question Message-ID: Hi all, Have been following: http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app ..as an introduction into the story runner. It shows how to get a couple of scenarios going to test the restful_authenticated plugin from plain text stories. I thought I'd go completely bonkers and try and add a story of my own :) Scenario: Registered user logs in Given a username 'jdoe' And a password 'letmein' And an existing user with these credentials When the user logs in with username and password Then should redirect to '/' And I added these steps to try and make this pass: Given "an existing user with these credentials" do @user = User.new({ :login => @username, :password => @password, :password_confirmation => @password, :email => "jdoe at test.comm" }) @user.save User.find_by_login(@username).should_not be_nil end When "the user logs in with username and password" do post "/sessions/create", :user => { :login => @username, :password => @password } end Then "should redirect to '$path'" do |path| response.should redirect_to(path) end However, I'm getting a Spec::Expectations::ExpectationNotMetError: expected redirect to "/", got no redirect So the user is definitely being created in the test database, but the login doesn't seem to work, or to do the redirect. I must be doing something silly. If anyone could point me in the right direction, I'd be very grateful. Thanks very much, Steven From olivierdupuis at gmail.com Mon Apr 28 11:42:42 2008 From: olivierdupuis at gmail.com (Olivier Dupuis) Date: Mon, 28 Apr 2008 11:42:42 -0400 Subject: [rspec-users] Running spec_server In-Reply-To: <50636E05-A1A1-426B-92A9-56737A67876F@railsnewbie.com> References: <745312bd0804251216v2f8ca60dvff36297d92b12602@mail.gmail.com> <50636E05-A1A1-426B-92A9-56737A67876F@railsnewbie.com> Message-ID: <745312bd0804280842g2d8189f5m5414be6f6ca6cc99@mail.gmail.com> Hi Scott, I'm having no trouble running script/generate rspec. I'm using the CURRENT version of rspec and rspec_on_rails. I just reinstalled them last week. Any idea what could be causing this? Thank you Olivier Dupuis On Sat, Apr 26, 2008 at 12:15 AM, Scott Taylor < mailing_lists at railsnewbie.com> wrote: > > On Apr 25, 2008, at 3:16 PM, Olivier Dupuis wrote: > > Hello, > > > > I've been using rspec for a while now and just noticed spec_server. I > > would like to use it, but for some reason, it's not able to start. > > > > I have the latest versions of rspec and rspec_on_rails. I'm using > > WinXp. > > > > The specific error I get is the following: > > > > script/spec_server:9: undefined method '+' for nil:NilClass > > (NoMethodError) > > > > Have you tried running script/generate rspec ? > > What version of rspec/rspec_on_rails are you using? > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Mon Apr 28 12:10:00 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 28 Apr 2008 09:10:00 -0700 Subject: [rspec-users] story runner on restful_authentication question In-Reply-To: References: Message-ID: <810a540e0804280910jb6530a0x75615e8d0cfdeb03@mail.gmail.com> On Mon, Apr 28, 2008 at 8:31 AM, steven shingler wrote: > However, I'm getting a > Spec::Expectations::ExpectationNotMetError: expected redirect to "/", > got no redirect Often when this happens, it's because an error occurs in the request. You can tail test.log to see if there are any exceptions being thrown. My initial guess is that your request needs to be post "/sessions" instead of post "/sessions/create" Pat From andywatts at yahoo.com Mon Apr 28 15:51:19 2008 From: andywatts at yahoo.com (Andy Watts) Date: Mon, 28 Apr 2008 12:51:19 -0700 (PDT) Subject: [rspec-users] story runner on restful_authentication question In-Reply-To: References: Message-ID: <16945873.post@talk.nabble.com> Assuming there's nothing helpful in test.log.. Adding 'debugger' to the misfiring steps may help troubleshoot this.. You'll prolly need to add the following to your helper.rb first. require 'rubygems' require 'ruby-debug' Re-run the story and it should stop at the debugger. Between manually submitting requests and inspecting test.log you should get further. - Andy -- View this message in context: http://www.nabble.com/story-runner-on-restful_authentication-question-tp16941586p16945873.html Sent from the rspec-users mailing list archive at Nabble.com. From rubyphunk at googlemail.com Mon Apr 28 15:51:24 2008 From: rubyphunk at googlemail.com (rubyphunk) Date: Mon, 28 Apr 2008 12:51:24 -0700 (PDT) Subject: [rspec-users] ANN: RSpactor 0.9.10 (aka. beta) Message-ID: <88061a1b-5f4e-4976-b1d0-86be1c2440b2@y38g2000hsy.googlegroups.com> Hey all. I've just release a first preview/beta of the upcoming RSpactor.app; a spec runner for Mac OS X Leopard. This is just some kind of test version and I'm looking for people who love to sit on the edge :) I need some help to find bugs and polish the interface/interaction. RSpactor is basically a tool like 'autotest' but runs on Cocoa and focuses on RSpec. Instead of constantly polling your files it uses FSEvents to listen to changes in your project directory. Growl support is build in.. So if you are interested have a look at: http://rubyphunk.com/2008/4/28/ann-rspactor-0-9-10-some-people-call-it-beta thanks. - Andreas From loop at superinfinite.com Mon Apr 28 16:16:08 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Mon, 28 Apr 2008 22:16:08 +0200 Subject: [rspec-users] story runner on restful_authentication question In-Reply-To: References: Message-ID: <8B4E6199-48B2-47C1-B914-FE5044599390@superinfinite.com> On 28 apr 2008, at 17:31, steven shingler wrote: > > When "the user logs in with username and password" do > post "/sessions/create", :user => { :login => @username, :password > => @password } > end Try post_via_redirect... greetz, bartz From coreyhaines at gmail.com Mon Apr 28 20:08:51 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Mon, 28 Apr 2008 20:08:51 -0400 Subject: [rspec-users] ANN: RSpactor 0.9.10 (aka. beta) In-Reply-To: <88061a1b-5f4e-4976-b1d0-86be1c2440b2@y38g2000hsy.googlegroups.com> References: <88061a1b-5f4e-4976-b1d0-86be1c2440b2@y38g2000hsy.googlegroups.com> Message-ID: <6bdacb70804281708q65996a2bpaeca7369ba37fef9@mail.gmail.com> I'm using rspactor now over autotest. I'll give the beta a shot. -Corey On Mon, Apr 28, 2008 at 3:51 PM, rubyphunk wrote: > Hey all. > > I've just release a first preview/beta of the upcoming RSpactor.app; a > spec runner for Mac OS X Leopard. This is just some kind of test > version and I'm looking for people who love to sit on the edge :) I > need some help to find bugs and polish the interface/interaction. > > RSpactor is basically a tool like 'autotest' but runs on Cocoa and > focuses on RSpec. Instead of constantly polling your files it uses > FSEvents to listen to changes in your project directory. Growl support > is build in.. > > So if you are interested have a look at: > > http://rubyphunk.com/2008/4/28/ann-rspactor-0-9-10-some-people-call-it-beta > > > thanks. > - Andreas > _______________________________________________ > 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: From mailing_lists at railsnewbie.com Mon Apr 28 20:37:13 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 28 Apr 2008 20:37:13 -0400 Subject: [rspec-users] Running spec_server In-Reply-To: <745312bd0804280842g2d8189f5m5414be6f6ca6cc99@mail.gmail.com> References: <745312bd0804251216v2f8ca60dvff36297d92b12602@mail.gmail.com> <50636E05-A1A1-426B-92A9-56737A67876F@railsnewbie.com> <745312bd0804280842g2d8189f5m5414be6f6ca6cc99@mail.gmail.com> Message-ID: On Apr 28, 2008, at 11:42 AM, Olivier Dupuis wrote: > Hi Scott, > > I'm having no trouble running script/generate rspec. I'm using the > CURRENT version of rspec and rspec_on_rails. I just reinstalled > them last week. > > Any idea what could be causing this? > No idea. What is line 9 of script/spec_server ? Scott > Thank you > > Olivier Dupuis > > On Sat, Apr 26, 2008 at 12:15 AM, Scott Taylor > wrote: > > On Apr 25, 2008, at 3:16 PM, Olivier Dupuis wrote: > > Hello, > > I've been using rspec for a while now and just noticed spec_server. > I would like to use it, but for some reason, it's not able to start. > > I have the latest versions of rspec and rspec_on_rails. I'm using > WinXp. > > The specific error I get is the following: > > script/spec_server:9: undefined method '+' for nil:NilClass > (NoMethodError) > > Have you tried running script/generate rspec ? > > What version of rspec/rspec_on_rails are you using? > > 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From coreyhaines at gmail.com Mon Apr 28 20:46:49 2008 From: coreyhaines at gmail.com (Corey Haines) Date: Mon, 28 Apr 2008 20:46:49 -0400 Subject: [rspec-users] ANN: RSpactor 0.9.10 (aka. beta) In-Reply-To: <6bdacb70804281708q65996a2bpaeca7369ba37fef9@mail.gmail.com> References: <88061a1b-5f4e-4976-b1d0-86be1c2440b2@y38g2000hsy.googlegroups.com> <6bdacb70804281708q65996a2bpaeca7369ba37fef9@mail.gmail.com> Message-ID: <6bdacb70804281746qf09b579x4f771be804ab5a21@mail.gmail.com> Well, I got it running (seemingly), but I'm not 100% sure how to use it. -Corey On Mon, Apr 28, 2008 at 8:08 PM, Corey Haines wrote: > I'm using rspactor now over autotest. I'll give the beta a shot. > -Corey > > > On Mon, Apr 28, 2008 at 3:51 PM, rubyphunk > wrote: > > > Hey all. > > > > I've just release a first preview/beta of the upcoming RSpactor.app; a > > spec runner for Mac OS X Leopard. This is just some kind of test > > version and I'm looking for people who love to sit on the edge :) I > > need some help to find bugs and polish the interface/interaction. > > > > RSpactor is basically a tool like 'autotest' but runs on Cocoa and > > focuses on RSpec. Instead of constantly polling your files it uses > > FSEvents to listen to changes in your project directory. Growl support > > is build in.. > > > > So if you are interested have a look at: > > > > http://rubyphunk.com/2008/4/28/ann-rspactor-0-9-10-some-people-call-it-beta > > > > > > thanks. > > - Andreas > > _______________________________________________ > > 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: From chad.humphries at gmail.com Mon Apr 28 21:19:54 2008 From: chad.humphries at gmail.com (Chad Humphries) Date: Mon, 28 Apr 2008 21:19:54 -0400 Subject: [rspec-users] ANN: RSpactor 0.9.10 (aka. beta) In-Reply-To: <6bdacb70804281708q65996a2bpaeca7369ba37fef9@mail.gmail.com> References: <88061a1b-5f4e-4976-b1d0-86be1c2440b2@y38g2000hsy.googlegroups.com> <6bdacb70804281708q65996a2bpaeca7369ba37fef9@mail.gmail.com> Message-ID: <16f722280804281819v43b7a701r2263a50385490eb0@mail.gmail.com> Very cool, I'll try it out tomorrow. -- Chad On Mon, Apr 28, 2008 at 8:08 PM, Corey Haines wrote: > I'm using rspactor now over autotest. I'll give the beta a shot. > > -Corey > > > > On Mon, Apr 28, 2008 at 3:51 PM, rubyphunk wrote: > > > Hey all. > > > > I've just release a first preview/beta of the upcoming RSpactor.app; a > > spec runner for Mac OS X Leopard. This is just some kind of test > > version and I'm looking for people who love to sit on the edge :) I > > need some help to find bugs and polish the interface/interaction. > > > > RSpactor is basically a tool like 'autotest' but runs on Cocoa and > > focuses on RSpec. Instead of constantly polling your files it uses > > FSEvents to listen to changes in your project directory. Growl support > > is build in.. > > > > So if you are interested have a look at: > > > http://rubyphunk.com/2008/4/28/ann-rspactor-0-9-10-some-people-call-it-beta > > > > > > thanks. > > - Andreas > > _______________________________________________ > > 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 zach.dennis at gmail.com Mon Apr 28 23:03:53 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 28 Apr 2008 23:03:53 -0400 Subject: [rspec-users] ANN: RSpactor 0.9.10 (aka. beta) In-Reply-To: <6bdacb70804281746qf09b579x4f771be804ab5a21@mail.gmail.com> References: <88061a1b-5f4e-4976-b1d0-86be1c2440b2@y38g2000hsy.googlegroups.com> <6bdacb70804281708q65996a2bpaeca7369ba37fef9@mail.gmail.com> <6bdacb70804281746qf09b579x4f771be804ab5a21@mail.gmail.com> Message-ID: <85d99afe0804282003s3f9fd862l5586a2a28c26279@mail.gmail.com> Just put a directory path to a project in the text field, and click Run. It will do the rest as far as I can tell, Zach On Mon, Apr 28, 2008 at 8:46 PM, Corey Haines wrote: > Well, I got it running (seemingly), but I'm not 100% sure how to use it. > -Corey > > > On Mon, Apr 28, 2008 at 8:08 PM, Corey Haines > wrote: > > > I'm using rspactor now over autotest. I'll give the beta a shot. > > -Corey > > > > > > On Mon, Apr 28, 2008 at 3:51 PM, rubyphunk > > wrote: > > > > > Hey all. > > > > > > I've just release a first preview/beta of the upcoming RSpactor.app; a > > > spec runner for Mac OS X Leopard. This is just some kind of test > > > version and I'm looking for people who love to sit on the edge :) I > > > need some help to find bugs and polish the interface/interaction. > > > > > > RSpactor is basically a tool like 'autotest' but runs on Cocoa and > > > focuses on RSpec. Instead of constantly polling your files it uses > > > FSEvents to listen to changes in your project directory. Growl support > > > is build in.. > > > > > > So if you are interested have a look at: > > > > > > http://rubyphunk.com/2008/4/28/ann-rspactor-0-9-10-some-people-call-it-beta > > > > > > > > > thanks. > > > - Andreas > > > _______________________________________________ > > > 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 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From patcito at gmail.com Tue Apr 29 01:59:18 2008 From: patcito at gmail.com (Patrick Aljord) Date: Tue, 29 Apr 2008 00:59:18 -0500 Subject: [rspec-users] noob question for getting true or false from a function Message-ID: <6b6419750804282259p575222e5gdfede5c4e5d621ed@mail.gmail.com> Hey all, I have an action that looks like this: def create if using_open_id? open_id_authentication(params[:openid_url]) else password_authentication(params[:email], params[:password]) end end I have a spec that looks like this: it "should login and redirect" do post :create, :email => "foo at bar.com", :password => "test" session[:user_id].should_not be(nil) response.should be_redirect end any idea how to make this work so that using_open_id? returns false? For now I get "undefined method `using_open_id?' for #". I don't want to write a test for using_open_id? cause it comes with the open_id_authentication plugin. thanks in advance Pat From dchelimsky at gmail.com Tue Apr 29 02:06:17 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 29 Apr 2008 01:06:17 -0500 Subject: [rspec-users] noob question for getting true or false from a function In-Reply-To: <6b6419750804282259p575222e5gdfede5c4e5d621ed@mail.gmail.com> References: <6b6419750804282259p575222e5gdfede5c4e5d621ed@mail.gmail.com> Message-ID: <26B86BAD-3880-4018-A894-8F451EE0BF47@gmail.com> On Apr 29, 2008, at 12:59 AM, Patrick Aljord wrote: > Hey all, > > I have an action that looks like this: > > def create > if using_open_id? > open_id_authentication(params[:openid_url]) > else > password_authentication(params[:email], params[:password]) > end > end > > I have a spec that looks like this: > it "should login and redirect" do > post :create, :email => "foo at bar.com", :password => "test" > false> controller.stub!(:using_open_id?).and_return(false) > > session[:user_id].should_not be(nil) > response.should be_redirect > end > > any idea how to make this work so that using_open_id? returns false? > For now I get "undefined method `using_open_id?' for > #". I don't want to write a test for > using_open_id? cause it comes with the open_id_authentication plugin. HTH, David From rubyphunk at googlemail.com Tue Apr 29 03:17:28 2008 From: rubyphunk at googlemail.com (rubyphunk) Date: Tue, 29 Apr 2008 00:17:28 -0700 (PDT) Subject: [rspec-users] ANN: RSpactor 0.9.10 (aka. beta) In-Reply-To: <85d99afe0804282003s3f9fd862l5586a2a28c26279@mail.gmail.com> References: <88061a1b-5f4e-4976-b1d0-86be1c2440b2@y38g2000hsy.googlegroups.com> <6bdacb70804281708q65996a2bpaeca7369ba37fef9@mail.gmail.com> <6bdacb70804281746qf09b579x4f771be804ab5a21@mail.gmail.com> <85d99afe0804282003s3f9fd862l5586a2a28c26279@mail.gmail.com> Message-ID: If you have setup the binary as described in INSTALL.txt you can even run rspactor from command line. 'cd' in your project directory and run 'rspactor'.. - andreas On 29 Apr., 05:03, "Zach Dennis" wrote: > Just put a directory path to a project in the text field, and click Run. It > will do the rest as far as I can tell, > Zach > > > > On Mon, Apr 28, 2008 at 8:46 PM, Corey Haines wrote: > > Well, I got it running (seemingly), but I'm not 100% sure how to use it. > > -Corey > > > On Mon, Apr 28, 2008 at 8:08 PM, Corey Haines > > wrote: > > > > I'm using rspactor now over autotest. I'll give the beta a shot. > > > -Corey > > > > On Mon, Apr 28, 2008 at 3:51 PM, rubyphunk > > > wrote: > > > > > Hey all. > > > > > I've just release a first preview/beta of the upcoming RSpactor.app; a > > > > spec runner for Mac OS X Leopard. This is just some kind of test > > > > version and I'm looking for people who love to sit on the edge :) I > > > > need some help to find bugs and polish the interface/interaction. > > > > > RSpactor is basically a tool like 'autotest' but runs on Cocoa and > > > > focuses on RSpec. Instead of constantly polling your files it uses > > > > FSEvents to listen to changes in your project directory. Growl support > > > > is build in.. > > > > > So if you are interested have a look at: > > > > >http://rubyphunk.com/2008/4/28/ann-rspactor-0-9-10-some-people-call-i... > > > > > thanks. > > > > - Andreas > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-us... 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 > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > -- > Zach Dennishttp://www.continuousthinking.com > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From helder at gmail.com Tue Apr 29 03:19:35 2008 From: helder at gmail.com (Helder Ribeiro) Date: Tue, 29 Apr 2008 04:19:35 -0300 Subject: [rspec-users] noob question for getting true or false from a function In-Reply-To: <26B86BAD-3880-4018-A894-8F451EE0BF47@gmail.com> References: <6b6419750804282259p575222e5gdfede5c4e5d621ed@mail.gmail.com> <26B86BAD-3880-4018-A894-8F451EE0BF47@gmail.com> Message-ID: <9bb72e130804290019v9a5aao81d65751ed90b549@mail.gmail.com> On Tue, Apr 29, 2008 at 3:06 AM, David Chelimsky wrote: > On Apr 29, 2008, at 12:59 AM, Patrick Aljord wrote: > > > > Hey all, > > > > I have an action that looks like this: > > > > def create > > if using_open_id? > > open_id_authentication(params[:openid_url]) > > else > > password_authentication(params[:email], params[:password]) > > end > > end > > > > I have a spec that looks like this: > > it "should login and redirect" do > > post :create, :email => "foo at bar.com", :password => "test" > > > > > > controller.stub!(:using_open_id?).and_return(false) I had run into the same problem the other day. Thanks for the tip! :) > > > > > > > session[:user_id].should_not be(nil) > > response.should be_redirect > > end > > > > any idea how to make this work so that using_open_id? returns false? > > For now I get "undefined method `using_open_id?' for > > #". I don't want to write a test for > > using_open_id? cause it comes with the open_id_authentication plugin. > > > > HTH, > David > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- "If I have not seen as far as others, it is because giants were standing on my shoulders" -- Jeff Goll From rick.denatale at gmail.com Tue Apr 29 06:46:23 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 29 Apr 2008 06:46:23 -0400 Subject: [rspec-users] story runner on restful_authentication question In-Reply-To: <8B4E6199-48B2-47C1-B914-FE5044599390@superinfinite.com> References: <8B4E6199-48B2-47C1-B914-FE5044599390@superinfinite.com> Message-ID: On Mon, Apr 28, 2008 at 4:16 PM, Bart Zonneveld wrote: > > On 28 apr 2008, at 17:31, steven shingler wrote: > > > > > When "the user logs in with username and password" do > > post "/sessions/create", :user => { :login => @username, :password > > => @password } > > end > > > > Try post_via_redirect... No that will make his "should redirect to '$path" step fail since it will eat the redirect response and follow it. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From loop at superinfinite.com Tue Apr 29 06:49:18 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Tue, 29 Apr 2008 12:49:18 +0200 Subject: [rspec-users] story runner on restful_authentication question In-Reply-To: References: <8B4E6199-48B2-47C1-B914-FE5044599390@superinfinite.com> Message-ID: <3FB7EE6E-C89C-4F1D-AA23-7C6A66BF7F64@superinfinite.com> On 29-apr-2008, at 12:46, Rick DeNatale wrote: > On Mon, Apr 28, 2008 at 4:16 PM, Bart Zonneveld > wrote: >> >> On 28 apr 2008, at 17:31, steven shingler wrote: >> >>> >>> When "the user logs in with username and password" do >>> post "/sessions/create", :user => { :login => @username, :password >>> => @password } >>> end >>> >> >> Try post_via_redirect... > > No that will make his "should redirect to '$path" step fail since it > will eat the redirect response and follow it. Ack, brainfart. I mixed up the two in my head. gr, bartz From shingler at gmail.com Tue Apr 29 06:51:06 2008 From: shingler at gmail.com (steven shingler) Date: Tue, 29 Apr 2008 11:51:06 +0100 Subject: [rspec-users] story runner on restful_authentication question In-Reply-To: <8B4E6199-48B2-47C1-B914-FE5044599390@superinfinite.com> References: <8B4E6199-48B2-47C1-B914-FE5044599390@superinfinite.com> Message-ID: Thank you for all the replies. I'm unable to use ruby-debug, cos am running on JRuby, but a liberal sprinkling of logger.debug in the controllers helped me sort out what was going on the test.log. Thanks for that tip. It made me want for a way of writing something to the log from within the rspec step though - is there a quick way of doing that? Cheers, Steven On Mon, Apr 28, 2008 at 9:16 PM, Bart Zonneveld wrote: > > On 28 apr 2008, at 17:31, steven shingler wrote: > > > > > When "the user logs in with username and password" do > > post "/sessions/create", :user => { :login => @username, :password > > => @password } > > end > > > > Try post_via_redirect... > > greetz, > bartz > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Tue Apr 29 07:36:15 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 29 Apr 2008 07:36:15 -0400 Subject: [rspec-users] story runner on restful_authentication question In-Reply-To: References: <8B4E6199-48B2-47C1-B914-FE5044599390@superinfinite.com> Message-ID: On Tue, Apr 29, 2008 at 6:51 AM, steven shingler wrote: > Thank you for all the replies. > I'm unable to use ruby-debug, cos am running on JRuby, I haven't yet used JRuby, but there seems to be a JRuby wrapper for rdebug http://wiki.jruby.org/wiki/Using_the_JRuby_Debugger -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From andrea.fazzi at alca.le.it Tue Apr 29 07:59:40 2008 From: andrea.fazzi at alca.le.it (Andrea Fazzi) Date: Tue, 29 Apr 2008 13:59:40 +0200 Subject: [rspec-users] mock expectation in before block Message-ID: <48170DAC.1090108@alca.le.it> Hi all, consider a class Foo that send, in its constructor, some message to an object of class Bar: class Foo def initialize(bar) @bar = bar @bar.some_message end ... end Now, in order to test Foo, I'd like to decouple it from Bar mocking bar object, so: describe Foo do before do @bar = mock('bar') @bar.should_receive(:some_message) @foo = Foo.new(bar) end it 'should ...' it 'should ...' ... end The question is: is it appropriate to put a mock expectation inside a before block? Or mock expectations are relegated to example blocks? Thanks in advance. Andrea From shingler at gmail.com Tue Apr 29 08:33:03 2008 From: shingler at gmail.com (steven shingler) Date: Tue, 29 Apr 2008 13:33:03 +0100 Subject: [rspec-users] story runner on restful_authentication question In-Reply-To: References: <8B4E6199-48B2-47C1-B914-FE5044599390@superinfinite.com> Message-ID: ooh - good spot! thanks :) On Tue, Apr 29, 2008 at 12:36 PM, Rick DeNatale wrote: > On Tue, Apr 29, 2008 at 6:51 AM, steven shingler wrote: > > Thank you for all the replies. > > I'm unable to use ruby-debug, cos am running on JRuby, > > I haven't yet used JRuby, but there seems to be a JRuby wrapper for rdebug > > http://wiki.jruby.org/wiki/Using_the_JRuby_Debugger > > > -- > 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 matt at mattberther.com Tue Apr 29 09:10:59 2008 From: matt at mattberther.com (Matt Berther) Date: Tue, 29 Apr 2008 07:10:59 -0600 Subject: [rspec-users] mock expectation in before block In-Reply-To: <48170DAC.1090108@alca.le.it> References: <48170DAC.1090108@alca.le.it> Message-ID: <0E219067-5D46-42FE-8157-5B21FF6555E4@mattberther.com> Hi Andrea, I generally put stub! calls in the before block and then have the mock expectation in the example block. -- Matt Berther http://www.mattberther.com On Apr 29, 2008, at 5:59 AM, Andrea Fazzi wrote: > Hi all, > > consider a class Foo that send, in its constructor, some message to > an object of class Bar: > > class Foo > def initialize(bar) > @bar = bar > @bar.some_message > end > > ... > > end > > Now, in order to test Foo, I'd like to decouple it from Bar mocking > bar object, so: > > describe Foo do > > before do > @bar = mock('bar') > @bar.should_receive(:some_message) > @foo = Foo.new(bar) > end > > it 'should ...' > it 'should ...' > > ... > > end > > The question is: is it appropriate to put a mock expectation inside > a before block? Or mock expectations are relegated to example blocks? > > Thanks in advance. > Andrea > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From andrea.fazzi at alca.le.it Tue Apr 29 09:34:04 2008 From: andrea.fazzi at alca.le.it (Andrea Fazzi) Date: Tue, 29 Apr 2008 15:34:04 +0200 Subject: [rspec-users] mock expectation in before block In-Reply-To: <0E219067-5D46-42FE-8157-5B21FF6555E4@mattberther.com> References: <48170DAC.1090108@alca.le.it> <0E219067-5D46-42FE-8157-5B21FF6555E4@mattberther.com> Message-ID: <481723CC.6040103@alca.le.it> Matt Berther ha scritto: > Hi Andrea, > > I generally put stub! calls in the before block and then have the mock > expectation in the example block. > > -- > Matt Berther > http://www.mattberther.com > > > > > On Apr 29, 2008, at 5:59 AM, Andrea Fazzi wrote: > >> Hi all, >> >> consider a class Foo that send, in its constructor, some message to >> an object of class Bar: >> >> class Foo >> def initialize(bar) >> @bar = bar >> @bar.some_message >> end >> >> ... >> >> end >> >> Now, in order to test Foo, I'd like to decouple it from Bar mocking >> bar object, so: >> >> describe Foo do >> >> before do >> @bar = mock('bar') >> @bar.should_receive(:some_message) >> @foo = Foo.new(bar) >> end >> >> it 'should ...' >> it 'should ...' >> >> ... >> >> end >> >> The question is: is it appropriate to put a mock expectation inside a >> before block? Or mock expectations are relegated to example blocks? >> >> Thanks in advance. >> Andrea >> >> >> _______________________________________________ >> 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 > Thank you for your answer Matt. I think I've cought the point. Stub methods return canned responses so they are not intended to underline interactions between the mock object and the object under testing. Thank you again. Andrea From patcito at gmail.com Tue Apr 29 11:58:11 2008 From: patcito at gmail.com (Patrick Aljord) Date: Tue, 29 Apr 2008 10:58:11 -0500 Subject: [rspec-users] noob question for getting true or false from a function In-Reply-To: <26B86BAD-3880-4018-A894-8F451EE0BF47@gmail.com> References: <6b6419750804282259p575222e5gdfede5c4e5d621ed@mail.gmail.com> <26B86BAD-3880-4018-A894-8F451EE0BF47@gmail.com> Message-ID: <6b6419750804290858m1a76d955v7456248c6a69eb27@mail.gmail.com> ok thanks a lot. From patcito at gmail.com Tue Apr 29 12:00:52 2008 From: patcito at gmail.com (Patrick Aljord) Date: Tue, 29 Apr 2008 11:00:52 -0500 Subject: [rspec-users] another noob question about stubs Message-ID: <6b6419750804290900j21c97121u639086002b4fb8bc@mail.gmail.com> I have this function in my controller: def open_id_authentication(openid_url) authenticate_with_open_id(openid_url, :required => [:nickname, :email], :optional => [:fullname]) do |result, identity_url, registration| if result.successful? @user = User.find_or_initialize_by_identity_url(identity_url) if @user.new_record? @user.login = registration['nickname'] @user.fullname = registration['fullname'] @user.email = registration['email'] @user.save! @user.activate end self.current_user = @user successful_login else failed_login result.message, 'openid' end end end I tried to make a stub but with no success, maybe because it's a block. Any hint about that one please? Thanks in advance Pat From matt-lists at reprocessed.org Tue Apr 29 12:22:40 2008 From: matt-lists at reprocessed.org (Matt Patterson) Date: Tue, 29 Apr 2008 17:22:40 +0100 Subject: [rspec-users] another noob question about stubs In-Reply-To: <6b6419750804290900j21c97121u639086002b4fb8bc@mail.gmail.com> References: <6b6419750804290900j21c97121u639086002b4fb8bc@mail.gmail.com> Message-ID: On 29 Apr 2008, at 17:00, Patrick Aljord wrote: > I tried to make a stub but with no success, maybe because it's a > block. Any hint about that one please? What are you trying to stub? Are you trying to stub authenticate_with_open_id? > def open_id_authentication(openid_url) > authenticate_with_open_id(openid_url, :required => [:nickname, > :email], :optional => [:fullname]) do |result, identity_url, > registration| > if result.successful? > @user = User.find_or_initialize_by_identity_url(identity_url) > ... > end > end > end If so, you could try controller.stub! (:authenticate_with_open_id ).and_yield(:result, :identity_url, :registration) so that the code in the block actually gets run (a normal stub, or one with and_return with simply eat the block). Obviously, make sure that it's yielding the values you want it to. HTH Matt -- Matt Patterson | Design & Code | http://www.reprocessed.org/ From nabble.108 at xoxy.net Tue Apr 29 12:48:58 2008 From: nabble.108 at xoxy.net (Matt McNeil) Date: Tue, 29 Apr 2008 09:48:58 -0700 (PDT) Subject: [rspec-users] Spec'ing controller macros Message-ID: <16927457.post@talk.nabble.com> Hi, (This is my first post after months of appreciative lurking...) I'm trying to spec the following conditional controller macro: class ApplicationController < ActionController::Base # turn off session management for robots session :off, :if => lambda {|req| req.user_agent =~ /(Google|Slurp)/i } # ... end My current attempt seems to be quite unsuccessful: 1) when I include the controller.should_receive(:session) statement, the index action no longer seems to be actually called (ie a breakpoint placed in the index method is not triggered) 2) I receive the following error: Spec::Mocks::MockExpectationError in 'ApplicationController should turn off session management for requests made by robot user agent' Mock 'FooController' expected :session with (:off) but received it with (no args) ./spec/controllers/application_spec.rb:19: Any suggestions? Thanks much, Matt describe ApplicationController do class FooController < ApplicationController def index; render :text => "foo"; end end controller_name :foo it "should turn off session management for requests made by robot user agent" do request.stub!(:user_agent).and_return("Google Robot") controller.should_receive(:session).with(:off) get :index end end -- View this message in context: http://www.nabble.com/Spec%27ing-controller-macros-tp16927457p16927457.html Sent from the rspec-users mailing list archive at Nabble.com. From vertebrate at gmail.com Tue Apr 29 13:03:37 2008 From: vertebrate at gmail.com (Steve) Date: Tue, 29 Apr 2008 17:03:37 +0000 (UTC) Subject: [rspec-users] Fixture Scenarios plugin Message-ID: Just curious if anything special needs to be done to use the Rails fixture scenarios plugin(http://code.google.com/p/fixture-scenarios/) with rspec? Would I just create the "scenarios" inside the spec/fixtures dir, as opposed to the test/fixtures dir? Thanks, Steve From pergesu at gmail.com Tue Apr 29 13:12:26 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 29 Apr 2008 10:12:26 -0700 Subject: [rspec-users] Spec'ing controller macros In-Reply-To: <16927457.post@talk.nabble.com> References: <16927457.post@talk.nabble.com> Message-ID: <810a540e0804291012x738c3795g3f7428807584648a@mail.gmail.com> On Tue, Apr 29, 2008 at 9:48 AM, Matt McNeil wrote: > describe ApplicationController do > class FooController < ApplicationController > def index; render :text => "foo"; end > end > controller_name :foo > > it "should turn off session management for requests made by robot user > agent" do > request.stub!(:user_agent).and_return("Google Robot") > controller.should_receive(:session).with(:off) > get :index > end > end Hi Matt, The problem here is that it's actually the controller class that's receiving the 'session' message, not a controller object. In this case, mocking the call isn't going to do you much good. The :if block wouldn't get evaluated, forcing you to just duplicate the method arguments. The good news is you can test the desired behavior with a more state-based approach: it "should turn the session off" do request.stub!(:user_agent).and_return("Google Robot") get :index controller.should_not be_session_enabled end Pat From address4spams at 21croissants.com Tue Apr 29 13:25:30 2008 From: address4spams at 21croissants.com (21croissants) Date: Tue, 29 Apr 2008 10:25:30 -0700 (PDT) Subject: [rspec-users] Sharing: dont_repeat_yourself plugin custom RSpec matcher Message-ID: <16965619.post@talk.nabble.com> I wrote a Rails plugin which uses simian to look for duplicates lines in your code and reports in html format, Textmate or Netbeans. I wrote it using RSpec and I have included a RSpec custom matcher: it { rails_application. with_threshold_of_duplicate_lines(4). should be_DRY } If you use Autotest, your specs will fail the next time you do a nasty copy-paste !!! More details in http://21croissants.blogspot.com/2008/03/dry.html Feedback and patches (with specs!) welcome ;-) Jean-Michel -- View this message in context: http://www.nabble.com/Sharing%3A-dont_repeat_yourself-plugin-custom-RSpec-matcher-tp16965619p16965619.html Sent from the rspec-users mailing list archive at Nabble.com. From ashley.moran at patchspace.co.uk Tue Apr 29 15:36:28 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 29 Apr 2008 20:36:28 +0100 Subject: [rspec-users] Sharing: dont_repeat_yourself plugin custom RSpec matcher In-Reply-To: <16965619.post@talk.nabble.com> References: <16965619.post@talk.nabble.com> Message-ID: <71E6913D-A330-4FC8-BB81-6F6B310266CC@patchspace.co.uk> On 29 Apr 2008, at 18:25, 21croissants wrote: > I wrote a Rails plugin which uses simian to look for duplicates > lines in your > code and reports in html format, Textmate or Netbeans. > > I wrote it using RSpec and I have included a RSpec custom matcher: > it { rails_application. > with_threshold_of_duplicate_lines(4). > should be_DRY } > > If you use Autotest, your specs will fail the next time you do a nasty > copy-paste !!! > > More details in http://21croissants.blogspot.com/2008/03/dry.html > > Feedback and patches (with specs!) welcome ;-) Sounds good! Any reason why you wrote it as a Rails plugin though? This could be used for any ruby project... except mine of course, I never copy and paste, honest :o) Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ben at benmabey.com Tue Apr 29 18:47:48 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 29 Apr 2008 16:47:48 -0600 Subject: [rspec-users] odd fixture behavior Message-ID: <4817A594.7030603@benmabey.com> Hello all, I am upgrading an older app from rails 1.2.3 to rails 2.0.2 and am upgrading rspec and rspec-on-rails to 1.1.3 in the process. After upgrading I am getting some weird errors relating to fixtures. Most of the model example groups have fixtures declared at the top. What is odd is that I can run any given spec file individually with the spec command and they run just fine. However, when I run all the specs with rake spec certain spec groups fail due to fixtures not being loaded properly. Meaning, the DB should of been populated by the fixtures but in the specs the tables are empty. I have ran './script/generate rspec' and in my spec_helper.rb I have: Spec::Runner.configure do |config| config.use_transactional_fixtures = true config.use_instantiated_fixtures = false I know that rspec just relies on the test::unit fixture framework that rails provides so this isn't really a rspec issue but I'm hoping that someone on this list may have some ideas on what could be going wrong here. Were there changes to the way fixtures worked in rails 2.0 that would effect how I am doing things? I haven't used fixtures for ever (switched to a factory instead) so I haven't really kept up with there changes.... Any ideas on what could be wrong or how I could troubleshoot this problem would be greatly appreciated. Thanks, Ben From ben at benmabey.com Tue Apr 29 23:14:43 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 29 Apr 2008 21:14:43 -0600 Subject: [rspec-users] odd fixture behavior In-Reply-To: <4817A594.7030603@benmabey.com> References: <4817A594.7030603@benmabey.com> Message-ID: <4817E423.3060805@benmabey.com> Ben Mabey wrote: > Hello all, > I am upgrading an older app from rails 1.2.3 to rails 2.0.2 and am > upgrading rspec and rspec-on-rails to 1.1.3 in the process. > After upgrading I am getting some weird errors relating to fixtures. > Most of the model example groups have fixtures declared at the top. > What is odd is that I can run any given spec file individually with > the spec command and they run just fine. However, when I run all the > specs with rake spec certain spec groups fail due to fixtures not > being loaded properly. Meaning, the DB should of been populated by > the fixtures but in the specs the tables are empty. I have ran > './script/generate rspec' and in my spec_helper.rb I have: > > Spec::Runner.configure do |config| > config.use_transactional_fixtures = true > config.use_instantiated_fixtures = false > > I know that rspec just relies on the test::unit fixture framework that > rails provides so this isn't really a rspec issue but I'm hoping that > someone on this list may have some ideas on what could be going wrong > here. Were there changes to the way fixtures worked in rails 2.0 that > would effect how I am doing things? I haven't used fixtures for ever > (switched to a factory instead) so I haven't really kept up with there > changes.... Any ideas on what could be wrong or how I could > troubleshoot this problem would be greatly appreciated. Thanks, > > Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Okay.. nm... I resolved the issue. I don't know exactly what was wrong and I don't want to take the time/energy to figure it out... but something with my before(:all)'s were not playing well with the fixtures. By changing some of them to before(:each)'s it seemed to fix the problem. My best guess is that my before all's were dependent on the fixtures already being loaded when they were ran but that is not the case anymore. Sorry for the spam... Thanks, Ben From patcito at gmail.com Wed Apr 30 02:00:23 2008 From: patcito at gmail.com (Patrick Aljord) Date: Wed, 30 Apr 2008 01:00:23 -0500 Subject: [rspec-users] another noob question about stubs In-Reply-To: References: <6b6419750804290900j21c97121u639086002b4fb8bc@mail.gmail.com> Message-ID: <6b6419750804292300u53e6396dp4eff40ba838d460@mail.gmail.com> ok thanks, I still get a "undefined method `successful?'", successful? is a method that is used inside of the block, it's partof the open_id_authentication plugin, any way to include the plugin in the spec so that it recognizes the method? thanks in advance Pat From glenn at aldenta.com Wed Apr 30 08:49:28 2008 From: glenn at aldenta.com (Glenn Ford) Date: Wed, 30 Apr 2008 08:49:28 -0400 Subject: [rspec-users] ANN: RSpactor 0.9.10 (aka. beta) In-Reply-To: References: <88061a1b-5f4e-4976-b1d0-86be1c2440b2@y38g2000hsy.googlegroups.com> <6bdacb70804281708q65996a2bpaeca7369ba37fef9@mail.gmail.com> <6bdacb70804281746qf09b579x4f771be804ab5a21@mail.gmail.com> <85d99afe0804282003s3f9fd862l5586a2a28c26279@mail.gmail.com> Message-ID: <2E819F4F-FC76-4863-A41A-72BBC15E741A@aldenta.com> Works for me! However I have a feature request. Currently I exclude certain files like so: Autotest.add_hook :initialize do |at| %w{this_kind that_kind .git vendor .blah}.each {|exception| at.add_exception(exception)} end Will there be a way to do something like this with RSpactor? I like having the ability to ignore certain files. Some I skip because they don't work with my setup and to use RSpactor I have to comment out the whole file and remember not to accidentally commit it :) Glenn On Apr 29, 2008, at 3:17 AM, rubyphunk wrote: > If you have setup the binary as described in INSTALL.txt you can even > run rspactor from command line. > 'cd' in your project directory and run 'rspactor'.. > > - andreas > > > On 29 Apr., 05:03, "Zach Dennis" wrote: >> Just put a directory path to a project in the text field, and click >> Run. It >> will do the rest as far as I can tell, >> Zach >> >> >> >> On Mon, Apr 28, 2008 at 8:46 PM, Corey Haines >> wrote: >>> Well, I got it running (seemingly), but I'm not 100% sure how to >>> use it. >>> -Corey >> >>> On Mon, Apr 28, 2008 at 8:08 PM, Corey Haines >>> >>> wrote: >> >>>> I'm using rspactor now over autotest. I'll give the beta a shot. >>>> -Corey >> >>>> On Mon, Apr 28, 2008 at 3:51 PM, rubyphunk >>>> >>>> wrote: >> >>>>> Hey all. >> >>>>> I've just release a first preview/beta of the upcoming >>>>> RSpactor.app; a >>>>> spec runner for Mac OS X Leopard. This is just some kind of test >>>>> version and I'm looking for people who love to sit on the >>>>> edge :) I >>>>> need some help to find bugs and polish the interface/interaction. >> >>>>> RSpactor is basically a tool like 'autotest' but runs on Cocoa and >>>>> focuses on RSpec. Instead of constantly polling your files it uses >>>>> FSEvents to listen to changes in your project directory. Growl >>>>> support >>>>> is build in.. >> >>>>> So if you are interested have a look at: >> >>>>> http://rubyphunk.com/2008/4/28/ann-rspactor-0-9-10-some-people-call-i >>>>> ... >> >>>>> thanks. >>>>> - Andreas >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-us... 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 >> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> -- >> Zach Dennishttp://www.continuousthinking.com >> >> _______________________________________________ >> 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 bryansray at gmail.com Wed Apr 30 09:21:07 2008 From: bryansray at gmail.com (Bryan Ray) Date: Wed, 30 Apr 2008 08:21:07 -0500 Subject: [rspec-users] another noob question about stubs In-Reply-To: <6b6419750804292300u53e6396dp4eff40ba838d460@mail.gmail.com> References: <6b6419750804290900j21c97121u639086002b4fb8bc@mail.gmail.com> <6b6419750804292300u53e6396dp4eff40ba838d460@mail.gmail.com> Message-ID: <2F3ECFEF-57DF-4959-B836-F06C9EFEA72B@gmail.com> If you used Matt's code below, then successful? is most likely referring to a method after your open_id_authentication method. When you stub! that method you're effectively telling rspec to skip over it and return what I tell you instead. You'd need to paste more of your spec and controller action that you're stubbing for anyone to be of further help. On Apr 30, 2008, at 1:00 AM, Patrick Aljord wrote: > ok thanks, I still get a "undefined method `successful?'", successful? > is a method that is used inside of the block, it's partof the > open_id_authentication plugin, any way to include the plugin in the > spec so that it recognizes the method? > > thanks in advance > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ben at benmabey.com Wed Apr 30 09:54:22 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 30 Apr 2008 07:54:22 -0600 Subject: [rspec-users] ANN: RSpactor 0.9.10 (aka. beta) In-Reply-To: <88061a1b-5f4e-4976-b1d0-86be1c2440b2@y38g2000hsy.googlegroups.com> References: <88061a1b-5f4e-4976-b1d0-86be1c2440b2@y38g2000hsy.googlegroups.com> Message-ID: <48187A0E.3020008@benmabey.com> rubyphunk wrote: > Hey all. > > I've just release a first preview/beta of the upcoming RSpactor.app; a > spec runner for Mac OS X Leopard. This is just some kind of test > version and I'm looking for people who love to sit on the edge :) I > need some help to find bugs and polish the interface/interaction. > > RSpactor is basically a tool like 'autotest' but runs on Cocoa and > focuses on RSpec. Instead of constantly polling your files it uses > FSEvents to listen to changes in your project directory. Growl support > is build in.. > > So if you are interested have a look at: > http://rubyphunk.com/2008/4/28/ann-rspactor-0-9-10-some-people-call-it-beta > > > thanks. > - Andreas > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Andreas, This is great. I have been using it since Monday and I am loving it. Is there a mailing list setup just for RSpactor? -Ben From ashley.moran at patchspace.co.uk Wed Apr 30 10:51:46 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 30 Apr 2008 15:51:46 +0100 Subject: [rspec-users] BDD/Rails/Shoulda In-Reply-To: <04414D52-7044-4CC5-88AB-89F06FF57DE8@gmail.com> References: <51538E8C-C42A-4AE0-9CE0-25D6560E3CE6@parkerhill.com> <7B749038-B6C8-42EE-8CAB-D92661D3C019@patchspace.co.uk> <04414D52-7044-4CC5-88AB-89F06FF57DE8@gmail.com> Message-ID: On 28 Apr 2008, at 07:17, David Chelimsky wrote: > Also, this approach increases the level of granularity from > individual messages to complete statements. For example, let's say I > have this line commented: > > # do_something if this_condition and that_condition > > If this_condition and that_condition always return the same boolean > value, there is no need for a test for that_condition to exist. Nor > should it exist without having been driven into existence by an > example. > > So the approach of uncommenting prototype code still leaves you with > code that is less clean, if only slightly, than code which is purely > driven out by examples. Hmm, I have never found this in practice. In fact, about a month ago I was working on someone else's code and followed this process of uncommenting code as I wrote the specs for it (there were none for that class). I actually *removed* the 'if this_condition and that_condition' part of a line that follows the pattern you gave above. I don't see how you could end up with redundant code following this process. Perhaps I am doing something different that I didn't explain. Maybe it's because I am blanking out what the code says when I write the specs? I don't know, but I haven't found the problem you describe above. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From patcito at gmail.com Wed Apr 30 12:26:08 2008 From: patcito at gmail.com (Patrick Aljord) Date: Wed, 30 Apr 2008 11:26:08 -0500 Subject: [rspec-users] another noob question about stubs In-Reply-To: <2F3ECFEF-57DF-4959-B836-F06C9EFEA72B@gmail.com> References: <6b6419750804290900j21c97121u639086002b4fb8bc@mail.gmail.com> <6b6419750804292300u53e6396dp4eff40ba838d460@mail.gmail.com> <2F3ECFEF-57DF-4959-B836-F06C9EFEA72B@gmail.com> Message-ID: <6b6419750804300926u6273e793xaf3de1fecbae8fd9@mail.gmail.com> > You'd need to paste more of your spec and controller action that you're > stubbing for anyone to be of further help. > I think I posted it on my first post, here it is: def open_id_authentication(openid_url) authenticate_with_open_id(openid_url, :required => [:nickname, :email], :optional => [:fullname]) do |result, identity_url, registration| if result.successful? @user = User.find_or_initialize_by_identity_url(identity_url) if @user.new_record? @user.login = registration['nickname'] @user.fullname = registration['fullname'] @user.email = registration['email'] @user.save! @user.activate end self.current_user = @user successful_login else failed_login result.message, 'openid' end end end My spec looks like this: it "should login with openid and redirect" do openid_url = "patcito.myopenid.com" controller.stub!(:using_open_id?).and_return(true) controller.stub!(:authenticate_with_open_id).and_yield(result,openid_url,registration={"nickname"=>"patcito","email"=>"bob at gmail.com","fullname"=>'bobby bob'}) post :create, :openid_url => openid_url session[:user_id].should_not be(nil) response.should be_redirect end I tried to do something similar to this http://pastie.textmate.org/102377 but it complains that OpenID::Consumer::SUCCESS is not recognized. I guess I'd have to include my open_id_authentication plugin lib in my spec to get it recognized no? is there another way to include a lib in my spec to make it work? thanks in advance Pat From rubyphunk at googlemail.com Wed Apr 30 16:06:40 2008 From: rubyphunk at googlemail.com (rubyphunk) Date: Wed, 30 Apr 2008 13:06:40 -0700 (PDT) Subject: [rspec-users] ANN: RSpactor 0.9.10 (aka. beta) In-Reply-To: <2E819F4F-FC76-4863-A41A-72BBC15E741A@aldenta.com> References: <88061a1b-5f4e-4976-b1d0-86be1c2440b2@y38g2000hsy.googlegroups.com> <6bdacb70804281708q65996a2bpaeca7369ba37fef9@mail.gmail.com> <6bdacb70804281746qf09b579x4f771be804ab5a21@mail.gmail.com> <85d99afe0804282003s3f9fd862l5586a2a28c26279@mail.gmail.com> <2E819F4F-FC76-4863-A41A-72BBC15E741A@aldenta.com> Message-ID: Hi. On 30 Apr., 14:49, Glenn Ford wrote: > Works for me! ?However I have a feature request. ?Currently I exclude ? > certain files like so: > Autotest.add_hook :initialize do |at| > ? ?%w{this_kind that_kind .git vendor .blah}.each {|exception| ? > at.add_exception(exception)} > end > > Will there be a way to do something like this with RSpactor? ?I like ? > having the ability to ignore certain files. ?Some I skip because they ? > don't work with my setup and to use RSpactor I have to comment out the ? > whole file and remember not to accidentally commit it :) Yes. This is one of the features I want to implement before the 1.0 release. - andreas From rubyphunk at googlemail.com Wed Apr 30 16:22:04 2008 From: rubyphunk at googlemail.com (rubyphunk) Date: Wed, 30 Apr 2008 13:22:04 -0700 (PDT) Subject: [rspec-users] ANN: RSpactor 0.9.10 (aka. beta) In-Reply-To: <48187A0E.3020008@benmabey.com> References: <88061a1b-5f4e-4976-b1d0-86be1c2440b2@y38g2000hsy.googlegroups.com> <48187A0E.3020008@benmabey.com> Message-ID: <3b97376a-ca18-4530-b7f3-1662a1e01ee6@s50g2000hsb.googlegroups.com> On 30 Apr., 15:54, Ben Mabey wrote: > This is great. ?I have been using it since Monday and I am loving it. ? > Is there a mailing list setup just for RSpactor? Since shortly :) http://groups.google.com/group/rspactor - andreas From lists at ruby-forum.com Wed Apr 30 18:56:56 2008 From: lists at ruby-forum.com (John Perkins) Date: Thu, 1 May 2008 00:56:56 +0200 Subject: [rspec-users] autotest / rspec not failing tests Message-ID: <5fcaca4e2aecfdb5049f01ac593d6640@ruby-forum.com> Hi all, Bit of a noob problem. I'm attempting to get autotest / rspec running on my OSX 1.5 machine. Everything is the latest version. My test looks like: ---- require 'test/unit' class TestString < Test::Unit::TestCase def test_downcase assert_equal("abcd", "ABCD".downcase) end def test_upcase assert_equal("ABCDf", "abcd".upcase) end end ---- (should be failing!) and it is in the test/unit directory. Autotest is running, rspec / rspec_rails are installed as plugins, not gems. Heres my .autotest file: ---- require 'autotest/redgreen' require 'autotest/timestamp' module Autotest::Growl def self.growl title, msg, img, pri=0, sticky="" system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}" end Autotest.add_hook :ran_command do |at| image_root = "~/.autotest_images" results = [at.results].flatten.join("n") output = results.slice(/(d+)stests,s(d+)sassertions,s(d+)sfailures,s(d+)serrors/) if output if $~[3].to_i > 0 || $~[4].to_i > 0 cnt = [(9 + $~[3].to_i + $~[4].to_i) / 10 * 10, 50].min growl "FAIL", "#{output}", "#{image_root}/fail#{cnt}.png", 2 else growl "Pass", "#{output}", "#{image_root}/pass.png" end end end end ---- (for the doomguy / growl setup) My console output looks like: johnp:link_fixer John$ autotest -rails loading autotest/rails_rspec /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S script/spec -O spec/spec.opts # Waiting since 2008-04-30 12:41:52 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S script/spec -O spec/spec.opts # Waiting since 2008-04-30 12:42:14 ^CInterrupt a second time to quit ---- So, every time I save a file it repeats the -O spec/spec.opts line, but there is no explicit test output. Does anyone see what I'm doing wrong? Thanks, John -- Posted via http://www.ruby-forum.com/. From steve.downtown at gmail.com Wed Apr 30 19:02:11 2008 From: steve.downtown at gmail.com (Steve Downey) Date: Wed, 30 Apr 2008 16:02:11 -0700 Subject: [rspec-users] rake spec:rcov failing Message-ID: <4fff79200804301602g316fdd54o32131db1ec9d8f86@mail.gmail.com> Trying to run the 'spec:rcov' task and failing with error below. I saw a post from last year with a different REXML error but it was a FixNum issue. Any help appreciated. S OS X Ruby 1.8.6 Rails 2.02 RSpec-1.1.3 (build 20080131122909) REXML 3.1.6 ===== 876 examples, 0 failures, 87 pending /opt/local/lib/ruby/site_ruby/1.8/rexml/text.rb:155:in `check': Illegal character '<' in raw string " (RuntimeError) // span.cross-ref { display: none }" ) // ]]> " from /opt/local/lib/ruby/site_ruby/1.8/rexml/text.rb:153:in `each' from /opt/local/lib/ruby/site_ruby/1.8/rexml/text.rb:153:in `check' from /opt/local/lib/ruby/site_ruby/1.8/rexml/text.rb:125:in `parent=' from /opt/local/lib/ruby/site_ruby/1.8/rexml/parent.rb:19:in `<<' from (eval):161:in `<<' from (eval):112:in `create' from (eval):372:in `h_' from /opt/local/lib/ruby/gems/1.8/gems/rcov-0.8.0.2/lib/rcov/report.rb:746:in `create_index' ... 28 levels... from /opt/local/lib/ruby/gems/1.8/gems/rcov-0.8.0.2/lib/rcov.rb:628:in `dump_coverage_info' from /opt/local/lib/ruby/gems/1.8/gems/rcov-0.8.0.2/lib/rcov.rb:628:in `each' from /opt/local/lib/ruby/gems/1.8/gems/rcov-0.8.0.2/lib/rcov.rb:628:in `dump_coverage_info' from /opt/local/lib/ruby/gems/1.8/gems/rcov-0.8.0.2/bin/rcov:405 $ -------------- next part -------------- An HTML attachment was scrubbed... URL: