From address4spams at 21croissants.com Thu May 1 11:00:27 2008 From: address4spams at 21croissants.com (21croissants) Date: Thu, 1 May 2008 08:00:27 -0700 (PDT) Subject: [rspec-users] Sharing: dont_repeat_yourself plugin custom RSpec matcher In-Reply-To: <71E6913D-A330-4FC8-BB81-6F6B310266CC@patchspace.co.uk> References: <16965619.post@talk.nabble.com> <71E6913D-A330-4FC8-BB81-6F6B310266CC@patchspace.co.uk> Message-ID: <16993286.post@talk.nabble.com> thanks for your feedback Ashley. You're right and one of my next action will be to create a gem so it can be use in any ruby project, I will keep the Rails plugin of course. At the moment, you can write : require ... specific your location ... + '/lib/dont_repeat_yourself/reporter' dry_reporter = DontRepeatYourself::Reporter.new dry_reporter.configure_simian_for_ruby_project("/home/jeanmichel/ruby/projects/dry-report/rails_plugin/vendor/plugins/dont_repeat_yourself") dry_reporter.html_rails_report It will generate the report (HTML, Textmate) in a file called DRY_report.html at the root folder of your rails app. I reckon this is not very handy - you need to create a Rails project and install the plugin - but it will soon improve! JM Ashley Moran-4 wrote: > > > 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 > -- View this message in context: http://www.nabble.com/Sharing%3A-dont_repeat_yourself-plugin%2C-will-report-duplicate-lines-in-your-code%21-tp16965619p16993286.html Sent from the rspec-users mailing list archive at Nabble.com. From ashley.moran at patchspace.co.uk Thu May 1 12:07:40 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 1 May 2008 17:07:40 +0100 Subject: [rspec-users] Sharing: dont_repeat_yourself plugin custom RSpec matcher In-Reply-To: <16993286.post@talk.nabble.com> References: <16965619.post@talk.nabble.com> <71E6913D-A330-4FC8-BB81-6F6B310266CC@patchspace.co.uk> <16993286.post@talk.nabble.com> Message-ID: <8F1B2463-E06D-41B7-973A-AE54FA66BAF5@patchspace.co.uk> On 1 May 2008, at 16:00, 21croissants wrote: > You're right and one of my next action will be to create a gem so it > can be > use in any ruby project, I will keep the Rails plugin of course. Cool, be sure to post here when you've gemified it :) > At the moment, you can write : > > require ... specific your location ... + > '/lib/dont_repeat_yourself/reporter' > > dry_reporter = DontRepeatYourself::Reporter.new > dry_reporter.configure_simian_for_ruby_project("/home/jeanmichel/ > ruby/projects/dry-report/rails_plugin/vendor/plugins/ > dont_repeat_yourself") > dry_reporter.html_rails_report > > It will generate the report (HTML, Textmate) in a file called > DRY_report.html at the root folder of your rails app. > > I reckon this is not very handy - you need to create a Rails project > and > install the plugin - but it will soon improve! As a spoilt Rails developer I demand that everything written in Ruby works magically whatever I am doing :o) This reminds me a bit of a time when I created a Rails project just to use AR migrations. I think I'll wait for now until there is a gem version. Just out of curiosity, have you run your DRY reporter against the Rails code itself? Might be interesting to see the results... Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From tero at tilus.net Fri May 2 01:13:52 2008 From: tero at tilus.net (Tero Tilus) Date: Fri, 2 May 2008 08:13:52 +0300 Subject: [rspec-users] BDD/Rails/Shoulda In-Reply-To: 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: <20080502051351.GC18800@uivelo.tilus.net> 2008-04-30 15:51, Ashley Moran: > 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. Maybe the fact that the code was not yours makes a difference here? Dunnot, but I'd expect it to. > I don't see how you could end up with redundant code following this > process. I can well imagine how you may end up not getting all the advantages of BDD thru uncommenting process when you compare to clean BDD. But uncommenting is definitely better than writing spec on top of existing code, which in turn is _way_ better than not writing spec at all. > Maybe it's because I am blanking out what the code says when I write > the specs? Lucky you if you are able to do that. I've noticed I'm not. -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ From ashley.moran at patchspace.co.uk Fri May 2 12:06:34 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 2 May 2008 17:06:34 +0100 Subject: [rspec-users] BDD/Rails/Shoulda In-Reply-To: <20080502051351.GC18800@uivelo.tilus.net> References: <51538E8C-C42A-4AE0-9CE0-25D6560E3CE6@parkerhill.com> <7B749038-B6C8-42EE-8CAB-D92661D3C019@patchspace.co.uk> <04414D52-7044-4CC5-88AB-89F06FF57DE8@gmail.com> <20080502051351.GC18800@uivelo.tilus.net> Message-ID: <1867A8FF-EF69-4017-972D-2F8D69FFD84D@patchspace.co.uk> On 2 May 2008, at 06:13, Tero Tilus wrote: > I can well imagine how you may end up not getting all the advantages > of BDD thru uncommenting process when you compare to clean BDD. But > uncommenting is definitely better than writing spec on top of existing > code, which in turn is _way_ better than not writing spec at all. Perhaps "uncommenting" is a bad description. What I do is write specs for the behaviour I want, and see what bits of the code (if any) do that. (Which will obviously be pretty similar to the what it does anyway.) What I *don't* do is pick a line of code and write a spec for it so I can uncomment it. I guess that's how you would run into trouble. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From rspec-users at kero.tmfweb.nl Fri May 2 15:57:22 2008 From: rspec-users at kero.tmfweb.nl (Kero) Date: Fri, 2 May 2008 21:57:22 +0200 Subject: [rspec-users] Return code for running stories Message-ID: <20080502195722.GE4320@bumblebee.m38c.nl> Hi all! Just wrote a few stories and committed code to a project of mine, then realized I made a mistake (with the commit, not the code or tests). It would be nice to put the script that runs the stories as a pre-commit hook, preventing the commit from succeeding if the stories fail. For that, I need to set the right exit code. In turn, I need to know he result of the tests. Given the prescription of running stories: with_steps_for :accounts do run 'path/to/file/with/story' end I see neither #with_steps_for, nor #run return anything resembling the result of the tests (which does not really surprise me). So how to get the success/pending/failure of the stories out? Should I write a formatter/listener that exit(1)s on failure? Bye, Kero. PS: I'm back after a few months, and -behold- it looks like I can use rspec for work, too :) From nabble.108 at xoxy.net Fri May 2 17:17:01 2008 From: nabble.108 at xoxy.net (Matt McNeil) Date: Fri, 2 May 2008 14:17:01 -0700 (PDT) Subject: [rspec-users] spec'ing calls to super (or other Ruby keywords) Message-ID: <17027929.post@talk.nabble.com> Hi there, How does one spec an invocation of a Ruby keyword, such as super in this case? class User < ActiveResource::Base # faking the ActiveRecord before/after_save observers def save super UserMailer.deliver_activation(self) if recently_activated? end end Does the solution look anything like the following? describe User do describe '#save' do it "should call save on the parent class" do # something.should_receive(:something) @user.save end end end Any thoughts? Thanks much, Matt -- View this message in context: http://www.nabble.com/spec%27ing-calls-to-super-%28or-other-Ruby-keywords%29-tp17027929p17027929.html Sent from the rspec-users mailing list archive at Nabble.com. From ben at benmabey.com Fri May 2 19:21:32 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 02 May 2008 17:21:32 -0600 Subject: [rspec-users] Return code for running stories In-Reply-To: <20080502195722.GE4320@bumblebee.m38c.nl> References: <20080502195722.GE4320@bumblebee.m38c.nl> Message-ID: <481BA1FC.2080507@benmabey.com> Kero wrote: > Hi all! > > Just wrote a few stories and committed code to a project of mine, > then realized I made a mistake (with the commit, not the code or > tests). It would be nice to put the script > that runs the stories as a pre-commit hook, preventing the commit > from succeeding if the stories fail. > > For that, I need to set the right exit code. > In turn, I need to know he result of the tests. > > Given the prescription of running stories: > with_steps_for :accounts do > run 'path/to/file/with/story' > end > I see neither #with_steps_for, nor #run return anything resembling > the result of the tests (which does not really surprise me). > > So how to get the success/pending/failure of the stories out? > Should I write a formatter/listener that exit(1)s on failure? > > Bye, > Kero. > > PS: I'm back after a few months, and -behold- it looks like I > can use rspec for work, too :) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Kero, This does not work in rspec 1.1.3. I submitted a patch to add this functionality and it has already been accepted. So you can upgrade to edge rspec to get this functionality or just apply my patch.: http://rspec.lighthouseapp.com/projects/5645/tickets/228-story-runner-exit-code -Ben From rspec-users at kero.tmfweb.nl Sat May 3 04:34:32 2008 From: rspec-users at kero.tmfweb.nl (Kero) Date: Sat, 3 May 2008 10:34:32 +0200 Subject: [rspec-users] Return code for running stories In-Reply-To: <481BA1FC.2080507@benmabey.com> References: <20080502195722.GE4320@bumblebee.m38c.nl> <481BA1FC.2080507@benmabey.com> Message-ID: <20080503083432.GF4320@bumblebee.m38c.nl> >> I see neither #with_steps_for, nor #run return anything resembling >> the result of the tests (which does not really surprise me). >> >> So how to get the success/pending/failure of the stories out? >> Should I write a formatter/listener that exit(1)s on failure? >> >> PS: I'm back after a few months, and -behold- it looks like I >> can use rspec for work, too :) > > This does not work in rspec 1.1.3. I submitted a patch to add this > functionality and it has already been accepted. So you can upgrade to > edge rspec to get this functionality or just apply my patch.: > http://rspec.lighthouseapp.com/projects/5645/tickets/228-story-runner-exit-code Ironic, this is about the first thing that happened when I stepped off the list ;) Also, I had looked at HEAD svn, but it seems I need a git repo. Good, I like git! OK, seems to work, great! thanks! Bye, Kero. From duelin.markers at gmail.com Sat May 3 10:49:11 2008 From: duelin.markers at gmail.com (John D. Hume) Date: Sat, 3 May 2008 10:49:11 -0400 Subject: [rspec-users] spec'ing calls to super (or other Ruby keywords) In-Reply-To: <17027929.post@talk.nabble.com> References: <17027929.post@talk.nabble.com> Message-ID: I believe calls to super are sufficiently internal to the Ruby interpreter that a mocking framework can't intercept them without doing separate implementations for separate Ruby interpreters (and likely even separate versions). I could be wrong, but even so I'd recommend a different approach. If your need is really as simple as your example, what you have is just a method that has to get two things done: the base save and one additional call. You can write one (or more) example for each of those two things without your spec knowing that one of those things gets done by calling super. (You might object that by spec'ing the base #save behavior you're spec'ing the framework. I'd say you're USING the framework to spec something your code does. To be clear, I'm not suggesting you spec every detail of what save does: just something to make sure the record actually lands in the db.) (Sidebar: Keep in mind the return value if you're really overriding #save like that.) If you're dead set on spec'ing that the super method gets called, there are a couple of hideous ways of doing it that will leak out of your example. Namely, you can (in your spec) redefine the method in the superclass and verify it gets called or (also in your spec, and this one's a little less leaky) have the class under test include a module that defines the same method and verify it gets called. Don't do either of those though (unless it's just to prove to yourself that they're possible). -hume. On Fri, May 2, 2008 at 5:17 PM, Matt McNeil wrote: > > Hi there, > > How does one spec an invocation of a Ruby keyword, such as super in this > case? > > class User < ActiveResource::Base > # faking the ActiveRecord before/after_save observers > def save > super > UserMailer.deliver_activation(self) if recently_activated? > end > end > > Does the solution look anything like the following? > > describe User do > describe '#save' do > it "should call save on the parent class" do > # something.should_receive(:something) > @user.save > end > end > end > > Any thoughts? > > Thanks much, > Matt > > -- > View this message in context: > http://www.nabble.com/spec%27ing-calls-to-super-%28or-other-Ruby-keywords%29-tp17027929p17027929.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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From duelin.markers at gmail.com Sat May 3 11:07:21 2008 From: duelin.markers at gmail.com (John D. Hume) Date: Sat, 3 May 2008 11:07:21 -0400 Subject: [rspec-users] BDD/Rails/Shoulda In-Reply-To: <1867A8FF-EF69-4017-972D-2F8D69FFD84D@patchspace.co.uk> References: <51538E8C-C42A-4AE0-9CE0-25D6560E3CE6@parkerhill.com> <7B749038-B6C8-42EE-8CAB-D92661D3C019@patchspace.co.uk> <04414D52-7044-4CC5-88AB-89F06FF57DE8@gmail.com> <20080502051351.GC18800@uivelo.tilus.net> <1867A8FF-EF69-4017-972D-2F8D69FFD84D@patchspace.co.uk> Message-ID: Even when working test/spec-first, when I'm pairing with someone who isn't experienced working that way, I find myself constantly saying "I'm pretty sure we don't need that yet." (I've just written the spec my pair is trying to get passing, so I know how little code we need.) If it happens then, it will certainly happen when that same developer is uncommenting code already written. Out of curiosity, Ashley, what size team are you working with where you don't see this problem? -hume. On Fri, May 2, 2008 at 12:06 PM, Ashley Moran wrote: > > On 2 May 2008, at 06:13, Tero Tilus wrote: > > I can well imagine how you may end up not getting all the advantages >> of BDD thru uncommenting process when you compare to clean BDD. But >> uncommenting is definitely better than writing spec on top of existing >> code, which in turn is _way_ better than not writing spec at all. >> > > Perhaps "uncommenting" is a bad description. What I do is write specs for > the behaviour I want, and see what bits of the code (if any) do that. > (Which will obviously be pretty similar to the what it does anyway.) What > I *don't* do is pick a line of code and write a spec for it so I can > uncomment it. I guess that's how you would run into trouble. > > 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: From hotfusionman at yahoo.com Sat May 3 11:09:13 2008 From: hotfusionman at yahoo.com (Al Chou) Date: Sat, 3 May 2008 08:09:13 -0700 (PDT) Subject: [rspec-users] spec'ing calls to super (or other Ruby keywords) Message-ID: <96663.58122.qm@web58707.mail.re1.yahoo.com> In the particular case of super, another approach, though perhaps not using the spec framework, would be to assert (a la Test::Unit) that your class is a subclass of the intended superclass. To be truly anal, also assert that the superclass has a method with the same name as the subclass's method of interest and that the subclass has that method, too. But all this seems deeply into the xUnit world, and far from the BDD way. Al ----- Original Message ---- From: John D. Hume To: rspec-users Sent: Saturday, May 3, 2008 7:49:11 AM Subject: Re: [rspec-users] spec'ing calls to super (or other Ruby keywords) I believe calls to super are sufficiently internal to the Ruby interpreter that a mocking framework can't intercept them without doing separate implementations for separate Ruby interpreters (and likely even separate versions). I could be wrong, but even so I'd recommend a different approach. If your need is really as simple as your example, what you have is just a method that has to get two things done: the base save and one additional call. You can write one (or more) example for each of those two things without your spec knowing that one of those things gets done by calling super. (You might object that by spec'ing the base #save behavior you're spec'ing the framework. I'd say you're USING the framework to spec something your code does. To be clear, I'm not suggesting you spec every detail of what save does: just something to make sure the record actually lands in the db.) (Sidebar: Keep in mind the return value if you're really overriding #save like that.) If you're dead set on spec'ing that the super method gets called, there are a couple of hideous ways of doing it that will leak out of your example. Namely, you can (in your spec) redefine the method in the superclass and verify it gets called or (also in your spec, and this one's a little less leaky) have the class under test include a module that defines the same method and verify it gets called. Don't do either of those though (unless it's just to prove to yourself that they're possible). -hume. On Fri, May 2, 2008 at 5:17 PM, Matt McNeil wrote: Hi there, How does one spec an invocation of a Ruby keyword, such as super in this case? class User < ActiveResource::Base # faking the ActiveRecord before/after_save observers def save super UserMailer.deliver_activation(self) if recently_activated? end end Does the solution look anything like the following? describe User do describe '#save' do it "should call save on the parent class" do # something.should_receive(:something) @user.save end end end Any thoughts? Thanks much, Matt ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ -------------- next part -------------- An HTML attachment was scrubbed... URL: From joe at pinkpucker.net Sat May 3 12:17:14 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Sat, 3 May 2008 09:17:14 -0700 Subject: [rspec-users] Date comparisons Message-ID: I occasionally get this error: 1) 'A puzzle once featured, should no longer be nominated' FAILED expected: Sun May 04 09:10:26 -0700 2008, got: Sun May 04 09:10:26 -0700 2008 (using ==) ./spec/models/puzzle_spec.rb:180: So, the dates looks the same to me. Any ideas for how to debug? Joe From steve.downtown at gmail.com Sat May 3 12:37:29 2008 From: steve.downtown at gmail.com (Steve Downey) Date: Sat, 3 May 2008 09:37:29 -0700 Subject: [rspec-users] Date comparisons In-Reply-To: References: Message-ID: <4fff79200805030937n5a65e308mb6854e9a3d8de545@mail.gmail.com> I've seen that one too. Maybe has to do with how equality is defined in the Time or DateTime class. I get around it by comparing the string-ified versions: foo.time.to_s.should == expected_time.to_s On Sat, May 3, 2008 at 9:17 AM, Joe Van Dyk wrote: > I occasionally get this error: > > 1) > 'A puzzle once featured, should no longer be nominated' FAILED > expected: Sun May 04 09:10:26 -0700 2008, > got: Sun May 04 09:10:26 -0700 2008 (using ==) > ./spec/models/puzzle_spec.rb:180: > > > > So, the dates looks the same to me. Any ideas for how to debug? > > Joe > _______________________________________________ > 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 michael at schuerig.de Sat May 3 13:06:49 2008 From: michael at schuerig.de (Michael Schuerig) Date: Sat, 3 May 2008 19:06:49 +0200 Subject: [rspec-users] Any news on the rSpec books? Message-ID: <200805031906.49313.michael@schuerig.de> I admit it, when it comes to rSpec, I'm lazy. I've made a few feeble attempts to use it, but for once I'm waiting for a book-length treatment. At least two books were announced, I think. Can anyone in the know please report on their progress? Thanks Michael -- Michael Schuerig mailto:michael at schuerig.de http://www.schuerig.de/michael/ From steve.downtown at gmail.com Sat May 3 13:25:04 2008 From: steve.downtown at gmail.com (Steve Downey) Date: Sat, 3 May 2008 10:25:04 -0700 Subject: [rspec-users] Any news on the rSpec books? In-Reply-To: <200805031906.49313.michael@schuerig.de> References: <200805031906.49313.michael@schuerig.de> Message-ID: <4fff79200805031025n24f0f01bqb48272d0e4e667c9@mail.gmail.com> I sent an inquiry to Prag Bookshelf but didn't hear anything -- saw something online that led me to believe they were the publisher. PeepCode has several RSpec screencasts. On Sat, May 3, 2008 at 10:06 AM, Michael Schuerig wrote: > > I admit it, when it comes to rSpec, I'm lazy. I've made a few feeble > attempts to use it, but for once I'm waiting for a book-length > treatment. At least two books were announced, I think. Can anyone in > the know please report on their progress? > > Thanks > Michael > > -- > Michael Schuerig > mailto:michael at schuerig.de > http://www.schuerig.de/michael/ > _______________________________________________ > 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 dchelimsky at gmail.com Sat May 3 13:38:02 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 3 May 2008 12:38:02 -0500 Subject: [rspec-users] Any news on the rSpec books? In-Reply-To: <200805031906.49313.michael@schuerig.de> References: <200805031906.49313.michael@schuerig.de> Message-ID: There are three I know about, one of which I'm working on (Prag Bookshelf). I can tell you the one I'm working on will be in beta sometime in the next few months, but I can't really be any more specific than that right now. I can assure you that as things get more specific I'll be blogging about it like crazy. Cheers, David On May 3, 2008, at 12:06 PM, Michael Schuerig wrote: > > I admit it, when it comes to rSpec, I'm lazy. I've made a few feeble > attempts to use it, but for once I'm waiting for a book-length > treatment. At least two books were announced, I think. Can anyone in > the know please report on their progress? > > Thanks > Michael > > -- > Michael Schuerig > mailto:michael at schuerig.de > http://www.schuerig.de/michael/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rick.denatale at gmail.com Sat May 3 13:51:43 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sat, 3 May 2008 13:51:43 -0400 Subject: [rspec-users] Date comparisons In-Reply-To: References: Message-ID: On Sat, May 3, 2008 at 12:17 PM, Joe Van Dyk wrote: > I occasionally get this error: > > 1) > 'A puzzle once featured, should no longer be nominated' FAILED > expected: Sun May 04 09:10:26 -0700 2008, > got: Sun May 04 09:10:26 -0700 2008 (using ==) > ./spec/models/puzzle_spec.rb:180: > > > > So, the dates looks the same to me. Any ideas for how to debug? Just because too objects have the same to_s representation don't mean they are equal: Are these, perhaps times rather than dates? k$ irb irb(main):001:0> Time.now == Time.now => false irb(main):002:0> a, b = Time.now, Time.now => [Sat May 03 12:23:12 -0400 2008, Sat May 03 12:23:12 -0400 2008] irb(main):003:0> a == b => false This is a similar issue to Floats where there's more precision than the exernal representation shows. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From steve.downtown at gmail.com Sat May 3 14:12:16 2008 From: steve.downtown at gmail.com (Steve Downey) Date: Sat, 3 May 2008 11:12:16 -0700 Subject: [rspec-users] Date comparisons In-Reply-To: References: Message-ID: <4fff79200805031112p28571687wcc57919c438aed1f@mail.gmail.com> > > Just because too objects have the same to_s representation don't mean > they are equal: The important equality in this case is what matters to the tester. > > This is a similar issue to Floats where there's more precision than > the exernal representation shows. > Is there more precision than seconds in a Time instance? irb(main):006:0> a,b = Time.now, Time.now => [Sat May 03 11:06:31 -0700 2008, Sat May 03 11:06:31 -0700 2008] irb(main):007:0> puts a.to_i, b.to_i 1209837991 1209837991 => nil -------------- next part -------------- An HTML attachment was scrubbed... URL: From philodespotos at gmail.com Sat May 3 14:16:48 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Sat, 3 May 2008 13:16:48 -0500 Subject: [rspec-users] Date comparisons In-Reply-To: <4fff79200805031112p28571687wcc57919c438aed1f@mail.gmail.com> References: <4fff79200805031112p28571687wcc57919c438aed1f@mail.gmail.com> Message-ID: <60f3810c0805031116g27b49100le3620e48d6c89f13@mail.gmail.com> On Sat, May 3, 2008 at 1:12 PM, Steve Downey wrote: > Is there more precision than seconds in a Time instance? > > irb(main):006:0> a,b = Time.now, Time.now > => [Sat May 03 11:06:31 -0700 2008, Sat May 03 11:06:31 -0700 2008] > irb(main):007:0> puts a.to_i, b.to_i > 1209837991 > 1209837991 > => nil This came up this morning in #rspec; Time tracks microseconds which blows up equality: >> a, b = Time.now, Time.now => [Sat May 03 13:15:31 -0500 2008, Sat May 03 13:15:31 -0500 2008] >> a == b => false >> [a.usec, b.usec] => [93308, 93309] Because of this, I tend to use 'should be_between()' when handling times; someone else suggested the .to_i trick which is probably closer to what is intended, but for some reason I find it confusing. k From omen.king at gmail.com Sat May 3 15:18:55 2008 From: omen.king at gmail.com (Andrew Brown) Date: Sat, 3 May 2008 15:18:55 -0400 Subject: [rspec-users] Everyone Using Rspec Autotest? Message-ID: I haven't been spec'ing lately, but been hopping back on and adding autotest. However I get an error: http://pastie.caboo.se/177538/wrap I also noticed a post by Scott and there was mention of rspec_autotest. Is this is what everyone is using? http://svn.caldersphere.net/svn/main/plugins/rspec_autotest/ From jarkko at jlaine.net Sat May 3 15:21:54 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Sat, 3 May 2008 22:21:54 +0300 Subject: [rspec-users] Everyone Using Rspec Autotest? In-Reply-To: References: Message-ID: <3A19E407-7D71-4359-B252-5AE5F54D30EF@jlaine.net> On 3.5.2008, at 22.18, Andrew Brown wrote: > I haven't been spec'ing lately, but been hopping back on and adding > autotest. > However I get an error: > > http://pastie.caboo.se/177538/wrap > > I also noticed a post by Scott and there was mention of > rspec_autotest. > Is this is what everyone is using? I'm just using the one that comes with ZenTest. No need for anything else, just run 'autotest' in the root of your Rails app. //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: From omen.king at gmail.com Sat May 3 15:36:58 2008 From: omen.king at gmail.com (Andrew Brown) Date: Sat, 3 May 2008 15:36:58 -0400 Subject: [rspec-users] Everyone Using Rspec Autotest? In-Reply-To: <3A19E407-7D71-4359-B252-5AE5F54D30EF@jlaine.net> References: <3A19E407-7D71-4359-B252-5AE5F54D30EF@jlaine.net> Message-ID: <9D3C4788-594B-404B-9188-82CFEC1E4EE3@gmail.com> I will, once I resolve the error. On 3-May-08, at 3:21 PM, Jarkko Laine wrote: > > On 3.5.2008, at 22.18, Andrew Brown wrote: > >> I haven't been spec'ing lately, but been hopping back on and adding >> autotest. >> However I get an error: >> >> http://pastie.caboo.se/177538/wrap >> >> I also noticed a post by Scott and there was mention of >> rspec_autotest. >> Is this is what everyone is using? > > I'm just using the one that comes with ZenTest. No need for anything > else, just run 'autotest' in the root of your Rails app. > > //jarkko > > -- > 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 From shingler at gmail.com Sat May 3 16:08:25 2008 From: shingler at gmail.com (steven shingler) Date: Sat, 3 May 2008 21:08:25 +0100 Subject: [rspec-users] silly partial qu Message-ID: hi all, i'm just trying to check a partial has been rendered, by using: response.template.should_receive(:render).with(:partial => "tasks/list") this passes, even if I put something bogus in the partial name, such as: response.template.should_receive(:render).with(:partial => "___tassdfsdfks/list") does anyone know why this doesn't fail? is this the wrong way to simply check a partial is being rendered? am running this as a story step. thanks, steven From mailing_lists at railsnewbie.com Sat May 3 16:44:01 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 3 May 2008 16:44:01 -0400 Subject: [rspec-users] Everyone Using Rspec Autotest? In-Reply-To: References: Message-ID: On May 3, 2008, at 3:18 PM, Andrew Brown wrote: > I haven't been spec'ing lately, but been hopping back on and adding > autotest. > However I get an error: > > http://pastie.caboo.se/177538/wrap > > I also noticed a post by Scott and there was mention of > rspec_autotest. > Is this is what everyone is using? > > http://svn.caldersphere.net/svn/main/plugins/rspec_autotest/ > Update your gems - use Zentest 3.9.2. (3.9.1 might work too, but 3.8.x doesn't) Scott From omen.king at gmail.com Sat May 3 16:49:41 2008 From: omen.king at gmail.com (Andrew Brown) Date: Sat, 3 May 2008 16:49:41 -0400 Subject: [rspec-users] Everyone Using Rspec Autotest? In-Reply-To: References: Message-ID: <72B68BFE-1FBC-4FB1-9D42-D8A419909E0D@gmail.com> Thanks Scott that fixed it. Forgot to do the obvious. On 3-May-08, at 4:44 PM, Scott Taylor wrote: > > On May 3, 2008, at 3:18 PM, Andrew Brown wrote: > >> I haven't been spec'ing lately, but been hopping back on and adding >> autotest. >> However I get an error: >> >> http://pastie.caboo.se/177538/wrap >> >> I also noticed a post by Scott and there was mention of >> rspec_autotest. >> Is this is what everyone is using? >> >> http://svn.caldersphere.net/svn/main/plugins/rspec_autotest/ >> > > Update your gems - use Zentest 3.9.2. (3.9.1 might work too, but > 3.8.x doesn't) > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Sat May 3 16:51:51 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 3 May 2008 16:51:51 -0400 Subject: [rspec-users] spec'ing calls to super (or other Ruby keywords) In-Reply-To: <96663.58122.qm@web58707.mail.re1.yahoo.com> References: <96663.58122.qm@web58707.mail.re1.yahoo.com> Message-ID: <6CEE24A1-451C-422B-BEAF-835AEB8620F9@railsnewbie.com> On May 3, 2008, at 11:09 AM, Al Chou wrote: > In the particular case of super, another approach, though perhaps > not using the spec framework, would be to assert (a la Test::Unit) > that your class is a subclass of the intended superclass. To be > truly anal, also assert that the superclass has a method with the > same name as the subclass's method of interest and that the subclass > has that method, too. But all this seems deeply into the xUnit > world, and far from the BDD way. > > Al The truth is that you shouldn't be spec'ing calls to the super "method", but rather the behaviour of super. One quick way to do this is as so: [BaseClass, Subclass].each { |klass| it "should do whatever super does" do klass.new.foo_bar.should == :baz end end Your original example is a little trickier, because you didn't write the base class, and you probably aren't going to spec it out. There's obviously great complexity in that call to super. Now you know why none of us like writing specs against rails apps. Scott > > > ----- Original Message ---- > From: John D. Hume > To: rspec-users > Sent: Saturday, May 3, 2008 7:49:11 AM > Subject: Re: [rspec-users] spec'ing calls to super (or other Ruby > keywords) > > I believe calls to super are sufficiently internal to the Ruby > interpreter that a mocking framework can't intercept them without > doing separate implementations for separate Ruby interpreters (and > likely even separate versions). I could be wrong, but even so I'd > recommend a different approach. > > If your need is really as simple as your example, what you have is > just a method that has to get two things done: the base save and one > additional call. You can write one (or more) example for each of > those two things without your spec knowing that one of those things > gets done by calling super. (You might object that by spec'ing the > base #save behavior you're spec'ing the framework. I'd say you're > USING the framework to spec something your code does. To be clear, > I'm not suggesting you spec every detail of what save does: just > something to make sure the record actually lands in the db.) > > (Sidebar: Keep in mind the return value if you're really overriding > #save like that.) > > If you're dead set on spec'ing that the super method gets called, > there are a couple of hideous ways of doing it that will leak out of > your example. Namely, you can (in your spec) redefine the method in > the superclass and verify it gets called or (also in your spec, and > this one's a little less leaky) have the class under test include a > module that defines the same method and verify it gets called. > Don't do either of those though (unless it's just to prove to > yourself that they're possible). > > -hume. > > > On Fri, May 2, 2008 at 5:17 PM, Matt McNeil > wrote: > > Hi there, > > How does one spec an invocation of a Ruby keyword, such as super in > this > case? > > class User < ActiveResource::Base > # faking the ActiveRecord before/after_save observers > def save > super > UserMailer.deliver_activation(self) if recently_activated? > end > end > > Does the solution look anything like the following? > > describe User do > describe '#save' do > it "should call save on the parent class" do > # something.should_receive(:something) > @user.save > end > end > end > > Any thoughts? > > Thanks much, > Matt > > Be a better friend, newshound, and know-it-all with Yahoo! Mobile. > Try it now._______________________________________________ > 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 mailing_lists at railsnewbie.com Sat May 3 16:53:42 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 3 May 2008 16:53:42 -0400 Subject: [rspec-users] Date comparisons In-Reply-To: <60f3810c0805031116g27b49100le3620e48d6c89f13@mail.gmail.com> References: <4fff79200805031112p28571687wcc57919c438aed1f@mail.gmail.com> <60f3810c0805031116g27b49100le3620e48d6c89f13@mail.gmail.com> Message-ID: On May 3, 2008, at 2:16 PM, Kyle Hargraves wrote: > On Sat, May 3, 2008 at 1:12 PM, Steve Downey > wrote: >> Is there more precision than seconds in a Time instance? >> >> irb(main):006:0> a,b = Time.now, Time.now >> => [Sat May 03 11:06:31 -0700 2008, Sat May 03 11:06:31 -0700 2008] >> irb(main):007:0> puts a.to_i, b.to_i >> 1209837991 >> 1209837991 >> => nil > > This came up this morning in #rspec; Time tracks microseconds which > blows up equality: > >>> a, b = Time.now, Time.now > => [Sat May 03 13:15:31 -0500 2008, Sat May 03 13:15:31 -0500 2008] >>> a == b > => false >>> [a.usec, b.usec] > => [93308, 93309] > > Because of this, I tend to use 'should be_between()' when handling > times; someone else suggested the .to_i trick which is probably closer > to what is intended, but for some reason I find it confusing. If I'm in a rails project, I like to use to_s(:db) to compare the times - that's how they are stored in the database. Any greater precision (at least in MySQL) gets lost when the datetime is read out of the database. Scott From mailing_lists at railsnewbie.com Sat May 3 17:01:51 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 3 May 2008 17:01:51 -0400 Subject: [rspec-users] BDD/Rails/Shoulda In-Reply-To: References: <51538E8C-C42A-4AE0-9CE0-25D6560E3CE6@parkerhill.com> <7B749038-B6C8-42EE-8CAB-D92661D3C019@patchspace.co.uk> <04414D52-7044-4CC5-88AB-89F06FF57DE8@gmail.com> <20080502051351.GC18800@uivelo.tilus.net> <1867A8FF-EF69-4017-972D-2F8D69FFD84D@patchspace.co.uk> Message-ID: On May 3, 2008, at 11:07 AM, John D. Hume wrote: > Even when working test/spec-first, when I'm pairing with someone who > isn't experienced working that way, I find myself constantly saying > "I'm pretty sure we don't need that yet." (I've just written the > spec my pair is trying to get passing, so I know how little code we > need.) If it happens then, it will certainly happen when that same > developer is uncommenting code already written. > > Out of curiosity, Ashley, what size team are you working with where > you don't see this problem? > -hume. I remember a joke that Aslak mentioned a while back ago on this list: He had a friend (or co-worker) who wanted to write a tool which would delete every line of code which didn't get covered with rcov. I found that remark funny because Aslak didn't know if his co-worker was joking or not. Now that I think about it more, it probably wouldn't be a bad idea to have such a tool like this, even if it was just for didactic purposes. Scott > > > > On Fri, May 2, 2008 at 12:06 PM, Ashley Moran > wrote: > > On 2 May 2008, at 06:13, Tero Tilus wrote: > > I can well imagine how you may end up not getting all the advantages > of BDD thru uncommenting process when you compare to clean BDD. But > uncommenting is definitely better than writing spec on top of existing > code, which in turn is _way_ better than not writing spec at all. > > Perhaps "uncommenting" is a bad description. What I do is write > specs for the behaviour I want, and see what bits of the code (if > any) do that. (Which will obviously be pretty similar to the what > it does anyway.) What I *don't* do is pick a line of code and write > a spec for it so I can uncomment it. I guess that's how you would > run into trouble. > > > 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From rick.denatale at gmail.com Sat May 3 18:17:38 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sat, 3 May 2008 18:17:38 -0400 Subject: [rspec-users] silly partial qu In-Reply-To: References: Message-ID: On Sat, May 3, 2008 at 4:08 PM, steven shingler wrote: > hi all, > > i'm just trying to check a partial has been rendered, by using: > response.template.should_receive(:render).with(:partial => "tasks/list") > > this passes, even if I put something bogus in the partial name, such as: > response.template.should_receive(:render).with(:partial => > "___tassdfsdfks/list") > > does anyone know why this doesn't fail? > is this the wrong way to simply check a partial is being rendered? > am running this as a story step. I'm not sure how this is working to begin with. Where is this expectation in the flow of the code? It would seem to need to be before the request since it's a should_receive But then what's response at this point? And what's response.template? It's the controller, not the template which receives the render call. You say that this is in a story step? I've got a hunch that the step is'nt actually matching and therfore not getting run, which would explain why the assertion never fails. If you're doing this as a full stack rails integration story, I don't believe that you've got access to the controller, and this level of specification doesn't belong here but rather in a controller spec, where you might want to use expect_render instead of should_receive(:render) as well. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From hotfusionman at yahoo.com Sat May 3 18:58:04 2008 From: hotfusionman at yahoo.com (Al Chou) Date: Sat, 3 May 2008 15:58:04 -0700 (PDT) Subject: [rspec-users] spec'ing calls to super (or other Ruby keywords) Message-ID: <301749.35445.qm@web58709.mail.re1.yahoo.com> Funny, I mostly like writing RSpec specs for Rails, aside from the fact that it sometimes takes me a while to figure out exactly how and what I need to write to specify what I want to specify. In any case, I agree that the spec should specify what the method achieves, not the fact that the method calls super. Al ----- Original Message ---- From: Scott Taylor To: rspec-users Sent: Saturday, May 3, 2008 1:51:51 PM Subject: Re: [rspec-users] spec'ing calls to super (or other Ruby keywords) On May 3, 2008, at 11:09 AM, Al Chou wrote: In the particular case of super, another approach, though perhaps not using the spec framework, would be to assert (a la Test::Unit) that your class is a subclass of the intended superclass. To be truly anal, also assert that the superclass has a method with the same name as the subclass's method of interest and that the subclass has that method, too. But all this seems deeply into the xUnit world, and far from the BDD way. Al The truth is that you shouldn't be spec'ing calls to the super "method", but rather the behaviour of super. One quick way to do this is as so: [BaseClass, Subclass].each { |klass| it "should do whatever super does" do klass.new.foo_bar.should == :baz end end Your original example is a little trickier, because you didn't write the base class, and you probably aren't going to spec it out. There's obviously great complexity in that call to super. Now you know why none of us like writing specs against rails apps. Scott ----- Original Message ---- From: John D. Hume To: rspec-users Sent: Saturday, May 3, 2008 7:49:11 AM Subject: Re: [rspec-users] spec'ing calls to super (or other Ruby keywords) I believe calls to super are sufficiently internal to the Ruby interpreter that a mocking framework can't intercept them without doing separate implementations for separate Ruby interpreters (and likely even separate versions). I could be wrong, but even so I'd recommend a different approach. If your need is really as simple as your example, what you have is just a method that has to get two things done: the base save and one additional call. You can write one (or more) example for each of those two things without your spec knowing that one of those things gets done by calling super. (You might object that by spec'ing the base #save behavior you're spec'ing the framework. I'd say you're USING the framework to spec something your code does. To be clear, I'm not suggesting you spec every detail of what save does: just something to make sure the record actually lands in the db.) (Sidebar: Keep in mind the return value if you're really overriding #save like that.) If you're dead set on spec'ing that the super method gets called, there are a couple of hideous ways of doing it that will leak out of your example. Namely, you can (in your spec) redefine the method in the superclass and verify it gets called or (also in your spec, and this one's a little less leaky) have the class under test include a module that defines the same method and verify it gets called. Don't do either of those though (unless it's just to prove to yourself that they're possible). -hume. On Fri, May 2, 2008 at 5:17 PM, Matt McNeil wrote: Hi there, How does one spec an invocation of a Ruby keyword, such as super in this case? class User < ActiveResource::Base # faking the ActiveRecord before/after_save observers def save super UserMailer.deliver_activation(self) if recently_activated? end end Does the solution look anything like the following? describe User do describe '#save' do it "should call save on the parent class" do # something.should_receive(:something) @user.save end end end Any thoughts? Thanks much, Matt ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat May 3 23:08:09 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 3 May 2008 22:08:09 -0500 Subject: [rspec-users] BDD/Rails/Shoulda In-Reply-To: References: <51538E8C-C42A-4AE0-9CE0-25D6560E3CE6@parkerhill.com> <7B749038-B6C8-42EE-8CAB-D92661D3C019@patchspace.co.uk> <04414D52-7044-4CC5-88AB-89F06FF57DE8@gmail.com> <20080502051351.GC18800@uivelo.tilus.net> <1867A8FF-EF69-4017-972D-2F8D69FFD84D@patchspace.co.uk> Message-ID: <5F3F85D8-D2D0-4238-B5B4-B17C2C101587@gmail.com> On May 3, 2008, at 4:01 PM, Scott Taylor wrote: > I remember a joke that Aslak mentioned a while back ago on this > list: He had a friend (or co-worker) who wanted to write a tool > which would delete every line of code which didn't get covered with > rcov. I found that remark funny because Aslak didn't know if his co- > worker was joking or not. I think you've got the story mixed up a bit here. Aslak DID write a tool called Guantanamo that does just what you propose, for java, not Ruby: http://docs.codehaus.org/display/ASH/Guantanamo > > Now that I think about it more, it probably wouldn't be a bad idea > to have such a tool like this, even if it was just for didactic > purposes. > > Scott From shingler at gmail.com Sun May 4 10:16:33 2008 From: shingler at gmail.com (steven shingler) Date: Sun, 4 May 2008 15:16:33 +0100 Subject: [rspec-users] silly partial qu In-Reply-To: References: Message-ID: Hi Rick, Thanks for your reply. You are right that this step is basically testing the basic actions of a controller, and is being run as part of a story_with_steps stack. The step itself is definitely being hit, because I have a: response.should have_tag('li', @title) ...in the same step, and that is working nicely. This step is called right after clicking an Update button, which is a standard rails scaffold and does a: redirect_to(@task) - this causes a partial to be rendered to the screen as part of my default layout, and I was hoping to be able to verify that the partial loaded. What would fit my brain better, would be: response.should render_partial("tasks/list") ...but that isn't available :) I hope that is clearer - I am quite new to the world of rspec. If you can shed any more light that would be really great. Thanks, Steven On Sat, May 3, 2008 at 11:17 PM, Rick DeNatale wrote: > > On Sat, May 3, 2008 at 4:08 PM, steven shingler wrote: > > hi all, > > > > i'm just trying to check a partial has been rendered, by using: > > response.template.should_receive(:render).with(:partial => "tasks/list") > > > > this passes, even if I put something bogus in the partial name, such as: > > response.template.should_receive(:render).with(:partial => > > "___tassdfsdfks/list") > > > > does anyone know why this doesn't fail? > > is this the wrong way to simply check a partial is being rendered? > > am running this as a story step. > > I'm not sure how this is working to begin with. > > Where is this expectation in the flow of the code? It would seem to > need to be before the request since it's a should_receive > But then what's response at this point? > And what's response.template? > > It's the controller, not the template which receives the render call. > > You say that this is in a story step? I've got a hunch that the step > is'nt actually matching and therfore not getting run, which would > explain why the assertion never fails. > > If you're doing this as a full stack rails integration story, I don't > believe that you've got access to the controller, and this level of > specification doesn't belong here but rather in a controller spec, > where you might want to use expect_render instead of > should_receive(:render) as well. > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.denatale at gmail.com Sun May 4 10:36:31 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sun, 4 May 2008 10:36:31 -0400 Subject: [rspec-users] silly partial qu In-Reply-To: References: Message-ID: On Sun, May 4, 2008 at 10:16 AM, steven shingler wrote: > Hi Rick, > Thanks for your reply. > You are right that this step is basically testing the basic actions of > a controller, and is being run as part of a story_with_steps stack. > The step itself is definitely being hit, because I have a: > response.should have_tag('li', @title) > ...in the same step, and that is working nicely. > > This step is called right after clicking an Update button, which is a > standard rails scaffold and does a: redirect_to(@task) - this causes a > partial to be rendered to the screen as part of my default layout, and > I was hoping to be able to verify that the partial loaded. > > What would fit my brain better, would be: > response.should render_partial("tasks/list") Except that responses don't render anything, controllers do which result in the body of the response. Also even if this were controller.should render_partial... I can't see how this would work, since it seems to involve backwards time travel. In a controller spec you use controller.expect_render(:partial => ...) BEFORE doing a get/post etc. It works like x.should_receive(:foo) it's something which needs to be set up before something happens. > ...but that isn't available :) > > I hope that is clearer - I am quite new to the world of rspec. > If you can shed any more light that would be really great. Rails integration testing happens in the context of a simulated browser. It's awkward, if indeed it's possible at all, to instrument the mechanisms of controllers and templates here. This is normally done in controller and/or view specs. At the story/integration level, I think you really want to be looking at the result of the http requests, which means you should be setting expectations about what's in the response rather than how the response is going to be constructed. So instead of trying to determine if the tasks_list partial is being rendered, why not do something like having the partial generate evidence that it was invoked in the output, for example it might generate a div or ol or whatever which contains the tasks list which has a particular dom id, and then use response.should have_tag to verify that the task list is in the response? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From shingler at gmail.com Sun May 4 11:32:45 2008 From: shingler at gmail.com (steven shingler) Date: Sun, 4 May 2008 16:32:45 +0100 Subject: [rspec-users] silly partial qu In-Reply-To: References: Message-ID: Hi Rick - Thanks again. Cool - I see what you mean about what the story steps should get involved with, and what should be left to the specs. In that case, my response.should have_tag('li', @title) is a reasonable test, and I'll leave it at that! All the best, Steven On Sun, May 4, 2008 at 3:36 PM, Rick DeNatale wrote: > On Sun, May 4, 2008 at 10:16 AM, steven shingler wrote: > > Hi Rick, > > Thanks for your reply. > > You are right that this step is basically testing the basic actions of > > a controller, and is being run as part of a story_with_steps stack. > > The step itself is definitely being hit, because I have a: > > response.should have_tag('li', @title) > > ...in the same step, and that is working nicely. > > > > This step is called right after clicking an Update button, which is a > > standard rails scaffold and does a: redirect_to(@task) - this causes a > > partial to be rendered to the screen as part of my default layout, and > > I was hoping to be able to verify that the partial loaded. > > > > What would fit my brain better, would be: > > response.should render_partial("tasks/list") > > Except that responses don't render anything, controllers do which > result in the body of the response. > > Also even if this were > > controller.should render_partial... > > I can't see how this would work, since it seems to involve backwards > time travel. In a controller spec you use > > controller.expect_render(:partial => ...) > > BEFORE doing a get/post etc. It works like x.should_receive(:foo) > it's something which needs to be set up before something happens. > > > > ...but that isn't available :) > > > > I hope that is clearer - I am quite new to the world of rspec. > > If you can shed any more light that would be really great. > > Rails integration testing happens in the context of a simulated > browser. It's awkward, if indeed it's possible at all, to instrument > the mechanisms of controllers and templates here. This is normally > done in controller and/or view specs. > > At the story/integration level, I think you really want to be looking > at the result of the http requests, which means you should be setting > expectations about what's in the response rather than how the response > is going to be constructed. > > So instead of trying to determine if the tasks_list partial is being > rendered, why not do something like having the partial generate > evidence that it was invoked in the output, for example it might > generate a div or ol or whatever which contains the tasks list which > has a particular dom id, and then use response.should have_tag to > verify that the task list is in the response? > > -- > > > 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 Sun May 4 12:30:09 2008 From: matt at mattberther.com (Matt Berther) Date: Sun, 4 May 2008 10:30:09 -0600 Subject: [rspec-users] Everyone Using Rspec Autotest? In-Reply-To: <9D3C4788-594B-404B-9188-82CFEC1E4EE3@gmail.com> References: <3A19E407-7D71-4359-B252-5AE5F54D30EF@jlaine.net> <9D3C4788-594B-404B-9188-82CFEC1E4EE3@gmail.com> Message-ID: <6F869410-14D0-48AF-8846-9B01901BC8FE@mattberther.com> Hi Andrew, I've been using rspactor (the command line version) and really prefer it to autotest. If you're using a Mac, you may want to look at this. -- Matt Berther http://www.mattberther.com On May 3, 2008, at 1:36 PM, Andrew Brown wrote: > I will, once I resolve the error. > > > On 3-May-08, at 3:21 PM, Jarkko Laine wrote: > >> >> On 3.5.2008, at 22.18, Andrew Brown wrote: >> >>> I haven't been spec'ing lately, but been hopping back on and >>> adding autotest. >>> However I get an error: >>> >>> http://pastie.caboo.se/177538/wrap >>> >>> I also noticed a post by Scott and there was mention of >>> rspec_autotest. >>> Is this is what everyone is using? >> >> I'm just using the one that comes with ZenTest. No need for >> anything else, just run 'autotest' in the root of your Rails app. >> >> //jarkko >> >> -- >> 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 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From omen.king at gmail.com Sun May 4 12:40:00 2008 From: omen.king at gmail.com (Andrew Brown) Date: Sun, 4 May 2008 12:40:00 -0400 Subject: [rspec-users] Everyone Using Rspec Autotest? In-Reply-To: <6F869410-14D0-48AF-8846-9B01901BC8FE@mattberther.com> References: <3A19E407-7D71-4359-B252-5AE5F54D30EF@jlaine.net> <9D3C4788-594B-404B-9188-82CFEC1E4EE3@gmail.com> <6F869410-14D0-48AF-8846-9B01901BC8FE@mattberther.com> Message-ID: I am and I will On 4-May-08, at 12:30 PM, Matt Berther wrote: > rspactor From rick.denatale at gmail.com Sun May 4 20:39:28 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Sun, 4 May 2008 20:39:28 -0400 Subject: [rspec-users] Do message expectations work in story steps? Message-ID: I've never tried to use them myself, but another list member brought this up in another thread. He was using a message expectation in a story step, and couldn't get it to fail. Looking at what he was doing, it didn't look to me that it would ever succeed, which got me thinking. Message expectations are implemented in rspec by asking the mock framework to verify them after each example by calling verify_mocks_for_rspec. This seems to be the only place where this is called, so I've got my doubts that message expectations ever get verified when a story is run. Now, it's not clear just when in a story a message expectation should be tested, and it's probably the case that they shouldn't be used/supported in stories. If so should this be documented somewhere, or is it already? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ From cwdinfo at gmail.com Sun May 4 23:42:15 2008 From: cwdinfo at gmail.com (s.ross) Date: Sun, 4 May 2008 20:42:15 -0700 Subject: [rspec-users] Date comparisons In-Reply-To: References: Message-ID: Hi-- On May 3, 2008, at 9:17 AM, Joe Van Dyk wrote: > I occasionally get this error: > > 1) > 'A puzzle once featured, should no longer be nominated' FAILED > expected: Sun May 04 09:10:26 -0700 2008, > got: Sun May 04 09:10:26 -0700 2008 (using ==) > ./spec/models/puzzle_spec.rb:180: > > > > So, the dates looks the same to me. Any ideas for how to debug? > > Joe I monkeypatched DateTime (aieeeeee!) to get this effect. A custom matcher is probably a better solution. Here's the monkeypatch: require File.dirname(__FILE__) + '/../spec_helper' class DateTime def close?(other_date, difference) (other_date.to_time.to_i - DateTime.now.to_time.to_i).abs < difference end end #Delete this context and add some real ones context "should be able to create a project viewer" do fixtures :project_viewers specify "fixtures should load two ProjectViewers" do pb = ProjectViewer.create(:comments => 'a comment', :last_viewed_at => DateTime.now) pb.last_viewed_at.should_be_close(DateTime.now, 100) end end From aslak.hellesoy at gmail.com Mon May 5 02:07:30 2008 From: aslak.hellesoy at gmail.com (=?UTF-8?Q?Aslak_Helles=C3=B8y?=) Date: Mon, 5 May 2008 08:07:30 +0200 Subject: [rspec-users] Date comparisons In-Reply-To: References: Message-ID: <1EF80BAF-A6A7-4D68-B09E-F412DD0B14D7@gmail.com> If your code uses Date#now, always make sure you stub it in your specs. Always. On 5. mai. 2008, at 05.42, "s.ross" wrote: > Hi-- > > On May 3, 2008, at 9:17 AM, Joe Van Dyk wrote: > >> I occasionally get this error: >> >> 1) >> 'A puzzle once featured, should no longer be nominated' FAILED >> expected: Sun May 04 09:10:26 -0700 2008, >> got: Sun May 04 09:10:26 -0700 2008 (using ==) >> ./spec/models/puzzle_spec.rb:180: >> >> >> >> So, the dates looks the same to me. Any ideas for how to debug? >> >> Joe > > I monkeypatched DateTime (aieeeeee!) to get this effect. A custom > matcher is probably a better solution. Here's the monkeypatch: > > require File.dirname(__FILE__) + '/../spec_helper' > > class DateTime > def close?(other_date, difference) > (other_date.to_time.to_i - DateTime.now.to_time.to_i).abs < > difference > end > end > > #Delete this context and add some real ones > context "should be able to create a project viewer" do > fixtures :project_viewers > > specify "fixtures should load two ProjectViewers" do > pb = ProjectViewer.create(:comments => 'a > comment', :last_viewed_at => DateTime.now) > pb.last_viewed_at.should_be_close(DateTime.now, 100) > end > end > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Mon May 5 04:02:49 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 5 May 2008 01:02:49 -0700 Subject: [rspec-users] Date comparisons In-Reply-To: <1EF80BAF-A6A7-4D68-B09E-F412DD0B14D7@gmail.com> References: <1EF80BAF-A6A7-4D68-B09E-F412DD0B14D7@gmail.com> Message-ID: <810a540e0805050102m6ee3742k7935987432263e97@mail.gmail.com> Yes, that was my first idea as well. The Time class is a little fucked up in that < a, b = Time.now, Time.now < a == b #=> false So if you're using Time anywhere, you really ought to be stubbing it. "always" :) Pat On Sun, May 4, 2008 at 11:07 PM, Aslak Helles?y wrote: > If your code uses Date#now, always make sure you stub it in your specs. > Always. > > > > On 5. mai. 2008, at 05.42, "s.ross" wrote: > > > > Hi-- > > > > On May 3, 2008, at 9:17 AM, Joe Van Dyk wrote: > > > > > > > I occasionally get this error: > > > > > > 1) > > > 'A puzzle once featured, should no longer be nominated' FAILED > > > expected: Sun May 04 09:10:26 -0700 2008, > > > got: Sun May 04 09:10:26 -0700 2008 (using ==) > > > ./spec/models/puzzle_spec.rb:180: > > > > > > > > > > > > So, the dates looks the same to me. Any ideas for how to debug? > > > > > > Joe > > > > > > > I monkeypatched DateTime (aieeeeee!) to get this effect. A custom matcher > is probably a better solution. Here's the monkeypatch: > > > > require File.dirname(__FILE__) + '/../spec_helper' > > > > class DateTime > > def close?(other_date, difference) > > (other_date.to_time.to_i - DateTime.now.to_time.to_i).abs < > difference > > end > > end > > > > #Delete this context and add some real ones > > context "should be able to create a project viewer" do > > fixtures :project_viewers > > > > specify "fixtures should load two ProjectViewers" do > > pb = ProjectViewer.create(:comments => 'a comment', :last_viewed_at => > DateTime.now) > > pb.last_viewed_at.should_be_close(DateTime.now, 100) > > end > > end > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.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 jarkko at jlaine.net Mon May 5 04:12:43 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Mon, 5 May 2008 11:12:43 +0300 Subject: [rspec-users] Date comparisons In-Reply-To: <810a540e0805050102m6ee3742k7935987432263e97@mail.gmail.com> References: <1EF80BAF-A6A7-4D68-B09E-F412DD0B14D7@gmail.com> <810a540e0805050102m6ee3742k7935987432263e97@mail.gmail.com> Message-ID: <4AADED9C-F819-40F4-99E6-DFA7A313F5B0@jlaine.net> On 5.5.2008, at 11.02, Pat Maddox wrote: > Yes, that was my first idea as well. The Time class is a little > fucked up in that > > < a, b = Time.now, Time.now > < a == b #=> false That's definitely a gotcha but I wouldn't necessarily say it's fucked up. It's just that Time#now returns the current (exact) point of time, so running it successively on the same machine will by definition return different values (by a tiny margin but still). The fact that the textual representation of the two look exactly the same certainly makes it confusing the first time get bitten by it, though :-) Cheers, //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: From tastapod at gmail.com Mon May 5 05:28:34 2008 From: tastapod at gmail.com (Dan North) Date: Mon, 5 May 2008 10:28:34 +0100 Subject: [rspec-users] Date comparisons In-Reply-To: <4AADED9C-F819-40F4-99E6-DFA7A313F5B0@jlaine.net> References: <1EF80BAF-A6A7-4D68-B09E-F412DD0B14D7@gmail.com> <810a540e0805050102m6ee3742k7935987432263e97@mail.gmail.com> <4AADED9C-F819-40F4-99E6-DFA7A313F5B0@jlaine.net> Message-ID: The (pretty much universal) problem with dates and times is that people use "date" and "time" to mean different things. There's a java library called joda that provides a really clean vocabulary around this. An *instant* is a point in time. You shouldn't be able to ask for two instants and get the same answer however close together you ask. (There's probably something philosophical in there somewhere.) A *datetime* is a type of instant with millisecond precision that can tell you the time and date it represents, based on a timezone. The Ruby Time class represents an instant but renders itself as a datetime, hence the confusion (it has microsecond precision that you only get to see if you know to ask). A *local date* is a day when something happens, say 4th May 2008. My understanding of 4th May in the UK is bounded by different start and end instants than, say, David's in the US, because of timezones, but we both know what we "mean" by 4th May 2008. A *duration* is a length of time in milliseconds. Given these atoms you can have fairly sensible conversations about times and dates. For instance, in the current example I might do this: Instant = Time # make it clear what I'm using it for ... Instant.new == Instant.new # false, but now I know why Cheers, Dan ps. and as Aslak says, make sure you control "time" in your examples - either by stubbing Time or by injecting your own Clock abstraction. 2008/5/5 Jarkko Laine : > On 5.5.2008, at 11.02, Pat Maddox wrote: > > Yes, that was my first idea as well. The Time class is a little > > fucked up in that > > > > < a, b = Time.now, Time.now > > < a == b #=> false > > > > That's definitely a gotcha but I wouldn't necessarily say it's fucked up. > It's just that Time#now returns the current (exact) point of time, so > running it successively on the same machine will by definition return > different values (by a tiny margin but still). > > The fact that the textual representation of the two look exactly the same > certainly makes it confusing the first time get bitten by it, though :-) > > Cheers, > //jarkko > > -- > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Mon May 5 11:42:11 2008 From: lists at ruby-forum.com (Cyril Mougel) Date: Mon, 5 May 2008 17:42:11 +0200 Subject: [rspec-users] Problems with redirect_to In-Reply-To: <57c63afe0802220743q391a76c8g8a94835e0c85fad1@mail.gmail.com> References: <57c63afe0802220600l552a8e67u9c46467dfe612e2b@mail.gmail.com> <57c63afe0802220625s74d7817s10875cd3ae2e6cb5@mail.gmail.com> <57c63afe0802220743q391a76c8g8a94835e0c85fad1@mail.gmail.com> Message-ID: <73b6a648f23b7fff33dbb5c0bee7247a@ruby-forum.com> David Chelimsky wrote: > On Fri, Feb 22, 2008 at 9:20 AM, Maur?cio Linhares > wrote: >> "/pages/test" and sent it two the recognize_path method, but this path >> ActionController::Routing::Routes.recognize_path path, :method => :get >> end >> >> As you can only redirect to GET requests, this should not be a >> problem. Should i file a patch for this? > > > That would be great, thanks! Please do review > http://rspec.lighthouseapp.com/projects/5645/how-to-file-a-ticket > before you do. > This bug are a ticket or not ? Because I have the same problem and I don't find in lighthouse bug tracking. -- Posted via http://www.ruby-forum.com/. From cwdinfo at gmail.com Mon May 5 12:59:21 2008 From: cwdinfo at gmail.com (s.ross) Date: Mon, 5 May 2008 09:59:21 -0700 Subject: [rspec-users] Date comparisons In-Reply-To: <1EF80BAF-A6A7-4D68-B09E-F412DD0B14D7@gmail.com> References: <1EF80BAF-A6A7-4D68-B09E-F412DD0B14D7@gmail.com> Message-ID: <94CAA9CA-0D77-424F-AACE-D984127B8A87@gmail.com> On May 4, 2008, at 11:07 PM, Aslak Helles?y wrote: > If your code uses Date#now, always make sure you stub it in your > specs. Always. Yes, but the OP's question was why do two "same" date objects compare as different. This is a typical problem with floating-point and anything that counts time. I used DateTime.now in my sample code below, but certainly I agree that specifying an exact object either by stubbing or explicit constant specification is a better idea. There will be cases, however, where a strict equality test can't be trusted and one must compare something as being within some "close" tolerance. -s > On 5. mai. 2008, at 05.42, "s.ross" wrote: > >> Hi-- >> >> On May 3, 2008, at 9:17 AM, Joe Van Dyk wrote: >> >>> I occasionally get this error: >>> >>> 1) >>> 'A puzzle once featured, should no longer be nominated' FAILED >>> expected: Sun May 04 09:10:26 -0700 2008, >>> got: Sun May 04 09:10:26 -0700 2008 (using ==) >>> ./spec/models/puzzle_spec.rb:180: >>> >>> >>> >>> So, the dates looks the same to me. Any ideas for how to debug? >>> >>> Joe >> >> I monkeypatched DateTime (aieeeeee!) to get this effect. A custom >> matcher is probably a better solution. Here's the monkeypatch: >> >> require File.dirname(__FILE__) + '/../spec_helper' >> >> class DateTime >> def close?(other_date, difference) >> (other_date.to_time.to_i - DateTime.now.to_time.to_i).abs < >> difference >> end >> end >> >> #Delete this context and add some real ones >> context "should be able to create a project viewer" do >> fixtures :project_viewers >> >> specify "fixtures should load two ProjectViewers" do >> pb = ProjectViewer.create(:comments => 'a >> comment', :last_viewed_at => DateTime.now) >> pb.last_viewed_at.should_be_close(DateTime.now, 100) >> end >> end >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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 nabble.108 at xoxy.net Mon May 5 20:18:02 2008 From: nabble.108 at xoxy.net (Matt McNeil) Date: Mon, 5 May 2008 17:18:02 -0700 (PDT) Subject: [rspec-users] specifying output of render call Message-ID: <17071496.post@talk.nabble.com> Hello again, First of all, thanks much for everyone's input on my question last week about spec'ing an invocation of super. Here's another question that seems resistant to my Google searching: With this helper method (defined in a module and included in Rails controllers): def render_rjs_redirect(url = '/') render :update do |page| page << "location.href='#{url}'" end end Is it possible/advisable to specify either the block passed to render or the output of the helper, something like below? The only way I have been able so far to spec this was to create a FooController with an index action that called the method and then checked the response.body, but that seems like a lot of overhead to test such a simple method. Is there a better or obvious way to do this? Thanks! Matt it "should render javascript to redirect the browser" do self.should_receive(:render).with(:update) { |page| page << "location.href='example.com'"} render_rjs_redirect('example.com') end it "should render javascript to redirect the browser" do render_rjs_redirect('example.com') response.body.should == "location.href='example.com'" end -- View this message in context: http://www.nabble.com/specifying-output-of-render-call-tp17071496p17071496.html Sent from the rspec-users mailing list archive at Nabble.com. From pergesu at gmail.com Mon May 5 22:47:27 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 5 May 2008 19:47:27 -0700 Subject: [rspec-users] specifying output of render call In-Reply-To: <17071496.post@talk.nabble.com> References: <17071496.post@talk.nabble.com> Message-ID: <810a540e0805051947v28f229benc8729e62a22af2ce@mail.gmail.com> Hey Matt, One problem with rjs is that it's very difficult to test. You can't execute it, and executing code is necessary for specification by example. In this case, I would probably not unit test that code, based on the combination of it being simple code but difficult to test. I would probably right a "ping" test though, that just makes the request and asserts an ok response. That at least covers syntax errors or bad method calls. You could write a selenium test if you want I suppose. My current favorite pattern for RJS-type stuff is to push the behavior into the client and have the server just render JSON. This makes it very easy to test the behavior using jspec, and leaves you with a very natural separation of concerns. Pat From jmenoube at gmail.com Tue May 6 00:15:40 2008 From: jmenoube at gmail.com (Eeby) Date: Mon, 5 May 2008 21:15:40 -0700 (PDT) Subject: [rspec-users] "Plugin not found" after RSpec install Message-ID: <815ba561-55a3-45e8-937f-4a0193db1240@b9g2000prh.googlegroups.com> I tried to install the RSpec Rails plugin as described here: http://rspec.info/documentation/rails/install.html After I run this... ruby script/plugin install http://rspec.rubyforge.org/svn/tags/CURRENT/rspec At the very end after a lot of output I get this error: Plugin not found: ["http://rspec.rubyforge.org/svn/tags/CURRENT/ rspec"] It looks as though it actually was installed because the dir is there and the output reported scores of items being installed. Any idea why I get that error? Thanks, Ethan From jmenoube at gmail.com Tue May 6 00:23:41 2008 From: jmenoube at gmail.com (Eeby) Date: Mon, 5 May 2008 21:23:41 -0700 (PDT) Subject: [rspec-users] "Plugin not found" after RSpec install Message-ID: <0bdba0ac-e9c0-4b04-99ff-db611ed25fb4@d19g2000prm.googlegroups.com> I tried to install the RSpec Rails plugin as described here: http://rspec.info/documentation/rails/install.html After I run this... ruby script/plugin install http://rspec.rubyforge.org/svn/tags/CURRENT/rspec At the very end after a lot of output I get this error: Plugin not found: ["http://rspec.rubyforge.org/svn/tags/CURRENT/ rspec"] It looks as though it actually was installed because the dir is there and the output reported scores of items being installed. Any idea why I get that error? Thanks, Ethan From hans at degraaff.org Tue May 6 01:03:11 2008 From: hans at degraaff.org (Hans de Graaff) Date: Tue, 06 May 2008 07:03:11 +0200 Subject: [rspec-users] another noob question about stubs In-Reply-To: <6b6419750804300926u6273e793xaf3de1fecbae8fd9@mail.gmail.com> References: <6b6419750804290900j21c97121u639086002b4fb8bc@mail.gmail.com> <6b6419750804292300u53e6396dp4eff40ba838d460@mail.gmail.com> <2F3ECFEF-57DF-4959-B836-F06C9EFEA72B@gmail.com> <6b6419750804300926u6273e793xaf3de1fecbae8fd9@mail.gmail.com> Message-ID: <1210050191.15276.6.camel@ip6-localhost> On Wed, 2008-04-30 at 11:26 -0500, Patrick Aljord wrote: > 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 result is not defined, so the successful? method isn't known. I'd create a mock for it and stub! that method. result = mock('openid result') result.stub!(:successful?).and_return(true) You can then use result.should_receive(:successful?) in subsequent specs to describe what happens if the result of the call is and isn't successful. Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From dchelimsky at gmail.com Tue May 6 06:30:24 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 6 May 2008 05:30:24 -0500 Subject: [rspec-users] "Plugin not found" after RSpec install In-Reply-To: <0bdba0ac-e9c0-4b04-99ff-db611ed25fb4@d19g2000prm.googlegroups.com> References: <0bdba0ac-e9c0-4b04-99ff-db611ed25fb4@d19g2000prm.googlegroups.com> Message-ID: On May 5, 2008, at 11:23 PM, Eeby wrote: > > > I tried to install the RSpec Rails plugin as described here: > > http://rspec.info/documentation/rails/install.html > > After I run this... > > ruby script/plugin install http://rspec.rubyforge.org/svn/tags/CURRENT/rspec > > At the very end after a lot of output I get this error: > > Plugin not found: ["http://rspec.rubyforge.org/svn/tags/CURRENT/ > rspec"] > > It looks as though it actually was installed because the dir is there > and the output reported scores of items being installed. > > Any idea why I get that error? I'm not getting any error. I'm using Rails 2.0.2. You? From jmenoube at gmail.com Tue May 6 12:46:12 2008 From: jmenoube at gmail.com (Eeby) Date: Tue, 6 May 2008 09:46:12 -0700 (PDT) Subject: [rspec-users] "Plugin not found" after RSpec install In-Reply-To: References: <0bdba0ac-e9c0-4b04-99ff-db611ed25fb4@d19g2000prm.googlegroups.com> Message-ID: <2435c63d-e61e-4d22-9be6-eb11d8128158@v26g2000prm.googlegroups.com> > I'm not getting any error. I'm using Rails 2.0.2. You? Same Rails version. OS X. Ruby 1.8.6. I worked with it a little, and the RSpec functionality seems to be working OK as far as I can tell. (I'm just starting to learn how to use RSpec.) Did I install the plugin from the right source? I noticed that there's also an RSpec-rails project on GitHub. Is the svn repository outdated? Ethan From dchelimsky at gmail.com Tue May 6 12:48:57 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 6 May 2008 11:48:57 -0500 Subject: [rspec-users] "Plugin not found" after RSpec install In-Reply-To: <2435c63d-e61e-4d22-9be6-eb11d8128158@v26g2000prm.googlegroups.com> References: <0bdba0ac-e9c0-4b04-99ff-db611ed25fb4@d19g2000prm.googlegroups.com> <2435c63d-e61e-4d22-9be6-eb11d8128158@v26g2000prm.googlegroups.com> Message-ID: <67CCFE08-BE17-4CCA-B411-5EF166891262@gmail.com> On May 6, 2008, at 11:46 AM, Eeby wrote: >> I'm not getting any error. I'm using Rails 2.0.2. You? > > Same Rails version. > > OS X. Ruby 1.8.6. > > I worked with it a little, and the RSpec functionality seems to be > working OK as far as I can tell. (I'm just starting to learn how to > use RSpec.) > > Did I install the plugin from the right source? I noticed that there's > also an RSpec-rails project on GitHub. Is the svn repository outdated? What you're getting from svn is the last release: 1.1.3. If you want the latest you should grab the github repo, but there has not been a release from source at github yet. > > > Ethan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From george at benevolentcode.com Tue May 6 13:11:48 2008 From: george at benevolentcode.com (George Anderson) Date: Tue, 6 May 2008 13:11:48 -0400 Subject: [rspec-users] "Plugin not found" after RSpec install In-Reply-To: <815ba561-55a3-45e8-937f-4a0193db1240@b9g2000prh.googlegroups.com> References: <815ba561-55a3-45e8-937f-4a0193db1240@b9g2000prh.googlegroups.com> Message-ID: <782d66f30805061011o10e3a06fx10279403ac3f757@mail.gmail.com> Can you pastie the full output? /g On Tue, May 6, 2008 at 12:15 AM, Eeby wrote: > I tried to install the RSpec Rails plugin as described here: > > http://rspec.info/documentation/rails/install.html > > After I run this... > > ruby script/plugin install http://rspec.rubyforge.org/svn/tags/CURRENT/rspec > > At the very end after a lot of output I get this error: > > Plugin not found: ["http://rspec.rubyforge.org/svn/tags/CURRENT/ > rspec"] > > It looks as though it actually was installed because the dir is there > and the output reported scores of items being installed. > > Any idea why I get that error? > > Thanks, > > Ethan > _______________________________________________ > 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 erik at snowedin.net Tue May 6 16:03:37 2008 From: erik at snowedin.net (Erik Pukinskis) Date: Tue, 6 May 2008 13:03:37 -0700 Subject: [rspec-users] Can you use RSpec to test initializers? Message-ID: Hi there! I'm trying to spec out some code that will set the smtp_settings in a custom ActiveMailer object. Basically I want to check that if my configuration object has the right smtp_server, that the ActiveMailer object gets set up correctly. So, my spec looks like this: it "uses smtp server if config says so" do GitoriousConfig.should_receive(:[]).with('smtp_settings').and_return({ :address => "smtp.postoffice.net", }) Mailer.smtp_settings[:address].should == "smtp.postoffice.net" end The trouble is, the code that sets the mailer settings is in an initializer (config/initializers/mailer.rb) and it gets run long before my spec gets run, and so it never encounters my mock. Is there any way I can get the initializer code to run inside my spec? I know I could create a separate initialize method on my Mailer object that has the initialization stuff, and call that method from both my test and my initializer, but that seems less ideal than just calling the initializer from the spec. Any advice? I can't find any information at all online about using Rspec with initializers. Thank you! Erik From jmenoube at gmail.com Tue May 6 17:46:21 2008 From: jmenoube at gmail.com (Eeby) Date: Tue, 6 May 2008 14:46:21 -0700 (PDT) Subject: [rspec-users] "Plugin not found" after RSpec install In-Reply-To: <782d66f30805061011o10e3a06fx10279403ac3f757@mail.gmail.com> References: <815ba561-55a3-45e8-937f-4a0193db1240@b9g2000prh.googlegroups.com> <782d66f30805061011o10e3a06fx10279403ac3f757@mail.gmail.com> Message-ID: On May 6, 10:11 am, "George Anderson" wrote: > Can you pastie the full output? > > /g I deleted the plugins from my project to replay the whole scenario so I could copy and paste it. However, this time there was no error. I pasted it anyway: http://pastie.caboo.se/192662 Thanks, Ethan From mailing_lists at railsnewbie.com Tue May 6 21:55:12 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 6 May 2008 21:55:12 -0400 Subject: [rspec-users] Can you use RSpec to test initializers? In-Reply-To: References: Message-ID: <247869AB-C510-4B3B-A361-EAB69D78AF61@railsnewbie.com> On May 6, 2008, at 4:03 PM, Erik Pukinskis wrote: > Hi there! > > I'm trying to spec out some code that will set the smtp_settings in a > custom ActiveMailer object. Basically I want to check that if my > configuration object has the right smtp_server, that the ActiveMailer > object gets set up correctly. So, my spec looks like this: > > it "uses smtp server if config says so" do > GitoriousConfig.should_receive(: > []).with('smtp_settings').and_return({ > :address => "smtp.postoffice.net", > }) > > Mailer.smtp_settings[:address].should == "smtp.postoffice.net" > end > > The trouble is, the code that sets the mailer settings is in an > initializer (config/initializers/mailer.rb) and it gets run long > before my spec gets run, and so it never encounters my mock. Is there > any way I can get the initializer code to run inside my spec? > > I know I could create a separate initialize method on my Mailer object > that has the initialization stuff, and call that method from both my > test and my initializer, but that seems less ideal than just calling > the initializer from the spec. > > Any advice? I can't find any information at all online about using > Rspec with initializers. You could try using Kernel#load to load the file inside the spec, but you might get strange errors on the other side... Let me know how it works out. Scott From zach.dennis at gmail.com Wed May 7 11:09:56 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 7 May 2008 11:09:56 -0400 Subject: [rspec-users] Can you use RSpec to test initializers? In-Reply-To: References: Message-ID: <85d99afe0805070809h4b219fc5ob0a0138b7bfd0a0f@mail.gmail.com> On Tue, May 6, 2008 at 4:03 PM, Erik Pukinskis wrote: > Hi there! > > I'm trying to spec out some code that will set the smtp_settings in a > custom ActiveMailer object. Basically I want to check that if my > configuration object has the right smtp_server, that the ActiveMailer > object gets set up correctly. So, my spec looks like this: > > it "uses smtp server if config says so" do > GitoriousConfig.should_receive(:[]).with('smtp_settings').and_return({ > :address => "smtp.postoffice.net", > }) > > Mailer.smtp_settings[:address].should == "smtp.postoffice.net" > end > > The trouble is, the code that sets the mailer settings is in an > initializer (config/initializers/mailer.rb) and it gets run long > before my spec gets run, and so it never encounters my mock. Is there > any way I can get the initializer code to run inside my spec? > > I know I could create a separate initialize method on my Mailer object > that has the initialization stuff, and call that method from both my > test and my initializer, but that seems less ideal than just calling > the initializer from the spec. > > Any advice? I can't find any information at all online about using > Rspec with initializers. > Erik, I would not test configuration settings this way. Setting up mock expectations helps when you are talking to another object whose implementation you don't have yet, or don't want the test to rely. Since you are testing configuration settings I would vote that you test against the actual configuration settings. A quick sidebar, I don't like setting up SMTP settings in an initializer. I prefer to do it in the correct environment/*.rb file. This is because you often don't want your development or test environments sending out emails (at least not via the same route as production). If you do move the configuration setup from your initializer to an environment file then what you want to test is going to be more difficult since it may be different for each environment. And when you run a spec it's going to be executed in the test environment, which is probably not the SMTP settings you wanted to ensure got setup. You are probably wanting to make sure the production environment runs with specific settings. In the past I've foregone automated testing of my configuration settings. I usually setup my production.rb configuration on the production server, and then every time I deploy I'm symlink that file into RAILS_ROOT/config/environment/. This greatly reduces the risk that the production settings is going to be modified or altered unintentionally. Keeping snapshot backups of your production setup (or even just the configuration files) also helps reduce risk even more. You could put your production files in their own svn or git repository so you can easily revert back when you do make changes to those files. If you really want to test the production settings you could right a test which loaded up the rails application in the production environment, printed out the SMTP settings in YAML, and then your test could read that in using YAML.load and you could ensure the settings are what you expect. IE: settings = YAML.load( `RAILS_ENV=production ruby -r config/environment.rb -e "y ActionMailer::Base.smtp_settings"` ) settings[:domain].should == "smtp.example.com" -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed May 7 19:18:39 2008 From: lists at ruby-forum.com (Oliver Saunders) Date: Thu, 8 May 2008 01:18:39 +0200 Subject: [rspec-users] Hiding the passes Message-ID: <544f078832283730ec567df80a82a84e@ruby-forum.com> How do you hide all the green passing examples from the output? I don't need to know what has passed and it means I have to scroll to see what has failed. -- Posted via http://www.ruby-forum.com/. From steve.downtown at gmail.com Wed May 7 20:14:39 2008 From: steve.downtown at gmail.com (Steve Downey) Date: Wed, 7 May 2008 17:14:39 -0700 Subject: [rspec-users] Hiding the passes In-Reply-To: <544f078832283730ec567df80a82a84e@ruby-forum.com> References: <544f078832283730ec567df80a82a84e@ruby-forum.com> Message-ID: <4fff79200805071714g559b948bq536ce62d1f6f402b@mail.gmail.com> I assume you are running with '-f s' switch? Maybe its in your spec.opts file ... maybe as --format progress? If you change that to '-f p' you only see progress as a single '.' for each passing test with errors at the end of the output. Or maybe I'm not understanding the question. On Wed, May 7, 2008 at 4:18 PM, Oliver Saunders wrote: > How do you hide all the green passing examples from the output? > I don't need to know what has passed and it means I have to scroll to > see what has failed. > -- > 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: From pergesu at gmail.com Wed May 7 21:01:47 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 7 May 2008 18:01:47 -0700 Subject: [rspec-users] Hiding the passes In-Reply-To: <544f078832283730ec567df80a82a84e@ruby-forum.com> References: <544f078832283730ec567df80a82a84e@ruby-forum.com> Message-ID: <810a540e0805071801n53b85282m2dc3d7bb39f0eb56@mail.gmail.com> On Wed, May 7, 2008 at 4:18 PM, Oliver Saunders wrote: > How do you hide all the green passing examples from the output? > I don't need to know what has passed and it means I have to scroll to > see what has failed. Hey Oliver, You can write a custom formatter that implements #example_passed as a noop: class HalfEmptyFormatter < Spec::Runner::Formatter::ProgressBarFormatter def example_passed; end end From ben at benmabey.com Wed May 7 21:53:49 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 07 May 2008 19:53:49 -0600 Subject: [rspec-users] Hiding the passes In-Reply-To: <4fff79200805071714g559b948bq536ce62d1f6f402b@mail.gmail.com> References: <544f078832283730ec567df80a82a84e@ruby-forum.com> <4fff79200805071714g559b948bq536ce62d1f6f402b@mail.gmail.com> Message-ID: <48225D2D.60903@benmabey.com> Steve Downey wrote: > I assume you are running with '-f s' switch? Maybe its in your > spec.opts file ... maybe as --format progress? > > If you change that to '-f p' you only see progress as a single '.' for > each passing test with errors at the end of the output. > > Or maybe I'm not understanding the question. > > On Wed, May 7, 2008 at 4:18 PM, Oliver Saunders > wrote: > > How do you hide all the green passing examples from the output? > I don't need to know what has passed and it means I have to scroll to > see what has failed. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users I wrote some JS that would hide the passing specs on the HTML formatted version and would allow you to expand it later. I might be able to dig it up if your interested... -Ben From lists at ruby-forum.com Thu May 8 08:22:37 2008 From: lists at ruby-forum.com (Joseph Wilk) Date: Thu, 8 May 2008 14:22:37 +0200 Subject: [rspec-users] Rspec Stories / Selenium Nightmare Message-ID: <4014db023e946c1e69d59f04ea87989c@ruby-forum.com> I have been using Rspec stories with Webrat feeling very productive and happy. Then I needed to do something with Selenium (Webrat could have done what I needed but it does not yet have the functionality). Selenium-core as part of a rails plugin looked nice but did not seem to fit with rspec stories. So I went the Selenium-rc route. Since Selenium uses a separate instance of rails (http://www.nabble.com/stories-with-selenium-and-the-db-td16190686.html) I had to turn off the ActiveRecordSafetyListener used in rspec to make sure the db writes committed. Which in turn left me having to manually cleanup my selenium stories :( So that required writing a new, rather gritty scenario listener which dealt with the cleaning operation. It has to do lots of horrible things like remove all listeners for a selenium story and then re-add them all for the others stories. *Code Extract* def story_ended(title, narrative) case title when 'Edit a page' #We have finished the selenium story $selenium_driver.stop #Do we need to re-add some listeners if !@listener_reloaded Spec::Story::Runner.scenario_runner.add_listener(ActiveRecordSafetyListener.instance) @listener_reloaded=true end end end I had to duplicate a lot of the story steps since now any previous post/gets did not work since they post to the test instance and not the selenium rails instance. I also needed to invoke against the selenium driver so even when the steps would work I had to duplicate them with $selenium_driver.do_something() This nice Given: Given('log in as a admin user') post '/admin/sessions/create', :login => @user.login, :password => @user.password end Being duplicated with this Given('log in as a admin user') $selenium_driver.open '/admin/login' $selenium_driver.type 'login', 'developer' $selenium_driver.type 'password', 'test' $selenium_driver.click 'commit' end After some very painful testing and a lot of time I got my Selenium-rc and Webrat stories working. This experience really opened my eyes to the big void introduced by Selenium-rc running outside of the test instance. This has made me wonder whether I should have rspec stories stepping outside of the test rails instance to drive Selenium tests. Has anyone managed to make this process easier? I'm hoping I'm doing something silly which is making it all harder! Is it feasible to bring selenium into the test rails instances? Is it just always going to be painful? I was skipping along having a lot of fun with stories and Webrat, now I'm face down in a puddle of mud, dreading that Selenium moment. -- Joseph Wilk http://www.joesniff.co.uk -- Posted via http://www.ruby-forum.com/. From zach.dennis at gmail.com Thu May 8 11:10:30 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 8 May 2008 11:10:30 -0400 Subject: [rspec-users] Rspec Stories / Selenium Nightmare In-Reply-To: <4014db023e946c1e69d59f04ea87989c@ruby-forum.com> References: <4014db023e946c1e69d59f04ea87989c@ruby-forum.com> Message-ID: <85d99afe0805080810l2a2ffd5dwd7f653f00110bf92@mail.gmail.com> I've had really iffy luck with Selenium plugins in the past (selenium-on-rails, seleniumfu_rc, selenium_rc, etc.) so I've started to write a RailsSeleniumStory. I also had to remove the ActiveRecordSafetyListener in my efforts. The RailsSeleniumStory is a part of the mhs_testing plugin [0] and it provides higher level helpers. For example I love how form-test-helper is used to select and submit forms: # option 1 form = select_form 'expense_form' form.expense.amount = 12.99 form.submit # option 2 submit_form 'expense_form' do |form| form.expense.amount = 12.99 form.expense.category_id = 2 form.expense.comments = "map for trip" end You can use this same syntax within RailsSeleniumStories. Right now you can also use "have_tag" and "with_tag" matchers with Selenium. It supports basic matching (I wouldn't get to crazy with nesting or lots of assert-select/have-tag options), but it will be supporting more options shortly. So your login example could just look like: Given('log in as a admin user') open "/admin/login" submit_form "login_form" do |form| form.login = 'developer' form.password = 'test' end end Which IMO I really like because if you need variations of that you can pull out a helper method like: def submit_login_form(user, password='test') submit_form "login_form" do |form| form.login = user.login form.password = passsword end end And you could push your open into a helper as well: def go_to_login_page open "/admin/login" end And now your Given could look like: Given('log in as a admin user') go_to_login_page submit_login_form @user, 'test' end Now granted submit_form and select_form both take a form's id, so each of your forms need to have one. If you are interested and have the time please check it out. Granted it's in its infancy and there's not a whole lot of docs right now (there is a README.Selenium for instructions on how-to setup in your project), but you can find me on GTalk or in irc.freenode.net (zdennis) and of course right here on the rspec ML. I am have 33 scenarios using the RailsSeleniumStory, ttyl, Zach 0 - http://github.com/mvanholstyn/mhs_testing/tree/master On Thu, May 8, 2008 at 8:22 AM, Joseph Wilk wrote: > I have been using Rspec stories with Webrat feeling very productive and > happy. > > Then I needed to do something with Selenium (Webrat could have done what > I needed but it does not yet have the functionality). > > Selenium-core as part of a rails plugin looked nice but did not seem to > fit with rspec stories. So I went the Selenium-rc route. > > Since Selenium uses a separate instance of rails > (http://www.nabble.com/stories-with-selenium-and-the-db-td16190686.html) > I had to turn off the ActiveRecordSafetyListener used in rspec to make > sure the db writes committed. > > Which in turn left me having to manually cleanup my selenium stories :( > > So that required writing a new, rather gritty scenario listener which > dealt with the cleaning operation. It has to do lots of horrible things > like remove all listeners for a selenium story and then re-add them all > for the others stories. > > *Code Extract* > > def story_ended(title, narrative) > case title > when 'Edit a page' > > #We have finished the selenium story > $selenium_driver.stop > > #Do we need to re-add some listeners > if !@listener_reloaded > > Spec::Story::Runner.scenario_runner.add_listener(ActiveRecordSafetyListener.instance) > @listener_reloaded=true > end > end > end > > > I had to duplicate a lot of the story steps since now any previous > post/gets did not work since they post to the test instance and not the > selenium rails instance. > > I also needed to invoke against the selenium driver so even when the > steps would work I had to duplicate them with > $selenium_driver.do_something() > > > This nice Given: > > Given('log in as a admin user') > post '/admin/sessions/create', :login => @user.login, :password => > @user.password > end > > Being duplicated with this > > Given('log in as a admin user') > $selenium_driver.open '/admin/login' > $selenium_driver.type 'login', 'developer' > $selenium_driver.type 'password', 'test' > $selenium_driver.click 'commit' > end > > After some very painful testing and a lot of time I got my Selenium-rc > and Webrat stories working. This experience really opened my eyes to the > big void introduced by Selenium-rc running outside of the test instance. > > This has made me wonder whether I should have rspec stories stepping > outside of the test rails instance to drive Selenium tests. > > Has anyone managed to make this process easier? > > I'm hoping I'm doing something silly which is making it all harder! > > Is it feasible to bring selenium into the test rails instances? > > Is it just always going to be painful? > > I was skipping along having a lot of fun with stories and Webrat, now > I'm face down in a puddle of mud, dreading that Selenium moment. > > -- > Joseph Wilk > http://www.joesniff.co.uk > -- > 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 dchelimsky at gmail.com Thu May 8 11:15:28 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 8 May 2008 10:15:28 -0500 Subject: [rspec-users] Rspec Stories / Selenium Nightmare In-Reply-To: <85d99afe0805080810l2a2ffd5dwd7f653f00110bf92@mail.gmail.com> References: <4014db023e946c1e69d59f04ea87989c@ruby-forum.com> <85d99afe0805080810l2a2ffd5dwd7f653f00110bf92@mail.gmail.com> Message-ID: <05627E77-E4B0-4100-AEBA-430A18510EC3@gmail.com> Just an FYI - spec-ui, an rspec extension that supports integration with selenium and watir, has been under some discussion lately and should see some new life soon. On May 8, 2008, at 10:10 AM, Zach Dennis wrote: > I've had really iffy luck with Selenium plugins in the past > (selenium-on-rails, seleniumfu_rc, selenium_rc, etc.) so I've > started to write a RailsSeleniumStory. I also had to remove the > ActiveRecordSafetyListener in my efforts. > > The RailsSeleniumStory is a part of the mhs_testing plugin [0] and > it provides higher level helpers. For example I love how form-test- > helper is used to select and submit forms: > > # option 1 > form = select_form 'expense_form' > form.expense.amount = 12.99 > form.submit > > # option 2 > submit_form 'expense_form' do |form| > form.expense.amount = 12.99 > form.expense.category_id = 2 > form.expense.comments = "map for trip" > end > > You can use this same syntax within RailsSeleniumStories. Right now > you can also use "have_tag" and "with_tag" matchers with Selenium. > It supports basic matching (I wouldn't get to crazy with nesting or > lots of assert-select/have-tag options), but it will be supporting > more options shortly. > > So your login example could just look like: > > Given('log in as a admin user') > open "/admin/login" > submit_form "login_form" do |form| > form.login = 'developer' > form.password = 'test' > end > end > > Which IMO I really like because if you need variations of that you > can pull out a helper method like: > > def submit_login_form(user, password='test') > submit_form "login_form" do |form| > form.login = user.login > form.password = passsword > end > end > > And you could push your open into a helper as well: > def go_to_login_page > open "/admin/login" > end > > And now your Given could look like: > Given('log in as a admin user') > go_to_login_page > submit_login_form @user, 'test' > end > > Now granted submit_form and select_form both take a form's id, so > each of your forms need to have one. > > If you are interested and have the time please check it out. Granted > it's in its infancy and there's not a whole lot of docs right now > (there is a README.Selenium for instructions on how-to setup in your > project), but you can find me on GTalk or in irc.freenode.net > (zdennis) and of course right here on the rspec ML. I am have 33 > scenarios using the RailsSeleniumStory, > > ttyl, > > Zach > > 0 - http://github.com/mvanholstyn/mhs_testing/tree/master > > > > On Thu, May 8, 2008 at 8:22 AM, Joseph Wilk > wrote: > I have been using Rspec stories with Webrat feeling very productive > and > happy. > > Then I needed to do something with Selenium (Webrat could have done > what > I needed but it does not yet have the functionality). > > Selenium-core as part of a rails plugin looked nice but did not seem > to > fit with rspec stories. So I went the Selenium-rc route. > > Since Selenium uses a separate instance of rails > (http://www.nabble.com/stories-with-selenium-and-the-db-td16190686.html > ) > I had to turn off the ActiveRecordSafetyListener used in rspec to make > sure the db writes committed. > > Which in turn left me having to manually cleanup my selenium > stories :( > > So that required writing a new, rather gritty scenario listener which > dealt with the cleaning operation. It has to do lots of horrible > things > like remove all listeners for a selenium story and then re-add them > all > for the others stories. > > *Code Extract* > > def story_ended(title, narrative) > case title > when 'Edit a page' > > #We have finished the selenium story > $selenium_driver.stop > > #Do we need to re-add some listeners > if !@listener_reloaded > > Spec > ::Story > ::Runner > .scenario_runner.add_listener(ActiveRecordSafetyListener.instance) > @listener_reloaded=true > end > end > end > > > I had to duplicate a lot of the story steps since now any previous > post/gets did not work since they post to the test instance and not > the > selenium rails instance. > > I also needed to invoke against the selenium driver so even when the > steps would work I had to duplicate them with > $selenium_driver.do_something() > > > This nice Given: > > Given('log in as a admin user') > post '/admin/sessions/create', :login => @user.login, :password > => > @user.password > end > > Being duplicated with this > > Given('log in as a admin user') > $selenium_driver.open '/admin/login' > $selenium_driver.type 'login', 'developer' > $selenium_driver.type 'password', 'test' > $selenium_driver.click 'commit' > end > > After some very painful testing and a lot of time I got my Selenium-rc > and Webrat stories working. This experience really opened my eyes to > the > big void introduced by Selenium-rc running outside of the test > instance. > > This has made me wonder whether I should have rspec stories stepping > outside of the test rails instance to drive Selenium tests. > > Has anyone managed to make this process easier? > > I'm hoping I'm doing something silly which is making it all harder! > > Is it feasible to bring selenium into the test rails instances? > > Is it just always going to be painful? > > I was skipping along having a lot of fun with stories and Webrat, now > I'm face down in a puddle of mud, dreading that Selenium moment. > > -- > Joseph Wilk > http://www.joesniff.co.uk > -- > 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 > _______________________________________________ > 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 lists at ruby-forum.com Thu May 8 14:40:51 2008 From: lists at ruby-forum.com (Oliver Saunders) Date: Thu, 8 May 2008 20:40:51 +0200 Subject: [rspec-users] Hiding the passes In-Reply-To: <48225D2D.60903@benmabey.com> References: <544f078832283730ec567df80a82a84e@ruby-forum.com> <4fff79200805071714g559b948bq536ce62d1f6f402b@mail.gmail.com> <48225D2D.60903@benmabey.com> Message-ID: <03cfaa2b93c716efbedf02bd8af7c197@ruby-forum.com> I should explain I'm running the tests from textmate. So for those interested in doing the same I changed the "Run Examples" command in the RSpec bundle to: #!/usr/bin/env ruby require ENV['TM_BUNDLE_SUPPORT'] + "/lib/spec/mate" require 'spec/runner/formatter/html_formatter' module Spec::Runner::Formatter class TextMateFormatter < HtmlFormatter # hide passes def example_passed(*args); end end end Spec::Mate::Runner.new.run_file STDOUT -- Posted via http://www.ruby-forum.com/. From steve.downtown at gmail.com Thu May 8 16:05:18 2008 From: steve.downtown at gmail.com (Steve Downey) Date: Thu, 8 May 2008 13:05:18 -0700 Subject: [rspec-users] Fixtures not clearing tables? Message-ID: <4fff79200805081305m1d13fe92k30e2b25a09645d5f@mail.gmail.com> I have a case where I'm loading fixtures and a row added to a table in a spec is around at the start of all subsequent specs. When I set config.use_transactional_fixtures = false the fixtures load/clear as expected. Any ideas? -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Thu May 8 18:24:25 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 8 May 2008 18:24:25 -0400 Subject: [rspec-users] Rspec Stories / Selenium Nightmare In-Reply-To: <05627E77-E4B0-4100-AEBA-430A18510EC3@gmail.com> References: <4014db023e946c1e69d59f04ea87989c@ruby-forum.com> <85d99afe0805080810l2a2ffd5dwd7f653f00110bf92@mail.gmail.com> <05627E77-E4B0-4100-AEBA-430A18510EC3@gmail.com> Message-ID: <85d99afe0805081524l44318a69y67cd479d872ddb51@mail.gmail.com> David, Can you provide any more info? Is it just being talked about or are people actively working on it now? I would be interested in assisting. I've done a lot with Selenium and the ruby driver and would be interested in providing beautiful high level helpers that allow people switch from non-Selenium based specs to Selenium-based specs with more ease. I know this can be a barrier for people. Zach On Thu, May 8, 2008 at 11:15 AM, David Chelimsky wrote: > Just an FYI - spec-ui, an rspec extension that supports integration with > selenium and watir, has been under some discussion lately and should see > some new life soon. > > On May 8, 2008, at 10:10 AM, Zach Dennis wrote: > > I've had really iffy luck with Selenium plugins in the past > (selenium-on-rails, seleniumfu_rc, selenium_rc, etc.) so I've started to > write a RailsSeleniumStory. I also had to remove the > ActiveRecordSafetyListener in my efforts. > > The RailsSeleniumStory is a part of the mhs_testing plugin [0] and it > provides higher level helpers. For example I love how form-test-helper is > used to select and submit forms: > > # option 1 > form = select_form 'expense_form' > form.expense.amount = 12.99 > form.submit > > # option 2 > submit_form 'expense_form' do |form| > form.expense.amount = 12.99 > form.expense.category_id = 2 > form.expense.comments = "map for trip" > end > > You can use this same syntax within RailsSeleniumStories. Right now you can > also use "have_tag" and "with_tag" matchers with Selenium. It supports basic > matching (I wouldn't get to crazy with nesting or lots of > assert-select/have-tag options), but it will be supporting more options > shortly. > > So your login example could just look like: > > Given('log in as a admin user') > open "/admin/login" > submit_form "login_form" do |form| > form.login = 'developer' > form.password = 'test' > end > end > > Which IMO I really like because if you need variations of that you can pull > out a helper method like: > > def submit_login_form(user, password='test') > submit_form "login_form" do |form| > form.login = user.login > form.password = passsword > end > end > > And you could push your open into a helper as well: > def go_to_login_page > open "/admin/login" > end > > And now your Given could look like: > Given('log in as a admin user') > go_to_login_page > submit_login_form @user, 'test' > end > > Now granted submit_form and select_form both take a form's id, so each of > your forms need to have one. > > If you are interested and have the time please check it out. Granted it's > in its infancy and there's not a whole lot of docs right now (there is a > README.Selenium for instructions on how-to setup in your project), but you > can find me on GTalk or in irc.freenode.net (zdennis) and of course right > here on the rspec ML. I am have 33 scenarios using the RailsSeleniumStory, > > ttyl, > > Zach > > 0 - http://github.com/mvanholstyn/mhs_testing/tree/master > > > > On Thu, May 8, 2008 at 8:22 AM, Joseph Wilk wrote: > >> I have been using Rspec stories with Webrat feeling very productive and >> happy. >> >> Then I needed to do something with Selenium (Webrat could have done what >> I needed but it does not yet have the functionality). >> >> Selenium-core as part of a rails plugin looked nice but did not seem to >> fit with rspec stories. So I went the Selenium-rc route. >> >> Since Selenium uses a separate instance of rails >> (http://www.nabble.com/stories-with-selenium-and-the-db-td16190686.html) >> I had to turn off the ActiveRecordSafetyListener used in rspec to make >> sure the db writes committed. >> >> Which in turn left me having to manually cleanup my selenium stories :( >> >> So that required writing a new, rather gritty scenario listener which >> dealt with the cleaning operation. It has to do lots of horrible things >> like remove all listeners for a selenium story and then re-add them all >> for the others stories. >> >> *Code Extract* >> >> def story_ended(title, narrative) >> case title >> when 'Edit a page' >> >> #We have finished the selenium story >> $selenium_driver.stop >> >> #Do we need to re-add some listeners >> if !@listener_reloaded >> >> Spec::Story::Runner.scenario_runner.add_listener(ActiveRecordSafetyListener.instance) >> @listener_reloaded=true >> end >> end >> end >> >> >> I had to duplicate a lot of the story steps since now any previous >> post/gets did not work since they post to the test instance and not the >> selenium rails instance. >> >> I also needed to invoke against the selenium driver so even when the >> steps would work I had to duplicate them with >> $selenium_driver.do_something() >> >> >> This nice Given: >> >> Given('log in as a admin user') >> post '/admin/sessions/create', :login => @user.login, :password => >> @user.password >> end >> >> Being duplicated with this >> >> Given('log in as a admin user') >> $selenium_driver.open '/admin/login' >> $selenium_driver.type 'login', 'developer' >> $selenium_driver.type 'password', 'test' >> $selenium_driver.click 'commit' >> end >> >> After some very painful testing and a lot of time I got my Selenium-rc >> and Webrat stories working. This experience really opened my eyes to the >> big void introduced by Selenium-rc running outside of the test instance. >> >> This has made me wonder whether I should have rspec stories stepping >> outside of the test rails instance to drive Selenium tests. >> >> Has anyone managed to make this process easier? >> >> I'm hoping I'm doing something silly which is making it all harder! >> >> Is it feasible to bring selenium into the test rails instances? >> >> Is it just always going to be painful? >> >> I was skipping along having a lot of fun with stories and Webrat, now >> I'm face down in a puddle of mud, dreading that Selenium moment. >> >> -- >> Joseph Wilk >> http://www.joesniff.co.uk >> -- >> 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_______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwilden at twistage.com Thu May 8 18:26:52 2008 From: mwilden at twistage.com (Mark Wilden) Date: Thu, 8 May 2008 15:26:52 -0700 Subject: [rspec-users] Testing render :text without has_text References: <123D6B60-6C94-4EC5-90E8-D781B2ED8EBE@mwilden.com> Message-ID: <3DAFEE82-FD6B-4049-8B50-9379AD41D20F@twistage.com> A controller I'm trying to test simply delivers a text string to the client, which then demarshalls it to retrieve some objects. I want to test that the returned string is correct. I don't want to compare the string character-by-character with response.has_text because that ties me to the implementation of the Marshall class. Instead, I just want to demarshall the string and compare that with the expected objects. To do this, I need RSpec to give me the complete text string that's rendered by the controller. Here's the controller: class StatsController < ApplicationController layout nil def query reports = StatisticsReporter.query params[:query_params] render :text => Marshal.dump(reports) end end And here's the test: describe StatsController do before :each do @query_params = { :foo => :bar } end it "should return a demarshallable string of the reports" do reports = [ StatisticsReport.new(:date => nil), StatisticsReport.new(:bytes_transferred => 0) ] StatisticsReporter.should_receive(:query).and_return reports get :query, :query_params => @query_params # PROBLEM CODE (the equality test needs tweaking, but you get the idea) Marshal.load(response.what_goes_here?).should == reports end end (This code may look familiar to one member of this list...:) Can this be done? adthanksvance, ///ark From dchelimsky at gmail.com Thu May 8 18:36:33 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 8 May 2008 17:36:33 -0500 Subject: [rspec-users] Rspec Stories / Selenium Nightmare In-Reply-To: <85d99afe0805081524l44318a69y67cd479d872ddb51@mail.gmail.com> References: <4014db023e946c1e69d59f04ea87989c@ruby-forum.com> <85d99afe0805080810l2a2ffd5dwd7f653f00110bf92@mail.gmail.com> <05627E77-E4B0-4100-AEBA-430A18510EC3@gmail.com> <85d99afe0805081524l44318a69y67cd479d872ddb51@mail.gmail.com> Message-ID: <909F712C-8080-49CB-9717-72705CF7BF24@gmail.com> On May 8, 2008, at 5:24 PM, Zach Dennis wrote: > David, > > Can you provide any more info? Is it just being talked about or are > people actively working on it now? I would be interested in > assisting. I've done a lot with Selenium and the ruby driver and > would be interested in providing beautiful high level helpers that > allow people switch from non-Selenium based specs to Selenium-based > specs with more ease. I know this can be a barrier for people. The short term plan is that Aslak will set up a spec-ui project up at github, at which point you, Ian Dees (who ha also expressed an interested in working on this), and anyone else who wishes can set up clones. It might take a while before there is a formal release (gem published to rubyforge), but at least this positions us to move forward with your assistance. I don't want to commit to a time frame, but my suspicion is that we should have git repo u