From barjunk at attglobal.net Sun Jul 1 14:35:02 2007 From: barjunk at attglobal.net (barsalou) Date: Sun, 01 Jul 2007 10:35:02 -0800 Subject: [rspec-users] testing instance variables that are set inside views In-Reply-To: <57c63afe0706301341l19d4041bvca9dd519ce3b74fc@mail.gmail.com> References: <468576DB.7060803@vanderbilt.edu> <8d961d900706300052n47b6798ci16a2d0b5667ccd42@mail.gmail.com> <20070630123510.rsfz95u3okkks4s4@lcgalaska.com> <57c63afe0706301341l19d4041bvca9dd519ce3b74fc@mail.gmail.com> Message-ID: <20070701103502.nzp6dpib2o80s0s0@lcgalaska.com> Quoting David Chelimsky : >>> >> Thanks Aslak, I wondered this myself. I looked around here : >> http://rspec.rubyforge.org/rdoc/index.html for have_tag but didn't find >> it. >> >> Where would be a good place to find some of these matchers? > > have_tag is not part of rspec's core, it's in the rails plugin. The > rdoc for that is at http://rspec.rubyforge.org/rdoc-rails/index.html > > Cheers, > David Perfect, thanks! Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From barjunk at attglobal.net Sun Jul 1 18:05:21 2007 From: barjunk at attglobal.net (barsalou) Date: Sun, 01 Jul 2007 14:05:21 -0800 Subject: [rspec-users] rspec for the svn-less (ruby version) Message-ID: <20070701140521.mkcxpwec08kokoog@lcgalaska.com> A couple of things: - it is defaulted to 1.0.5, but if there was a "current" I could probably use that instead. - it seems like everyone might not use the rspec_on_rails piece...what do other think? - there are some other checks I could put in here, suggestions are welcome. - general code suggestions are welcome as well. Mike B. Here is my ruby version: #!/usr/bin/ruby -w require 'ftools' def usage puts puts "Usage: makespec.rb []" puts puts "Version defaults to 1.0.5" puts puts "Example: " puts " makespec.rb /var/www/rails/railsapp 1.0.5" puts end if ARGV[0].nil? then usage puts puts "You must include a pathname" puts exit 1 end version = ARGV[1] if ARGV[1].nil? then puts puts "Defaulting to version: 1.0.5" puts version = "1.0.5" end rspec="rspec-" + version + ".tgz" rspecrails="rspec_on_rails-" + version + ".tgz" app = ARGV[0] if ! File.exist?(rspec) then puts puts "Rspec tarball (" + rspec + ") does not exist in the current directory" puts exit 1 end if ! File.exist?(rspecrails) then puts puts "Rspec-rails tarball (" + rspecrails + ") does not exist in the current d irectory" puts exit 1 end if FileTest.directory? app + "/vendor/plugins" then system("tar","zxvf", rspec) system("tar","zxvf", rspecrails) cwd = Dir.pwd Dir.chdir(app + "/vendor/plugins") File.move(cwd + "/" + File.basename(rspec,".tgz"),app + "/vendor/plugins/rspec") File.move(cwd + "/" + File.basename(rspecrails,".tgz"),app + "/vendor/plugins/rspec_on_rails") else puts app + "/vendor/plugins doesn't exist" exit 1 end ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From aslak.hellesoy at gmail.com Sun Jul 1 21:06:12 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 2 Jul 2007 03:06:12 +0200 Subject: [rspec-users] rspec for the svn-less (ruby version) In-Reply-To: <20070701140521.mkcxpwec08kokoog@lcgalaska.com> References: <20070701140521.mkcxpwec08kokoog@lcgalaska.com> Message-ID: <8d961d900707011806h1b6afe9ag7c9d5450b3f295cb@mail.gmail.com> On 7/2/07, barsalou wrote: > A couple of things: > > - it is defaulted to 1.0.5, but if there was a "current" I could > probably use that instead. > http://rspec.rubyforge.org/download.html says 1.0.5, I'll try to remember to mention svn://rubyforge.org/var/svn/rspec/tags/CURRENT, which is pointing to (and will continue to point to) the latest release. > - it seems like everyone might not use the rspec_on_rails piece...what > do other think? > Your observation is correct. Many people use RSpec without Rails. It was always meant to be a generic tool, and it will remain that way, while continuing Rails support in the sister Spec::Rails project. > - there are some other checks I could put in here, suggestions are welcome. > I prefer cash. I will send you my account number privately :-). > - general code suggestions are welcome as well. > > Mike B. > > > Here is my ruby version: > > #!/usr/bin/ruby -w > > require 'ftools' > > def usage > puts > puts "Usage: makespec.rb []" > puts > puts "Version defaults to 1.0.5" > puts > puts "Example: " > puts " makespec.rb /var/www/rails/railsapp 1.0.5" > puts > end > > if ARGV[0].nil? then > usage > puts > puts "You must include a pathname" > puts > exit 1 > end > > version = ARGV[1] > > if ARGV[1].nil? then > puts > puts "Defaulting to version: 1.0.5" > puts > version = "1.0.5" > end > > rspec="rspec-" + version + ".tgz" > rspecrails="rspec_on_rails-" + version + ".tgz" > app = ARGV[0] > > if ! File.exist?(rspec) then > puts > puts "Rspec tarball (" + rspec + ") does not exist in the current directory" > puts > exit 1 > end > > if ! File.exist?(rspecrails) then > puts > puts "Rspec-rails tarball (" + rspecrails + ") does not exist in the > current d > irectory" > puts > exit 1 > end > > if FileTest.directory? app + "/vendor/plugins" then > system("tar","zxvf", rspec) > system("tar","zxvf", rspecrails) > cwd = Dir.pwd > Dir.chdir(app + "/vendor/plugins") > File.move(cwd + "/" + File.basename(rspec,".tgz"),app + > "/vendor/plugins/rspec") > File.move(cwd + "/" + File.basename(rspecrails,".tgz"),app + > "/vendor/plugins/rspec_on_rails") > else > puts app + "/vendor/plugins doesn't exist" > exit 1 > end > Rake also makes tarballs, and I think correctly so. It seems like the reason why our (gzipped) tarballs are broken (http://rubyforge.org/frs/?group_id=797) is the upload/release tool we use - or possibly (but not likely) a RubyForge bug. I don't think your script will make a difference, but I'll definitely look into it the next time I adress the tarball bug. > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Mon Jul 2 05:18:21 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Mon, 2 Jul 2007 10:18:21 +0100 Subject: [rspec-users] Aspects in RSpec 1.0.5 In-Reply-To: <57c63afe0706270857k317b943cg2b87184baebcc155@mail.gmail.com> References: <3CDEC40C-9326-4424-9667-5EC656CD1C3F@ashleymoran.me.uk> <57c63afe0706270857k317b943cg2b87184baebcc155@mail.gmail.com> Message-ID: On 27 Jun 2007, at 16:57, David Chelimsky wrote: > There's an RFE for this in the tracker - wanna contribute this as a > patch? If you do, please use "facet" instead of "aspect". I had a quick look at this - didn't get much chance because I had work to do too. I had a scan through the specs and code for the Behaviour class, but I came a bit unstuck because adding the "facet" method doesn't actually add any behaviour. So what goes in the specs? Is it enough to test that a spec inside a facet (inside a facet?) runs? Or a spec inside a facet (inside a facet?) fails? Or should I test that specs get added to the list of those due to run? Ashley From dchelimsky at gmail.com Mon Jul 2 05:22:32 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 2 Jul 2007 04:22:32 -0500 Subject: [rspec-users] Aspects in RSpec 1.0.5 In-Reply-To: References: <3CDEC40C-9326-4424-9667-5EC656CD1C3F@ashleymoran.me.uk> <57c63afe0706270857k317b943cg2b87184baebcc155@mail.gmail.com> Message-ID: <57c63afe0707020222p16330702u3befb471a3ddf26c@mail.gmail.com> On 7/2/07, Ashley Moran wrote: > > On 27 Jun 2007, at 16:57, David Chelimsky wrote: > > > There's an RFE for this in the tracker - wanna contribute this as a > > patch? If you do, please use "facet" instead of "aspect". > > > I had a quick look at this - didn't get much chance because I had > work to do too. I had a scan through the specs and code for the > Behaviour class, but I came a bit unstuck because adding the "facet" > method doesn't actually add any behaviour. So what goes in the > specs? Is it enough to test that a spec inside a facet (inside a > facet?) runs? Or a spec inside a facet (inside a facet?) fails? Or > should I test that specs get added to the list of those due to run? IIRC, part of the facet idea was to prepend the facet text to the descriptive string: describe XP do facet "pair programming" do it "should work better when team members have breath mints" do end end end XP - (pair programming) should work better when team members have breath mints So you could write examples that describe the behaviour's description string. David > > Ashley > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dgleal at gmail.com Mon Jul 2 06:33:54 2007 From: dgleal at gmail.com (David Leal) Date: Mon, 2 Jul 2007 11:33:54 +0100 Subject: [rspec-users] Testing route globbing and limitations of get() Message-ID: <1b86cb980707020333p6303d7eu4b9a53a7d927fa23@mail.gmail.com> Hi everyone, I'm new to rails and also to rspec, but I tried to do my homework. To answer my questions, I searched this list's archives, the Rails API, and Google, to no avail. Therefor, I'd be grateful if someone could point me in the right directions: 1) There doesn't seem to be a counterpart to assert_recognizes in rspec. route_for() won't work with route globbing (or will it?) So, how do I test route globbing? 2) Still using route globbing, if I do get '/something/somewhere' rspec will complain that it couldn't find an action for '/something/somewhere'. I suppose this is the correct behaviour, since we're testing the controller, and not routing. However, since the controller action is a catchall, I must pass a path to it, or it won't know what to do. If I try to specify the path using request.path = '/something/somewhere' get 'my_action_name' the path comes out as '/'. Can anyone instruct me on how to do this correctly? Cheers, -- David Leal -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070702/88d94b31/attachment.html From dchelimsky at gmail.com Mon Jul 2 08:51:58 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 2 Jul 2007 07:51:58 -0500 Subject: [rspec-users] Testing route globbing and limitations of get() In-Reply-To: <1b86cb980707020333p6303d7eu4b9a53a7d927fa23@mail.gmail.com> References: <1b86cb980707020333p6303d7eu4b9a53a7d927fa23@mail.gmail.com> Message-ID: <57c63afe0707020551k2e394373o8a7109167446cf9c@mail.gmail.com> On 7/2/07, David Leal wrote: > Hi everyone, > > I'm new to rails and also to rspec, but I tried to do my homework. To answer > my questions, I searched this list's archives, the Rails API, and Google, to > no avail. Therefor, I'd be grateful if someone could point me in the right > directions: > > 1) There doesn't seem to be a counterpart to assert_recognizes in rspec. > route_for() won't work with route globbing (or will it?) So, how do I test > route globbing? For now you can use assert_recognizes. > > 2) Still using route globbing, if I do > > get '/something/somewhere' You can use full paths like that in Rails integration testing (which is not yet supported in RSpec), but not in controllers. For controller examples, you just use the action name: describe SomethingController do it "should get me somewhere" do get 'somewhere' ... > rspec will complain that it couldn't find an action for > '/something/somewhere'. That's Rails complaining. RSpec is just the messenger. > I suppose this is the correct behaviour, since we're > testing the controller, and not routing. However, since the controller > action is a catchall, I must pass a path to it, or it won't know what to do. > If I try to specify the path using > > request.path = '/something/somewhere' > get 'my_action_name' > > the path comes out as '/'. This is all stuff related to Integration Testing, which I'm guessing is what you read about. > Can anyone instruct me on how to do this correctly? I think this should be answered by now. Write back if you still don't understand. Cheers, David > > Cheers, > > -- > David Leal > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dgleal at gmail.com Mon Jul 2 11:31:14 2007 From: dgleal at gmail.com (David Leal) Date: Mon, 2 Jul 2007 16:31:14 +0100 Subject: [rspec-users] Testing route globbing and limitations of get() In-Reply-To: <57c63afe0707020551k2e394373o8a7109167446cf9c@mail.gmail.com> References: <1b86cb980707020333p6303d7eu4b9a53a7d927fa23@mail.gmail.com> <57c63afe0707020551k2e394373o8a7109167446cf9c@mail.gmail.com> Message-ID: <1b86cb980707020831w8227a51k536447ab5ae3bfef@mail.gmail.com> Hi David, thanks for your reply. Regarding the last topic below, there's something about which I'm not quite clear: The catchall method that I'm trying to test works by getting a path from the request object passed to it (during testing it's a TestRequest object). If I understand correctly, there is no way to test this method without writing an integration test. But shouldn't the request object honor the path I've set instead of resetting it? On 7/2/07, David Chelimsky wrote: > > > If I try to specify the path using > > > > request.path = '/something/somewhere' > > get 'my_action_name' > > > > the path comes out as '/'. > > This is all stuff related to Integration Testing, which I'm guessing > is what you read about. > > > Can anyone instruct me on how to do this correctly? > > I think this should be answered by now. Write back if you still don't > understand. > -- David Leal 969 572 510 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070702/a7896cb2/attachment.html From dchelimsky at gmail.com Mon Jul 2 11:34:30 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 2 Jul 2007 10:34:30 -0500 Subject: [rspec-users] Testing route globbing and limitations of get() In-Reply-To: <1b86cb980707020831w8227a51k536447ab5ae3bfef@mail.gmail.com> References: <1b86cb980707020333p6303d7eu4b9a53a7d927fa23@mail.gmail.com> <57c63afe0707020551k2e394373o8a7109167446cf9c@mail.gmail.com> <1b86cb980707020831w8227a51k536447ab5ae3bfef@mail.gmail.com> Message-ID: <57c63afe0707020834v2b7e5fa7x1594388315761898@mail.gmail.com> On 7/2/07, David Leal wrote: > Hi David, thanks for your reply. > > Regarding the last topic below, there's something about which I'm not quite > clear: > > The catchall method that I'm trying to test works by getting a path from the > request object passed to it (during testing it's a TestRequest object). If I > understand correctly, there is no way to test this method without writing an > integration test. But shouldn't the request object honor the path I've set > instead of resetting it? I've never tried to do what you're doing so I can't answer from experience. What I can tell you is that the TestRequest object is part of Rails, not rspec, so you might have some good luck on the rails forums and mailing lists. > > > On 7/2/07, David Chelimsky wrote: > > > If I try to specify the path using > > > > > > request.path = '/something/somewhere' > > > get 'my_action_name' > > > > > > the path comes out as '/'. > > > > This is all stuff related to Integration Testing, which I'm guessing > > is what you read about. > > > > > Can anyone instruct me on how to do this correctly? > > > > I think this should be answered by now. Write back if you still don't > > understand. > > > > -- > David Leal > 969 572 510 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dgleal at gmail.com Mon Jul 2 11:43:30 2007 From: dgleal at gmail.com (David Leal) Date: Mon, 2 Jul 2007 16:43:30 +0100 Subject: [rspec-users] Testing route globbing and limitations of get() In-Reply-To: <57c63afe0707020834v2b7e5fa7x1594388315761898@mail.gmail.com> References: <1b86cb980707020333p6303d7eu4b9a53a7d927fa23@mail.gmail.com> <57c63afe0707020551k2e394373o8a7109167446cf9c@mail.gmail.com> <1b86cb980707020831w8227a51k536447ab5ae3bfef@mail.gmail.com> <57c63afe0707020834v2b7e5fa7x1594388315761898@mail.gmail.com> Message-ID: <1b86cb980707020843r20a1dd0erdfe42a2f1c3468fe@mail.gmail.com> Thanks for your answers, David. I'll investigate. It's still a bit hard for me to understand where are the boundaries between rails tests and rspec. Cheers, David On 7/2/07, David Chelimsky wrote: > > On 7/2/07, David Leal wrote: > > Hi David, thanks for your reply. > > > > Regarding the last topic below, there's something about which I'm not > quite > > clear: > > > > The catchall method that I'm trying to test works by getting a path from > the > > request object passed to it (during testing it's a TestRequest object). > If I > > understand correctly, there is no way to test this method without > writing an > > integration test. But shouldn't the request object honor the path I've > set > > instead of resetting it? > > I've never tried to do what you're doing so I can't answer from > experience. What I can tell you is that the TestRequest object is part > of Rails, not rspec, so you might have some good luck on the rails > forums and mailing lists. > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070702/4d688559/attachment.html From dchelimsky at gmail.com Mon Jul 2 11:46:30 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 2 Jul 2007 10:46:30 -0500 Subject: [rspec-users] Testing route globbing and limitations of get() In-Reply-To: <1b86cb980707020843r20a1dd0erdfe42a2f1c3468fe@mail.gmail.com> References: <1b86cb980707020333p6303d7eu4b9a53a7d927fa23@mail.gmail.com> <57c63afe0707020551k2e394373o8a7109167446cf9c@mail.gmail.com> <1b86cb980707020831w8227a51k536447ab5ae3bfef@mail.gmail.com> <57c63afe0707020834v2b7e5fa7x1594388315761898@mail.gmail.com> <1b86cb980707020843r20a1dd0erdfe42a2f1c3468fe@mail.gmail.com> Message-ID: <57c63afe0707020846rf41c8c6re2a9c14433eca018@mail.gmail.com> On 7/2/07, David Leal wrote: > Thanks for your answers, David. I'll investigate. It's still a bit hard for > me to understand where are the boundaries between rails tests and rspec. Spec::Rails, RSpec's rails plugin, wraps test/unit, so: Model Examples work like Rails unit tests View, Controller and Helper Examples work like Rails functional tests We don't have a parallel to Rails integration tests. That help? > > Cheers, > > David > > > On 7/2/07, David Chelimsky wrote: > > On 7/2/07, David Leal wrote: > > > Hi David, thanks for your reply. > > > > > > Regarding the last topic below, there's something about which I'm not > quite > > > clear: > > > > > > The catchall method that I'm trying to test works by getting a path from > the > > > request object passed to it (during testing it's a TestRequest object). > If I > > > understand correctly, there is no way to test this method without > writing an > > > integration test. But shouldn't the request object honor the path I've > set > > > instead of resetting it? > > > > I've never tried to do what you're doing so I can't answer from > > experience. What I can tell you is that the TestRequest object is part > > of Rails, not rspec, so you might have some good luck on the rails > > forums and mailing lists. > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dgleal at gmail.com Mon Jul 2 12:31:36 2007 From: dgleal at gmail.com (David Leal) Date: Mon, 2 Jul 2007 17:31:36 +0100 Subject: [rspec-users] Testing route globbing and limitations of get() In-Reply-To: <57c63afe0707020846rf41c8c6re2a9c14433eca018@mail.gmail.com> References: <1b86cb980707020333p6303d7eu4b9a53a7d927fa23@mail.gmail.com> <57c63afe0707020551k2e394373o8a7109167446cf9c@mail.gmail.com> <1b86cb980707020831w8227a51k536447ab5ae3bfef@mail.gmail.com> <57c63afe0707020834v2b7e5fa7x1594388315761898@mail.gmail.com> <1b86cb980707020843r20a1dd0erdfe42a2f1c3468fe@mail.gmail.com> <57c63afe0707020846rf41c8c6re2a9c14433eca018@mail.gmail.com> Message-ID: <1b86cb980707020931h40ce0cc1y3db1365f155b8efb@mail.gmail.com> I see. It's simple. Sorry that I missed that. I looked at Mephisto's tests to see how they do it. Turns out you need to call get :action, :path => ["all", "path", "components"] # for /all/path/components Again, thanks for the help, David. Cheers, David On 7/2/07, David Chelimsky wrote: > > On 7/2/07, David Leal wrote: > > Thanks for your answers, David. I'll investigate. It's still a bit hard > for > > me to understand where are the boundaries between rails tests and rspec. > > Spec::Rails, RSpec's rails plugin, wraps test/unit, so: > > Model Examples work like Rails unit tests > View, Controller and Helper Examples work like Rails functional tests > > We don't have a parallel to Rails integration tests. > > That help? > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070702/f8f714b0/attachment.html From pritchie at videotron.ca Tue Jul 3 14:28:30 2007 From: pritchie at videotron.ca (Patrick Ritchie) Date: Tue, 03 Jul 2007 14:28:30 -0400 Subject: [rspec-users] testing instance variables that are set inside views In-Reply-To: <8d961d900706300052n47b6798ci16a2d0b5667ccd42@mail.gmail.com> References: <468576DB.7060803@vanderbilt.edu> <8d961d900706300052n47b6798ci16a2d0b5667ccd42@mail.gmail.com> Message-ID: <468A954E.2060704@videotron.ca> Hi, I think @header may not be an implementation detail in this case. If your layout looks like this: ... <%= @header || 'Default Title' %> ... And the view we are testing looks like this: ...

<%= @header = 'Specific Title'>

... Then setting @header is an essential behavior for the view spec. Or am I missing something? Cheers! Patrick > @header is an implementation detail of your view that you shouldn't > care about in your view spec at all. I recommend you use the have_tag > matcher instead to verify what content gets rendered as expected. > > Aslak > > On 6/29/07, Jeremy Stephens wrote: > >> Hi all, >> >> In my view specs (for Rails), how can I get at instance variables that >> are set within my view? For example, if my view looks like this: >> >> <% @header = "My Header" -%> >>
some content
>> >> How can I get to @header from within my view spec? I've tried @header >> and assigns[:header] to no avail. >> >> TIA, >> Jeremy >> >> -- >> Jeremy Stephens Computer Systems Analyst I School of Medicine >> Department of Biostatistics Vanderbilt University >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070703/7dc3b9d2/attachment-0001.html From has.sox at gmail.com Wed Jul 4 00:38:25 2007 From: has.sox at gmail.com (Daniel N) Date: Wed, 4 Jul 2007 14:38:25 +1000 Subject: [rspec-users] Testing Rails Associations Message-ID: <2fff50390707032138y9ba5542pd92087d78ae33712@mail.gmail.com> Hi, I'm very new to rspec, so if this is not the right forum please let me know. I'm starting to spec my models first in an existing rails app, porting from a mix of Test::Unit, and simply_bdd amongst others. I'm at the point where I want to test that certain associations are present. What I'm not sure of is should I test the association or the method and return object. That is, if I wanted to test a has_many should I: Confirm the methods exist, and that the return an array etc OR Check that the model has the named has_many association through it's reflections. On one hand the second one looks like it will be a bit more robust, since if there is a has_many relationship, then all the associated methods may be used througout the app. This would put testing in the one place. On the other hand, this would be really testing the implementation of the model rather than it's behaviour. The behaviour is to call @ article.comments and have an array of comments returned. Any thoughts? Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070704/8f209d4f/attachment.html From aslak.hellesoy at gmail.com Wed Jul 4 03:54:22 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 4 Jul 2007 09:54:22 +0200 Subject: [rspec-users] testing instance variables that are set inside views In-Reply-To: <468A954E.2060704@videotron.ca> References: <468576DB.7060803@vanderbilt.edu> <8d961d900706300052n47b6798ci16a2d0b5667ccd42@mail.gmail.com> <468A954E.2060704@videotron.ca> Message-ID: <8d961d900707040054r18c6d604pae2f291b2aec14@mail.gmail.com> On 7/3/07, Patrick Ritchie wrote: > > Hi, > > I think @header may not be an implementation detail in this case. > > If your layout looks like this: > > ... > > <%= @header || 'Default Title' %> > > ... > > And the view we are testing looks like this: > > ... >

<%= @header = 'Specific Title'>

> ... > > Then setting @header is an essential behavior for the view spec. > > Or am I missing something? > Before I can answer about how to test this with RSpec, I need to understand what's going on in the code. Isn't the head part of the layout evaluated before the body? If that's the case, what's the point of assigning the @header variable in the view? It wouldn't change the title anyway. Aslak > Cheers! > Patrick > > > @header is an implementation detail of your view that you shouldn't > care about in your view spec at all. I recommend you use the have_tag > matcher instead to verify what content gets rendered as expected. > > Aslak > > On 6/29/07, Jeremy Stephens > wrote: > > > Hi all, > > In my view specs (for Rails), how can I get at instance variables that > are set within my view? For example, if my view looks like this: > > <% @header = "My Header" -%> >
some content
> > How can I get to @header from within my view spec? I've tried @header > and assigns[:header] to no avail. > > TIA, > Jeremy > > -- > Jeremy Stephens Computer Systems Analyst I School of Medicine > Department of Biostatistics Vanderbilt University > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Wed Jul 4 04:42:01 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 4 Jul 2007 09:42:01 +0100 Subject: [rspec-users] Aspects in RSpec 1.0.5 In-Reply-To: <57c63afe0707020222p16330702u3befb471a3ddf26c@mail.gmail.com> References: <3CDEC40C-9326-4424-9667-5EC656CD1C3F@ashleymoran.me.uk> <57c63afe0706270857k317b943cg2b87184baebcc155@mail.gmail.com> <57c63afe0707020222p16330702u3befb471a3ddf26c@mail.gmail.com> Message-ID: <0FE18859-1EFF-4968-B566-5AB445B4CAF8@ashleymoran.me.uk> On 2 Jul 2007, at 10:22, David Chelimsky wrote: > IIRC, part of the facet idea was to prepend the facet text to the > descriptive string: > > describe XP do > facet "pair programming" do > it "should work better when team members have breath mints" do > end > end > end > > XP > - (pair programming) should work better when team members have > breath mints I never knew that :) > > So you could write examples that describe the behaviour's > description string. I'll have another go this weekend, again if I get chance... Just to clear something up, can you define Behaviour and Example for me? When I went through the code I got the impression that a Behaviour is everything in the "describe" block and an Example is everything in an "it" block. Ashley From dchelimsky at gmail.com Wed Jul 4 07:09:00 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 4 Jul 2007 06:09:00 -0500 Subject: [rspec-users] Aspects in RSpec 1.0.5 In-Reply-To: <0FE18859-1EFF-4968-B566-5AB445B4CAF8@ashleymoran.me.uk> References: <3CDEC40C-9326-4424-9667-5EC656CD1C3F@ashleymoran.me.uk> <57c63afe0706270857k317b943cg2b87184baebcc155@mail.gmail.com> <57c63afe0707020222p16330702u3befb471a3ddf26c@mail.gmail.com> <0FE18859-1EFF-4968-B566-5AB445B4CAF8@ashleymoran.me.uk> Message-ID: <57c63afe0707040409s4ccfe6daib4512fadbd9d33da@mail.gmail.com> On 7/4/07, Ashley Moran wrote: > > On 2 Jul 2007, at 10:22, David Chelimsky wrote: > > > IIRC, part of the facet idea was to prepend the facet text to the > > descriptive string: > > > > describe XP do > > facet "pair programming" do > > it "should work better when team members have breath mints" do > > end > > end > > end > > > > XP > > - (pair programming) should work better when team members have > > breath mints > > I never knew that :) > > > > > So you could write examples that describe the behaviour's > > description string. > > I'll have another go this weekend, again if I get chance... > > Just to clear something up, can you define Behaviour and Example for > me? When I went through the code I got the impression that a > Behaviour is everything in the "describe" block and an Example is > everything in an "it" block. That's correct. > > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pritchie at videotron.ca Wed Jul 4 11:35:03 2007 From: pritchie at videotron.ca (Patrick Ritchie) Date: Wed, 04 Jul 2007 11:35:03 -0400 Subject: [rspec-users] testing instance variables that are set inside views In-Reply-To: <8d961d900707040054r18c6d604pae2f291b2aec14@mail.gmail.com> References: <468576DB.7060803@vanderbilt.edu> <8d961d900706300052n47b6798ci16a2d0b5667ccd42@mail.gmail.com> <468A954E.2060704@videotron.ca> <8d961d900707040054r18c6d604pae2f291b2aec14@mail.gmail.com> Message-ID: <468BBE27.4080202@videotron.ca> aslak hellesoy wrote: > On 7/3/07, Patrick Ritchie wrote: > >> Hi, >> >> I think @header may not be an implementation detail in this case. >> >> If your layout looks like this: >> >> ... >> >> <%= @header || 'Default Title' %> >> >> ... >> >> And the view we are testing looks like this: >> >> ... >>

<%= @header = 'Specific Title'>

>> ... >> >> Then setting @header is an essential behavior for the view spec. >> >> Or am I missing something? >> >> > > Before I can answer about how to test this with RSpec, I need to > understand what's going on in the code. Isn't the head part of the > layout evaluated before the body? If that's the case, what's the point > of assigning the @header variable in the view? It wouldn't change the > title anyway The layout is evaluated after the view so the above code is a useful way to include some piece of data in the head without having to initialize it in the controller. Very handy for things like head/title or view specific onload js etc... Cheers! Patrick -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070704/4b0e5cf3/attachment.html From dchelimsky at gmail.com Wed Jul 4 11:41:59 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 4 Jul 2007 10:41:59 -0500 Subject: [rspec-users] testing instance variables that are set inside views In-Reply-To: <468BBE27.4080202@videotron.ca> References: <468576DB.7060803@vanderbilt.edu> <8d961d900706300052n47b6798ci16a2d0b5667ccd42@mail.gmail.com> <468A954E.2060704@videotron.ca> <8d961d900707040054r18c6d604pae2f291b2aec14@mail.gmail.com> <468BBE27.4080202@videotron.ca> Message-ID: <57c63afe0707040841p7b88d46cha488c336c66d53d9@mail.gmail.com> On 7/4/07, Patrick Ritchie wrote: > > aslak hellesoy wrote: > On 7/3/07, Patrick Ritchie wrote: > > > Hi, > > I think @header may not be an implementation detail in this case. > > If your layout looks like this: > > ... > > <%= @header || 'Default Title' %> > > ... > > And the view we are testing looks like this: > > ... >

<%= @header = 'Specific Title'>

> ... > > Then setting @header is an essential behavior for the view spec. > > Or am I missing something? > > > Before I can answer about how to test this with RSpec, I need to > understand what's going on in the code. Isn't the head part of the > layout evaluated before the body? If that's the case, what's the point > of assigning the @header variable in the view? It wouldn't change the > title anyway > The layout is evaluated after the view so the above code is a useful way to > include some piece of data in the head without having to initialize it in > the controller. Very handy for things like head/title or view specific > onload js etc... Correct me if I'm wrong, but it seems to me that the behavior you're interested in is that the right thing shows up in the title: response.should have_tag('title', 'whatever I am expecting') Am I missing something? > > Cheers! > Patrick > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pritchie at videotron.ca Wed Jul 4 12:09:31 2007 From: pritchie at videotron.ca (Patrick Ritchie) Date: Wed, 04 Jul 2007 12:09:31 -0400 Subject: [rspec-users] testing instance variables that are set inside views In-Reply-To: <57c63afe0707040841p7b88d46cha488c336c66d53d9@mail.gmail.com> References: <468576DB.7060803@vanderbilt.edu> <8d961d900706300052n47b6798ci16a2d0b5667ccd42@mail.gmail.com> <468A954E.2060704@videotron.ca> <8d961d900707040054r18c6d604pae2f291b2aec14@mail.gmail.com> <468BBE27.4080202@videotron.ca> <57c63afe0707040841p7b88d46cha488c336c66d53d9@mail.gmail.com> Message-ID: <468BC63B.3000805@videotron.ca> David Chelimsky wrote: > On 7/4/07, Patrick Ritchie wrote: > >> aslak hellesoy wrote: >> On 7/3/07, Patrick Ritchie wrote: >> >> >> Hi, >> >> I think @header may not be an implementation detail in this case. >> >> If your layout looks like this: >> >> ... >> >> <%= @header || 'Default Title' %> >> >> ... >> >> And the view we are testing looks like this: >> >> ... >>

<%= @header = 'Specific Title'>

>> ... >> >> Then setting @header is an essential behavior for the view spec. >> >> Or am I missing something? >> >> >> Before I can answer about how to test this with RSpec, I need to >> understand what's going on in the code. Isn't the head part of the >> layout evaluated before the body? If that's the case, what's the point >> of assigning the @header variable in the view? It wouldn't change the >> title anyway >> The layout is evaluated after the view so the above code is a useful way to >> include some piece of data in the head without having to initialize it in >> the controller. Very handy for things like head/title or view specific >> onload js etc... >> > > Correct me if I'm wrong, but it seems to me that the behavior you're > interested in is that the right thing shows up in the title: > > response.should have_tag('title', 'whatever I am expecting') > > Am I missing something? > I could do that, but that's not the really behavior I'm interested in for the view. I'd rather look at the title tag in my layout spec and the instance variable in my view. It doesn't really make a difference in this simple case, but it would if the title was inserted from a partial called from the layout, or the instance variable was used in multiple places in the layout. Cheers! Patrick -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070704/624f3d80/attachment.html From don at donpetersen.net Wed Jul 4 07:52:25 2007 From: don at donpetersen.net (Don Petersen) Date: Wed, 4 Jul 2007 06:52:25 -0500 Subject: [rspec-users] testing instance variables that are set inside views In-Reply-To: <468BC63B.3000805@videotron.ca> References: <468576DB.7060803@vanderbilt.edu> <8d961d900706300052n47b6798ci16a2d0b5667ccd42@mail.gmail.com> <468A954E.2060704@videotron.ca> <8d961d900707040054r18c6d604pae2f291b2aec14@mail.gmail.com> <468BBE27.4080202@videotron.ca> <57c63afe0707040841p7b88d46cha488c336c66d53d9@mail.gmail.com> <468BC63B.3000805@videotron.ca> Message-ID: I can sympathize with not wanting to just verify the final html output, even though it would probably be sufficient in this simple case. I'm a big fan of helpers for any logic in views, even simple stuff like this. If you had a couple of methods in your ApplicationHelper that handled setting and getting the page title value, that would be very easy to test. Approaching it this way, you can use the helper specs to verify that the actual set/get logic worked. You can even take that whole 'title = @header || "Default Title"' logic out of your layout if you wanted, and put it in the helper where you're only testing that logic and nothing more. So in your view spec, where you had previously been wanting to test if an instance variable had been set, now you just need to verify that the helper method was called. Like so: @controller.template.should_receive(:set_page_title) That's how I have done this very logic in the past, and it feels right to me. Alternately, if you don't want to use helpers, you might use "content_for"(http://api.rubyonrails.org/classes/ActionView/Helpers/ CaptureHelper.html). It's probably overkill for just a basic string like this, but maybe you can rig it to work in this case. Don On Jul 4, 2007, at 11:09 AM, Patrick Ritchie wrote: > David Chelimsky wrote: >> On 7/4/07, Patrick Ritchie wrote: >>> aslak hellesoy wrote: On 7/3/07, Patrick Ritchie >>> wrote: Hi, I think @header may not be an >>> implementation detail in this case. If your layout looks like >>> this: ... ... And the view we are testing looks like this: ... <% >>> = @header = 'Specific Title'> ... Then setting @header is an >>> essential behavior for the view spec. Or am I missing something? >>> Before I can answer about how to test this with RSpec, I need to >>> understand what's going on in the code. Isn't the head part of >>> the layout evaluated before the body? If that's the case, what's >>> the point of assigning the @header variable in the view? It >>> wouldn't change the title anyway The layout is evaluated after >>> the view so the above code is a useful way to include some piece >>> of data in the head without having to initialize it in the >>> controller. Very handy for things like head/title or view >>> specific onload js etc... >> Correct me if I'm wrong, but it seems to me that the behavior >> you're interested in is that the right thing shows up in the >> title: response.should have_tag('title', 'whatever I am >> expecting') Am I missing something? > I could do that, but that's not the really behavior I'm interested > in for the view. I'd rather look at the title tag in my layout spec > and the instance variable in my view. > > It doesn't really make a difference in this simple case, but it > would if the title was inserted from a partial called from the > layout, or the instance variable was used in multiple places in the > layout. > > Cheers! > Patrick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From pritchie at videotron.ca Wed Jul 4 13:55:20 2007 From: pritchie at videotron.ca (Patrick Ritchie) Date: Wed, 04 Jul 2007 13:55:20 -0400 Subject: [rspec-users] testing instance variables that are set inside views In-Reply-To: References: <468576DB.7060803@vanderbilt.edu> <8d961d900706300052n47b6798ci16a2d0b5667ccd42@mail.gmail.com> <468A954E.2060704@videotron.ca> <8d961d900707040054r18c6d604pae2f291b2aec14@mail.gmail.com> <468BBE27.4080202@videotron.ca> <57c63afe0707040841p7b88d46cha488c336c66d53d9@mail.gmail.com> <468BC63B.3000805@videotron.ca> Message-ID: <468BDF08.5040209@videotron.ca> Hi Don, Thanks for the tip! That looks like a great way to handle this case. So what does everybody think, is this the definitive answer for setting instance variables in your views? (use a helper) or are their cases where we may still want to check instance variables in view specs? Cheers! Patrick > I can sympathize with not wanting to just verify the final html > output, even though it would probably be sufficient in this simple case. > > I'm a big fan of helpers for any logic in views, even simple stuff > like this. If you had a couple of methods in your ApplicationHelper > that handled setting and getting the page title value, that would be > very easy to test. > > Approaching it this way, you can use the helper specs to verify that > the actual set/get logic worked. You can even take that whole 'title > = @header || "Default Title"' logic out of your layout if you wanted, > and put it in the helper where you're only testing that logic and > nothing more. > > So in your view spec, where you had previously been wanting to test > if an instance variable had been set, now you just need to verify > that the helper method was called. Like so: > @controller.template.should_receive(:set_page_title) > > That's how I have done this very logic in the past, and it feels > right to me. > > Alternately, if you don't want to use helpers, you might use > "content_for"(http://api.rubyonrails.org/classes/ActionView/Helpers/ > CaptureHelper.html). It's probably overkill for just a basic string > like this, but maybe you can rig it to work in this case. > > Don > > On Jul 4, 2007, at 11:09 AM, Patrick Ritchie wrote: > > >> David Chelimsky wrote: >> >>> On 7/4/07, Patrick Ritchie wrote: >>> >>>> aslak hellesoy wrote: On 7/3/07, Patrick Ritchie >>>> wrote: Hi, I think @header may not be an >>>> implementation detail in this case. If your layout looks like >>>> this: ... ... And the view we are testing looks like this: ... <% >>>> = @header = 'Specific Title'> ... Then setting @header is an >>>> essential behavior for the view spec. Or am I missing something? >>>> Before I can answer about how to test this with RSpec, I need to >>>> understand what's going on in the code. Isn't the head part of >>>> the layout evaluated before the body? If that's the case, what's >>>> the point of assigning the @header variable in the view? It >>>> wouldn't change the title anyway The layout is evaluated after >>>> the view so the above code is a useful way to include some piece >>>> of data in the head without having to initialize it in the >>>> controller. Very handy for things like head/title or view >>>> specific onload js etc... >>>> >>> Correct me if I'm wrong, but it seems to me that the behavior >>> you're interested in is that the right thing shows up in the >>> title: response.should have_tag('title', 'whatever I am >>> expecting') Am I missing something? >>> >> I could do that, but that's not the really behavior I'm interested >> in for the view. I'd rather look at the title tag in my layout spec >> and the instance variable in my view. >> >> It doesn't really make a difference in this simple case, but it >> would if the title was inserted from a partial called from the >> layout, or the instance variable was used in multiple places in the >> layout. >> >> Cheers! >> Patrick >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070704/ebf47d56/attachment.html From dchelimsky at gmail.com Wed Jul 4 14:02:11 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 4 Jul 2007 13:02:11 -0500 Subject: [rspec-users] testing instance variables that are set inside views In-Reply-To: <468BDF08.5040209@videotron.ca> References: <468576DB.7060803@vanderbilt.edu> <8d961d900706300052n47b6798ci16a2d0b5667ccd42@mail.gmail.com> <468A954E.2060704@videotron.ca> <8d961d900707040054r18c6d604pae2f291b2aec14@mail.gmail.com> <468BBE27.4080202@videotron.ca> <57c63afe0707040841p7b88d46cha488c336c66d53d9@mail.gmail.com> <468BC63B.3000805@videotron.ca> <468BDF08.5040209@videotron.ca> Message-ID: <57c63afe0707041102o4e06279cwc1f076e2e5931915@mail.gmail.com> On 7/4/07, Patrick Ritchie wrote: > > Hi Don, > > Thanks for the tip! That looks like a great way to handle this case. > > So what does everybody think, is this the definitive answer for setting > instance variables in your views? (use a helper) or are their cases where we > may still want to check instance variables in view specs? >From a design perspective, conventional wisdom suggests that you don't put any decision making or control in your views. Doing this in helpers is the Rails Way. >From a practical perspective, there is no direct support for accessing instance variables in views in rspec, so the helper route seems to be the path of least resistance. Of course, you could always use instance_eval. This IS Ruby, after all. But I wouldn't recommend it. Cheers, David > > Cheers! > Patrick > > > I can sympathize with not wanting to just verify the final html > output, even though it would probably be sufficient in this simple case. > > I'm a big fan of helpers for any logic in views, even simple stuff > like this. If you had a couple of methods in your ApplicationHelper > that handled setting and getting the page title value, that would be > very easy to test. > > Approaching it this way, you can use the helper specs to verify that > the actual set/get logic worked. You can even take that whole 'title > = @header || "Default Title"' logic out of your layout if you wanted, > and put it in the helper where you're only testing that logic and > nothing more. > > So in your view spec, where you had previously been wanting to test > if an instance variable had been set, now you just need to verify > that the helper method was called. Like so: > @controller.template.should_receive(:set_page_title) > > That's how I have done this very logic in the past, and it feels > right to me. > > Alternately, if you don't want to use helpers, you might use > "content_for"(http://api.rubyonrails.org/classes/ActionView/Helpers/ > CaptureHelper.html). It's probably overkill for just a basic string > like this, but maybe you can rig it to work in this case. > > Don > > On Jul 4, 2007, at 11:09 AM, Patrick Ritchie wrote: > > > > David Chelimsky wrote: > > > On 7/4/07, Patrick Ritchie wrote: > > > aslak hellesoy wrote: On 7/3/07, Patrick Ritchie > wrote: Hi, I think @header may not be an > implementation detail in this case. If your layout looks like > this: ... ... And the view we are testing looks like this: ... <% > = @header = 'Specific Title'> ... Then setting @header is an > essential behavior for the view spec. Or am I missing something? > Before I can answer about how to test this with RSpec, I need to > understand what's going on in the code. Isn't the head part of > the layout evaluated before the body? If that's the case, what's > the point of assigning the @header variable in the view? It > wouldn't change the title anyway The layout is evaluated after > the view so the above code is a useful way to include some piece > of data in the head without having to initialize it in the > controller. Very handy for things like head/title or view > specific onload js etc... > > Correct me if I'm wrong, but it seems to me that the behavior > you're interested in is that the right thing shows up in the > title: response.should have_tag('title', 'whatever I am > expecting') Am I missing something? > > I could do that, but that's not the really behavior I'm interested > in for the view. I'd rather look at the title tag in my layout spec > and the instance variable in my view. > > It doesn't really make a difference in this simple case, but it > would if the title was inserted from a partial called from the > layout, or the instance variable was used in multiple places in the > layout. > > Cheers! > Patrick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From win at wincent.com Thu Jul 5 04:28:22 2007 From: win at wincent.com (Wincent Colaiuta) Date: Thu, 5 Jul 2007 10:28:22 +0200 Subject: [rspec-users] Nicer failure message formatting In-Reply-To: <190A2F5D-96D3-49D2-805A-4B8209B32F53@wincent.com> References: <190A2F5D-96D3-49D2-805A-4B8209B32F53@wincent.com> Message-ID: <389B0522-7590-4B3D-AC88-162B80BC9F1E@wincent.com> El 22/6/2007, a las 15:34, Wincent Colaiuta escribi?: > El 22/6/2007, a las 14:36, Tom Locke escribi?: > >> Easier to read: >> >> expected: >> "this is a very long string blah blah" >> got: >> "this is a very very long string blah blah" >> (using ==) >> >> Comments? > > For me even easier to read would be: > > expected: "this is a very long string blah blah" > got : "this is a very very long string blah blah" > (using ==) I've whipped up a patch for this against the current trunk (r2153). I was sick of seeing output like this: Now I see output like this: So for really short strings ("foo" vs "bar") readability is about the same, and for longer strings like the ones in the linked examples the readability is much improved. For *really* long strings (which wrap over multiple lines) readability in the console still sucks. You can see this for yourself by resizing your browser window to see how readability goes down as soon as wrapping starts to take place. But this is still a big improvement. If you run your specs from inside TextMate then even long strings are much more readable, because SpecMate doesn't perform soft wrapping of long lines when showing diffs. Pasting the diff here: Will also try submitting via RubyForge, but I have a lot of troubling logging in thanks to the transparent proxy imposed by my ISP... :-( Cheers, Wincent From win at wincent.com Thu Jul 5 04:32:53 2007 From: win at wincent.com (Wincent Colaiuta) Date: Thu, 5 Jul 2007 10:32:53 +0200 Subject: [rspec-users] Nicer failure message formatting In-Reply-To: <389B0522-7590-4B3D-AC88-162B80BC9F1E@wincent.com> References: <190A2F5D-96D3-49D2-805A-4B8209B32F53@wincent.com> <389B0522-7590-4B3D-AC88-162B80BC9F1E@wincent.com> Message-ID: El 5/7/2007, a las 10:28, Wincent Colaiuta escribi?: > Pasting the diff here: > > > > Will also try submitting via RubyForge, but I have a lot of troubling > logging in thanks to the transparent proxy imposed by my ISP... :-( Managed to stay logged in long enough to get it submitted: Cheers, Wincent From has.sox at gmail.com Thu Jul 5 09:28:28 2007 From: has.sox at gmail.com (Daniel N) Date: Thu, 5 Jul 2007 23:28:28 +1000 Subject: [rspec-users] mocking methods in the controller. Message-ID: <2fff50390707050628i55391c60v75ea4b1b12e1311c@mail.gmail.com> Hi, I'm very new to rspec so please be patient with me. I've tried to take some of my tests out of the controller specs to check for things that are rendered. This has not worked so well, since my views have the controller method current_user in quite a few places. Is there any way that I can define this so that my views will be executed? Will this same thing occur for all helper methods that are definied in the controller? Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070705/1a8e6a3a/attachment.html From work at ashleymoran.me.uk Thu Jul 5 11:30:09 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 5 Jul 2007 16:30:09 +0100 Subject: [rspec-users] Fwd: argument constraints docs on www site References: <418CA05B-B966-472B-BE3E-EAFDDC6AF2B3@codeweavers.net> Message-ID: Hi Thought I had found an actual issue here but turned out it was me being an idiot. In the process though, I noticed that the rspec page docs say you should use ":anything" rather than "anything()", although it is deprecated. Any reason for that or does it just need updating? Ashley From dchelimsky at gmail.com Thu Jul 5 11:40:37 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 5 Jul 2007 10:40:37 -0500 Subject: [rspec-users] Fwd: argument constraints docs on www site In-Reply-To: References: <418CA05B-B966-472B-BE3E-EAFDDC6AF2B3@codeweavers.net> Message-ID: <57c63afe0707050840r7ca7e70ah383e860e4bc7d7f6@mail.gmail.com> On 7/5/07, Ashley Moran wrote: > Hi > > Thought I had found an actual issue here but turned out it was me > being an idiot. In the process though, I noticed that the rspec page > docs say you should use ":anything" rather than "anything()", > although it is deprecated. Any reason for that or does it just need > updating? It's updated in the trunk docs, so it'll get updated when we release 1.0.6. We don't generally update the site between releases because it's a hassle to manage. > > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at codeweavers.net Thu Jul 5 10:36:01 2007 From: ashley.moran at codeweavers.net (Ashley Moran) Date: Thu, 5 Jul 2007 15:36:01 +0100 Subject: [rspec-users] argument constraints docs on www site Message-ID: <418CA05B-B966-472B-BE3E-EAFDDC6AF2B3@codeweavers.net> Hi Thought I had found an actual issue here but turned out it was me being an idiot. In the process though, I noticed that the rspec page docs say you should use ":anything" rather than "anything()", although it is deprecated. Any reason for that or does it just need updating? Ashley -- ?If only we?d been written in Ruby.? Steve from Urbis upon hearing that the junk segment ?ALU? is repeated 300,000 times in the human genome Codeweavers Ltd (Registered in England and Wales No. 04092394. VAT registration no. 823826816) Address: Unit 11, Imex Technology Park, ST4 8LJ. Tel: 0870 443 0888 From cwdinfo at gmail.com Thu Jul 5 15:09:15 2007 From: cwdinfo at gmail.com (s.ross) Date: Thu, 5 Jul 2007 12:09:15 -0700 Subject: [rspec-users] Wording describe/it so specdocs look good In-Reply-To: References: Message-ID: <103B3F02-F94B-4BED-80B0-31ECD1006BBD@gmail.com> I'm looking through my specs and they work great, but they don't read as English. I'm wondering how others are phrasing these. Here are some examples: describe Agent do it 'should be possible to create one' do end end This reads as "Agent should be possible to create one". Any suggestions how the describe/it might better be worded? Thx From edward.og at gmail.com Thu Jul 5 15:19:59 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Thu, 05 Jul 2007 15:19:59 -0400 Subject: [rspec-users] Wording describe/it so specdocs look good In-Reply-To: <103B3F02-F94B-4BED-80B0-31ECD1006BBD@gmail.com> References: <103B3F02-F94B-4BED-80B0-31ECD1006BBD@gmail.com> Message-ID: <468D445F.9070507@gmail.com> > I'm looking through my specs and they work great, but they don't read > as English. I'm wondering how others are phrasing these. Here are > some examples: > > describe Agent do > it 'should be possible to create one' do > end > end Does describe Agent do it 'should be createable' do # stuff end end work for you? From cwdinfo at gmail.com Thu Jul 5 15:39:27 2007 From: cwdinfo at gmail.com (s.ross) Date: Thu, 5 Jul 2007 12:39:27 -0700 Subject: [rspec-users] Wording describe/it so specdocs look good In-Reply-To: <468D445F.9070507@gmail.com> References: <103B3F02-F94B-4BED-80B0-31ECD1006BBD@gmail.com> <468D445F.9070507@gmail.com> Message-ID: <56ECC68B-4B02-497F-BEEA-AD795F6B2D10@gmail.com> For that simple case, yes. But how about the case where I specify: Agent "should not be possible for the same user to rate the same agent twice with same kind of transaction" The English grammar gets a bit twisty. Perhaps: Agent "should not allow the same user to rate the same agent twice with the same kind of transaction" Thoughts? On Jul 5, 2007, at 12:19 PM, Edward Ocampo-Gooding wrote: >> I'm looking through my specs and they work great, but they don't read >> as English. I'm wondering how others are phrasing these. Here are >> some examples: >> >> describe Agent do >> it 'should be possible to create one' do >> end >> end > > Does > > describe Agent do > it 'should be createable' do > # stuff > end > end > > work for you? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Jul 5 15:52:46 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 5 Jul 2007 14:52:46 -0500 Subject: [rspec-users] Wording describe/it so specdocs look good In-Reply-To: <56ECC68B-4B02-497F-BEEA-AD795F6B2D10@gmail.com> References: <103B3F02-F94B-4BED-80B0-31ECD1006BBD@gmail.com> <468D445F.9070507@gmail.com> <56ECC68B-4B02-497F-BEEA-AD795F6B2D10@gmail.com> Message-ID: <57c63afe0707051252o6c248babw56aa3f76b2ecf292@mail.gmail.com> On 7/5/07, s.ross wrote: > For that simple case, yes. But how about the case where I specify: > > Agent "should not be possible for the same user to rate the same > agent twice with same kind of transaction" > > The English grammar gets a bit twisty. Perhaps: > > Agent "should not allow the same user to rate the same agent twice > with the same kind of transaction" > > Thoughts? How would you phrase all this with context/specify? Or, a bit further off target, TestCase/test_method? > > > On Jul 5, 2007, at 12:19 PM, Edward Ocampo-Gooding wrote: > > >> I'm looking through my specs and they work great, but they don't read > >> as English. I'm wondering how others are phrasing these. Here are > >> some examples: > >> > >> describe Agent do > >> it 'should be possible to create one' do > >> end > >> end > > > > Does > > > > describe Agent do > > it 'should be createable' do > > # stuff > > end > > end > > > > work for you? > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.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 cwdinfo at gmail.com Thu Jul 5 16:06:41 2007 From: cwdinfo at gmail.com (s.ross) Date: Thu, 5 Jul 2007 13:06:41 -0700 Subject: [rspec-users] Wording describe/it so specdocs look good In-Reply-To: <57c63afe0707051252o6c248babw56aa3f76b2ecf292@mail.gmail.com> References: <103B3F02-F94B-4BED-80B0-31ECD1006BBD@gmail.com> <468D445F.9070507@gmail.com> <56ECC68B-4B02-497F-BEEA-AD795F6B2D10@gmail.com> <57c63afe0707051252o6c248babw56aa3f76b2ecf292@mail.gmail.com> Message-ID: On Jul 5, 2007, at 12:52 PM, David Chelimsky wrote: >> Agent "should not allow the same user to rate the same agent twice >> with the same kind of transaction" >> >> Thoughts? > > How would you phrase all this with context/specify? Or, a bit further > off target, TestCase/test_method? > I wouldn't phrase it differently with context/specify and with TestCase/test_method, I'd probably care less because I wouldn't have been trained to create beautiful, self-documenting example descriptions :) I'm just thinking there must be a nicer way to express what I mean. From edward.og at gmail.com Thu Jul 5 16:24:40 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Thu, 05 Jul 2007 16:24:40 -0400 Subject: [rspec-users] Wording describe/it so specdocs look good In-Reply-To: <56ECC68B-4B02-497F-BEEA-AD795F6B2D10@gmail.com> References: <103B3F02-F94B-4BED-80B0-31ECD1006BBD@gmail.com> <468D445F.9070507@gmail.com> <56ECC68B-4B02-497F-BEEA-AD795F6B2D10@gmail.com> Message-ID: <468D5388.8080603@gmail.com> Does this work? describe Agent, "rated by a user with the same kind of transaction" do it 'should not be rated twice' do # stuff end end s.ross wrote: > For that simple case, yes. But how about the case where I specify: > > Agent "should not be possible for the same user to rate the same > agent twice with same kind of transaction" > > The English grammar gets a bit twisty. Perhaps: > > Agent "should not allow the same user to rate the same agent twice > with the same kind of transaction" > > Thoughts? > > > On Jul 5, 2007, at 12:19 PM, Edward Ocampo-Gooding wrote: > >>> I'm looking through my specs and they work great, but they don't read >>> as English. I'm wondering how others are phrasing these. Here are >>> some examples: >>> >>> describe Agent do >>> it 'should be possible to create one' do >>> end >>> end >> Does >> >> describe Agent do >> it 'should be createable' do >> # stuff >> end >> end >> >> work for you? >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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 don at donpetersen.net Thu Jul 5 16:25:28 2007 From: don at donpetersen.net (Don Petersen) Date: Thu, 5 Jul 2007 15:25:28 -0500 Subject: [rspec-users] Wording describe/it so specdocs look good In-Reply-To: References: <103B3F02-F94B-4BED-80B0-31ECD1006BBD@gmail.com> <468D445F.9070507@gmail.com> <56ECC68B-4B02-497F-BEEA-AD795F6B2D10@gmail.com> <57c63afe0707051252o6c248babw56aa3f76b2ecf292@mail.gmail.com> Message-ID: <753DD095-4ECE-48F9-B4D1-31A59450ACEC@donpetersen.net> I have no idea what the business logic is, but I guess I see a few words there which could be more concise. "should not allow" could become "disallows". Not much shorter, but I don't think it's written anywhere that everything must to start with "should"? "the same user to rate the same agent twice" could become "duplicate ratings" So maybe: Agent disallows duplicate ratings of the same transaction type Again I'm just taking a wild shot in the dark about your business logic from that description. I don't mention "user" or "agent" in mine. But we're already describing Agent, and can anything but a User rate an agent? If only a User can, do you even need to specify that it's a User who is doing the rating? I do find exercises like this where you have to try and describe your problem domain succinctly helps to understand it, and to be able to talk to another developer or your customer intelligently about it. Don On Jul 5, 2007, at 3:06 PM, s.ross wrote: > > On Jul 5, 2007, at 12:52 PM, David Chelimsky wrote: > >>> Agent "should not allow the same user to rate the same agent twice >>> with the same kind of transaction" >>> >>> Thoughts? >> >> How would you phrase all this with context/specify? Or, a bit further >> off target, TestCase/test_method? >> > > I wouldn't phrase it differently with context/specify and with > TestCase/test_method, I'd probably care less because I wouldn't have > been trained to create beautiful, self-documenting example > descriptions :) > > I'm just thinking there must be a nicer way to express what I mean. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From crafterm at gmail.com Fri Jul 6 02:11:30 2007 From: crafterm at gmail.com (Marcus Crafter) Date: Fri, 6 Jul 2007 16:11:30 +1000 Subject: [rspec-users] Edge, link_to and mocks Message-ID: Hi All, Anyone noticed that using the newer link_to syntax in edge currently fails with mocked objects in view specs or helpers. eg. if you have something like the following in your view (or equivalent in a helper): <%= link_to @dog.name, @dog %> as opposed to the current 1.2 syntax: <%= link_to @dog.name, dog_path(@dog) %> Using a mock_model as the 'dog' will raise a: undefined method `polymorphic_path' for [Dynamically generated class for RSpec example]:# error - I presume due to the introspection on the @dog object to find out what kind of class it is to create it's URL. Anyone worked around this at all, other than using the older syntax? Any ideas appreciated. Cheers, Marcus From dchelimsky at gmail.com Fri Jul 6 03:00:28 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 6 Jul 2007 02:00:28 -0500 Subject: [rspec-users] Edge, link_to and mocks In-Reply-To: References: Message-ID: <57c63afe0707060000i5b5fef29l5e017e22c4db3739@mail.gmail.com> On 7/6/07, Marcus Crafter wrote: > Hi All, > > Anyone noticed that using the newer link_to syntax in edge currently > fails with mocked objects in view specs or helpers. > > eg. if you have something like the following in your view (or > equivalent in a helper): > > <%= link_to @dog.name, @dog %> > > as opposed to the current 1.2 syntax: > > <%= link_to @dog.name, dog_path(@dog) %> > > Using a mock_model as the 'dog' will raise a: > > undefined method `polymorphic_path' for [Dynamically generated class > for RSpec example]:# > > error - I presume due to the introspection on the @dog object to find > out what kind of class it is to create it's URL. > > Anyone worked around this at all, other than using the older syntax? > Any ideas appreciated. All mock_model does is that it wraps mock, adding some method stubs. So you can do this: thing = mock_model(Thing) thing.polymorphic_path = 'whatever' ... Also - please report this sort of thing to rspec's tracker: http://rubyforge.org/tracker/?group_id=797 > > Cheers, > > Marcus > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jul 6 03:07:40 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 6 Jul 2007 02:07:40 -0500 Subject: [rspec-users] Testing Rails Associations In-Reply-To: <2fff50390707032138y9ba5542pd92087d78ae33712@mail.gmail.com> References: <2fff50390707032138y9ba5542pd92087d78ae33712@mail.gmail.com> Message-ID: <57c63afe0707060007n467399d7r7987fa92a849f953@mail.gmail.com> On 7/3/07, Daniel N wrote: > Hi, > > I'm very new to rspec, so if this is not the right forum please let me > know. > > I'm starting to spec my models first in an existing rails app, porting from > a mix of Test::Unit, and simply_bdd amongst others. > > I'm at the point where I want to test that certain associations are > present. What I'm not sure of is should I test the association or the > method and return object. > > That is, if I wanted to test a has_many should I: > > Confirm the methods exist, and that the return an array etc > > OR > > Check that the model has the named has_many association through it's > reflections. > > On one hand the second one looks like it will be a bit more robust, since > if there is a has_many relationship, then all the associated methods may be > used througout the app. This would put testing in the one place. > > On the other hand, this would be really testing the implementation of the > model rather than it's behaviour. The behaviour is to call > @article.comments and have an array of comments returned. > > Any thoughts? I think the jury is still out on this one. Both approaches present problems, and no better approaches have been proposed. I'd say try it both ways and report back on experiences. David > Cheers > Daniel > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jul 6 03:11:14 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 6 Jul 2007 02:11:14 -0500 Subject: [rspec-users] mocking methods in the controller. In-Reply-To: <2fff50390707050628i55391c60v75ea4b1b12e1311c@mail.gmail.com> References: <2fff50390707050628i55391c60v75ea4b1b12e1311c@mail.gmail.com> Message-ID: <57c63afe0707060011w1c5d35e9l293e075dab359bd7@mail.gmail.com> On 7/5/07, Daniel N wrote: > Hi, > > I'm very new to rspec so please be patient with me. > > I've tried to take some of my tests out of the controller specs to check for > things that are rendered. > > This has not worked so well, since my views have the controller method > > current_user > > in quite a few places. > > Is there any way that I can define this so that my views will be executed? > Will this same thing occur for all helper methods that are definied in the > controller? If I understand you correctly, you are trying to take tests for views that were previously rails functional tests and turn them into rspec view examples. If that is the case, you should be able to do this: template.stub!(:current_user).and_return(mock_model(User)) If not, please provide an explicit example so we can better understand what you're talking about. Cheers, David > > Cheers > Daniel > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Fri Jul 6 03:35:13 2007 From: has.sox at gmail.com (Daniel N) Date: Fri, 6 Jul 2007 17:35:13 +1000 Subject: [rspec-users] mocking methods in the controller. In-Reply-To: <57c63afe0707060011w1c5d35e9l293e075dab359bd7@mail.gmail.com> References: <2fff50390707050628i55391c60v75ea4b1b12e1311c@mail.gmail.com> <57c63afe0707060011w1c5d35e9l293e075dab359bd7@mail.gmail.com> Message-ID: <2fff50390707060035nb036c50qe4440feb836f5076@mail.gmail.com> On 7/6/07, David Chelimsky wrote: > > On 7/5/07, Daniel N wrote: > > Hi, > > > > I'm very new to rspec so please be patient with me. > > > > I've tried to take some of my tests out of the controller specs to check > for > > things that are rendered. > > > > This has not worked so well, since my views have the controller method > > > > current_user > > > > in quite a few places. > > > > Is there any way that I can define this so that my views will be > executed? > > Will this same thing occur for all helper methods that are definied in > the > > controller? > > If I understand you correctly, you are trying to take tests for views > that were previously rails functional tests and turn them into rspec > view examples. If that is the case, you should be able to do this: > > template.stub!(:current_user).and_return(mock_model(User)) > > If not, please provide an explicit example so we can better understand > what you're talking about. > > Cheers, > David Thanx David, That looks like what I was looking for. I will try it when I get home. Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070706/d0825410/attachment.html From has.sox at gmail.com Fri Jul 6 03:49:52 2007 From: has.sox at gmail.com (Daniel N) Date: Fri, 6 Jul 2007 17:49:52 +1000 Subject: [rspec-users] Testing Rails Associations In-Reply-To: <57c63afe0707060007n467399d7r7987fa92a849f953@mail.gmail.com> References: <2fff50390707032138y9ba5542pd92087d78ae33712@mail.gmail.com> <57c63afe0707060007n467399d7r7987fa92a849f953@mail.gmail.com> Message-ID: <2fff50390707060049l17ecd756h7d8874c7989f0999@mail.gmail.com> On 7/6/07, David Chelimsky wrote: > > On 7/3/07, Daniel N wrote: > > Hi, > > > > I'm very new to rspec, so if this is not the right forum please let me > > know. > > > > I'm starting to spec my models first in an existing rails app, porting > from > > a mix of Test::Unit, and simply_bdd amongst others. > > > > I'm at the point where I want to test that certain associations are > > present. What I'm not sure of is should I test the association or the > > method and return object. > > > > That is, if I wanted to test a has_many should I: > > > > Confirm the methods exist, and that the return an array etc > > > > OR > > > > Check that the model has the named has_many association through it's > > reflections. > > > > On one hand the second one looks like it will be a bit more robust, > since > > if there is a has_many relationship, then all the associated methods may > be > > used througout the app. This would put testing in the one place. > > > > On the other hand, this would be really testing the implementation of > the > > model rather than it's behaviour. The behaviour is to call > > @article.comments and have an array of comments returned. > > > > Any thoughts? > > I think the jury is still out on this one. Both approaches present > problems, and no better approaches have been proposed. I'd say try it > both ways and report back on experiences. > > David > > > Cheers > > Daniel > > I went with the second way, testing the association through reflections. The reason I did this is that by testing that there is a has_* or belongs_to you are really testing the availablity of all the assoicated methods. Which you are then free to use throughout your app. If you go the other way, you are not in fact testing if a model "has_many" since this implies that all has_many methods will be included, not just returning and setting an Array. If your interested I've put up the module that I am using to provide these and a couple of other methods on pastie. This is my first go so please don't expect anything spectacular. http://pastie.caboo.se/76462 Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070706/0cef0276/attachment.html From has.sox at gmail.com Fri Jul 6 04:40:52 2007 From: has.sox at gmail.com (Daniel N) Date: Fri, 6 Jul 2007 18:40:52 +1000 Subject: [rspec-users] Testing Rails Associations In-Reply-To: <2fff50390707060049l17ecd756h7d8874c7989f0999@mail.gmail.com> References: <2fff50390707032138y9ba5542pd92087d78ae33712@mail.gmail.com> <57c63afe0707060007n467399d7r7987fa92a849f953@mail.gmail.com> <2fff50390707060049l17ecd756h7d8874c7989f0999@mail.gmail.com> Message-ID: <2fff50390707060140p59c91492sb8667c81704d794c@mail.gmail.com> On 7/6/07, Daniel N wrote: > > > > On 7/6/07, David Chelimsky wrote: > > On 7/3/07, Daniel N wrote: > > > Hi, > > > > > > I'm very new to rspec, so if this is not the right forum please let me > > > know. > > > > > > I'm starting to spec my models first in an existing rails app, porting > from > > > a mix of Test::Unit, and simply_bdd amongst others. > > > > > > I'm at the point where I want to test that certain associations are > > > present. What I'm not sure of is should I test the association or the > > > method and return object. > > > > > > That is, if I wanted to test a has_many should I: > > > > > > Confirm the methods exist, and that the return an array etc > > > > > > OR > > > > > > Check that the model has the named has_many association through it's > > > reflections. > > > > > > On one hand the second one looks like it will be a bit more robust, > since > > > if there is a has_many relationship, then all the associated methods may > be > > > used througout the app. This would put testing in the one place. > > > > > > On the other hand, this would be really testing the implementation of > the > > > model rather than it's behaviour. The behaviour is to call > > > @article.comments and have an array of comments returned. > > > > > > Any thoughts? > > > > I think the jury is still out on this one. Both approaches present > > problems, and no better approaches have been proposed. I'd say try it > > both ways and report back on experiences. > > > > David > > > > > Cheers > > > Daniel > > > > > I went with the second way, testing the association through reflections. > The reason I did this is that by testing that there is a has_* or belongs_to > you are really testing the availablity of all the assoicated methods. Which > you are then free to use throughout your app. > > If you go the other way, you are not in fact testing if a model "has_many" > since this implies that all has_many methods will be included, not just > returning and setting an Array. > > If your interested I've put up the module that I am using to provide these > and a couple of other methods on pastie. This is my first go so please > don't expect anything spectacular. > > http://pastie.caboo.se/76462 > > Cheers > Daniel > Wow I should really have checked that more thoroughly. I found many mistakes in that. Here is one I've fixed up. http://pastie.caboo.se/76470 Daniel From has.sox at gmail.com Fri Jul 6 08:42:29 2007 From: has.sox at gmail.com (Daniel N) Date: Fri, 6 Jul 2007 22:42:29 +1000 Subject: [rspec-users] mocking methods in the controller. In-Reply-To: <2fff50390707060035nb036c50qe4440feb836f5076@mail.gmail.com> References: <2fff50390707050628i55391c60v75ea4b1b12e1311c@mail.gmail.com> <57c63afe0707060011w1c5d35e9l293e075dab359bd7@mail.gmail.com> <2fff50390707060035nb036c50qe4440feb836f5076@mail.gmail.com> Message-ID: <2fff50390707060542x3c8e721ag619bfc8b375e9181@mail.gmail.com> On 7/6/07, Daniel N wrote: > > > > On 7/6/07, David Chelimsky wrote: > > > > On 7/5/07, Daniel N wrote: > > > Hi, > > > > > > I'm very new to rspec so please be patient with me. > > > > > > I've tried to take some of my tests out of the controller specs to > > check for > > > things that are rendered. > > > > > > This has not worked so well, since my views have the controller method > > > > > > current_user > > > > > > in quite a few places. > > > > > > Is there any way that I can define this so that my views will be > > executed? > > > Will this same thing occur for all helper methods that are definied in > > the > > > controller? > > > > If I understand you correctly, you are trying to take tests for views > > that were previously rails functional tests and turn them into rspec > > view examples. If that is the case, you should be able to do this: > > > > template.stub!(:current_user).and_return(mock_model(User)) > > > > If not, please provide an explicit example so we can better understand > > what you're talking about. > > > > Cheers, > > David > > > > Thanx David, > > That looks like what I was looking for. > > I will try it when I get home. > > Cheers > Daniel > Ok I've started to have a crack at this but it's getting way out of hand. Everytime I stub a method there's another one to do. I've also found that when there's a partial _detail and I've passed the :collection => @things to it it blows up complaining that the local variable is nil in dom_id( detail ) Am I doing someting wrong? The start of my specs is before do @u = mock_model( User ) @book = mock_model( Book ) public_book = mock_model( Book ) private_book = mock_model( Book ) public_book.stub!(:title=).and_return( "Public Title" ) private_book.stub!(:title=).and_return( "Private Title" ) public_book.stub!( :title ).and_return( "Public Title" ) private_book.stub!( :title ).and_return( "Private Title" ) @u.stub!( :public_books ).and_return( [public_book] ) @u.stub!( :private_books ).and_return( [private_book] ) @clip = mock_model( Clip ) @clip.stub!( :id ).and_return( 1 ) @clips = [ @clip ] template.stub!( :current_user ).and_return( @u ) end and I've only started. Is it normal to have to stub this much for a view? Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070706/c135d879/attachment.html From dchelimsky at gmail.com Fri Jul 6 08:59:28 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 6 Jul 2007 07:59:28 -0500 Subject: [rspec-users] mocking methods in the controller. In-Reply-To: <2fff50390707060542x3c8e721ag619bfc8b375e9181@mail.gmail.com> References: <2fff50390707050628i55391c60v75ea4b1b12e1311c@mail.gmail.com> <57c63afe0707060011w1c5d35e9l293e075dab359bd7@mail.gmail.com> <2fff50390707060035nb036c50qe4440feb836f5076@mail.gmail.com> <2fff50390707060542x3c8e721ag619bfc8b375e9181@mail.gmail.com> Message-ID: <57c63afe0707060559l58fd8826k91afd8b2d696e0d3@mail.gmail.com> On 7/6/07, Daniel N wrote: > On 7/6/07, Daniel N wrote: > > On 7/6/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > On 7/5/07, Daniel N wrote: > > > > Hi, > > > > > > > > I'm very new to rspec so please be patient with me. > > > > > > > > I've tried to take some of my tests out of the controller specs to > check for > > > > things that are rendered. > > > > > > > > This has not worked so well, since my views have the controller method > > > > > > > > current_user > > > > > > > > in quite a few places. > > > > > > > > Is there any way that I can define this so that my views will be > executed? > > > > Will this same thing occur for all helper methods that are definied in > the > > > > controller? > > > > > > If I understand you correctly, you are trying to take tests for views > > > that were previously rails functional tests and turn them into rspec > > > view examples. If that is the case, you should be able to do this: > > > > > > > template.stub!(:current_user).and_return(mock_model(User)) > > > > > > If not, please provide an explicit example so we can better understand > > > what you're talking about. > > > > > > Cheers, > > > David > > > > > > > > Thanx David, > > > > That looks like what I was looking for. > > > > I will try it when I get home. > > > > Cheers > > Daniel > > Ok I've started to have a crack at this but it's getting way out of hand. > Everytime I stub a method there's another one to do. > > I've also found that when there's a partial _detail and I've passed the > :collection => @things to it it blows up complaining that the local variable > is nil in > dom_id( detail ) If you're using the trunk, you can do this: template.expects_render(:partial => 'detail', :collection => @things) > > Am I doing someting wrong? The start of my specs is > > before do > @u = mock_model( User ) > @book = mock_model( Book ) > > public_book = mock_model( Book ) > private_book = mock_model( Book ) > public_book.stub!(:title=).and_return( "Public Title" ) > private_book.stub!(:title=).and_return( "Private Title" > ) > public_book.stub!( :title ).and_return( "Public Title" ) > private_book.stub!( :title ).and_return( "Private Title" ) Why are you stubbing the same calls twice each? > > @u.stub!( :public_books ).and_return( [public_book] ) > @u.stub!( :private_books ).and_return( [private_book] ) > @clip = mock_model( Clip ) > @clip.stub!( :id ).and_return( 1 ) > @clips = [ @clip ] > > template.stub!( :current_user ).and_return( @u ) > end > > and I've only started. Is it normal to have to stub this much for a view? Depends on how much stuff is in your view :) You've got a couple of options. You could create instances of the model instead. As long as you're not saving and retrieving them there's very little db interaction - just enough for AR to discover the attributes. If you prefer to keep it all mocked/stubbed, you could clean up a bit like this: before do @u = mock_model( User ) @book = mock_model( Book ) public_book = mock_model(Book, :title => 'Public Title') private_book = mock_model( Book, :title => 'Private Title') @u.stub!( :public_books ).and_return( [public_book] ) @u.stub!( :private_books ).and_return( [private_book] ) @clips = [ @clip = mock_model( Clip, :id => 1 ) ] template.stub!( :current_user ).and_return( @u ) end That stubs the same amount of stuff, but its a little cleaner. You could also write a shared behaviour that stubs current user: describe "authenticated page view", :shared => true do before(:each) do template.stub!( :current_user ).and_return( @u ) end end describe "/some/page" it_should_behave_like "authenticated page view" before(:each) do @u = mock_model( User ) @book = mock_model( Book ) public_book = mock_model(Book, :title => 'Public Title') private_book = mock_model( Book, :title => 'Private Title') @u.stub!( :public_books ).and_return( [public_book] ) @u.stub!( :private_books ).and_return( [private_book] ) @clips = [ @clip = mock_model( Clip, :id => 1 ) ] end end There's probably a bit more to clean up but I'd have to see the view code. Would you mind letting us see it? > > Cheers > Daniel > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Fri Jul 6 10:27:16 2007 From: has.sox at gmail.com (Daniel N) Date: Sat, 7 Jul 2007 00:27:16 +1000 Subject: [rspec-users] mocking methods in the controller. In-Reply-To: <57c63afe0707060559l58fd8826k91afd8b2d696e0d3@mail.gmail.com> References: <2fff50390707050628i55391c60v75ea4b1b12e1311c@mail.gmail.com> <57c63afe0707060011w1c5d35e9l293e075dab359bd7@mail.gmail.com> <2fff50390707060035nb036c50qe4440feb836f5076@mail.gmail.com> <2fff50390707060542x3c8e721ag619bfc8b375e9181@mail.gmail.com> <57c63afe0707060559l58fd8826k91afd8b2d696e0d3@mail.gmail.com> Message-ID: <2fff50390707060727m1ac54674m1ed9aea4869d96c5@mail.gmail.com> On 7/6/07, David Chelimsky wrote: > > On 7/6/07, Daniel N wrote: > > On 7/6/07, Daniel N wrote: > > > On 7/6/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > On 7/5/07, Daniel N wrote: > > > > > Hi, > > > > > > > > > > I'm very new to rspec so please be patient with me. > > > > > > > > > > I've tried to take some of my tests out of the controller specs to > > check for > > > > > things that are rendered. > > > > > > > > > > This has not worked so well, since my views have the controller > method > > > > > > > > > > current_user > > > > > > > > > > in quite a few places. > > > > > > > > > > Is there any way that I can define this so that my views will be > > executed? > > > > > Will this same thing occur for all helper methods that are > definied in > > the > > > > > controller? > > > > > > > > If I understand you correctly, you are trying to take tests for > views > > > > that were previously rails functional tests and turn them into rspec > > > > view examples. If that is the case, you should be able to do this: > > > > > > > > > > template.stub!(:current_user).and_return(mock_model(User)) > > > > > > > > If not, please provide an explicit example so we can better > understand > > > > what you're talking about. > > > > > > > > Cheers, > > > > David > > > > > > > > > > > > Thanx David, > > > > > > That looks like what I was looking for. > > > > > > I will try it when I get home. > > > > > > Cheers > > > Daniel > > > > Ok I've started to have a crack at this but it's getting way out of > hand. > > Everytime I stub a method there's another one to do. > > > > I've also found that when there's a partial _detail and I've passed the > > :collection => @things to it it blows up complaining that the local > variable > > is nil in > > dom_id( detail ) > > If you're using the trunk, you can do this: > > template.expects_render(:partial => 'detail', :collection => @things) > > > > > Am I doing someting wrong? The start of my specs is > > > > before do > > @u = mock_model( User ) > > @book = mock_model( Book ) > > > > public_book = mock_model( Book ) > > private_book = mock_model( Book ) > > public_book.stub!(:title=).and_return( "Public Title" ) > > private_book.stub!(:title=).and_return( "Private Title" > > ) > > public_book.stub!( :title ).and_return( "Public Title" ) > > private_book.stub!( :title ).and_return( "Private Title" ) > > Why are you stubbing the same calls twice each? > > > > > @u.stub!( :public_books ).and_return( [public_book] ) > > @u.stub!( :private_books ).and_return( [private_book] ) > > @clip = mock_model( Clip ) > > @clip.stub!( :id ).and_return( 1 ) > > @clips = [ @clip ] > > > > template.stub!( :current_user ).and_return( @u ) > > end > > > > and I've only started. Is it normal to have to stub this much for a > view? > > Depends on how much stuff is in your view :) > > You've got a couple of options. You could create instances of the > model instead. As long as you're not saving and retrieving them > there's very little db interaction - just enough for AR to discover > the attributes. > > If you prefer to keep it all mocked/stubbed, you could clean up a bit like > this: > > before do > @u = mock_model( User ) > @book = mock_model( Book ) > > public_book = mock_model(Book, :title => 'Public Title') > private_book = mock_model( Book, :title => 'Private Title') > > @u.stub!( :public_books ).and_return( [public_book] ) > @u.stub!( :private_books ).and_return( [private_book] ) > > @clips = [ @clip = mock_model( Clip, :id => 1 ) ] > > template.stub!( :current_user ).and_return( @u ) > end > > That stubs the same amount of stuff, but its a little cleaner. You > could also write a shared behaviour that stubs current user: > > describe "authenticated page view", :shared => true do > before(:each) do > template.stub!( :current_user ).and_return( @u ) > end > end > > describe "/some/page" > it_should_behave_like "authenticated page view" > > before(:each) do > @u = mock_model( User ) > @book = mock_model( Book ) > > public_book = mock_model(Book, :title => 'Public Title') > private_book = mock_model( Book, :title => 'Private Title') > > @u.stub!( :public_books ).and_return( [public_book] ) > @u.stub!( :private_books ).and_return( [private_book] ) > > @clips = [ @clip = mock_model( Clip, :id => 1 ) ] > > end > end > > There's probably a bit more to clean up but I'd have to see the view > code. Would you mind letting us see it? > > > > > Cheers > > Daniel index.html.erb <% content_for :action_bar do %> <% @public_books = current_user.public_books %> <% @private_books = current_user.private_books %> <%= render :file => 'books/_book_list.html.erb' -%> <% end %> <% if @book %>

<%= @book.title -%>

<%= render :partial => 'detail', :collection => @clips %>
<% else %> <%= render :partial => 'detail', :collection => @clips -%> <% end %> detail.html.erb

<%= detail.title-%>

<%= URI.parse( detail.url).host -%>
<%= detail.created_at.to_s( :long ) -%>
    <%= render :partial => 'action_menu_links', :locals => { :clip => detail, :book => @book } -%>
    <%= render :partial => 'alternative_content_links', :locals => { :clip => detail } -%>
<% render_as = @view_type || 'html' %> <% render_as = 'html' unless Clip.available_types.include?( render_as ) %> <% case render_as %> <% when 'quote' %> <%= render :partial => 'text', :locals => { :clip => detail } %> <% when 'images' %> <%= render :partial => 'images', :locals => { :clip => detail } %> <% when 'html' %> <%= render :partial => 'html', :locals => { :clip => detail } %> <% end %>
The _text, _images, _html partials are very simple so I won't show them here. This will be enough I think to evaluate it. Thankyou for helping with this. Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070707/7a172439/attachment.html From jed.hurt at gmail.com Fri Jul 6 11:45:39 2007 From: jed.hurt at gmail.com (Jed Hurt) Date: Fri, 6 Jul 2007 09:45:39 -0600 Subject: [rspec-users] Outside-In with RSpec on Rails Message-ID: I just read 'Mocks Aren't Stubs' and was intrigued by the notion of 'outside-in' TDD. As a Rails developer, I'm curious if others are employing this method when developing Rails applications using RSpec. Is it common practice (or even practical) to drive the development of a Rails app by starting with view specs, then controller specs, then models? From dchelimsky at gmail.com Fri Jul 6 11:55:09 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 6 Jul 2007 10:55:09 -0500 Subject: [rspec-users] Outside-In with RSpec on Rails In-Reply-To: References: Message-ID: <57c63afe0707060855k501bf8a0l8a1eed29f76a95ee@mail.gmail.com> On 7/6/07, Jed Hurt wrote: > I just read 'Mocks Aren't Stubs' and was intrigued by the notion of > 'outside-in' TDD. > > As a Rails developer, I'm curious if others are employing this method > when developing Rails applications using RSpec. Is it common practice > (or even practical) to drive the development of a Rails app by > starting with view specs, then controller specs, then models? Common? Not from what I've seen. I think that most ppl seem to start w/ the controller. That said, I've been starting with the views with some success. I find that when I've started with the controller, I've ended up doing a lot more refactoring once that slice was done (i.e. a given view/controller action/model trio) than I do when I start w/ the view. In other words, the designs that emerge when I start w/ views are closer to the designs that I want. This is just me. I'm not advocating that this will work for everybody. David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jcfischer.lists at gmail.com Fri Jul 6 12:07:42 2007 From: jcfischer.lists at gmail.com (Jens-Christian Fischer) Date: Fri, 6 Jul 2007 18:07:42 +0200 Subject: [rspec-users] stubbing helper methods for View specs Message-ID: <64BFD93F-71D6-47E0-A4C0-22DEBDB6C6DD@gmail.com> Hi there I have several view specs, that include the following snippet in their "before" block to stub the methods by acts_as_authenticated before :each do @u = mock_model(User) @u.should_receive(:name).and_return("Hans Muster") template.should_receive(:logged_in?).and_return(true) template.should_receive(:current_user).and_return(@u) end this works for views / helpers like this: it "should show bla" do render "/layouts/thetool" response.should have_tag("p", "bla") end and the view (haml to make things more interesting) - if logged_in? %p bla Now I also use Ezra acl_system2 plugin which defines a "restrict_to" method that queries some roles. When I stub the methods above and run specs, I get the following error: ActionView::TemplateError in '/users/show should display the information of the user' undefined local variable or method `current_user' for # On line #59 of app/views/users/show.haml 56: - @user.roles.each do |role| 57: = role.title 58: 59: - restrict_to "admin | projektleiter" do 60: = link_to "Bearbeiten", edit_user_url(@user) app/views//users/show.haml:59 vendor/plugins/acl_system2/lib/caboose/access_control.rb:75:in `restrict_to' (eval):2:in `restrict_to' (eval):164:in `_render_haml_1' vendor/plugins/haml/lib/haml/engine.rb:435:in `compile' vendor/plugins/haml/lib/haml/engine.rb:186:in `to_html' vendor/plugins/haml/lib/haml/template.rb:69:in `render' vendor/rails/actionpack/lib/action_view/base.rb:502:in `delegate_render' vendor/rails/actionpack/lib/action_view/base.rb:324:in `render_template_old' vendor/plugins/haml/lib/haml/template.rb:96:in `render_template' vendor/rails/actionpack/lib/action_view/base.rb:286:in `globalize_old_render_file' vendor/plugins/trunk/lib/globalize/rails/action_view.rb:20:in `render_file' vendor/rails/actionpack/lib/action_controller/base.rb:879:in `render_file' vendor/rails/actionpack/lib/action_controller/base.rb:814:in `render_with_no_layout' vendor/rails/actionpack/lib/action_controller/layout.rb:258:in `render_without_benchmark' vendor/rails/actionpack/lib/action_controller/benchmarking.rb: 51:in `render' /usr/local/lib/ruby/site_ruby/1.8/benchmark.rb:300:in `measure' vendor/rails/actionpack/lib/action_controller/benchmarking.rb: 51:in `render' vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/ view.rb:51:in `render' spec/views/users/show_haml_spec.rb:23 ... Interestingly, when I misspell the name of the stub in the working example, I get the following error: 1) ActionView::TemplateError in '/shared/layout_test not logged in should have the correct head information' undefined method `logged_in?' for # On line #13 of app/views/layouts/thetool.haml app/views//layouts/thetool.haml:13 app/helpers/application_helper.rb:5:in `login_logout' (eval):28:in `_render_haml_1' vendor/plugins/haml/lib/haml/engine.rb:435:in `compile' vendor/plugins/haml/lib/haml/engine.rb:186:in `to_html' vendor/plugins/haml/lib/haml/template.rb:69:in `render' vendor/rails/actionpack/lib/action_view/base.rb:502:in `delegate_render' vendor/rails/actionpack/lib/action_view/base.rb:324:in `render_template_old' vendor/plugins/haml/lib/haml/template.rb:96:in `render_template' vendor/rails/actionpack/lib/action_view/base.rb:286:in `globalize_old_render_file' vendor/plugins/trunk/lib/globalize/rails/action_view.rb:20:in `render_file' vendor/rails/actionpack/lib/action_controller/base.rb:879:in `render_file' vendor/rails/actionpack/lib/action_controller/base.rb:814:in `render_with_no_layout' vendor/rails/actionpack/lib/action_controller/layout.rb:258:in `render_without_benchmark' vendor/rails/actionpack/lib/action_controller/benchmarking.rb: 51:in `render' /usr/local/lib/ruby/site_ruby/1.8/benchmark.rb:300:in `measure' vendor/rails/actionpack/lib/action_controller/benchmarking.rb: 51:in `render' vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/ view.rb:51:in `render' spec/views/layouts/thetool_haml_spec.rb:16 Note the different class (# vs #) in the two specs. I don't have enough rspec_fu to deduce where the problem lies.. Any helpers? thanks Jens-Christian From jed.hurt at gmail.com Fri Jul 6 12:13:49 2007 From: jed.hurt at gmail.com (Jed Hurt) Date: Fri, 6 Jul 2007 10:13:49 -0600 Subject: [rspec-users] Outside-In with RSpec on Rails In-Reply-To: <57c63afe0707060855k501bf8a0l8a1eed29f76a95ee@mail.gmail.com> References: <57c63afe0707060855k501bf8a0l8a1eed29f76a95ee@mail.gmail.com> Message-ID: Cool. I'll have to give it a try on my next project. On 7/6/07, David Chelimsky wrote: > On 7/6/07, Jed Hurt wrote: > > I just read 'Mocks Aren't Stubs' and was intrigued by the notion of > > 'outside-in' TDD. > > > > As a Rails developer, I'm curious if others are employing this method > > when developing Rails applications using RSpec. Is it common practice > > (or even practical) to drive the development of a Rails app by > > starting with view specs, then controller specs, then models? > > Common? Not from what I've seen. I think that most ppl seem to start > w/ the controller. > > That said, I've been starting with the views with some success. I find > that when I've started with the controller, I've ended up doing a lot > more refactoring once that slice was done (i.e. a given > view/controller action/model trio) than I do when I start w/ the view. > In other words, the designs that emerge when I start w/ views are > closer to the designs that I want. > > This is just me. I'm not advocating that this will work for everybody. > > David > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jul 6 12:17:10 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 6 Jul 2007 11:17:10 -0500 Subject: [rspec-users] mocking methods in the controller. In-Reply-To: <2fff50390707060727m1ac54674m1ed9aea4869d96c5@mail.gmail.com> References: <2fff50390707050628i55391c60v75ea4b1b12e1311c@mail.gmail.com> <57c63afe0707060011w1c5d35e9l293e075dab359bd7@mail.gmail.com> <2fff50390707060035nb036c50qe4440feb836f5076@mail.gmail.com> <2fff50390707060542x3c8e721ag619bfc8b375e9181@mail.gmail.com> <57c63afe0707060559l58fd8826k91afd8b2d696e0d3@mail.gmail.com> <2fff50390707060727m1ac54674m1ed9aea4869d96c5@mail.gmail.com> Message-ID: <57c63afe0707060917k4cfc3096ya9314bfcb551839@mail.gmail.com> On 7/6/07, Daniel N wrote: > > > > On 7/6/07, David Chelimsky wrote: > > On 7/6/07, Daniel N wrote: > > > On 7/6/07, Daniel N wrote: > > > > On 7/6/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > > On 7/5/07, Daniel N wrote: > > > > > > Hi, > > > > > > > > > > > > I'm very new to rspec so please be patient with me. > > > > > > > > > > > > I've tried to take some of my tests out of the controller specs to > > > check for > > > > > > things that are rendered. > > > > > > > > > > > > This has not worked so well, since my views have the controller > method > > > > > > > > > > > > current_user > > > > > > > > > > > > in quite a few places. > > > > > > > > > > > > Is there any way that I can define this so that my views will be > > > executed? > > > > > > Will this same thing occur for all helper methods that are > definied in > > > the > > > > > > controller? > > > > > > > > > > If I understand you correctly, you are trying to take tests for > views > > > > > that were previously rails functional tests and turn them into rspec > > > > > view examples. If that is the case, you should be able to do this: > > > > > > > > > > > > > > template.stub!(:current_user).and_return(mock_model(User)) > > > > > > > > > > If not, please provide an explicit example so we can better > understand > > > > > what you're talking about. > > > > > > > > > > Cheers, > > > > > David > > > > > > > > > > > > > > > > Thanx David, > > > > > > > > That looks like what I was looking for. > > > > > > > > I will try it when I get home. > > > > > > > > Cheers > > > > Daniel > > > > > > Ok I've started to have a crack at this but it's getting way out of > hand. > > > Everytime I stub a method there's another one to do. > > > > > > I've also found that when there's a partial _detail and I've passed the > > > :collection => @things to it it blows up complaining that the local > variable > > > is nil in > > > dom_id( detail ) > > > > If you're using the trunk, you can do this: > > > > template.expects_render(:partial => 'detail', :collection => @things) > > > > > > > > Am I doing someting wrong? The start of my specs is > > > > > > before do > > > @u = mock_model( User ) > > > @book = mock_model( Book ) > > > > > > public_book = mock_model( Book ) > > > private_book = mock_model( Book ) > > > public_book.stub!(:title=).and_return( "Public > Title" ) > > > private_book.stub!(:title=).and_return( "Private > Title" > > > ) > > > public_book.stub!( :title ).and_return( "Public Title" ) > > > private_book.stub!( :title ).and_return( "Private Title" ) > > > > Why are you stubbing the same calls twice each? > > > > > > > > @u.stub!( :public_books ).and_return( [public_book] ) > > > @u.stub!( :private_books ).and_return( [private_book] ) > > > @clip = mock_model( Clip ) > > > @clip.stub!( :id ).and_return( 1 ) > > > @clips = [ @clip ] > > > > > > template.stub!( :current_user ).and_return( @u ) > > > end > > > > > > and I've only started. Is it normal to have to stub this much for a > view? > > > > Depends on how much stuff is in your view :) > > > > You've got a couple of options. You could create instances of the > > model instead. As long as you're not saving and retrieving them > > there's very little db interaction - just enough for AR to discover > > the attributes. > > > > If you prefer to keep it all mocked/stubbed, you could clean up a bit like > this: > > > > before do > > @u = mock_model( User ) > > @book = mock_model( Book ) > > > > public_book = mock_model(Book, :title => 'Public Title') > > private_book = mock_model( Book, :title => 'Private Title') > > > > @u.stub!( :public_books ).and_return( [public_book] ) > > @u.stub!( :private_books ).and_return( [private_book] ) > > > > @clips = [ @clip = mock_model( Clip, :id => 1 ) ] > > > > template.stub!( :current_user ).and_return( @u ) > > end > > > > That stubs the same amount of stuff, but its a little cleaner. You > > could also write a shared behaviour that stubs current user: > > > > describe "authenticated page view", :shared => true do > > before(:each) do > > template.stub!( :current_user ).and_return( @u ) > > end > > end > > > > describe "/some/page" > > it_should_behave_like "authenticated page view" > > > > before(:each) do > > @u = mock_model( User ) > > @book = mock_model( Book ) > > > > public_book = mock_model(Book, :title => 'Public Title') > > private_book = mock_model( Book, :title => 'Private Title') > > > > @u.stub!( :public_books ).and_return( [public_book] ) > > @u.stub!( :private_books ).and_return( [private_book] ) > > > > @clips = [ @clip = mock_model( Clip, :id => 1 ) ] > > > > end > > end > > > > There's probably a bit more to clean up but I'd have to see the view > > code. Would you mind letting us see it? > > > > > > > > Cheers > > > Daniel > > > index.html.erb > > <% content_for :action_bar do %> > <% @public_books = current_user.public_books %> > <% @private_books = current_user.private_books %> > <%= render :file => 'books/_book_list.html.erb' -%> > <% end %> > > <% if @book %> >
>

<%= @book.title -%>

>
    >
  • > > >
  • >
> <%= render :partial => 'detail', :collection => @clips %> >
> <% else %> > <%= render :partial => 'detail', :collection => @clips -%> > > <% end %> > > > detail.html.erb >
>
> >

<%= detail.title > -%>

>
> <%= > URI.parse(detail.url).host -%>
> <%= detail.created_at.to_s ( :long ) -%> >
>
>
>
>
    > <%= render :partial => 'action_menu_links', :locals => { :clip > => detail, :book => @book } -%> >
>
    > <%= render :partial => 'alternative_content_links', :locals => { > :clip => detail } -%> >
>
>
> <% render_as = @view_type || 'html' %> > <% render_as = 'html' unless Clip.available_types.include?( render_as ) > %> > <% case render_as %> > <% when 'quote' %> > <%= render :partial => 'text', :locals => { :clip => detail > } %> > <% when 'images' %> > <%= render :partial => 'images', :locals => { :clip => detail > } %> > <% when 'html' %> > <%= render :partial => 'html', :locals => { :clip => > detail } %> > <% end %> > >
>
>
> > > The _text, _images, _html partials are very simple so I won't show them > here. This will be enough I think to evaluate it. > > Thank you for helping with this. OK - there's quite a bit going on here, and I don't really have time to address every detail right now - but here's a couple of things to think about: Conventional wisdom suggests that you should favor decision making in controllers and helpers rather than in the views themselves. One reason for this is that view templates boil down to a single method, so you have to provide all of the state they need every time. If your view has nothing but instance variables that get assigned from the controller, and never reach into them for their data, then you have nothing to set up in a test. Consider this: <% content_for :action_bar do %> <% @public_books = current_user.public_books %> <% @private_books = current_user.private_books %> <%= render :file => 'books/_book_list.html.erb' -%> <% end %> That design choice requires that you set up a current_user which can provide public_books and private_books. If, instead, you handled that in the controller, you'd still have to provide a current_user for the controller examples, but it becomes much easier to start pushing things around to different methods that can each be tested in isolation, so the setup for each can get smaller. If you did this, the view example might look like this: template.expects_render(:file => 'books/_book_list.html.erb') instead of this: template.stub!(:current_user).and_return( mock_model(User, :public_books => [], :private_books => [], ) ) template.expects_render(:file => 'books/_book_list.html.erb') Given what you've got, I think you could do this (with trunk) in before(:each): ============================ controller.stub!(:dom_id).and_return("anything") template.stub!(:current_user).and_return( mock_model(User, :public_books => [], :private_books => [], ) ) template.stubs_render(:file => 'books/_book_list.html.erb') template.stubs_render(:partial => 'detail', :collection => @clips) assigns[:clips] => [] assigns[:book] => mock_model(Book) ============================ Then you could use Message Expectations (mocks) in each example for the specific thing you want to describe. Hope this helps. David > > Daniel > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jul 6 14:27:47 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 6 Jul 2007 13:27:47 -0500 Subject: [rspec-users] stubbing helper methods for View specs In-Reply-To: <64BFD93F-71D6-47E0-A4C0-22DEBDB6C6DD@gmail.com> References: <64BFD93F-71D6-47E0-A4C0-22DEBDB6C6DD@gmail.com> Message-ID: <57c63afe0707061127i598c64b0k32e2229c82241782@mail.gmail.com> On 7/6/07, Jens-Christian Fischer wrote: > Hi there > > I have several view specs, that include the following snippet in > their "before" block to stub the methods by acts_as_authenticated > > before :each do > @u = mock_model(User) > @u.should_receive(:name).and_return("Hans Muster") > template.should_receive(:logged_in?).and_return(true) > template.should_receive(:current_user).and_return(@u) > end > > this works for views / helpers like this: > > it "should show bla" do > render "/layouts/thetool" > response.should have_tag("p", "bla") > end > > and the view (haml to make things more interesting) > > - if logged_in? > %p bla > > > Now I also use Ezra acl_system2 plugin which defines a "restrict_to" > method that queries some roles. When I stub the methods above and run > specs, I get the following error: > > ActionView::TemplateError in '/users/show should display the > information of the user' > undefined local variable or method `current_user' for > # > On line #59 of app/views/users/show.haml > > 56: - @user.roles.each do |role| > 57: = role.title > 58: > 59: - restrict_to "admin | projektleiter" do > 60: = link_to "Bearbeiten", edit_user_url(@user) > app/views//users/show.haml:59 > vendor/plugins/acl_system2/lib/caboose/access_control.rb:75:in > `restrict_to' > (eval):2:in `restrict_to' > (eval):164:in `_render_haml_1' > vendor/plugins/haml/lib/haml/engine.rb:435:in `compile' > vendor/plugins/haml/lib/haml/engine.rb:186:in `to_html' > vendor/plugins/haml/lib/haml/template.rb:69:in `render' > vendor/rails/actionpack/lib/action_view/base.rb:502:in > `delegate_render' > vendor/rails/actionpack/lib/action_view/base.rb:324:in > `render_template_old' > vendor/plugins/haml/lib/haml/template.rb:96:in `render_template' > vendor/rails/actionpack/lib/action_view/base.rb:286:in > `globalize_old_render_file' > vendor/plugins/trunk/lib/globalize/rails/action_view.rb:20:in > `render_file' > vendor/rails/actionpack/lib/action_controller/base.rb:879:in > `render_file' > vendor/rails/actionpack/lib/action_controller/base.rb:814:in > `render_with_no_layout' > vendor/rails/actionpack/lib/action_controller/layout.rb:258:in > `render_without_benchmark' > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > 51:in `render' > /usr/local/lib/ruby/site_ruby/1.8/benchmark.rb:300:in `measure' > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > 51:in `render' > vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/ > view.rb:51:in `render' > spec/views/users/show_haml_spec.rb:23 > ... > > > > Interestingly, when I misspell the name of the stub in the working > example, I get the following error: > > 1) > ActionView::TemplateError in '/shared/layout_test not logged in > should have the correct head information' > undefined method `logged_in?' for # > On line #13 of app/views/layouts/thetool.haml > > app/views//layouts/thetool.haml:13 > app/helpers/application_helper.rb:5:in `login_logout' > (eval):28:in `_render_haml_1' > vendor/plugins/haml/lib/haml/engine.rb:435:in `compile' > vendor/plugins/haml/lib/haml/engine.rb:186:in `to_html' > vendor/plugins/haml/lib/haml/template.rb:69:in `render' > vendor/rails/actionpack/lib/action_view/base.rb:502:in > `delegate_render' > vendor/rails/actionpack/lib/action_view/base.rb:324:in > `render_template_old' > vendor/plugins/haml/lib/haml/template.rb:96:in `render_template' > vendor/rails/actionpack/lib/action_view/base.rb:286:in > `globalize_old_render_file' > vendor/plugins/trunk/lib/globalize/rails/action_view.rb:20:in > `render_file' > vendor/rails/actionpack/lib/action_controller/base.rb:879:in > `render_file' > vendor/rails/actionpack/lib/action_controller/base.rb:814:in > `render_with_no_layout' > vendor/rails/actionpack/lib/action_controller/layout.rb:258:in > `render_without_benchmark' > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > 51:in `render' > /usr/local/lib/ruby/site_ruby/1.8/benchmark.rb:300:in `measure' > vendor/rails/actionpack/lib/action_controller/benchmarking.rb: > 51:in `render' > vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/ > view.rb:51:in `render' > spec/views/layouts/thetool_haml_spec.rb:16 > > > Note the different class (# vs > #) in the two specs. > > I don't have enough rspec_fu to deduce where the problem lies.. > > > Any helpers? In a nutshell - Rails compiles templates the first time they are encountered in a given runtime. Combine this with the fact that mock expectations are cleared out after every example, but the mock framework doesn't have access to the compiled template, and you can imagine that this is )(*&)(*ing nightmare-ish can of worms. I thought I had a solution for this in trunk, but I've just discovered some problems with it and am working to resolve them. Sorry - can't be more helpful right now. > > thanks > Jens-Christian > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jcfischer.lists at gmail.com Fri Jul 6 15:13:57 2007 From: jcfischer.lists at gmail.com (Jens-Christian Fischer) Date: Fri, 6 Jul 2007 21:13:57 +0200 Subject: [rspec-users] stubbing helper methods for View specs In-Reply-To: <57c63afe0707061127i598c64b0k32e2229c82241782@mail.gmail.com> References: <64BFD93F-71D6-47E0-A4C0-22DEBDB6C6DD@gmail.com> <57c63afe0707061127i598c64b0k32e2229c82241782@mail.gmail.com> Message-ID: <15B88DEF-F378-4013-B4E2-C3AB670F1339@gmail.com> >> >> I don't have enough rspec_fu to deduce where the problem lies.. >> >> >> Any helpers? > > In a nutshell - Rails compiles templates the first time they are > encountered in a given runtime. Combine this with the fact that mock > expectations are cleared out after every example, but the mock > framework doesn't have access to the compiled template, and you can > imagine that this is )(*&)(*ing nightmare-ish can of worms. > > I thought I had a solution for this in trunk, but I've just discovered > some problems with it and am working to resolve them. > > Sorry - can't be more helpful right now. so my best bet would be to use regular functional tests for the time being? (Having no specs/tests kind of seems to be the wrong solution to this problem... :) cheers jc From dchelimsky at gmail.com Fri Jul 6 15:17:43 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 6 Jul 2007 14:17:43 -0500 Subject: [rspec-users] stubbing helper methods for View specs In-Reply-To: <15B88DEF-F378-4013-B4E2-C3AB670F1339@gmail.com> References: <64BFD93F-71D6-47E0-A4C0-22DEBDB6C6DD@gmail.com> <57c63afe0707061127i598c64b0k32e2229c82241782@mail.gmail.com> <15B88DEF-F378-4013-B4E2-C3AB670F1339@gmail.com> Message-ID: <57c63afe0707061217i5ed65afg22764f9a6f35221@mail.gmail.com> On 7/6/07, Jens-Christian Fischer wrote: > >> > >> I don't have enough rspec_fu to deduce where the problem lies.. > >> > >> > >> Any helpers? > > > > In a nutshell - Rails compiles templates the first time they are > > encountered in a given runtime. Combine this with the fact that mock > > expectations are cleared out after every example, but the mock > > framework doesn't have access to the compiled template, and you can > > imagine that this is )(*&)(*ing nightmare-ish can of worms. > > > > I thought I had a solution for this in trunk, but I've just discovered > > some problems with it and am working to resolve them. > > > > Sorry - can't be more helpful right now. > > so my best bet would be to use regular functional tests for the time > being? (Having no specs/tests kind of seems to be the wrong solution > to this problem... Agreed that you shouldn't be without examples for this stuff, but you have other options within rspec: 1 - use rspec controller examples in integration mode and use real objects (almost exactly like rails functionals, except its rspec). 2 - use rspec view examples without mocking things directly on the template. You can still mock helper methods (on controller or helpers). > > :) > > cheers jc > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Mon Jul 9 09:55:09 2007 From: has.sox at gmail.com (Daniel N) Date: Mon, 9 Jul 2007 23:55:09 +1000 Subject: [rspec-users] Is it bad to use a shared example in rspec_helper.rb? Message-ID: <2fff50390707090655u457cf3fepc930114d24da6409@mail.gmail.com> I want to extract the method for logging in so that I don't have to include it in each before call. Is it bad to use a describe block within the rspec_helper in a rails project for controller tests? I have in my spec_helper.rb describe "an authenticated request", :shared => true do before( :each ) do @u = mock_model( User ) mock_login( @u ) end def mock_login( user ) session[:user] = user controller.send( :instance_variable_set, :@current_user, user ) controller.stub!( :current_user ).and_return( user ) end end which I then share in my relevant controller tests with it_should_behave_like "an authenticated request" Is this bad? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070709/d74c003f/attachment-0001.html From has.sox at gmail.com Mon Jul 9 10:31:33 2007 From: has.sox at gmail.com (Daniel N) Date: Tue, 10 Jul 2007 00:31:33 +1000 Subject: [rspec-users] Mocking User.find( :all, :limit => 10 ) Message-ID: <2fff50390707090731ob737113qa28680f3653cbcfe@mail.gmail.com> Hi, I'm trying to setup a mock for my controller test but I can't get it to recognise the mock. I use it "should find all users" do User.should_receive(:find).with( :all, :limit => 10 ).and_return([@user]) do_get end and in the controller @users = User.find(:all, :limit => 10 ) But this does not work. It gives me User expected :find with (:all) once, but received it 0 times If I remove the :limit from the controller @users = User.find(:all) I get User expected :find with (:all, {:limit=>10}) once, but received it 0 times How do I spec mocks with options passed to them? Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070710/4d8df89c/attachment.html From has.sox at gmail.com Mon Jul 9 11:00:31 2007 From: has.sox at gmail.com (Daniel N) Date: Tue, 10 Jul 2007 01:00:31 +1000 Subject: [rspec-users] Mocking User.find( :all, :limit => 10 ) In-Reply-To: <2fff50390707090731ob737113qa28680f3653cbcfe@mail.gmail.com> References: <2fff50390707090731ob737113qa28680f3653cbcfe@mail.gmail.com> Message-ID: <2fff50390707090800l1b75aa34s6914514a2ffc81fb@mail.gmail.com> My Bad... Please ignore On 7/10/07, Daniel N wrote: > > Hi, > > I'm trying to setup a mock for my controller test but I can't get it to > recognise the mock. > > I use > > it "should find all users" do > User.should_receive(:find).with( :all, :limit => 10 > ).and_return([@user]) > do_get > end > > and in the controller > @users = User.find(:all, :limit => 10 ) > > But this does not work. It gives me > User expected :find with (:all) once, but received it 0 times > > If I remove the :limit from the controller > @users = User.find(:all) > > I get > User expected :find with (:all, {:limit=>10}) once, but received it 0 > times > > How do I spec mocks with options passed to them? > > Cheers > Daniel > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070710/cb13ee46/attachment.html From johan at johansorensen.com Mon Jul 9 11:33:28 2007 From: johan at johansorensen.com (=?ISO-8859-1?Q?Johan_S=F8rensen?=) Date: Mon, 9 Jul 2007 17:33:28 +0200 Subject: [rspec-users] Mocking User.find( :all, :limit => 10 ) In-Reply-To: <2fff50390707090800l1b75aa34s6914514a2ffc81fb@mail.gmail.com> References: <2fff50390707090731ob737113qa28680f3653cbcfe@mail.gmail.com> <2fff50390707090800l1b75aa34s6914514a2ffc81fb@mail.gmail.com> Message-ID: <43731001-FC81-4843-A2AF-95145D960610@johansorensen.com> On Jul 9, 2007, at 5:00 PM, Daniel N wrote: > My Bad... Please ignore > > On 7/10/07, Daniel N wrote: > it "should find all users" do > User.should_receive(:find).with( :all, :limit => 10 ).and_return > ([@user]) > do_get > end Sorry for piggybacking on your post, but since you've apparantly figured out your isssue I have a slightly similar question; sometimes I have (in ActiveRecord) a verbose #find I want to mock out using should_receive, maybe looking something along this: Foo.find(:all, :select => "foos.*, bars.*, :joins => "join bazzers on foos.baz_id = ..", :conditions => "quux = 1", etc etc) ... But all I really may care about with a specific mock expectation is that it gets the right :conditions key in the passed-in hash. Is there a way in RSpec to check for a specific hash key (or evaluating other things along those lines) in the parameter expectation using the should_receive(:find).with(...) construct? JS -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070709/1bfa23f9/attachment.html From joshknowles at gmail.com Mon Jul 9 11:38:01 2007 From: joshknowles at gmail.com (Josh Knowles) Date: Mon, 9 Jul 2007 08:38:01 -0700 Subject: [rspec-users] Mocking User.find( :all, :limit => 10 ) In-Reply-To: <43731001-FC81-4843-A2AF-95145D960610@johansorensen.com> References: <2fff50390707090731ob737113qa28680f3653cbcfe@mail.gmail.com> <2fff50390707090800l1b75aa34s6914514a2ffc81fb@mail.gmail.com> <43731001-FC81-4843-A2AF-95145D960610@johansorensen.com> Message-ID: On 7/9/07, Johan S?rensen wrote: > > > > Is there a way in RSpec to check for a specific hash key (or evaluating > other things along those lines) in the parameter expectation using the > should_receive(:find).with(...) construct? > As opposed to getting into complicated mocking scenarios, consider abstracting this logic into your model: http://blog.caboo.se/articles/2007/6/19/rspec-notes-from-the-trenches-2 -- Josh Knowles joshknowles at gmail.com http://joshknowles.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070709/e823b7a8/attachment.html From johan at johansorensen.com Mon Jul 9 11:42:45 2007 From: johan at johansorensen.com (=?ISO-8859-1?Q?Johan_S=F8rensen?=) Date: Mon, 9 Jul 2007 17:42:45 +0200 Subject: [rspec-users] Mocking User.find( :all, :limit => 10 ) In-Reply-To: References: <2fff50390707090731ob737113qa28680f3653cbcfe@mail.gmail.com> <2fff50390707090800l1b75aa34s6914514a2ffc81fb@mail.gmail.com> <43731001-FC81-4843-A2AF-95145D960610@johansorensen.com> Message-ID: <15DB1604-33FE-4CFC-8598-12277477C40F@johansorensen.com> On Jul 9, 2007, at 5:38 PM, Josh Knowles wrote: > On 7/9/07, Johan S?rensen wrote: > > > Is there a way in RSpec to check for a specific hash key (or > evaluating other things along those lines) in the parameter > expectation using the should_receive(:find).with(...) construct? > > > As opposed to getting into complicated mocking scenarios, consider > abstracting this logic into your model: http://blog.caboo.se/ > articles/2007/6/19/rspec-notes-from-the-trenches-2 Well, that's where it is, and for various reasons writing to the database is something I'm avoiding as long as I can (speedy tests and complex fk constraints being a few of them). I'm still not convinced that it's a good idea to do that for model specs, but that's another topic ;) JS -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070709/661f9da8/attachment.html From dchelimsky at gmail.com Mon Jul 9 11:42:58 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 9 Jul 2007 10:42:58 -0500 Subject: [rspec-users] Mocking User.find( :all, :limit => 10 ) In-Reply-To: References: <2fff50390707090731ob737113qa28680f3653cbcfe@mail.gmail.com> <2fff50390707090800l1b75aa34s6914514a2ffc81fb@mail.gmail.com> <43731001-FC81-4843-A2AF-95145D960610@johansorensen.com> Message-ID: <57c63afe0707090842q20e4b9c3u7dd4851821af2df1@mail.gmail.com> On 7/9/07, Josh Knowles wrote: > > > On 7/9/07, Johan S?rensen wrote: > > > > > > > > > > > > Is there a way in RSpec to check for a specific hash key (or evaluating > other things along those lines) in the parameter expectation using the > should_receive(:find).with(...) construct? > > > As opposed to getting into complicated mocking scenarios, consider > abstracting this logic into your model: > http://blog.caboo.se/articles/2007/6/19/rspec-notes-from-the-trenches-2 Agreed that this is a good approach in terms of dealing w/ rails models. As for the question of isolating specific key/value pairs in a hash, you could do this: obj.should_receive(:message) do |*args| hash = args.pop hash[interesting_key].should == expected_value end It's not pretty, but it works. The other thing you might consider is a custom matcher. Something like: obj.should_receive(:message).with(has_key_value(key, value)) The mock framework can use these just as the expectation framework - though mocks rely on == instead of matches. David > > > > > -- > Josh Knowles > joshknowles at gmail.com > http://joshknowles.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From johan at johansorensen.com Mon Jul 9 13:41:18 2007 From: johan at johansorensen.com (=?ISO-8859-1?Q?Johan_S=F8rensen?=) Date: Mon, 9 Jul 2007 19:41:18 +0200 Subject: [rspec-users] Mocking User.find( :all, :limit => 10 ) In-Reply-To: <57c63afe0707090842q20e4b9c3u7dd4851821af2df1@mail.gmail.com> References: <2fff50390707090731ob737113qa28680f3653cbcfe@mail.gmail.com> <2fff50390707090800l1b75aa34s6914514a2ffc81fb@mail.gmail.com> <43731001-FC81-4843-A2AF-95145D960610@johansorensen.com> <57c63afe0707090842q20e4b9c3u7dd4851821af2df1@mail.gmail.com> Message-ID: On Jul 9, 2007, at 5:42 PM, David Chelimsky wrote: >> >> As opposed to getting into complicated mocking scenarios, consider >> abstracting this logic into your model: >> http://blog.caboo.se/articles/2007/6/19/rspec-notes-from-the- >> trenches-2 > > Agreed that this is a good approach in terms of dealing w/ rails > models. I generally agree with this, no doubt. But when the it comes to big apps and bigger test/spec suites, all that database communication (and fixtures creation/teardown), slows testruns downs and that lowers the chances of people running them regularly. There's of course many different ways of dealing with this (another I'm doing is reworking the way fixtures work), but in a way I see it the same way as I do with, say, XML-RPC models (or REST, or other networking related models) that I maybe I don't really need to test communication with the network backend all the time, but more interested in that my model implementation behave like I expect them to when it comes to sending data to the client. Of course this starts to turn into a slightly slippery slope when it comes to rails since it relies so much its direct database mapping. I'm still trying this approach out along with other things to cut down specs runtime , and I eagerly await the day it bites me in the arse. :) > As for the question of isolating specific key/value pairs in a > hash, you could do this: > > obj.should_receive(:message) do |*args| > hash = args.pop > hash[interesting_key].should == expected_value > end > > It's not pretty, but it works. > > The other thing you might consider is a custom matcher. Something > like: > > obj.should_receive(:message).with(has_key_value(key, value)) > > The mock framework can use these just as the expectation framework - > though mocks rely on == instead of matches. Cheers, I didn't know that you could do custom matchers for those kind of expectations too. JS -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070709/2f57838e/attachment-0001.html From dchelimsky at gmail.com Mon Jul 9 13:44:00 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 9 Jul 2007 12:44:00 -0500 Subject: [rspec-users] Mocking User.find( :all, :limit => 10 ) In-Reply-To: References: <2fff50390707090731ob737113qa28680f3653cbcfe@mail.gmail.com> <2fff50390707090800l1b75aa34s6914514a2ffc81fb@mail.gmail.com> <43731001-FC81-4843-A2AF-95145D960610@johansorensen.com> <57c63afe0707090842q20e4b9c3u7dd4851821af2df1@mail.gmail.com> Message-ID: <57c63afe0707091044qfc85513q2cd2853e290d3b9d@mail.gmail.com> On 7/9/07, Johan S?rensen wrote: > > > On Jul 9, 2007, at 5:42 PM, David Chelimsky wrote: > > > > > > > As opposed to getting into complicated mocking scenarios, consider > > abstracting this logic into your model: > > http://blog.caboo.se/articles/2007/6/19/rspec-notes-from-the-trenches-2 > > > > > Agreed that this is a good approach in terms of dealing w/ rails > > models. > > I generally agree with this, no doubt. But when the it comes to big apps and > bigger test/spec suites, all that database communication (and fixtures > creation/teardown), slows testruns downs and that lowers the chances of > people running them regularly. > There's of course many different ways of dealing with this (another I'm > doing is reworking the way fixtures work), but in a way I see it the same > way as I do with, say, XML-RPC models (or REST, or other networking related > models) that I maybe I don't really need to test communication with the > network backend all the time, but more interested in that my model > implementation behave like I expect them to when it comes to sending data to > the client. Of course this starts to turn into a slightly slippery slope > when it comes to rails since it relies so much its direct database mapping. > > I'm still trying this approach out along with other things to cut down specs > runtime , and I eagerly await the day it bites me in the arse. :) > > > As for the question of isolating specific key/value pairs in a > > hash, you could do this: > > > > > obj.should_receive(:message) do |*args| > > hash = args.pop > > hash[interesting_key].should == expected_value > > end > > > > > It's not pretty, but it works. > > > > > The other thing you might consider is a custom matcher. Something like: > > > > > obj.should_receive(:message).with(has_key_value(key, > value)) > > > > > The mock framework can use these just as the expectation framework - > > though mocks rely on == instead of matches. > Cheers, I didn't know that you could do custom matchers for those kind of > expectations too. It's not exactly widely publicized :) But that's how rspec's own anything, numeric, etc mock argument matchers work. > > JS > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From edward.og at gmail.com Mon Jul 9 21:20:21 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Mon, 09 Jul 2007 21:20:21 -0400 Subject: [rspec-users] raise_controller_errors In-Reply-To: <57c63afe0707091044qfc85513q2cd2853e290d3b9d@mail.gmail.com> References: <2fff50390707090731ob737113qa28680f3653cbcfe@mail.gmail.com> <2fff50390707090800l1b75aa34s6914514a2ffc81fb@mail.gmail.com> <43731001-FC81-4843-A2AF-95145D960610@johansorensen.com> <57c63afe0707090842q20e4b9c3u7dd4851821af2df1@mail.gmail.com> <57c63afe0707091044qfc85513q2cd2853e290d3b9d@mail.gmail.com> Message-ID: <4692DED5.8090704@gmail.com> Hi Folks, I think I've run into a problem after upgrading to edge rspec [revision 2160], but I'm not sure where to fix things. Default controller specs that look like this: ############################################################ require File.dirname(__FILE__) + '/../spec_helper' describe PurchaseController do #Delete this example and add some real ones it "should use PurchaseController" do controller.should be_an_instance_of(PurchaseController) end end ############################################################ are now causing errors like these: ############################################################ NameError in 'PurchaseController should use PurchaseController' undefined local variable or method `raise_controller_errors' for [RSpec example]:# ./spec/models/../spec_helper.rb:12: ############################################################ For the record, my spec_helper.rb is just the default generated one: ############################################################ ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'spec/rails' Spec::Runner.configure do |config| config.use_transactional_fixtures = true config.use_instantiated_fixtures = false config.fixture_path = RAILS_ROOT + '/spec/fixtures' end ############################################################ Am I missing something in spec_helper.rb or do I have some residual stuff from a previous version of rspec? I'm pretty sure that I've gotten rid of the generated stuff, but could I be missing something? Thanks, Edward From dchelimsky at gmail.com Mon Jul 9 21:22:59 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 9 Jul 2007 20:22:59 -0500 Subject: [rspec-users] raise_controller_errors In-Reply-To: <4692DED5.8090704@gmail.com> References: <2fff50390707090731ob737113qa28680f3653cbcfe@mail.gmail.com> <2fff50390707090800l1b75aa34s6914514a2ffc81fb@mail.gmail.com> <43731001-FC81-4843-A2AF-95145D960610@johansorensen.com> <57c63afe0707090842q20e4b9c3u7dd4851821af2df1@mail.gmail.com> <57c63afe0707091044qfc85513q2cd2853e290d3b9d@mail.gmail.com> <4692DED5.8090704@gmail.com> Message-ID: <57c63afe0707091822n51b6b18fne8a1c9d161d34b62@mail.gmail.com> Did you run "ruby script/generate rspec"? http://rspec.rubyforge.org/upgrade.html On 7/9/07, Edward Ocampo-Gooding wrote: > Hi Folks, > > I think I've run into a problem after upgrading to edge rspec [revision > 2160], but I'm not sure where to fix things. > > Default controller specs that look like this: > > ############################################################ > require File.dirname(__FILE__) + '/../spec_helper' > > describe PurchaseController do > > #Delete this example and add some real ones > it "should use PurchaseController" do > controller.should be_an_instance_of(PurchaseController) > end > > end > > ############################################################ > > are now causing errors like these: > > ############################################################ > NameError in 'PurchaseController should use PurchaseController' > undefined local variable or method `raise_controller_errors' for [RSpec > example]:# > ./spec/models/../spec_helper.rb:12: > ############################################################ > > For the record, my spec_helper.rb is just the default generated one: > > ############################################################ > ENV["RAILS_ENV"] = "test" > require File.expand_path(File.dirname(__FILE__) + "/../config/environment") > require 'spec/rails' > > Spec::Runner.configure do |config| > config.use_transactional_fixtures = true > config.use_instantiated_fixtures = false > config.fixture_path = RAILS_ROOT + '/spec/fixtures' > end > ############################################################ > > Am I missing something in spec_helper.rb or do I have some residual > stuff from a previous version of rspec? I'm pretty sure that I've gotten > rid of the generated stuff, but could I be missing something? > > Thanks, > Edward > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From edward.og at gmail.com Mon Jul 9 21:31:12 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Mon, 09 Jul 2007 21:31:12 -0400 Subject: [rspec-users] raise_controller_errors In-Reply-To: <57c63afe0707091822n51b6b18fne8a1c9d161d34b62@mail.gmail.com> References: <2fff50390707090731ob737113qa28680f3653cbcfe@mail.gmail.com> <2fff50390707090800l1b75aa34s6914514a2ffc81fb@mail.gmail.com> <43731001-FC81-4843-A2AF-95145D960610@johansorensen.com> <57c63afe0707090842q20e4b9c3u7dd4851821af2df1@mail.gmail.com> <57c63afe0707091044qfc85513q2cd2853e290d3b9d@mail.gmail.com> <4692DED5.8090704@gmail.com> <57c63afe0707091822n51b6b18fne8a1c9d161d34b62@mail.gmail.com> Message-ID: <4692E160.6080304@gmail.com> David Chelimsky wrote: > Did you run "ruby script/generate rspec"? Yep; but this time I let it regenerate spec.opts Turns out that the --drb flag is the culprit. I'll file (or look for a similar) bug report. Edward From dchelimsky at gmail.com Mon Jul 9 21:33:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 9 Jul 2007 20:33:01 -0500 Subject: [rspec-users] raise_controller_errors In-Reply-To: <4692E160.6080304@gmail.com> References: <2fff50390707090731ob737113qa28680f3653cbcfe@mail.gmail.com> <2fff50390707090800l1b75aa34s6914514a2ffc81fb@mail.gmail.com> <43731001-FC81-4843-A2AF-95145D960610@johansorensen.com> <57c63afe0707090842q20e4b9c3u7dd4851821af2df1@mail.gmail.com> <57c63afe0707091044qfc85513q2cd2853e290d3b9d@mail.gmail.com> <4692DED5.8090704@gmail.com> <57c63afe0707091822n51b6b18fne8a1c9d161d34b62@mail.gmail.com> <4692E160.6080304@gmail.com> Message-ID: <57c63afe0707091833p50a4dc25hd990465d75da69b2@mail.gmail.com> On 7/9/07, Edward Ocampo-Gooding wrote: > David Chelimsky wrote: > > Did you run "ruby script/generate rspec"? > > Yep; but this time I let it regenerate spec.opts > > Turns out that the --drb flag is the culprit. I don't understand how --drb is related to this. You said you were seeing a problem with a method that used to be in spec_helper.rb and has been removed (raise_controller_errors). What does that have to do with --drb? > > I'll file (or look for a similar) bug report. > > Edward > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From edward.og at gmail.com Mon Jul 9 21:45:47 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Mon, 09 Jul 2007 21:45:47 -0400 Subject: [rspec-users] raise_controller_errors In-Reply-To: <57c63afe0707091833p50a4dc25hd990465d75da69b2@mail.gmail.com> References: <2fff50390707090731ob737113qa28680f3653cbcfe@mail.gmail.com> <2fff50390707090800l1b75aa34s6914514a2ffc81fb@mail.gmail.com> <43731001-FC81-4843-A2AF-95145D960610@johansorensen.com> <57c63afe0707090842q20e4b9c3u7dd4851821af2df1@mail.gmail.com> <57c63afe0707091044qfc85513q2cd2853e290d3b9d@mail.gmail.com> <4692DED5.8090704@gmail.com> <57c63afe0707091822n51b6b18fne8a1c9d161d34b62@mail.gmail.com> <4692E160.6080304@gmail.com> <57c63afe0707091833p50a4dc25hd990465d75da69b2@mail.gmail.com> Message-ID: <4692E4CB.7020107@gmail.com> David Chelimsky wrote: > On 7/9/07, Edward Ocampo-Gooding wrote: >> David Chelimsky wrote: >>> Did you run "ruby script/generate rspec"? >> Yep; but this time I let it regenerate spec.opts >> >> Turns out that the --drb flag is the culprit. > > I don't understand how --drb is related to this. You said you were > seeing a problem with a method that used to be in spec_helper.rb and > has been removed (raise_controller_errors). What does that have to do > with --drb? No, it's always been a virgin generated spec_helper.rb file; I was just wondering earlier if I was missing something in that. I previously had --drb in my spec.opts and was having those "undefined local variable or method `raise_controller_errors'", but after removing --drb, everything works as expected. Edward From marcus at ahnve.com Tue Jul 10 04:22:00 2007 From: marcus at ahnve.com (Marcus Ahnve) Date: Tue, 10 Jul 2007 10:22:00 +0200 Subject: [rspec-users] Outside-In with RSpec on Rails In-Reply-To: References: <57c63afe0707060855k501bf8a0l8a1eed29f76a95ee@mail.gmail.com> Message-ID: <4d4e79cc0707100122u3e38483gab17aad1179b3312@mail.gmail.com> Whether or not to start with the view is a topic of great debate. Many agile luminaries propose waiting with the ui for as long as possible, whereas 37Signals for example won't start coding without a full HTML mockup. I've tried all different ways - even starting with the model - but I agree with David, starting with the view seem to result in less refactoring. Cheers /Marcus On 7/6/07, Jed Hurt wrote: > Cool. I'll have to give it a try on my next project. > > On 7/6/07, David Chelimsky wrote: > > On 7/6/07, Jed Hurt wrote: > > > I just read 'Mocks Aren't Stubs' and was intrigued by the notion of > > > 'outside-in' TDD. > > > > > > As a Rails developer, I'm curious if others are employing this method > > > when developing Rails applications using RSpec. Is it common practice > > > (or even practical) to drive the development of a Rails app by > > > starting with view specs, then controller specs, then models? > > > > Common? Not from what I've seen. I think that most ppl seem to start > > w/ the controller. > > > > That said, I've been starting with the views with some success. I find > > that when I've started with the controller, I've ended up doing a lot > > more refactoring once that slice was done (i.e. a given > > view/controller action/model trio) than I do when I start w/ the view. > > In other words, the designs that emerge when I start w/ views are > > closer to the designs that I want. > > > > This is just me. I'm not advocating that this will work for everybody. > > > > David > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://marcus.ahnve.net From aslak.hellesoy at gmail.com Tue Jul 10 05:27:31 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 10 Jul 2007 11:27:31 +0200 Subject: [rspec-users] Outside-In with RSpec on Rails In-Reply-To: <4d4e79cc0707100122u3e38483gab17aad1179b3312@mail.gmail.com> References: <57c63afe0707060855k501bf8a0l8a1eed29f76a95ee@mail.gmail.com> <4d4e79cc0707100122u3e38483gab17aad1179b3312@mail.gmail.com> Message-ID: <8d961d900707100227ua97013bic04695713e252669@mail.gmail.com> On 7/10/07, Marcus Ahnve wrote: > Whether or not to start with the view is a topic of great debate. Many > agile luminaries propose waiting with the ui for as long as possible, > whereas 37Signals for example won't start coding without a full HTML > mockup. > I wouldn't call myself an agile luminary, but I am at least a strong proponent. TDD means "write the test first" BDD takes this idea to a more general level: "write the client first" (the outside) The design/implementation benefits you get from writing the test first can also be achieved by writing the outside of your app first - it leads you to write the code that the client needs, rather than trying to guess it. The client is your test/spec OR a piece of your app that is "farther out". Same thing really. Aslak > I've tried all different ways - even starting with the model - but I > agree with David, starting with the view seem to result in less > refactoring. > > Cheers /Marcus > > On 7/6/07, Jed Hurt wrote: > > Cool. I'll have to give it a try on my next project. > > > > On 7/6/07, David Chelimsky wrote: > > > On 7/6/07, Jed Hurt wrote: > > > > I just read 'Mocks Aren't Stubs' and was intrigued by the notion of > > > > 'outside-in' TDD. > > > > > > > > As a Rails developer, I'm curious if others are employing this method > > > > when developing Rails applications using RSpec. Is it common practice > > > > (or even practical) to drive the development of a Rails app by > > > > starting with view specs, then controller specs, then models? > > > > > > Common? Not from what I've seen. I think that most ppl seem to start > > > w/ the controller. > > > > > > That said, I've been starting with the views with some success. I find > > > that when I've started with the controller, I've ended up doing a lot > > > more refactoring once that slice was done (i.e. a given > > > view/controller action/model trio) than I do when I start w/ the view. > > > In other words, the designs that emerge when I start w/ views are > > > closer to the designs that I want. > > > > > > This is just me. I'm not advocating that this will work for everybody. > > > > > > David > > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > -- > http://marcus.ahnve.net > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From marcus at ahnve.com Tue Jul 10 06:09:07 2007 From: marcus at ahnve.com (Marcus Ahnve) Date: Tue, 10 Jul 2007 12:09:07 +0200 Subject: [rspec-users] Outside-In with RSpec on Rails In-Reply-To: <8d961d900707100227ua97013bic04695713e252669@mail.gmail.com> References: <57c63afe0707060855k501bf8a0l8a1eed29f76a95ee@mail.gmail.com> <4d4e79cc0707100122u3e38483gab17aad1179b3312@mail.gmail.com> <8d961d900707100227ua97013bic04695713e252669@mail.gmail.com> Message-ID: <4d4e79cc0707100309v38a937adu4949122ad4d2536a@mail.gmail.com> On 7/10/07, aslak hellesoy wrote: > On 7/10/07, Marcus Ahnve wrote: > > Whether or not to start with the view is a topic of great debate. Many > > agile luminaries propose waiting with the ui for as long as possible, > > whereas 37Signals for example won't start coding without a full HTML > > mockup. > > > > I wouldn't call myself an agile luminary, but I am at least a strong proponent. > > TDD means "write the test first" > BDD takes this idea to a more general level: "write the client first" > (the outside) That's a great and concise description. > The design/implementation benefits you get from writing the test first > can also be achieved by writing the outside of your app first - it > leads you to write the code that the client needs, rather than trying > to guess it. The client is your test/spec OR a piece of your app that > is "farther out". Same thing really. Good stuff - I haven't thought of the UI in that way before. /Marcus -- http://marcus.ahnve.net From work at ashleymoran.me.uk Tue Jul 10 07:54:36 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 10 Jul 2007 12:54:36 +0100 Subject: [rspec-users] Multiple calls to a class method Message-ID: <7FCA0F82-F18F-478D-98E1-697DE3CCACA4@ashleymoran.me.uk> Hi Just wrote myself a Date.extract_from_rails_hash to handle parsing the "date(1i)", "date(2i)" parameters created in the controller params. I've got a method that needs to call this either once or twice, depending on the contents of the form (one section of the form is rendered conditionally). So I had two specs for the case where the second form section is included: it "..." do Date.should_receive(:extract_from_rails_hash). with(REQUEST_ARGS_WITH_FINANCE_AGREEMENT [:vehicle], :registration_date). and_return(Date.new(2006, 12, 1)) # ... end it "..." do Date.should_receive(:extract_from_rails_hash). with(REQUEST_ARGS_WITH_FINANCE_AGREEMENT [:finance_agreement], :start_date). and_return(Date.new(2006, 12, 4)) # ... end In each of these specs I only care about one of the calls, but they fail because the Date method is being called twice, and it reports the other call as an error. What is the thinking behind this? I know you shouldn't have unspecified code, but it seems restrictive to force all calls to a method to be covered in the same example. Thanks Ashley From dchelimsky at gmail.com Tue Jul 10 08:16:20 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 10 Jul 2007 07:16:20 -0500 Subject: [rspec-users] Multiple calls to a class method In-Reply-To: <7FCA0F82-F18F-478D-98E1-697DE3CCACA4@ashleymoran.me.uk> References: <7FCA0F82-F18F-478D-98E1-697DE3CCACA4@ashleymoran.me.uk> Message-ID: <57c63afe0707100516x694cf7b8h94ced691b3fef2d6@mail.gmail.com> On 7/10/07, Ashley Moran wrote: > Hi > > Just wrote myself a Date.extract_from_rails_hash to handle parsing > the "date(1i)", "date(2i)" parameters created in the controller > params. I've got a method that needs to call this either once or > twice, depending on the contents of the form (one section of the form > is rendered conditionally). So I had two specs for the case where > the second form section is included: > > it "..." do > Date.should_receive(:extract_from_rails_hash). > with(REQUEST_ARGS_WITH_FINANCE_AGREEMENT > [:vehicle], :registration_date). > and_return(Date.new(2006, 12, 1)) > # ... > end > > it "..." do > Date.should_receive(:extract_from_rails_hash). > with(REQUEST_ARGS_WITH_FINANCE_AGREEMENT > [:finance_agreement], :start_date). > and_return(Date.new(2006, 12, 4)) > # ... > end > > In each of these specs I only care about one of the calls, but they > fail because the Date method is being called twice, and it reports > the other call as an error. > > What is the thinking behind this? I know you shouldn't have > unspecified code, but it seems restrictive to force all calls to a > method to be covered in the same example. This is pretty standard in mocking frameworks. In fact, your frustration was Jim Weirich's motivation for writing Flexmock, so you may want to give that framework a shot. Using RSpec's mocks, the way I get around this is to stub the call in before(:each) and the mock the call in the example: describe "something" do before(:each) do Date.stub!(:extract_from_rails_hash) end it "..." do Date.should_receive(:extract_from_rails_hash). with(one_set_of_args). and_return(Date.new(2006, 12, 1)) # ... end it "..." do Date.should_receive(:extract_from_rails_hash). with(another_set_of_args). and_return(Date.new(2006, 12, 1)) # ... end end This tells the Date class object to ignore all extract_from_rails_hash messages except the one that you are interested in in th example. David > > Thanks > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Tue Jul 10 10:19:55 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 10 Jul 2007 15:19:55 +0100 Subject: [rspec-users] Multiple calls to a class method In-Reply-To: <57c63afe0707100516x694cf7b8h94ced691b3fef2d6@mail.gmail.com> References: <7FCA0F82-F18F-478D-98E1-697DE3CCACA4@ashleymoran.me.uk> <57c63afe0707100516x694cf7b8h94ced691b3fef2d6@mail.gmail.com> Message-ID: <1D5EB2A0-4821-43E4-A523-608C52AE16DA@ashleymoran.me.uk> On 10 Jul 2007, at 13:16, David Chelimsky wrote: > This is pretty standard in mocking frameworks. In fact, your > frustration was Jim Weirich's motivation for writing Flexmock, so you > may want to give that framework a shot. > This tells the Date class object to ignore all extract_from_rails_hash > messages except the one that you are interested in in th example. Thanks for clearing that up. I might take a look at FlexMock some time and see how it compares. I don't run into this problem often so it was more of a philosophical question but nice to know there's at least a workaround. Regards Ashley From work at ashleymoran.me.uk Wed Jul 11 06:42:15 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 11 Jul 2007 11:42:15 +0100 Subject: [rspec-users] "they" synonym for "it"? Message-ID: I've noticed that I phrase a lot of shared behaviours in plural, eg describe "All payment_details views" How about a "they" alias to "it" so you can write describe "All payment_details views", :shared => true do they "should have a card number field" do # ... end end WDYT? Ashley From aslak.hellesoy at gmail.com Wed Jul 11 07:52:54 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 11 Jul 2007 13:52:54 +0200 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: References: Message-ID: <8d961d900707110452j2d9d67f0g29864d24fa31c6d9@mail.gmail.com> On 7/11/07, Ashley Moran wrote: > I've noticed that I phrase a lot of shared behaviours in plural, eg > > describe "All payment_details views" > > How about a "they" alias to "it" so you can write > > describe "All payment_details views", :shared => true do > they "should have a card number field" do > # ... > end > end > > WDYT? > I'm a little worried that If we add this alias, people are going to want umpteen other aliases like it_should etc. It should be easy for you to just alias that method locally in your project Aslak > Ashley > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Jul 11 08:47:29 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 11 Jul 2007 07:47:29 -0500 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: <8d961d900707110452j2d9d67f0g29864d24fa31c6d9@mail.gmail.com> References: <8d961d900707110452j2d9d67f0g29864d24fa31c6d9@mail.gmail.com> Message-ID: <57c63afe0707110547g3fbf11d7s10767fdc8a97e1f0@mail.gmail.com> On 7/11/07, aslak hellesoy wrote: > On 7/11/07, Ashley Moran wrote: > > I've noticed that I phrase a lot of shared behaviours in plural, eg > > > > describe "All payment_details views" > > > > How about a "they" alias to "it" so you can write > > > > describe "All payment_details views", :shared => true do > > they "should have a card number field" do > > # ... > > end > > end > > > > WDYT? > > > > I'm a little worried that If we add this alias, people are going to > want umpteen other aliases like it_should etc. > > It should be easy for you to just alias that method locally in your project +1 We want to keep things simple. > > Aslak > > > Ashley > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Wed Jul 11 09:01:48 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 11 Jul 2007 14:01:48 +0100 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: <57c63afe0707110547g3fbf11d7s10767fdc8a97e1f0@mail.gmail.com> References: <8d961d900707110452j2d9d67f0g29864d24fa31c6d9@mail.gmail.com> <57c63afe0707110547g3fbf11d7s10767fdc8a97e1f0@mail.gmail.com> Message-ID: <097925D8-DBD5-46F6-AB0E-AC335DC053CA@ashleymoran.me.uk> On 11 Jul 2007, at 13:47, David Chelimsky wrote: >> It should be easy for you to just alias that method locally in >> your project > > +1 > We want to keep things simple. Fair point! From win at wincent.com Wed Jul 11 09:25:49 2007 From: win at wincent.com (Wincent Colaiuta) Date: Wed, 11 Jul 2007 15:25:49 +0200 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: References: Message-ID: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> El 11/7/2007, a las 12:42, Ashley Moran escribi?: > I've noticed that I phrase a lot of shared behaviours in plural, eg > > describe "All payment_details views" > > How about a "they" alias to "it" so you can write > > describe "All payment_details views", :shared => true do > they "should have a card number field" do > # ... > end > end > > WDYT? In a case like this, isn't "All" the same as "any" or even "a", or even omitting the article entirely? For example: describe 'Any payment_details view' do it 'should have a card number field' do ... describe 'A payment_details view' do it 'should have a card number field' do ... describe 'payment_details view' do it 'should have a card number field' do ... # or whatever the class is called describe PaymentDetailsView do it 'should have a card number field' do ... Cheers, Wincent From dchelimsky at gmail.com Wed Jul 11 09:29:26 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 11 Jul 2007 08:29:26 -0500 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> Message-ID: <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> On 7/11/07, Wincent Colaiuta wrote: > El 11/7/2007, a las 12:42, Ashley Moran escribi?: > > > I've noticed that I phrase a lot of shared behaviours in plural, eg > > > > describe "All payment_details views" > > > > How about a "they" alias to "it" so you can write > > > > describe "All payment_details views", :shared => true do > > they "should have a card number field" do > > # ... > > end > > end > > > > WDYT? > > In a case like this, isn't "All" the same as "any" or even "a", or > even omitting the article entirely? > > For example: > > describe 'Any payment_details view' do > it 'should have a card number field' do > ... > > describe 'A payment_details view' do > it 'should have a card number field' do > ... > > describe 'payment_details view' do > it 'should have a card number field' do > ... > > # or whatever the class is called > describe PaymentDetailsView do > it 'should have a card number field' do > ... Excellent point. I'm sure the code in each example would be dealing with a single object, not all objects. > > Cheers, > Wincent > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Wed Jul 11 09:32:36 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 11 Jul 2007 14:32:36 +0100 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> Message-ID: <9B5D1202-C0B4-417D-ADD5-96A884519665@ashleymoran.me.uk> On 11 Jul 2007, at 14:25, Wincent Colaiuta wrote: > In a case like this, isn't "All" the same as "any" or even "a", or > even omitting the article entirely? Mmm, I noticed that myself not long after I posted lol. I've already started rewording everything... From work at ashleymoran.me.uk Wed Jul 11 09:35:42 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 11 Jul 2007 14:35:42 +0100 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> Message-ID: On 11 Jul 2007, at 14:29, David Chelimsky wrote: > Excellent point. I'm sure the code in each example would be dealing > with a single object, not all objects. We had a Polish guy start here last year (sadly poached by a company in London now). When I showed him RSpec I told him the thing he would find hardest was not the spec code, it was the English involved in writing the descriptions. Might be useful if I followed my own advice :) From pedro.delgallego at gmail.com Wed Jul 11 10:00:52 2007 From: pedro.delgallego at gmail.com (Pedro Del Gallego) Date: Wed, 11 Jul 2007 16:00:52 +0200 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> Message-ID: <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> > We had a Polish guy start here last year (sadly poached by a company > in London now). When I showed him RSpec I told him the thing he > would find hardest was not the spec code, it was the English involved > in writing the descriptions. Might be useful if I followed my own > advice :) Thats my biggest problem with rspec, (I'm a non english speaker working in a German/English environment) It would be great a guide or a tips list to make our specs more readebles, Something like 10 English tips to improve your specs readability ;) -- ------------------------------------- Pedro Del Gallego Email : pedro.delgallego at gmail.com From work at ashleymoran.me.uk Wed Jul 11 11:06:11 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 11 Jul 2007 16:06:11 +0100 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> Message-ID: <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> On 11 Jul 2007, at 15:00, Pedro Del Gallego wrote: > Thats my biggest problem with rspec, (I'm a non english speaker > working in a German/English environment) It would be great a guide or > a tips list to make our specs more readebles, Something like 10 > English tips to improve your specs readability ;) Don't think I can come up with 10 off the top of my head but I always told Pawel to follow the rule "phrase descriptions as GIVEN WHEN THEN". There's plenty of better examples on this list and elsewhere, but basically if I have an idea like this: A cow prodded with a stick should moo I think: GIVEN="a cow", WHEN="prodded with a stick", THEN="moo" and turn it into this code: describe Cow do before(:each) do @cow = Cow.new end it 'should say "moo" when sent prod_with_stick' do @cow.prod_with_stick.should == "moo" end end It doesn't apply rigidly to every situation, but 90% of the time, if I keep chanting GIVEN WHEN THEN I write clean, focussed specs. The rest is mainly vocabulary (although sometimes it can be hard to phrase something clearly). Ashley From dchelimsky at gmail.com Wed Jul 11 11:12:35 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 11 Jul 2007 10:12:35 -0500 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> Message-ID: <57c63afe0707110812p3a8af222oc2da9c91e05a120a@mail.gmail.com> On 7/11/07, Ashley Moran wrote: > > On 11 Jul 2007, at 15:00, Pedro Del Gallego wrote: > > > Thats my biggest problem with rspec, (I'm a non english speaker > > working in a German/English environment) It would be great a guide or > > a tips list to make our specs more readebles, Something like 10 > > English tips to improve your specs readability ;) > > > Don't think I can come up with 10 off the top of my head but I always > told Pawel to follow the rule "phrase descriptions as GIVEN WHEN > THEN". There's plenty of better examples on this list and elsewhere, > but basically if I have an idea like this: > > A cow prodded with a stick should moo > > I think: > GIVEN="a cow", WHEN="prodded with a stick", THEN="moo" > > and turn it into this code: > describe Cow do > before(:each) do > @cow = Cow.new > end > it 'should say "moo" when sent prod_with_stick' do > @cow.prod_with_stick.should == "moo" > end > end > > It doesn't apply rigidly to every situation, but 90% of the time, if > I keep chanting GIVEN WHEN THEN I write clean, focussed specs. The > rest is mainly vocabulary (although sometimes it can be hard to > phrase something clearly). I've been in that habit too. In general, I want the GIVEN expressed in the String passed to describe and/or before(:each). The WHEN and THEN should be in the example. As Ashley suggests, this isn't 100% of the time, but I find that the more I stick to this the easier it is to grok everything when looking back. Also, I try to stick to one WHEN and one THEN per example. This means that if there are mocks involved, my examples generally look like this: it "should foo when bar" do collaborator.should_receive(:baz) thing.bar end OR it "should foo when bar" do thing.bar thing.baz.should == something end BUT NEVER it "should foo when bar" do collaborator.should_receive(:baz) thing.bar thing.fu.should == something end FWIW. Cheers, David > > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From anthony at digitalphenom.com Wed Jul 11 12:12:52 2007 From: anthony at digitalphenom.com (Anthony Carlos) Date: Wed, 11 Jul 2007 12:12:52 -0400 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> Message-ID: I think this is a nugget of experience about which it's worth shouting. I've read lots of articles about the theory behind BDD and TDD, but I need(ed) help learning how to phrase and write specs. That is, what to spec and how to write it; what is good style, and what is not so good. I'd love to come up with a guide like "The Elements of Style" by Strunk, White, et. al, which I used in college to really learn how to write. Perhaps we need to bundle "The Elements of RSpec Style" with the documentation on the website. I'm happy to collect and edit suggestions. What do you think? -Anthony On Jul 11, 2007, at 11:06 AM, Ashley Moran wrote: > > On 11 Jul 2007, at 15:00, Pedro Del Gallego wrote: > >> Thats my biggest problem with rspec, (I'm a non english speaker >> working in a German/English environment) It would be great a >> guide or >> a tips list to make our specs more readebles, Something like 10 >> English tips to improve your specs readability ;) > > > Don't think I can come up with 10 off the top of my head but I always > told Pawel to follow the rule "phrase descriptions as GIVEN WHEN > THEN". There's plenty of better examples on this list and elsewhere, > but basically if I have an idea like this: > > A cow prodded with a stick should moo > > I think: > GIVEN="a cow", WHEN="prodded with a stick", THEN="moo" > > and turn it into this code: > describe Cow do > before(:each) do > @cow = Cow.new > end > it 'should say "moo" when sent prod_with_stick' do > @cow.prod_with_stick.should == "moo" > end > end > > It doesn't apply rigidly to every situation, but 90% of the time, if > I keep chanting GIVEN WHEN THEN I write clean, focussed specs. The > rest is mainly vocabulary (although sometimes it can be hard to > phrase something clearly). > > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From tom at experthuman.com Wed Jul 11 12:31:48 2007 From: tom at experthuman.com (Tom Stuart) Date: Wed, 11 Jul 2007 17:31:48 +0100 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> Message-ID: <13F6DF51-EC9F-4161-8C52-C5264C7B075B@experthuman.com> On 11 Jul 2007, at 17:12, Anthony Carlos wrote: > Perhaps we need to bundle "The Elements of RSpec Style" with the > documentation on the website. I'm happy to collect and edit > suggestions. I would like to enthusiastically (albeit fundamentally unhelpfully) voice my support for this idea. The main win of RSpec over Test::Unit is the framework of linguistic constraints it provides to help guide people down the right path, but the main weakness is that it still doesn't go far enough -- most conversations I have with people about BDD are concerned with the continuing struggle to work out what the "right way" to write specs is. Toy examples (cf Stack, Account) are unhelpful in this regard because they demonstrate the common-sense mechanics of RSpec without really delivering any accumulated wisdom about how real specs should look and behave, and that's the hard part to grasp when you're trying to learn this stuff. I realise there's a well-intentioned progressive reticence to preach a dogmatic gospel about how specs should be named, designed and constructed, but as with Rails I believe that people derive genuine comfort and encouragement from being told The One Correct Way when they're starting out, and once they become competent enough to have dissenting opinions of their own they rarely seem to have a problem with enacting them. There are lots of gems of pragmatic wisdom dotted throughout the rspec-users archives -- yeah, David's "one WHEN/THEN per example" is a great one -- and I think it'd be tremendously useful to collect and promote these as Truth even if no expert quite believes that they are. Cheers, -Tom From work at ashleymoran.me.uk Wed Jul 11 12:35:12 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 11 Jul 2007 17:35:12 +0100 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> Message-ID: On 11 Jul 2007, at 17:12, Anthony Carlos wrote: > What do you think? I think there's a lot of merit in that idea. I've come across loads of situations where it was not obvious how to write the specs or code so that the code or specs (respectively) are clear and useful. I'm sure they could be distilled to a set of template situations - I'd be happy to submit examples. When people ask what developing with tests is like I tend to say that the difference between using RSpec and writing specs is like the difference between learning how a paintbrush works and learning how to paint a picture. RSpec's easy enough to pick up, but I wish I could point people at a more theoretical how-to that helps with the difficult "how do I spec this?" problems. Ashley From daniel at danielfischer.com Thu Jul 12 04:21:18 2007 From: daniel at danielfischer.com (Fischer, Daniel) Date: Thu, 12 Jul 2007 01:21:18 -0700 Subject: [rspec-users] Agh, this is annoying. Why is this happening? Message-ID: <7e565b5c0707120121s58d10c2coaba70e289294fd66@mail.gmail.com> My problem: Mock 'Task_1005' received unexpected message :user_id= with (1) No matter what I do to try to stub that out it will still fail out and give me that message. Here is my spec describe TasksController, "handling POST /tasks" do before(:each) do @task = mock_model(Task, :to_param => "1", :save => true) Task.stub!(:new).and_return(@task) @user = mock_model(User) @user.stub!(:id).and_return(1) @user.stub!(:login).and_return("moo") User.stub!(:find).and_return(@user) @params = {} end def do_post @request.session[:user] = @user.id post :create, :task => @params end it "should create a new task" do Task.should_receive(:user_id).with(@user.id).and_return(true) Task.should_receive(:new).with(@params).and_return(@task) do_post end it "should redirect to /tasks" do Task.should_receive(:user_id).with(@user.id).and_return(true) do_post response.should redirect_to(home_url) end end And my controller: def create @task = Task.new(params[:task]) @task.user_id = current_user.id @task.status = Status.find_by_name('in progress') respond_to do |format| if @task.save flash[:notice] = 'Task was successfully created.' format.html { redirect_to home_url } format.xml { head :created, :location => task_url(@task) } else flash[:error] = @task.errors format.html { redirect_to home_url } format.xml { render :xml => @task.errors.to_xml } end end end So obviously it's failing with the current_user.id thing. I'm using restful_authentication. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070712/266c9c6d/attachment-0001.html From work at ashleymoran.me.uk Thu Jul 12 05:06:49 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Thu, 12 Jul 2007 10:06:49 +0100 Subject: [rspec-users] Agh, this is annoying. Why is this happening? In-Reply-To: <7e565b5c0707120121s58d10c2coaba70e289294fd66@mail.gmail.com> References: <7e565b5c0707120121s58d10c2coaba70e289294fd66@mail.gmail.com> Message-ID: <4135AB7D-2A30-4E69-A056-FFFC8D5D152C@ashleymoran.me.uk> On 12 Jul 2007, at 09:21, Fischer, Daniel wrote: > My problem: > > Mock 'Task_1005' received unexpected message :user_id= with (1) > > No matter what I do to try to stub that out it will still fail out > and give me that message. > > Here is my spec > > > describe TasksController, "handling POST /tasks" do > before(:each) do > @task = mock_model(Task, :to_param => "1", :save => true) @task = mock_model(Task, :to_param => "1", :save => true, :user_id= => nil) > > Task.stub!(:new).and_return(@task) > @user = mock_model(User) > @user.stub!(:id).and_return(1) > @user.stub!(:login).and_return("moo") > User.stub!(:find).and_return(@user) > @params = {} > end > > def do_post > @request.session[:user] = @ user.id > post :create, :task => @params > end > > it "should create a new task" do > Task.should_receive(:user_id).with(@user.id).and_return(true) @task.should_receive(:user_id=).with(@user.id).and_return(true) > > Task.should_receive(:new).with(@params).and_return(@task) > do_post > end > > it "should redirect to /tasks" do > Task.should_receive(:user_id).with(@user.id ).and_return(true) > do_post > response.should redirect_to(home_url) > end > end > > And my controller: > > def create > @task = Task.new(params[:task]) > @task.user_id = current_user.id > @task.status = Status.find_by_name('in progress') > > respond_to do |format| > if @task.save > flash[:notice] = 'Task was successfully created.' > format.html { redirect_to home_url } > format.xml { head :created, :location => task_url(@task) } > else > flash[:error] = @task.errors > format.html { redirect_to home_url } > format.xml { render :xml => @ task.errors.to_xml } > end > end > end > > So obviously it's failing with the current_user.id thing. I'm using > restful_authentication. Daniel, It looks like it's failing for a different reason than you think, if I understood your code. (Although I only woke up an hour ago and by rights I should still be in bed...) I've never used restful_authentication, so I don't know about "current_user", but I suspect it needs to be stubbed out - otherwise you are running some sort of semi-integration test, testing the plugin as well as your own code. Also, like David pointed out yesterday, you probably shouldn't combine specs. You want to split "should create a new task" into "should create a new task" and it "should assign the current user's id to the new task". Also there should be no need to put an expectation on Task (or @task?) in "should redirect to /tasks". That's my interpretation of things, please correct me if I misunderstood. Ashley From aslak.hellesoy at gmail.com Thu Jul 12 05:33:08 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 12 Jul 2007 11:33:08 +0200 Subject: [rspec-users] Agh, this is annoying. Why is this happening? In-Reply-To: <7e565b5c0707120121s58d10c2coaba70e289294fd66@mail.gmail.com> References: <7e565b5c0707120121s58d10c2coaba70e289294fd66@mail.gmail.com> Message-ID: <8d961d900707120233q3c70ca59o6408886c3eebb545@mail.gmail.com> This doesn't make sense: Task.should_receive(:user_id).with(@user.id).and_return(true) It means that you expect this: foo = Task.user_id(@user_id) # foo will be true I suspect you rather want this to happen: @task.user_id = @user_id In which case your mock setup should be: @task.should_receive(:user_id=).with(@user.id) Aslak On 7/12/07, Fischer, Daniel wrote: > My problem: > > Mock 'Task_1005' received unexpected message :user_id= with (1) > > No matter what I do to try to stub that out it will still fail out and give > me that message. > > Here is my spec > > > describe TasksController, "handling POST /tasks" do > before(:each) do > @task = mock_model(Task, :to_param => "1", :save => true) > Task.stub!(:new).and_return(@task) > @user = mock_model(User) > @user.stub!(:id).and_return(1) > @user.stub!(:login).and_return("moo") > User.stub!(:find).and_return(@user) > @params = {} > end > > def do_post > @request.session[:user] = @ user.id > post :create, :task => @params > end > > it "should create a new task" do > Task.should_receive(:user_id).with(@user.id).and_return(true) > > Task.should_receive(:new).with(@params).and_return(@task) > do_post > end > > it "should redirect to /tasks" do > Task.should_receive(:user_id).with(@user.id ).and_return(true) > do_post > response.should redirect_to(home_url) > end > end > > And my controller: > > def create > @task = Task.new(params[:task]) > @task.user_id = current_user.id > @task.status = Status.find_by_name('in progress') > > respond_to do |format| > if @task.save > flash[:notice] = 'Task was successfully created.' > format.html { redirect_to home_url } > format.xml { head :created, :location => task_url(@task) } > else > flash[:error] = @task.errors > format.html { redirect_to home_url } > format.xml { render :xml => @ task.errors.to_xml } > end > end > end > > So obviously it's failing with the current_user.id thing. I'm using > restful_authentication. > > Thanks! > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Jul 12 07:42:16 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 12 Jul 2007 06:42:16 -0500 Subject: [rspec-users] Agh, this is annoying. Why is this happening? In-Reply-To: <8d961d900707120233q3c70ca59o6408886c3eebb545@mail.gmail.com> References: <7e565b5c0707120121s58d10c2coaba70e289294fd66@mail.gmail.com> <8d961d900707120233q3c70ca59o6408886c3eebb545@mail.gmail.com> Message-ID: <57c63afe0707120442r3cd88be1ic740a27208b8f212@mail.gmail.com> On 7/12/07, aslak hellesoy wrote: > This doesn't make sense: > > Task.should_receive(:user_id).with(@user.id).and_return(true) > > It means that you expect this: > > foo = Task.user_id(@user_id) # foo will be true > > I suspect you rather want this to happen: > > @task.user_id = @user_id > > In which case your mock setup should be: > > @task.should_receive(:user_id=).with(@user.id) This is also supported by the error message you are getting: Mock 'Task_1005' received unexpected message :user_id= with (1) It states that the unexpected message is :user_id=, not :user_id. Easy enough thing to miss. Very subtle. But I'll bet you won't miss it again :) Cheers, David > > Aslak > > On 7/12/07, Fischer, Daniel wrote: > > My problem: > > > > Mock 'Task_1005' received unexpected message :user_id= with (1) > > > > No matter what I do to try to stub that out it will still fail out and give > > me that message. > > > > Here is my spec > > > > > > describe TasksController, "handling POST /tasks" do > > before(:each) do > > @task = mock_model(Task, :to_param => "1", :save => true) > > Task.stub!(:new).and_return(@task) > > @user = mock_model(User) > > @user.stub!(:id).and_return(1) > > @user.stub!(:login).and_return("moo") > > User.stub!(:find).and_return(@user) > > @params = {} > > end > > > > def do_post > > @request.session[:user] = @ user.id > > post :create, :task => @params > > end > > > > it "should create a new task" do > > Task.should_receive(:user_id).with(@user.id).and_return(true) > > > > Task.should_receive(:new).with(@params).and_return(@task) > > do_post > > end > > > > it "should redirect to /tasks" do > > Task.should_receive(:user_id).with(@user.id ).and_return(true) > > do_post > > response.should redirect_to(home_url) > > end > > end > > > > And my controller: > > > > def create > > @task = Task.new(params[:task]) > > @task.user_id = current_user.id > > @task.status = Status.find_by_name('in progress') > > > > respond_to do |format| > > if @task.save > > flash[:notice] = 'Task was successfully created.' > > format.html { redirect_to home_url } > > format.xml { head :created, :location => task_url(@task) } > > else > > flash[:error] = @task.errors > > format.html { redirect_to home_url } > > format.xml { render :xml => @ task.errors.to_xml } > > end > > end > > end > > > > So obviously it's failing with the current_user.id thing. I'm using > > restful_authentication. > > > > Thanks! > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From robert.feldt at bth.se Thu Jul 12 09:19:40 2007 From: robert.feldt at bth.se (Robert Feldt) Date: Thu, 12 Jul 2007 15:19:40 +0200 Subject: [rspec-users] Promoting options to heckle? In-Reply-To: <87a13e220707120549w532a74a3w9e1ff6dd2f816de8@mail.gmail.com> References: <87a13e220707120549w532a74a3w9e1ff6dd2f816de8@mail.gmail.com> Message-ID: <87a13e220707120619o77a0f6b3o40dc0c423774fd9e@mail.gmail.com> Hi, I'm trying out RSpec with the heckle option (for mutation testing). Problem is that heckle goes into an infinite loop when running it on an example. I want to send a "--verbose" to heckle but can't find a way to do that through the spec binary. Since this is not an uncommon situation when using heckle I would like this to be supported in some way by RSpec. Thoughts? Best regards, /Robert Feldt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070712/d92af696/attachment.html From dchelimsky at gmail.com Thu Jul 12 12:12:40 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 12 Jul 2007 11:12:40 -0500 Subject: [rspec-users] Promoting options to heckle? In-Reply-To: <87a13e220707120619o77a0f6b3o40dc0c423774fd9e@mail.gmail.com> References: <87a13e220707120549w532a74a3w9e1ff6dd2f816de8@mail.gmail.com> <87a13e220707120619o77a0f6b3o40dc0c423774fd9e@mail.gmail.com> Message-ID: <57c63afe0707120912x1a7708feo68b4d187ba651785@mail.gmail.com> On 7/12/07, Robert Feldt wrote: > Hi, > > I'm trying out RSpec with the heckle option (for mutation testing). > > > Problem is that heckle goes into an infinite loop when running it on an > example. I want to send a "--verbose" to heckle but can't find a way to do > that through the spec binary. Since this is not an uncommon situation when > using heckle I would like this to be supported in some way by RSpec. > Thoughts? Hi Robert, I can see this working a couple of ways. We've got a -b switch which results in a complete backtrace showing up. That seems more or less synonymous with the notion of --verbose, which we don't have explicitly. So, what if we added a --verbose switch that affected any other options, like Heckle, or RCov? I think that would be simpler than trying to come up with targeted --verbose switches. WDYT? > > Best regards, > > /Robert Feldt > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From anthony at digitalphenom.com Thu Jul 12 12:20:23 2007 From: anthony at digitalphenom.com (Anthony Carlos) Date: Thu, 12 Jul 2007 12:20:23 -0400 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> Message-ID: <619209E4-B843-4DFE-81CB-F050A39F26AA@digitalphenom.com> If you guys don't mind, I'm going to create a sample web page with this concept on it, stealing from Ashley and David's writings. If people like it, perhaps we can get it included in the documentation. On Jul 11, 2007, at 12:35 PM, Ashley Moran wrote: > > On 11 Jul 2007, at 17:12, Anthony Carlos wrote: > >> What do you think? > > > I think there's a lot of merit in that idea. I've come across loads > of situations where it was not obvious how to write the specs or code > so that the code or specs (respectively) are clear and useful. I'm > sure they could be distilled to a set of template situations - I'd be > happy to submit examples. > > When people ask what developing with tests is like I tend to say that > the difference between using RSpec and writing specs is like the > difference between learning how a paintbrush works and learning how > to paint a picture. RSpec's easy enough to pick up, but I wish I > could point people at a more theoretical how-to that helps with the > difficult "how do I spec this?" problems. > > Ashley > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Thu Jul 12 12:53:46 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 12 Jul 2007 18:53:46 +0200 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: <619209E4-B843-4DFE-81CB-F050A39F26AA@digitalphenom.com> References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> <619209E4-B843-4DFE-81CB-F050A39F26AA@digitalphenom.com> Message-ID: <8d961d900707120953k7f833df3g279ea7becdff4ac7@mail.gmail.com> On 7/12/07, Anthony Carlos wrote: > If you guys don't mind, I'm going to create a sample web page with > this concept on it, stealing from Ashley and David's writings. If > people like it, perhaps we can get it included in the documentation. > Go ahead, that would be great! Aslak > On Jul 11, 2007, at 12:35 PM, Ashley Moran wrote: > > > > > On 11 Jul 2007, at 17:12, Anthony Carlos wrote: > > > >> What do you think? > > > > > > I think there's a lot of merit in that idea. I've come across loads > > of situations where it was not obvious how to write the specs or code > > so that the code or specs (respectively) are clear and useful. I'm > > sure they could be distilled to a set of template situations - I'd be > > happy to submit examples. > > > > When people ask what developing with tests is like I tend to say that > > the difference between using RSpec and writing specs is like the > > difference between learning how a paintbrush works and learning how > > to paint a picture. RSpec's easy enough to pick up, but I wish I > > could point people at a more theoretical how-to that helps with the > > difficult "how do I spec this?" problems. > > > > Ashley > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From robert.feldt at bth.se Thu Jul 12 15:26:17 2007 From: robert.feldt at bth.se (Robert Feldt) Date: Thu, 12 Jul 2007 21:26:17 +0200 Subject: [rspec-users] Promoting options to heckle? In-Reply-To: <57c63afe0707120912x1a7708feo68b4d187ba651785@mail.gmail.com> References: <87a13e220707120549w532a74a3w9e1ff6dd2f816de8@mail.gmail.com> <87a13e220707120619o77a0f6b3o40dc0c423774fd9e@mail.gmail.com> <57c63afe0707120912x1a7708feo68b4d187ba651785@mail.gmail.com> Message-ID: <87a13e220707121226h55a316ffk8fabd84f0198b630@mail.gmail.com> On 7/12/07, David Chelimsky wrote: > > On 7/12/07, Robert Feldt wrote: > > Hi, > > > > I'm trying out RSpec with the heckle option (for mutation testing). > > > > > > Problem is that heckle goes into an infinite loop when running it on an > > example. I want to send a "--verbose" to heckle but can't find a way to > do > > that through the spec binary. Since this is not an uncommon situation > when > > using heckle I would like this to be supported in some way by RSpec. > > Thoughts? That sounds very reasonable. I like it. Regards, Robert Hi Robert, > > I can see this working a couple of ways. We've got a -b switch which > results in a complete backtrace showing up. That seems more or less > synonymous with the notion of --verbose, which we don't have > explicitly. So, what if we added a --verbose switch that affected any > other options, like Heckle, or RCov? I think that would be simpler > than trying to come up with targeted --verbose switches. > > WDYT? > > > > > Best regards, > > > > /Robert Feldt > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Best regards, /Robert Feldt -- PhD, Assistant Professor in Software Engineering Blekinge Institute of Technology School of Engineering (APS) SE-372 25 Ronneby Sweden Phone: +46 (0) 457 385 887 Mobile: +46 (0) 733 580 580 Web pages: Research group: http://www.bth.se/tek/serl/ Research project: http://www.bth.se/besq/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070712/fd7187ee/attachment-0001.html From robert.feldt at bth.se Fri Jul 13 02:10:21 2007 From: robert.feldt at bth.se (Robert Feldt) Date: Fri, 13 Jul 2007 08:10:21 +0200 Subject: [rspec-users] Promoting options to heckle? In-Reply-To: <57c63afe0707120912x1a7708feo68b4d187ba651785@mail.gmail.com> References: <87a13e220707120549w532a74a3w9e1ff6dd2f816de8@mail.gmail.com> <87a13e220707120619o77a0f6b3o40dc0c423774fd9e@mail.gmail.com> <57c63afe0707120912x1a7708feo68b4d187ba651785@mail.gmail.com> Message-ID: <87a13e220707122310q47c68665s90ef338fdf32474a@mail.gmail.com> On 7/12/07, David Chelimsky wrote: > > On 7/12/07, Robert Feldt wrote: > > Hi, > > > > I'm trying out RSpec with the heckle option (for mutation testing). > > > > > > Problem is that heckle goes into an infinite loop when running it on an > > example. I want to send a "--verbose" to heckle but can't find a way to > do > > that through the spec binary. Since this is not an uncommon situation > when > > using heckle I would like this to be supported in some way by RSpec. > > Thoughts? One alternative I thought of is to have a standard way to "promote" options to other tools that spec invokes. Along the lines of: spec --heckle --options-heckle "--verbose --branches MyModule::MyClass#my_method" ... and the argument to --options-heckle (or --options-rcov etc) would simply be passed along in the call to heckle. This would cover more situations with a single solution. Regards, Robert Hi Robert, > > I can see this working a couple of ways. We've got a -b switch which > results in a complete backtrace showing up. That seems more or less > synonymous with the notion of --verbose, which we don't have > explicitly. So, what if we added a --verbose switch that affected any > other options, like Heckle, or RCov? I think that would be simpler > than trying to come up with targeted --verbose switches. > > WDYT? > > > > > Best regards, > > > > /Robert Feldt > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Best regards, /Robert Feldt -- PhD, Assistant Professor in Software Engineering Blekinge Institute of Technology School of Engineering (APS) SE-372 25 Ronneby Sweden Phone: +46 (0) 457 385 887 Mobile: +46 (0) 733 580 580 Web pages: Research group: http://www.bth.se/tek/serl/ Research project: http://www.bth.se/besq/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070713/b1c21c46/attachment.html From work at ashleymoran.me.uk Fri Jul 13 04:44:53 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Fri, 13 Jul 2007 09:44:53 +0100 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: <619209E4-B843-4DFE-81CB-F050A39F26AA@digitalphenom.com> References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> <619209E4-B843-4DFE-81CB-F050A39F26AA@digitalphenom.com> Message-ID: <53072B4B-36B5-4482-BFD5-A96296E6AF2E@ashleymoran.me.uk> On 12 Jul 2007, at 17:20, Anthony Carlos wrote: > If you guys don't mind, I'm going to create a sample web page with > this concept on it, stealing from Ashley and David's writings. If > people like it, perhaps we can get it included in the documentation. Do you have a wiki you could use? If not I could open a public page on my company's wiki and you could edit it there - might be easier to do collaborative stuff that way. Ashley From dchelimsky at gmail.com Fri Jul 13 08:07:52 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 13 Jul 2007 07:07:52 -0500 Subject: [rspec-users] "they" synonym for "it"? In-Reply-To: <53072B4B-36B5-4482-BFD5-A96296E6AF2E@ashleymoran.me.uk> References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> <619209E4-B843-4DFE-81CB-F050A39F26AA@digitalphenom.com> <53072B4B-36B5-4482-BFD5-A96296E6AF2E@ashleymoran.me.uk> Message-ID: <57c63afe0707130507k389f882fh694b7a32fe075ff3@mail.gmail.com> On 7/13/07, Ashley Moran wrote: > > On 12 Jul 2007, at 17:20, Anthony Carlos wrote: > > > If you guys don't mind, I'm going to create a sample web page with > > this concept on it, stealing from Ashley and David's writings. If > > people like it, perhaps we can get it included in the documentation. > > Do you have a wiki you could use? If not I could open a public page > on my company's wiki and you could edit it there - might be easier to > do collaborative stuff that way. We don't right now, nor do we have resources to set one up, so if you can set something up that would be awesome. Thanks Ashley, David > > Ashley > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From work at ashleymoran.me.uk Fri Jul 13 09:53:44 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Fri, 13 Jul 2007 14:53:44 +0100 Subject: [rspec-users] RSpec wiki In-Reply-To: <57c63afe0707130507k389f882fh694b7a32fe075ff3@mail.gmail.com> References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> <619209E4-B843-4DFE-81CB-F050A39F26AA@digitalphenom.com> <53072B4B-36B5-4482-BFD5-A96296E6AF2E@ashleymoran.me.uk> <57c63afe0707130507k389f882fh694b7a32fe075ff3@mail.gmail.com> Message-ID: On 13 Jul 2007, at 13:07, David Chelimsky wrote: > We don't right now, nor do we have resources to set one up, so if you > can set something up that would be awesome. Ok I cobbled something together on our company wiki (which runs on XWiki). I've created an RSpecCollab space - a space is just a group of pages with common permissions - that is publicly viewable but only editable by registered users. It's a bit quirky but the key stuff seems to work. Please let me know if I inadvertently gave the whole world access to our corporate secrets :) URL: http://www.codeweavers.net/wiki/bin/view/RSpecCollab/WebHome I've made a few accounts which I will send by email in a sec. If anyone else wants an account just ask and I will set one up. Ashley From anthony at digitalphenom.com Fri Jul 13 11:58:49 2007 From: anthony at digitalphenom.com (Anthony Carlos) Date: Fri, 13 Jul 2007 11:58:49 -0400 Subject: [rspec-users] RSpec wiki In-Reply-To: References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> <619209E4-B843-4DFE-81CB-F050A39F26AA@digitalphenom.com> <53072B4B-36B5-4482-BFD5-A96296E6AF2E@ashleymoran.me.uk> <57c63afe0707130507k389f882fh694b7a32fe075ff3@mail.gmail.com> Message-ID: Ashley: Thanks for the wiki page. I've logged-in and posted a brief statement about our intentions. I'm playing the role of editor here, since, I'm not the best at writing examples, and I'm still feeling around for boundaries. I don't want to steal someone's writings without their consent, but I don't want to sprinkle people's names for each concept. Perhaps a thanks to each contributor in one section at the end will suffice? Thanks, -Anthony On Jul 13, 2007, at 9:53 AM, Ashley Moran wrote: > > On 13 Jul 2007, at 13:07, David Chelimsky wrote: > >> We don't right now, nor do we have resources to set one up, so if you >> can set something up that would be awesome. > > Ok I cobbled something together on our company wiki (which runs on > XWiki). I've created an RSpecCollab space - a space is just a group > of pages with common permissions - that is publicly viewable but only > editable by registered users. It's a bit quirky but the key stuff > seems to work. Please let me know if I inadvertently gave the whole > world access to our corporate secrets :) > > URL: http://www.codeweavers.net/wiki/bin/view/RSpecCollab/WebHome > > I've made a few accounts which I will send by email in a sec. If > anyone else wants an account just ask and I will set one up. > > Ashley > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From work at ashleymoran.me.uk Fri Jul 13 12:13:52 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Fri, 13 Jul 2007 17:13:52 +0100 Subject: [rspec-users] RSpec wiki In-Reply-To: References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> <619209E4-B843-4DFE-81CB-F050A39F26AA@digitalphenom.com> <53072B4B-36B5-4482-BFD5-A96296E6AF2E@ashleymoran.me.uk> <57c63afe0707130507k389f882fh694b7a32fe075ff3@mail.gmail.com> Message-ID: On 13 Jul 2007, at 16:58, Anthony Carlos wrote: > Thanks for the wiki page. I've logged-in and posted a brief statement > about our intentions. I'm playing the role of editor here, since, I'm > not the best at writing examples, and I'm still feeling around for > boundaries. I don't want to steal someone's writings without their > consent, but I don't want to sprinkle people's names for each > concept. Perhaps a thanks to each contributor in one section at the > end will suffice? I'm not too worried about my name being attached to a code sample that involves prodding cows with sticks :) One thing you might want to try is splitting each example up into its own page. You can make a list like this 1.1 Examples * [GivenWhenThen] * [SomethingElse] * ... then it creates links to pages that are created when you save some content (Headings are made with 1, 1.1, 1.1.1 etc) You've used some square brackets to put comments in - they need a \ in front of them to prevent them being treated as links I might write a couple of examples based on on shared specs / decomposing classes problems that have come up at work. If I get change I'll write them up soon so they can be reviewed Ashley From anthony at digitalphenom.com Fri Jul 13 12:49:31 2007 From: anthony at digitalphenom.com (Anthony Carlos) Date: Fri, 13 Jul 2007 12:49:31 -0400 Subject: [rspec-users] RSpec wiki In-Reply-To: References: <7F9A8274-3318-4D86-93F6-DD826289ADA3@wincent.com> <57c63afe0707110629k2569f5dam8803550f624a88b9@mail.gmail.com> <2e93189b0707110700n2c59ff1an2545544e3bd87ac8@mail.gmail.com> <38D81635-7A4B-44B4-B71A-56A86A1591C2@ashleymoran.me.uk> <619209E4-B843-4DFE-81CB-F050A39F26AA@digitalphenom.com> <53072B4B-36B5-4482-BFD5-A96296E6AF2E@ashleymoran.me.uk> <57c63afe0707130507k389f882fh694b7a32fe075ff3@mail.gmail.com> Message-ID: <297431E3-C05B-4FF5-A99E-4AB7312AF472@digitalphenom.com> Thanks for the primer on the wiki. I don't use them very often, but I'll pick up the formatting stuff soon enough. I will try to set-up additional pages later today. Thanks, -Anthony On Jul 13, 2007, at 12:13 PM, Ashley Moran wrote: > > On 13 Jul 2007, at 16:58, Anthony Carlos wrote: > >> Thanks for the wiki page. I've logged-in and posted a brief statement >> about our intentions. I'm playing the role of editor here, since, I'm >> not the best at writing examples, and I'm still feeling around for >> boundaries. I don't want to steal someone's writings without their >> consent, but I don't want to sprinkle people's names for each >> concept. Perhaps a thanks to each contributor in one section at the >> end will suffice? > > I'm not too worried about my name being attached to a code sample > that involves prodding cows with sticks :) > > One thing you might want to try is splitting each example up into its > own page. You can make a list like this > > 1.1 Examples > * [GivenWhenThen] > * [SomethingElse] > * ... > > then it creates links to pages that are created when you save some > content > > (Headings are made with 1, 1.1, 1.1.1 etc) > > You've used some square brackets to put comments in - they need a \ > in front of them to prevent them being treated as links > > I might write a couple of examples based on on shared specs / > decomposing classes problems that have come up at work. If I get > change I'll write them up soon so they can be reviewed > > Ashley > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From Gregory.Murphy at Sun.COM Fri Jul 13 15:13:03 2007 From: Gregory.Murphy at Sun.COM (Gregory Murphy) Date: Fri, 13 Jul 2007 12:13:03 -0700 Subject: [rspec-users] spec for Rails library Message-ID: <4697CEBF.1040400@sun.com> How does one write a spec for a Rails library? // Gregory From aslak.hellesoy at gmail.com Fri Jul 13 15:24:52 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 13 Jul 2007 21:24:52 +0200 Subject: [rspec-users] spec for Rails library In-Reply-To: <4697CEBF.1040400@sun.com> References: <4697CEBF.1040400@sun.com> Message-ID: <8d961d900707131224r1c4ce1f6ud2c43c4c11100645@mail.gmail.com> On 7/13/07, Gregory Murphy wrote: > How does one write a spec for a Rails library? > Umm, just like you would for any other Ruby library. Can you be more specific? Aslak > // Gregory > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From Gregory.Murphy at Sun.COM Fri Jul 13 15:31:05 2007 From: Gregory.Murphy at Sun.COM (Gregory Murphy) Date: Fri, 13 Jul 2007 12:31:05 -0700 Subject: [rspec-users] spec for Rails library In-Reply-To: <8d961d900707131224r1c4ce1f6ud2c43c4c11100645@mail.gmail.com> References: <4697CEBF.1040400@sun.com> <8d961d900707131224r1c4ce1f6ud2c43c4c11100645@mail.gmail.com> Message-ID: <4697D2F9.2070804@sun.com> aslak hellesoy wrote: > On 7/13/07, Gregory Murphy wrote: >> How does one write a spec for a Rails library? >> > > Umm, just like you would for any other Ruby library. Can you be more > specific? Sorry, I'm referring in particular to RSpec for Rails. It generates a number of directories in a Rails app, with a place for model specs, for example, and a rake task to run them, e.g. 'rake spec:models'. But there is no place and no task for library tests. // Gregory From tom at experthuman.com Fri Jul 13 17:12:06 2007 From: tom at experthuman.com (Tom Stuart) Date: Fri, 13 Jul 2007 22:12:06 +0100 Subject: [rspec-users] spec for Rails library In-Reply-To: <4697D2F9.2070804@sun.com> References: <4697CEBF.1040400@sun.com> <8d961d900707131224r1c4ce1f6ud2c43c4c11100645@mail.gmail.com> <4697D2F9.2070804@sun.com> Message-ID: <3C19569D-370B-482D-920F-70CCCC329BB4@experthuman.com> On 13 Jul 2007, at 20:31, Gregory Murphy wrote: > I'm referring in particular to RSpec for Rails. It generates a > number of directories in a Rails app, with a place for model specs, > for > example, and a rake task to run them, e.g. 'rake spec:models'. But > there > is no place and no task for library tests. Put them wherever you want -- most people seem to use spec/lib (cf http://rubyforge.org/pipermail/rspec-users/2007-June/002069.html). They'll get run by "rake spec" along with everything else; add :libs to the "[:models, :controllers, :views, :helpers].each" line in vendor/plugins/rspec_on_rails/tasks/rspec.rake if you want to be able to say "rake spec:libs". Cheers, -Tom From aslak.hellesoy at gmail.com Fri Jul 13 17:45:02 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 13 Jul 2007 23:45:02 +0200 Subject: [rspec-users] spec for Rails library In-Reply-To: <3C19569D-370B-482D-920F-70CCCC329BB4@experthuman.com> References: <4697CEBF.1040400@sun.com> <8d961d900707131224r1c4ce1f6ud2c43c4c11100645@mail.gmail.com> <4697D2F9.2070804@sun.com> <3C19569D-370B-482D-920F-70CCCC329BB4@experthuman.com> Message-ID: <8d961d900707131445n2f0d115dodbf4e015ebd54d6c@mail.gmail.com> On 7/13/07, Tom Stuart wrote: > On 13 Jul 2007, at 20:31, Gregory Murphy wrote: > > I'm referring in particular to RSpec for Rails. It generates a > > number of directories in a Rails app, with a place for model specs, > > for > > example, and a rake task to run them, e.g. 'rake spec:models'. But > > there > > is no place and no task for library tests. > > Put them wherever you want -- most people seem to use spec/lib (cf > http://rubyforge.org/pipermail/rspec-users/2007-June/002069.html). > They'll get run by "rake spec" along with everything else; add :libs > to the "[:models, :controllers, :views, :helpers].each" line in > vendor/plugins/rspec_on_rails/tasks/rspec.rake if you want to be able > to say "rake spec:libs". > Hey! That's not for users to do! I've added it to rspec.rake ;-) Aslak > Cheers, > -Tom > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jed.hurt at gmail.com Sat Jul 14 03:31:42 2007 From: jed.hurt at gmail.com (Jed Hurt) Date: Sat, 14 Jul 2007 01:31:42 -0600 Subject: [rspec-users] expect_render twice in views Message-ID: I found this: controller.expect_render(:partial => 'thing', :collection => things).once but I am trying to expect_render twice in my view spec: template.expect_render(:partial => 'order_details').twice This doesn't work as the template.expect_render call seems to be returning an array. Is it possible to expect the rendering of a partial twice in a view spec? From aslak.hellesoy at gmail.com Sat Jul 14 04:57:14 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 14 Jul 2007 10:57:14 +0200 Subject: [rspec-users] expect_render twice in views In-Reply-To: References: Message-ID: <8d961d900707140157g41fa9270ufdf47a975d6232a7@mail.gmail.com> On 7/14/07, Jed Hurt wrote: > I found this: > > controller.expect_render(:partial => 'thing', :collection => things).once > > but I am trying to expect_render twice in my view spec: > > template.expect_render(:partial => 'order_details').twice > > > This doesn't work as the template.expect_render call seems to be > returning an array. Is it possible to expect the rendering of a > partial twice in a view spec? Currently not (AFAICT). Could you submit an RFE, or better - a patch? Aslak > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Jul 14 10:13:14 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 14 Jul 2007 09:13:14 -0500 Subject: [rspec-users] expect_render twice in views In-Reply-To: <8d961d900707140157g41fa9270ufdf47a975d6232a7@mail.gmail.com> References: <8d961d900707140157g41fa9270ufdf47a975d6232a7@mail.gmail.com> Message-ID: <57c63afe0707140713p18aff7b0k7c51876464bc90e8@mail.gmail.com> On 7/14/07, aslak hellesoy wrote: > On 7/14/07, Jed Hurt wrote: > > I found this: > > > > controller.expect_render(:partial => 'thing', :collection => things).once > > > > but I am trying to expect_render twice in my view spec: > > > > template.expect_render(:partial => 'order_details').twice > > > > > > This doesn't work as the template.expect_render call seems to be > > returning an array. Is it possible to expect the rendering of a > > partial twice in a view spec? > > Currently not (AFAICT). Could you submit an RFE, or better - a patch? Given that I this hasn't been released yet and we want to a release soon, I broke form and just fixed this in trunk r2174. Cheers, David > > Aslak > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Sat Jul 14 11:43:45 2007 From: has.sox at gmail.com (Daniel N) Date: Sun, 15 Jul 2007 01:43:45 +1000 Subject: [rspec-users] Specing Layouts Message-ID: <2fff50390707140843w8e2630evc805db93c614c955@mail.gmail.com> Hi, I've just started to try and spec my application.html.erb layout as one of the view specs but it totally barfs. I'm guessing that it's due to the yield statements in the layout. Any clues as to how to proceed? Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070715/09c30332/attachment.html From jed.hurt at gmail.com Sat Jul 14 12:45:21 2007 From: jed.hurt at gmail.com (Jed Hurt) Date: Sat, 14 Jul 2007 10:45:21 -0600 Subject: [rspec-users] expect_render twice in views In-Reply-To: <57c63afe0707140713p18aff7b0k7c51876464bc90e8@mail.gmail.com> References: <8d961d900707140157g41fa9270ufdf47a975d6232a7@mail.gmail.com> <57c63afe0707140713p18aff7b0k7c51876464bc90e8@mail.gmail.com> Message-ID: Works like a charm. Thanks! On 7/14/07, David Chelimsky wrote: > On 7/14/07, aslak hellesoy wrote: > > On 7/14/07, Jed Hurt wrote: > > > I found this: > > > > > > controller.expect_render(:partial => 'thing', :collection => things).once > > > > > > but I am trying to expect_render twice in my view spec: > > > > > > template.expect_render(:partial => 'order_details').twice > > > > > > > > > This doesn't work as the template.expect_render call seems to be > > > returning an array. Is it possible to expect the rendering of a > > > partial twice in a view spec? > > > > Currently not (AFAICT). Could you submit an RFE, or better - a patch? > > Given that I this hasn't been released yet and we want to a release > soon, I broke form and just fixed this in trunk r2174. > > Cheers, > David > > > > > Aslak > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Jul 14 12:50:48 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 14 Jul 2007 11:50:48 -0500 Subject: [rspec-users] Specing Layouts In-Reply-To: <2fff50390707140843w8e2630evc805db93c614c955@mail.gmail.com> References: <2fff50390707140843w8e2630evc805db93c614c955@mail.gmail.com> Message-ID: <57c63afe0707140950k2b347d7g2847dc1f62660b92@mail.gmail.com> On 7/14/07, Daniel N wrote: > Hi, > > I've just started to try and spec my application.html.erb layout as one of > the view specs but it totally barfs. > > I'm guessing that it's due to the yield statements in the layout. > > Any clues as to how to proceed? Backtrace please? Could be any number of things. > > Cheers > Daniel > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Sat Jul 14 23:25:35 2007 From: has.sox at gmail.com (Daniel N) Date: Sun, 15 Jul 2007 13:25:35 +1000 Subject: [rspec-users] Specing Layouts In-Reply-To: <57c63afe0707140950k2b347d7g2847dc1f62660b92@mail.gmail.com> References: <2fff50390707140843w8e2630evc805db93c614c955@mail.gmail.com> <57c63afe0707140950k2b347d7g2847dc1f62660b92@mail.gmail.com> Message-ID: <2fff50390707142025x28e39032j40ca2626c7ec210d@mail.gmail.com> On 7/15/07, David Chelimsky wrote: > > On 7/14/07, Daniel N wrote: > > Hi, > > > > I've just started to try and spec my application.html.erb layout as one > of > > the view specs but it totally barfs. > > > > I'm guessing that it's due to the yield statements in the layout. > > > > Any clues as to how to proceed? > > Backtrace please? Could be any number of things. > > > Sorry, here it is ......rake aborted! Command ruby -I"/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib" "/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/bin/spec" "spec/controllers/books_controller_spec.rb" "spec/controllers/sessions_controller_spec.rb" "spec/controllers/users_controller_spec.rb" "spec/helpers/books_helper_spec.rb" "spec/helpers/sessions_helper_spec.rb" "spec/helpers/users_helper_spec.rb" "spec/models/book_spec.rb" "spec/models/user_notifier_spec.rb" "spec/models/user_spec.rb" "spec/views/books/_detail.html.erb_spec.rb" "spec/views/books/edit.html.erb_spec.rb" "spec/views/books/index.html.erb_spec.rb" "spec/views/books/new.html.erb_spec.rb" "spec/views/books/new_rjs.html.erb_spec.rb" "spec/views/books/rjs_index.html.erb_spec.rb" "spec/views/books/show.html.erb_spec.rb" "spec/views/layouts/application.html.erb_spec.rb" --options "/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/spec/spec.opts" failed /Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib/spec/rake/spectask.rb:166:in `define' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:823:in `verbose' /Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib/spec/rake/spectask.rb:138:in `define' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `each' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in `top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1711:in `run' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in `run' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/bin/rake:7 /usr/local/bin/rake:16:in `load' /usr/local/bin/rake:16 And the test is require File.dirname(__FILE__) + '/../../spec_helper' describe "/layouts/application.html.erb" do it "should render" do render "/layouts/application.html.erb" end end Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070715/5d59648f/attachment-0001.html From dchelimsky at gmail.com Sun Jul 15 08:58:33 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 15 Jul 2007 07:58:33 -0500 Subject: [rspec-users] Specing Layouts In-Reply-To: <2fff50390707142025x28e39032j40ca2626c7ec210d@mail.gmail.com> References: <2fff50390707140843w8e2630evc805db93c614c955@mail.gmail.com> <57c63afe0707140950k2b347d7g2847dc1f62660b92@mail.gmail.com> <2fff50390707142025x28e39032j40ca2626c7ec210d@mail.gmail.com> Message-ID: <57c63afe0707150558k448bf3c3mf24b40a3cd67a103@mail.gmail.com> On 7/14/07, Daniel N wrote: > > > On 7/15/07, David Chelimsky wrote: > > On 7/14/07, Daniel N wrote: > > > Hi, > > > > > > I've just started to try and spec my application.html.erb layout as one > of > > > the view specs but it totally barfs. > > > > > > I'm guessing that it's due to the yield statements in the layout. > > > > > > Any clues as to how to proceed? > > > > Backtrace please? Could be any number of things. > > > > > > > Sorry, here it is > > ......rake aborted! > Command ruby > -I"/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib" > "/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/bin/spec" > "spec/controllers/books_controller_spec.rb" > "spec/controllers/sessions_controller_spec.rb" > "spec/controllers/users_controller_spec.rb" > "spec/helpers/books_helper_spec.rb" > "spec/helpers/sessions_helper_spec.rb" > "spec/helpers/users_helper_spec.rb" > "spec/models/book_spec.rb" > "spec/models/user_notifier_spec.rb" > "spec/models/user_spec.rb" > "spec/views/books/_detail.html.erb_spec.rb" > "spec/views/books/edit.html.erb_spec.rb" > "spec/views/books/index.html.erb_spec.rb" > "spec/views/books/new.html.erb_spec.rb" > "spec/views/books/new_rjs.html.erb_spec.rb" > "spec/views/books/rjs_index.html.erb_spec.rb" > "spec/views/books/show.html.erb_spec.rb" > "spec/views/layouts/application.html.erb_spec.rb" --options > "/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/spec/spec.opts" > failed > /Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib/spec/rake/spectask.rb:166:in > `define' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:823:in > `verbose' > /Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib/spec/rake/spectask.rb:138:in > `define' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > `call' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > `execute' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > `each' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > `execute' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in > `invoke' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in > `synchronize' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in > `invoke' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > `top_level' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > `each' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > `top_level' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in > `standard_exception_handling' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in > `top_level' > /usr/local/lib/ruby/gems/1.8/gems/rake- > 0.7.3/lib/rake.rb:1711:in `run' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in > `standard_exception_handling' > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in > `run' > /usr/local/lib/ruby/gems/1.8/gems/rake- 0.7.3/bin/rake:7 > /usr/local/bin/rake:16:in `load' > /usr/local/bin/rake:16 > > And the test is > > require File.dirname(__FILE__) + '/../../spec_helper' > > describe "/layouts/application.html.erb" do > > it "should render" do > render "/layouts/application.html.erb" > end > > > end Thanks. Unfortunately there's nothing in that backtrace that talks about application.html.erb. Would you please run this command and post the result? script/spec spec/views/layouts/application.html.erb -b Thanks, David > > Cheers > Daniel > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Sun Jul 15 10:08:00 2007 From: has.sox at gmail.com (Daniel N) Date: Mon, 16 Jul 2007 00:08:00 +1000 Subject: [rspec-users] Specing Layouts In-Reply-To: <57c63afe0707150558k448bf3c3mf24b40a3cd67a103@mail.gmail.com> References: <2fff50390707140843w8e2630evc805db93c614c955@mail.gmail.com> <57c63afe0707140950k2b347d7g2847dc1f62660b92@mail.gmail.com> <2fff50390707142025x28e39032j40ca2626c7ec210d@mail.gmail.com> <57c63afe0707150558k448bf3c3mf24b40a3cd67a103@mail.gmail.com> Message-ID: <2fff50390707150707x706865acy681c97d9b069d614@mail.gmail.com> On 7/15/07, David Chelimsky wrote: > > On 7/14/07, Daniel N wrote: > > > > > > On 7/15/07, David Chelimsky wrote: > > > On 7/14/07, Daniel N wrote: > > > > Hi, > > > > > > > > I've just started to try and spec my application.html.erb layout as > one > > of > > > > the view specs but it totally barfs. > > > > > > > > I'm guessing that it's due to the yield statements in the layout. > > > > > > > > Any clues as to how to proceed? > > > > > > Backtrace please? Could be any number of things. > > > > > > > > > > > Sorry, here it is > > > > ......rake aborted! > > Command ruby > > > -I"/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib" > > > "/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/bin/spec" > > "spec/controllers/books_controller_spec.rb" > > "spec/controllers/sessions_controller_spec.rb" > > "spec/controllers/users_controller_spec.rb" > > "spec/helpers/books_helper_spec.rb" > > "spec/helpers/sessions_helper_spec.rb" > > "spec/helpers/users_helper_spec.rb" > > "spec/models/book_spec.rb" > > "spec/models/user_notifier_spec.rb" > > "spec/models/user_spec.rb" > > "spec/views/books/_detail.html.erb_spec.rb" > > "spec/views/books/edit.html.erb_spec.rb" > > "spec/views/books/index.html.erb_spec.rb" > > "spec/views/books/new.html.erb_spec.rb" > > "spec/views/books/new_rjs.html.erb_spec.rb" > > "spec/views/books/rjs_index.html.erb_spec.rb" > > "spec/views/books/show.html.erb_spec.rb" > > "spec/views/layouts/application.html.erb_spec.rb" --options > > > "/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/spec/spec.opts" > > failed > > > /Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib/spec/rake/spectask.rb:166:in > > `define' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:823:in > > `verbose' > > > /Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib/spec/rake/spectask.rb:138:in > > `define' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > `call' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > `execute' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > `each' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > `execute' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in > > `invoke' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in > > `synchronize' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in > > `invoke' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > `top_level' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > `each' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > `top_level' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in > > `standard_exception_handling' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in > > `top_level' > > /usr/local/lib/ruby/gems/1.8/gems/rake- > > 0.7.3/lib/rake.rb:1711:in `run' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in > > `standard_exception_handling' > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in > > `run' > > /usr/local/lib/ruby/gems/1.8/gems/rake- 0.7.3/bin/rake:7 > > /usr/local/bin/rake:16:in `load' > > /usr/local/bin/rake:16 > > > > And the test is > > > > require File.dirname(__FILE__) + '/../../spec_helper' > > > > describe "/layouts/application.html.erb" do > > > > it "should render" do > > render "/layouts/application.html.erb" > > end > > > > > > end > > Thanks. Unfortunately there's nothing in that backtrace that talks > about application.html.erb. Would you please run this command and post > the result? > > script/spec spec/views/layouts/application.html.erb -b > > Thanks, > David Hi David, Very strange indeed. I had to change the command to script/spec spec/views/layouts/application.html.erb_spec.rb -b When I run this I get no errors at all. But I also get no output at all. When I run the focused example in Textmate it passes but there is no listing of the example in the output. This is the same as running the Behaviour Description It also does not seem to fail anything. I ran the following def do_render > render "/layouts/application.html.erb" > end > > it "should render the template" do > do_render > response.should have_tag("not_there_tag") > flunk > end This seems to pass everything. But when I run it with rake spec I get the same error as before In an attempt to see if it is running the template at all I put a dodgy method call in the template to try to crash it. It crashes. Here's the stack trace ActionView::TemplateError in '/layouts/application.html.erb should render the template' undefined local variable or method `bad_method' for #<#:0x33446f0> On line #14 of app/views/layouts/application.html.erb 11: <%= javascript_include_tag :defaults, 'lowpro' -%> 12: <%= stylesheet_link_tag 'common' -%> 13: <%= resource_on_demand %> 14: <%= bad_method %> 15: 16: 17: #{RAILS_ROOT}/app/views//layouts/application.html.erb:14:in `_run_erb_47app47views47layouts47application46html46erb' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_view/base.rb:346:in `send' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_view/base.rb:346:in `compile_and_render_template' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_view/base.rb:322:in `render_template_old' #{RAILS_ROOT}/vendor/plugins/stable/lib/haml/template.rb:96:in `render_template' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_view/base.rb:282:in `render_file' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_controller/base.rb:854:in `render_file' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_controller/base.rb:789:in `render_with_no_layout' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_controller/layout.rb:258:in `render_without_benchmark' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_controller/benchmarking.rb:51:in `render' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_controller/benchmarking.rb:51:in `render' #{RAILS_ROOT}/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:55:in `send' #{RAILS_ROOT}/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:55:in `render' spec/views/layouts/application.html.erb_spec.rb:6:in `do_render' spec/views/layouts/application.html.erb_spec.rb:10 #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:81:in `instance_eval' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:81:in `run_example' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:26:in `run' /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:24:in `run' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:80:in `run' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in `each' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in `run' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:58:in `run_behaviours' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:57:in `each' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:57:in `run_behaviours' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:21:in `run' #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in `run' script/spec:4 I've changed to a haml template, and used the same spec but with a different file (.haml) to render and it ran fine. Passes everything with complete listings etc. I really don't know what to make of it. Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070716/cd6d8130/attachment.html From has.sox at gmail.com Sun Jul 15 10:35:16 2007 From: has.sox at gmail.com (Daniel N) Date: Mon, 16 Jul 2007 00:35:16 +1000 Subject: [rspec-users] Specing Layouts In-Reply-To: <2fff50390707150707x706865acy681c97d9b069d614@mail.gmail.com> References: <2fff50390707140843w8e2630evc805db93c614c955@mail.gmail.com> <57c63afe0707140950k2b347d7g2847dc1f62660b92@mail.gmail.com> <2fff50390707142025x28e39032j40ca2626c7ec210d@mail.gmail.com> <57c63afe0707150558k448bf3c3mf24b40a3cd67a103@mail.gmail.com> <2fff50390707150707x706865acy681c97d9b069d614@mail.gmail.com> Message-ID: <2fff50390707150735t16867e62hdb7612c4643bd8ac@mail.gmail.com> On 7/16/07, Daniel N wrote: > > > > On 7/15/07, David Chelimsky wrote: > > > > On 7/14/07, Daniel N wrote: > > > > > > > > > On 7/15/07, David Chelimsky wrote: > > > > On 7/14/07, Daniel N wrote: > > > > > Hi, > > > > > > > > > > I've just started to try and spec my application.html.erb layout > > as one > > > of > > > > > the view specs but it totally barfs. > > > > > > > > > > I'm guessing that it's due to the yield statements in the layout. > > > > > > > > > > Any clues as to how to proceed? > > > > > > > > Backtrace please? Could be any number of things. > > > > > > > > > > > > > > > Sorry, here it is > > > > > > ......rake aborted! > > > Command ruby > > > > > -I"/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib" > > > > > > > "/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/bin/spec" > > > "spec/controllers/books_controller_spec.rb" > > > "spec/controllers/sessions_controller_spec.rb" > > > "spec/controllers/users_controller_spec.rb" > > > "spec/helpers/books_helper_spec.rb" > > > "spec/helpers/sessions_helper_spec.rb" > > > "spec/helpers/users_helper_spec.rb" > > > "spec/models/book_spec.rb" > > > "spec/models/user_notifier_spec.rb" > > > "spec/models/user_spec.rb" > > > "spec/views/books/_detail.html.erb_spec.rb" > > > "spec/views/books/edit.html.erb_spec.rb" > > > "spec/views/books/index.html.erb_spec.rb" > > > "spec/views/books/new.html.erb_spec.rb" > > > "spec/views/books/new_rjs.html.erb_spec.rb" > > > "spec/views/books/rjs_index.html.erb_spec.rb" > > > "spec/views/books/show.html.erb_spec.rb" > > > "spec/views/layouts/application.html.erb_spec.rb" --options > > > > > "/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/spec/spec.opts" > > > > > failed > > > > > /Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib/spec/rake/spectask.rb:166:in > > > `define' > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3 /lib/rake.rb:823:in > > > `verbose' > > > > > /Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib/spec/rake/spectask.rb:138:in > > > `define' > > > /usr/local/lib/ruby/gems/1.8/gems/rake- 0.7.3/lib/rake.rb:392:in > > > `call' > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > > `execute' > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > > `each' > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > > `execute' > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in > > > `invoke' > > > /usr/local/lib/ruby/gems/1.8/gems/rake- 0.7.3/lib/rake.rb:355:in > > > `synchronize' > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in > > > `invoke' > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > > `top_level' > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > > `each' > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > > `top_level' > > > /usr/local/lib/ruby/gems/1.8/gems/rake- 0.7.3/lib/rake.rb:1761:in > > > `standard_exception_handling' > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in > > > `top_level' > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > > > 0.7.3/lib/rake.rb:1711:in `run' > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in > > > `standard_exception_handling' > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in > > > `run' > > > /usr/local/lib/ruby/gems/1.8/gems/rake- 0.7.3/bin/rake:7 > > > /usr/local/bin/rake:16:in `load' > > > /usr/local/bin/rake:16 > > > > > > And the test is > > > > > > require File.dirname (__FILE__) + '/../../spec_helper' > > > > > > describe "/layouts/application.html.erb" do > > > > > > it "should render" do > > > render "/layouts/application.html.erb" > > > end > > > > > > > > > end > > > > Thanks. Unfortunately there's nothing in that backtrace that talks > > about application.html.erb. Would you please run this command and post > > the result? > > > > script/spec spec/views/layouts/application.html.erb -b > > > > Thanks, > > David > > > Hi David, > > Very strange indeed. I had to change the command to > script/spec spec/views/layouts/application.html.erb_spec.rb -b > > When I run this I get no errors at all. But I also get no output at all. > > When I run the focused example in Textmate it passes but there is no > listing of the example in the output. This is the same as running the > Behaviour Description > > It also does not seem to fail anything. I ran the following > > def do_render > > render "/layouts/application.html.erb" > > end > > > > it "should render the template" do > > do_render > > response.should have_tag("not_there_tag") > > flunk > > end > > > This seems to pass everything. But when I run it with > rake spec I get the same error as before > > In an attempt to see if it is running the template at all I put a dodgy > method call in the template to try to crash it. It crashes. > > Here's the stack trace > > ActionView::TemplateError in '/layouts/application.html.erb should render > the template' > undefined local variable or method `bad_method' for > #<#:0x33446f0> > On line #14 of app/views/layouts/application.html.erb > > 11: <%= javascript_include_tag :defaults, 'lowpro' -%> > 12: <%= stylesheet_link_tag 'common' -%> > 13: <%= resource_on_demand %> > 14: <%= bad_method %> > 15: > 16: > 17: > > #{RAILS_ROOT}/app/views//layouts/application.html.erb:14:in > `_run_erb_47app47views47layouts47application46html46erb' > /usr/local/lib/ruby/gems/1.8/gems/actionpack- 1.13.3.6752/lib/action_view/base.rb:346:in > `send' > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_view/base.rb:346:in > `compile_and_render_template' > /usr/local/lib/ruby/gems/1.8/gems/actionpack- 1.13.3.6752/lib/action_view/base.rb:322:in > `render_template_old' > #{RAILS_ROOT}/vendor/plugins/stable/lib/haml/template.rb:96:in > `render_template' > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_view/base.rb:282:in `render_file' > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_controller/base.rb:854:in > `render_file' > /usr/local/lib/ruby/gems/1.8/gems/actionpack- 1.13.3.6752/lib/action_controller/base.rb:789:in > `render_with_no_layout' > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_controller/layout.rb:258:in > `render_without_benchmark' > /usr/local/lib/ruby/gems/1.8/gems/actionpack- 1.13.3.6752/lib/action_controller/benchmarking.rb:51:in > `render' > /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_controller/benchmarking.rb:51:in > `render' > > #{RAILS_ROOT}/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:55:in > `send' > > #{RAILS_ROOT}/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:55:in > `render' > spec/views/layouts/application.html.erb_spec.rb:6:in `do_render' > spec/views/layouts/application.html.erb_spec.rb:10 > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:81:in > `instance_eval' > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:81:in > `run_example' > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:26:in `run' > /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout' > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:24:in `run' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:80:in > `run' > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in > `each' > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in > `run' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:58:in > `run_behaviours' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:57:in > `each' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:57:in > `run_behaviours' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:21:in > `run' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in > `run' > script/spec:4 > > I've changed to a haml template, and used the same spec but with a > different file (.haml) to render and it ran fine. Passes everything with > complete listings etc. > > I really don't know what to make of it. > > Cheers > Daniel David, Thankyou for being so patient. I've discovered the issue. I'm basically re-writing my app as I port it over to specs from a nasty mix of units and various plugins. During the move I've started to test the application layout where it tries to render a parital that I haven't got yet. Once I take the render :partial call out for the non existing partial, everything went back to normal. I hope I haven't wasted too much of your time. I'm really sorry. Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070716/6c8a7751/attachment-0001.html From dchelimsky at gmail.com Sun Jul 15 10:35:33 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 15 Jul 2007 09:35:33 -0500 Subject: [rspec-users] Specing Layouts In-Reply-To: <2fff50390707150707x706865acy681c97d9b069d614@mail.gmail.com> References: <2fff50390707140843w8e2630evc805db93c614c955@mail.gmail.com> <57c63afe0707140950k2b347d7g2847dc1f62660b92@mail.gmail.com> <2fff50390707142025x28e39032j40ca2626c7ec210d@mail.gmail.com> <57c63afe0707150558k448bf3c3mf24b40a3cd67a103@mail.gmail.com> <2fff50390707150707x706865acy681c97d9b069d614@mail.gmail.com> Message-ID: <57c63afe0707150735l441a6a7dle5480c697c0ece69@mail.gmail.com> On 7/15/07, Daniel N wrote: > > > > On 7/15/07, David Chelimsky wrote: > > On 7/14/07, Daniel N wrote: > > > > > > > > > On 7/15/07, David Chelimsky wrote: > > > > On 7/14/07, Daniel N wrote: > > > > > Hi, > > > > > > > > > > I've just started to try and spec my application.html.erb layout as > one > > > of > > > > > the view specs but it totally barfs. > > > > > > > > > > I'm guessing that it's due to the yield statements in the layout. > > > > > > > > > > Any clues as to how to proceed? > > > > > > > > Backtrace please? Could be any number of things. > > > > > > > > > > > > > > > Sorry, here it is > > > > > > ......rake aborted! > > > Command ruby > > > > -I"/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib" > > > > "/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/bin/spec" > > > "spec/controllers/books_controller_spec.rb" > > > "spec/controllers/sessions_controller_spec.rb" > > > "spec/controllers/users_controller_spec.rb" > > > "spec/helpers/books_helper_spec.rb" > > > "spec/helpers/sessions_helper_spec.rb" > > > "spec/helpers/users_helper_spec.rb" > > > "spec/models/book_spec.rb" > > > "spec/models/user_notifier_spec.rb" > > > "spec/models/user_spec.rb" > > > "spec/views/books/_detail.html.erb_spec.rb" > > > "spec/views/books/edit.html.erb_spec.rb" > > > "spec/views/books/index.html.erb_spec.rb" > > > "spec/views/books/new.html.erb_spec.rb" > > > "spec/views/books/new_rjs.html.erb_spec.rb" > > > "spec/views/books/rjs_index.html.erb_spec.rb" > > > "spec/views/books/show.html.erb_spec.rb" > > > "spec/views/layouts/application.html.erb_spec.rb" > --options > > > > "/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/spec/spec.opts" > > > failed > > > > /Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib/spec/rake/spectask.rb:166:in > > > `define' > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3 > /lib/rake.rb:823:in > > > `verbose' > > > > /Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib/spec/rake/spectask.rb:138:in > > > `define' > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > 0.7.3/lib/rake.rb:392:in > > > `call' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > > `execute' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > > `each' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > > `execute' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in > > > `invoke' > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > 0.7.3/lib/rake.rb:355:in > > > `synchronize' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in > > > `invoke' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > > `top_level' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > > `each' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > > `top_level' > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > 0.7.3/lib/rake.rb:1761:in > > > `standard_exception_handling' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in > > > `top_level' > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > > > 0.7.3/lib/rake.rb:1711:in `run' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in > > > `standard_exception_handling' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in > > > `run' > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > 0.7.3/bin/rake:7 > > > /usr/local/bin/rake:16:in `load' > > > /usr/local/bin/rake:16 > > > > > > And the test is > > > > > > require File.dirname (__FILE__) + '/../../spec_helper' > > > > > > describe "/layouts/application.html.erb" do > > > > > > it "should render" do > > > render "/layouts/application.html.erb" > > > end > > > > > > > > > end > > > > Thanks. Unfortunately there's nothing in that backtrace that talks > > about application.html.erb. Would you please run this command and post > > the result? > > > > script/spec spec/views/layouts/application.html.erb -b > > > > Thanks, > > David > > Hi David, > > Very strange indeed. I had to change the command to > script/spec spec/views/layouts/application.html.erb_spec.rb > -b > > When I run this I get no errors at all. But I also get no output at all. > > When I run the focused example in Textmate it passes but there is no listing > of the example in the output. This is the same as running the Behaviour > Description > > It also does not seem to fail anything. I ran the following > > > def do_render > > render "/layouts/application.html.erb" > > end > > > > it "should render the template" do > > do_render > > response.should have_tag("not_there_tag") > > flunk > > end > > This seems to pass everything. But when I run it with > rake spec I get the same error as before > > In an attempt to see if it is running the template at all I put a dodgy > method call in the template to try to crash it. It crashes. > > Here's the stack trace > > ActionView::TemplateError in '/layouts/application.html.erb should render > the template' > undefined local variable or method `bad_method' for > #<#:0x33446f0> > On line #14 of app/views/layouts/application.html.erb > > 11: <%= javascript_include_tag :defaults, 'lowpro' -%> > 12: <%= stylesheet_link_tag 'common' -%> > 13: <%= resource_on_demand %> > 14: <%= bad_method %> > 15: > 16: > 17: > > > #{RAILS_ROOT}/app/views//layouts/application.html.erb:14:in > `_run_erb_47app47views47layouts47application46html46erb' > /usr/local/lib/ruby/gems/1.8/gems/actionpack- > 1.13.3.6752/lib/action_view/base.rb:346:in `send' > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_view/base.rb:346:in > `compile_and_render_template' > /usr/local/lib/ruby/gems/1.8/gems/actionpack- > 1.13.3.6752/lib/action_view/base.rb:322:in `render_template_old' > > #{RAILS_ROOT}/vendor/plugins/stable/lib/haml/template.rb:96:in > `render_template' > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752 > /lib/action_view/base.rb:282:in `render_file' > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_controller/base.rb:854:in > `render_file' > /usr/local/lib/ruby/gems/1.8/gems/actionpack- > 1.13.3.6752/lib/action_controller/base.rb:789:in > `render_with_no_layout' > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_controller/layout.rb:258:in > `render_without_benchmark' > /usr/local/lib/ruby/gems/1.8/gems/actionpack- > 1.13.3.6752/lib/action_controller/benchmarking.rb:51:in > `render' > /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_controller/benchmarking.rb:51:in > `render' > > #{RAILS_ROOT}/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:55:in > `send' > > #{RAILS_ROOT}/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:55:in > `render' > spec/views/layouts/application.html.erb_spec.rb:6:in > `do_render' > spec/views/layouts/application.html.erb_spec.rb:10 > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:81:in > `instance_eval' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:81:in > `run_example' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:26:in > `run' > /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:24:in > `run' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:80:in > `run' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in > `each' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in > `run' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:58:in > `run_behaviours' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:57:in > `each' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:57:in > `run_behaviours' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:21:in > `run' > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in > `run' > script/spec:4 > > I've changed to a haml template, and used the same spec but with a different > file (.haml) to render and it ran fine. Passes everything with complete > listings etc. > > I really don't know what to make of it. Me neither. I don't have any trouble like what you've described, and I do have application.html.erb described in my apps. As for .haml, I haven't tried using .haml and rspec_on_rails does not support .haml at this point, nor is there any plan to do so. Not that we've chosen not to, just that it hasn't come up as a feature request. Although, if it does, it won't likely get implemented until either Aslak or I decide to start using haml on our own projects or someone on this list submits a patch. Haml aside, I'm clueless. If you want to send me a zip file (you can send it off list) of the whole project, I'd be glad to try and start it up and see what I can find. Meanwhile, if anyone else is having a similar experience, please speak up. Thanks, David > > Cheers > Daniel > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Jul 15 10:36:40 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 15 Jul 2007 09:36:40 -0500 Subject: [rspec-users] Specing Layouts In-Reply-To: <2fff50390707150735t16867e62hdb7612c4643bd8ac@mail.gmail.com> References: <2fff50390707140843w8e2630evc805db93c614c955@mail.gmail.com> <57c63afe0707140950k2b347d7g2847dc1f62660b92@mail.gmail.com> <2fff50390707142025x28e39032j40ca2626c7ec210d@mail.gmail.com> <57c63afe0707150558k448bf3c3mf24b40a3cd67a103@mail.gmail.com> <2fff50390707150707x706865acy681c97d9b069d614@mail.gmail.com> <2fff50390707150735t16867e62hdb7612c4643bd8ac@mail.gmail.com> Message-ID: <57c63afe0707150736p10f172b8n345d2b6c0e3003eb@mail.gmail.com> On 7/15/07, Daniel N wrote: > > > > On 7/16/07, Daniel N wrote: > > > > > > > > > > On 7/15/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > On 7/14/07, Daniel N wrote: > > > > > > > > > > > > On 7/15/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > > On 7/14/07, Daniel N wrote: > > > > > > Hi, > > > > > > > > > > > > I've just started to try and spec my application.html.erb layout > as one > > > > of > > > > > > the view specs but it totally barfs. > > > > > > > > > > > > I'm guessing that it's due to the yield statements in the layout. > > > > > > > > > > > > Any clues as to how to proceed? > > > > > > > > > > Backtrace please? Could be any number of things. > > > > > > > > > > > > > > > > > > > Sorry, here it is > > > > > > > > ......rake aborted! > > > > Command ruby > > > > > -I"/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib" > > > > > "/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/bin/spec" > > > > "spec/controllers/books_controller_spec.rb" > > > > "spec/controllers/sessions_controller_spec.rb" > > > > "spec/controllers/users_controller_spec.rb" > > > > "spec/helpers/books_helper_spec.rb" > > > > "spec/helpers/sessions_helper_spec.rb" > > > > "spec/helpers/users_helper_spec.rb" > > > > "spec/models/book_spec.rb" > > > > "spec/models/user_notifier_spec.rb" > > > > "spec/models/user_spec.rb" > > > > "spec/views/books/_detail.html.erb_spec.rb" > > > > "spec/views/books/edit.html.erb_spec.rb" > > > > "spec/views/books/index.html.erb_spec.rb" > > > > "spec/views/books/new.html.erb_spec.rb" > > > > "spec/views/books/new_rjs.html.erb_spec.rb" > > > > "spec/views/books/rjs_index.html.erb_spec.rb" > > > > "spec/views/books/show.html.erb_spec.rb" > > > > "spec/views/layouts/application.html.erb_spec.rb" > --options > > > > > "/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/spec/spec.opts" > > > > failed > > > > > /Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib/spec/rake/spectask.rb:166:in > > > > `define' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3 > /lib/rake.rb:823:in > > > > `verbose' > > > > > /Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib/spec/rake/spectask.rb:138:in > > > > `define' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > 0.7.3/lib/rake.rb:392:in > > > > `call' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > > > `execute' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > > > `each' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > > > `execute' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in > > > > `invoke' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > 0.7.3/lib/rake.rb:355:in > > > > `synchronize' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in > > > > `invoke' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > > > `top_level' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > > > `each' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > > > `top_level' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > 0.7.3/lib/rake.rb:1761:in > > > > `standard_exception_handling' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in > > > > `top_level' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > > > > 0.7.3/lib/rake.rb:1711:in `run' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in > > > > `standard_exception_handling' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in > > > > `run' > > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > 0.7.3/bin/rake:7 > > > > /usr/local/bin/rake:16:in `load' > > > > /usr/local/bin/rake:16 > > > > > > > > And the test is > > > > > > > > require File.dirname (__FILE__) + '/../../spec_helper' > > > > > > > > describe "/layouts/application.html.erb" do > > > > > > > > it "should render" do > > > > render "/layouts/application.html.erb" > > > > end > > > > > > > > > > > > end > > > > > > Thanks. Unfortunately there's nothing in that backtrace that talks > > > about application.html.erb. Would you please run this command and post > > > the result? > > > > > > script/spec spec/views/layouts/application.html.erb -b > > > > > > Thanks, > > > David > > > > > > Hi David, > > > > Very strange indeed. I had to change the command to > > script/spec > spec/views/layouts/application.html.erb_spec.rb -b > > > > When I run this I get no errors at all. But I also get no output at all. > > > > When I run the focused example in Textmate it passes but there is no > listing of the example in the output. This is the same as running the > Behaviour Description > > > > It also does not seem to fail anything. I ran the following > > > > > > > def do_render > > > render "/layouts/application.html.erb" > > > end > > > > > > it "should render the template" do > > > do_render > > > response.should have_tag("not_there_tag") > > > flunk > > > end > > > > This seems to pass everything. But when I run it with > > rake spec I get the same error as before > > > > In an attempt to see if it is running the template at all I put a dodgy > method call in the template to try to crash it. It crashes. > > > > Here's the stack trace > > > > ActionView::TemplateError in '/layouts/application.html.erb should render > the template' > > undefined local variable or method `bad_method' for > #<#:0x33446f0> > > On line #14 of app/views/layouts/application.html.erb > > > > 11: <%= javascript_include_tag :defaults, 'lowpro' -%> > > 12: <%= stylesheet_link_tag 'common' -%> > > 13: <%= resource_on_demand %> > > 14: <%= bad_method %> > > 15: > > 16: > > 17: > > > > > #{RAILS_ROOT}/app/views//layouts/application.html.erb:14:in > `_run_erb_47app47views47layouts47application46html46erb' > > /usr/local/lib/ruby/gems/1.8/gems/actionpack- > 1.13.3.6752/lib/action_view/base.rb:346:in `send' > > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_view/base.rb:346:in > `compile_and_render_template' > > /usr/local/lib/ruby/gems/1.8/gems/actionpack- > 1.13.3.6752/lib/action_view/base.rb:322:in `render_template_old' > > > #{RAILS_ROOT}/vendor/plugins/stable/lib/haml/template.rb:96:in > `render_template' > > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752 > /lib/action_view/base.rb:282:in `render_file' > > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_controller/base.rb:854:in > `render_file' > > /usr/local/lib/ruby/gems/1.8/gems/actionpack- > 1.13.3.6752/lib/action_controller/base.rb:789:in > `render_with_no_layout' > > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_controller/layout.rb:258:in > `render_without_benchmark' > > /usr/local/lib/ruby/gems/1.8/gems/actionpack- > 1.13.3.6752/lib/action_controller/benchmarking.rb:51:in > `render' > > /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' > > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752/lib/action_controller/benchmarking.rb:51:in > `render' > > > #{RAILS_ROOT}/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:55:in > `send' > > > #{RAILS_ROOT}/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:55:in > `render' > > spec/views/layouts/application.html.erb_spec.rb:6:in > `do_render' > > spec/views/layouts/application.html.erb_spec.rb:10 > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:81:in > `instance_eval' > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:81:in > `run_example' > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:26:in > `run' > > /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout' > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:24:in > `run' > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:80:in > `run' > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in > `each' > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in > `run' > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:58:in > `run_behaviours' > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:57:in > `each' > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:57:in > `run_behaviours' > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:21:in > `run' > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in > `run' > > script/spec:4 > > > > I've changed to a haml template, and used the same spec but with a > different file (.haml) to render and it ran fine. Passes everything with > complete listings etc. > > > > I really don't know what to make of it. > > > > Cheers > > Daniel > > > David, > > Thankyou for being so patient. I've discovered the issue. I'm basically > re-writing my app as I port it over to specs from a nasty mix of units and > various plugins. > > During the move I've started to test the application layout where it tries > to render a parital that I haven't got yet. > > Once I take the render :partial call out for the non existing partial, > everything went back to normal. > > I hope I haven't wasted too much of your time. I'm really sorry. No worries Daniel - when I don't have the time I don't deal w/ this stuff :) Cheers, David > > Cheers > Daniel > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Sun Jul 15 10:48:38 2007 From: has.sox at gmail.com (Daniel N) Date: Mon, 16 Jul 2007 00:48:38 +1000 Subject: [rspec-users] Specing Layouts In-Reply-To: <57c63afe0707150736p10f172b8n345d2b6c0e3003eb@mail.gmail.com> References: <2fff50390707140843w8e2630evc805db93c614c955@mail.gmail.com> <57c63afe0707140950k2b347d7g2847dc1f62660b92@mail.gmail.com> <2fff50390707142025x28e39032j40ca2626c7ec210d@mail.gmail.com> <57c63afe0707150558k448bf3c3mf24b40a3cd67a103@mail.gmail.com> <2fff50390707150707x706865acy681c97d9b069d614@mail.gmail.com> <2fff50390707150735t16867e62hdb7612c4643bd8ac@mail.gmail.com> <57c63afe0707150736p10f172b8n345d2b6c0e3003eb@mail.gmail.com> Message-ID: <2fff50390707150748o57e2928ep2ce4ee6ca90ddd49@mail.gmail.com> On 7/16/07, David Chelimsky wrote: > > On 7/15/07, Daniel N wrote: > > > > > > > > On 7/16/07, Daniel N wrote: > > > > > > > > > > > > > > > On 7/15/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > On 7/14/07, Daniel N wrote: > > > > > > > > > > > > > > > On 7/15/07, David Chelimsky < dchelimsky at gmail.com> wrote: > > > > > > On 7/14/07, Daniel N wrote: > > > > > > > Hi, > > > > > > > > > > > > > > I've just started to try and spec my application.html.erblayout > > as one > > > > > of > > > > > > > the view specs but it totally barfs. > > > > > > > > > > > > > > I'm guessing that it's due to the yield statements in the > layout. > > > > > > > > > > > > > > Any clues as to how to proceed? > > > > > > > > > > > > Backtrace please? Could be any number of things. > > > > > > > > > > > > > > > > > > > > > > > Sorry, here it is > > > > > > > > > > ......rake aborted! > > > > > Command ruby > > > > > > > > -I"/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib" > > > > > > > > "/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/bin/spec" > > > > > "spec/controllers/books_controller_spec.rb" > > > > > "spec/controllers/sessions_controller_spec.rb" > > > > > "spec/controllers/users_controller_spec.rb" > > > > > "spec/helpers/books_helper_spec.rb" > > > > > "spec/helpers/sessions_helper_spec.rb" > > > > > "spec/helpers/users_helper_spec.rb" > > > > > "spec/models/book_spec.rb" > > > > > "spec/models/user_notifier_spec.rb" > > > > > "spec/models/user_spec.rb" > > > > > "spec/views/books/_detail.html.erb_spec.rb" > > > > > "spec/views/books/edit.html.erb_spec.rb" > > > > > "spec/views/books/index.html.erb_spec.rb" > > > > > "spec/views/books/new.html.erb_spec.rb" > > > > > "spec/views/books/new_rjs.html.erb_spec.rb" > > > > > "spec/views/books/rjs_index.html.erb_spec.rb" > > > > > "spec/views/books/show.html.erb_spec.rb" > > > > > "spec/views/layouts/application.html.erb_spec.rb" > > --options > > > > > > > > "/Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/spec/spec.opts" > > > > > failed > > > > > > > > /Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib/spec/rake/spectask.rb:166:in > > > > > `define' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3 > > /lib/rake.rb:823:in > > > > > `verbose' > > > > > > > > /Users/dneighman/Documents/Projects/rails_projects/update_to_clippings/vendor/plugins/rspec/lib/spec/rake/spectask.rb:138:in > > > > > `define' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > > 0.7.3/lib/rake.rb:392:in > > > > > `call' > > > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > > > > `execute' > > > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > > > > `each' > > > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in > > > > > `execute' > > > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in > > > > > `invoke' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > > 0.7.3/lib/rake.rb:355:in > > > > > `synchronize' > > > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in > > > > > `invoke' > > > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > > > > `top_level' > > > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > > > > `each' > > > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in > > > > > `top_level' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > > 0.7.3/lib/rake.rb:1761:in > > > > > `standard_exception_handling' > > > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in > > > > > `top_level' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > > > > > 0.7.3/lib/rake.rb:1711:in `run' > > > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in > > > > > `standard_exception_handling' > > > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in > > > > > `run' > > > > > /usr/local/lib/ruby/gems/1.8/gems/rake- > > 0.7.3/bin/rake:7 > > > > > /usr/local/bin/rake:16:in `load' > > > > > /usr/local/bin/rake:16 > > > > > > > > > > And the test is > > > > > > > > > > require File.dirname (__FILE__) + '/../../spec_helper' > > > > > > > > > > describe "/layouts/application.html.erb" do > > > > > > > > > > it "should render" do > > > > > render "/layouts/application.html.erb" > > > > > end > > > > > > > > > > > > > > > end > > > > > > > > Thanks. Unfortunately there's nothing in that backtrace that talks > > > > about application.html.erb. Would you please run this command and > post > > > > the result? > > > > > > > > script/spec spec/views/layouts/application.html.erb -b > > > > > > > > Thanks, > > > > David > > > > > > > > > Hi David, > > > > > > Very strange indeed. I had to change the command to > > > script/spec > > spec/views/layouts/application.html.erb_spec.rb -b > > > > > > When I run this I get no errors at all. But I also get no output at > all. > > > > > > When I run the focused example in Textmate it passes but there is no > > listing of the example in the output. This is the same as running the > > Behaviour Description > > > > > > It also does not seem to fail anything. I ran the following > > > > > > > > > > def do_render > > > > render "/layouts/application.html.erb" > > > > end > > > > > > > > it "should render the template" do > > > > do_render > > > > response.should have_tag("not_there_tag") > > > > flunk > > > > end > > > > > > This seems to pass everything. But when I run it with > > > rake spec I get the same error as before > > > > > > In an attempt to see if it is running the template at all I put a > dodgy > > method call in the template to try to crash it. It crashes. > > > > > > Here's the stack trace > > > > > > ActionView::TemplateError in '/layouts/application.html.erb should > render > > the template' > > > undefined local variable or method `bad_method' for > > #<#:0x33446f0> > > > On line #14 of app/views/layouts/application.html.erb > > > > > > 11: <%= javascript_include_tag :defaults, 'lowpro' -%> > > > 12: <%= stylesheet_link_tag 'common' -%> > > > 13: <%= resource_on_demand %> > > > 14: <%= bad_method %> > > > 15: > > > 16: > > > 17: > > > > > > > > #{RAILS_ROOT}/app/views//layouts/application.html.erb:14:in > > `_run_erb_47app47views47layouts47application46html46erb' > > > /usr/local/lib/ruby/gems/1.8/gems/actionpack- > > 1.13.3.6752/lib/action_view/base.rb:346:in `send' > > > > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752 > /lib/action_view/base.rb:346:in > > `compile_and_render_template' > > > /usr/local/lib/ruby/gems/1.8/gems/actionpack- > > 1.13.3.6752/lib/action_view/base.rb:322:in `render_template_old' > > > > > #{RAILS_ROOT}/vendor/plugins/stable/lib/haml/template.rb:96:in > > `render_template' > > > > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752 > > /lib/action_view/base.rb:282:in `render_file' > > > > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752 > /lib/action_controller/base.rb:854:in > > `render_file' > > > /usr/local/lib/ruby/gems/1.8/gems/actionpack- > > 1.13.3.6752/lib/action_controller/base.rb:789:in > > `render_with_no_layout' > > > > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752 > /lib/action_controller/layout.rb:258:in > > `render_without_benchmark' > > > /usr/local/lib/ruby/gems/1.8/gems/actionpack- > > 1.13.3.6752/lib/action_controller/benchmarking.rb:51:in > > `render' > > > /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' > > > > > /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3.6752 > /lib/action_controller/benchmarking.rb:51:in > > `render' > > > > > > #{RAILS_ROOT}/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:55:in > > `send' > > > > > > #{RAILS_ROOT}/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:55:in > > `render' > > > spec/views/layouts/application.html.erb_spec.rb:6:in > > `do_render' > > > spec/views/layouts/application.html.erb_spec.rb:10 > > > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:81:in > > `instance_eval' > > > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:81:in > > `run_example' > > > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:26:in > > `run' > > > /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout' > > > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/example.rb:24:in > > `run' > > > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:80:in > > `run' > > > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in > > `each' > > > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:74:in > > `run' > > > > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:58:in > > `run_behaviours' > > > > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:57:in > > `each' > > > > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:57:in > > `run_behaviours' > > > > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:21:in > > `run' > > > > > #{RAILS_ROOT}/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in > > `run' > > > script/spec:4 > > > > > > I've changed to a haml template, and used the same spec but with a > > different file (.haml) to render and it ran fine. Passes everything > with > > complete listings etc. > > > > > > I really don't know what to make of it. > > > > > > Cheers > > > Daniel > > > > > > David, > > > > Thankyou for being so patient. I've discovered the issue. I'm > basically > > re-writing my app as I port it over to specs from a nasty mix of units > and > > various plugins. > > > > During the move I've started to test the application layout where it > tries > > to render a parital that I haven't got yet. > > > > Once I take the render :partial call out for the non existing partial, > > everything went back to normal. > > > > I hope I haven't wasted too much of your time. I'm really sorry. > > No worries Daniel - when I don't have the time I don't deal w/ this stuff > :) > > Cheers, > David > > > > > Cheers > > Daniel > > > > > > David, I've gone through quite a few templates in haml now with specs and they all seem to work fine. I'm on edge rails. Don't know if that makes a difference. Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070716/4739d4e1/attachment-0001.html From crafterm at gmail.com Mon Jul 16 07:02:03 2007 From: crafterm at gmail.com (Marcus Crafter) Date: Mon, 16 Jul 2007 21:02:03 +1000 Subject: [rspec-users] Accessing content_for html in view specs? Message-ID: <2EA1205C-D4B2-41E9-B9E0-EF6705A63200@gmail.com> Hi All, Hope all is going well. I've got a few views that create some content using 'content_for' blocks <% content_for :blah do %> ..... <% end %> Has anyone worked out a way to be able to access the html that's generated inside those blocks? Since they're not part of the view, have_tag('') seems to miss them, and at the moment I can't find a way to be able to access the generated content? Any thoughts, ideas appreciated. Cheers, Marcus From dchelimsky at gmail.com Mon Jul 16 07:04:26 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 16 Jul 2007 06:04:26 -0500 Subject: [rspec-users] Accessing content_for html in view specs? In-Reply-To: <2EA1205C-D4B2-41E9-B9E0-EF6705A63200@gmail.com> References: <2EA1205C-D4B2-41E9-B9E0-EF6705A63200@gmail.com> Message-ID: <57c63afe0707160404j24ed9c40m9102ed0fe58c3d99@mail.gmail.com> On 7/16/07, Marcus Crafter wrote: > Hi All, > > Hope all is going well. > > I've got a few views that create some content using 'content_for' blocks > > <% content_for :blah do %> > ..... > <% end %> > > Has anyone worked out a way to be able to access the html that's > generated inside those blocks? > > Since they're not part of the view, have_tag('') seems to miss them, > and at the moment I can't find a way to be able to access the > generated content? > > Any thoughts, ideas appreciated. Since have_tag wraps assert_select, you may want to post this to the rails mailing lists as well. > > Cheers, > > Marcus > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tom at experthuman.com Mon Jul 16 07:11:57 2007 From: tom at experthuman.com (Tom Stuart) Date: Mon, 16 Jul 2007 12:11:57 +0100 Subject: [rspec-users] Accessing content_for html in view specs? In-Reply-To: <2EA1205C-D4B2-41E9-B9E0-EF6705A63200@gmail.com> References: <2EA1205C-D4B2-41E9-B9E0-EF6705A63200@gmail.com> Message-ID: On 16 Jul 2007, at 12:02, Marcus Crafter wrote: > <% content_for :blah do %> ..... <% end %> > Has anyone worked out a way to be able to access the html that's > generated inside those blocks? It ends up in @content_for_blah, doesn't it? From crafterm at redartisan.com Mon Jul 16 07:14:44 2007 From: crafterm at redartisan.com (Marcus Crafter) Date: Mon, 16 Jul 2007 21:14:44 +1000 Subject: [rspec-users] Accessing content_for html in view specs? In-Reply-To: References: <2EA1205C-D4B2-41E9-B9E0-EF6705A63200@gmail.com> Message-ID: On 16/07/2007, at 9:11 PM, Tom Stuart wrote: > On 16 Jul 2007, at 12:02, Marcus Crafter wrote: >> <% content_for :blah do %> ..... <% end %> >> Has anyone worked out a way to be able to access the html that's >> generated inside those blocks? > > It ends up in @content_for_blah, doesn't it? I thought it did too, but that's a nil reference in the spec unfortunately. Cheers, Marcus From tom at experthuman.com Mon Jul 16 07:41:34 2007 From: tom at experthuman.com (Tom Stuart) Date: Mon, 16 Jul 2007 12:41:34 +0100 Subject: [rspec-users] Accessing content_for html in view specs? In-Reply-To: References: <2EA1205C-D4B2-41E9-B9E0-EF6705A63200@gmail.com> Message-ID: <8033C0B7-7045-4493-9C6F-AACFD6CC2257@experthuman.com> On 16 Jul 2007, at 12:14, Marcus Crafter wrote: > On 16/07/2007, at 9:11 PM, Tom Stuart wrote: >> On 16 Jul 2007, at 12:02, Marcus Crafter wrote: >>> <% content_for :blah do %> ..... <% end %> >>> It ends up in @content_for_blah, doesn't it? > I thought it did too, but that's a nil reference in the spec > unfortunately. Well, it's an instance variable in the view, not your spec. This was discussed recently on rspec-users (starts at http://rubyforge.org/ pipermail/rspec-users/2007-June/002222.html and continues into July) with the general consensus being that you can write a helper or use instance_eval if you *really* want to access your view's instance variables, but that you're almost always better off specifying this sort of behaviour by expecting the output to show up in the place where it's meant to show up, e.g. have_tag() on the view that does yield :blah in your case, rather than fiddling about with state. Cheers, -Tom From rctucker at u.washington.edu Mon Jul 16 20:43:38 2007 From: rctucker at u.washington.edu (Ryan Tucker) Date: Mon, 16 Jul 2007 17:43:38 -0700 Subject: [rspec-users] Getting past my login system Message-ID: <469C10BA.2080203@u.washington.edu> Thank you in advance for your help. I am relatively new to both Rails and Rspec and I am hoping for some insight from some experienced veterans. Right now I am using Rspec for code that has already been written so that additional functionality can be developed using the BDD method. My problem shows up when I try to spec controllers that are behind the login system. Each page checks for the session[:user], and if they do not exists, requires them to login. Logging in is handled by one controller (the Admin controller) and I want to access a page under another controller (say a Students controller). In my students_controller_spec.rb, I want want to make sure http://test.host/students is successfully displayed, so I wrote something like: it "should be successful" do get :index response.should be_success end The problem is that is keeps redirecting to my login page at http://test.host/login. I tried then setting session[:user] and doing a post to my login page to simulate a login so that I could access the correct page, but that does not seem to work. I tried a number of things, including the following: def do_login @user = User.find(:first, :conditions => ['username = ?' , 'ryan'] ) session[:user] = @user.id post :login, :path => [] end describe StudentsController do it "should be successful" do do_login get :index response.should be_success end end This still results in being redirected to the login page at http://test.host/login when I want to go to http://test.host/students. Also, I realize I am actually doing a call on my test database for this. Part of the reason is that code that called during login checks fields of a user. The other reason is I could not get it to work using stubs, but that might just have been because I was not using them properly. Any insight will be helpful, thanks! -Ryan From rctucker at u.washington.edu Mon Jul 16 22:21:04 2007 From: rctucker at u.washington.edu (Ryan Tucker) Date: Mon, 16 Jul 2007 19:21:04 -0700 Subject: [rspec-users] Getting past my login system In-Reply-To: <469C10BA.2080203@u.washington.edu> References: <469C10BA.2080203@u.washington.edu> Message-ID: <469C2790.6040607@u.washington.edu> Ryan Tucker wrote: > Thank you in advance for your help. I am relatively new to both Rails > and Rspec and I am hoping for some insight from some experienced veterans. > > Right now I am using Rspec for code that has already been written so > that additional functionality can be developed using the BDD method. My > problem shows up when I try to spec controllers that are behind the > login system. Each page checks for the session[:user], and if they do > not exists, requires them to login. Logging in is handled by one > controller (the Admin controller) and I want to access a page under > another controller (say a Students controller). > > In my students_controller_spec.rb, I want want to make sure > http://test.host/students is successfully displayed, so I wrote > something like: > > it "should be successful" do > get :index > response.should be_success > end > > The problem is that is keeps redirecting to my login page at > http://test.host/login. I tried then setting session[:user] and doing a > post to my login page to simulate a login so that I could access the > correct page, but that does not seem to work. I tried a number of > things, including the following: > > def do_login > @user = User.find(:first, :conditions => ['username = ?' , 'ryan'] ) > session[:user] = @user.id > post :login, :path => [] > end > > describe StudentsController do > it "should be successful" do > do_login > get :index > response.should be_success > end > end > > This still results in being redirected to the login page at > http://test.host/login when I want to go to http://test.host/students. > Also, I realize I am actually doing a call on my test database for > this. Part of the reason is that code that called during login checks > fields of a user. The other reason is I could not get it to work using > stubs, but that might just have been because I was not using them properly. > > Any insight will be helpful, thanks! > > -Ryan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Forgot one thing. In trying to do the post, I get the error that "No action responded to login" suggesting that I am not properly accessing the login function in my Admin controller. Thanks again, Ryan From has.sox at gmail.com Mon Jul 16 22:32:37 2007 From: has.sox at gmail.com (Daniel N) Date: Tue, 17 Jul 2007 12:32:37 +1000 Subject: [rspec-users] Getting past my login system In-Reply-To: <469C2790.6040607@u.washington.edu> References: <469C10BA.2080203@u.washington.edu> <469C2790.6040607@u.washington.edu> Message-ID: <2fff50390707161932s2af745b2h4e9ad4dbe2d1ed6f@mail.gmail.com> On 7/17/07, Ryan Tucker wrote: > > Ryan Tucker wrote: > > Thank you in advance for your help. I am relatively new to both Rails > > and Rspec and I am hoping for some insight from some experienced > veterans. > > > > Right now I am using Rspec for code that has already been written so > > that additional functionality can be developed using the BDD method. My > > problem shows up when I try to spec controllers that are behind the > > login system. Each page checks for the session[:user], and if they do > > not exists, requires them to login. Logging in is handled by one > > controller (the Admin controller) and I want to access a page under > > another controller (say a Students controller). > > > > In my students_controller_spec.rb, I want want to make sure > > http://test.host/students is successfully displayed, so I wrote > > something like: > > > > it "should be successful" do > > get :index > > response.should be_success > > end > > > > The problem is that is keeps redirecting to my login page at > > http://test.host/login. I tried then setting session[:user] and doing a > > post to my login page to simulate a login so that I could access the > > correct page, but that does not seem to work. I tried a number of > > things, including the following: > > > > def do_login > > @user = User.find(:first, :conditions => ['username = ?' , 'ryan'] ) > > session[:user] = @user.id > > post :login, :path => [] > > end > > > > describe StudentsController do > > it "should be successful" do > > do_login > > get :index > > response.should be_success > > end > > end > > > > This still results in being redirected to the login page at > > http://test.host/login when I want to go to http://test.host/students. > > Also, I realize I am actually doing a call on my test database for > > this. Part of the reason is that code that called during login checks > > fields of a user. The other reason is I could not get it to work using > > stubs, but that might just have been because I was not using them > properly. > > > > Any insight will be helpful, thanks! > > > > -Ryan > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > Forgot one thing. > > In trying to do the post, I get the error that "No action responded to > login" suggesting that I am not properly accessing the login function in > my Admin controller. > > Thanks again, > Ryan Ryan, the login action is being called on your StudentsController and so it's not found. If it's the presence of the session[:user] that tells the before_filter that your logged in, the you don't need to do the post. In fact you shouldn't post, since as you found out if you post to login, your posting to the login action of the controller your currently in. Bad. Your setting the session and you shouldn't need to do any more. HTH Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070717/eeba2f1f/attachment-0001.html From rctucker at u.washington.edu Mon Jul 16 22:44:08 2007 From: rctucker at u.washington.edu (Ryan Tucker) Date: Mon, 16 Jul 2007 19:44:08 -0700 Subject: [rspec-users] Getting past my login system In-Reply-To: <2fff50390707161932s2af745b2h4e9ad4dbe2d1ed6f@mail.gmail.com> References: <469C10BA.2080203@u.washington.edu> <469C2790.6040607@u.washington.edu> <2fff50390707161932s2af745b2h4e9ad4dbe2d1ed6f@mail.gmail.com> Message-ID: <469C2CF8.3000706@u.washington.edu> Daniel N wrote: > > > On 7/17/07, *Ryan Tucker* > wrote: > > Ryan Tucker wrote: > > Thank you in advance for your help. I am relatively new to both > Rails > > and Rspec and I am hoping for some insight from some experienced > veterans. > > > > Right now I am using Rspec for code that has already been > written so > > that additional functionality can be developed using the BDD > method. My > > problem shows up when I try to spec controllers that are behind the > > login system. Each page checks for the session[:user], and if > they do > > not exists, requires them to login. Logging in is handled by one > > controller (the Admin controller) and I want to access a page under > > another controller (say a Students controller). > > > > In my students_controller_spec.rb, I want want to make sure > > http://test.host/students is successfully displayed, so I wrote > > something like: > > > > it "should be successful" do > > get :index > > response.should be_success > > end > > > > The problem is that is keeps redirecting to my login page at > > http://test.host/login. I tried then setting session[:user] and > doing a > > post to my login page to simulate a login so that I could access the > > correct page, but that does not seem to work. I tried a number of > > things, including the following: > > > > def do_login > > @user = User.find(:first, :conditions => ['username = ?' , > 'ryan'] ) > > session[:user] = @user.id > > post :login, :path => [] > > end > > > > describe StudentsController do > > it "should be successful" do > > do_login > > get :index > > response.should be_success > > end > > end > > > > This still results in being redirected to the login page at > > http://test.host/login when I want to go to > http://test.host/students. > > Also, I realize I am actually doing a call on my test database for > > this. Part of the reason is that code that called during login > checks > > fields of a user. The other reason is I could not get it to > work using > > stubs, but that might just have been because I was not using > them properly. > > > > Any insight will be helpful, thanks! > > > > -Ryan > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > Forgot one thing. > > In trying to do the post, I get the error that "No action > responded to > login" suggesting that I am not properly accessing the login > function in > my Admin controller. > > Thanks again, > Ryan > > > > Ryan, the login action is being called on your StudentsController and > so it's not found. > > If it's the presence of the session[:user] that tells the > before_filter that your logged in, the you don't need to do the post. > In fact you shouldn't post, since as you found out if you post to > login, your posting to the login action of the controller your > currently in. Bad. Your setting the session and you shouldn't need > to do any more. > > HTH > Daniel > > > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Thanks, Daniel. That was my understanding as well, but, for some reason, that has not been enough. The post was an attempt to simulate an actual login by posting to another controller (I know it was bad...) since just setting the session[:user] was not a success. Thank you for your help though. Take care, Ryan From has.sox at gmail.com Mon Jul 16 23:38:47 2007 From: has.sox at gmail.com (Daniel N) Date: Tue, 17 Jul 2007 13:38:47 +1000 Subject: [rspec-users] Getting past my login system In-Reply-To: <469C2CF8.3000706@u.washington.edu> References: <469C10BA.2080203@u.washington.edu> <469C2790.6040607@u.washington.edu> <2fff50390707161932s2af745b2h4e9ad4dbe2d1ed6f@mail.gmail.com> <469C2CF8.3000706@u.washington.edu> Message-ID: <2fff50390707162038h3666c988j8d6a39d9e77065a9@mail.gmail.com> On 7/17/07, Ryan Tucker wrote: > > Daniel N wrote: > > > > > > On 7/17/07, *Ryan Tucker* > > wrote: > > > > Ryan Tucker wrote: > > > Thank you in advance for your help. I am relatively new to both > > Rails > > > and Rspec and I am hoping for some insight from some experienced > > veterans. > > > > > > Right now I am using Rspec for code that has already been > > written so > > > that additional functionality can be developed using the BDD > > method. My > > > problem shows up when I try to spec controllers that are behind > the > > > login system. Each page checks for the session[:user], and if > > they do > > > not exists, requires them to login. Logging in is handled by one > > > controller (the Admin controller) and I want to access a page > under > > > another controller (say a Students controller). > > > > > > In my students_controller_spec.rb, I want want to make sure > > > http://test.host/students is successfully displayed, so I wrote > > > something like: > > > > > > it "should be successful" do > > > get :index > > > response.should be_success > > > end > > > > > > The problem is that is keeps redirecting to my login page at > > > http://test.host/login. I tried then setting session[:user] and > > doing a > > > post to my login page to simulate a login so that I could access > the > > > correct page, but that does not seem to work. I tried a number of > > > things, including the following: > > > > > > def do_login > > > @user = User.find(:first, :conditions => ['username = ?' , > > 'ryan'] ) > > > session[:user] = @user.id > > > post :login, :path => [] > > > end > > > > > > describe StudentsController do > > > it "should be successful" do > > > do_login > > > get :index > > > response.should be_success > > > end > > > end > > > > > > This still results in being redirected to the login page at > > > http://test.host/login when I want to go to > > http://test.host/students. > > > Also, I realize I am actually doing a call on my test database for > > > this. Part of the reason is that code that called during login > > checks > > > fields of a user. The other reason is I could not get it to > > work using > > > stubs, but that might just have been because I was not using > > them properly. > > > > > > Any insight will be helpful, thanks! > > > > > > -Ryan > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > Forgot one thing. > > > > In trying to do the post, I get the error that "No action > > responded to > > login" suggesting that I am not properly accessing the login > > function in > > my Admin controller. > > > > Thanks again, > > Ryan > > > > > > > > Ryan, the login action is being called on your StudentsController and > > so it's not found. > > > > If it's the presence of the session[:user] that tells the > > before_filter that your logged in, the you don't need to do the post. > > In fact you shouldn't post, since as you found out if you post to > > login, your posting to the login action of the controller your > > currently in. Bad. Your setting the session and you shouldn't need > > to do any more. > > > > HTH > > Daniel > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > Thanks, Daniel. > > That was my understanding as well, but, for some reason, that has not > been enough. The post was an attempt to simulate an actual login by > posting to another controller (I know it was bad...) since just setting > the session[:user] was not a success. Thank you for your help though. > > Take care, > Ryan Can you post your before_filter method that checks if your logged in? Also your login method in your Admin controller. Cheers -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070717/f06acd2a/attachment.html From rctucker at u.washington.edu Tue Jul 17 01:28:55 2007 From: rctucker at u.washington.edu (Ryan Tucker) Date: Mon, 16 Jul 2007 22:28:55 -0700 Subject: [rspec-users] Getting past my login system In-Reply-To: <2fff50390707162038h3666c988j8d6a39d9e77065a9@mail.gmail.com> References: <469C10BA.2080203@u.washington.edu> <469C2790.6040607@u.washington.edu> <2fff50390707161932s2af745b2h4e9ad4dbe2d1ed6f@mail.gmail.com> <469C2CF8.3000706@u.washington.edu> <2fff50390707162038h3666c988j8d6a39d9e77065a9@mail.gmail.com> Message-ID: <469C5397.1010405@u.washington.edu> Daniel N wrote: > > > On 7/17/07, *Ryan Tucker* > wrote: > > Daniel N wrote: > > > > > > On 7/17/07, *Ryan Tucker* > > >> wrote: > > > > Ryan Tucker wrote: > > > Thank you in advance for your help. I am relatively new > to both > > Rails > > > and Rspec and I am hoping for some insight from some > experienced > > veterans. > > > > > > Right now I am using Rspec for code that has already been > > written so > > > that additional functionality can be developed using the BDD > > method. My > > > problem shows up when I try to spec controllers that are > behind the > > > login system. Each page checks for the session[:user], and if > > they do > > > not exists, requires them to login. Logging in is handled > by one > > > controller (the Admin controller) and I want to access a > page under > > > another controller (say a Students controller). > > > > > > In my students_controller_spec.rb, I want want to make sure > > > http://test.host/students is successfully displayed, so I > wrote > > > something like: > > > > > > it "should be successful" do > > > get :index > > > response.should be_success > > > end > > > > > > The problem is that is keeps redirecting to my login page at > > > http://test.host/login. I tried then setting > session[:user] and > > doing a > > > post to my login page to simulate a login so that I could > access the > > > correct page, but that does not seem to work. I tried a > number of > > > things, including the following: > > > > > > def do_login > > > @user = User.find(:first, :conditions => ['username = ?' , > > 'ryan'] ) > > > session[:user] = @ user.id > > > post :login, :path => [] > > > end > > > > > > describe StudentsController do > > > it "should be successful" do > > > do_login > > > get :index > > > response.should be_success > > > end > > > end > > > > > > This still results in being redirected to the login page at > > > http://test.host/login when I want to go to > > http://test.host/students. > > > Also, I realize I am actually doing a call on my test > database for > > > this. Part of the reason is that code that called during > login > > checks > > > fields of a user. The other reason is I could not get it to > > work using > > > stubs, but that might just have been because I was not using > > them properly. > > > > > > Any insight will be helpful, thanks! > > > > > > -Ryan > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > Forgot one thing. > > > > In trying to do the post, I get the error that "No action > > responded to > > login" suggesting that I am not properly accessing the login > > function in > > my Admin controller. > > > > Thanks again, > > Ryan > > > > > > > > Ryan, the login action is being called on > your StudentsController and > > so it's not found. > > > > If it's the presence of the session[:user] that tells the > > before_filter that your logged in, the you don't need to do the > post. > > In fact you shouldn't post, since as you found out if you post to > > login, your posting to the login action of the controller your > > currently in. Bad. Your setting the session and you shouldn't need > > to do any more. > > > > HTH > > Daniel > > > > > > > ------------------------------------------------------------------------ > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > Thanks, Daniel. > > That was my understanding as well, but, for some reason, that has not > been enough. The post was an attempt to simulate an actual login by > posting to another controller (I know it was bad...) since just > setting > the session[:user] was not a success. Thank you for your help though. > > Take care, > Ryan > > > Can you post your before_filter method that checks if your logged in? > > Also your login method in your Admin controller. > > Cheers > > > > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users # The Logins are to track a users activity, and this supports # when a user wants to access a page and needs to login first, sending them to it after they login. # Authenticate checks the username and password against the username and password in the # database. def login if request.post? if @current_user = User.authenticate(params[:username], params[:password]) login = Login.create(:remote_ip => request.remote_ip.to_s, :user_agent => request.user_agent.to_s, :http_vars => request.env) @current_user.logins << login session[:user] = @current_user.id uri = session[:original_uri] session[:original_uri] = nil redirect_to uri || home_url return else flash[:error] = "Access denied" end end if session[:user] redirect_to home_url return false end set_page_title "Log In" end # This checks that there is a current user, and checks if they are active # In my case, I am keeping track of whether or not I have disabled # a user. active?() returns true so long as they are have not been deactivated. def check_authentication unless @current_user and @current_user.active? session[:original_uri] = request.request_uri redirect_to log_in_url return false end true end Thank you again for your help. Take care, Ryan From has.sox at gmail.com Tue Jul 17 01:55:46 2007 From: has.sox at gmail.com (Daniel N) Date: Tue, 17 Jul 2007 15:55:46 +1000 Subject: [rspec-users] Getting past my login system In-Reply-To: <469C5397.1010405@u.washington.edu> References: <469C10BA.2080203@u.washington.edu> <469C2790.6040607@u.washington.edu> <2fff50390707161932s2af745b2h4e9ad4dbe2d1ed6f@mail.gmail.com> <469C2CF8.3000706@u.washington.edu> <2fff50390707162038h3666c988j8d6a39d9e77065a9@mail.gmail.com> <469C5397.1010405@u.washington.edu> Message-ID: <2fff50390707162255n43b8da0l11edeca7f82dd015@mail.gmail.com> On 7/17/07, Ryan Tucker wrote: > > Daniel N wrote: > > > > > > On 7/17/07, *Ryan Tucker* > > wrote: > > > > Daniel N wrote: > > > > > > > > > On 7/17/07, *Ryan Tucker* > > > > > >> wrote: > > > > > > Ryan Tucker wrote: > > > > Thank you in advance for your help. I am relatively new > > to both > > > Rails > > > > and Rspec and I am hoping for some insight from some > > experienced > > > veterans. > > > > > > > > Right now I am using Rspec for code that has already been > > > written so > > > > that additional functionality can be developed using the BDD > > > method. My > > > > problem shows up when I try to spec controllers that are > > behind the > > > > login system. Each page checks for the session[:user], and > if > > > they do > > > > not exists, requires them to login. Logging in is handled > > by one > > > > controller (the Admin controller) and I want to access a > > page under > > > > another controller (say a Students controller). > > > > > > > > In my students_controller_spec.rb, I want want to make sure > > > > http://test.host/students is successfully displayed, so I > > wrote > > > > something like: > > > > > > > > it "should be successful" do > > > > get :index > > > > response.should be_success > > > > end > > > > > > > > The problem is that is keeps redirecting to my login page at > > > > http://test.host/login. I tried then setting > > session[:user] and > > > doing a > > > > post to my login page to simulate a login so that I could > > access the > > > > correct page, but that does not seem to work. I tried a > > number of > > > > things, including the following: > > > > > > > > def do_login > > > > @user = User.find(:first, :conditions => ['username = ?' , > > > 'ryan'] ) > > > > session[:user] = @ user.id < > http://user.id> > > > > post :login, :path => [] > > > > end > > > > > > > > describe StudentsController do > > > > it "should be successful" do > > > > do_login > > > > get :index > > > > response.should be_success > > > > end > > > > end > > > > > > > > This still results in being redirected to the login page at > > > > http://test.host/login when I want to go to > > > http://test.host/students. > > > > Also, I realize I am actually doing a call on my test > > database for > > > > this. Part of the reason is that code that called during > > login > > > checks > > > > fields of a user. The other reason is I could not get it to > > > work using > > > > stubs, but that might just have been because I was not using > > > them properly. > > > > > > > > Any insight will be helpful, thanks! > > > > > > > > -Ryan > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > Forgot one thing. > > > > > > In trying to do the post, I get the error that "No action > > > responded to > > > login" suggesting that I am not properly accessing the login > > > function in > > > my Admin controller. > > > > > > Thanks again, > > > Ryan > > > > > > > > > > > > Ryan, the login action is being called on > > your StudentsController and > > > so it's not found. > > > > > > If it's the presence of the session[:user] that tells the > > > before_filter that your logged in, the you don't need to do the > > post. > > > In fact you shouldn't post, since as you found out if you post to > > > login, your posting to the login action of the controller your > > > currently in. Bad. Your setting the session and you shouldn't > need > > > to do any more. > > > > > > HTH > > > Daniel > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > Thanks, Daniel. > > > > That was my understanding as well, but, for some reason, that has > not > > been enough. The post was an attempt to simulate an actual login by > > posting to another controller (I know it was bad...) since just > > setting > > the session[:user] was not a success. Thank you for your help > though. > > > > Take care, > > Ryan > > > > > > Can you post your before_filter method that checks if your logged in? > > > > Also your login method in your Admin controller. > > > > Cheers > > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > # The Logins are to track a users activity, and this supports > # when a user wants to access a page and needs to login first, sending > them to it after they login. > # Authenticate checks the username and password against the username > and password in the > # database. > def login > if request.post? > if @current_user = User.authenticate(params[:username], > params[:password]) > login = Login.create(:remote_ip => request.remote_ip.to_s, > :user_agent => request.user_agent.to_s, :http_vars => request.env) > @current_user.logins << login > session[:user] = @current_user.id > uri = session[:original_uri] > session[:original_uri] = nil > redirect_to uri || home_url > return > else > flash[:error] = "Access denied" > end > end > > if session[:user] > redirect_to home_url > return false > end > set_page_title "Log In" > end > > # This checks that there is a current user, and checks if they are > active > # In my case, I am keeping track of whether or not I have disabled > # a user. active?() returns true so long as they are have not been > deactivated. > def check_authentication > unless @current_user and @current_user.active? > session[:original_uri] = request.request_uri > redirect_to log_in_url > return false > end > true > end > > > Thank you again for your help. I hope I can ;) Take care, > Ryan Ok there's a fair bit of stuff going on in the login code. It doesn't seem that you've included your before_filter that checks to see if a user is logged in in your controller. Do you use a before_filter or some other method in the controller to check for logged in status? Can you post the code that checks if a user is logged in for the controller. Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070717/0d991eee/attachment.html From mailing_lists at railsnewbie.com Tue Jul 17 01:53:59 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 17 Jul 2007 01:53:59 -0400 Subject: [rspec-users] Getting past my login system In-Reply-To: <469C10BA.2080203@u.washington.edu> References: <469C10BA.2080203@u.washington.edu> Message-ID: <974A7923-5F0D-479A-89C6-8A45C19B61A8@railsnewbie.com> You'll probably want to stub the method 'find' on the user class, with a user mock: before :each do @user = mock_model User User.stub!(:find).and_return @user end Then you can do the post on the controller you are spec'ing You should also search the mailing list - this question has been asked numerous times, in various forms. If none of those applies, let us know how it is different. Cheers, Scott Taylor On Jul 16, 2007, at 8:43 PM, Ryan Tucker wrote: > > > Thank you in advance for your help. I am relatively new to both Rails > and Rspec and I am hoping for some insight from some experienced > veterans. > > Right now I am using Rspec for code that has already been written so > that additional functionality can be developed using the BDD > method. My > problem shows up when I try to spec controllers that are behind the > login system. Each page checks for the session[:user], and if they do > not exists, requires them to login. Logging in is handled by one > controller (the Admin controller) and I want to access a page under > another controller (say a Students controller). > > In my students_controller_spec.rb, I want want to make sure > http://test.host/students is successfully displayed, so I wrote > something like: > > it "should be successful" do > get :index > response.should be_success > end > > The problem is that is keeps redirecting to my login page at > http://test.host/login. I tried then setting session[:user] and > doing a > post to my login page to simulate a login so that I could access the > correct page, but that does not seem to work. I tried a number of > things, including the following: > > def do_login > @user = User.find(:first, :conditions => ['username = ?' , 'ryan'] ) > session[:user] = @user.id > post :login, :path => [] > end > > describe StudentsController do > it "should be successful" do > do_login > get :index > response.should be_success > end > end > > This still results in being redirected to the login page at > http://test.host/login when I want to go to http://test.host/students. > Also, I realize I am actually doing a call on my test database for > this. Part of the reason is that code that called during login checks > fields of a user. The other reason is I could not get it to work > using > stubs, but that might just have been because I was not using them > properly. > > Any insight will be helpful, thanks! > > -Ryan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rctucker at u.washington.edu Tue Jul 17 02:26:51 2007 From: rctucker at u.washington.edu (Ryan Tucker) Date: Mon, 16 Jul 2007 23:26:51 -0700 Subject: [rspec-users] Getting past my login system In-Reply-To: <2fff50390707162255n43b8da0l11edeca7f82dd015@mail.gmail.com> References: <469C10BA.2080203@u.washington.edu> <469C2790.6040607@u.washington.edu> <2fff50390707161932s2af745b2h4e9ad4dbe2d1ed6f@mail.gmail.com> <469C2CF8.3000706@u.washington.edu> <2fff50390707162038h3666c988j8d6a39d9e77065a9@mail.gmail.com> <469C5397.1010405@u.washington.edu> <2fff50390707162255n43b8da0l11edeca7f82dd015@mail.gmail.com> Message-ID: <469C612B.8060700@u.washington.edu> Daniel N wrote: > > > On 7/17/07, *Ryan Tucker* > wrote: > > Daniel N wrote: > > > > > > On 7/17/07, *Ryan Tucker* > > >> wrote: > > > > Daniel N wrote: > > > > > > > > > On 7/17/07, *Ryan Tucker* > > > > > > > > >>> wrote: > > > > > > Ryan Tucker wrote: > > > > Thank you in advance for your help. I am relatively new > > to both > > > Rails > > > > and Rspec and I am hoping for some insight from some > > experienced > > > veterans. > > > > > > > > Right now I am using Rspec for code that has already > been > > > written so > > > > that additional functionality can be developed using > the BDD > > > method. My > > > > problem shows up when I try to spec controllers that are > > behind the > > > > login system. Each page checks for the > session[:user], and if > > > they do > > > > not exists, requires them to login. Logging in is > handled > > by one > > > > controller (the Admin controller) and I want to access a > > page under > > > > another controller (say a Students controller). > > > > > > > > In my students_controller_spec.rb, I want want to > make sure > > > > http://test.host/students is successfully displayed, > so I > > wrote > > > > something like: > > > > > > > > it "should be successful" do > > > > get :index > > > > response.should be_success > > > > end > > > > > > > > The problem is that is keeps redirecting to my login > page at > > > > http://test.host/login. I tried then setting > > session[:user] and > > > doing a > > > > post to my login page to simulate a login so that I > could > > access the > > > > correct page, but that does not seem to work. I tried a > > number of > > > > things, including the following: > > > > > > > > def do_login > > > > @user = User.find(:first, :conditions => > ['username = ?' , > > > 'ryan'] ) > > > > session[:user] = @ user.id > > > > > post :login, :path => [] > > > > end > > > > > > > > describe StudentsController do > > > > it "should be successful" do > > > > do_login > > > > get :index > > > > response.should be_success > > > > end > > > > end > > > > > > > > This still results in being redirected to the login > page at > > > > http://test.host/login when I want to go to > > > http://test.host/students. > > > > Also, I realize I am actually doing a call on my test > > database for > > > > this. Part of the reason is that code that called > during > > login > > > checks > > > > fields of a user. The other reason is I could not > get it to > > > work using > > > > stubs, but that might just have been because I was > not using > > > them properly. > > > > > > > > Any insight will be helpful, thanks! > > > > > > > > -Ryan > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > > rspec-users at rubyforge.org > >> > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > Forgot one thing. > > > > > > In trying to do the post, I get the error that "No action > > > responded to > > > login" suggesting that I am not properly accessing the > login > > > function in > > > my Admin controller. > > > > > > Thanks again, > > > Ryan > > > > > > > > > > > > Ryan, the login action is being called on > > your StudentsController and > > > so it's not found. > > > > > > If it's the presence of the session[:user] that tells the > > > before_filter that your logged in, the you don't need to > do the > > post. > > > In fact you shouldn't post, since as you found out if you > post to > > > login, your posting to the login action of the controller your > > > currently in. Bad. Your setting the session and you > shouldn't need > > > to do any more. > > > > > > HTH > > > Daniel > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > Thanks, Daniel. > > > > That was my understanding as well, but, for some reason, > that has not > > been enough. The post was an attempt to simulate an actual > login by > > posting to another controller (I know it was bad...) since just > > setting > > the session[:user] was not a success. Thank you for your > help though. > > > > Take care, > > Ryan > > > > > > Can you post your before_filter method that checks if your > logged in? > > > > Also your login method in your Admin controller. > > > > Cheers > > > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > # The Logins are to track a users activity, and this supports > # when a user wants to access a page and needs to login first, > sending > them to it after they login. > # Authenticate checks the username and password against the username > and password in the > # database. > def login > if request.post? > if @current_user = User.authenticate(params[:username], > params[:password]) > login = Login.create(:remote_ip => request.remote_ip.to_s, > :user_agent => request.user_agent.to_s , :http_vars => request.env) > @current_user.logins << login > session[:user] = @current_user.id > uri = session[:original_uri] > session[:original_uri] = nil > redirect_to uri || home_url > return > else > flash[:error] = "Access denied" > end > end > > if session[:user] > redirect_to home_url > return false > end > set_page_title "Log In" > end > > # This checks that there is a current user, and checks if they > are active > # In my case, I am keeping track of whether or not I have disabled > # a user. active?() returns true so long as they are have not been > deactivated. > def check_authentication > unless @current_user and @current_user.active? > session[:original_uri] = request.request_uri > redirect_to log_in_url > return false > end > true > end > > > Thank you again for your help. > > > I hope I can ;) > > Take care, > Ryan > > > > Ok there's a fair bit of stuff going on in the login code. It doesn't > seem that you've included your before_filter that checks to see if a > user is logged in in your controller. > > Do you use a before_filter or some other method in the controller to > check for logged in status? Can you post the code that checks if a > user is logged in for the controller. > > Cheers > Daniel > > > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users There is also a method that checks whether or not a user has rights to view a particular page as below. def check_authorization unless @current_user.superuser or @current_rights.detect do |right| right.action == action_name && right.controller == self.class.controller_path end flash[:warning] = "You are not authorized to view the page you requested." redirect_to home_url return false end end The @current_user is set in another method set_user(). def set_user unless session[:user].nil? begin @current_user = User.find( session[:user], :include => [ :positions ] ) @user_preferences = @current_user.preferences || {} @current_rights = @current_user.positions.collect do |pos| pos.role.rights.collect end.flatten.uniq rescue # Do nothing end end end So, login() sets the session[:user], set_user() sets the @current_user as well as the rights of the user and check_authentication()/check_authorization() use the @current_user to check whether or not a user is who they say they are (via password verification) or view the page (via rights). My apologies if this has been redundant. I did try reading through other posts before posting my own, but I guess I did not understand how to apply what I read to what I have. I did attempt mocking a user using the method suggested by Scott, but got an error stating: "Mock 'User_1000' received unexpected message :preferences wit (no args)." Perhaps it is because I am not doing that properly either, so I will make sure I understand that a bit better first. Thanks for everyone's help. Take care, Ryan From has.sox at gmail.com Tue Jul 17 02:40:50 2007 From: has.sox at gmail.com (Daniel N) Date: Tue, 17 Jul 2007 16:40:50 +1000 Subject: [rspec-users] Getting past my login system In-Reply-To: <469C612B.8060700@u.washington.edu> References: <469C10BA.2080203@u.washington.edu> <469C2790.6040607@u.washington.edu> <2fff50390707161932s2af745b2h4e9ad4dbe2d1ed6f@mail.gmail.com> <469C2CF8.3000706@u.washington.edu> <2fff50390707162038h3666c988j8d6a39d9e77065a9@mail.gmail.com> <469C5397.1010405@u.washington.edu> <2fff50390707162255n43b8da0l11edeca7f82dd015@mail.gmail.com> <469C612B.8060700@u.washington.edu> Message-ID: <2fff50390707162340h16577b8am64b26e1fe3ba9ef5@mail.gmail.com> On 7/17/07, Ryan Tucker wrote: > > Daniel N wrote: > > > > > > On 7/17/07, *Ryan Tucker* > > wrote: > > > > Daniel N wrote: > > > > > > > > > On 7/17/07, *Ryan Tucker* > > > > > >> wrote: > > > > > > Daniel N wrote: > > > > > > > > > > > > On 7/17/07, *Ryan Tucker* > > > > > > > > > > > > > > > >>> wrote: > > > > > > > > Ryan Tucker wrote: > > > > > Thank you in advance for your help. I am relatively > new > > > to both > > > > Rails > > > > > and Rspec and I am hoping for some insight from some > > > experienced > > > > veterans. > > > > > > > > > > Right now I am using Rspec for code that has already > > been > > > > written so > > > > > that additional functionality can be developed using > > the BDD > > > > method. My > > > > > problem shows up when I try to spec controllers that > are > > > behind the > > > > > login system. Each page checks for the > > session[:user], and if > > > > they do > > > > > not exists, requires them to login. Logging in is > > handled > > > by one > > > > > controller (the Admin controller) and I want to access > a > > > page under > > > > > another controller (say a Students controller). > > > > > > > > > > In my students_controller_spec.rb, I want want to > > make sure > > > > > http://test.host/students is successfully displayed, > > so I > > > wrote > > > > > something like: > > > > > > > > > > it "should be successful" do > > > > > get :index > > > > > response.should be_success > > > > > end > > > > > > > > > > The problem is that is keeps redirecting to my login > > page at > > > > > http://test.host/login. I tried then setting > > > session[:user] and > > > > doing a > > > > > post to my login page to simulate a login so that I > > could > > > access the > > > > > correct page, but that does not seem to work. I tried > a > > > number of > > > > > things, including the following: > > > > > > > > > > def do_login > > > > > @user = User.find(:first, :conditions => > > ['username = ?' , > > > > 'ryan'] ) > > > > > session[:user] = @ user.id > > > > > > > post :login, :path => [] > > > > > end > > > > > > > > > > describe StudentsController do > > > > > it "should be successful" do > > > > > do_login > > > > > get :index > > > > > response.should be_success > > > > > end > > > > > end > > > > > > > > > > This still results in being redirected to the login > > page at > > > > > http://test.host/login when I want to go to > > > > http://test.host/students. > > > > > Also, I realize I am actually doing a call on my test > > > database for > > > > > this. Part of the reason is that code that called > > during > > > login > > > > checks > > > > > fields of a user. The other reason is I could not > > get it to > > > > work using > > > > > stubs, but that might just have been because I was > > not using > > > > them properly. > > > > > > > > > > Any insight will be helpful, thanks! > > > > > > > > > > -Ryan > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > > > > > rspec-users at rubyforge.org > > >>> > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > Forgot one thing. > > > > > > > > In trying to do the post, I get the error that "No > action > > > > responded to > > > > login" suggesting that I am not properly accessing the > > login > > > > function in > > > > my Admin controller. > > > > > > > > Thanks again, > > > > Ryan > > > > > > > > > > > > > > > > Ryan, the login action is being called on > > > your StudentsController and > > > > so it's not found. > > > > > > > > If it's the presence of the session[:user] that tells the > > > > before_filter that your logged in, the you don't need to > > do the > > > post. > > > > In fact you shouldn't post, since as you found out if you > > post to > > > > login, your posting to the login action of the controller > your > > > > currently in. Bad. Your setting the session and you > > shouldn't need > > > > to do any more. > > > > > > > > HTH > > > > Daniel > > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > >> > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > Thanks, Daniel. > > > > > > That was my understanding as well, but, for some reason, > > that has not > > > been enough. The post was an attempt to simulate an actual > > login by > > > posting to another controller (I know it was bad...) since > just > > > setting > > > the session[:user] was not a success. Thank you for your > > help though. > > > > > > Take care, > > > Ryan > > > > > > > > > Can you post your before_filter method that checks if your > > logged in? > > > > > > Also your login method in your Admin controller. > > > > > > Cheers > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > # The Logins are to track a users activity, and this supports > > # when a user wants to access a page and needs to login first, > > sending > > them to it after they login. > > # Authenticate checks the username and password against the > username > > and password in the > > # database. > > def login > > if request.post? > > if @current_user = User.authenticate(params[:username], > > params[:password]) > > login = Login.create(:remote_ip => request.remote_ip.to_s, > > :user_agent => request.user_agent.to_s , :http_vars => request.env) > > @current_user.logins << login > > session[:user] = @current_user.id > > uri = session[:original_uri] > > session[:original_uri] = nil > > redirect_to uri || home_url > > return > > else > > flash[:error] = "Access denied" > > end > > end > > > > if session[:user] > > redirect_to home_url > > return false > > end > > set_page_title "Log In" > > end > > > > # This checks that there is a current user, and checks if they > > are active > > # In my case, I am keeping track of whether or not I have disabled > > # a user. active?() returns true so long as they are have not > been > > deactivated. > > def check_authentication > > unless @current_user and @current_user.active? > > session[:original_uri] = request.request_uri > > redirect_to log_in_url > > return false > > end > > true > > end > > > > > > Thank you again for your help. > > > > > > I hope I can ;) > > > > Take care, > > Ryan > > > > > > > > Ok there's a fair bit of stuff going on in the login code. It doesn't > > seem that you've included your before_filter that checks to see if a > > user is logged in in your controller. > > > > Do you use a before_filter or some other method in the controller to > > check for logged in status? Can you post the code that checks if a > > user is logged in for the controller. > > > > Cheers > > Daniel > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > There is also a method that checks whether or not a user has rights to > view a particular page as below. > > def check_authorization > unless @current_user.superuser or > @current_rights.detect do |right| > right.action == action_name && right.controller == > self.class.controller_path > end > flash[:warning] = "You are not authorized to view the page you > requested." > redirect_to home_url > return false > end > end > > > The @current_user is set in another method set_user(). > > def set_user > unless session[:user].nil? > begin > @current_user = User.find( session[:user], :include => [ > :positions ] ) > @user_preferences = @current_user.preferences || {} > @current_rights = @current_user.positions.collect do |pos| > pos.role.rights.collect > end.flatten.uniq > rescue > # Do nothing > end > end > end > > So, login() sets the session[:user], set_user() sets the @current_user > as well as the rights of the user and > check_authentication()/check_authorization() use the @current_user to > check whether or not a user is who they say they are (via password > verification) or view the page (via rights). > > My apologies if this has been redundant. I did try reading through other > posts before posting my own, but I guess I did not understand how to > apply what I read to what I have. I did attempt mocking a user using the > method suggested by Scott, but got an error stating: > "Mock 'User_1000' received unexpected message :preferences wit (no args)." > > Perhaps it is because I am not doing that properly either, so I will > make sure I understand that a bit better first. > > Thanks for everyone's help. > > Take care, > Ryan Ok, it seems to me that if you assign the @current_user varaible and stub it to return true on the superuser method then everything should be ok. def do_login @user = mock_model( User, :id => 1 ) # Get yourself a user that you can reference in your spec @user.stub!( :superuser ).and_return( true ) # Short circuit the check_authorization method to be a super user by default. You can override this in your individual behaviours. session[:user] = @user.id # should short circuit the set_user method. assigns[ :current_user ] = @user # Set the current user end I think that should do it. You might find you need to stub the @user model a bit depending on what other methods are being called on it. HTH Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070717/53fc9304/attachment-0001.html From rctucker at u.washington.edu Tue Jul 17 02:45:08 2007 From: rctucker at u.washington.edu (Ryan Tucker) Date: Mon, 16 Jul 2007 23:45:08 -0700 Subject: [rspec-users] Getting past my login system In-Reply-To: <2fff50390707162340h16577b8am64b26e1fe3ba9ef5@mail.gmail.com> References: <469C10BA.2080203@u.washington.edu> <469C2790.6040607@u.washington.edu> <2fff50390707161932s2af745b2h4e9ad4dbe2d1ed6f@mail.gmail.com> <469C2CF8.3000706@u.washington.edu> <2fff50390707162038h3666c988j8d6a39d9e77065a9@mail.gmail.com> <469C5397.1010405@u.washington.edu> <2fff50390707162255n43b8da0l11edeca7f82dd015@mail.gmail.com> <469C612B.8060700@u.washington.edu> <2fff50390707162340h16577b8am64b26e1fe3ba9ef5@mail.gmail.com> Message-ID: <469C6574.5050309@u.washington.edu> Daniel N wrote: > > > On 7/17/07, *Ryan Tucker* > wrote: > > Daniel N wrote: > > > > > > On 7/17/07, *Ryan Tucker* > > >> wrote: > > > > Daniel N wrote: > > > > > > > > > On 7/17/07, *Ryan Tucker* > > > > > > > > >>> wrote: > > > > > > Daniel N wrote: > > > > > > > > > > > > On 7/17/07, *Ryan Tucker* < > rctucker at u.washington.edu > > > > > > > > >> > > > > > > > > > > > > >>>> wrote: > > > > > > > > Ryan Tucker wrote: > > > > > Thank you in advance for your help. I am > relatively new > > > to both > > > > Rails > > > > > and Rspec and I am hoping for some insight > from some > > > experienced > > > > veterans. > > > > > > > > > > Right now I am using Rspec for code that has > already > > been > > > > written so > > > > > that additional functionality can be developed > using > > the BDD > > > > method. My > > > > > problem shows up when I try to spec > controllers that are > > > behind the > > > > > login system. Each page checks for the > > session[:user], and if > > > > they do > > > > > not exists, requires them to login. Logging in is > > handled > > > by one > > > > > controller (the Admin controller) and I want > to access a > > > page under > > > > > another controller (say a Students controller). > > > > > > > > > > In my students_controller_spec.rb, I want want to > > make sure > > > > > http://test.host/students is successfully > displayed, > > so I > > > wrote > > > > > something like: > > > > > > > > > > it "should be successful" do > > > > > get :index > > > > > response.should be_success > > > > > end > > > > > > > > > > The problem is that is keeps redirecting to my > login > > page at > > > > > http://test.host/login. I tried then setting > > > session[:user] and > > > > doing a > > > > > post to my login page to simulate a login so > that I > > could > > > access the > > > > > correct page, but that does not seem to > work. I tried a > > > number of > > > > > things, including the following: > > > > > > > > > > def do_login > > > > > @user = User.find(:first, :conditions => > > ['username = ?' , > > > > 'ryan'] ) > > > > > session[:user] = @ user.id > > > > > > > > > post :login, :path => [] > > > > > end > > > > > > > > > > describe StudentsController do > > > > > it "should be successful" do > > > > > do_login > > > > > get :index > > > > > response.should be_success > > > > > end > > > > > end > > > > > > > > > > This still results in being redirected to the > login > > page at > > > > > http://test.host/login when I want to go to > > > > http://test.host/students. > > > > > Also, I realize I am actually doing a call on > my test > > > database for > > > > > this. Part of the reason is that code that called > > during > > > login > > > > checks > > > > > fields of a user. The other reason is I could not > > get it to > > > > work using > > > > > stubs, but that might just have been because I was > > not using > > > > them properly. > > > > > > > > > > Any insight will be helpful, thanks! > > > > > > > > > > -Ryan > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > > > > > >> > > rspec-users at rubyforge.org > > > > > rspec-users at rubyforge.org >>> > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > Forgot one thing. > > > > > > > > In trying to do the post, I get the error that > "No action > > > > responded to > > > > login" suggesting that I am not properly > accessing the > > login > > > > function in > > > > my Admin controller. > > > > > > > > Thanks again, > > > > Ryan > > > > > > > > > > > > > > > > Ryan, the login action is being called on > > > your StudentsController and > > > > so it's not found. > > > > > > > > If it's the presence of the session[:user] that > tells the > > > > before_filter that your logged in, the you don't > need to > > do the > > > post. > > > > In fact you shouldn't post, since as you found out > if you > > post to > > > > login, your posting to the login action of the > controller your > > > > currently in. Bad. Your setting the session and you > > shouldn't need > > > > to do any more. > > > > > > > > HTH > > > > Daniel > > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > > > > >> > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > Thanks, Daniel. > > > > > > That was my understanding as well, but, for some reason, > > that has not > > > been enough. The post was an attempt to simulate an > actual > > login by > > > posting to another controller (I know it was bad...) > since just > > > setting > > > the session[:user] was not a success. Thank you for your > > help though. > > > > > > Take care, > > > Ryan > > > > > > > > > Can you post your before_filter method that checks if your > > logged in? > > > > > > Also your login method in your Admin controller. > > > > > > Cheers > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > # The Logins are to track a users activity, and this > supports > > # when a user wants to access a page and needs to login first, > > sending > > them to it after they login. > > # Authenticate checks the username and password against > the username > > and password in the > > # database. > > def login > > if request.post? > > if @current_user = User.authenticate(params[:username], > > params[:password]) > > login = Login.create(:remote_ip => > request.remote_ip.to_s, > > :user_agent => request.user_agent.to_s , :http_vars => > request.env) > > @current_user.logins << login > > session[:user] = @current_user.id > > uri = session[:original_uri] > > session[:original_uri] = nil > > redirect_to uri || home_url > > return > > else > > flash[:error] = "Access denied" > > end > > end > > > > if session[:user] > > redirect_to home_url > > return false > > end > > set_page_title "Log In" > > end > > > > # This checks that there is a current user, and checks if they > > are active > > # In my case, I am keeping track of whether or not I have > disabled > > # a user. active?() returns true so long as they are have > not been > > deactivated. > > def check_authentication > > unless @current_user and @current_user.active? > > session[:original_uri] = request.request_uri > > redirect_to log_in_url > > return false > > end > > true > > end > > > > > > Thank you again for your help. > > > > > > I hope I can ;) > > > > Take care, > > Ryan > > > > > > > > Ok there's a fair bit of stuff going on in the login code. It > doesn't > > seem that you've included your before_filter that checks to see if a > > user is logged in in your controller. > > > > Do you use a before_filter or some other method in the controller to > > check for logged in status? Can you post the code that checks if a > > user is logged in for the controller. > > > > Cheers > > Daniel > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > There is also a method that checks whether or not a user has > rights to > view a particular page as below. > > def check_authorization > unless @current_user.superuser or > @current_rights.detect do |right| > right.action == action_name && right.controller == > self.class.controller_path > end > flash[:warning] = "You are not authorized to view the page you > requested." > redirect_to home_url > return false > end > end > > > The @current_user is set in another method set_user(). > > def set_user > unless session[:user].nil? > begin > @current_user = User.find( session[:user], :include => [ > :positions ] ) > @user_preferences = @current_user.preferences || {} > @current_rights = @current_user.positions.collect do |pos| > pos.role.rights.collect > end.flatten.uniq > rescue > # Do nothing > end > end > end > > So, login() sets the session[:user], set_user() sets the > @current_user > as well as the rights of the user and > check_authentication()/check_authorization() use the @current_user to > check whether or not a user is who they say they are (via password > verification) or view the page (via rights). > > My apologies if this has been redundant. I did try reading through > other > posts before posting my own, but I guess I did not understand how to > apply what I read to what I have. I did attempt mocking a user > using the > method suggested by Scott, but got an error stating: > "Mock 'User_1000' received unexpected message :preferences wit (no > args)." > > Perhaps it is because I am not doing that properly either, so I will > make sure I understand that a bit better first. > > Thanks for everyone's help. > > Take care, > Ryan > > > > Ok, it seems to me that if you assign the @current_user varaible and > stub it to return true on the superuser method then everything should > be ok. > > def do_login > @user = mock_model( User, :id => 1 ) # Get yourself a user that you > can reference in your spec > @user.stub!( :superuser ).and_return( true ) # Short circuit the > check_authorization method to be a super user by default. You can > override this in your individual behaviours. > > session[:user] = @user.id # should short circuit > the set_user method. > assigns[ :current_user ] = @user # Set the current user > end > > I think that should do it. You might find you need to stub the @user > model a bit depending on what other methods are being called on it. > > HTH > Daniel > > > > > > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Daniel, Thank you so much. I will see if I can make that works. Thanks again for your time and effort! Take care, Ryan From scott at railsnewbie.com Tue Jul 17 04:44:24 2007 From: scott at railsnewbie.com (Scott Taylor) Date: Tue, 17 Jul 2007 04:44:24 -0400 Subject: [rspec-users] Getting past my login system In-Reply-To: <469C612B.8060700@u.washington.edu> References: <469C10BA.2080203@u.washington.edu> <469C2790.6040607@u.washington.edu> <2fff50390707161932s2af745b2h4e9ad4dbe2d1ed6f@mail.gmail.com> <469C2CF8.3000706@u.washington.edu> <2fff50390707162038h3666c988j8d6a39d9e77065a9@mail.gmail.com> <469C5397.1010405@u.washington.edu> <2fff50390707162255n43b8da0l11edeca7f82dd015@mail.gmail.com> <469C612B.8060700@u.washington.edu> Message-ID: <36EDCF67-B928-43B4-ABE2-968D8AA92D94@railsnewbie.com> > My apologies if this has been redundant. I did try reading through > other > posts before posting my own, but I guess I did not understand how to > apply what I read to what I have. I did attempt mocking a user > using the > method suggested by Scott, but got an error stating: > "Mock 'User_1000' received unexpected message :preferences wit (no > args)." I'm glad you finally solved the problem (with the help of Daniel N). I didn't mean to be condescending on the matter of reading the mailing list. Authentication is a hard matter to deal with because of Rails complications. As for mocks - you might want to google Martin Fowlers article about how "Mocks aren't stubs". Every mock that receives an unexpected message (i.e. method call) will raise a MockExpectationError. This is a sign that you should probably be stubbing those methods. Regards, Scott Taylor From rctucker at u.washington.edu Tue Jul 17 14:32:38 2007 From: rctucker at u.washington.edu (Ryan Tucker) Date: Tue, 17 Jul 2007 11:32:38 -0700 Subject: [rspec-users] Getting past my login system In-Reply-To: <36EDCF67-B928-43B4-ABE2-968D8AA92D94@railsnewbie.com> References: <469C10BA.2080203@u.washington.edu> <469C2790.6040607@u.washington.edu> <2fff50390707161932s2af745b2h4e9ad4dbe2d1ed6f@mail.gmail.com> <469C2CF8.3000706@u.washington.edu> <2fff50390707162038h3666c988j8d6a39d9e77065a9@mail.gmail.com> <469C5397.1010405@u.washington.edu> <2fff50390707162255n43b8da0l11edeca7f82dd015@mail.gmail.com> <469C612B.8060700@u.washington.edu> <36EDCF67-B928-43B4-ABE2-968D8AA92D94@railsnewbie.com> Message-ID: <469D0B46.8020605@u.washington.edu> Scott Taylor wrote: >> My apologies if this has been redundant. I did try reading through >> other >> posts before posting my own, but I guess I did not understand how to >> apply what I read to what I have. I did attempt mocking a user >> using the >> method suggested by Scott, but got an error stating: >> "Mock 'User_1000' received unexpected message :preferences wit (no >> args)." >> > > I'm glad you finally solved the problem (with the help of Daniel N). > > I didn't mean to be condescending on the matter of reading the > mailing list. Authentication is a hard matter to deal with because > of Rails complications. > > As for mocks - you might want to google Martin Fowlers article about > how "Mocks aren't stubs". Every mock that receives an unexpected > message (i.e. method call) will raise a MockExpectationError. This > is a sign that you should probably be stubbing those methods. > > Regards, > > Scott Taylor > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Scott, No offense was taken. It turned out it was just my lack of understanding of the mocks and stubs that was getting in the way of all of this. It is all very clear now. Thank you very much, to the both of you, this has been a huge help. Take care, Ryan From psadauskas at absolute-performance.com Wed Jul 18 16:48:18 2007 From: psadauskas at absolute-performance.com (Paul) Date: Wed, 18 Jul 2007 14:48:18 -0600 Subject: [rspec-users] Mocking Rails association collections Message-ID: <469E7C92.4050708@absolute-performance.com> Rails model association collections allow you to do nifty things like: article.comments.find(:all, :conditions => {:created_at > 1.day.ago}) Has anyone found a good way to mock this up? I'm currently doing this: @comment1 = mock_model(Comment) comments = mock(Array) comments.stub!(:find).and_return([@comment1]) @article = mock_model(Article) @article.stub!(:comments).and_return(comments) I don't like this, because of that intermediate 'comments' object, whose only purpose is so that i can stub the chained method. I'd like to do something like this: @comment1 = mock_model(Comment) @article = mock_model(Article, :comments => mock(Array, :find => [@comment1])) But trying this causes an error: "Mock 'Array' received unexpected message :find with (:all, ...)" because you can't inline stubs with ordinary `mock`. I can replace it with `mock_model`, but this feels unclean. Has anyone come across a good 'best-practice' solution to this problem? TIA, Paul Sadauskas From dchelimsky at gmail.com Wed Jul 18 17:30:08 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 18 Jul 2007 17:30:08 -0400 Subject: [rspec-users] Mocking Rails association collections In-Reply-To: <469E7C92.4050708@absolute-performance.com> References: <469E7C92.4050708@absolute-performance.com> Message-ID: <57c63afe0707181430i39e70b5etbb83ec2fe7b8849d@mail.gmail.com> On 7/18/07, Paul wrote: > Rails model association collections allow you to do nifty things like: > > article.comments.find(:all, :conditions => {:created_at > 1.day.ago}) > > Has anyone found a good way to mock this up? I'm currently doing this: > > @comment1 = mock_model(Comment) > comments = mock(Array) > comments.stub!(:find).and_return([@comment1]) > > @article = mock_model(Article) > @article.stub!(:comments).and_return(comments) > > I don't like this, because of that intermediate 'comments' object, whose > only purpose is so that i can stub the chained method. I'd like to do > something like this: > > @comment1 = mock_model(Comment) > > @article = mock_model(Article, :comments => mock(Array, :find => > [@comment1])) > > But trying this causes an error: "Mock 'Array' received unexpected > message :find with (:all, ...)" because you can't inline stubs with > ordinary `mock`. I can replace it with `mock_model`, but this feels unclean. > > Has anyone come across a good 'best-practice' solution to this problem? You can use the stub() method instead of mock() to inline method stubs: @article = mock_model( Article, :comments => stub(Array, :find => [@comment1]) ) The mock() method works differently because it does different stuff w/ the Hash under the covers. > > TIA, > Paul Sadauskas > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From court3nay at gmail.com Wed Jul 18 18:10:11 2007 From: court3nay at gmail.com (court3nay) Date: Wed, 18 Jul 2007 15:10:11 -0700 Subject: [rspec-users] Mocking Rails association collections In-Reply-To: <57c63afe0707181430i39e70b5etbb83ec2fe7b8849d@mail.gmail.com> References: <469E7C92.4050708@absolute-performance.com> <57c63afe0707181430i39e70b5etbb83ec2fe7b8849d@mail.gmail.com> Message-ID: Any chance of some prettier syntax for that? ------- Courtenay On Jul 18, 2007, at 2:30 PM, "David Chelimsky" wrote: > On 7/18/07, Paul wrote: >> Rails model association collections allow you to do nifty things >> like: >> >> article.comments.find(:all, :conditions => {:created_at > >> 1.day.ago}) >> >> Has anyone found a good way to mock this up? I'm currently doing >> this: >> >> @comment1 = mock_model(Comment) >> comments = mock(Array) >> comments.stub!(:find).and_return([@comment1]) >> >> @article = mock_model(Article) >> @article.stub!(:comments).and_return(comments) >> >> I don't like this, because of that intermediate 'comments' object, >> whose >> only purpose is so that i can stub the chained method. I'd like to do >> something like this: >> >> @comment1 = mock_model(Comment) >> >> @article = mock_model(Article, :comments => mock(Array, :find => >> [@comment1])) >> >> But trying this causes an error: "Mock 'Array' received unexpected >> message :find with (:all, ...)" because you can't inline stubs with >> ordinary `mock`. I can replace it with `mock_model`, but this feels >> unclean. >> >> Has anyone come across a good 'best-practice' solution to this >> problem? > > You can use the stub() method instead of mock() to inline method > stubs: > > @article = mock_model( > Article, :comments => stub(Array, :find => [@comment1]) > ) > > The mock() method works differently because it does different stuff w/ > the Hash under the covers. > >> >> TIA, >> Paul Sadauskas >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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 court3nay at gmail.com Wed Jul 18 18:13:17 2007 From: court3nay at gmail.com (court3nay) Date: Wed, 18 Jul 2007 15:13:17 -0700 Subject: [rspec-users] Mocking Rails association collections Message-ID: Any chance of some prettier syntax for that? ------- Courtenay On Jul 18, 2007, at 2:30 PM, "David Chelimsky" wrote: > On 7/18/07, Paul wrote: >> Rails model association collections allow you to do nifty things >> like: >> >> article.comments.find(:all, :conditions => {:created_at > 1.day.ago}) >> >> Has anyone found a good way to mock this up? I'm currently doing >> this: >> >> @comment1 = mock_model(Comment) >> comments = mock(Array) >> comments.stub!(:find).and_return([@comment1]) >> >> @article = mock_model(Article) >> @article.stub!(:comments).and_return(comments) >> >> I don't like this, because of that intermediate 'comments' object, >> whose >> only purpose is so that i can stub the chained method. I'd like to do >> something like this: >> >> @comment1 = mock_model(Comment) >> >> @article = mock_model(Article, :comments => mock(Array, :find => >> [@comment1])) >> >> But trying this causes an error: "Mock 'Array' received unexpected >> message :find with (:all, ...)" because you can't inline stubs with >> ordinary `mock`. I can replace it with `mock_model`, but this feels >> unclean. >> >> Has anyone come across a good 'best-practice' solution to this >> problem? > > You can use the stub() method instead of mock() to inline method > stubs: > > @article = mock_model( > Article, :comments => stub(Array, :find => [@comment1]) > ) > > The mock() method works differently because it does different stuff w/ > the Hash under the covers. > >> >> TIA, >> Paul Sadauskas >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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 psadauskas at absolute-performance.com Wed Jul 18 18:41:45 2007 From: psadauskas at absolute-performance.com (Paul) Date: Wed, 18 Jul 2007 16:41:45 -0600 Subject: [rspec-users] Mocking Rails association collections In-Reply-To: <57c63afe0707181430i39e70b5etbb83ec2fe7b8849d@mail.gmail.com> References: <469E7C92.4050708@absolute-performance.com> <57c63afe0707181430i39e70b5etbb83ec2fe7b8849d@mail.gmail.com> Message-ID: <469E9729.9010602@absolute-performance.com> I eventually ended up using this, from a somewhat-related post to this list a couple months ago: def assoc_mock(stubs = {}) proxy = mock('association_proxy') stubs.each do |method, ret| proxy.stub!(method).and_return(ret) end proxy end Then I can do something like I wanted: @comment = mock_model(Comment) @article = mock_model(Article, :comments => (@comment = assoc_mock(:find => [@comment]))) But this works just like the stub!(Foo, :method => return). I might keep mine, though, its a little more explicit as to what the 'in-between' collection is. Thanks, Paul David Chelimsky wrote: > On 7/18/07, Paul wrote: > >> Rails model association collections allow you to do nifty things like: >> >> article.comments.find(:all, :conditions => {:created_at > 1.day.ago}) >> >> Has anyone found a good way to mock this up? I'm currently doing this: >> >> @comment1 = mock_model(Comment) >> comments = mock(Array) >> comments.stub!(:find).and_return([@comment1]) >> >> @article = mock_model(Article) >> @article.stub!(:comments).and_return(comments) >> >> I don't like this, because of that intermediate 'comments' object, whose >> only purpose is so that i can stub the chained method. I'd like to do >> something like this: >> >> @comment1 = mock_model(Comment) >> >> @article = mock_model(Article, :comments => mock(Array, :find => >> [@comment1])) >> >> But trying this causes an error: "Mock 'Array' received unexpected >> message :find with (:all, ...)" because you can't inline stubs with >> ordinary `mock`. I can replace it with `mock_model`, but this feels unclean. >> >> Has anyone come across a good 'best-practice' solution to this problem? >> > > You can use the stub() method instead of mock() to inline method stubs: > > @article = mock_model( > Article, :comments => stub(Array, :find => [@comment1]) > ) > > The mock() method works differently because it does different stuff w/ > the Hash under the covers. > > >> TIA, >> Paul Sadauskas >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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 raasdnil at gmail.com Wed Jul 18 18:56:15 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 19 Jul 2007 08:56:15 +1000 Subject: [rspec-users] Rails - Mock going out of scope? Message-ID: <57a815bf0707181556h695f2991ra575fe04d1b77195@mail.gmail.com> Hello list, I think I have a rails related RSpec problem with a mock going out of scope on a recursive call to a model. The code is at: http://pastie.textmate.org/79821 if you want to see it highlighted. I have pasted it below as well. Basically, I have an acts_as_nested_set model called "Node", which works fine. I have a function which finds the language name of the node instance. If the language is nil for the node instance being queried, it then recursively calles language_name on it's parent until one of them has the language. Then this gets returned. When I do this with a fixture, it works fine. Ie, a Database call can be made to a language table and I get the language name. In the code attached it has a langauge instance being mocked. I get the same result if I mock Language.should_receive(:find)... It SEEMS like the Mock is going out of scope on the recursive call to parent. The direct spec to the parent to get language name works fine. Any ideas? (the code below is slimmed down to the code needed to run the spec. Regards Mikel CODE:: class Node < ActiveRecord::Base belongs_to :language acts_as_nested_set :scope => :root_id def language_name self.root? ? language.name : parent.language_name end end describe Node, "instance" do fixtures :nodes before(:each) do @language = mock_model(Language, :name => "Japanese") @node = Node.create!(:language => @language) @section1 = Node.create!() @chapter1 = Node.create!() end it "should return it's own language if it is root" do # Passes @language.should_receive(:name).exactly(:once).and_return("Japanese") @node.language_name.should == "Japanese" end it "should return it's parent's language if it is a child" do # Fails (message below) @section1.move_to_child_of(@node) @chapter1.move_to_child_of(@section1) @language.should_receive(:name).exactly(:once).and_return("Japanese") @section1.language_name.should == "Japanese" @language.should_receive(:name).exactly(:once).and_return("Japanese") @chapter1.language_name.should == "Japanese" end end SPEC ERROR:: NoMethodError in 'Node instance should return it's parent's language if it is a child' You have a nil object when you didn't expect it! The error occurred while evaluating nil.name /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in 'language_name' /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in 'language_name' ./spec/models/node_spec.rb:160: script/spec:4: From dchelimsky at gmail.com Wed Jul 18 21:01:38 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 18 Jul 2007 21:01:38 -0400 Subject: [rspec-users] Mocking Rails association collections In-Reply-To: References: <469E7C92.4050708@absolute-performance.com> <57c63afe0707181430i39e70b5etbb83ec2fe7b8849d@mail.gmail.com> Message-ID: <57c63afe0707181801y64253bfeh6f99683419ad706a@mail.gmail.com> On 7/18/07, court3nay wrote: > Any chance of some prettier syntax for that? There's always a chance. What do you propose? > > ------- > Courtenay > > On Jul 18, 2007, at 2:30 PM, "David Chelimsky" > wrote: > > > On 7/18/07, Paul wrote: > >> Rails model association collections allow you to do nifty things > >> like: > >> > >> article.comments.find(:all, :conditions => {:created_at > > >> 1.day.ago}) > >> > >> Has anyone found a good way to mock this up? I'm currently doing > >> this: > >> > >> @comment1 = mock_model(Comment) > >> comments = mock(Array) > >> comments.stub!(:find).and_return([@comment1]) > >> > >> @article = mock_model(Article) > >> @article.stub!(:comments).and_return(comments) > >> > >> I don't like this, because of that intermediate 'comments' object, > >> whose > >> only purpose is so that i can stub the chained method. I'd like to do > >> something like this: > >> > >> @comment1 = mock_model(Comment) > >> > >> @article = mock_model(Article, :comments => mock(Array, :find => > >> [@comment1])) > >> > >> But trying this causes an error: "Mock 'Array' received unexpected > >> message :find with (:all, ...)" because you can't inline stubs with > >> ordinary `mock`. I can replace it with `mock_model`, but this feels > >> unclean. > >> > >> Has anyone come across a good 'best-practice' solution to this > >> problem? > > > > You can use the stub() method instead of mock() to inline method > > stubs: > > > > @article = mock_model( > > Article, :comments => stub(Array, :find => [@comment1]) > > ) > > > > The mock() method works differently because it does different stuff w/ > > the Hash under the covers. > > > >> > >> TIA, > >> Paul Sadauskas > >> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From esad.talks at esse.at Wed Jul 18 21:51:42 2007 From: esad.talks at esse.at (Esad Hajdarevic) Date: Thu, 19 Jul 2007 03:51:42 +0200 Subject: [rspec-users] stopping on first failure Message-ID: <469EC3AE.6060105@esse.at> Hi! Is there an option that I could provide to the spec runner that would make it stop after it encounters the first spec that fails? Esad From dchelimsky at gmail.com Wed Jul 18 22:23:29 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 18 Jul 2007 22:23:29 -0400 Subject: [rspec-users] stopping on first failure In-Reply-To: <469EC3AE.6060105@esse.at> References: <469EC3AE.6060105@esse.at> Message-ID: <57c63afe0707181923l4f9e7162j8092f39a341a36ac@mail.gmail.com> On 7/18/07, Esad Hajdarevic wrote: > Hi! > > Is there an option that I could provide to the spec runner that would > make it stop after it > encounters the first spec that fails? Not yet. Please submit an RFE if you'd like to see it: http://rubyforge.org/tracker/?group_id=797 > > Esad > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Jul 18 23:24:59 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 18 Jul 2007 23:24:59 -0400 Subject: [rspec-users] Rails - Mock going out of scope? In-Reply-To: <57a815bf0707181556h695f2991ra575fe04d1b77195@mail.gmail.com> References: <57a815bf0707181556h695f2991ra575fe04d1b77195@mail.gmail.com> Message-ID: <57c63afe0707182024k51a19e99vc29da81e71499129@mail.gmail.com> On 7/18/07, Mikel Lindsaar wrote: > Hello list, > > I think I have a rails related RSpec problem with a mock going out of > scope on a recursive call to a model. > > The code is at: http://pastie.textmate.org/79821 if you want to see it > highlighted. I have pasted it below as well. > > Basically, I have an acts_as_nested_set model called "Node", which > works fine. I have a function which finds the language name of the > node instance. If the language is nil for the node instance being > queried, it then recursively calles language_name on it's parent until > one of them has the language. Then this gets returned. > > When I do this with a fixture, it works fine. Ie, a Database call can > be made to a language table and I get the language name. > > In the code attached it has a langauge instance being mocked. I get > the same result if I mock Language.should_receive(:find)... > > It SEEMS like the Mock is going out of scope on the recursive call to > parent. The direct spec to the parent to get language name works > fine. > > Any ideas? (the code below is slimmed down to the code needed to run the spec. > > Regards > > Mikel > > CODE:: > > class Node < ActiveRecord::Base > > belongs_to :language > acts_as_nested_set :scope => :root_id > > def language_name > self.root? ? language.name : parent.language_name > end > end > > describe Node, "instance" do > > fixtures :nodes > > before(:each) do > @language = mock_model(Language, :name => "Japanese") > @node = Node.create!(:language => @language) > @section1 = Node.create!() > @chapter1 = Node.create!() > end > > it "should return it's own language if it is root" do # Passes > @language.should_receive(:name).exactly(:once).and_return("Japanese") > @node.language_name.should == "Japanese" > end > > it "should return it's parent's language if it is a child" do # > Fails (message below) > @section1.move_to_child_of(@node) > @chapter1.move_to_child_of(@section1) > @language.should_receive(:name).exactly(:once).and_return("Japanese") > @section1.language_name.should == "Japanese" > @language.should_receive(:name).exactly(:once).and_return("Japanese") > @chapter1.language_name.should == "Japanese" > end > end It's generally not recommended that you set expectations, invoke them and then set them again. I'm not sure, but that may be the problem here. Try this: it "should return it's parent's language if it is a child" do # Fails (message below) @section1.move_to_child_of(@node) @chapter1.move_to_child_of(@section1) @language.should_receive(:name).exactly(:twice).and_return("Japanese") @section1.language_name.should == "Japanese" @chapter1.language_name.should == "Japanese" end Does that work? > > SPEC ERROR:: > > NoMethodError in 'Node instance should return it's parent's language > if it is a child' > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.name > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > 'language_name' > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > 'language_name' > ./spec/models/node_spec.rb:160: > script/spec:4: > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Jul 18 23:35:45 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 18 Jul 2007 23:35:45 -0400 Subject: [rspec-users] need help getting a word right Message-ID: <57c63afe0707182035t6b4e49f8u83b99e8da0b5e479@mail.gmail.com> Hey all, I see examples showing up that look like this: describe Thing do before(:each) do @thing = Thing.new end it do @thing.should be_something end end This will produce output like this: Thing - should be something But "it do" is driving me mad :( We need a better word. Of course, 'specify' has not been completely removed, so you can still do this: describe Thing do before(:each) { @thing = Thing.new } specify { @thing.should be_something } end Consise? Yes. But I'm not psyched about 'specify' either. There IS a perfect word for this situation. What is it? Suggestions? Thanks, David From has.sox at gmail.com Wed Jul 18 23:42:41 2007 From: has.sox at gmail.com (Daniel N) Date: Thu, 19 Jul 2007 13:42:41 +1000 Subject: [rspec-users] need help getting a word right In-Reply-To: <57c63afe0707182035t6b4e49f8u83b99e8da0b5e479@mail.gmail.com> References: <57c63afe0707182035t6b4e49f8u83b99e8da0b5e479@mail.gmail.com> Message-ID: <2fff50390707182042q5d34ca75kc4ab67b75a41d4fc@mail.gmail.com> On 7/19/07, David Chelimsky wrote: > > Hey all, > > I see examples showing up that look like this: > > describe Thing do > before(:each) do > @thing = Thing.new > end > > it do > @thing.should be_something > end > end > > This will produce output like this: > > Thing > - should be something > > But "it do" is driving me mad :( > > We need a better word. Of course, 'specify' has not been completely > removed, so you can still do this: > > describe Thing do > before(:each) { @thing = Thing.new } > specify { @thing.should be_something } > end > > Consise? Yes. But I'm not psyched about 'specify' either. There IS a > perfect word for this situation. What is it? Suggestions? > > Thanks, > David What about conform describe Thing do before(:each) { @thing = Thing.new } conform { @thing.should be_something } end -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070719/433a2be1/attachment.html From philodespotos at gmail.com Wed Jul 18 23:43:00 2007 From: philodespotos at gmail.com (Kyle Hargraves) Date: Wed, 18 Jul 2007 22:43:00 -0500 Subject: [rspec-users] need help getting a word right In-Reply-To: <57c63afe0707182035t6b4e49f8u83b99e8da0b5e479@mail.gmail.com> References: <57c63afe0707182035t6b4e49f8u83b99e8da0b5e479@mail.gmail.com> Message-ID: <469EDDC4.3060309@gmail.com> David Chelimsky wrote: > Consise? Yes. But I'm not psyched about 'specify' either. There IS a > perfect word for this situation. What is it? Suggestions? Personally, I disagree. For examples like that, I think 'specify' is a pretty ideal word. It reads exactly as I want it to. Depending on what I'm describing, I tend to use either 'it' or 'specify' exclusively, but I definitely do mix them throughout my projects. (I always use 'describe,' though.) The only problem I ever have is when the specify block needs to be larger than a line, and 'specify do' reads poorly -- which may be what you have against it, too. So far, I've just tried to avoid that... Of course, I say that now, and then someone will have a great suggestion for a word that makes tons more sense. Kyle From robert.feldt at bth.se Wed Jul 18 23:44:05 2007 From: robert.feldt at bth.se (Robert Feldt) Date: Thu, 19 Jul 2007 05:44:05 +0200 Subject: [rspec-users] need help getting a word right In-Reply-To: <57c63afe0707182035t6b4e49f8u83b99e8da0b5e479@mail.gmail.com> References: <57c63afe0707182035t6b4e49f8u83b99e8da0b5e479@mail.gmail.com> Message-ID: <87a13e220707182044n148aeb07tf9bfee7be365d22@mail.gmail.com> On 7/19/07, David Chelimsky wrote: > > Hey all, > > I see examples showing up that look like this: > > describe Thing do > before(:each) do > @thing = Thing.new > end > > it do > @thing.should be_something > end > end > > This will produce output like this: > > Thing > - should be something > > But "it do" is driving me mad :( > > We need a better word. Of course, 'specify' has not been completely > removed, so you can still do this: > > describe Thing do > before(:each) { @thing = Thing.new } > specify { @thing.should be_something } > end > > Consise? Yes. But I'm not psyched about 'specify' either. There IS a > perfect word for this situation. What is it? Suggestions? I like "should" or "spec" the best. While I'm at it why not "given" instead of "describe"? Cheers, Robert Feldt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070719/b3a44391/attachment.html From raasdnil at gmail.com Wed Jul 18 23:51:38 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 19 Jul 2007 13:51:38 +1000 Subject: [rspec-users] Rails - Mock going out of scope? In-Reply-To: <57c63afe0707182024k51a19e99vc29da81e71499129@mail.gmail.com> References: <57a815bf0707181556h695f2991ra575fe04d1b77195@mail.gmail.com> <57c63afe0707182024k51a19e99vc29da81e71499129@mail.gmail.com> Message-ID: <57a815bf0707182051k2058fceakb1676d929641c67@mail.gmail.com> Heya David, Thanks for the reply. No, that didn't work, get the same error: NoMethodError in 'Node instance should return it's parent's language if it is a child' You have a nil object when you didn't expect it! The error occurred while evaluating nil.name If I include the fixture :languages, then replace out @language = mock_model... with @language = languages(:one) it all works dandy. But I'm trying to ween myself off fixtures :) Regards Mikel On 7/19/07, David Chelimsky wrote: > On 7/18/07, Mikel Lindsaar wrote: > > Hello list, > > > > I think I have a rails related RSpec problem with a mock going out of > > scope on a recursive call to a model. > > > > The code is at: http://pastie.textmate.org/79821 if you want to see it > > highlighted. I have pasted it below as well. > > > > Basically, I have an acts_as_nested_set model called "Node", which > > works fine. I have a function which finds the language name of the > > node instance. If the language is nil for the node instance being > > queried, it then recursively calles language_name on it's parent until > > one of them has the language. Then this gets returned. > > > > When I do this with a fixture, it works fine. Ie, a Database call can > > be made to a language table and I get the language name. > > > > In the code attached it has a langauge instance being mocked. I get > > the same result if I mock Language.should_receive(:find)... > > > > It SEEMS like the Mock is going out of scope on the recursive call to > > parent. The direct spec to the parent to get language name works > > fine. > > > > Any ideas? (the code below is slimmed down to the code needed to run the spec. > > > > Regards > > > > Mikel > > > > CODE:: > > > > class Node < ActiveRecord::Base > > > > belongs_to :language > > acts_as_nested_set :scope => :root_id > > > > def language_name > > self.root? ? language.name : parent.language_name > > end > > end > > > > describe Node, "instance" do > > > > fixtures :nodes > > > > before(:each) do > > @language = mock_model(Language, :name => "Japanese") > > @node = Node.create!(:language => @language) > > @section1 = Node.create!() > > @chapter1 = Node.create!() > > end > > > > it "should return it's own language if it is root" do # Passes > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > @node.language_name.should == "Japanese" > > end > > > > it "should return it's parent's language if it is a child" do # > > Fails (message below) > > @section1.move_to_child_of(@node) > > @chapter1.move_to_child_of(@section1) > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > @section1.language_name.should == "Japanese" > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > @chapter1.language_name.should == "Japanese" > > end > > end > > It's generally not recommended that you set expectations, invoke them > and then set them again. I'm not sure, but that may be the problem > here. Try this: > > it "should return it's parent's language if it is a child" do # > Fails (message below) > @section1.move_to_child_of(@node) > @chapter1.move_to_child_of(@section1) > @language.should_receive(:name).exactly(:twice).and_return("Japanese") > @section1.language_name.should == "Japanese" > @chapter1.language_name.should == "Japanese" > end > > Does that work? > > > > > SPEC ERROR:: > > > > NoMethodError in 'Node instance should return it's parent's language > > if it is a child' > > You have a nil object when you didn't expect it! > > The error occurred while evaluating nil.name > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > 'language_name' > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > 'language_name' > > ./spec/models/node_spec.rb:160: > > script/spec:4: > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Jul 18 23:54:11 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 18 Jul 2007 23:54:11 -0400 Subject: [rspec-users] Rails - Mock going out of scope? In-Reply-To: <57a815bf0707182051k2058fceakb1676d929641c67@mail.gmail.com> References: <57a815bf0707181556h695f2991ra575fe04d1b77195@mail.gmail.com> <57c63afe0707182024k51a19e99vc29da81e71499129@mail.gmail.com> <57a815bf0707182051k2058fceakb1676d929641c67@mail.gmail.com> Message-ID: <57c63afe0707182054h3e19c8e7n1cdb72a59a320430@mail.gmail.com> Would you mind posting the migrations? On 7/18/07, Mikel Lindsaar wrote: > Heya David, > > Thanks for the reply. > > No, that didn't work, get the same error: > > NoMethodError in 'Node instance should return it's parent's language > if it is a child' > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.name > > > If I include the fixture :languages, then replace out @language = > mock_model... with > > @language = languages(:one) > > it all works dandy. But I'm trying to ween myself off fixtures :) > > Regards > > Mikel > > > > On 7/19/07, David Chelimsky wrote: > > On 7/18/07, Mikel Lindsaar wrote: > > > Hello list, > > > > > > I think I have a rails related RSpec problem with a mock going out of > > > scope on a recursive call to a model. > > > > > > The code is at: http://pastie.textmate.org/79821 if you want to see it > > > highlighted. I have pasted it below as well. > > > > > > Basically, I have an acts_as_nested_set model called "Node", which > > > works fine. I have a function which finds the language name of the > > > node instance. If the language is nil for the node instance being > > > queried, it then recursively calles language_name on it's parent until > > > one of them has the language. Then this gets returned. > > > > > > When I do this with a fixture, it works fine. Ie, a Database call can > > > be made to a language table and I get the language name. > > > > > > In the code attached it has a langauge instance being mocked. I get > > > the same result if I mock Language.should_receive(:find)... > > > > > > It SEEMS like the Mock is going out of scope on the recursive call to > > > parent. The direct spec to the parent to get language name works > > > fine. > > > > > > Any ideas? (the code below is slimmed down to the code needed to run the spec. > > > > > > Regards > > > > > > Mikel > > > > > > CODE:: > > > > > > class Node < ActiveRecord::Base > > > > > > belongs_to :language > > > acts_as_nested_set :scope => :root_id > > > > > > def language_name > > > self.root? ? language.name : parent.language_name > > > end > > > end > > > > > > describe Node, "instance" do > > > > > > fixtures :nodes > > > > > > before(:each) do > > > @language = mock_model(Language, :name => "Japanese") > > > @node = Node.create!(:language => @language) > > > @section1 = Node.create!() > > > @chapter1 = Node.create!() > > > end > > > > > > it "should return it's own language if it is root" do # Passes > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > @node.language_name.should == "Japanese" > > > end > > > > > > it "should return it's parent's language if it is a child" do # > > > Fails (message below) > > > @section1.move_to_child_of(@node) > > > @chapter1.move_to_child_of(@section1) > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > @section1.language_name.should == "Japanese" > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > @chapter1.language_name.should == "Japanese" > > > end > > > end > > > > It's generally not recommended that you set expectations, invoke them > > and then set them again. I'm not sure, but that may be the problem > > here. Try this: > > > > it "should return it's parent's language if it is a child" do # > > Fails (message below) > > @section1.move_to_child_of(@node) > > @chapter1.move_to_child_of(@section1) > > @language.should_receive(:name).exactly(:twice).and_return("Japanese") > > @section1.language_name.should == "Japanese" > > @chapter1.language_name.should == "Japanese" > > end > > > > Does that work? > > > > > > > > SPEC ERROR:: > > > > > > NoMethodError in 'Node instance should return it's parent's language > > > if it is a child' > > > You have a nil object when you didn't expect it! > > > The error occurred while evaluating nil.name > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > 'language_name' > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > 'language_name' > > > ./spec/models/node_spec.rb:160: > > > script/spec:4: > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Jul 19 00:02:21 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 19 Jul 2007 00:02:21 -0400 Subject: [rspec-users] Rails - Mock going out of scope? In-Reply-To: <57c63afe0707182054h3e19c8e7n1cdb72a59a320430@mail.gmail.com> References: <57a815bf0707181556h695f2991ra575fe04d1b77195@mail.gmail.com> <57c63afe0707182024k51a19e99vc29da81e71499129@mail.gmail.com> <57a815bf0707182051k2058fceakb1676d929641c67@mail.gmail.com> <57c63afe0707182054h3e19c8e7n1cdb72a59a320430@mail.gmail.com> Message-ID: <57c63afe0707182102ra36c57q9739f18f80d6a8d@mail.gmail.com> You might also want to try this w/ another mock framework like mocha or flexmock (or rr if you're on edge). If you do, please report the results here. Thx On 7/18/07, David Chelimsky wrote: > Would you mind posting the migrations? > > On 7/18/07, Mikel Lindsaar wrote: > > Heya David, > > > > Thanks for the reply. > > > > No, that didn't work, get the same error: > > > > NoMethodError in 'Node instance should return it's parent's language > > if it is a child' > > You have a nil object when you didn't expect it! > > The error occurred while evaluating nil.name > > > > > > If I include the fixture :languages, then replace out @language = > > mock_model... with > > > > @language = languages(:one) > > > > it all works dandy. But I'm trying to ween myself off fixtures :) > > > > Regards > > > > Mikel > > > > > > > > On 7/19/07, David Chelimsky wrote: > > > On 7/18/07, Mikel Lindsaar wrote: > > > > Hello list, > > > > > > > > I think I have a rails related RSpec problem with a mock going out of > > > > scope on a recursive call to a model. > > > > > > > > The code is at: http://pastie.textmate.org/79821 if you want to see it > > > > highlighted. I have pasted it below as well. > > > > > > > > Basically, I have an acts_as_nested_set model called "Node", which > > > > works fine. I have a function which finds the language name of the > > > > node instance. If the language is nil for the node instance being > > > > queried, it then recursively calles language_name on it's parent until > > > > one of them has the language. Then this gets returned. > > > > > > > > When I do this with a fixture, it works fine. Ie, a Database call can > > > > be made to a language table and I get the language name. > > > > > > > > In the code attached it has a langauge instance being mocked. I get > > > > the same result if I mock Language.should_receive(:find)... > > > > > > > > It SEEMS like the Mock is going out of scope on the recursive call to > > > > parent. The direct spec to the parent to get language name works > > > > fine. > > > > > > > > Any ideas? (the code below is slimmed down to the code needed to run the spec. > > > > > > > > Regards > > > > > > > > Mikel > > > > > > > > CODE:: > > > > > > > > class Node < ActiveRecord::Base > > > > > > > > belongs_to :language > > > > acts_as_nested_set :scope => :root_id > > > > > > > > def language_name > > > > self.root? ? language.name : parent.language_name > > > > end > > > > end > > > > > > > > describe Node, "instance" do > > > > > > > > fixtures :nodes > > > > > > > > before(:each) do > > > > @language = mock_model(Language, :name => "Japanese") > > > > @node = Node.create!(:language => @language) > > > > @section1 = Node.create!() > > > > @chapter1 = Node.create!() > > > > end > > > > > > > > it "should return it's own language if it is root" do # Passes > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > @node.language_name.should == "Japanese" > > > > end > > > > > > > > it "should return it's parent's language if it is a child" do # > > > > Fails (message below) > > > > @section1.move_to_child_of(@node) > > > > @chapter1.move_to_child_of(@section1) > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > @section1.language_name.should == "Japanese" > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > @chapter1.language_name.should == "Japanese" > > > > end > > > > end > > > > > > It's generally not recommended that you set expectations, invoke them > > > and then set them again. I'm not sure, but that may be the problem > > > here. Try this: > > > > > > it "should return it's parent's language if it is a child" do # > > > Fails (message below) > > > @section1.move_to_child_of(@node) > > > @chapter1.move_to_child_of(@section1) > > > @language.should_receive(:name).exactly(:twice).and_return("Japanese") > > > @section1.language_name.should == "Japanese" > > > @chapter1.language_name.should == "Japanese" > > > end > > > > > > Does that work? > > > > > > > > > > > SPEC ERROR:: > > > > > > > > NoMethodError in 'Node instance should return it's parent's language > > > > if it is a child' > > > > You have a nil object when you didn't expect it! > > > > The error occurred while evaluating nil.name > > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > > 'language_name' > > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > > 'language_name' > > > > ./spec/models/node_spec.rb:160: > > > > script/spec:4: > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From raasdnil at gmail.com Thu Jul 19 00:23:50 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 19 Jul 2007 14:23:50 +1000 Subject: [rspec-users] Rails - Mock going out of scope? In-Reply-To: <57c63afe0707182054h3e19c8e7n1cdb72a59a320430@mail.gmail.com> References: <57a815bf0707181556h695f2991ra575fe04d1b77195@mail.gmail.com> <57c63afe0707182024k51a19e99vc29da81e71499129@mail.gmail.com> <57a815bf0707182051k2058fceakb1676d929641c67@mail.gmail.com> <57c63afe0707182054h3e19c8e7n1cdb72a59a320430@mail.gmail.com> Message-ID: <57a815bf0707182123h59e99075s424f367cdceb5660@mail.gmail.com> Here are the migrations: class CreateNodes < ActiveRecord::Migration def self.up create_table ("nodes", :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8', :force => true) do |t| t.column "title", :string t.column "language_id", :integer t.column "parent_id", :integer t.column "lft", :integer t.column "rgt", :integer t.column "original_node_id", :integer t.column "owner_id", :integer t.column "owner_type", :string t.column "root_id", :integer end end def self.down drop_table "nodes" end end class CreateLanguagesTable < ActiveRecord::Migration def self.up create_table (:languages, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8', :force => true) do |t| t.column :name, :string end end def self.down drop_table :languages end end The Nodes Model also has a self referrential association, but I don't think that would be causing any problems. class Node < ActiveRecord::Base belongs_to :language belongs_to :owner, :polymorphic => true # Self referrential association, nodes have many original nodes - keeps track # of all original => translation associations belongs_to :original_node, :class_name => "Node", :foreign_key => "original_node_id" has_many :translated_nodes, :class_name => "Node", :foreign_key => "original_node_id" acts_as_nested_set :scope => :root_id # + code from the original pastie end There are some other associations, but they are all belongs_to or has_many, so I haven't bothered to put all the tables in here and have removed the appropriate foreign keys from the nodes table. Regards Mikel On 7/19/07, David Chelimsky wrote: > Would you mind posting the migrations? > > On 7/18/07, Mikel Lindsaar wrote: > > Heya David, > > > > Thanks for the reply. > > > > No, that didn't work, get the same error: > > > > NoMethodError in 'Node instance should return it's parent's language > > if it is a child' > > You have a nil object when you didn't expect it! > > The error occurred while evaluating nil.name > > > > > > If I include the fixture :languages, then replace out @language = > > mock_model... with > > > > @language = languages(:one) > > > > it all works dandy. But I'm trying to ween myself off fixtures :) > > > > Regards > > > > Mikel > > > > > > > > On 7/19/07, David Chelimsky wrote: > > > On 7/18/07, Mikel Lindsaar wrote: > > > > Hello list, > > > > > > > > I think I have a rails related RSpec problem with a mock going out of > > > > scope on a recursive call to a model. > > > > > > > > The code is at: http://pastie.textmate.org/79821 if you want to see it > > > > highlighted. I have pasted it below as well. > > > > > > > > Basically, I have an acts_as_nested_set model called "Node", which > > > > works fine. I have a function which finds the language name of the > > > > node instance. If the language is nil for the node instance being > > > > queried, it then recursively calles language_name on it's parent until > > > > one of them has the language. Then this gets returned. > > > > > > > > When I do this with a fixture, it works fine. Ie, a Database call can > > > > be made to a language table and I get the language name. > > > > > > > > In the code attached it has a langauge instance being mocked. I get > > > > the same result if I mock Language.should_receive(:find)... > > > > > > > > It SEEMS like the Mock is going out of scope on the recursive call to > > > > parent. The direct spec to the parent to get language name works > > > > fine. > > > > > > > > Any ideas? (the code below is slimmed down to the code needed to run the spec. > > > > > > > > Regards > > > > > > > > Mikel > > > > > > > > CODE:: > > > > > > > > class Node < ActiveRecord::Base > > > > > > > > belongs_to :language > > > > acts_as_nested_set :scope => :root_id > > > > > > > > def language_name > > > > self.root? ? language.name : parent.language_name > > > > end > > > > end > > > > > > > > describe Node, "instance" do > > > > > > > > fixtures :nodes > > > > > > > > before(:each) do > > > > @language = mock_model(Language, :name => "Japanese") > > > > @node = Node.create!(:language => @language) > > > > @section1 = Node.create!() > > > > @chapter1 = Node.create!() > > > > end > > > > > > > > it "should return it's own language if it is root" do # Passes > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > @node.language_name.should == "Japanese" > > > > end > > > > > > > > it "should return it's parent's language if it is a child" do # > > > > Fails (message below) > > > > @section1.move_to_child_of(@node) > > > > @chapter1.move_to_child_of(@section1) > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > @section1.language_name.should == "Japanese" > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > @chapter1.language_name.should == "Japanese" > > > > end > > > > end > > > > > > It's generally not recommended that you set expectations, invoke them > > > and then set them again. I'm not sure, but that may be the problem > > > here. Try this: > > > > > > it "should return it's parent's language if it is a child" do # > > > Fails (message below) > > > @section1.move_to_child_of(@node) > > > @chapter1.move_to_child_of(@section1) > > > @language.should_receive(:name).exactly(:twice).and_return("Japanese") > > > @section1.language_name.should == "Japanese" > > > @chapter1.language_name.should == "Japanese" > > > end > > > > > > Does that work? > > > > > > > > > > > SPEC ERROR:: > > > > > > > > NoMethodError in 'Node instance should return it's parent's language > > > > if it is a child' > > > > You have a nil object when you didn't expect it! > > > > The error occurred while evaluating nil.name > > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > > 'language_name' > > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > > 'language_name' > > > > ./spec/models/node_spec.rb:160: > > > > script/spec:4: > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Jul 19 00:34:42 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 19 Jul 2007 00:34:42 -0400 Subject: [rspec-users] Rails - Mock going out of scope? In-Reply-To: <57a815bf0707182123h59e99075s424f367cdceb5660@mail.gmail.com> References: <57a815bf0707181556h695f2991ra575fe04d1b77195@mail.gmail.com> <57c63afe0707182024k51a19e99vc29da81e71499129@mail.gmail.com> <57a815bf0707182051k2058fceakb1676d929641c67@mail.gmail.com> <57c63afe0707182054h3e19c8e7n1cdb72a59a320430@mail.gmail.com> <57a815bf0707182123h59e99075s424f367cdceb5660@mail.gmail.com> Message-ID: <57c63afe0707182134w38ae3e60vaed10692be285c67@mail.gmail.com> Here are the errors I'm getting now: 1) NoMethodError in 'Node instance should return it's parent's language if it is a child' undefined method `move_to_child_of' for # ./spec/models/node_spec.rb:20: 2) NameError in 'Node instance should return it's own language if it is root' undefined local variable or method `parent' for # /Users/david/projects/ruby/nodes/config/../app/models/node.rb:7:in `language_name' ./spec/models/node_spec.rb:16: What version of rails are you using? And is there a plugin you're using for nested set? David On 7/19/07, Mikel Lindsaar wrote: > Here are the migrations: > > class CreateNodes < ActiveRecord::Migration > def self.up > create_table ("nodes", :options => 'ENGINE=InnoDB DEFAULT > CHARSET=utf8', :force => true) do |t| > t.column "title", :string > t.column "language_id", :integer > t.column "parent_id", :integer > t.column "lft", :integer > t.column "rgt", :integer > t.column "original_node_id", :integer > t.column "owner_id", :integer > t.column "owner_type", :string > t.column "root_id", :integer > end > end > > def self.down > drop_table "nodes" > end > end > > class CreateLanguagesTable < ActiveRecord::Migration > def self.up > create_table (:languages, :options => 'ENGINE=InnoDB DEFAULT > CHARSET=utf8', :force => true) do |t| > t.column :name, :string > end > end > > def self.down > drop_table :languages > end > end > > > The Nodes Model also has a self referrential association, but I don't > think that would be causing any problems. > > class Node < ActiveRecord::Base > belongs_to :language > belongs_to :owner, :polymorphic => true > > # Self referrential association, nodes have many original nodes - keeps track > # of all original => translation associations > belongs_to :original_node, :class_name => "Node", :foreign_key => > "original_node_id" > has_many :translated_nodes, :class_name => "Node", :foreign_key => > "original_node_id" > > acts_as_nested_set :scope => :root_id > > # + code from the original pastie > > end > > > There are some other associations, but they are all belongs_to or > has_many, so I haven't bothered to put all the tables in here and have > removed the appropriate foreign keys from the nodes table. > > > Regards > > Mikel > > > On 7/19/07, David Chelimsky wrote: > > Would you mind posting the migrations? > > > > On 7/18/07, Mikel Lindsaar wrote: > > > Heya David, > > > > > > Thanks for the reply. > > > > > > No, that didn't work, get the same error: > > > > > > NoMethodError in 'Node instance should return it's parent's language > > > if it is a child' > > > You have a nil object when you didn't expect it! > > > The error occurred while evaluating nil.name > > > > > > > > > If I include the fixture :languages, then replace out @language = > > > mock_model... with > > > > > > @language = languages(:one) > > > > > > it all works dandy. But I'm trying to ween myself off fixtures :) > > > > > > Regards > > > > > > Mikel > > > > > > > > > > > > On 7/19/07, David Chelimsky wrote: > > > > On 7/18/07, Mikel Lindsaar wrote: > > > > > Hello list, > > > > > > > > > > I think I have a rails related RSpec problem with a mock going out of > > > > > scope on a recursive call to a model. > > > > > > > > > > The code is at: http://pastie.textmate.org/79821 if you want to see it > > > > > highlighted. I have pasted it below as well. > > > > > > > > > > Basically, I have an acts_as_nested_set model called "Node", which > > > > > works fine. I have a function which finds the language name of the > > > > > node instance. If the language is nil for the node instance being > > > > > queried, it then recursively calles language_name on it's parent until > > > > > one of them has the language. Then this gets returned. > > > > > > > > > > When I do this with a fixture, it works fine. Ie, a Database call can > > > > > be made to a language table and I get the language name. > > > > > > > > > > In the code attached it has a langauge instance being mocked. I get > > > > > the same result if I mock Language.should_receive(:find)... > > > > > > > > > > It SEEMS like the Mock is going out of scope on the recursive call to > > > > > parent. The direct spec to the parent to get language name works > > > > > fine. > > > > > > > > > > Any ideas? (the code below is slimmed down to the code needed to run the spec. > > > > > > > > > > Regards > > > > > > > > > > Mikel > > > > > > > > > > CODE:: > > > > > > > > > > class Node < ActiveRecord::Base > > > > > > > > > > belongs_to :language > > > > > acts_as_nested_set :scope => :root_id > > > > > > > > > > def language_name > > > > > self.root? ? language.name : parent.language_name > > > > > end > > > > > end > > > > > > > > > > describe Node, "instance" do > > > > > > > > > > fixtures :nodes > > > > > > > > > > before(:each) do > > > > > @language = mock_model(Language, :name => "Japanese") > > > > > @node = Node.create!(:language => @language) > > > > > @section1 = Node.create!() > > > > > @chapter1 = Node.create!() > > > > > end > > > > > > > > > > it "should return it's own language if it is root" do # Passes > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > @node.language_name.should == "Japanese" > > > > > end > > > > > > > > > > it "should return it's parent's language if it is a child" do # > > > > > Fails (message below) > > > > > @section1.move_to_child_of(@node) > > > > > @chapter1.move_to_child_of(@section1) > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > @section1.language_name.should == "Japanese" > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > @chapter1.language_name.should == "Japanese" > > > > > end > > > > > end > > > > > > > > It's generally not recommended that you set expectations, invoke them > > > > and then set them again. I'm not sure, but that may be the problem > > > > here. Try this: > > > > > > > > it "should return it's parent's language if it is a child" do # > > > > Fails (message below) > > > > @section1.move_to_child_of(@node) > > > > @chapter1.move_to_child_of(@section1) > > > > @language.should_receive(:name).exactly(:twice).and_return("Japanese") > > > > @section1.language_name.should == "Japanese" > > > > @chapter1.language_name.should == "Japanese" > > > > end > > > > > > > > Does that work? > > > > > > > > > > > > > > SPEC ERROR:: > > > > > > > > > > NoMethodError in 'Node instance should return it's parent's language > > > > > if it is a child' > > > > > You have a nil object when you didn't expect it! > > > > > The error occurred while evaluating nil.name > > > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > > > 'language_name' > > > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > > > 'language_name' > > > > > ./spec/models/node_spec.rb:160: > > > > > script/spec:4: > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From raasdnil at gmail.com Thu Jul 19 00:49:07 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 19 Jul 2007 14:49:07 +1000 Subject: [rspec-users] Rails - Mock going out of scope? In-Reply-To: <57c63afe0707182134w38ae3e60vaed10692be285c67@mail.gmail.com> References: <57a815bf0707181556h695f2991ra575fe04d1b77195@mail.gmail.com> <57c63afe0707182024k51a19e99vc29da81e71499129@mail.gmail.com> <57a815bf0707182051k2058fceakb1676d929641c67@mail.gmail.com> <57c63afe0707182054h3e19c8e7n1cdb72a59a320430@mail.gmail.com> <57a815bf0707182123h59e99075s424f367cdceb5660@mail.gmail.com> <57c63afe0707182134w38ae3e60vaed10692be285c67@mail.gmail.com> Message-ID: <57a815bf0707182149k59cc45d4h4dc351ce5111a759@mail.gmail.com> Crap, I totally, forgot to mention, sorry David. I am using betternestedset http://wiki.rubyonrails.org/rails/pages/BetterNestedSet script/plugin source svn://rubyforge.org/var/svn/betternestedset script/plugin install betternestedset Regards Mikel On 7/19/07, David Chelimsky wrote: > Here are the errors I'm getting now: > > 1) > NoMethodError in 'Node instance should return it's parent's language > if it is a child' > undefined method `move_to_child_of' for # > ./spec/models/node_spec.rb:20: > > 2) > NameError in 'Node instance should return it's own language if it is root' > undefined local variable or method `parent' for # > /Users/david/projects/ruby/nodes/config/../app/models/node.rb:7:in > `language_name' > ./spec/models/node_spec.rb:16: > > What version of rails are you using? And is there a plugin you're > using for nested set? > > David > > On 7/19/07, Mikel Lindsaar wrote: > > Here are the migrations: > > > > class CreateNodes < ActiveRecord::Migration > > def self.up > > create_table ("nodes", :options => 'ENGINE=InnoDB DEFAULT > > CHARSET=utf8', :force => true) do |t| > > t.column "title", :string > > t.column "language_id", :integer > > t.column "parent_id", :integer > > t.column "lft", :integer > > t.column "rgt", :integer > > t.column "original_node_id", :integer > > t.column "owner_id", :integer > > t.column "owner_type", :string > > t.column "root_id", :integer > > end > > end > > > > def self.down > > drop_table "nodes" > > end > > end > > > > class CreateLanguagesTable < ActiveRecord::Migration > > def self.up > > create_table (:languages, :options => 'ENGINE=InnoDB DEFAULT > > CHARSET=utf8', :force => true) do |t| > > t.column :name, :string > > end > > end > > > > def self.down > > drop_table :languages > > end > > end > > > > > > The Nodes Model also has a self referrential association, but I don't > > think that would be causing any problems. > > > > class Node < ActiveRecord::Base > > belongs_to :language > > belongs_to :owner, :polymorphic => true > > > > # Self referrential association, nodes have many original nodes - keeps track > > # of all original => translation associations > > belongs_to :original_node, :class_name => "Node", :foreign_key => > > "original_node_id" > > has_many :translated_nodes, :class_name => "Node", :foreign_key => > > "original_node_id" > > > > acts_as_nested_set :scope => :root_id > > > > # + code from the original pastie > > > > end > > > > > > There are some other associations, but they are all belongs_to or > > has_many, so I haven't bothered to put all the tables in here and have > > removed the appropriate foreign keys from the nodes table. > > > > > > Regards > > > > Mikel > > > > > > On 7/19/07, David Chelimsky wrote: > > > Would you mind posting the migrations? > > > > > > On 7/18/07, Mikel Lindsaar wrote: > > > > Heya David, > > > > > > > > Thanks for the reply. > > > > > > > > No, that didn't work, get the same error: > > > > > > > > NoMethodError in 'Node instance should return it's parent's language > > > > if it is a child' > > > > You have a nil object when you didn't expect it! > > > > The error occurred while evaluating nil.name > > > > > > > > > > > > If I include the fixture :languages, then replace out @language = > > > > mock_model... with > > > > > > > > @language = languages(:one) > > > > > > > > it all works dandy. But I'm trying to ween myself off fixtures :) > > > > > > > > Regards > > > > > > > > Mikel > > > > > > > > > > > > > > > > On 7/19/07, David Chelimsky wrote: > > > > > On 7/18/07, Mikel Lindsaar wrote: > > > > > > Hello list, > > > > > > > > > > > > I think I have a rails related RSpec problem with a mock going out of > > > > > > scope on a recursive call to a model. > > > > > > > > > > > > The code is at: http://pastie.textmate.org/79821 if you want to see it > > > > > > highlighted. I have pasted it below as well. > > > > > > > > > > > > Basically, I have an acts_as_nested_set model called "Node", which > > > > > > works fine. I have a function which finds the language name of the > > > > > > node instance. If the language is nil for the node instance being > > > > > > queried, it then recursively calles language_name on it's parent until > > > > > > one of them has the language. Then this gets returned. > > > > > > > > > > > > When I do this with a fixture, it works fine. Ie, a Database call can > > > > > > be made to a language table and I get the language name. > > > > > > > > > > > > In the code attached it has a langauge instance being mocked. I get > > > > > > the same result if I mock Language.should_receive(:find)... > > > > > > > > > > > > It SEEMS like the Mock is going out of scope on the recursive call to > > > > > > parent. The direct spec to the parent to get language name works > > > > > > fine. > > > > > > > > > > > > Any ideas? (the code below is slimmed down to the code needed to run the spec. > > > > > > > > > > > > Regards > > > > > > > > > > > > Mikel > > > > > > > > > > > > CODE:: > > > > > > > > > > > > class Node < ActiveRecord::Base > > > > > > > > > > > > belongs_to :language > > > > > > acts_as_nested_set :scope => :root_id > > > > > > > > > > > > def language_name > > > > > > self.root? ? language.name : parent.language_name > > > > > > end > > > > > > end > > > > > > > > > > > > describe Node, "instance" do > > > > > > > > > > > > fixtures :nodes > > > > > > > > > > > > before(:each) do > > > > > > @language = mock_model(Language, :name => "Japanese") > > > > > > @node = Node.create!(:language => @language) > > > > > > @section1 = Node.create!() > > > > > > @chapter1 = Node.create!() > > > > > > end > > > > > > > > > > > > it "should return it's own language if it is root" do # Passes > > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > > @node.language_name.should == "Japanese" > > > > > > end > > > > > > > > > > > > it "should return it's parent's language if it is a child" do # > > > > > > Fails (message below) > > > > > > @section1.move_to_child_of(@node) > > > > > > @chapter1.move_to_child_of(@section1) > > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > > @section1.language_name.should == "Japanese" > > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > > @chapter1.language_name.should == "Japanese" > > > > > > end > > > > > > end > > > > > > > > > > It's generally not recommended that you set expectations, invoke them > > > > > and then set them again. I'm not sure, but that may be the problem > > > > > here. Try this: > > > > > > > > > > it "should return it's parent's language if it is a child" do # > > > > > Fails (message below) > > > > > @section1.move_to_child_of(@node) > > > > > @chapter1.move_to_child_of(@section1) > > > > > @language.should_receive(:name).exactly(:twice).and_return("Japanese") > > > > > @section1.language_name.should == "Japanese" > > > > > @chapter1.language_name.should == "Japanese" > > > > > end > > > > > > > > > > Does that work? > > > > > > > > > > > > > > > > > SPEC ERROR:: > > > > > > > > > > > > NoMethodError in 'Node instance should return it's parent's language > > > > > > if it is a child' > > > > > > You have a nil object when you didn't expect it! > > > > > > The error occurred while evaluating nil.name > > > > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > > > > 'language_name' > > > > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > > > > 'language_name' > > > > > > ./spec/models/node_spec.rb:160: > > > > > > script/spec:4: > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From raasdnil at gmail.com Thu Jul 19 00:50:15 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 19 Jul 2007 14:50:15 +1000 Subject: [rspec-users] Rails - Mock going out of scope? In-Reply-To: <57a815bf0707182149k59cc45d4h4dc351ce5111a759@mail.gmail.com> References: <57a815bf0707181556h695f2991ra575fe04d1b77195@mail.gmail.com> <57c63afe0707182024k51a19e99vc29da81e71499129@mail.gmail.com> <57a815bf0707182051k2058fceakb1676d929641c67@mail.gmail.com> <57c63afe0707182054h3e19c8e7n1cdb72a59a320430@mail.gmail.com> <57a815bf0707182123h59e99075s424f367cdceb5660@mail.gmail.com> <57c63afe0707182134w38ae3e60vaed10692be285c67@mail.gmail.com> <57a815bf0707182149k59cc45d4h4dc351ce5111a759@mail.gmail.com> Message-ID: <57a815bf0707182150v1ab34e83pd5f90a4d6733474d@mail.gmail.com> Using 1.2.3 and RSpec with the RSpec Rails plugin installed from CURRENT on the RSpec SVN server. On 7/19/07, Mikel Lindsaar wrote: > Crap, I totally, forgot to mention, sorry David. I am using betternestedset > > http://wiki.rubyonrails.org/rails/pages/BetterNestedSet > > script/plugin source svn://rubyforge.org/var/svn/betternestedset > script/plugin install betternestedset > > > Regards > > Mikel > > On 7/19/07, David Chelimsky wrote: > > Here are the errors I'm getting now: > > > > 1) > > NoMethodError in 'Node instance should return it's parent's language > > if it is a child' > > undefined method `move_to_child_of' for # > > ./spec/models/node_spec.rb:20: > > > > 2) > > NameError in 'Node instance should return it's own language if it is root' > > undefined local variable or method `parent' for # > > /Users/david/projects/ruby/nodes/config/../app/models/node.rb:7:in > > `language_name' > > ./spec/models/node_spec.rb:16: > > > > What version of rails are you using? And is there a plugin you're > > using for nested set? > > > > David > > > > On 7/19/07, Mikel Lindsaar wrote: > > > Here are the migrations: > > > > > > class CreateNodes < ActiveRecord::Migration > > > def self.up > > > create_table ("nodes", :options => 'ENGINE=InnoDB DEFAULT > > > CHARSET=utf8', :force => true) do |t| > > > t.column "title", :string > > > t.column "language_id", :integer > > > t.column "parent_id", :integer > > > t.column "lft", :integer > > > t.column "rgt", :integer > > > t.column "original_node_id", :integer > > > t.column "owner_id", :integer > > > t.column "owner_type", :string > > > t.column "root_id", :integer > > > end > > > end > > > > > > def self.down > > > drop_table "nodes" > > > end > > > end > > > > > > class CreateLanguagesTable < ActiveRecord::Migration > > > def self.up > > > create_table (:languages, :options => 'ENGINE=InnoDB DEFAULT > > > CHARSET=utf8', :force => true) do |t| > > > t.column :name, :string > > > end > > > end > > > > > > def self.down > > > drop_table :languages > > > end > > > end > > > > > > > > > The Nodes Model also has a self referrential association, but I don't > > > think that would be causing any problems. > > > > > > class Node < ActiveRecord::Base > > > belongs_to :language > > > belongs_to :owner, :polymorphic => true > > > > > > # Self referrential association, nodes have many original nodes - keeps track > > > # of all original => translation associations > > > belongs_to :original_node, :class_name => "Node", :foreign_key => > > > "original_node_id" > > > has_many :translated_nodes, :class_name => "Node", :foreign_key => > > > "original_node_id" > > > > > > acts_as_nested_set :scope => :root_id > > > > > > # + code from the original pastie > > > > > > end > > > > > > > > > There are some other associations, but they are all belongs_to or > > > has_many, so I haven't bothered to put all the tables in here and have > > > removed the appropriate foreign keys from the nodes table. > > > > > > > > > Regards > > > > > > Mikel > > > > > > > > > On 7/19/07, David Chelimsky wrote: > > > > Would you mind posting the migrations? > > > > > > > > On 7/18/07, Mikel Lindsaar wrote: > > > > > Heya David, > > > > > > > > > > Thanks for the reply. > > > > > > > > > > No, that didn't work, get the same error: > > > > > > > > > > NoMethodError in 'Node instance should return it's parent's language > > > > > if it is a child' > > > > > You have a nil object when you didn't expect it! > > > > > The error occurred while evaluating nil.name > > > > > > > > > > > > > > > If I include the fixture :languages, then replace out @language = > > > > > mock_model... with > > > > > > > > > > @language = languages(:one) > > > > > > > > > > it all works dandy. But I'm trying to ween myself off fixtures :) > > > > > > > > > > Regards > > > > > > > > > > Mikel > > > > > > > > > > > > > > > > > > > > On 7/19/07, David Chelimsky wrote: > > > > > > On 7/18/07, Mikel Lindsaar wrote: > > > > > > > Hello list, > > > > > > > > > > > > > > I think I have a rails related RSpec problem with a mock going out of > > > > > > > scope on a recursive call to a model. > > > > > > > > > > > > > > The code is at: http://pastie.textmate.org/79821 if you want to see it > > > > > > > highlighted. I have pasted it below as well. > > > > > > > > > > > > > > Basically, I have an acts_as_nested_set model called "Node", which > > > > > > > works fine. I have a function which finds the language name of the > > > > > > > node instance. If the language is nil for the node instance being > > > > > > > queried, it then recursively calles language_name on it's parent until > > > > > > > one of them has the language. Then this gets returned. > > > > > > > > > > > > > > When I do this with a fixture, it works fine. Ie, a Database call can > > > > > > > be made to a language table and I get the language name. > > > > > > > > > > > > > > In the code attached it has a langauge instance being mocked. I get > > > > > > > the same result if I mock Language.should_receive(:find)... > > > > > > > > > > > > > > It SEEMS like the Mock is going out of scope on the recursive call to > > > > > > > parent. The direct spec to the parent to get language name works > > > > > > > fine. > > > > > > > > > > > > > > Any ideas? (the code below is slimmed down to the code needed to run the spec. > > > > > > > > > > > > > > Regards > > > > > > > > > > > > > > Mikel > > > > > > > > > > > > > > CODE:: > > > > > > > > > > > > > > class Node < ActiveRecord::Base > > > > > > > > > > > > > > belongs_to :language > > > > > > > acts_as_nested_set :scope => :root_id > > > > > > > > > > > > > > def language_name > > > > > > > self.root? ? language.name : parent.language_name > > > > > > > end > > > > > > > end > > > > > > > > > > > > > > describe Node, "instance" do > > > > > > > > > > > > > > fixtures :nodes > > > > > > > > > > > > > > before(:each) do > > > > > > > @language = mock_model(Language, :name => "Japanese") > > > > > > > @node = Node.create!(:language => @language) > > > > > > > @section1 = Node.create!() > > > > > > > @chapter1 = Node.create!() > > > > > > > end > > > > > > > > > > > > > > it "should return it's own language if it is root" do # Passes > > > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > > > @node.language_name.should == "Japanese" > > > > > > > end > > > > > > > > > > > > > > it "should return it's parent's language if it is a child" do # > > > > > > > Fails (message below) > > > > > > > @section1.move_to_child_of(@node) > > > > > > > @chapter1.move_to_child_of(@section1) > > > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > > > @section1.language_name.should == "Japanese" > > > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > > > @chapter1.language_name.should == "Japanese" > > > > > > > end > > > > > > > end > > > > > > > > > > > > It's generally not recommended that you set expectations, invoke them > > > > > > and then set them again. I'm not sure, but that may be the problem > > > > > > here. Try this: > > > > > > > > > > > > it "should return it's parent's language if it is a child" do # > > > > > > Fails (message below) > > > > > > @section1.move_to_child_of(@node) > > > > > > @chapter1.move_to_child_of(@section1) > > > > > > @language.should_receive(:name).exactly(:twice).and_return("Japanese") > > > > > > @section1.language_name.should == "Japanese" > > > > > > @chapter1.language_name.should == "Japanese" > > > > > > end > > > > > > > > > > > > Does that work? > > > > > > > > > > > > > > > > > > > > SPEC ERROR:: > > > > > > > > > > > > > > NoMethodError in 'Node instance should return it's parent's language > > > > > > > if it is a child' > > > > > > > You have a nil object when you didn't expect it! > > > > > > > The error occurred while evaluating nil.name > > > > > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > > > > > 'language_name' > > > > > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > > > > > 'language_name' > > > > > > > ./spec/models/node_spec.rb:160: > > > > > > > script/spec:4: > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-users at rubyforge.org > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From barjunk at attglobal.net Thu Jul 19 01:08:21 2007 From: barjunk at attglobal.net (barsalou) Date: Wed, 18 Jul 2007 21:08:21 -0800 Subject: [rspec-users] need help getting a word right In-Reply-To: <57c63afe0707182035t6b4e49f8u83b99e8da0b5e479@mail.gmail.com> References: <57c63afe0707182035t6b4e49f8u83b99e8da0b5e479@mail.gmail.com> Message-ID: <20070718210821.l1a8no138oo0swc0@lcgalaska.com> Well in that specific case, please seems like a good choice please do @thing.should be_somthing end But If you had text in between then it wouldn't seem the same: please "whatever text" do @thing.should be_something end Quoting David Chelimsky : > Hey all, > > I see examples showing up that look like this: > > describe Thing do > before(:each) do > @thing = Thing.new > end > > it do > @thing.should be_something > end > end > > This will produce output like this: > > Thing > - should be something > > But "it do" is driving me mad :( > > We need a better word. Of course, 'specify' has not been completely > removed, so you can still do this: > > describe Thing do > before(:each) { @thing = Thing.new } > specify { @thing.should be_something } > end > > Consise? Yes. But I'm not psyched about 'specify' either. There IS a > perfect word for this situation. What is it? Suggestions? > > Thanks, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From raasdnil at gmail.com Thu Jul 19 01:14:09 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 19 Jul 2007 15:14:09 +1000 Subject: [rspec-users] need help getting a word right In-Reply-To: <87a13e220707182044n148aeb07tf9bfee7be365d22@mail.gmail.com> References: <57c63afe0707182035t6b4e49f8u83b99e8da0b5e479@mail.gmail.com> <87a13e220707182044n148aeb07tf9bfee7be365d22@mail.gmail.com> Message-ID: <57a815bf0707182214i6ebee810u4dbd1d5c97872da8@mail.gmail.com> I like the it "should..." do end calls, specifiy as well makes sense. So what is the problem? I think we should take a look at what comments are for. Essentially the "should blah" text acts as a comment on the spec. One that is then picked up by RSpec and inserted to make our specifications more readable in one line. So, if we treat these "shoulds..." as essentially comments, it then opens the door to a resolution as the only place you should use comments is when the code itself is not immediately self documenting. In the Spec world, this really means anything that is more than say one or two lines of code. Why? Well, that's just an opinion. But we could make the following best practice: If your spec utilizes one matcher and fits on one line, then use: specify { target.should == blah } if your spec can not be succinctly and clearly described in one line of code, then you should add a spec "comment" and so use it "should accept an XML feed" do xml = mock(XMLFeed) target.handle_feed(xml).should == true end The point of specs is their readability and clarity. By making that simple distinction as a "best practice" you handle the situation. That way reading down the spec code would be almost as clear as looking at the RSpec doc html page. then again, with text editors typing "it" and writing a spec is really not THAT hard is it? Regards Mikel On 7/19/07, Robert Feldt wrote: > > > On 7/19/07, David Chelimsky wrote: > > Hey all, > > > > I see examples showing up that look like this: > > > > describe Thing do > > before(:each) do > > @thing = Thing.new > > end > > > > it do > > @thing.should be_something > > end > > end > > > > This will produce output like this: > > > > Thing > > - should be something > > > > But "it do" is driving me mad :( > > > > We need a better word. Of course, 'specify' has not been completely > > removed, so you can still do this: > > > > describe Thing do > > before(:each) { @thing = Thing.new } > > specify { @thing.should be_something } > > end > > > > Consise? Yes. But I'm not psyched about 'specify' either. There IS a > > perfect word for this situation. What is it? Suggestions? > > I like "should" or "spec" the best. > > While I'm at it why not "given" instead of "describe"? > > Cheers, > > Robert Feldt > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Jul 19 01:23:07 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 19 Jul 2007 01:23:07 -0400 Subject: [rspec-users] Rails - Mock going out of scope? In-Reply-To: <57a815bf0707182150v1ab34e83pd5f90a4d6733474d@mail.gmail.com> References: <57a815bf0707181556h695f2991ra575fe04d1b77195@mail.gmail.com> <57c63afe0707182024k51a19e99vc29da81e71499129@mail.gmail.com> <57a815bf0707182051k2058fceakb1676d929641c67@mail.gmail.com> <57c63afe0707182054h3e19c8e7n1cdb72a59a320430@mail.gmail.com> <57a815bf0707182123h59e99075s424f367cdceb5660@mail.gmail.com> <57c63afe0707182134w38ae3e60vaed10692be285c67@mail.gmail.com> <57a815bf0707182149k59cc45d4h4dc351ce5111a759@mail.gmail.com> <57a815bf0707182150v1ab34e83pd5f90a4d6733474d@mail.gmail.com> Message-ID: <57c63afe0707182223q24e55ae1rd1fed6df4c1a4cd7@mail.gmail.com> D'oh. I should have figured this out on first sighting: The parent method does a find, so it retrieves a new object from the db - not the instance of Node you have defined. This new instance has no language associated with it (because the one you gave it pretends to exist by sporting an ID, but is never saved to the DB). Make sense? So, if you want to mock this, you have to mock a bit more than what you have in mind. Check out this pastie: http://pastie.textmate.org/80159 David On 7/19/07, Mikel Lindsaar wrote: > Using 1.2.3 and RSpec with the RSpec Rails plugin installed from > CURRENT on the RSpec SVN server. > > On 7/19/07, Mikel Lindsaar wrote: > > Crap, I totally, forgot to mention, sorry David. I am using betternestedset > > > > http://wiki.rubyonrails.org/rails/pages/BetterNestedSet > > > > script/plugin source svn://rubyforge.org/var/svn/betternestedset > > script/plugin install betternestedset > > > > > > Regards > > > > Mikel > > > > On 7/19/07, David Chelimsky wrote: > > > Here are the errors I'm getting now: > > > > > > 1) > > > NoMethodError in 'Node instance should return it's parent's language > > > if it is a child' > > > undefined method `move_to_child_of' for # > > > ./spec/models/node_spec.rb:20: > > > > > > 2) > > > NameError in 'Node instance should return it's own language if it is root' > > > undefined local variable or method `parent' for # > > > /Users/david/projects/ruby/nodes/config/../app/models/node.rb:7:in > > > `language_name' > > > ./spec/models/node_spec.rb:16: > > > > > > What version of rails are you using? And is there a plugin you're > > > using for nested set? > > > > > > David > > > > > > On 7/19/07, Mikel Lindsaar wrote: > > > > Here are the migrations: > > > > > > > > class CreateNodes < ActiveRecord::Migration > > > > def self.up > > > > create_table ("nodes", :options => 'ENGINE=InnoDB DEFAULT > > > > CHARSET=utf8', :force => true) do |t| > > > > t.column "title", :string > > > > t.column "language_id", :integer > > > > t.column "parent_id", :integer > > > > t.column "lft", :integer > > > > t.column "rgt", :integer > > > > t.column "original_node_id", :integer > > > > t.column "owner_id", :integer > > > > t.column "owner_type", :string > > > > t.column "root_id", :integer > > > > end > > > > end > > > > > > > > def self.down > > > > drop_table "nodes" > > > > end > > > > end > > > > > > > > class CreateLanguagesTable < ActiveRecord::Migration > > > > def self.up > > > > create_table (:languages, :options => 'ENGINE=InnoDB DEFAULT > > > > CHARSET=utf8', :force => true) do |t| > > > > t.column :name, :string > > > > end > > > > end > > > > > > > > def self.down > > > > drop_table :languages > > > > end > > > > end > > > > > > > > > > > > The Nodes Model also has a self referrential association, but I don't > > > > think that would be causing any problems. > > > > > > > > class Node < ActiveRecord::Base > > > > belongs_to :language > > > > belongs_to :owner, :polymorphic => true > > > > > > > > # Self referrential association, nodes have many original nodes - keeps track > > > > # of all original => translation associations > > > > belongs_to :original_node, :class_name => "Node", :foreign_key => > > > > "original_node_id" > > > > has_many :translated_nodes, :class_name => "Node", :foreign_key => > > > > "original_node_id" > > > > > > > > acts_as_nested_set :scope => :root_id > > > > > > > > # + code from the original pastie > > > > > > > > end > > > > > > > > > > > > There are some other associations, but they are all belongs_to or > > > > has_many, so I haven't bothered to put all the tables in here and have > > > > removed the appropriate foreign keys from the nodes table. > > > > > > > > > > > > Regards > > > > > > > > Mikel > > > > > > > > > > > > On 7/19/07, David Chelimsky wrote: > > > > > Would you mind posting the migrations? > > > > > > > > > > On 7/18/07, Mikel Lindsaar wrote: > > > > > > Heya David, > > > > > > > > > > > > Thanks for the reply. > > > > > > > > > > > > No, that didn't work, get the same error: > > > > > > > > > > > > NoMethodError in 'Node instance should return it's parent's language > > > > > > if it is a child' > > > > > > You have a nil object when you didn't expect it! > > > > > > The error occurred while evaluating nil.name > > > > > > > > > > > > > > > > > > If I include the fixture :languages, then replace out @language = > > > > > > mock_model... with > > > > > > > > > > > > @language = languages(:one) > > > > > > > > > > > > it all works dandy. But I'm trying to ween myself off fixtures :) > > > > > > > > > > > > Regards > > > > > > > > > > > > Mikel > > > > > > > > > > > > > > > > > > > > > > > > On 7/19/07, David Chelimsky wrote: > > > > > > > On 7/18/07, Mikel Lindsaar wrote: > > > > > > > > Hello list, > > > > > > > > > > > > > > > > I think I have a rails related RSpec problem with a mock going out of > > > > > > > > scope on a recursive call to a model. > > > > > > > > > > > > > > > > The code is at: http://pastie.textmate.org/79821 if you want to see it > > > > > > > > highlighted. I have pasted it below as well. > > > > > > > > > > > > > > > > Basically, I have an acts_as_nested_set model called "Node", which > > > > > > > > works fine. I have a function which finds the language name of the > > > > > > > > node instance. If the language is nil for the node instance being > > > > > > > > queried, it then recursively calles language_name on it's parent until > > > > > > > > one of them has the language. Then this gets returned. > > > > > > > > > > > > > > > > When I do this with a fixture, it works fine. Ie, a Database call can > > > > > > > > be made to a language table and I get the language name. > > > > > > > > > > > > > > > > In the code attached it has a langauge instance being mocked. I get > > > > > > > > the same result if I mock Language.should_receive(:find)... > > > > > > > > > > > > > > > > It SEEMS like the Mock is going out of scope on the recursive call to > > > > > > > > parent. The direct spec to the parent to get language name works > > > > > > > > fine. > > > > > > > > > > > > > > > > Any ideas? (the code below is slimmed down to the code needed to run the spec. > > > > > > > > > > > > > > > > Regards > > > > > > > > > > > > > > > > Mikel > > > > > > > > > > > > > > > > CODE:: > > > > > > > > > > > > > > > > class Node < ActiveRecord::Base > > > > > > > > > > > > > > > > belongs_to :language > > > > > > > > acts_as_nested_set :scope => :root_id > > > > > > > > > > > > > > > > def language_name > > > > > > > > self.root? ? language.name : parent.language_name > > > > > > > > end > > > > > > > > end > > > > > > > > > > > > > > > > describe Node, "instance" do > > > > > > > > > > > > > > > > fixtures :nodes > > > > > > > > > > > > > > > > before(:each) do > > > > > > > > @language = mock_model(Language, :name => "Japanese") > > > > > > > > @node = Node.create!(:language => @language) > > > > > > > > @section1 = Node.create!() > > > > > > > > @chapter1 = Node.create!() > > > > > > > > end > > > > > > > > > > > > > > > > it "should return it's own language if it is root" do # Passes > > > > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > > > > @node.language_name.should == "Japanese" > > > > > > > > end > > > > > > > > > > > > > > > > it "should return it's parent's language if it is a child" do # > > > > > > > > Fails (message below) > > > > > > > > @section1.move_to_child_of(@node) > > > > > > > > @chapter1.move_to_child_of(@section1) > > > > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > > > > @section1.language_name.should == "Japanese" > > > > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > > > > @chapter1.language_name.should == "Japanese" > > > > > > > > end > > > > > > > > end > > > > > > > > > > > > > > It's generally not recommended that you set expectations, invoke them > > > > > > > and then set them again. I'm not sure, but that may be the problem > > > > > > > here. Try this: > > > > > > > > > > > > > > it "should return it's parent's language if it is a child" do # > > > > > > > Fails (message below) > > > > > > > @section1.move_to_child_of(@node) > > > > > > > @chapter1.move_to_child_of(@section1) > > > > > > > @language.should_receive(:name).exactly(:twice).and_return("Japanese") > > > > > > > @section1.language_name.should == "Japanese" > > > > > > > @chapter1.language_name.should == "Japanese" > > > > > > > end > > > > > > > > > > > > > > Does that work? > > > > > > > > > > > > > > > > > > > > > > > SPEC ERROR:: > > > > > > > > > > > > > > > > NoMethodError in 'Node instance should return it's parent's language > > > > > > > > if it is a child' > > > > > > > > You have a nil object when you didn't expect it! > > > > > > > > The error occurred while evaluating nil.name > > > > > > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > > > > > > 'language_name' > > > > > > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > > > > > > 'language_name' > > > > > > > > ./spec/models/node_spec.rb:160: > > > > > > > > script/spec:4: > > > > > > > > _______________________________________________ > > > > > > > > rspec-users mailing list > > > > > > > > rspec-users at rubyforge.org > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-users at rubyforge.org > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From raasdnil at gmail.com Thu Jul 19 01:28:03 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 19 Jul 2007 15:28:03 +1000 Subject: [rspec-users] Rails - Mock going out of scope? In-Reply-To: <57c63afe0707182223q24e55ae1rd1fed6df4c1a4cd7@mail.gmail.com> References: <57a815bf0707181556h695f2991ra575fe04d1b77195@mail.gmail.com> <57c63afe0707182024k51a19e99vc29da81e71499129@mail.gmail.com> <57a815bf0707182051k2058fceakb1676d929641c67@mail.gmail.com> <57c63afe0707182054h3e19c8e7n1cdb72a59a320430@mail.gmail.com> <57a815bf0707182123h59e99075s424f367cdceb5660@mail.gmail.com> <57c63afe0707182134w38ae3e60vaed10692be285c67@mail.gmail.com> <57a815bf0707182149k59cc45d4h4dc351ce5111a759@mail.gmail.com> <57a815bf0707182150v1ab34e83pd5f90a4d6733474d@mail.gmail.com> <57c63afe0707182223q24e55ae1rd1fed6df4c1a4cd7@mail.gmail.com> Message-ID: <57a815bf0707182228y3a3e1339m5faadb1a324cdd99@mail.gmail.com> Makes total sense. Thank you _very_ much David :) All works well and handles another question I have on a disrelated matter. By the way, loving RSpec. Makes testing a lot more interesting and rewarding. Thanks for all your work. Regards Mikel On 7/19/07, David Chelimsky wrote: > D'oh. I should have figured this out on first sighting: > > The parent method does a find, so it retrieves a new object from the > db - not the instance of Node you have defined. This new instance has > no language associated with it (because the one you gave it pretends > to exist by sporting an ID, but is never saved to the DB). > > Make sense? > > So, if you want to mock this, you have to mock a bit more than what > you have in mind. Check out this pastie: > http://pastie.textmate.org/80159 > > David > > On 7/19/07, Mikel Lindsaar wrote: > > Using 1.2.3 and RSpec with the RSpec Rails plugin installed from > > CURRENT on the RSpec SVN server. > > > > On 7/19/07, Mikel Lindsaar wrote: > > > Crap, I totally, forgot to mention, sorry David. I am using betternestedset > > > > > > http://wiki.rubyonrails.org/rails/pages/BetterNestedSet > > > > > > script/plugin source svn://rubyforge.org/var/svn/betternestedset > > > script/plugin install betternestedset > > > > > > > > > Regards > > > > > > Mikel > > > > > > On 7/19/07, David Chelimsky wrote: > > > > Here are the errors I'm getting now: > > > > > > > > 1) > > > > NoMethodError in 'Node instance should return it's parent's language > > > > if it is a child' > > > > undefined method `move_to_child_of' for # > > > > ./spec/models/node_spec.rb:20: > > > > > > > > 2) > > > > NameError in 'Node instance should return it's own language if it is root' > > > > undefined local variable or method `parent' for # > > > > /Users/david/projects/ruby/nodes/config/../app/models/node.rb:7:in > > > > `language_name' > > > > ./spec/models/node_spec.rb:16: > > > > > > > > What version of rails are you using? And is there a plugin you're > > > > using for nested set? > > > > > > > > David > > > > > > > > On 7/19/07, Mikel Lindsaar wrote: > > > > > Here are the migrations: > > > > > > > > > > class CreateNodes < ActiveRecord::Migration > > > > > def self.up > > > > > create_table ("nodes", :options => 'ENGINE=InnoDB DEFAULT > > > > > CHARSET=utf8', :force => true) do |t| > > > > > t.column "title", :string > > > > > t.column "language_id", :integer > > > > > t.column "parent_id", :integer > > > > > t.column "lft", :integer > > > > > t.column "rgt", :integer > > > > > t.column "original_node_id", :integer > > > > > t.column "owner_id", :integer > > > > > t.column "owner_type", :string > > > > > t.column "root_id", :integer > > > > > end > > > > > end > > > > > > > > > > def self.down > > > > > drop_table "nodes" > > > > > end > > > > > end > > > > > > > > > > class CreateLanguagesTable < ActiveRecord::Migration > > > > > def self.up > > > > > create_table (:languages, :options => 'ENGINE=InnoDB DEFAULT > > > > > CHARSET=utf8', :force => true) do |t| > > > > > t.column :name, :string > > > > > end > > > > > end > > > > > > > > > > def self.down > > > > > drop_table :languages > > > > > end > > > > > end > > > > > > > > > > > > > > > The Nodes Model also has a self referrential association, but I don't > > > > > think that would be causing any problems. > > > > > > > > > > class Node < ActiveRecord::Base > > > > > belongs_to :language > > > > > belongs_to :owner, :polymorphic => true > > > > > > > > > > # Self referrential association, nodes have many original nodes - keeps track > > > > > # of all original => translation associations > > > > > belongs_to :original_node, :class_name => "Node", :foreign_key => > > > > > "original_node_id" > > > > > has_many :translated_nodes, :class_name => "Node", :foreign_key => > > > > > "original_node_id" > > > > > > > > > > acts_as_nested_set :scope => :root_id > > > > > > > > > > # + code from the original pastie > > > > > > > > > > end > > > > > > > > > > > > > > > There are some other associations, but they are all belongs_to or > > > > > has_many, so I haven't bothered to put all the tables in here and have > > > > > removed the appropriate foreign keys from the nodes table. > > > > > > > > > > > > > > > Regards > > > > > > > > > > Mikel > > > > > > > > > > > > > > > On 7/19/07, David Chelimsky wrote: > > > > > > Would you mind posting the migrations? > > > > > > > > > > > > On 7/18/07, Mikel Lindsaar wrote: > > > > > > > Heya David, > > > > > > > > > > > > > > Thanks for the reply. > > > > > > > > > > > > > > No, that didn't work, get the same error: > > > > > > > > > > > > > > NoMethodError in 'Node instance should return it's parent's language > > > > > > > if it is a child' > > > > > > > You have a nil object when you didn't expect it! > > > > > > > The error occurred while evaluating nil.name > > > > > > > > > > > > > > > > > > > > > If I include the fixture :languages, then replace out @language = > > > > > > > mock_model... with > > > > > > > > > > > > > > @language = languages(:one) > > > > > > > > > > > > > > it all works dandy. But I'm trying to ween myself off fixtures :) > > > > > > > > > > > > > > Regards > > > > > > > > > > > > > > Mikel > > > > > > > > > > > > > > > > > > > > > > > > > > > > On 7/19/07, David Chelimsky wrote: > > > > > > > > On 7/18/07, Mikel Lindsaar wrote: > > > > > > > > > Hello list, > > > > > > > > > > > > > > > > > > I think I have a rails related RSpec problem with a mock going out of > > > > > > > > > scope on a recursive call to a model. > > > > > > > > > > > > > > > > > > The code is at: http://pastie.textmate.org/79821 if you want to see it > > > > > > > > > highlighted. I have pasted it below as well. > > > > > > > > > > > > > > > > > > Basically, I have an acts_as_nested_set model called "Node", which > > > > > > > > > works fine. I have a function which finds the language name of the > > > > > > > > > node instance. If the language is nil for the node instance being > > > > > > > > > queried, it then recursively calles language_name on it's parent until > > > > > > > > > one of them has the language. Then this gets returned. > > > > > > > > > > > > > > > > > > When I do this with a fixture, it works fine. Ie, a Database call can > > > > > > > > > be made to a language table and I get the language name. > > > > > > > > > > > > > > > > > > In the code attached it has a langauge instance being mocked. I get > > > > > > > > > the same result if I mock Language.should_receive(:find)... > > > > > > > > > > > > > > > > > > It SEEMS like the Mock is going out of scope on the recursive call to > > > > > > > > > parent. The direct spec to the parent to get language name works > > > > > > > > > fine. > > > > > > > > > > > > > > > > > > Any ideas? (the code below is slimmed down to the code needed to run the spec. > > > > > > > > > > > > > > > > > > Regards > > > > > > > > > > > > > > > > > > Mikel > > > > > > > > > > > > > > > > > > CODE:: > > > > > > > > > > > > > > > > > > class Node < ActiveRecord::Base > > > > > > > > > > > > > > > > > > belongs_to :language > > > > > > > > > acts_as_nested_set :scope => :root_id > > > > > > > > > > > > > > > > > > def language_name > > > > > > > > > self.root? ? language.name : parent.language_name > > > > > > > > > end > > > > > > > > > end > > > > > > > > > > > > > > > > > > describe Node, "instance" do > > > > > > > > > > > > > > > > > > fixtures :nodes > > > > > > > > > > > > > > > > > > before(:each) do > > > > > > > > > @language = mock_model(Language, :name => "Japanese") > > > > > > > > > @node = Node.create!(:language => @language) > > > > > > > > > @section1 = Node.create!() > > > > > > > > > @chapter1 = Node.create!() > > > > > > > > > end > > > > > > > > > > > > > > > > > > it "should return it's own language if it is root" do # Passes > > > > > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > > > > > @node.language_name.should == "Japanese" > > > > > > > > > end > > > > > > > > > > > > > > > > > > it "should return it's parent's language if it is a child" do # > > > > > > > > > Fails (message below) > > > > > > > > > @section1.move_to_child_of(@node) > > > > > > > > > @chapter1.move_to_child_of(@section1) > > > > > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > > > > > @section1.language_name.should == "Japanese" > > > > > > > > > @language.should_receive(:name).exactly(:once).and_return("Japanese") > > > > > > > > > @chapter1.language_name.should == "Japanese" > > > > > > > > > end > > > > > > > > > end > > > > > > > > > > > > > > > > It's generally not recommended that you set expectations, invoke them > > > > > > > > and then set them again. I'm not sure, but that may be the problem > > > > > > > > here. Try this: > > > > > > > > > > > > > > > > it "should return it's parent's language if it is a child" do # > > > > > > > > Fails (message below) > > > > > > > > @section1.move_to_child_of(@node) > > > > > > > > @chapter1.move_to_child_of(@section1) > > > > > > > > @language.should_receive(:name).exactly(:twice).and_return("Japanese") > > > > > > > > @section1.language_name.should == "Japanese" > > > > > > > > @chapter1.language_name.should == "Japanese" > > > > > > > > end > > > > > > > > > > > > > > > > Does that work? > > > > > > > > > > > > > > > > > > > > > > > > > > SPEC ERROR:: > > > > > > > > > > > > > > > > > > NoMethodError in 'Node instance should return it's parent's language > > > > > > > > > if it is a child' > > > > > > > > > You have a nil object when you didn't expect it! > > > > > > > > > The error occurred while evaluating nil.name > > > > > > > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > > > > > > > 'language_name' > > > > > > > > > /Users/mikel/working/universal_translator/config/../app/models/node.rb:29:in > > > > > > > > > 'language_name' > > > > > > > > > ./spec/models/node_spec.rb:160: > > > > > > > > > script/spec:4: > > > > > > > > > _______________________________________________ > > > > > > > > > rspec-users mailing list > > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > > rspec-users mailing list > > > > > > > > rspec-users at rubyforge.org > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-users at rubyforge.org > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From raasdnil at gmail.com Fri Jul 20 00:33:04 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Fri, 20 Jul 2007 14:33:04 +1000 Subject: [rspec-users] Little tool to help RSpec Textmate Users Message-ID: <57a815bf0707192133j2c94524ev68579cc9976d8d27@mail.gmail.com> Thought someone else might like this. Just a simple way to modify your TODO list to show all unimplemented specs in your project. Insanely simple, but all good things usually are :) http://www.blognow.com.au/q/67397/Behaviour_Driven_Design_RSpec_and_Textmate039s_TODO_List.html Not sure how that long URL will wrap, the short home page is: http://www.blognow.com.au/q/ If you want to do it yourself and don't need picutres, make a new marker in the TODO preferences with: /\s+it\s"(\S.*?)"\s+$/i as the Regex. This will find all 'it "should do somethings"' in your project and give you a nice hyperlinked list. Regards Mikel From lancecarlson at gmail.com Fri Jul 20 22:52:49 2007 From: lancecarlson at gmail.com (Lance Carlson) Date: Fri, 20 Jul 2007 22:52:49 -0400 Subject: [rspec-users] Testing shorthand array push << Message-ID: <49f64a900707201952s1b620bd3jad7eb207c05b237a@mail.gmail.com> Hi everyone, I'm trying to test the shorthand way to push objects into an array. My controller looks like: current_user.foos << @foo and I keep getting an error like Mock 'foos' received unexpected message :<< with does anyone have a good solution for this? I tried controller.send(:current_user).labels.stub!(:<<).and_return([]) and that didn't work. TIA! -Lance -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070720/1c71d52d/attachment.html From dchelimsky at gmail.com Sat Jul 21 09:24:48 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 21 Jul 2007 08:24:48 -0500 Subject: [rspec-users] Testing shorthand array push << In-Reply-To: <49f64a900707201952s1b620bd3jad7eb207c05b237a@mail.gmail.com> References: <49f64a900707201952s1b620bd3jad7eb207c05b237a@mail.gmail.com> Message-ID: <57c63afe0707210624ma77a22cv534391b25c242526@mail.gmail.com> On 7/20/07, Lance Carlson wrote: > Hi everyone, > > I'm trying to test the shorthand way to push objects into an array. My > controller looks like: > > current_user.foos << @foo > > and I keep getting an error like Mock 'foos' received unexpected message :<< > with > > does anyone have a good solution for this? > > I tried controller.send(:current_user).labels.stub!(:<<).and_return([]) and > that didn't work. That should work. Would you please post the rspec example and the controller code? > > TIA! > -Lance > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From edward.og at gmail.com Sun Jul 22 03:00:39 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Sun, 22 Jul 2007 03:00:39 -0400 Subject: [rspec-users] have_tag for href with specific link? Message-ID: <46A30097.8040702@gmail.com> Hi folks, I'm trying out this idea of "outside-in" and writing specs for my views first. Being a person who generally starts with some scribbles of a user interface and moves right to models, this has yet to be fun, but I'm giving it a shot. My question: I'm trying to specify that an index page should show a list of things, each with a link to a delete action. How would my have_tag (or whatever I should be using) look like? Thanks, Edward From hans at degraaff.org Sun Jul 22 03:05:00 2007 From: hans at degraaff.org (Hans de Graaff) Date: Sun, 22 Jul 2007 09:05:00 +0200 Subject: [rspec-users] have_tag for href with specific link? In-Reply-To: <46A30097.8040702@gmail.com> References: <46A30097.8040702@gmail.com> Message-ID: <1185087900.25622.2.camel@ip6-localhost> On Sun, 2007-07-22 at 03:00 -0400, Edward Ocampo-Gooding wrote: > My question: I'm trying to specify that an index page should show a list > of things, each with a link to a delete action. How would my have_tag > (or whatever I should be using) look like? have_tag just wraps assert_select from Rails, so you can use all its goodness to select specific DOM elements. In your case something like this should work: response.should have_tag('a[href^=/stuff/delete]') The ^= matches the beginning of the argument. Check the assert_select docs for all the possible ways to match DOM elements. Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/rspec-users/attachments/20070722/58e17cd8/attachment.bin From bosshoff at gmail.com Sun Jul 22 08:39:38 2007 From: bosshoff at gmail.com (Chris Hoffman) Date: Sun, 22 Jul 2007 08:39:38 -0400 Subject: [rspec-users] Rails' fixtures suck! But what about something like this? In-Reply-To: References: Message-ID: <359ebde50707220539p5f1d182t4b2281ad2bae39ef@mail.gmail.com> Have you tried just using fixture scenarios? Did it work? On 5/21/07, Carl Lerche wrote: > Sorry about the very long email, but this is a hairy topic that's been > annoying me for some time and I decided to try to do something about. > Also, if you got this twice, I apologize too, but it didn't seem to > have successfully gone out the first time. > > Background: > ---------- > > I've been dealing with Rails for about a year and a half now. I've > been using Rails' built in testing framework, and it's fine... until I > really have to start dealing with the fixtures. I am currently working > on an application that really focuses on selecting data using complex > logic. The only way to test the application in a meaningful way is by > using a large number of fixtures. This has become a real nightmare to > manage and I almost am spending more time keeping the fixtures up to > date than I am coding or testing. So, I took a moment, stepped back, > and took a good look at how I could I could improve fixtures to make > my life a lot easier. > > I have gotten a quick and dirty prototype of my solution running, but > before I really roll up my sleeves and start polishing it up, I > thought I would try to get some suggestions from the community. > > Overview: > --------- > > In my experience, the current fixture framework has three main problems: > > - There is no way to create different version of fixtures. What I mean > by this is that you only can have one users.yml file even if your > tests depend on different initial conditions. What this usually means > is that you will just keep tagging on to the end of users.yml even > though it is not the most efficient way to do it. > - Managing relationships between tables is a really big pain. One must > manually keep track of IDs. This can quickly become a major headache. > - There is no clean way to quickly generate data. If I want 50 > records that I could easily generate in a loop, I still gotta write > them by hand (at least, I wasn't able to figure out how to add loops > to my yaml files in a clean way). > - There is a lot of repetition. No way to follow DRY. > > Solution: > --------- > > + Versioned Fixtures > > First, to address the fixture "versions", I thought the easiest way to > do this would be scenarios (I was inspired from fixture-scenarios). > The way fixtures could be laid out is as follows: > > + specs > |- fixtures > |- global > |- only_one_signed_up_user > |- lots_of_posts_in_los_angeles > |- ... > > All global fixtures (fixtures that should be loaded before every spec) > go into global, then, for each different scenario, there is a > directory created with the relevant fixtures in there. Then, in the > specs, you could do the following > > ------------------------------- > require File.dirname(__FILE__) + '/../spec_helper' > > describe User, :when => :only_one_signed_up_user do > > it "should be the only user" do > User.count.should == 1 > end > end > ------------------------------- > > The key part here would be the :when => :scenario_name option to the > describe method. > > + Writing the fixtures > > Writing fixtures with YAML is quite ugly. I think a better way to do > it would be using a DSL, but coming up with a good syntax is hard. > This is where I am the most hesitant. I have two "options" and I was > wondering if people could comment on them and give me some feedback > and suggestions. > > - The first option is how I started out: http://pastie.caboo.se/63359 > > In this option, fixtures for multiple tables can be written in a > single file. You would start out by using the _create_ method to tell > the parser what table the fixtures are for and you could also specify > :with, which would set default attributes for fixtures. > > You could also nest fixtures in order to easily scope them (see the > last user fixture how I specified nested post fixtures). > > - The second option is what I currently prefer: http://pastie.caboo.se/63361 > > In this option, I keep the one table per file concept that is > currently used. As such, we don't need to specify what table we want > to use before hand. I make available a with_options method which lets > you set default attributes for fixtures. It's also easy to create > loops to automatically generate fixtures, as I show in the second half > of the file. The f method is the actual method for creating a fixture. > it takes a name as a string and a block in which the attributes of the > fixtures are specified. However, the method_missing method is > implemented to handle any missing methods and use that to create > fixtures too as seen with fixture_name { ... } > > + Dealing with relationships > > I think what I hate the most about fixtures right now is having to > deal with table relationships. Having to keep track of IDs myself is > horrible. So, I thought that the easiest way to do this is making the > table_name(:fixture_name) method available straight inside the > fixtures. So, if I have a user model that has a location associated > with it (let's say a zip code, longitude, and latitude), instead of > having to copy / paste that data across fixtures, I can do the > following: > > ------------------------------- > local_guy { > zip_id zips(:portland) > longitude zips(:portland).longitude > latitude zips(:portland).latitude > } > ------------------------------- > > This is much easier to deal with than the other way around. This also > introduces dependencies between fixtures, I thought the easiest way to > handle it would be adding a fixture_order configuration: > > ------------------------------- > Spec::Runner.configure do |config| > config.fixture_order = :zips, :categories, :users, :posts > end > ------------------------------- > > + What's not solved with this > > I haven't figured out a good way to handle counter_cache columns. > Right now, this would still require you to manually count how many > fixtures you have associated with a parent and add that to the > counter_cache column. Any ideas of a better way to do this? > > Well, that's all I came up with. I'm going to keep hacking away at > this and hopefully you all have some feedback to improve this concept. > > -- > EPA Rating: 3000 Lines of Code / Gallon (of coffee) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From edward.og at gmail.com Sun Jul 22 11:10:12 2007 From: edward.og at gmail.com (Edward Ocampo-Gooding) Date: Sun, 22 Jul 2007 11:10:12 -0400 Subject: [rspec-users] have_tag for href with specific link? In-Reply-To: <1185087900.25622.2.camel@ip6-localhost> References: <46A30097.8040702@gmail.com> <1185087900.25622.2.camel@ip6-localhost> Message-ID: <46A37354.1020902@gmail.com> Hans de Graaff wrote: > On Sun, 2007-07-22 at 03:00 -0400, Edward Ocampo-Gooding wrote: > >> My question: I'm trying to specify that an index page should show a list >> of things, each with a link to a delete action. How would my have_tag >> (or whatever I should be using) look like? > > have_tag just wraps assert_select from Rails, so you can use all its > goodness to select specific DOM elements. In your case something like > this should work: > > response.should have_tag('a[href^=/stuff/delete]') > > The ^= matches the beginning of the argument. Check the assert_select > docs for all the possible ways to match DOM elements. Right on. Thanks Hans. From court3nay at gmail.com Sun Jul 22 12:55:32 2007 From: court3nay at gmail.com (court3nay) Date: Sun, 22 Jul 2007 09:55:32 -0700 Subject: [rspec-users] Rails' fixtures suck! But what about something like this? In-Reply-To: <359ebde50707220539p5f1d182t4b2281ad2bae39ef@mail.gmail.com> References: <359ebde50707220539p5f1d182t4b2281ad2bae39ef@mail.gmail.com> Message-ID: Please see http://dev.rubyonrails.org/tickets/6424 for further code on fixtures and foreign keys. You might also be interested in the ar_fixtures plugin from topfunky to dump fixtures from dev to yaml. In most cases I'm using mocks and stubbing rather than canned data. Its much easier IMO to create a bunch of objects as you need them. That being said, fixtures are far from a "solved problem" and I look forward to your plugin. ------- Courtenay On Jul 22, 2007, at 5:39 AM, "Chris Hoffman" wrote: > Have you tried just using fixture scenarios? Did it work? > > On 5/21/07, Carl Lerche wrote: >> Sorry about the very long email, but this is a hairy topic that's >> been >> annoying me for some time and I decided to try to do something about. >> Also, if you got this twice, I apologize too, but it didn't seem to >> have successfully gone out the first time. >> >> Background: >> ---------- >> >> I've been dealing with Rails for about a year and a half now. I've >> been using Rails' built in testing framework, and it's fine... >> until I >> really have to start dealing with the fixtures. I am currently >> working >> on an application that really focuses on selecting data using complex >> logic. The only way to test the application in a meaningful way is by >> using a large number of fixtures. This has become a real nightmare to >> manage and I almost am spending more time keeping the fixtures up to >> date than I am coding or testing. So, I took a moment, stepped back, >> and took a good look at how I could I could improve fixtures to make >> my life a lot easier. >> >> I have gotten a quick and dirty prototype of my solution running, but >> before I really roll up my sleeves and start polishing it up, I >> thought I would try to get some suggestions from the community. >> >> Overview: >> --------- >> >> In my experience, the current fixture framework has three main >> problems: >> >> - There is no way to create different version of fixtures. What I >> mean >> by this is that you only can have one users.yml file even if your >> tests depend on different initial conditions. What this usually means >> is that you will just keep tagging on to the end of users.yml even >> though it is not the most efficient way to do it. >> - Managing relationships between tables is a really big pain. One >> must >> manually keep track of IDs. This can quickly become a major headache. >> - There is no clean way to quickly generate data. If I want 50 >> records that I could easily generate in a loop, I still gotta write >> them by hand (at least, I wasn't able to figure out how to add loops >> to my yaml files in a clean way). >> - There is a lot of repetition. No way to follow DRY. >> >> Solution: >> --------- >> >> + Versioned Fixtures >> >> First, to address the fixture "versions", I thought the easiest way >> to >> do this would be scenarios (I was inspired from fixture-scenarios). >> The way fixtures could be laid out is as follows: >> >> + specs >> |- fixtures >> |- global >> |- only_one_signed_up_user >> |- lots_of_posts_in_los_angeles >> |- ... >> >> All global fixtures (fixtures that should be loaded before every >> spec) >> go into global, then, for each different scenario, there is a >> directory created with the relevant fixtures in there. Then, in the >> specs, you could do the following >> >> ------------------------------- >> require File.dirname(__FILE__) + '/../spec_helper' >> >> describe User, :when => :only_one_signed_up_user do >> >> it "should be the only user" do >> User.count.should == 1 >> end >> end >> ------------------------------- >> >> The key part here would be the :when => :scenario_name option to the >> describe method. >> >> + Writing the fixtures >> >> Writing fixtures with YAML is quite ugly. I think a better way to do >> it would be using a DSL, but coming up with a good syntax is hard. >> This is where I am the most hesitant. I have two "options" and I was >> wondering if people could comment on them and give me some feedback >> and suggestions. >> >> - The first option is how I started out: http://pastie.caboo.se/63359 >> >> In this option, fixtures for multiple tables can be written in a >> single file. You would start out by using the _create_ method to tell >> the parser what table the fixtures are for and you could also specify >> :with, which would set default attributes for fixtures. >> >> You could also nest fixtures in order to easily scope them (see the >> last user fixture how I specified nested post fixtures). >> >> - The second option is what I currently prefer: http://pastie.caboo.se/63361 >> >> In this option, I keep the one table per file concept that is >> currently used. As such, we don't need to specify what table we want >> to use before hand. I make available a with_options method which lets >> you set default attributes for fixtures. It's also easy to create >> loops to automatically generate fixtures, as I show in the second >> half >> of the file. The f method is the actual method for creating a >> fixture. >> it takes a name as a string and a block in which the attributes of >> the >> fixtures are specified. However, the method_missing method is >> implemented to handle any missing methods and use that to create >> fixtures too as seen with fixture_name { ... } >> >> + Dealing with relationships >> >> I think what I hate the most about fixtures right now is having to >> deal with table relationships. Having to keep track of IDs myself is >> horrible. So, I thought that the easiest way to do this is making the >> table_name(:fixture_name) method available straight inside the >> fixtures. So, if I have a user model that has a location associated >> with it (let's say a zip code, longitude, and latitude), instead of >> having to copy / paste that data across fixtures, I can do the >> following: >> >> ------------------------------- >> local_guy { >> zip_id zips(:portland) >> longitude zips(:portland).longitude >> latitude zips(:portland).latitude >> } >> ------------------------------- >> >> This is much easier to deal with than the other way around. This also >> introduces dependencies between fixtures, I thought the easiest way >> to >> handle it would be adding a fixture_order configuration: >> >> ------------------------------- >> Spec::Runner.configure do |config| >> config.fixture_order = :zips, :categories, :users, :posts >> end >> ------------------------------- >> >> + What's not solved with this >> >> I haven't figured out a good way to handle counter_cache columns. >> Right now, this would still require you to manually count how many >> fixtures you have associated with a parent and add that to the >> counter_cache column. Any ideas of a better way to do this? >> >> Well, that's all I came up with. I'm going to keep hacking away at >> this and hopefully you all have some feedback to improve this >> concept. >> >> -- >> EPA Rating: 3000 Lines of Code / Gallon (of coffee) >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Mon Jul 23 22:03:21 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 23 Jul 2007 22:03:21 -0400 Subject: [rspec-users] Dealing with nested/namespaced classes w/ describe Message-ID: <3CC6E547-43F5-4DA7-80CD-2A38DA6799F9@railsnewbie.com> Hi all, Just wondering about this: I've been dealing with classes/modules nested in several layers of namespaces. Here would be an example of a describe block: describe ClassOne::ClassTwo::ClassThree, "description here" do ... end What would be the easiest way to write something a little more terse, like: describe ClassThree, "description here" do ... end If this has come up before, just tell me to google. Thanks for your time, Scott Taylor From philodespotos at gmail.com Mon Jul 23 22:15:29 2007 From: philodespotos at gmail.com (Kyle Hargraves) Date: Mon, 23 Jul 2007 21:15:29 -0500 Subject: [rspec-users] Dealing with nested/namespaced classes w/ describe In-Reply-To: <3CC6E547-43F5-4DA7-80CD-2A38DA6799F9@railsnewbie.com> References: <3CC6E547-43F5-4DA7-80CD-2A38DA6799F9@railsnewbie.com> Message-ID: <46A560C1.503@gmail.com> Scott Taylor wrote: > Hi all, > > Just wondering about this: I've been dealing with classes/modules > nested in several layers of namespaces. Here would be an example of > a describe block: > > describe ClassOne::ClassTwo::ClassThree, "description here" do > ... > end > > What would be the easiest way to write something a little more terse, > like: > > describe ClassThree, "description here" do > ... > end > > If this has come up before, just tell me to google. > > Thanks for your time, > > Scott Taylor You can put the descriptions inside of modules. AFAICT, this has no effect on how anything functions, it just lets you drop the namespacing ugliness from your code: module SomeProject class SomeClass end end module SomeProject describe SomeClass, "something or other" do end end Kyle From mailing_lists at railsnewbie.com Tue Jul 24 00:12:36 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 24 Jul 2007 00:12:36 -0400 Subject: [rspec-users] Dealing with nested/namespaced classes w/ describe In-Reply-To: <46A560C1.503@gmail.com> References: <3CC6E547-43F5-4DA7-80CD-2A38DA6799F9@railsnewbie.com> <46A560C1.503@gmail.com> Message-ID: <112289E4-0A2B-4107-9838-4C0380664F32@railsnewbie.com> Ah. Thank you. That is just a wonderful solution. Much better than the solution of redefining a new constant. Best, Scott On Jul 23, 2007, at 10:15 PM, Kyle Hargraves wrote: > Scott Taylor wrote: >> Hi all, >> >> Just wondering about this: I've been dealing with classes/modules >> nested in several layers of namespaces. Here would be an example of >> a describe block: >> >> describe ClassOne::ClassTwo::ClassThree, "description here" do >> ... >> end >> >> What would be the easiest way to write something a little more terse, >> like: >> >> describe ClassThree, "description here" do >> ... >> end >> >> If this has come up before, just tell me to google. >> >> Thanks for your time, >> >> Scott Taylor > > You can put the descriptions inside of modules. AFAICT, this has no > effect on how anything functions, it just lets you drop the > namespacing > ugliness from your code: > > module SomeProject > class SomeClass > end > end > > module SomeProject > > describe SomeClass, "something or other" do > end > > end > > Kyle > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From raasdnil at gmail.com Tue Jul 24 07:53:18 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Tue, 24 Jul 2007 21:53:18 +1000 Subject: [rspec-users] Mocking Resolv::DNS? Message-ID: <57a815bf0707240453p65d016b2w8addcb05539bf66d@mail.gmail.com> Hello Rspecers, I have a rails project where I am calling Resolv::DNS.open and then using the block to check a domain name. The code snippet in question is: domain = "mytest.com" Resolv::DNS.open do |dns| @mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX) end I obviously want to stub this out, especially for speed but can't quite work out how. I have done: >From what I can tell, Resolv::DNS first is receiving :open and it will then be yielding instances of Resolv::DNS to be using inside the block. So, my last unsuccessfull attempt at mocking this out is: @dns = mock(Resolv::DNS) Resolv::DNS.should_receive(:open).and_return([@dns]) @dns.should_receive(:getresources).and_return("MX Record") The errors I am getting are not about mocks receiving unexpected messages. The :open message mock gets called. The second one (on @dns.should_receive(:getresources) also does not complain. But @mx in the above code ends up as nil, when I would think it should end up as "MX Record". Any pointers? Regards Mikel -- http://www.blognow.com.au/q From pergesu at gmail.com Tue Jul 24 08:12:54 2007 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 24 Jul 2007 06:12:54 -0600 Subject: [rspec-users] Mocking Resolv::DNS? In-Reply-To: <57a815bf0707240453p65d016b2w8addcb05539bf66d@mail.gmail.com> References: <57a815bf0707240453p65d016b2w8addcb05539bf66d@mail.gmail.com> Message-ID: <810a540e0707240512u1968f5dek156ca312e441ef9b@mail.gmail.com> On 7/24/07, Mikel Lindsaar wrote: > Hello Rspecers, > > I have a rails project where I am calling Resolv::DNS.open and then > using the block to check a domain name. > > The code snippet in question is: > > domain = "mytest.com" > Resolv::DNS.open do |dns| > @mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX) > end > > I obviously want to stub this out, especially for speed but can't > quite work out how. > > I have done: > > >From what I can tell, Resolv::DNS first is receiving :open and it will > then be yielding instances of Resolv::DNS to be using inside the > block. > > So, my last unsuccessfull attempt at mocking this out is: > > @dns = mock(Resolv::DNS) > Resolv::DNS.should_receive(:open).and_return([@dns]) > @dns.should_receive(:getresources).and_return("MX Record") > > The errors I am getting are not about mocks receiving unexpected > messages. The :open message mock gets called. The second one (on > @dns.should_receive(:getresources) also does not complain. > > But @mx in the above code ends up as nil, when I would think it should > end up as "MX Record". > > Any pointers? > > Regards > > Mikel > > -- > http://www.blognow.com.au/q > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I'm not sure if this will work, but try Resolv::DNS.should_receive(:open).and_yield(@dns) Pat From raasdnil at gmail.com Tue Jul 24 09:02:38 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Tue, 24 Jul 2007 23:02:38 +1000 Subject: [rspec-users] Mocking Resolv::DNS? In-Reply-To: <810a540e0707240512u1968f5dek156ca312e441ef9b@mail.gmail.com> References: <57a815bf0707240453p65d016b2w8addcb05539bf66d@mail.gmail.com> <810a540e0707240512u1968f5dek156ca312e441ef9b@mail.gmail.com> Message-ID: <57a815bf0707240602n4df6eaddj7c78ec43b627233a@mail.gmail.com> Thank you, works perfectly! Regards Mikel On 7/24/07, Pat Maddox wrote: > On 7/24/07, Mikel Lindsaar wrote: > > Hello Rspecers, > > > > I have a rails project where I am calling Resolv::DNS.open and then > > using the block to check a domain name. > > > > The code snippet in question is: > > > > domain = "mytest.com" > > Resolv::DNS.open do |dns| > > @mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX) > > end > > > > I obviously want to stub this out, especially for speed but can't > > quite work out how. > > > > I have done: > > > > >From what I can tell, Resolv::DNS first is receiving :open and it will > > then be yielding instances of Resolv::DNS to be using inside the > > block. > > > > So, my last unsuccessfull attempt at mocking this out is: > > > > @dns = mock(Resolv::DNS) > > Resolv::DNS.should_receive(:open).and_return([@dns]) > > @dns.should_receive(:getresources).and_return("MX Record") > > > > The errors I am getting are not about mocks receiving unexpected > > messages. The :open message mock gets called. The second one (on > > @dns.should_receive(:getresources) also does not complain. > > > > But @mx in the above code ends up as nil, when I would think it should > > end up as "MX Record". > > > > Any pointers? > > > > Regards > > > > Mikel > > > > -- > > http://www.blognow.com.au/q > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > I'm not sure if this will work, but try > > Resolv::DNS.should_receive(:open).and_yield(@dns) > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Tue Jul 24 09:07:30 2007 From: has.sox at gmail.com (Daniel N) Date: Tue, 24 Jul 2007 23:07:30 +1000 Subject: [rspec-users] Mock or Stub strategy for validates_uniqueness_of Message-ID: <2fff50390707240607x7686c9e3u6779c8e09ff38305@mail.gmail.com> Hi, I'm a bit stuck with mocking a unit test of a join model with regards to a validates_uniqueness_of clause. I have class Book < AR:B has_many :clippings various validates_presence_of etc end class Clip < AR:B has_many :clippings various validates_presence_of etc end class Clipping < AR:B belongs_to :book belongs_to :clip validates_uniqueness_of :clip_id, :scope => :book_id end What I want to do is just confirm that the validates uniqueness_of clause is set and functioning correctly in the spec for the clipping model. So if I was using fixtures I would do something like it "should not allow duplicate clips in the same book" do clip = clips( :some_clip ) book = books( :some_book ) lambda do clipping = Clipping.create( :clip => clip, :book => book ) end.should change( Clipping, :count ).by( 1 ) lambda do clipping = Clipping.create( :clip => clip, :book => ) clipping.should_not be_valid end.should_not change( Clipping, :count ) end Any hints as to how to do this without using fixtures? Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070724/d3118a91/attachment-0001.html From work at ashleymoran.me.uk Tue Jul 24 09:42:20 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 24 Jul 2007 14:42:20 +0100 Subject: [rspec-users] Mock or Stub strategy for validates_uniqueness_of In-Reply-To: <2fff50390707240607x7686c9e3u6779c8e09ff38305@mail.gmail.com> References: <2fff50390707240607x7686c9e3u6779c8e09ff38305@mail.gmail.com> Message-ID: <2C4C4237-7B54-44AD-A1F5-3C3E16A1CDE2@ashleymoran.me.uk> On 24 Jul 2007, at 14:07, Daniel N wrote: > Any hints as to how to do this without using fixtures? I did this literally minutes ago. I don't use fixtures at all, ever. Instead I put the data in the before block, eg: describe Purchase, "assigned to a Quote that already has a saved purchase" do before(:each) do @dealer = Dealer.create!(:name => "Dealer1", :external_identifier => "D123") @site = Site.create!(:hostname => "my.host.name", :dealer => @dealer) @provider = Provider.create!(:name => "Provider1") @product = Product.create!(:name => "Product1", :provider => @provider) @applicant = Applicant.create!(:first_name => "Fred", :last_name => "Flinstone", :email => "fred at flinstone.com", :telephone_home => "01782 123456") @quote_parameters = QuoteParameters.create!(:term => 36, :applicant => @applicant, :product => @product, :site => @site) @quote = InsuranceQuote.create!(:valid_until => 1.days.from_now, :quote_parameters => @quote_parameters, :premium => 250) Purchase.create!(:quote => @quote, :amount_financed => 200) end it "should be invalid" do purchase = Purchase.new(:quote => @quote, :amount_collected_by_card => "value") purchase.should_not be_valid purchase.errors.on(:quote_id).should_not be_nil end end Comments welcome on whether this is a good way to do this. (I know that the above doesn't test my database unique constraint, which I don't do in this case come to think of it, but I try to keep DB specs separate, hard as that may be sometimes.) Ashley From has.sox at gmail.com Tue Jul 24 09:49:47 2007 From: has.sox at gmail.com (Daniel N) Date: Tue, 24 Jul 2007 23:49:47 +1000 Subject: [rspec-users] Mock or Stub strategy for validates_uniqueness_of In-Reply-To: <2C4C4237-7B54-44AD-A1F5-3C3E16A1CDE2@ashleymoran.me.uk> References: <2fff50390707240607x7686c9e3u6779c8e09ff38305@mail.gmail.com> <2C4C4237-7B54-44AD-A1F5-3C3E16A1CDE2@ashleymoran.me.uk> Message-ID: <2fff50390707240649s7a4e35fbi99b5c091369f607d@mail.gmail.com> On 7/24/07, Ashley Moran wrote: > > > On 24 Jul 2007, at 14:07, Daniel N wrote: > > > Any hints as to how to do this without using fixtures? > > I did this literally minutes ago. I don't use fixtures at all, > ever. Instead I put the data in the before block, eg: > > describe Purchase, "assigned to a Quote that already has a saved > purchase" do > before(:each) do > @dealer = Dealer.create!(:name => > "Dealer1", :external_identifier => "D123") > @site = Site.create!(:hostname => "my.host.name", :dealer => > @dealer) > > @provider = Provider.create!(:name => "Provider1") > @product = Product.create!(:name => "Product1", :provider => > @provider) > @applicant = Applicant.create!(:first_name => "Fred", :last_name > => "Flinstone", :email => "fred at flinstone.com", :telephone_home => > "01782 123456") > @quote_parameters = QuoteParameters.create!(:term => > 36, :applicant => @applicant, :product => @product, :site => @site) > @quote = InsuranceQuote.create!(:valid_until => > 1.days.from_now, :quote_parameters => @quote_parameters, :premium => > 250) > Purchase.create!(:quote => @quote, :amount_financed => 200) > end > > it "should be invalid" do > purchase = Purchase.new(:quote => > @quote, :amount_collected_by_card => "value") > purchase.should_not be_valid > purchase.errors.on(:quote_id).should_not be_nil > end > end > > Comments welcome on whether this is a good way to do this. (I know > that the above doesn't test my database unique constraint, which I > don't do in this case come to think of it, but I try to keep DB specs > separate, hard as that may be sometimes.) > > Ashley That looks like the kind of thing I was initially thinking of, but I started to think that having all those objects being created in a non-related spec could lead to trouble. If I change what makes any of those objects valid, these supposedly unrelated specs will then break. I want to try and keep everything seperate, but in this case it seems that things are interdependent. Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070724/53e8aedd/attachment.html From has.sox at gmail.com Tue Jul 24 10:29:50 2007 From: has.sox at gmail.com (Daniel N) Date: Wed, 25 Jul 2007 00:29:50 +1000 Subject: [rspec-users] Possible Bug Message-ID: <2fff50390707240729n77ec5179w5de2302cc6abb5f1@mail.gmail.com> I'm trying to test some code that has validates each and I've got a very strange failure Mock 'Book_1027' expected :store_with_privacy? with (#) but received it with (#) The Spec it "should check that a book can save a clip" do @user = mock_model( User, :id => 3 ) @clip = mock_model( Clip, :id => 1, :privacy => :public, :user => @user ) @book = mock_model( Book, :id => 2, :privacy => :public, :user => @user, :user_id => @user.id ) @book.should_receive( :store_with_privacy? ).with( @clip ) clipping = Clipping.new( valid_clipping_attributes.with( :clip => @clip, :book => @book ) ) clipping.valid? end And the model class Clipping < AR:B belongs_to :clip belongs_to :book ... validates_each :clip do |model, attr, value| if !model.book.nil? && !model.clip.nil? if !model.book.store_with_privacy?( model.clip ) model.errors.add( :clip, "You can't add this item to this book" ) end end end ... end Any thoughts on what might be causing that? Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070725/dd9d8127/attachment.html From has.sox at gmail.com Tue Jul 24 10:40:41 2007 From: has.sox at gmail.com (Daniel N) Date: Wed, 25 Jul 2007 00:40:41 +1000 Subject: [rspec-users] Mock or Stub strategy for validates_uniqueness_of In-Reply-To: <2fff50390707240649s7a4e35fbi99b5c091369f607d@mail.gmail.com> References: <2fff50390707240607x7686c9e3u6779c8e09ff38305@mail.gmail.com> <2C4C4237-7B54-44AD-A1F5-3C3E16A1CDE2@ashleymoran.me.uk> <2fff50390707240649s7a4e35fbi99b5c091369f607d@mail.gmail.com> Message-ID: <2fff50390707240740y22ac9647v9dd18bb0c97e778e@mail.gmail.com> On 7/24/07, Daniel N wrote: > > > > On 7/24/07, Ashley Moran wrote: > > > > > > On 24 Jul 2007, at 14:07, Daniel N wrote: > > > > > Any hints as to how to do this without using fixtures? > > > > I did this literally minutes ago. I don't use fixtures at all, > > ever. Instead I put the data in the before block, eg: > > > > describe Purchase, "assigned to a Quote that already has a saved > > purchase" do > > before(:each) do > > @dealer = Dealer.create!(:name => > > "Dealer1", :external_identifier => "D123") > > @site = Site.create!(:hostname => "my.host.name", :dealer => > > @dealer) > > > > @provider = Provider.create!(:name => "Provider1") > > @product = Product.create!(:name => "Product1", :provider => > > @provider) > > @applicant = Applicant.create!(:first_name => "Fred", :last_name > > => "Flinstone", :email => " fred at flinstone.com", :telephone_home => > > "01782 123456") > > @quote_parameters = QuoteParameters.create!(:term => > > 36, :applicant => @applicant, :product => @product, :site => @site) > > @quote = InsuranceQuote.create!(:valid_until => > > 1.days.from_now, :quote_parameters => @quote_parameters, :premium => > > 250) > > Purchase.create!(:quote => @quote, :amount_financed => 200) > > end > > > > it "should be invalid" do > > purchase = Purchase.new(:quote => > > @quote, :amount_collected_by_card => "value") > > purchase.should_not be_valid > > purchase.errors.on (:quote_id).should_not be_nil > > end > > end > > > > Comments welcome on whether this is a good way to do this. (I know > > that the above doesn't test my database unique constraint, which I > > don't do in this case come to think of it, but I try to keep DB specs > > separate, hard as that may be sometimes.) > > > > Ashley > > > That looks like the kind of thing I was initially thinking of, but I > started to think that having all those objects being created in a > non-related spec could lead to trouble. If I change what makes any of those > objects valid, these supposedly unrelated specs will then break. > > I want to try and keep everything seperate, but in this case it seems that > things are interdependent. > > Cheers > Daniel > What I've ended up doing is the following test it "should have a uniq clip_id for a given book" do lambda do Clipping.create( valid_clipping_attributes ) Clipping.create( valid_clipping_attributes ) end.should change( Clipping, :count ).by( 1 ) end It hits the database, but the valid_clipping_attributes are mocks that are used throughout the spec so it's divorced from the other specs. If there are any better ideas I'm open to them. Thanx for the response Ashley. Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070725/d701aec4/attachment.html From has.sox at gmail.com Tue Jul 24 10:45:56 2007 From: has.sox at gmail.com (Daniel N) Date: Wed, 25 Jul 2007 00:45:56 +1000 Subject: [rspec-users] Possible Bug In-Reply-To: <2fff50390707240729n77ec5179w5de2302cc6abb5f1@mail.gmail.com> References: <2fff50390707240729n77ec5179w5de2302cc6abb5f1@mail.gmail.com> Message-ID: <2fff50390707240745s170949fcpf6870f863b4b0cd3@mail.gmail.com> On 7/25/07, Daniel N wrote: > > I'm trying to test some code that has validates each and I've got a very > strange failure > > Mock 'Book_1027' expected :store_with_privacy? with (# @name="Clip_1025">) but received it with (# @name="Clip_1025">) > > The Spec > > it "should check that a book can save a clip" do > @user = mock_model( User, :id => 3 ) > @clip = mock_model( Clip, :id => 1, :privacy => :public, :user => > @user ) > @book = mock_model( Book, :id => 2, :privacy => :public, :user => > @user, :user_id => @user.id ) > > @book.should_receive( :store_with_privacy? ).with( @clip ) > > clipping = Clipping.new( valid_clipping_attributes.with( :clip => > @clip, :book => @book ) ) > clipping.valid? > end > > And the model > > class Clipping < AR:B > belongs_to :clip > belongs_to :book > ... > > validates_each :clip do |model, attr, value| > if !model.book.nil? && !model.clip.nil? > if !model.book.store_with_privacy?( model.clip ) > model.errors.add( :clip, "You can't add this item to this book" ) > end > end > end > > ... > end > > Any thoughts on what might be causing that? > > Cheers > Daniel > I've also found that by stubbing the @book.store_with_privacy? in a before block, and then having an example that just mocks that method @book.should_receive( :store_with_privacy? ).with( @clip ) makes it act differently. In this case I get Mock 'Book_1026' expected :store_with_privacy? with (#) once, but received it 0 times It seems that the stub is taking precedence over the should_receive call. Is this expected behaviour? Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070725/4f74b415/attachment-0001.html From dchelimsky at gmail.com Tue Jul 24 11:01:48 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 24 Jul 2007 11:01:48 -0400 Subject: [rspec-users] Possible Bug In-Reply-To: <2fff50390707240745s170949fcpf6870f863b4b0cd3@mail.gmail.com> References: <2fff50390707240729n77ec5179w5de2302cc6abb5f1@mail.gmail.com> <2fff50390707240745s170949fcpf6870f863b4b0cd3@mail.gmail.com> Message-ID: <57c63afe0707240801l1ca0625l4f8d36a986effe9d@mail.gmail.com> On 7/24/07, Daniel N wrote: > > > On 7/25/07, Daniel N wrote: > > I'm trying to test some code that has validates each and I've got a very > strange failure > > > > Mock 'Book_1027' expected :store_with_privacy? with (# @name="Clip_1025">) but received it with (# @name="Clip_1025">) > > > > The Spec > > > > it "should check that a book can save a clip" do > > @user = mock_model( User, :id => 3 ) > > @clip = mock_model( Clip, :id => 1, :privacy => :public, :user => > @user ) > > @book = mock_model( Book, :id => 2, :privacy => :public, :user => > @user, :user_id => @user.id ) > > > > @book.should_receive( :store_with_privacy? ).with( @clip ) > > > > clipping = Clipping.new( valid_clipping_attributes.with( :clip => > @clip, :book => @book ) ) > > clipping.valid? > > end > > > > And the model > > > > class Clipping < AR:B > > belongs_to :clip > > belongs_to :book > > ... > > > > validates_each :clip do |model, attr, value| > > if !model.book.nil? && !model.clip.nil? > > if !model.book.store_with_privacy?( model.clip ) > > model.errors.add( :clip, "You can't add this item to this book" ) > > end > > end > > end > > > > ... > > end > > > > Any thoughts on what might be causing that? > > > > Cheers > > Daniel > > > > > I've also found that by stubbing the @book.store_with_privacy? in a before > block, and then having an example that just mocks that method > > @book.should_receive( :store_with_privacy? ).with( @clip ) > > makes it act differently. In this case I get > > Mock 'Book_1026' expected :store_with_privacy? with (# @name="Clip_1025">) once, but received it 0 times > > It seems that the stub is taking precedence over the should_receive call. > > Is this expected behaviour? Absolutely not. Please submit a bug report to the tracker on this, with the examples you have here. http://rubyforge.org/tracker/index.php?group_id=797 Thanks, David > > Cheers > Daniel > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Tue Jul 24 11:18:00 2007 From: has.sox at gmail.com (Daniel N) Date: Wed, 25 Jul 2007 01:18:00 +1000 Subject: [rspec-users] Possible Bug In-Reply-To: <57c63afe0707240801l1ca0625l4f8d36a986effe9d@mail.gmail.com> References: <2fff50390707240729n77ec5179w5de2302cc6abb5f1@mail.gmail.com> <2fff50390707240745s170949fcpf6870f863b4b0cd3@mail.gmail.com> <57c63afe0707240801l1ca0625l4f8d36a986effe9d@mail.gmail.com> Message-ID: <2fff50390707240818s40ae2d43x2f4443baf35c84fd@mail.gmail.com> On 7/25/07, David Chelimsky wrote: > > On 7/24/07, Daniel N wrote: > > > > > > On 7/25/07, Daniel N wrote: > > > I'm trying to test some code that has validates each and I've got a > very > > strange failure > > > > > > Mock 'Book_1027' expected :store_with_privacy? with (# > @name="Clip_1025">) but received it with (# > @name="Clip_1025">) > > > > > > The Spec > > > > > > it "should check that a book can save a clip" do > > > @user = mock_model( User, :id => 3 ) > > > @clip = mock_model( Clip, :id => 1, :privacy => :public, :user => > > @user ) > > > @book = mock_model( Book, :id => 2, :privacy => :public, :user => > > @user, :user_id => @user.id ) > > > > > > @book.should_receive( :store_with_privacy? ).with( @clip ) > > > > > > clipping = Clipping.new( valid_clipping_attributes.with( :clip => > > @clip, :book => @book ) ) > > > clipping.valid? > > > end > > > > > > And the model > > > > > > class Clipping < AR:B > > > belongs_to :clip > > > belongs_to :book > > > ... > > > > > > validates_each :clip do |model, attr, value| > > > if !model.book.nil? && !model.clip.nil? > > > if !model.book.store_with_privacy?( model.clip ) > > > model.errors.add( :clip, "You can't add this item to this > book" ) > > > end > > > end > > > end > > > > > > ... > > > end > > > > > > Any thoughts on what might be causing that? > > > > > > Cheers > > > Daniel > > > > > > > > > I've also found that by stubbing the @book.store_with_privacy? in a > before > > block, and then having an example that just mocks that method > > > > @book.should_receive( :store_with_privacy? ).with( @clip ) > > > > makes it act differently. In this case I get > > > > Mock 'Book_1026' expected :store_with_privacy? with (# > @name="Clip_1025">) once, but received it 0 times > > > > It seems that the stub is taking precedence over the should_receive > call. > > > > Is this expected behaviour? > > Absolutely not. Please submit a bug report to the tracker on this, > with the examples you have here. > > http://rubyforge.org/tracker/index.php?group_id=797 > > Thanks, > David Done -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070725/74ed489c/attachment.html From dchelimsky at gmail.com Tue Jul 24 11:25:20 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 24 Jul 2007 11:25:20 -0400 Subject: [rspec-users] Possible Bug In-Reply-To: <2fff50390707240818s40ae2d43x2f4443baf35c84fd@mail.gmail.com> References: <2fff50390707240729n77ec5179w5de2302cc6abb5f1@mail.gmail.com> <2fff50390707240745s170949fcpf6870f863b4b0cd3@mail.gmail.com> <57c63afe0707240801l1ca0625l4f8d36a986effe9d@mail.gmail.com> <2fff50390707240818s40ae2d43x2f4443baf35c84fd@mail.gmail.com> Message-ID: <57c63afe0707240825y64489bd9m29ebf3528366a0ce@mail.gmail.com> On 7/24/07, Daniel N wrote: > > > > On 7/25/07, David Chelimsky wrote: > > On 7/24/07, Daniel N wrote: > > > > > > > > > On 7/25/07, Daniel N wrote: > > > > I'm trying to test some code that has validates each and I've got a > very > > > strange failure > > > > > > > > Mock 'Book_1027' expected :store_with_privacy? with (# > > @name="Clip_1025">) but received it with (# > > @name="Clip_1025">) > > > > > > > > The Spec > > > > > > > > it "should check that a book can save a clip" do > > > > @user = mock_model( User, :id => 3 ) > > > > @clip = mock_model( Clip, :id => 1, :privacy => :public, :user => > > > @user ) > > > > @book = mock_model( Book, :id => 2, :privacy => :public, :user => > > > @user, :user_id => @user.id ) > > > > > > > > @book.should_receive ( :store_with_privacy? ).with( @clip ) > > > > > > > > clipping = Clipping.new( valid_clipping_attributes.with( :clip => > > > @clip, :book => @book ) ) > > > > clipping.valid? > > > > end > > > > > > > > And the model > > > > > > > > class Clipping < AR:B > > > > belongs_to :clip > > > > belongs_to :book > > > > ... > > > > > > > > validates_each :clip do |model, attr, value| > > > > if !model.book.nil? && !model.clip.nil? > > > > if !model.book.store_with_privacy?( model.clip > ) > > > > model.errors.add( :clip, "You can't add this item to this > book" ) > > > > end > > > > end > > > > end > > > > > > > > ... > > > > end > > > > > > > > Any thoughts on what might be causing that? > > > > > > > > Cheers > > > > Daniel > > > > > > > > > > > > > I've also found that by stubbing the @book.store_with_privacy? in a > before > > > block, and then having an example that just mocks that method > > > > > > @book.should_receive ( :store_with_privacy? ).with( @clip ) > > > > > > makes it act differently. In this case I get > > > > > > Mock 'Book_1026' expected :store_with_privacy? with (# > > @name="Clip_1025">) once, but received it 0 times > > > > > > It seems that the stub is taking precedence over the should_receive > call. > > > > > > Is this expected behaviour? > > > > Absolutely not. Please submit a bug report to the tracker on this, > > with the examples you have here. > > > > http://rubyforge.org/tracker/index.php?group_id=797 > > > > Thanks, > > David > > Done Thanks > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From epugh at opensourceconnections.com Tue Jul 24 16:26:05 2007 From: epugh at opensourceconnections.com (Eric Pugh) Date: Tue, 24 Jul 2007 13:26:05 -0700 Subject: [rspec-users] Rspec on rails with out database? Message-ID: <3ED1F6E8-5ABF-470C-A1E6-1BC920A5CB85@opensourceconnections.com> Hi all, I am trying to use rspec_on_rails in a Rails app that doesn't have a database. so far I have just been faking it out by dumping in a sqlite3 database just to make Rails happy. I was using for test::unit a rake task that eliminated the calls to database prep: # Added this .rake file to keep Rake happy without a database. # Remove once a database is in the picture. ["test:units", "test:functionals", "test:integration", "recent"].each do |name| Rake::Task[name].prerequisites.clear end However, adding the spec:models etc doesn't work, I get a "Don't know how to build task 'spec:models'" error... What is the right way of faking out the database? Using one of the Mock frameworks? Eric ------------------------------------------------------- Principal OpenSource Connections Site: http://www.opensourceconnections.com Blog: http://blog.opensourceconnections.com Cell: 1-434-466-1467 From carpeaqua at gmail.com Tue Jul 24 17:46:23 2007 From: carpeaqua at gmail.com (Justin Williams) Date: Tue, 24 Jul 2007 16:46:23 -0500 Subject: [rspec-users] Mocking Access Control Message-ID: <981f96b60707241446sfa91203j5a8f804f9007f346@mail.gmail.com> I'm trying to jump on the TDD/BDD bandwagon, but am having trouble understanding how i should mock my user. The user has a habtm relationship to a roles model (acl_system2 plugin), but I'm not sure how to tell rspec about a model. My code: describe UsersController do integrate_views before(:each) do @user = mock_model(User) @user.stub!(:new_record?).and_return(false) @user.stub!(:id).and_return(666) @user.stub!(:email).and_return("john at doe.com") @user.stub!(:password).and_return("dummypassword") User.stub!(:new).and_return(@user) end it "should login as a tutor" do @user.stub!(:type).and_return("Tutor") post :login, {:login => {:email => "teamup at teamup.host", :password => "teamup"}} response.should redirect_to(:controller => "toolkit/overview", :action => "index") should_be_logged_in end it "should logout" do get :logout response.should redirect_to(:controller => "users", :action => "login") should_not_be_logged_in end protected def should_be_logged_in response.session.should_not be_nil session[:user].should_not be_nil end def should_not_be_logged_in response.session.should_not be_nil session[:user].should be_nil end end Unfortunately, the actual method its testing works fine, but my test is getting the following error: "expected redirect to {:action=>"index", :controller=>"toolkit/overview"}, got no redirect" I am pretty sure it is because I haven't set the role attribute, but I'm not sure how to establish that relationship using stubs. I tried setting mock_model(User, :roles => mock(Role, :title => "tutor")) but that didn't seem to matter. Anyone able to shed some light on this for me? Thanks. -- - Justin Williams work: http://secondgearllc.com/ play: http://carpeaqua.com From dchelimsky at gmail.com Tue Jul 24 17:51:49 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 24 Jul 2007 17:51:49 -0400 Subject: [rspec-users] Mocking Access Control In-Reply-To: <981f96b60707241446sfa91203j5a8f804f9007f346@mail.gmail.com> References: <981f96b60707241446sfa91203j5a8f804f9007f346@mail.gmail.com> Message-ID: <57c63afe0707241451h619efac8m68e49ef6661b2002@mail.gmail.com> On 7/24/07, Justin Williams wrote: > I'm trying to jump on the TDD/BDD bandwagon, but am having trouble > understanding how i should mock my user. The user has a habtm > relationship to a roles model (acl_system2 plugin), but I'm not sure > how to tell rspec about a model. > > My code: > > describe UsersController do > integrate_views > > before(:each) do > @user = mock_model(User) > @user.stub!(:new_record?).and_return(false) > @user.stub!(:id).and_return(666) > @user.stub!(:email).and_return("john at doe.com") > @user.stub!(:password).and_return("dummypassword") > User.stub!(:new).and_return(@user) > end > > it "should login as a tutor" do > @user.stub!(:type).and_return("Tutor") > post :login, {:login => {:email => "teamup at teamup.host", :password > => "teamup"}} > response.should redirect_to(:controller => "toolkit/overview", > :action => "index") > should_be_logged_in > end > > it "should logout" do > get :logout > response.should redirect_to(:controller => "users", :action => "login") > should_not_be_logged_in > end > > protected > > def should_be_logged_in > response.session.should_not be_nil > session[:user].should_not be_nil > end > > def should_not_be_logged_in > response.session.should_not be_nil > session[:user].should be_nil > end > end > > Unfortunately, the actual method its testing works fine, but my test > is getting the following error: > > "expected redirect to {:action=>"index", > :controller=>"toolkit/overview"}, got no redirect" > > I am pretty sure it is because I haven't set the role attribute, but > I'm not sure how to establish that relationship using stubs. I tried > setting mock_model(User, :roles => mock(Role, :title => "tutor")) but > that didn't seem to matter. > > Anyone able to shed some light on this for me? Would you please post the code for the actions as well? > > Thanks. > > -- > - > Justin Williams > work: http://secondgearllc.com/ > play: http://carpeaqua.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rick.tessner at gmail.com Tue Jul 24 18:10:44 2007 From: rick.tessner at gmail.com (Rick Tessner) Date: Tue, 24 Jul 2007 15:10:44 -0700 Subject: [rspec-users] spec'ing helpers that use controller Message-ID: <1185315044.11009.18.camel@localhost> Hi all, I'm in the process of creating rspecs for my helpers. One of the helpers in app/helpers/application_helper.rb looks like this: def page_name @page_name || "Define @page_name in #{controller.controller_name}::#{controller.action_name}" end The rspec is simply: it "should something" do page_name end Running ./script/spec spec/helpers/application_helper_spec.rb produces: F 1) NameError in 'ApplicationHelper hmmmm' undefined local variable or method `controller' for [RSpec example]:# /path/trunk/config/../app/helpers/application_helper.rb:21:in `page_title' ./spec/helpers/application_helper_spec.rb:6: ./script/spec:4: Finished in 0.024011 seconds 1 example, 1 failure The helper spec doesn't know about "controller". Would I have to mock the controller? If so, how? If not, what would be the solution to writing a spec for this or any helper that might use "controller"? -- Rick rick.tessner at gmail.com From court3nay at gmail.com Tue Jul 24 18:26:35 2007 From: court3nay at gmail.com (Courtenay) Date: Tue, 24 Jul 2007 15:26:35 -0700 Subject: [rspec-users] spec'ing helpers that use controller In-Reply-To: <1185315044.11009.18.camel@localhost> References: <1185315044.11009.18.camel@localhost> Message-ID: <4b430c8f0707241526t24959384hb153795592339ea7@mail.gmail.com> Does this work? ApplicationHelper.stub!(:controller).and_return mock('controller', :controller_name => 'foo') On 7/24/07, Rick Tessner wrote: > Hi all, > > I'm in the process of creating rspecs for my helpers. One of the > helpers in app/helpers/application_helper.rb looks like this: > > def page_name > @page_name || "Define @page_name in > #{controller.controller_name}::#{controller.action_name}" > end > > The rspec is simply: > > it "should something" do > page_name > end > > Running ./script/spec spec/helpers/application_helper_spec.rb produces: > > F > > 1) > NameError in 'ApplicationHelper hmmmm' > undefined local variable or method `controller' for [RSpec > example]:# > /path/trunk/config/../app/helpers/application_helper.rb:21:in > `page_title' > ./spec/helpers/application_helper_spec.rb:6: > ./script/spec:4: > > Finished in 0.024011 seconds > > 1 example, 1 failure > > The helper spec doesn't know about "controller". Would I have to mock > the controller? If so, how? If not, what would be the solution to > writing a spec for this or any helper that might use "controller"? > > -- > Rick > rick.tessner at gmail.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From carpeaqua at gmail.com Tue Jul 24 18:33:37 2007 From: carpeaqua at gmail.com (Justin Williams) Date: Tue, 24 Jul 2007 17:33:37 -0500 Subject: [rspec-users] Mocking Access Control In-Reply-To: <57c63afe0707241451h619efac8m68e49ef6661b2002@mail.gmail.com> References: <981f96b60707241446sfa91203j5a8f804f9007f346@mail.gmail.com> <57c63afe0707241451h619efac8m68e49ef6661b2002@mail.gmail.com> Message-ID: <981f96b60707241533j36cfdb90ifbb025bc6e85628e@mail.gmail.com> On 7/24/07, David Chelimsky wrote: > Would you please post the code for the actions as well? def login if request.post? begin session[:user] = User.authenticate(params[:login][:email], params[:login][:password]).id if current_user.roles.include?(Role.find_by_title("employee")) or current_user.roles.include?(Role.find_by_title("administrator")) redirect_to staff_path elsif current_user.roles.include?(Role.find_by_title("tutor")) redirect_to toolkit_path elsif current_user.roles.include?(Role.find_by_title("client")) redirect_to client_path end rescue flash[:warning] = "Your e-mail address or password is invalid." render :action => "login" end end end It should also be noted, I realized the specs have two different sets of credentials. Modifying this to use a single one doesn't correct it. I was just a bit too liberal in my cut/pasting for email. Thanks! - j From rick.tessner at gmail.com Tue Jul 24 18:37:21 2007 From: rick.tessner at gmail.com (Rick Tessner) Date: Tue, 24 Jul 2007 15:37:21 -0700 Subject: [rspec-users] spec'ing helpers that use controller In-Reply-To: <4b430c8f0707241526t24959384hb153795592339ea7@mail.gmail.com> References: <1185315044.11009.18.camel@localhost> <4b430c8f0707241526t24959384hb153795592339ea7@mail.gmail.com> Message-ID: <1185316641.11009.21.camel@localhost> Hi, On Tue, 2007-24-07 at 15:26 -0700, Courtenay wrote: > Does this work? > > ApplicationHelper.stub!(:controller).and_return mock('controller', > :controller_name => 'foo') Sadly, no. Same result: undefined local variable or method `controller' for [RSpec example]: # -- Rick rick.tessner at gmail.com From raasdnil at gmail.com Tue Jul 24 19:16:33 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Wed, 25 Jul 2007 09:16:33 +1000 Subject: [rspec-users] Mock or Stub strategy for validates_uniqueness_of In-Reply-To: <2fff50390707240740y22ac9647v9dd18bb0c97e778e@mail.gmail.com> References: <2fff50390707240607x7686c9e3u6779c8e09ff38305@mail.gmail.com> <2C4C4237-7B54-44AD-A1F5-3C3E16A1CDE2@ashleymoran.me.uk> <2fff50390707240649s7a4e35fbi99b5c091369f607d@mail.gmail.com> <2fff50390707240740y22ac9647v9dd18bb0c97e778e@mail.gmail.com> Message-ID: <57a815bf0707241616u7f484c30w39b2c9044a1a6dd3@mail.gmail.com> There would be a different way. In the idea of "Only test the code you write" all you really need to spec is that you have set the right association, because activerecord has it's own tests to ensure the uniq call works. You can do this with a call to reflect_on_association. Unfortunately that call does not return a hash, but an association object. I wrote a blog post on how to do this easily with a spec_helper.rb method that adds to_hash to reflect on association. http://www.blognow.com.au/q/67540/Reflect_on_association_one_liner_to_check_association_details.html In the end you end up with a spec that looks like this: it "should test reflection details" do association_results = { :macro => :has_many, :options => {:through => :clipping, :uniq => true}, :class_name => "nil" } Book.reflect_on_association(:clip).to_hash.should == association_results end Of course, you can add whatever values you want into the hash. I now have one of these specs at the top of pretty much every model spec. Just set up the hash with all your association rules and then this can be checked and kept track of when you are refactoring or changing code. Hope that helps. Regards Mikel On 7/25/07, Daniel N wrote: > > > > On 7/24/07, Daniel N wrote: > > > > > > > > > > On 7/24/07, Ashley Moran < work at ashleymoran.me.uk> wrote: > > > > > > On 24 Jul 2007, at 14:07, Daniel N wrote: > > > > > > > Any hints as to how to do this without using fixtures? > > > > > > I did this literally minutes ago. I don't use fixtures at all, > > > ever. Instead I put the data in the before block, eg: > > > > > > describe Purchase, "assigned to a Quote that already has a saved > > > purchase" do > > > before(:each) do > > > @dealer = Dealer.create!(:name => > > > "Dealer1", :external_identifier => "D123") > > > @site = Site.create!(:hostname => "my.host.name", :dealer => > > > @dealer) > > > > > > @provider = Provider.create!(:name => "Provider1") > > > @product = Product.create!(:name => "Product1", :provider => > > > @provider) > > > @applicant = Applicant.create!(:first_name => "Fred", :last_name > > > => "Flinstone", :email => " fred at flinstone.com", :telephone_home => > > > "01782 123456") > > > @quote_parameters = QuoteParameters.create!(:term => > > > 36, :applicant => @applicant, :product => @product, :site => @site) > > > @quote = InsuranceQuote.create!(:valid_until => > > > 1.days.from_now, :quote_parameters => @quote_parameters, :premium => > > > 250) > > > Purchase.create!(:quote => @quote, :amount_financed => 200) > > > end > > > > > > it "should be invalid" do > > > purchase = Purchase.new(:quote => > > > @quote, :amount_collected_by_card => "value") > > > purchase.should_not be_valid > > > purchase.errors.on (:quote_id).should_not be_nil > > > end > > > end > > > > > > Comments welcome on whether this is a good way to do this. (I know > > > that the above doesn't test my database unique constraint, which I > > > don't do in this case come to think of it, but I try to keep DB specs > > > separate, hard as that may be sometimes.) > > > > > > Ashley > > > > > > That looks like the kind of thing I was initially thinking of, but I > started to think that having all those objects being created in a > non-related spec could lead to trouble. If I change what makes any of those > objects valid, these supposedly unrelated specs will then break. > > > > I want to try and keep everything seperate, but in this case it seems that > things are interdependent. > > > > Cheers > > Daniel > > What I've ended up doing is the following test > > it "should have a uniq clip_id for a given book" do > lambda do > Clipping.create( valid_clipping_attributes ) > Clipping.create( valid_clipping_attributes ) > end.should change( Clipping, :count ).by( 1 ) > end > > It hits the database, but the valid_clipping_attributes are mocks that are > used throughout the spec so it's divorced from the other specs. > > If there are any better ideas I'm open to them. > > Thanx for the response Ashley. > > Daniel > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From court3nay at gmail.com Tue Jul 24 19:30:03 2007 From: court3nay at gmail.com (Courtenay) Date: Tue, 24 Jul 2007 16:30:03 -0700 Subject: [rspec-users] spec'ing helpers that use controller In-Reply-To: <1185316641.11009.21.camel@localhost> References: <1185315044.11009.18.camel@localhost> <4b430c8f0707241526t24959384hb153795592339ea7@mail.gmail.com> <1185316641.11009.21.camel@localhost> Message-ID: <4b430c8f0707241630v72d4ff78ledf155cdf594ada4@mail.gmail.com> On 7/24/07, Rick Tessner wrote: > Hi, > > On Tue, 2007-24-07 at 15:26 -0700, Courtenay wrote: > > Does this work? > > > > ApplicationHelper.stub!(:controller).and_return mock('controller', > > :controller_name => 'foo') > > Sadly, no. Same result: > > undefined local variable or method `controller' for [RSpec > example]: # specing helpers just includes the module in your spec. So you can cheat like describe "Application Helper" do helper_name :application def controller @controller end before(:each) do @controller = mock('controller') end it "should blah blah" do end end From has.sox at gmail.com Tue Jul 24 19:46:57 2007 From: has.sox at gmail.com (Daniel N) Date: Wed, 25 Jul 2007 09:46:57 +1000 Subject: [rspec-users] Mock or Stub strategy for validates_uniqueness_of In-Reply-To: <57a815bf0707241616u7f484c30w39b2c9044a1a6dd3@mail.gmail.com> References: <2fff50390707240607x7686c9e3u6779c8e09ff38305@mail.gmail.com> <2C4C4237-7B54-44AD-A1F5-3C3E16A1CDE2@ashleymoran.me.uk> <2fff50390707240649s7a4e35fbi99b5c091369f607d@mail.gmail.com> <2fff50390707240740y22ac9647v9dd18bb0c97e778e@mail.gmail.com> <57a815bf0707241616u7f484c30w39b2c9044a1a6dd3@mail.gmail.com> Message-ID: <2fff50390707241646i6183f887if425d1f6b3e92e01@mail.gmail.com> On 7/25/07, Mikel Lindsaar wrote: > > There would be a different way. > > In the idea of "Only test the code you write" all you really need to > spec is that you have set the right association, because activerecord > has it's own tests to ensure the uniq call works. > > You can do this with a call to reflect_on_association. Unfortunately > that call does not return a hash, but an association object. > > I wrote a blog post on how to do this easily with a spec_helper.rb > method that adds to_hash to reflect on association. > > > http://www.blognow.com.au/q/67540/Reflect_on_association_one_liner_to_check_association_details.html > > In the end you end up with a spec that looks like this: > > it "should test reflection details" do > > association_results = { > :macro => :has_many, > :options => {:through => :clipping, :uniq => true}, > :class_name => "nil" > } > > Book.reflect_on_association(:clip).to_hash.should == > association_results > > end > > > Of course, you can add whatever values you want into the hash. > > I now have one of these specs at the top of pretty much every model > spec. Just set up the hash with all your association rules and then > this can be checked and kept track of when you are refactoring or > changing code. > > Hope that helps. > > Regards > > Mikel Thanx Mikel. I didn't even think of using a uniq on the has_many. I was using a validates_uniquness_of :scope => 'book_id' I will definitley look into this one. Thankyou Daniel On 7/25/07, Daniel N wrote: > > > > > > > > On 7/24/07, Daniel N wrote: > > > > > > > > > > > > > > > On 7/24/07, Ashley Moran < work at ashleymoran.me.uk> wrote: > > > > > > > > On 24 Jul 2007, at 14:07, Daniel N wrote: > > > > > > > > > Any hints as to how to do this without using fixtures? > > > > > > > > I did this literally minutes ago. I don't use fixtures at all, > > > > ever. Instead I put the data in the before block, eg: > > > > > > > > describe Purchase, "assigned to a Quote that already has a saved > > > > purchase" do > > > > before(:each) do > > > > @dealer = Dealer.create!(:name => > > > > "Dealer1", :external_identifier => "D123") > > > > @site = Site.create!(:hostname => "my.host.name", :dealer => > > > > @dealer) > > > > > > > > @provider = Provider.create!(:name => "Provider1") > > > > @product = Product.create!(:name => "Product1", :provider => > > > > @provider) > > > > @applicant = Applicant.create!(:first_name => "Fred", > :last_name > > > > => "Flinstone", :email => " fred at flinstone.com", :telephone_home => > > > > "01782 123456") > > > > @quote_parameters = QuoteParameters.create!(:term => > > > > 36, :applicant => @applicant, :product => @product, :site => @site) > > > > @quote = InsuranceQuote.create!(:valid_until => > > > > 1.days.from_now, :quote_parameters => @quote_parameters, :premium => > > > > 250) > > > > Purchase.create!(:quote => @quote, :amount_financed => 200) > > > > end > > > > > > > > it "should be invalid" do > > > > purchase = Purchase.new(:quote => > > > > @quote, :amount_collected_by_card => "value") > > > > purchase.should_not be_valid > > > > purchase.errors.on (:quote_id).should_not be_nil > > > > end > > > > end > > > > > > > > Comments welcome on whether this is a good way to do this. (I know > > > > that the above doesn't test my database unique constraint, which I > > > > don't do in this case come to think of it, but I try to keep DB > specs > > > > separate, hard as that may be sometimes.) > > > > > > > > Ashley > > > > > > > > > That looks like the kind of thing I was initially thinking of, but I > > started to think that having all those objects being created in a > > non-related spec could lead to trouble. If I change what makes any of > those > > objects valid, these supposedly unrelated specs will then break. > > > > > > I want to try and keep everything seperate, but in this case it seems > that > > things are interdependent. > > > > > > Cheers > > > Daniel > > > > What I've ended up doing is the following test > > > > it "should have a uniq clip_id for a given book" do > > lambda do > > Clipping.create( valid_clipping_attributes ) > > Clipping.create( valid_clipping_attributes ) > > end.should change( Clipping, :count ).by( 1 ) > > end > > > > It hits the database, but the valid_clipping_attributes are mocks that > are > > used throughout the spec so it's divorced from the other specs. > > > > If there are any better ideas I'm open to them. > > > > Thanx for the response Ashley. > > > > Daniel > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070725/c0afd796/attachment.html From philodespotos at gmail.com Tue Jul 24 20:07:01 2007 From: philodespotos at gmail.com (Kyle Hargraves) Date: Tue, 24 Jul 2007 19:07:01 -0500 Subject: [rspec-users] Mock or Stub strategy for validates_uniqueness_of In-Reply-To: <2fff50390707241646i6183f887if425d1f6b3e92e01@mail.gmail.com> References: <2fff50390707240607x7686c9e3u6779c8e09ff38305@mail.gmail.com> <2C4C4237-7B54-44AD-A1F5-3C3E16A1CDE2@ashleymoran.me.uk> <2fff50390707240649s7a4e35fbi99b5c091369f607d@mail.gmail.com> <2fff50390707240740y22ac9647v9dd18bb0c97e778e@mail.gmail.com> <57a815bf0707241616u7f484c30w39b2c9044a1a6dd3@mail.gmail.com> <2fff50390707241646i6183f887if425d1f6b3e92e01@mail.gmail.com> Message-ID: <46A69425.20005@gmail.com> Daniel N wrote: > On 7/25/07, Mikel Lindsaar wrote: >> >> There would be a different way. >> >> In the idea of "Only test the code you write" all you really need to >> spec is that you have set the right association, because activerecord >> has it's own tests to ensure the uniq call works. >> >> You can do this with a call to reflect_on_association. Unfortunately >> that call does not return a hash, but an association object. >> >> I wrote a blog post on how to do this easily with a spec_helper.rb >> method that adds to_hash to reflect on association. >> >> >> http://www.blognow.com.au/q/67540/Reflect_on_association_one_liner_to_check_association_details.html >> >> >> In the end you end up with a spec that looks like this: >> >> it "should test reflection details" do >> >> association_results = { >> :macro => :has_many, >> :options => {:through => :clipping, :uniq => true}, >> :class_name => "nil" >> } >> >> Book.reflect_on_association(:clip).to_hash.should == >> association_results >> >> end >> >> >> Of course, you can add whatever values you want into the hash. >> >> I now have one of these specs at the top of pretty much every model >> spec. Just set up the hash with all your association rules and then >> this can be checked and kept track of when you are refactoring or >> changing code. >> >> Hope that helps. >> >> Regards >> >> Mikel > > > Thanx Mikel. > > I didn't even think of using a uniq on the has_many. I was using a > validates_uniquness_of :scope => 'book_id' > > I will definitley look into this one. > > Thankyou > Daniel However you decide to go about solving it, the idiom you hit upon is what, to me, actually describes the behaviour; if the book already has a clip once, you can't add it again: lambda { add_twice }.should change(...).by(1) It states very clearly what results you wish to see. Going through reflect_on_association feels too much like specifying the use of a particular implementation, rather than the desired outcome. Kyle From has.sox at gmail.com Tue Jul 24 20:31:50 2007 From: has.sox at gmail.com (Daniel N) Date: Wed, 25 Jul 2007 10:31:50 +1000 Subject: [rspec-users] Mock or Stub strategy for validates_uniqueness_of In-Reply-To: <46A69425.20005@gmail.com> References: <2fff50390707240607x7686c9e3u6779c8e09ff38305@mail.gmail.com> <2C4C4237-7B54-44AD-A1F5-3C3E16A1CDE2@ashleymoran.me.uk> <2fff50390707240649s7a4e35fbi99b5c091369f607d@mail.gmail.com> <2fff50390707240740y22ac9647v9dd18bb0c97e778e@mail.gmail.com> <57a815bf0707241616u7f484c30w39b2c9044a1a6dd3@mail.gmail.com> <2fff50390707241646i6183f887if425d1f6b3e92e01@mail.gmail.com> <46A69425.20005@gmail.com> Message-ID: <2fff50390707241731p22b681a6xb52ab0a663454325@mail.gmail.com> On 7/25/07, Kyle Hargraves wrote: > > Daniel N wrote: > > On 7/25/07, Mikel Lindsaar wrote: > >> > >> There would be a different way. > >> > >> In the idea of "Only test the code you write" all you really need to > >> spec is that you have set the right association, because activerecord > >> has it's own tests to ensure the uniq call works. > >> > >> You can do this with a call to reflect_on_association. Unfortunately > >> that call does not return a hash, but an association object. > >> > >> I wrote a blog post on how to do this easily with a spec_helper.rb > >> method that adds to_hash to reflect on association. > >> > >> > >> > http://www.blognow.com.au/q/67540/Reflect_on_association_one_liner_to_check_association_details.html > >> > >> > >> In the end you end up with a spec that looks like this: > >> > >> it "should test reflection details" do > >> > >> association_results = { > >> :macro => :has_many, > >> :options => {:through => :clipping, :uniq => true}, > >> :class_name => "nil" > >> } > >> > >> Book.reflect_on_association(:clip).to_hash.should == > >> association_results > >> > >> end > >> > >> > >> Of course, you can add whatever values you want into the hash. > >> > >> I now have one of these specs at the top of pretty much every model > >> spec. Just set up the hash with all your association rules and then > >> this can be checked and kept track of when you are refactoring or > >> changing code. > >> > >> Hope that helps. > >> > >> Regards > >> > >> Mikel > > > > > > Thanx Mikel. > > > > I didn't even think of using a uniq on the has_many. I was using a > > validates_uniquness_of :scope => 'book_id' > > > > I will definitley look into this one. > > > > Thankyou > > Daniel > > However you decide to go about solving it, the idiom you hit upon is > what, to me, actually describes the behaviour; if the book already has a > clip once, you can't add it again: > > lambda { add_twice }.should change(...).by(1) > > It states very clearly what results you wish to see. > > Going through reflect_on_association feels too much like specifying the > use of a particular implementation, rather than the desired outcome. > > Kyle It looks much better when you write it like that though ;) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070725/51ecc28f/attachment.html From ricktessner at canada.com Tue Jul 24 23:54:21 2007 From: ricktessner at canada.com (Rick Tessner) Date: Tue, 24 Jul 2007 20:54:21 -0700 Subject: [rspec-users] spec'ing helpers that use controller In-Reply-To: <4b430c8f0707241630v72d4ff78ledf155cdf594ada4@mail.gmail.com> References: <1185315044.11009.18.camel@localhost> <4b430c8f0707241526t24959384hb153795592339ea7@mail.gmail.com> <1185316641.11009.21.camel@localhost> <4b430c8f0707241630v72d4ff78ledf155cdf594ada4@mail.gmail.com> Message-ID: <1185335661.15448.7.camel@localhost> Hi, This worked just fine. :) Thanks. On Tue, 2007-24-07 at 16:30 -0700, Courtenay wrote: > specing helpers just includes the module in your spec. > > So you can cheat like > > describe "Application Helper" do > helper_name :application > > def controller > @controller > end > > before(:each) do > @controller = mock('controller') > end > > it "should blah blah" do > end > > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- Rick Tessner From raasdnil at gmail.com Tue Jul 24 23:58:22 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Wed, 25 Jul 2007 13:58:22 +1000 Subject: [rspec-users] Mock or Stub strategy for validates_uniqueness_of In-Reply-To: <2fff50390707241731p22b681a6xb52ab0a663454325@mail.gmail.com> References: <2fff50390707240607x7686c9e3u6779c8e09ff38305@mail.gmail.com> <2C4C4237-7B54-44AD-A1F5-3C3E16A1CDE2@ashleymoran.me.uk> <2fff50390707240649s7a4e35fbi99b5c091369f607d@mail.gmail.com> <2fff50390707240740y22ac9647v9dd18bb0c97e778e@mail.gmail.com> <57a815bf0707241616u7f484c30w39b2c9044a1a6dd3@mail.gmail.com> <2fff50390707241646i6183f887if425d1f6b3e92e01@mail.gmail.com> <46A69425.20005@gmail.com> <2fff50390707241731p22b681a6xb52ab0a663454325@mail.gmail.com> Message-ID: <57a815bf0707242058g2183b202u87616c9e9c2bc380@mail.gmail.com> Kyle, That is a good point. We are after the behaviour, not the implementation. Regards Mikel On 7/25/07, Daniel N wrote: > > > > On 7/25/07, Kyle Hargraves wrote: > > Daniel N wrote: > > > On 7/25/07, Mikel Lindsaar wrote: > > >> > > >> There would be a different way. > > >> > > >> In the idea of "Only test the code you write" all you really need to > > >> spec is that you have set the right association, because activerecord > > >> has it's own tests to ensure the uniq call works. > > >> > > >> You can do this with a call to > reflect_on_association. Unfortunately > > >> that call does not return a hash, but an association object. > > >> > > >> I wrote a blog post on how to do this easily with a spec_helper.rb > > >> method that adds to_hash to reflect on association. > > >> > > >> > > >> > http://www.blognow.com.au/q/67540/Reflect_on_association_one_liner_to_check_association_details.html > > >> > > >> > > >> In the end you end up with a spec that looks like this: > > >> > > >> it "should test reflection details" do > > >> > > >> association_results = { > > >> :macro => :has_many, > > >> :options => {:through => :clipping, :uniq => true}, > > >> :class_name => "nil" > > >> } > > >> > > >> Book.reflect_on_association (:clip).to_hash.should == > > >> association_results > > >> > > >> end > > >> > > >> > > >> Of course, you can add whatever values you want into the hash. > > >> > > >> I now have one of these specs at the top of pretty much every model > > >> spec. Just set up the hash with all your association rules and then > > >> this can be checked and kept track of when you are refactoring or > > >> changing code. > > >> > > >> Hope that helps. > > >> > > >> Regards > > >> > > >> Mikel > > > > > > > > > Thanx Mikel. > > > > > > I didn't even think of using a uniq on the has_many. I was using a > > > validates_uniquness_of :scope => 'book_id' > > > > > > I will definitley look into this one. > > > > > > Thankyou > > > Daniel > > > > However you decide to go about solving it, the idiom you hit upon is > > what, to me, actually describes the behaviour; if the book already has a > > clip once, you can't add it again: > > > > lambda { add_twice }.should change(...).by(1) > > > > It states very clearly what results you wish to see. > > > > Going through reflect_on_association feels too much like specifying the > > use of a particular implementation, rather than the desired outcome. > > > > Kyle > > > It looks much better when you write it like that though ;) > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Wed Jul 25 06:31:33 2007 From: has.sox at gmail.com (Daniel N) Date: Wed, 25 Jul 2007 20:31:33 +1000 Subject: [rspec-users] Mock or Stub strategy for validates_uniqueness_of In-Reply-To: <57a815bf0707242058g2183b202u87616c9e9c2bc380@mail.gmail.com> References: <2fff50390707240607x7686c9e3u6779c8e09ff38305@mail.gmail.com> <2C4C4237-7B54-44AD-A1F5-3C3E16A1CDE2@ashleymoran.me.uk> <2fff50390707240649s7a4e35fbi99b5c091369f607d@mail.gmail.com> <2fff50390707240740y22ac9647v9dd18bb0c97e778e@mail.gmail.com> <57a815bf0707241616u7f484c30w39b2c9044a1a6dd3@mail.gmail.com> <2fff50390707241646i6183f887if425d1f6b3e92e01@mail.gmail.com> <46A69425.20005@gmail.com> <2fff50390707241731p22b681a6xb52ab0a663454325@mail.gmail.com> <57a815bf0707242058g2183b202u87616c9e9c2bc380@mail.gmail.com> Message-ID: <2fff50390707250331w232122d2h122833a67b7f393@mail.gmail.com> On 7/25/07, Mikel Lindsaar wrote: > > Kyle, > > That is a good point. We are after the behaviour, not the implementation. > > Regards > > Mikel > > On 7/25/07, Daniel N wrote: > > > > > > > > On 7/25/07, Kyle Hargraves wrote: > > > Daniel N wrote: > > > > On 7/25/07, Mikel Lindsaar wrote: > > > >> > > > >> There would be a different way. > > > >> > > > >> In the idea of "Only test the code you write" all you really need > to > > > >> spec is that you have set the right association, because > activerecord > > > >> has it's own tests to ensure the uniq call works. > > > >> > > > >> You can do this with a call to > > reflect_on_association. Unfortunately > > > >> that call does not return a hash, but an association object. > > > >> > > > >> I wrote a blog post on how to do this easily with a spec_helper.rb > > > >> method that adds to_hash to reflect on association. > > > >> > > > >> > > > >> > > > http://www.blognow.com.au/q/67540/Reflect_on_association_one_liner_to_check_association_details.html > > > >> > > > >> > > > >> In the end you end up with a spec that looks like this: > > > >> > > > >> it "should test reflection details" do > > > >> > > > >> association_results = { > > > >> :macro => :has_many, > > > >> :options => {:through => :clipping, :uniq => true}, > > > >> :class_name => "nil" > > > >> } > > > >> > > > >> Book.reflect_on_association (:clip).to_hash.should == > > > >> association_results > > > >> > > > >> end > > > >> > > > >> > > > >> Of course, you can add whatever values you want into the hash. > > > >> > > > >> I now have one of these specs at the top of pretty much every model > > > >> spec. Just set up the hash with all your association rules and > then > > > >> this can be checked and kept track of when you are refactoring or > > > >> changing code. > > > >> > > > >> Hope that helps. > > > >> > > > >> Regards > > > >> > > > >> Mikel > > > > > > > > > > > > Thanx Mikel. > > > > > > > > I didn't even think of using a uniq on the has_many. I was using a > > > > validates_uniquness_of :scope => 'book_id' > > > > > > > > I will definitley look into this one. > > > > > > > > Thankyou > > > > Daniel > > > > > > However you decide to go about solving it, the idiom you hit upon is > > > what, to me, actually describes the behaviour; if the book already has > a > > > clip once, you can't add it again: > > > > > > lambda { add_twice }.should change(...).by(1) > > > > > > It states very clearly what results you wish to see. > > > > > > Going through reflect_on_association feels too much like specifying > the > > > use of a particular implementation, rather than the desired outcome. > > > > > > Kyle > > > > > > It looks much better when you write it like that though ;) > > > > > > Thanx for the input guys. I wasn''t entirely happy with what I had because it didn't actually test what I wanted. It tests that a duplicate cannot be added. But I specifically wanted to not allow duplicates for a given clip_id it "should have a uniq clip_id for a given book" do lambda do Clipping.create( valid_clipping_attributes ) Clipping.create( valid_clipping_attributes ) end.should change( Clipping, :count ).by( 1 ) end became it "should have a uniq clip_id for a given book" do lambda do Clipping.create( valid_clipping_attributes.with( :book => @book, :clip => @clip ) ) clipping = Clipping.create( valid_clipping_attributes.with( :book => @book, :clip => @clip ) ) clipping.should have(1).error_on( :clip_id ) clipping.errors.on( :clip_id ).should match( /(already|duplicate|exists)/i ) end.should change( Clipping, :count ).by( 1 ) end If anyone was interested :P Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070725/db8d118b/attachment.html From port001 at gmail.com Wed Jul 25 08:02:45 2007 From: port001 at gmail.com (Ian Leitch) Date: Wed, 25 Jul 2007 13:02:45 +0100 Subject: [rspec-users] MockCov: Proof of concept Message-ID: Hey list, RSpec is great, I've been using it at work for a couple of months now. One gripe I have is that I find it hard to know exactly to what extent my code is covered by the specs. I am aware of RCov and Heckle; they're great, but I'd like to demonstrate another perspective of coverage analysis I've hacked up. The perspective is that of what is mocked and what isn't, with RCov execution analysis mixed in for better viewing. My itch was "To what extent is my code mocked?" -- hence the name MockCov. It produces a report for each file with stubbed methods and executed lines highlighted. From that I can easily see what my specs failed to mock and therefore most probably didn't specify any kind of behavior for. Here is a sample report: http://zioko.com/review_drop.rb.html (please forgive the small size of this sample, my employer understandably didn't want me showing too much of our code) You'll notice that there isn't any kind of statistical coverage summary, I'm not sure how to quantity the results and indeed haven't spent any time thinking about it; that can come later. For now I'd just like to gauge the response to this. I haven't packaged the code up yet, it's a horrible hack and needs to be reworked from scratch; I need to talk with someone on how best to integrate it with RSpec before that happens though. Let me know your thoughts. Cheers Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070725/b4b657f7/attachment-0001.html From work at ashleymoran.me.uk Wed Jul 25 10:24:53 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 25 Jul 2007 15:24:53 +0100 Subject: [rspec-users] Mock or Stub strategy for validates_uniqueness_of In-Reply-To: <2fff50390707240649s7a4e35fbi99b5c091369f607d@mail.gmail.com> References: <2fff50390707240607x7686c9e3u6779c8e09ff38305@mail.gmail.com> <2C4C4237-7B54-44AD-A1F5-3C3E16A1CDE2@ashleymoran.me.uk> <2fff50390707240649s7a4e35fbi99b5c091369f607d@mail.gmail.com> Message-ID: On 24 Jul 2007, at 14:49, Daniel N wrote: > That looks like the kind of thing I was initially thinking of, but > I started to think that having all those objects being created in a > non-related spec could lead to trouble. If I change what makes any > of those objects valid, these supposedly unrelated specs will then > break. Yep, I've had that several times unfortunately... > I want to try and keep everything seperate, but in this case it > seems that things are interdependent. from the other email... > It hits the database, but the valid_clipping_attributes are mocks > that are used throughout the spec so it's divorced from the other > specs. I like the idea of separating out the valid atributes. Most of my models start along the lines of "An XModel created with valid attributes should be valid" this sanity checks that I know what a valid model is and means if anything goes wrong I don't waste hours hunting through Ashley From work at ashleymoran.me.uk Wed Jul 25 10:30:24 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Wed, 25 Jul 2007 15:30:24 +0100 Subject: [rspec-users] Mock or Stub strategy for validates_uniqueness_of In-Reply-To: <46A69425.20005@gmail.com> References: <2fff50390707240607x7686c9e3u6779c8e09ff38305@mail.gmail.com> <2C4C4237-7B54-44AD-A1F5-3C3E16A1CDE2@ashleymoran.me.uk> <2fff50390707240649s7a4e35fbi99b5c091369f607d@mail.gmail.com> <2fff50390707240740y22ac9647v9dd18bb0c97e778e@mail.gmail.com> <57a815bf0707241616u7f484c30w39b2c9044a1a6dd3@mail.gmail.com> <2fff50390707241646i6183f887if425d1f6b3e92e01@mail.gmail.com> <46A69425.20005@gmail.com> Message-ID: On 25 Jul 2007, at 01:07, Kyle Hargraves wrote: > Going through reflect_on_association feels too much like specifying > the > use of a particular implementation, rather than the desired outcome. I second that. I agree that you should only test the code you write, but unfortunately(!) you get a lot of behaviour for each line of code you write in rails, so I prefer to test the expected behaviour than signs that the behaviour is in place Sometimes I'm forced to break this, in which case I write an assumption spec that tests a single case of what the library should be doing, then test that I interact with it properly. Ashley From marcus at ahnve.com Wed Jul 25 12:27:17 2007 From: marcus at ahnve.com (Marcus Ahnve) Date: Wed, 25 Jul 2007 18:27:17 +0200 Subject: [rspec-users] MockCov: Proof of concept In-Reply-To: References: Message-ID: <4d4e79cc0707250927x7afe666eoae104c72bdea8b49@mail.gmail.com> Really cool - I have asked myself that question several times. /Marcus On 7/25/07, Ian Leitch wrote: > Hey list, > > RSpec is great, I've been using it at work for a couple of months now. One > gripe I have is that I find it hard to know exactly to what extent my code > is covered by the specs. I am aware of RCov and Heckle; they're great, but > I'd like to demonstrate another perspective of coverage analysis I've hacked > up. > > The perspective is that of what is mocked and what isn't, with RCov > execution analysis mixed in for better viewing. My itch was "To what extent > is my code mocked?" -- hence the name MockCov. > It produces a report for each file with stubbed methods and executed lines > highlighted. From that I can easily see what my specs failed to mock and > therefore most probably didn't specify any kind of behavior for. > > Here is a sample report: > http://zioko.com/review_drop.rb.html > (please forgive the small size of this sample, my employer understandably > didn't want me showing too much of our code) > > You'll notice that there isn't any kind of statistical coverage summary, I'm > not sure how to quantity the results and indeed haven't spent any time > thinking about it; that can come later. For now I'd just like to gauge the > response to this. > > I haven't packaged the code up yet, it's a horrible hack and needs to be > reworked from scratch; I need to talk with someone on how best to integrate > it with RSpec before that happens though. > > Let me know your thoughts. > > Cheers > Ian > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- http://marcus.ahnve.net From raasdnil at gmail.com Wed Jul 25 20:26:47 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 26 Jul 2007 10:26:47 +1000 Subject: [rspec-users] autotest loosing RAILS_ROOT Constant? Message-ID: <57a815bf0707251726m3c49f0f3nc933743d8ec7d046@mail.gmail.com> I am having a weird error that I have not had before... I'm bouncing it off the list to see if anyone else has had it, or to give me some pointers about how to find it. Basically, AUTOTEST will run (RSpec mode), fine, then suddenly, will complain that RAILS_ROOT is undefined. Then I stop and restart it, with no code change... no problem. It happens on different specs where I use RAILS_ROOT like so: @file = open("#{RAILS_ROOT}/spec/fixtures/files/test_file.txt", "r") { |f| f.read} All the specs that error are just like that. They are nothing special, read a file, send it to a method, get the result, result.should == file This is what it looks like in my console: =================================== 1) NameError in 'ListToCsvConverter should ...1' uninitialized constant RAILS_ROOT ./spec/lib/list_to_csv_converter_spec.rb:18: script/spec:4: 2) NameError in 'ListToCsvConverter should ...2' uninitialized constant RAILS_ROOT ./spec/lib/list_to_csv_converter_spec.rb:11: script/spec:4: Finished in 0.008741 seconds 2 examples, 2 failures ^Cmenu c: continue q: quit r: restart menu> r /usr/local/bin/ruby -S script/spec -O spec/spec.opts spec.rb ........................................................................................ Finished in 0.533593 seconds 88 examples, 0 failures =================================== As I said... weird. Anyone else run into this? Regards Mikel From raasdnil at gmail.com Thu Jul 26 02:20:59 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Thu, 26 Jul 2007 16:20:59 +1000 Subject: [rspec-users] autotest loosing RAILS_ROOT Constant? In-Reply-To: <57a815bf0707251726m3c49f0f3nc933743d8ec7d046@mail.gmail.com> References: <57a815bf0707251726m3c49f0f3nc933743d8ec7d046@mail.gmail.com> Message-ID: <57a815bf0707252320t2d230239ibdd39aa264ca2364@mail.gmail.com> Don't fear... chalk this up to an error casued between the screen and keyboard... The specs that were causing this problem had a missing spec_helper.rb line. duh! Regards Mikel On 7/26/07, Mikel Lindsaar wrote: > I am having a weird error that I have not had before... I'm bouncing > it off the list to see if anyone else has had it, or to give me some > pointers about how to find it. > > Basically, AUTOTEST will run (RSpec mode), fine, then suddenly, will > complain that RAILS_ROOT is undefined. > > Then I stop and restart it, with no code change... no problem. > > It happens on different specs where I use RAILS_ROOT like so: > > @file = open("#{RAILS_ROOT}/spec/fixtures/files/test_file.txt", "r") { > |f| f.read} > > All the specs that error are just like that. They are nothing > special, read a file, send it to a method, get the result, > result.should == file > > This is what it looks like in my console: > > =================================== > > 1) > NameError in 'ListToCsvConverter should ...1' > uninitialized constant RAILS_ROOT > ./spec/lib/list_to_csv_converter_spec.rb:18: > script/spec:4: > > 2) > NameError in 'ListToCsvConverter should ...2' > uninitialized constant RAILS_ROOT > ./spec/lib/list_to_csv_converter_spec.rb:11: > script/spec:4: > > Finished in 0.008741 seconds > > 2 examples, 2 failures > ^Cmenu > c: continue > q: quit > r: restart > menu> r > /usr/local/bin/ruby -S script/spec -O spec/spec.opts spec.rb > ........................................................................................ > > > Finished in 0.533593 seconds > > 88 examples, 0 failures > > =================================== > > > As I said... weird. > > Anyone else run into this? > > Regards > > Mikel > From win at wincent.com Thu Jul 26 05:26:28 2007 From: win at wincent.com (Wincent Colaiuta) Date: Thu, 26 Jul 2007 11:26:28 +0200 Subject: [rspec-users] Coding standards and whitespace Message-ID: <9989DB21-CFBE-4AC4-B9F4-A46D9A3E0A4A@wincent.com> Recently as a result of using Git I've noticed a number of inconsistencies in the RSpec codebase with respect to whitespace (mixed line endings, mixed use of spaces and tabs for indentation, and trailing whitespace at the end of lines). I never would have noticed, but Git produces nice colorized diff output which highlights these kinds of inconsistencies. I wanted to ask if the core RSpec team had established any conventions/standards for these things. The basic rationale is that if all contributors agree to a small number of conventions for whitespace there are less likely to be changesets with non- substantive whitespace differences (really, false alarms). The procedure I used to explore this was as follows: First export a clean copy of the trunk: svn export svn://rubyforge.org/var/svn/rspec/trunk rspec-trunk cd rspec-trunk Then use the following Bash incantation to see which files had UNIX, Mac or Windows line endings: IFS=" " for FILE in $(find . -type f) do if ! perl -ne "exit 1 if m/\r/;" "$FILE"; then echo "CR detected in : $FILE" else echo "ok : $FILE" fi done All text files used UNIX line endings (LF) with the exception of these four, which used Windows line endings (CRLF): doc/src/default.css rspec/bin/spec_translator spec_ui/examples/selenium/README.txt spec_ui/History.txt I did a similar Bash thing to find out which files had tabs in them; many of them appear to consistently use tabs for indentation but some do not, using a mixture of tabs and spaces. doc/src/breadcrumbs.css doc/src/default.css doc/src/default.template rspec/lib/spec/runner/formatter/base_text_formatter.rb rspec/lib/spec/runner/formatter/html_formatter.rb rspec/lib/spec/runner/spec_parser.rb rspec/spec/spec/runner/formatter/html_formatted-1.8.4.html rspec/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html rspec/spec/spec/runner/formatter/html_formatted-1.8.5.html rspec/spec/spec/runner/formatter/html_formatted-1.8.6.html RSpec.tmbundle/Commands/Alternate File.tmCommand RSpec.tmbundle/Commands/Run Focussed Specification.tmCommand RSpec.tmbundle/Commands/Run Specifications - Normal.tmCommand RSpec.tmbundle/Commands/Run Specifications in selected files or directories.tmCommand RSpec.tmbundle/info.plist RSpec.tmbundle/Snippets/and_raise.tmSnippet RSpec.tmbundle/Snippets/and_return_block.tmSnippet RSpec.tmbundle/Snippets/and_return_value.tmSnippet RSpec.tmbundle/Snippets/and_throw.tmSnippet RSpec.tmbundle/Snippets/and_yield.tmSnippet RSpec.tmbundle/Snippets/any_number_of_times.tmSnippet RSpec.tmbundle/Snippets/at_least.tmSnippet RSpec.tmbundle/Snippets/at_least_once.tmSnippet RSpec.tmbundle/Snippets/at_least_twice.tmSnippet RSpec.tmbundle/Snippets/at_most.tmSnippet RSpec.tmbundle/Snippets/at_most_once.tmSnippet RSpec.tmbundle/Snippets/at_most_twice.tmSnippet RSpec.tmbundle/Snippets/controller_context.tmSnippet RSpec.tmbundle/Snippets/controller_context_RESTful.tmSnippet RSpec.tmbundle/Snippets/Custom Matcher.tmSnippet RSpec.tmbundle/Snippets/Describe.tmSnippet RSpec.tmbundle/Snippets/Describe_type.tmSnippet RSpec.tmbundle/Snippets/Describe_type_string.tmSnippet RSpec.tmbundle/Snippets/exactly.tmSnippet RSpec.tmbundle/Snippets/It.tmSnippet RSpec.tmbundle/Snippets/mock.tmSnippet RSpec.tmbundle/Snippets/once.tmSnippet RSpec.tmbundle/Snippets/Require spec_helper.tmSnippet RSpec.tmbundle/Snippets/response_should_be_success.tmSnippet RSpec.tmbundle/Snippets/response_should_not_be_success.tmSnippet RSpec.tmbundle/Snippets/Set Controller for Spec.tmSnippet RSpec.tmbundle/Snippets/setup.tmSnippet RSpec.tmbundle/Snippets/should ==.tmSnippet RSpec.tmbundle/Snippets/should =~.tmSnippet RSpec.tmbundle/Snippets/should eql.tmSnippet RSpec.tmbundle/Snippets/should_be.tmSnippet RSpec.tmbundle/Snippets/should_be_a_kind_of.tmSnippet RSpec.tmbundle/Snippets/should_be_an_instance_of.tmSnippet RSpec.tmbundle/Snippets/should_be_close.tmSnippet RSpec.tmbundle/Snippets/should_be_redirect.tmSnippet RSpec.tmbundle/Snippets/should_equal.tmSnippet RSpec.tmbundle/Snippets/should_have.tmSnippet RSpec.tmbundle/Snippets/should_have_at_least.tmSnippet RSpec.tmbundle/Snippets/should_have_at_most.tmSnippet RSpec.tmbundle/Snippets/should_have_records.tmSnippet RSpec.tmbundle/Snippets/should_include.tmSnippet RSpec.tmbundle/Snippets/should_match.tmSnippet RSpec.tmbundle/Snippets/should_not ==.tmSnippet RSpec.tmbundle/Snippets/should_not =~.tmSnippet RSpec.tmbundle/Snippets/should_not eql.tmSnippet RSpec.tmbundle/Snippets/should_not_be.tmSnippet RSpec.tmbundle/Snippets/should_not_be_a_kind_of.tmSnippet RSpec.tmbundle/Snippets/should_not_be_an_instance_of.tmSnippet RSpec.tmbundle/Snippets/should_not_be_close.tmSnippet RSpec.tmbundle/Snippets/should_not_be_redirect.tmSnippet RSpec.tmbundle/Snippets/should_not_equal.tmSnippet RSpec.tmbundle/Snippets/should_not_include.tmSnippet RSpec.tmbundle/Snippets/should_not_match.tmSnippet RSpec.tmbundle/Snippets/should_not_predicate.tmSnippet RSpec.tmbundle/Snippets/should_not_raise.tmSnippet RSpec.tmbundle/Snippets/should_not_receive.tmSnippet RSpec.tmbundle/Snippets/should_not_respond_to.tmSnippet RSpec.tmbundle/Snippets/should_not_satisfy.tmSnippet RSpec.tmbundle/Snippets/should_not_throw.tmSnippet RSpec.tmbundle/Snippets/should_predicate.tmSnippet RSpec.tmbundle/Snippets/should_raise.tmSnippet RSpec.tmbundle/Snippets/should_receive.tmSnippet RSpec.tmbundle/Snippets/should_receive_with_any_args.tmSnippet RSpec.tmbundle/Snippets/should_receive_with_args.tmSnippet RSpec.tmbundle/Snippets/should_receive_with_no_args.tmSnippet RSpec.tmbundle/Snippets/should_redirect_to.tmSnippet RSpec.tmbundle/Snippets/should_render.tmSnippet RSpec.tmbundle/Snippets/should_respond_to.tmSnippet RSpec.tmbundle/Snippets/should_satisfy.tmSnippet RSpec.tmbundle/Snippets/should_throw.tmSnippet RSpec.tmbundle/Snippets/teardown.tmSnippet RSpec.tmbundle/Snippets/twice.tmSnippet rspec_on_rails/generators/rspec/templates/script/spec_server Finally I did a search for trailing whitespace. Which yielded the following list. Many of the lines contain nothing but whitespace; sometimes this use is consistent (ie. the whitespace corresponds to the nesting level of the current scope) but at other times it is not. doc/metainfo.yaml doc/plugin/breadcrumbs.rb doc/plugin/rspec_content.rb doc/plugin/svn_tag.rb doc/plugin/syntax.rb doc/plugin/version.rb doc/src/breadcrumbs.css doc/src/community/contribute.page doc/src/community/index.page doc/src/default.template doc/src/documentation/before_and_after.page doc/src/documentation/index.page doc/src/documentation/mocks/index.page doc/src/documentation/mocks/mocks.page doc/src/documentation/rails/generators.page doc/src/documentation/rails/index.page doc/src/documentation/rails/install.page doc/src/documentation/rails/runners.page doc/src/documentation/rails/writing/index.page doc/src/documentation/tools/extensions/editors/index.page doc/src/documentation/tools/extensions/editors/textmate.page doc/src/documentation/tools/heckle.page doc/src/documentation/tools/index.page doc/src/documentation/tools/rake.page doc/src/documentation/tools/rcov.page doc/src/documentation/tools/spec.page doc/src/download.page doc/src/images/ducks1.png doc/src/index.page doc/src/upgrade.page example_rails_app/app/controllers/naughty_controller.rb example_rails_app/app/controllers/people_controller.rb example_rails_app/app/helpers/people_helper.rb example_rails_app/app/models/person.rb example_rails_app/config/boot.rb example_rails_app/config/environment.rb example_rails_app/config/environments/test.rb example_rails_app/config/routes.rb example_rails_app/db/migrate/004_create_things.rb example_rails_app/lib/tasks/bootstrap_rspec.rake example_rails_app/public/.htaccess example_rails_app/public/index.html example_rails_app/public/javascripts/controls.js example_rails_app/public/javascripts/dragdrop.js example_rails_app/public/javascripts/effects.js example_rails_app/spec/controllers/naughty_controller_spec.rb example_rails_app/spec/controllers/people_controller_spec.rb example_rails_app/spec/fixtures/animals.yml example_rails_app/spec/helpers/people_helper_spec.rb example_rails_app/spec/models/person_spec.rb example_rails_app/spec/views/person/create_view_spec.rb example_rails_app/spec/views/person/show_view_spec.rb example_rails_app/spec/watir/person_spec.rb example_rails_app/TODO pre_commit/lib/pre_commit/core.rb pre_commit/lib/pre_commit/pre_commit.rb pre_commit/lib/pre_commit/rspec.rb pre_commit/lib/pre_commit/rspec_on_rails.rb pre_commit/spec/pre_commit/pre_commit_spec.rb pre_commit/spec/pre_commit/rspec_on_rails_spec.rb rspec/CHANGES rspec/examples/auto_spec_description_example.rb rspec/examples/before_and_after_example.rb rspec/examples/behave_as_example.rb rspec/examples/custom_expectation_matchers.rb rspec/examples/file_accessor.rb rspec/examples/file_accessor_spec.rb rspec/examples/helper_method_example.rb rspec/examples/legacy_spec.rb rspec/examples/predicate_example.rb rspec/examples/shared_behaviours_example.rb rspec/examples/stack.rb rspec/examples/stack_spec.rb rspec/examples/stubbing_example.rb rspec/examples/test_case_adapter_example.rb rspec/examples/test_case_spec.rb rspec/failing_examples/failure_in_setup.rb rspec/failing_examples/failure_in_teardown.rb rspec/failing_examples/mocking_example.rb rspec/failing_examples/predicate_example.rb rspec/failing_examples/raising_example.rb rspec/failing_examples/team_spec.rb rspec/lib/autotest/rspec.rb rspec/lib/spec/dsl/behaviour.rb rspec/lib/spec/dsl/behaviour_callbacks.rb rspec/lib/spec/dsl/behaviour_eval.rb rspec/lib/spec/dsl/behaviour_factory.rb rspec/lib/spec/dsl/configuration.rb rspec/lib/spec/dsl/description.rb rspec/lib/spec/dsl/example.rb rspec/lib/spec/dsl/example_matcher.rb rspec/lib/spec/dsl/example_should_raise_handler.rb rspec/lib/spec/expectations/differs/default.rb rspec/lib/spec/expectations/handler.rb rspec/lib/spec/expectations.rb rspec/lib/spec/extensions/object.rb rspec/lib/spec/matchers/be.rb rspec/lib/spec/matchers/be_close.rb rspec/lib/spec/matchers/change.rb rspec/lib/spec/matchers/eql.rb rspec/lib/spec/matchers/equal.rb rspec/lib/spec/matchers/has.rb rspec/lib/spec/matchers/have.rb rspec/lib/spec/matchers/include.rb rspec/lib/spec/matchers/match.rb rspec/lib/spec/matchers/operator_matcher.rb rspec/lib/spec/matchers/raise_error.rb rspec/lib/spec/matchers/respond_to.rb rspec/lib/spec/matchers/satisfy.rb rspec/lib/spec/matchers/throw_symbol.rb rspec/lib/spec/matchers.rb rspec/lib/spec/mocks/argument_constraint_matchers.rb rspec/lib/spec/mocks/argument_expectation.rb rspec/lib/spec/mocks/error_generator.rb rspec/lib/spec/mocks/errors.rb rspec/lib/spec/mocks/message_expectation.rb rspec/lib/spec/mocks/methods.rb rspec/lib/spec/mocks/mock.rb rspec/lib/spec/mocks/order_group.rb rspec/lib/spec/mocks/proxy.rb rspec/lib/spec/mocks/space.rb rspec/lib/spec/mocks/spec_methods.rb rspec/lib/spec/mocks.rb rspec/lib/spec/rake/spectask.rb rspec/lib/spec/rake/verify_rcov.rb rspec/lib/spec/runner/backtrace_tweaker.rb rspec/lib/spec/runner/behaviour_runner.rb rspec/lib/spec/runner/command_line.rb rspec/lib/spec/runner/extensions/kernel.rb rspec/lib/spec/runner/extensions/object.rb rspec/lib/spec/runner/formatter/base_formatter.rb rspec/lib/spec/runner/formatter/base_text_formatter.rb rspec/lib/spec/runner/formatter/failing_behaviours_formatter.rb rspec/lib/spec/runner/formatter/failing_examples_formatter.rb rspec/lib/spec/runner/formatter/html_formatter.rb rspec/lib/spec/runner/formatter/progress_bar_formatter.rb rspec/lib/spec/runner/formatter/rdoc_formatter.rb rspec/lib/spec/runner/formatter/snippet_extractor.rb rspec/lib/spec/runner/formatter/specdoc_formatter.rb rspec/lib/spec/runner/heckle_runner.rb rspec/lib/spec/runner/option_parser.rb rspec/lib/spec/runner/options.rb rspec/lib/spec/runner/reporter.rb rspec/lib/spec/runner/spec_parser.rb rspec/lib/spec/runner.rb rspec/lib/spec/translator.rb rspec/lib/spec/version.rb rspec/Rakefile rspec/README rspec/spec/spec/dsl/behaviour_eval_spec.rb rspec/spec/spec/dsl/behaviour_factory_spec.rb rspec/spec/spec/dsl/behaviour_spec.rb rspec/spec/spec/dsl/configuration_spec.rb rspec/spec/spec/dsl/description_spec.rb rspec/spec/spec/dsl/example_class_spec.rb rspec/spec/spec/dsl/example_instance_spec.rb rspec/spec/spec/dsl/example_should_raise_spec.rb rspec/spec/spec/dsl/predicate_matcher_spec.rb rspec/spec/spec/dsl/shared_behaviour_spec.rb rspec/spec/spec/expectations/extensions/object_spec.rb rspec/spec/spec/expectations/fail_with_spec.rb rspec/spec/spec/matchers/be_spec.rb rspec/spec/spec/matchers/change_spec.rb rspec/spec/spec/matchers/description_generation_spec.rb rspec/spec/spec/matchers/exist_spec.rb rspec/spec/spec/matchers/handler_spec.rb rspec/spec/spec/matchers/have_spec.rb rspec/spec/spec/matchers/matcher_methods_spec.rb rspec/spec/spec/matchers/operator_matcher_spec.rb rspec/spec/spec/matchers/raise_error_spec.rb rspec/spec/spec/matchers/respond_to_spec.rb rspec/spec/spec/matchers/throw_symbol_spec.rb rspec/spec/spec/mocks/any_number_of_times_spec.rb rspec/spec/spec/mocks/bug_report_11545_spec.rb rspec/spec/spec/mocks/bug_report_7611_spec.rb rspec/spec/spec/mocks/bug_report_8302_spec.rb rspec/spec/spec/mocks/failing_mock_argument_constraints_spec.rb rspec/spec/spec/mocks/mock_ordering_spec.rb rspec/spec/spec/mocks/mock_space_spec.rb rspec/spec/spec/mocks/mock_spec.rb rspec/spec/spec/mocks/multiple_return_value_spec.rb rspec/spec/spec/mocks/once_counts_spec.rb rspec/spec/spec/mocks/partial_mock_spec.rb rspec/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb rspec/spec/spec/mocks/passing_mock_argument_constraints_spec.rb rspec/spec/spec/mocks/stub_spec.rb rspec/spec/spec/mocks/twice_counts_spec.rb rspec/spec/spec/runner/behaviour_runner_spec.rb rspec/spec/spec/runner/command_line_spec.rb rspec/spec/spec/runner/drb_command_line_spec.rb rspec/spec/spec/runner/example_matcher_spec.rb rspec/spec/spec/runner/execution_context_spec.rb rspec/spec/spec/runner/extensions/kernel_spec.rb rspec/spec/spec/runner/formatter/failing_behaviours_formatter_spec.rb rspec/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html rspec/spec/spec/runner/formatter/html_formatter_spec.rb rspec/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb rspec/spec/spec/runner/formatter/progress_bar_formatter_spec.rb rspec/spec/spec/runner/formatter/rdoc_formatter_dry_run_spec.rb rspec/spec/spec/runner/formatter/rdoc_formatter_spec.rb rspec/spec/spec/runner/formatter/specdoc_formatter_dry_run_spec.rb rspec/spec/spec/runner/noisy_backtrace_tweaker_spec.rb rspec/spec/spec/runner/option_parser_spec.rb rspec/spec/spec/runner/options_spec.rb rspec/spec/spec/runner/quiet_backtrace_tweaker_spec.rb rspec/spec/spec/runner/reporter_spec.rb rspec/spec/spec/runner/spec_parser_spec.rb rspec/spec/spec/spec_classes.rb rspec/spec/spec/translator_spec.rb rspec/spec.opts rspec/UPGRADE RSpec.tmbundle/Support/lib/spec/mate/switch_command.rb RSpec.tmbundle/Support/lib/spec_mate.rb RSpec.tmbundle/Support/spec/spec/mate/switch_command_spec.rb RSpec.tmbundle/Support/spec/spec_mate_spec.rb rspec_on_rails/generators/rspec/templates/script/spec_server rspec_on_rails/generators/rspec_controller/templates/helper_spec.rb rspec_on_rails/generators/rspec_controller/templates/view_spec.rb rspec_on_rails/generators/rspec_controller/USAGE rspec_on_rails/generators/rspec_scaffold/rspec_scaffold_generator.rb rspec_on_rails/generators/rspec_scaffold/templates/controller_spec.rb rspec_on_rails/generators/rspec_scaffold/templates/edit_erb_spec.rb rspec_on_rails/generators/rspec_scaffold/templates/index_erb_spec.rb rspec_on_rails/generators/rspec_scaffold/templates/new_erb_spec.rb rspec_on_rails/generators/rspec_scaffold/templates/show_erb_spec.rb rspec_on_rails/lib/autotest/rails_rspec.rb rspec_on_rails/lib/spec/dsl/configuration.rb rspec_on_rails/lib/spec/matchers/have.rb rspec_on_rails/lib/spec/rails/dsl/behaviour/base.rb rspec_on_rails/lib/spec/rails/dsl/behaviour/controller.rb rspec_on_rails/lib/spec/rails/dsl/behaviour/functional.rb rspec_on_rails/lib/spec/rails/dsl/behaviour/helper.rb rspec_on_rails/lib/spec/rails/dsl/behaviour/render_observer.rb rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb rspec_on_rails/lib/spec/rails/extensions/action_controller/base.rb rspec_on_rails/lib/spec/rails/matchers/assert_select.rb rspec_on_rails/lib/spec/rails/matchers/have_text.rb rspec_on_rails/lib/spec/rails/matchers/redirect_to.rb rspec_on_rails/lib/spec/rails/matchers/render_template.rb rspec_on_rails/lib/spec/rails.rb rspec_on_rails/MIT-LICENSE rspec_on_rails/spec/rails/autotest/mappings_spec.rb rspec_on_rails/spec/rails/dsl/behaviour_factory_spec.rb rspec_on_rails/spec/rails/dsl/configuration_spec.rb rspec_on_rails/spec/rails/dsl/controller_isolation_spec.rb rspec_on_rails/spec/rails/dsl/controller_spec_spec.rb rspec_on_rails/spec/rails/dsl/helper_spec_spec.rb rspec_on_rails/spec/rails/dsl/ivar_proxy_spec.rb rspec_on_rails/spec/rails/dsl/shared_behaviour_spec.rb rspec_on_rails/spec/rails/dsl/view_spec_spec.rb rspec_on_rails/spec/rails/extensions/action_view_base_spec.rb rspec_on_rails/spec/rails/extensions/active_record_spec.rb rspec_on_rails/spec/rails/matchers/assert_select_spec.rb rspec_on_rails/spec/rails/matchers/description_generation_spec.rb rspec_on_rails/spec/rails/matchers/redirect_to_spec.rb rspec_on_rails/spec/rails/matchers/render_spec.rb rspec_on_rails/spec/spec_helper.rb rspec_on_rails/spec_resources/controllers/controller_spec_controller.rb rspec_on_rails/spec_resources/controllers/redirect_spec_controller.rb rspec_on_rails/spec_resources/controllers/render_spec_controller.rb rspec_on_rails/spec_resources/controllers/rjs_spec_controller.rb rspec_on_rails/spec_resources/helpers/explicit_helper.rb rspec_on_rails/tasks/rspec.rake spec_distributed/lib/spec/distributed/master_runner.rb spec_distributed/lib/spec/distributed/slave_runner.rb spec_distributed/Rakefile spec_distributed/README.txt spec_distributed/setup.rb spec_ui/examples/selenium/Rakefile spec_ui/examples/selenium/spec/spec_helper.rb spec_ui/examples/watir/Rakefile spec_ui/examples/watir/spec/watir/find_rspecs_homepage_spec.rb spec_ui/lib/spec/ui/formatter.rb spec_ui/lib/spec/ui/selenium/driver_ext.rb spec_ui/lib/spec/ui/watir/browser.rb spec_ui/lib/spec/ui/watir/matchers.rb spec_ui/Rakefile spec_ui/spec/spec/ui/watir/matchers_spec.rb No big deal, but just wanted to throw this out there to see what you think. Cheers, Wincent From lists at paulbrackenridge.com Thu Jul 26 11:13:44 2007 From: lists at paulbrackenridge.com (Paul Brackenridge) Date: Thu, 26 Jul 2007 16:13:44 +0100 Subject: [rspec-users] rspec_resource error Message-ID: First of all hi, I'm new to the list, and rather new to rspec as will probably show in myquestion. I have tried installing rspec and rspec_on_rails as plugs both using "script/install" and "piston import" commands using the "current release install instructions" here [1]. However, there doesn't seem to be any mention of the rspec_resource generator?. When I run script/generate I get the following: Installed Generators Plugins: authenticated, rspec, rspec_controller, rspec_model, rspec_scaffold Builtin: controller, integration_test, mailer, migration, model, observer, plugin, resource, scaffold, scaffold_resource, session_migration, web_service Could anyone spread any light as to why rspec_resource isn't being installed? Sorry for the simple question but I can't seem to find any help on the rspec rubyforge page or through google. Any help would be much appreciated. Thanks, P [1] http://rspec.rubyforge.org/documentation/rails/install.html -- Paul Brackenridge -------------------------------------------------- E - paul at paulbrackenridge.com B - http://paulbrackenridge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070726/f84cff85/attachment.html From peter_marklund at fastmail.fm Thu Jul 26 12:24:15 2007 From: peter_marklund at fastmail.fm (Peter Marklund) Date: Thu, 26 Jul 2007 18:24:15 +0200 Subject: [rspec-users] Canonical way to generate RSpec HTML report in Rails app Message-ID: Hi! I was just wondering how you typically generate a spec HTML report in a Rails app. Currently I'm doing something like this: spec spec -f h:spec/spec_report.html But that seems sort of clumsy and I would have thought that there was a rake task for it. Have I overlooked something? Thanks! Peter ---------------------------- Peter Marklund Garvar Lundins Gr?nd 7 11220 Stockholm Sweden Mobile Phone: +46-(0)70-4164857 Home Phone: +46-(0)8-50091315 Skype: peter_marklund IM: AIM - petermarklund, MSN - peter_marklund at hotmail.com, Yahoo - peter_marklund2002 http://marklunds.com ---------------------------- From don at donpetersen.net Thu Jul 26 12:37:33 2007 From: don at donpetersen.net (Don Petersen) Date: Thu, 26 Jul 2007 11:37:33 -0500 Subject: [rspec-users] Canonical way to generate RSpec HTML report in Rails app In-Reply-To: References: Message-ID: <67EB38A5-7F3F-4FC4-BC93-4BBDD7FC21E6@donpetersen.net> There might be a "better" way to do it, but I basically ripped off the builtin spec:doc Rake task almost verbatim and made a custom task in my Rails app for generating the HTML report. This isn't anything magical, but you should be able to drop a file called "whatever_you_want.rake" in your lib/tasks with the contents provided, and it'll give you a "spec doc:html_doc" task that will generate the report and save it to "spec/report.html". Here's the task code: http://pastie.textmate.org/82520 Like a said, complete rip off of another builtin task. Notice that it's executing as a dry-run, so it's not actually executing the specs, just generating the report of what specs you have. Take that out and it will actually run them and report accordingly... Don On Jul 26, 2007, at 11:24 AM, Peter Marklund wrote: > Hi! > I was just wondering how you typically generate a spec HTML report in > a Rails app. Currently I'm doing something like this: > > spec spec -f h:spec/spec_report.html > > But that seems sort of clumsy and I would have thought that there was > a rake task for it. Have I overlooked something? > > Thanks! > > Peter > > > > ---------------------------- > Peter Marklund > Garvar Lundins Gr?nd 7 > 11220 Stockholm > Sweden > > Mobile Phone: +46-(0)70-4164857 > Home Phone: +46-(0)8-50091315 > Skype: peter_marklund > > IM: AIM - petermarklund, MSN - peter_marklund at hotmail.com, Yahoo - > peter_marklund2002 > > http://marklunds.com > ---------------------------- > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From peter_marklund at fastmail.fm Thu Jul 26 12:54:12 2007 From: peter_marklund at fastmail.fm (Peter Marklund) Date: Thu, 26 Jul 2007 18:54:12 +0200 Subject: [rspec-users] Canonical way to generate RSpec HTML report in Rails app In-Reply-To: <67EB38A5-7F3F-4FC4-BC93-4BBDD7FC21E6@donpetersen.net> References: <67EB38A5-7F3F-4FC4-BC93-4BBDD7FC21E6@donpetersen.net> Message-ID: Hi Don! Thanks, that looks nice. For now I'm just using this bash alias: alias specdoc='spec spec -f h:spec/spec_report.html; open spec/ spec_report.html' However, I guess it's nicer to have this be a Rake task so that it can be used by the whole development team. I was looking for an easy way to pass options on from rake to the spec command, but I'm sort of starting to get the feeling that sometimes it's better to invoke the spec command directly instead of going via rake just as is the case with Capistrano and the cap command. Cheers Peter On Jul 26, 2007, at 6:37 PM, Don Petersen wrote: > There might be a "better" way to do it, but I basically ripped off > the builtin spec:doc Rake task almost verbatim and made a custom task > in my Rails app for generating the HTML report. This isn't anything > magical, but you should be able to drop a file called > "whatever_you_want.rake" in your lib/tasks with the contents > provided, and it'll give you a "spec doc:html_doc" task that will > generate the report and save it to "spec/report.html". > > Here's the task code: http://pastie.textmate.org/82520 > > Like a said, complete rip off of another builtin task. Notice that > it's executing as a dry-run, so it's not actually executing the > specs, just generating the report of what specs you have. Take that > out and it will actually run them and report accordingly... > > Don > > On Jul 26, 2007, at 11:24 AM, Peter Marklund wrote: > >> Hi! >> I was just wondering how you typically generate a spec HTML report in >> a Rails app. Currently I'm doing something like this: >> >> spec spec -f h:spec/spec_report.html >> >> But that seems sort of clumsy and I would have thought that there was >> a rake task for it. Have I overlooked something? >> >> Thanks! >> >> Peter >> >> >> >> ---------------------------- >> Peter Marklund >> Garvar Lundins Gr?nd 7 >> 11220 Stockholm >> Sweden >> >> Mobile Phone: +46-(0)70-4164857 >> Home Phone: +46-(0)8-50091315 >> Skype: peter_marklund >> >> IM: AIM - petermarklund, MSN - peter_marklund at hotmail.com, Yahoo - >> peter_marklund2002 >> >> http://marklunds.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 ---------------------------- Peter Marklund Garvar Lundins Gr?nd 7 11220 Stockholm Sweden Mobile Phone: +46-(0)70-4164857 Home Phone: +46-(0)8-50091315 Skype: peter_marklund IM: AIM - petermarklund, MSN - peter_marklund at hotmail.com, Yahoo - peter_marklund2002 http://marklunds.com ---------------------------- From drichards at showcase60.com Thu Jul 26 12:50:37 2007 From: drichards at showcase60.com (David Richards) Date: Thu, 26 Jul 2007 10:50:37 -0600 Subject: [rspec-users] rspec_on_rails magical incantations Message-ID: <211720B4-A949-4131-9F65-9C3012FDE48D@showcase60.com> I ran into something really puzzling today. I don't know exactly why it's happening, but I thought I'd share my experiences. I started a dummy app just to test an idea outside of the context of my real work today. So, I quickly get things started: * rails junk * cd junk * ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/ CURRENT/rspec * ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/ CURRENT/rspec_on_rails * script/generate rspec * script/generate rspec_scaffold Junk name:string * script/generate rspec * cp ../mrm/config/database.yml config/ (just a good database script that tells me where I keep my SQLite databases) * rake db:migrate * autotest That gives me an error on @junk = Junk.new in the setup of my scaffolded Junk model. I wrestled with it for a while, and couldn't get around it. I could get the test to pass with rake spec, which uses the other runner, but not with autotest or script/spec, which I believe use the same runner. So I scraped the whole app and started from scratch, this time generating rspec before I generated the scaffold. Turns out this was the trick. Now, why the funny problem, I don't know. I guess the generator needs to see something different while it generates, but I can't imagine what it is. The spec_helper.rb and the spec.opts are the same, I believe. (I checked that between my working app and non- working app and didn't see a difference.) There are the previous- failures.txt, which I can't imagine would affect anything. Then there's script/spec and script/spec_server. I'm sure it has something to do with the scaffold generator talking to them somehow, but since the generated spec is identical, I don't know. Anyway, I'm stumped. If anyone understands this, great. It's one less mystery at the end of the day. If not, I'll just remember to do my incantations in the correct order and post this in case someone else runs into the same problem. Cheers, David From johan at johansorensen.com Thu Jul 26 13:06:45 2007 From: johan at johansorensen.com (=?ISO-8859-1?Q?Johan_S=F8rensen?=) Date: Thu, 26 Jul 2007 19:06:45 +0200 Subject: [rspec-users] Canonical way to generate RSpec HTML report in Rails app In-Reply-To: References: <67EB38A5-7F3F-4FC4-BC93-4BBDD7FC21E6@donpetersen.net> Message-ID: <679ED8CE-70F8-4211-8AED-F4F64ECABEEF@johansorensen.com> On Jul 26, 2007, at 6:54 PM, Peter Marklund wrote: > Hi Don! > Thanks, that looks nice. For now I'm just using this bash alias: > > alias specdoc='spec spec -f h:spec/spec_report.html; open spec/ > spec_report.html' > > However, I guess it's nicer to have this be a Rake task so that it > can be used by the whole development team. I was looking for an easy > way to pass options on from rake to the spec command, but I'm sort of > starting to get the feeling that sometimes it's better to invoke the > spec command directly instead of going via rake just as is the case > with Capistrano and the cap command. > Maybe something like (untested, but it's along the lines of my other SpecTask's): require "spec/rake/spectask" Spec::Rake::SpecTask.new("htmlspecdocs") do |t| t.spec_files = FileList["spec/**/*_spec.rb"] t.spec_opts = [ "--require", File.dirname(__FILE__) + "/../../spec/spec_helper", # maybe just "h" is enough instead of the classpath here "--format", "Spec::Runner::Formatter::HtmlFormatter:doc/ spec_report.html" ] end JS From rob.anderton at thewebfellas.com Thu Jul 26 11:30:39 2007 From: rob.anderton at thewebfellas.com (rob_twf) Date: Thu, 26 Jul 2007 08:30:39 -0700 (PDT) Subject: [rspec-users] Spec for validation plugin Message-ID: <11812924.post@talk.nabble.com> Hi, I'm writing a specification for a model called Location which has a post_code attribute which should be a valid UK postcode. I'm using the http://svn.designbyfront.com/rails/plugins/validates_as_uk_postcode/ validates_as_uk_postcode plugin to handle the validation but I'm not sure how I should properly specify my model. Heres the model code: class Location < ActiveRecord::Base validates_as_uk_postcode :post_code end In my model spec I want something like this (assume @location has been setup as a new Location instance): it "should be invalid if the post code is incorrectly formatted" do @location.post_code => 'Q1 1QQ' @location.should_not be_valid @location.should have(1).error_on(:post_code) end But there are many examples of invalid post codes and they are already tested in the plugin's own test cases. I only really want to test my code, rather than retest the plugin. So my question is how should I write the specification so that it doesn't duplicate the tests in the plugin but at the same time expresses the correct behaviour of the Location model? Thanks in advance, Rob -- View this message in context: http://www.nabble.com/Spec-for-validation-plugin-tf4152378.html#a11812924 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Thu Jul 26 15:10:45 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 26 Jul 2007 15:10:45 -0400 Subject: [rspec-users] Spec for validation plugin In-Reply-To: <11812924.post@talk.nabble.com> References: <11812924.post@talk.nabble.com> Message-ID: <57c63afe0707261210j279d58e1mc74329036d0254c5@mail.gmail.com> On 7/26/07, rob_twf wrote: > > Hi, > > I'm writing a specification for a model called Location which has a > post_code attribute which should be a valid UK postcode. I'm using the > http://svn.designbyfront.com/rails/plugins/validates_as_uk_postcode/ > validates_as_uk_postcode plugin to handle the validation but I'm not sure > how I should properly specify my model. > > Heres the model code: > > class Location < ActiveRecord::Base > validates_as_uk_postcode :post_code > end > > In my model spec I want something like this (assume @location has been setup > as a new Location instance): > > it "should be invalid if the post code is incorrectly formatted" do > @location.post_code => 'Q1 1QQ' > @location.should_not be_valid > @location.should have(1).error_on(:post_code) > end > > But there are many examples of invalid post codes and they are already > tested in the plugin's own test cases. I only really want to test my code, > rather than retest the plugin. > > So my question is how should I write the specification so that it doesn't > duplicate the tests in the plugin but at the same time expresses the correct > behaviour of the Location model? Here are some interesting thoughts on that: http://blog.jayfields.com/2006/12/rails-unit-testing-activerecord.html Just apply the same thinking to rspec. > > Thanks in advance, > Rob > -- > View this message in context: http://www.nabble.com/Spec-for-validation-plugin-tf4152378.html#a11812924 > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Thu Jul 26 15:39:00 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 26 Jul 2007 15:39:00 -0400 Subject: [rspec-users] MockCov: Proof of concept In-Reply-To: <4d4e79cc0707250927x7afe666eoae104c72bdea8b49@mail.gmail.com> References: <4d4e79cc0707250927x7afe666eoae104c72bdea8b49@mail.gmail.com> Message-ID: <4C487041-CECB-45C2-9085-98E86B930505@railsnewbie.com> Yeah - I think that's a neat idea too. Does the code only work with RSpec's mocking framework? Maybe it could be integrated into Rcov somehow. Scott On Jul 25, 2007, at 12:27 PM, Marcus Ahnve wrote: > Really cool - I have asked myself that question several times. > > /Marcus > > On 7/25/07, Ian Leitch wrote: >> Hey list, >> >> RSpec is great, I've been using it at work for a couple of months >> now. One >> gripe I have is that I find it hard to know exactly to what extent >> my code >> is covered by the specs. I am aware of RCov and Heckle; they're >> great, but >> I'd like to demonstrate another perspective of coverage analysis >> I've hacked >> up. >> >> The perspective is that of what is mocked and what isn't, with RCov >> execution analysis mixed in for better viewing. My itch was "To >> what extent >> is my code mocked?" -- hence the name MockCov. >> It produces a report for each file with stubbed methods and >> executed lines >> highlighted. From that I can easily see what my specs failed to >> mock and >> therefore most probably didn't specify any kind of behavior for. >> >> Here is a sample report: >> http://zioko.com/review_drop.rb.html >> (please forgive the small size of this sample, my employer >> understandably >> didn't want me showing too much of our code) >> >> You'll notice that there isn't any kind of statistical coverage >> summary, I'm >> not sure how to quantity the results and indeed haven't spent any >> time >> thinking about it; that can come later. For now I'd just like to >> gauge the >> response to this. >> >> I haven't packaged the code up yet, it's a horrible hack and needs >> to be >> reworked from scratch; I need to talk with someone on how best to >> integrate >> it with RSpec before that happens though. >> >> Let me know your thoughts. >> >> Cheers >> Ian >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > -- > http://marcus.ahnve.net > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From carpeaqua at gmail.com Thu Jul 26 16:29:07 2007 From: carpeaqua at gmail.com (Justin Williams) Date: Thu, 26 Jul 2007 15:29:07 -0500 Subject: [rspec-users] Mocking Access Control In-Reply-To: <981f96b60707241533j36cfdb90ifbb025bc6e85628e@mail.gmail.com> References: <981f96b60707241446sfa91203j5a8f804f9007f346@mail.gmail.com> <57c63afe0707241451h619efac8m68e49ef6661b2002@mail.gmail.com> <981f96b60707241533j36cfdb90ifbb025bc6e85628e@mail.gmail.com> Message-ID: <981f96b60707261329m4e3b0397s3e1a950b30f1a616@mail.gmail.com> I've done some more work on the specs, and it seems that my mocks aren't pushing in the roles array associated with current_user. describe UsersController do before(:each) do @user = mock_model(User, :id => 1, :email => 'teamup at teamup.host', :password => 'teamup' ) controller.stub!(:current_user).and_return(@user) end it "should login as a tutor" do @role = mock_model(Role) @role.stub!(:title).and_return("tutor") @user.should_receive(:roles).and_return([@role]) @user.stub!(:type).and_return("Tutor") User.should_receive(:authenticate).with('teamup at teamup.host','teamup').and_return(@user) session[:user] = @user.id post :login, :login => {:email => "teamup at teamup.host", :password => "teamup"} response.should be_success response.should redirect_to(:controller => "toolkit/overview") should_be_logged_in end end The error i receive is 'UsersController should login as a tutor' FAILED expected redirect to {:controller=>"toolkit/overview"}, got no redirect". If I modify the test to be should render_template("index") it will fail, saying that the template is reverting back to login. Any ideas on what I'm doing wrong? Thanks! - j On 7/24/07, Justin Williams wrote: > On 7/24/07, David Chelimsky wrote: > > > Would you please post the code for the actions as well? > > def login > if request.post? > begin > session[:user] = User.authenticate(params[:login][:email], > params[:login][:password]).id > > if current_user.roles.include?(Role.find_by_title("employee")) or > current_user.roles.include?(Role.find_by_title("administrator")) > redirect_to staff_path > elsif current_user.roles.include?(Role.find_by_title("tutor")) > redirect_to toolkit_path > elsif current_user.roles.include?(Role.find_by_title("client")) > redirect_to client_path > end > rescue > flash[:warning] = "Your e-mail address or password is invalid." > render :action => "login" > end > end > end > > > It should also be noted, I realized the specs have two different sets > of credentials. Modifying this to use a single one doesn't correct > it. I was just a bit too liberal in my cut/pasting for email. > > Thanks! > > - j > -- - Justin Williams justin at carpeaqua.com work: http://www.secondgearllc.com/ play: http://www.carpeaqua.com From court3nay at gmail.com Thu Jul 26 17:22:36 2007 From: court3nay at gmail.com (Courtenay) Date: Thu, 26 Jul 2007 14:22:36 -0700 Subject: [rspec-users] Mocking Access Control In-Reply-To: <981f96b60707261329m4e3b0397s3e1a950b30f1a616@mail.gmail.com> References: <981f96b60707241446sfa91203j5a8f804f9007f346@mail.gmail.com> <57c63afe0707241451h619efac8m68e49ef6661b2002@mail.gmail.com> <981f96b60707241533j36cfdb90ifbb025bc6e85628e@mail.gmail.com> <981f96b60707261329m4e3b0397s3e1a950b30f1a616@mail.gmail.com> Message-ID: <4b430c8f0707261422o5354b162h7e99f8d1e8d77caf@mail.gmail.com> For starters, refactor your user<-->roles interaction. class User def has_role?(name) role = Role.find_by_name(name) roles.include?(role) end end Trust me, this will make things much easier to spec, and later, to scale. Also, it keeps the DB-specific stuff ("find") in the model, where it belongs. It is my belief that if you see a "find" call in the controller, you could probably refactor it and make it easier to maintain, and just plain better. For example, this will only make one DB call per role check for a total of ~5 db calls def has_role?(name) roles.count(:conditions => { :name => name }) > 0 end This will make one db call to retrieve the list of role names for a total of 1 db call for the whole action. def has_role?(name) @role_names ||= roles.map(&:name) @role_names.include?(name) end So you can change the implementation without screwing round with a bunch of tests. In fact neither of these would require a change of controller specs. @user.should_receive(:has_role?).with('tutor').and_return(true) Hope this helps :) Courtenay On 7/26/07, Justin Williams wrote: > I've done some more work on the specs, and it seems that my mocks > aren't pushing in the roles array associated with current_user. > > > describe UsersController do > before(:each) do > @user = mock_model(User, > :id => 1, > :email => 'teamup at teamup.host', > :password => 'teamup' > ) > > controller.stub!(:current_user).and_return(@user) > end > > it "should login as a tutor" do > @role = mock_model(Role) > @role.stub!(:title).and_return("tutor") > @user.should_receive(:roles).and_return([@role]) > @user.stub!(:type).and_return("Tutor") > > User.should_receive(:authenticate).with('teamup at teamup.host','teamup').and_return(@user) > session[:user] = @user.id > post :login, :login => {:email => "teamup at teamup.host", :password > => "teamup"} > response.should be_success > response.should redirect_to(:controller => "toolkit/overview") > should_be_logged_in > end > end > > > The error i receive is 'UsersController should login as a tutor' > FAILED expected redirect to {:controller=>"toolkit/overview"}, got no > redirect". If I modify the test to be should render_template("index") > it will fail, saying that the template is reverting back to login. > > Any ideas on what I'm doing wrong? > > Thanks! > > - j > > On 7/24/07, Justin Williams wrote: > > On 7/24/07, David Chelimsky wrote: > > > > > Would you please post the code for the actions as well? > > > > def login > > if request.post? > > begin > > session[:user] = User.authenticate(params[:login][:email], > > params[:login][:password]).id > > > > if current_user.roles.include?(Role.find_by_title("employee")) or > > current_user.roles.include?(Role.find_by_title("administrator")) > > redirect_to staff_path > > elsif current_user.roles.include?(Role.find_by_title("tutor")) > > redirect_to toolkit_path > > elsif current_user.roles.include?(Role.find_by_title("client")) > > redirect_to client_path > > end > > rescue > > flash[:warning] = "Your e-mail address or password is invalid." > > render :action => "login" > > end > > end > > end > > > > > > It should also be noted, I realized the specs have two different sets > > of credentials. Modifying this to use a single one doesn't correct > > it. I was just a bit too liberal in my cut/pasting for email. > > > > Thanks! > > > > - j > > > > > -- > - > Justin Williams > justin at carpeaqua.com > work: http://www.secondgearllc.com/ > play: http://www.carpeaqua.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From crafterm at redartisan.com Thu Jul 26 18:52:16 2007 From: crafterm at redartisan.com (Marcus Crafter) Date: Fri, 27 Jul 2007 08:52:16 +1000 Subject: [rspec-users] rspec_resource error In-Reply-To: References: Message-ID: <73AC1761-5E6B-4DF8-975C-11E0F6F2B7CB@redartisan.com> Hi Paul, On 27/07/2007, at 1:13 AM, Paul Brackenridge wrote: > When I run script/generate I get the following: > > Installed Generators > Plugins: authenticated, rspec, rspec_controller, rspec_model, > rspec_scaffold > Builtin: controller, integration_test, mailer, migration, model, > observer, plugin, resource, scaffold, scaffold_resource, > session_migration, web_service > > Could anyone spread any light as to why rspec_resource isn't being > installed? Sorry for the simple question but I can't seem to find > any help on the rspec rubyforge page or through google. It's been renamed from rspec_resource to rspec_scaffold in a more recent release, looks like you're installation is good to go. We should look at updating the web site to reflect the name change. Hope this helps mate. Cheers, Marcus From lists at paulbrackenridge.com Thu Jul 26 18:55:19 2007 From: lists at paulbrackenridge.com (Paul Brackenridge) Date: Thu, 26 Jul 2007 23:55:19 +0100 Subject: [rspec-users] rspec_resource error In-Reply-To: <73AC1761-5E6B-4DF8-975C-11E0F6F2B7CB@redartisan.com> References: <73AC1761-5E6B-4DF8-975C-11E0F6F2B7CB@redartisan.com> Message-ID: On 26/07/07, Marcus Crafter wrote: > > > > It's been renamed from rspec_resource to rspec_scaffold in a more > recent release, looks like you're installation is good to go. We > should look at updating the web site to reflect the name change. > > Hope this helps mate. > > Cheers, > > Marcus > Ahhh!! Great news. Thanks for that :-) -- Paul Brackenridge -------------------------------------------------- E - paul at paulbrackenridge.com B - http://paulbrackenridge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070726/17d0ecbf/attachment.html From yrashk at gmail.com Thu Jul 26 19:26:28 2007 From: yrashk at gmail.com (Yurii Rashkovskii) Date: Fri, 27 Jul 2007 02:26:28 +0300 Subject: [rspec-users] response.should_not redirect_to Message-ID: <87A4A3F6-CA21-4667-80BF-BCF6AB018742@verbdev.com> Hey, May be it is just too deep night over here and I'm missing something though I got this failure on {{{response.should_not redirect_to}}}: 'QueuesController should allow authenticated user to access 'show'' FAILED Matcher does not support should_not. See Spec::Matchers for more information about matchers. Also I've found this in rspec_on_rails sources: # response.should_not redirect_to(url) # response.should_not redirect_to(:action => action_name) # response.should_not redirect_to(:controller => controller_name, :action => action_name) So, am I really missing something important? I've added negative_failure_message to RedirectTo matcher and it seems to function just fine (though as I've stated, it's quite late over here, so I could be wrong) class Spec::Rails::Matchers::RedirectTo def negative_failure_message return %Q{expected to not to be redirected to # {@expected.inspect}, but actually was redirected there} if @redirected end end Any ideas? From dchelimsky at gmail.com Thu Jul 26 20:26:35 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 26 Jul 2007 19:26:35 -0500 Subject: [rspec-users] response.should_not redirect_to In-Reply-To: <87A4A3F6-CA21-4667-80BF-BCF6AB018742@verbdev.com> References: <87A4A3F6-CA21-4667-80BF-BCF6AB018742@verbdev.com> Message-ID: <57c63afe0707261726p693e9c58q71aad774870d2432@mail.gmail.com> On 7/26/07, Yurii Rashkovskii wrote: > Hey, > > May be it is just too deep night over here and I'm missing something > though I got this failure on {{{response.should_not redirect_to}}}: > > 'QueuesController should allow authenticated user to access 'show'' > FAILED > Matcher does not support should_not. > See Spec::Matchers for more information > about matchers. > > Also I've found this in rspec_on_rails sources: > > # response.should_not redirect_to(url) > # response.should_not redirect_to(:action => action_name) > # response.should_not redirect_to(:controller => > controller_name, :action => action_name) > > > So, am I really missing something important? > > I've added negative_failure_message to RedirectTo matcher and it > seems to function just fine (though as I've stated, it's quite late > over here, so I could be wrong) > > class Spec::Rails::Matchers::RedirectTo > def negative_failure_message > return %Q{expected to not to be redirected to # > {@expected.inspect}, but actually was redirected there} if @redirected > end > end > > Any ideas? Sorry - the docs are inconsistent with the code - I intended to NOT allow "should_not redirect_to" because it seemed sort of silly to me. I would think you either want it to redirect somewhere known or expect something other than a redirect. WDYT? David From yrashk at gmail.com Thu Jul 26 20:31:42 2007 From: yrashk at gmail.com (Yurii Rashkovskii) Date: Fri, 27 Jul 2007 03:31:42 +0300 Subject: [rspec-users] response.should_not redirect_to In-Reply-To: <57c63afe0707261726p693e9c58q71aad774870d2432@mail.gmail.com> References: <87A4A3F6-CA21-4667-80BF-BCF6AB018742@verbdev.com> <57c63afe0707261726p693e9c58q71aad774870d2432@mail.gmail.com> Message-ID: <187B8267-CAE5-41AD-B449-FA4556A86AFF@verbdev.com> On Jul 27, 2007, at 3:26 AM, David Chelimsky wrote: > On 7/26/07, Yurii Rashkovskii wrote: >> Hey, >> >> May be it is just too deep night over here and I'm missing something >> though I got this failure on {{{response.should_not redirect_to}}}: >> >> 'QueuesController should allow authenticated user to access 'show'' >> FAILED >> Matcher does not support should_not. >> See Spec::Matchers for more information >> about matchers. ... >> >> class Spec::Rails::Matchers::RedirectTo >> def negative_failure_message >> return %Q{expected to not to be redirected to # >> {@expected.inspect}, but actually was redirected there} if >> @redirected >> end >> end >> >> Any ideas? > > Sorry - the docs are inconsistent with the code - I intended to NOT > allow "should_not redirect_to" because it seemed sort of silly to me. > I would think you either want it to redirect somewhere known or expect > something other than a redirect. WDYT? Here is an extract from my source code it "should allow authenticated user to access '#{action}'" do @user = mock_user_authentication(:id => 1, :identity_url => "http://openid.server/yrashk", :queues => []) get action, params assigns[:current_user].should == @user flash[:error].should be_nil response.should_not redirect_to(login_url) end Depending on action, it is either successful response or response that redirects somewhere (but not to login, since user is "proven" to be authenticated). In this example, I really don't want to care, whether it was successful response or redirection to somewhere, until it is not a redirection to login URL. Stupid enough? Yurii. From dchelimsky at gmail.com Thu Jul 26 20:44:15 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 26 Jul 2007 19:44:15 -0500 Subject: [rspec-users] response.should_not redirect_to In-Reply-To: <187B8267-CAE5-41AD-B449-FA4556A86AFF@verbdev.com> References: <87A4A3F6-CA21-4667-80BF-BCF6AB018742@verbdev.com> <57c63afe0707261726p693e9c58q71aad774870d2432@mail.gmail.com> <187B8267-CAE5-41AD-B449-FA4556A86AFF@verbdev.com> Message-ID: <57c63afe0707261744s5bdb9ca4ob7d4a68585874767@mail.gmail.com> On 7/26/07, Yurii Rashkovskii wrote: > > On Jul 27, 2007, at 3:26 AM, David Chelimsky wrote: > > > On 7/26/07, Yurii Rashkovskii wrote: > >> Hey, > >> > >> May be it is just too deep night over here and I'm missing something > >> though I got this failure on {{{response.should_not redirect_to}}}: > >> > >> 'QueuesController should allow authenticated user to access 'show'' > >> FAILED > >> Matcher does not support should_not. > >> See Spec::Matchers for more information > >> about matchers. > > ... > > >> > >> class Spec::Rails::Matchers::RedirectTo > >> def negative_failure_message > >> return %Q{expected to not to be redirected to # > >> {@expected.inspect}, but actually was redirected there} if > >> @redirected > >> end > >> end > >> > >> Any ideas? > > > > Sorry - the docs are inconsistent with the code - I intended to NOT > > allow "should_not redirect_to" because it seemed sort of silly to me. > > I would think you either want it to redirect somewhere known or expect > > something other than a redirect. WDYT? > > Here is an extract from my source code > > it "should allow authenticated user to access '#{action}'" do > @user = mock_user_authentication(:id => 1, :identity_url => > "http://openid.server/yrashk", :queues => []) > get action, params > assigns[:current_user].should == @user > flash[:error].should be_nil > response.should_not redirect_to(login_url) > end > > Depending on action, it is either successful response or response > that redirects somewhere (but not to login, since user is "proven" to > be authenticated). In this example, I really don't want to care, > whether it was successful response or redirection to somewhere, until > it is not a redirection to login URL. > > Stupid enough? That's not a fair question. Wanna submit a patch? > > Yurii. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From yrashk at gmail.com Thu Jul 26 20:49:08 2007 From: yrashk at gmail.com (Yurii Rashkovskii) Date: Fri, 27 Jul 2007 03:49:08 +0300 Subject: [rspec-users] response.should_not redirect_to In-Reply-To: <57c63afe0707261744s5bdb9ca4ob7d4a68585874767@mail.gmail.com> References: <87A4A3F6-CA21-4667-80BF-BCF6AB018742@verbdev.com> <57c63afe0707261726p693e9c58q71aad774870d2432@mail.gmail.com> <187B8267-CAE5-41AD-B449-FA4556A86AFF@verbdev.com> <57c63afe0707261744s5bdb9ca4ob7d4a68585874767@mail.gmail.com> Message-ID: <3FF93100-300F-41C6-9754-69404408BBBC@verbdev.com> David, >> >> Here is an extract from my source code >> >> it "should allow authenticated user to access '#{action}'" do >> @user = mock_user_authentication(:id => 1, :identity_url => >> "http://openid.server/yrashk", :queues => []) >> get action, params >> assigns[:current_user].should == @user >> flash[:error].should be_nil >> response.should_not redirect_to(login_url) >> end >> >> Depending on action, it is either successful response or response >> that redirects somewhere (but not to login, since user is "proven" to >> be authenticated). In this example, I really don't want to care, >> whether it was successful response or redirection to somewhere, until >> it is not a redirection to login URL. >> >> Stupid enough? > > That's not a fair question. > > Wanna submit a patch? > With please ? the code was above, once I will understand where should I put a spec for it. I got some misunderstanding there (probably the night is reason :) Yurii. From dchelimsky at gmail.com Thu Jul 26 20:52:40 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 26 Jul 2007 19:52:40 -0500 Subject: [rspec-users] response.should_not redirect_to In-Reply-To: <3FF93100-300F-41C6-9754-69404408BBBC@verbdev.com> References: <87A4A3F6-CA21-4667-80BF-BCF6AB018742@verbdev.com> <57c63afe0707261726p693e9c58q71aad774870d2432@mail.gmail.com> <187B8267-CAE5-41AD-B449-FA4556A86AFF@verbdev.com> <57c63afe0707261744s5bdb9ca4ob7d4a68585874767@mail.gmail.com> <3FF93100-300F-41C6-9754-69404408BBBC@verbdev.com> Message-ID: <57c63afe0707261752i441fc9bax359ff19082879da9@mail.gmail.com> On 7/26/07, Yurii Rashkovskii wrote: > David, > > >> > >> Here is an extract from my source code > >> > >> it "should allow authenticated user to access '#{action}'" do > >> @user = mock_user_authentication(:id => 1, :identity_url => > >> "http://openid.server/yrashk", :queues => []) > >> get action, params > >> assigns[:current_user].should == @user > >> flash[:error].should be_nil > >> response.should_not redirect_to(login_url) > >> end > >> > >> Depending on action, it is either successful response or response > >> that redirects somewhere (but not to login, since user is "proven" to > >> be authenticated). In this example, I really don't want to care, > >> whether it was successful response or redirection to somewhere, until > >> it is not a redirection to login URL. > >> > >> Stupid enough? > > > > That's not a fair question. > > > > Wanna submit a patch? > > > > With please ? the code was above, once I will understand where should > I put a spec for it. rspec_on_rails/spec/rails/matchers/redirect_to_spec.rb Cheers, David > I got some misunderstanding there (probably the > night is reason :) > > Yurii. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Jul 26 20:55:34 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 26 Jul 2007 19:55:34 -0500 Subject: [rspec-users] MockCov: Proof of concept In-Reply-To: References: Message-ID: <57c63afe0707261755o36220feq5485d506e8b2198b@mail.gmail.com> On 7/25/07, Ian Leitch wrote: > Hey list, > > RSpec is great, I've been using it at work for a couple of months now. One > gripe I have is that I find it hard to know exactly to what extent my code > is covered by the specs. I am aware of RCov and Heckle; they're great, but > I'd like to demonstrate another perspective of coverage analysis I've hacked > up. > > The perspective is that of what is mocked and what isn't, with RCov > execution analysis mixed in for better viewing. My itch was "To what extent > is my code mocked?" -- hence the name MockCov. > It produces a report for each file with stubbed methods and executed lines > highlighted. From that I can easily see what my specs failed to mock and > therefore most probably didn't specify any kind of behavior for. I'm not sure I understand how you get from this report to some action you need to take. Would you elaborate with a specific example? > > Here is a sample report: > http://zioko.com/review_drop.rb.html > (please forgive the small size of this sample, my employer understandably > didn't want me showing too much of our code) > > You'll notice that there isn't any kind of statistical coverage summary, I'm > not sure how to quantity the results and indeed haven't spent any time > thinking about it; that can come later. For now I'd just like to gauge the > response to this. > > I haven't packaged the code up yet, it's a horrible hack and needs to be > reworked from scratch; I need to talk with someone on how best to integrate > it with RSpec before that happens though. > > Let me know your thoughts. > > Cheers > Ian > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From yrashk at gmail.com Thu Jul 26 21:45:44 2007 From: yrashk at gmail.com (Yurii Rashkovskii) Date: Fri, 27 Jul 2007 04:45:44 +0300 Subject: [rspec-users] response.should_not redirect_to In-Reply-To: <57c63afe0707261752i441fc9bax359ff19082879da9@mail.gmail.com> References: <87A4A3F6-CA21-4667-80BF-BCF6AB018742@verbdev.com> <57c63afe0707261726p693e9c58q71aad774870d2432@mail.gmail.com> <187B8267-CAE5-41AD-B449-FA4556A86AFF@verbdev.com> <57c63afe0707261744s5bdb9ca4ob7d4a68585874767@mail.gmail.com> <3FF93100-300F-41C6-9754-69404408BBBC@verbdev.com> <57c63afe0707261752i441fc9bax359ff19082879da9@mail.gmail.com> Message-ID: David, >>>> Depending on action, it is either successful response or response >>>> that redirects somewhere (but not to login, since user is >>>> "proven" to >>>> be authenticated). In this example, I really don't want to care, >>>> whether it was successful response or redirection to somewhere, >>>> until >>>> it is not a redirection to login URL. >>>> >>>> Stupid enough? >>> >>> That's not a fair question. >>> >>> Wanna submit a patch? >>> >> >> With please ? the code was above, once I will understand where should >> I put a spec for it. > > rspec_on_rails/spec/rails/matchers/redirect_to_spec.rb That wasn't an issue, I'd rather was thinking where to place it within this file. Anyway, patch is submitted. Thank you, Yurii. From tim.watson at bt.com Fri Jul 27 03:27:05 2007 From: tim.watson at bt.com (tim.watson at bt.com) Date: Fri, 27 Jul 2007 08:27:05 +0100 Subject: [rspec-users] File.stub! Message-ID: <7E273B565B88AC4A8935D7337A29F1E305436CB5@E03MVX1-UKDY.domain1.systemhost.net> Hi, I'm trying to stub File.open and whenever I do, rspec blows up with the following error message (undefined method `add' for nil:NilClass), which seems to happen because method __add in class Proxy is calling #add on global $rspec_mocks, which in turn is nil. Can someone explain what I'm doing wrong, as I can't seem to stub anything out! Here's my code: class Foo def Foo.open( name, mode ) return name end end describe Something, 'blah blah' do class FooDouble #:nodoc: attr_reader :data def initialize @data = [] end def method_missing( name, *args ) puts "ignoring call to #{name} with args [#{args.each |arg| arg.inspect}]" end def <<(raw_data) @data.push raw_data end end before :all do Foo.stub!( :open ).and_return( FooDouble.new ) #have also tried and_return { FooDouble.new } end ... end From tim.watson at bt.com Fri Jul 27 04:02:05 2007 From: tim.watson at bt.com (tim.watson at bt.com) Date: Fri, 27 Jul 2007 09:02:05 +0100 Subject: [rspec-users] File.stub! In-Reply-To: <7E273B565B88AC4A8935D7337A29F1E305436CB5@E03MVX1-UKDY.domain1.systemhost.net> References: <7E273B565B88AC4A8935D7337A29F1E305436CB5@E03MVX1-UKDY.domain1.systemhost.net> Message-ID: <7E273B565B88AC4A8935D7337A29F1E305436D1A@E03MVX1-UKDY.domain1.systemhost.net> Hi, I've answered my own question. I changed before :all do; to just before do (which is the same as before :each do) and everything works fine. I'm not overly concerned that stubbing has to occur prior to each example method, but why is this the case? If this behaviour is intended (which I'm guessing it is), then perhaps this should make its way into the docs? Tim Watson Technologist BT Web21C SDK Email: tim.watson at bt.com Cell: +44 7918 711 612 -----Original Message----- From: rspec-users-bounces at rubyforge.org [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of tim.watson at bt.com Sent: 27 July 2007 08:27 To: rspec-users at rubyforge.org Subject: Re: [rspec-users] File.stub! Hi, I'm trying to stub File.open and whenever I do, rspec blows up with the following error message (undefined method `add' for nil:NilClass), which seems to happen because method __add in class Proxy is calling #add on global $rspec_mocks, which in turn is nil. Can someone explain what I'm doing wrong, as I can't seem to stub anything out! Here's my code: class Foo def Foo.open( name, mode ) return name end end describe Something, 'blah blah' do class FooDouble #:nodoc: attr_reader :data def initialize @data = [] end def method_missing( name, *args ) puts "ignoring call to #{name} with args [#{args.each |arg| arg.inspect}]" end def <<(raw_data) @data.push raw_data end end before :all do Foo.stub!( :open ).and_return( FooDouble.new ) #have also tried and_return { FooDouble.new } end ... end _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users From port001 at gmail.com Fri Jul 27 04:15:41 2007 From: port001 at gmail.com (Ian Leitch) Date: Fri, 27 Jul 2007 09:15:41 +0100 Subject: [rspec-users] MockCov: Proof of concept In-Reply-To: <4C487041-CECB-45C2-9085-98E86B930505@railsnewbie.com> References: <4d4e79cc0707250927x7afe666eoae104c72bdea8b49@mail.gmail.com> <4C487041-CECB-45C2-9085-98E86B930505@railsnewbie.com> Message-ID: Yeah, only RSpec at the moment, I haven't looked into integrating it with any of the others. The way it does its magic is tightly coupled with RSpecs design, specifically the metaclass proxies. Other frameworks may use the same approach, I don't know. It can't really be integrated with RCov for the reason above, indeed it wouldn't be able to produce any meaningful output if RCov were not used in combination with RSpec. On 26/07/07, Scott Taylor wrote: > > Yeah - I think that's a neat idea too. > > Does the code only work with RSpec's mocking framework? Maybe it > could be integrated into Rcov somehow. > > Scott > > On Jul 25, 2007, at 12:27 PM, Marcus Ahnve wrote: > > > Really cool - I have asked myself that question several times. > > > > /Marcus > > > > On 7/25/07, Ian Leitch wrote: > >> Hey list, > >> > >> RSpec is great, I've been using it at work for a couple of months > >> now. One > >> gripe I have is that I find it hard to know exactly to what extent > >> my code > >> is covered by the specs. I am aware of RCov and Heckle; they're > >> great, but > >> I'd like to demonstrate another perspective of coverage analysis > >> I've hacked > >> up. > >> > >> The perspective is that of what is mocked and what isn't, with RCov > >> execution analysis mixed in for better viewing. My itch was "To > >> what extent > >> is my code mocked?" -- hence the name MockCov. > >> It produces a report for each file with stubbed methods and > >> executed lines > >> highlighted. From that I can easily see what my specs failed to > >> mock and > >> therefore most probably didn't specify any kind of behavior for. > >> > >> Here is a sample report: > >> http://zioko.com/review_drop.rb.html > >> (please forgive the small size of this sample, my employer > >> understandably > >> didn't want me showing too much of our code) > >> > >> You'll notice that there isn't any kind of statistical coverage > >> summary, I'm > >> not sure how to quantity the results and indeed haven't spent any > >> time > >> thinking about it; that can come later. For now I'd just like to > >> gauge the > >> response to this. > >> > >> I haven't packaged the code up yet, it's a horrible hack and needs > >> to be > >> reworked from scratch; I need to talk with someone on how best to > >> integrate > >> it with RSpec before that happens though. > >> > >> Let me know your thoughts. > >> > >> Cheers > >> Ian > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > > > > > -- > > http://marcus.ahnve.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: http://rubyforge.org/pipermail/rspec-users/attachments/20070727/2747c7fe/attachment-0001.html From port001 at gmail.com Fri Jul 27 04:52:25 2007 From: port001 at gmail.com (Ian Leitch) Date: Fri, 27 Jul 2007 09:52:25 +0100 Subject: [rspec-users] MockCov: Proof of concept In-Reply-To: <57c63afe0707261755o36220feq5485d506e8b2198b@mail.gmail.com> References: <57c63afe0707261755o36220feq5485d506e8b2198b@mail.gmail.com> Message-ID: Sure. Say I have Class A and to test it, Spec B. From a quick look at Spec B I'm able to read the 'when' and 'should' descriptions and get a rough idea what the spec covers, yet nothing detailed, to do that I'd have to read the Class and Spec in conjunction, even still, it may not be obvious if a specific method or object is mocked. For example: my_important_method(meth1, meth2) Say we have spec'ed this to test the call with multiple values for meth1, but not for meth2. MockCov allows you to easily see that meth2 isn't stubbed and therefore that the behavior of my_important_method isn't sufficiently covered. Whereas Heckle lets you know about insufficient specs by performing mutations, MockCov should allow you to instead _see_ where the specs are lacking. I'm not saying this is a replacement for Heckle; they should compliment each other quite well. The example I posted in the initial email is very poor. I'm working on an new feature that will highlight variables in the code that were returned by mocked calls (it does so using ParseTree). I'll produce a better example to demonstrate that in the next few days. On 27/07/07, David Chelimsky wrote: > > On 7/25/07, Ian Leitch wrote: > > Hey list, > > > > RSpec is great, I've been using it at work for a couple of months now. > One > > gripe I have is that I find it hard to know exactly to what extent my > code > > is covered by the specs. I am aware of RCov and Heckle; they're great, > but > > I'd like to demonstrate another perspective of coverage analysis I've > hacked > > up. > > > > The perspective is that of what is mocked and what isn't, with RCov > > execution analysis mixed in for better viewing. My itch was "To what > extent > > is my code mocked?" -- hence the name MockCov. > > It produces a report for each file with stubbed methods and executed > lines > > highlighted. From that I can easily see what my specs failed to mock and > > therefore most probably didn't specify any kind of behavior for. > > I'm not sure I understand how you get from this report to some action > you need to take. Would you elaborate with a specific example? > > > > > Here is a sample report: > > http://zioko.com/review_drop.rb.html > > (please forgive the small size of this sample, my employer > understandably > > didn't want me showing too much of our code) > > > > You'll notice that there isn't any kind of statistical coverage summary, > I'm > > not sure how to quantity the results and indeed haven't spent any time > > thinking about it; that can come later. For now I'd just like to gauge > the > > response to this. > > > > I haven't packaged the code up yet, it's a horrible hack and needs to be > > reworked from scratch; I need to talk with someone on how best to > integrate > > it with RSpec before that happens though. > > > > Let me know your thoughts. > > > > Cheers > > Ian > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070727/0626a023/attachment.html From rob.anderton at thewebfellas.com Fri Jul 27 07:29:27 2007 From: rob.anderton at thewebfellas.com (rob_twf) Date: Fri, 27 Jul 2007 04:29:27 -0700 (PDT) Subject: [rspec-users] Spec for validation plugin In-Reply-To: <57c63afe0707261210j279d58e1mc74329036d0254c5@mail.gmail.com> References: <11812924.post@talk.nabble.com> <57c63afe0707261210j279d58e1mc74329036d0254c5@mail.gmail.com> Message-ID: <11827396.post@talk.nabble.com> David Chelimsky-2 wrote: > > > Here are some interesting thoughts on that: > > http://blog.jayfields.com/2006/12/rails-unit-testing-activerecord.html > > Just apply the same thinking to rspec. > > Thanks for the pointer, here's what I've done: In spec_helper.rb: class << ActiveRecord::Base def source_file File.expand_path("#{RAILS_ROOT}/app/models/#{self.name.underscore}.rb") end end (I preferred source_file to standard_path - seemed more descriptive) An then my specification looks like this: it "should validate that the postcode is correctly formatted" do Location.should_receive(:validates_as_uk_postcode).once.with(:post_code) load Location.source_file end That works nicely. I suppose the downside is it allows implementation to creep into the specs but if it saves me having to re-test somebody else's code I can live with it! I also looked at http://spicycode.com/2007/4/2/rspec-expecation-matchers-part-ii SpicyCode's RSpec extensions - the approach here appears to be similar to the code in my original example as it tests validation with a single invalid example and if that returns the expected result then assumes the validation will work for all invalid examples (I may be doing it a disservice here as I've only quickly looked at the source code). This still leaks implementation into the specs and I think I prefer the Jay Fields approach as it, in my opinion, more clearly specifies the expected behaviour of the model. Thanks again, Rob -- View this message in context: http://www.nabble.com/Spec-for-validation-plugin-tf4152378.html#a11827396 Sent from the rspec-users mailing list archive at Nabble.com. From rob.anderton at thewebfellas.com Fri Jul 27 08:27:24 2007 From: rob.anderton at thewebfellas.com (rob_twf) Date: Fri, 27 Jul 2007 05:27:24 -0700 (PDT) Subject: [rspec-users] Spec for validation plugin In-Reply-To: <11827396.post@talk.nabble.com> References: <11812924.post@talk.nabble.com> <57c63afe0707261210j279d58e1mc74329036d0254c5@mail.gmail.com> <11827396.post@talk.nabble.com> Message-ID: <11828149.post@talk.nabble.com> rob_twf wrote: > > > it "should validate that the postcode is correctly formatted" do > > Location.should_receive(:validates_as_uk_postcode).once.with(:post_code) > load Location.source_file > end > > That works nicely. > > Looks like I was a bit eager. Loading the class in this way causes problems with other validations. For example, I add a name attribute to my class and validate it's length like this: class Location < ActiveRecord::Base validates_length_of :name, :in => 1..50 validates_as_uk_postcode :post_code end And have this additional specification: it "should be invalid if the name is too long" do @location.name => 'x' * 51 @location.should_not be_valid @location.should have(1).error_on(:name) end ( This fails because the length validation occurs twice giving two (identical) errors on :name. Removing the post code validation specification allows the name length validation to work correctly. So load() is causing the validation to be defined twice - is there any way to avoid this? -- View this message in context: http://www.nabble.com/Spec-for-validation-plugin-tf4152378.html#a11828149 Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Fri Jul 27 09:35:21 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 27 Jul 2007 08:35:21 -0500 Subject: [rspec-users] File.stub! In-Reply-To: <7E273B565B88AC4A8935D7337A29F1E305436D1A@E03MVX1-UKDY.domain1.systemhost.net> References: <7E273B565B88AC4A8935D7337A29F1E305436CB5@E03MVX1-UKDY.domain1.systemhost.net> <7E273B565B88AC4A8935D7337A29F1E305436D1A@E03MVX1-UKDY.domain1.systemhost.net> Message-ID: <57c63afe0707270635u2f8c984hb6938b4778e525db@mail.gmail.com> On 7/27/07, tim.watson at bt.com wrote: > Hi, > > I've answered my own question. I changed before :all do; to just before > do (which is the same as before :each do) and everything works fine. I'm > not overly concerned that stubbing has to occur prior to each example > method, but why is this the case? If this behaviour is intended (which > I'm guessing it is), then perhaps this should make its way into the > docs? There's an open RFE to deal w/ better integrating before(:all) with everything else: http://rubyforge.org/tracker/?func=detail&group_id=797&aid=10696&atid=3152 > > Tim Watson > Technologist > BT Web21C SDK > Email: tim.watson at bt.com > Cell: +44 7918 711 612 > > > -----Original Message----- > From: rspec-users-bounces at rubyforge.org > [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of > tim.watson at bt.com > Sent: 27 July 2007 08:27 > To: rspec-users at rubyforge.org > Subject: Re: [rspec-users] File.stub! > > Hi, > > I'm trying to stub File.open and whenever I do, rspec blows up with the > following error message (undefined method `add' for nil:NilClass), which > seems to happen because method __add in class Proxy is calling #add on > global $rspec_mocks, which in turn is nil. > > Can someone explain what I'm doing wrong, as I can't seem to stub > anything out! Here's my code: > > class Foo > def Foo.open( name, mode ) > return name > end > end > > describe Something, 'blah blah' do > > class FooDouble #:nodoc: > attr_reader :data > def initialize > @data = [] > end > def method_missing( name, *args ) > puts "ignoring call to #{name} with args [#{args.each |arg| > arg.inspect}]" > end > def <<(raw_data) > @data.push raw_data > end > end > > before :all do > Foo.stub!( :open ).and_return( FooDouble.new ) > #have also tried and_return { FooDouble.new } > 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 ingo at ingoweiss.com Fri Jul 27 13:23:38 2007 From: ingo at ingoweiss.com (Ingo Weiss) Date: Fri, 27 Jul 2007 19:23:38 +0200 Subject: [rspec-users] autotest doesn't notice file changes In-Reply-To: <57c63afe0707270635u2f8c984hb6938b4778e525db@mail.gmail.com> References: <7E273B565B88AC4A8935D7337A29F1E305436CB5@E03MVX1-UKDY.domain1.systemhost.net> <7E273B565B88AC4A8935D7337A29F1E305436D1A@E03MVX1-UKDY.domain1.systemhost.net> <57c63afe0707270635u2f8c984hb6938b4778e525db@mail.gmail.com> Message-ID: <8D99E9E1-9F56-4872-A5D3-DAADDFB79D2E@ingoweiss.com> Hi all, I am trying to use autotest with rspec and rais, and it seems to work fine when I run autotest -rails initially, but then autotest fails to recognize file changes and run tests continuously. Did I skip a step? Here is my setup: rails v1.2.3 rspec plugin v1.0.5 rspec_on_rails plugin v1.0.5 ZenTest gem v3.6.1 Thanks for any help with fixing this! Ingo From dchelimsky at gmail.com Fri Jul 27 13:55:53 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 27 Jul 2007 12:55:53 -0500 Subject: [rspec-users] autotest doesn't notice file changes In-Reply-To: <8D99E9E1-9F56-4872-A5D3-DAADDFB79D2E@ingoweiss.com> References: <7E273B565B88AC4A8935D7337A29F1E305436CB5@E03MVX1-UKDY.domain1.systemhost.net> <7E273B565B88AC4A8935D7337A29F1E305436D1A@E03MVX1-UKDY.domain1.systemhost.net> <57c63afe0707270635u2f8c984hb6938b4778e525db@mail.gmail.com> <8D99E9E1-9F56-4872-A5D3-DAADDFB79D2E@ingoweiss.com> Message-ID: <57c63afe0707271055p7d5c4eb5ra76d991824639bb7@mail.gmail.com> On 7/27/07, Ingo Weiss wrote: > Hi all, > > I am trying to use autotest with rspec and rais, and it seems to work > fine when I run autotest -rails initially, but then autotest fails to > recognize file changes and run tests continuously. Did I skip a step? > Here is my setup: > > rails v1.2.3 > rspec plugin v1.0.5 > rspec_on_rails plugin v1.0.5 > ZenTest gem v3.6.1 Leave off -rails. Just type "autotest" > > Thanks for any help with fixing this! > Ingo > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From carpeaqua at gmail.com Fri Jul 27 16:38:52 2007 From: carpeaqua at gmail.com (Justin Williams) Date: Fri, 27 Jul 2007 15:38:52 -0500 Subject: [rspec-users] Mocking Access Control In-Reply-To: <4b430c8f0707261422o5354b162h7e99f8d1e8d77caf@mail.gmail.com> References: <981f96b60707241446sfa91203j5a8f804f9007f346@mail.gmail.com> <57c63afe0707241451h619efac8m68e49ef6661b2002@mail.gmail.com> <981f96b60707241533j36cfdb90ifbb025bc6e85628e@mail.gmail.com> <981f96b60707261329m4e3b0397s3e1a950b30f1a616@mail.gmail.com> <4b430c8f0707261422o5354b162h7e99f8d1e8d77caf@mail.gmail.com> Message-ID: <981f96b60707271338o1d1ad91cl1d9669fb821f0eec@mail.gmail.com> Thanks for the help. I think I'm getting closer. I'm still not getting a redirect. I still think it's the same reason though. I say this because when I modify the last line of my spec to be render_template("index") instead of redirect, it says that it renders the login template. Am I putting the should_receive for has_role? in the wrong place? My modified code is below. def login if request.post? begin session[:user] = User.authenticate(params[:login][:email], params[:login][:password]).id # Redirect the user as appropriate if current_user.has_role?("tutor") redirect_to toolkit_path end rescue flash[:warning] = "Your e-mail address or password is invalid." render :action => "login" end end end ------ describe UsersController do controller_name :users before(:each) do @current_user = mock_model(User, :email => 'teamup at teamup.host', :password => 'teamup' ) controller.stub!(:current_user).and_return(@current_user) end it "should login as a tutor" do @role = mock_model(Role, :title => 'tutor') @current_user.should_receive(:roles).once.and_return([@role]) User.should_receive(:authenticate).with(@current_user.email, at current_user.password).and_return(@current_user) @current_user.should_receive(:has_role?).with('tutor').and_return(true) post :login, :login => {:email => @current_user.email, :password => @current_user.password} request.session[:user].should == @current_user.id should_be_logged_in response.should be_redirect response.should redirect_to(toolkit_path) end end On 7/26/07, Courtenay wrote: > For starters, refactor your user<-->roles interaction. > > class User > > def has_role?(name) > role = Role.find_by_name(name) > roles.include?(role) > end > > end > > Trust me, this will make things much easier to spec, and later, to > scale. Also, it keeps the DB-specific stuff ("find") in the model, > where it belongs. > > It is my belief that if you see a "find" call in the controller, you > could probably refactor it and make it easier to maintain, and just > plain better. > > For example, this will only make one DB call per role check for a > total of ~5 db calls > > def has_role?(name) > roles.count(:conditions => { :name => name }) > 0 > end > > This will make one db call to retrieve the list of role names for a > total of 1 db call for the whole action. > > def has_role?(name) > @role_names ||= roles.map(&:name) > @role_names.include?(name) > end > > So you can change the implementation without screwing round with a > bunch of tests. In fact neither of these would require a change of > controller specs. > > @user.should_receive(:has_role?).with('tutor').and_return(true) > > Hope this helps :) > > Courtenay > > > On 7/26/07, Justin Williams wrote: > > I've done some more work on the specs, and it seems that my mocks > > aren't pushing in the roles array associated with current_user. > > > > > > describe UsersController do > > before(:each) do > > @user = mock_model(User, > > :id => 1, > > :email => 'teamup at teamup.host', > > :password => 'teamup' > > ) > > > > controller.stub!(:current_user).and_return(@user) > > end > > > > it "should login as a tutor" do > > @role = mock_model(Role) > > @role.stub!(:title).and_return("tutor") > > @user.should_receive(:roles).and_return([@role]) > > @user.stub!(:type).and_return("Tutor") > > > > User.should_receive(:authenticate).with('teamup at teamup.host','teamup').and_return(@user) > > session[:user] = @user.id > > post :login, :login => {:email => "teamup at teamup.host", :password > > => "teamup"} > > response.should be_success > > response.should redirect_to(:controller => "toolkit/overview") > > should_be_logged_in > > end > > end > > > > > > The error i receive is 'UsersController should login as a tutor' > > FAILED expected redirect to {:controller=>"toolkit/overview"}, got no > > redirect". If I modify the test to be should render_template("index") > > it will fail, saying that the template is reverting back to login. > > > > Any ideas on what I'm doing wrong? > > > > Thanks! > > > > - j > > > > On 7/24/07, Justin Williams wrote: > > > On 7/24/07, David Chelimsky wrote: > > > > > > > Would you please post the code for the actions as well? > > > > > > def login > > > if request.post? > > > begin > > > session[:user] = User.authenticate(params[:login][:email], > > > params[:login][:password]).id > > > > > > if current_user.roles.include?(Role.find_by_title("employee")) or > > > current_user.roles.include?(Role.find_by_title("administrator")) > > > redirect_to staff_path > > > elsif current_user.roles.include?(Role.find_by_title("tutor")) > > > redirect_to toolkit_path > > > elsif current_user.roles.include?(Role.find_by_title("client")) > > > redirect_to client_path > > > end > > > rescue > > > flash[:warning] = "Your e-mail address or password is invalid." > > > render :action => "login" > > > end > > > end > > > end > > > > > > > > > It should also be noted, I realized the specs have two different sets > > > of credentials. Modifying this to use a single one doesn't correct > > > it. I was just a bit too liberal in my cut/pasting for email. > > > > > > Thanks! > > > > > > - j > > > > > > > > > -- > > - > > Justin Williams > > justin at carpeaqua.com > > work: http://www.secondgearllc.com/ > > play: http://www.carpeaqua.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 > -- - Justin Williams justin at carpeaqua.com work: http://www.secondgearllc.com/ play: http://www.carpeaqua.com From court3nay at gmail.com Fri Jul 27 16:55:16 2007 From: court3nay at gmail.com (Courtenay) Date: Fri, 27 Jul 2007 13:55:16 -0700 Subject: [rspec-users] Mocking Access Control In-Reply-To: <981f96b60707271338o1d1ad91cl1d9669fb821f0eec@mail.gmail.com> References: <981f96b60707241446sfa91203j5a8f804f9007f346@mail.gmail.com> <57c63afe0707241451h619efac8m68e49ef6661b2002@mail.gmail.com> <981f96b60707241533j36cfdb90ifbb025bc6e85628e@mail.gmail.com> <981f96b60707261329m4e3b0397s3e1a950b30f1a616@mail.gmail.com> <4b430c8f0707261422o5354b162h7e99f8d1e8d77caf@mail.gmail.com> <981f96b60707271338o1d1ad91cl1d9669fb821f0eec@mail.gmail.com> Message-ID: <4b430c8f0707271355v4c20f479i60fbda9651facbaf@mail.gmail.com> On 7/27/07, Justin Williams wrote: > Thanks for the help. > You're welcome > I think I'm getting closer. I'm still not getting a redirect. I > still think it's the same reason though. I say this because when I > modify the last line of my spec to be render_template("index") instead > of redirect, it says that it renders the login template. > > Am I putting the should_receive for has_role? in the wrong place? > > My modified code is below. > > def login > if request.post? Have you seen the restful authentication plugin? It would simplify your code. I modified it for rSpec. You can view it in a working app here: http://sample.caboo.se/empty_rails_app/trunk/app/controllers/session_controller.rb > begin > session[:user] = User.authenticate(params[:login][:email], > params[:login][:password]).id > > # Redirect the user as appropriate > if current_user.has_role?("tutor") > redirect_to toolkit_path return Add a return here. You should get in the habit of putting a "return" after a redirect > end > rescue > flash[:warning] = "Your e-mail address or password is invalid." > render :action => "login" > end > end > end > > ------ > > describe UsersController do > controller_name :users > > before(:each) do > @current_user = mock_model(User, > :email => 'teamup at teamup.host', > :password => 'teamup' > ) > controller.stub!(:current_user).and_return(@current_user) > end > > it "should login as a tutor" do These two lines aren't needed: > @role = mock_model(Role, :title => 'tutor') > @current_user.should_receive(:roles).once.and_return([@role]) The point of refactoring the role stuff into "has_role?" is that the implementation of "has_role" could be anything. See how your controller doesn't know anything about "User.has_role?" Your test shouldn't either. Just assume that it works. And test it in the user model specs. Put this line before the authenticate line and it all should work. @current_user.should_receive(:has_role?).with('tutor').and_return true > User.should_receive(:authenticate).with(@current_user.email, at current_user.password).and_return(@current_user) > > @current_user.should_receive(:has_role?).with('tutor').and_return(true) > post :login, :login => {:email => @current_user.email, :password > => @current_user.password} > request.session[:user].should == @current_user.id > > should_be_logged_in > > response.should be_redirect > response.should redirect_to(toolkit_path) > end > end > From dchelimsky at gmail.com Fri Jul 27 17:38:23 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 27 Jul 2007 16:38:23 -0500 Subject: [rspec-users] Coding standards and whitespace In-Reply-To: <9989DB21-CFBE-4AC4-B9F4-A46D9A3E0A4A@wincent.com> References: <9989DB21-CFBE-4AC4-B9F4-A46D9A3E0A4A@wincent.com> Message-ID: <57c63afe0707271438q54044d4ai5ca5cab2c05f3dbd@mail.gmail.com> On 7/26/07, Wincent Colaiuta wrote: > Recently as a result of using Git I've noticed a number of > inconsistencies in the RSpec codebase with respect to whitespace > (mixed line endings, mixed use of spaces and tabs for indentation, > and trailing whitespace at the end of lines). I never would have > noticed, but Git produces nice colorized diff output which highlights > these kinds of inconsistencies. > > I wanted to ask if the core RSpec team had established any > conventions/standards for these things. The basic rationale is that > if all contributors agree to a small number of conventions for > whitespace there are less likely to be changesets with non- > substantive whitespace differences (really, false alarms). Your thinking makes sense, but we haven't set a standard for this. Do you know how to configure TextMate (which most of us use) to take care of this automagically when saving files? From dchelimsky at gmail.com Fri Jul 27 17:46:36 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 27 Jul 2007 16:46:36 -0500 Subject: [rspec-users] Rspec on rails with out database? In-Reply-To: <3ED1F6E8-5ABF-470C-A1E6-1BC920A5CB85@opensourceconnections.com> References: <3ED1F6E8-5ABF-470C-A1E6-1BC920A5CB85@opensourceconnections.com> Message-ID: <57c63afe0707271446p58760487sf2daa7bb8b9f5322@mail.gmail.com> On 7/24/07, Eric Pugh wrote: > Hi all, > > I am trying to use rspec_on_rails in a Rails app that doesn't have a > database. so far I have just been faking it out by dumping in a > sqlite3 database just to make Rails happy. Try deleting config/database.yml (or renaming it to something else) and then running: rake spec That should do it. From dchelimsky at gmail.com Fri Jul 27 17:48:50 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 27 Jul 2007 16:48:50 -0500 Subject: [rspec-users] Rspec on rails with out database? In-Reply-To: <57c63afe0707271446p58760487sf2daa7bb8b9f5322@mail.gmail.com> References: <3ED1F6E8-5ABF-470C-A1E6-1BC920A5CB85@opensourceconnections.com> <57c63afe0707271446p58760487sf2daa7bb8b9f5322@mail.gmail.com> Message-ID: <57c63afe0707271448y4720f778wf5af1e35e43c6cad@mail.gmail.com> On 7/27/07, David Chelimsky wrote: > On 7/24/07, Eric Pugh wrote: > > Hi all, > > > > I am trying to use rspec_on_rails in a Rails app that doesn't have a > > database. so far I have just been faking it out by dumping in a > > sqlite3 database just to make Rails happy. > > Try deleting config/database.yml (or renaming it to something else) > and then running: > > rake spec > > That should do it. I take it back. It doesn't work. There is an open RFE on making this work - perhaps it's time to address it. From dchelimsky at gmail.com Fri Jul 27 17:57:03 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 27 Jul 2007 16:57:03 -0500 Subject: [rspec-users] Rspec on rails with out database? In-Reply-To: <57c63afe0707271448y4720f778wf5af1e35e43c6cad@mail.gmail.com> References: <3ED1F6E8-5ABF-470C-A1E6-1BC920A5CB85@opensourceconnections.com> <57c63afe0707271446p58760487sf2daa7bb8b9f5322@mail.gmail.com> <57c63afe0707271448y4720f778wf5af1e35e43c6cad@mail.gmail.com> Message-ID: <57c63afe0707271457t360b6173k56ba500c05993c4c@mail.gmail.com> On 7/27/07, David Chelimsky wrote: > On 7/27/07, David Chelimsky wrote: > > On 7/24/07, Eric Pugh wrote: > > > Hi all, > > > > > > I am trying to use rspec_on_rails in a Rails app that doesn't have a > > > database. so far I have just been faking it out by dumping in a > > > sqlite3 database just to make Rails happy. > > > > Try deleting config/database.yml (or renaming it to something else) > > and then running: > > > > rake spec > > > > That should do it. > > I take it back. It doesn't work. There is an open RFE on making this > work - perhaps it's time to address it. > Ah - this worked using Rails 1.2.3 and RSpec's trunk. In config/environments.rb: Rails::Initializer.run do |config| config.frameworks -= [ :active_record ] end Cheers, David From barjunk at attglobal.net Fri Jul 27 20:58:07 2007 From: barjunk at attglobal.net (barsalou) Date: Fri, 27 Jul 2007 16:58:07 -0800 Subject: [rspec-users] Rspec on rails with out database? In-Reply-To: <57c63afe0707271457t360b6173k56ba500c05993c4c@mail.gmail.com> References: <3ED1F6E8-5ABF-470C-A1E6-1BC920A5CB85@opensourceconnections.com> <57c63afe0707271446p58760487sf2daa7bb8b9f5322@mail.gmail.com> <57c63afe0707271448y4720f778wf5af1e35e43c6cad@mail.gmail.com> <57c63afe0707271457t360b6173k56ba500c05993c4c@mail.gmail.com> Message-ID: <20070727165807.itnhd5f400o4c0gk@lcgalaska.com> Quoting David Chelimsky : > On 7/27/07, David Chelimsky wrote: >> On 7/27/07, David Chelimsky wrote: >> > On 7/24/07, Eric Pugh wrote: >> > > Hi all, >> > > >> > > I am trying to use rspec_on_rails in a Rails app that doesn't have a >> > > database. so far I have just been faking it out by dumping in a >> > > sqlite3 database just to make Rails happy. >> > >> > Try deleting config/database.yml (or renaming it to something else) >> > and then running: >> > >> > rake spec >> > >> > That should do it. >> >> I take it back. It doesn't work. There is an open RFE on making this >> work - perhaps it's time to address it. >> > > Ah - this worked using Rails 1.2.3 and RSpec's trunk. In > config/environments.rb: > > Rails::Initializer.run do |config| > config.frameworks -= [ :active_record ] > end David, I like this solution too, but then you don't have access to some of the other nicities for a model, like validations. I found these links: http://www.realityforge.org/articles/2005/12/02/validations-for-non-activerecord-model-objects http://wiki.rubyonrails.com/rails/pages/HowToUseValidationsWithoutExtendingActiveRecord http://www.railsweenie.com/forums/2/topics/724 That talk about different ways to solve this. The last link seems like the best. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From ingo at ingoweiss.com Sat Jul 28 08:11:19 2007 From: ingo at ingoweiss.com (Ingo Weiss) Date: Sat, 28 Jul 2007 14:11:19 +0200 Subject: [rspec-users] autotest doesn't notice file changes In-Reply-To: <57c63afe0707271055p7d5c4eb5ra76d991824639bb7@mail.gmail.com> References: <7E273B565B88AC4A8935D7337A29F1E305436CB5@E03MVX1-UKDY.domain1.systemhost.net> <7E273B565B88AC4A8935D7337A29F1E305436D1A@E03MVX1-UKDY.domain1.systemhost.net> <57c63afe0707270635u2f8c984hb6938b4778e525db@mail.gmail.com> <8D99E9E1-9F56-4872-A5D3-DAADDFB79D2E@ingoweiss.com> <57c63afe0707271055p7d5c4eb5ra76d991824639bb7@mail.gmail.com> Message-ID: This works - thanks, David! Ingo On Jul 27, 2007, at 7:55 PM, David Chelimsky wrote: > Leave off -rails. Just type "autotest" From has.sox at gmail.com Sat Jul 28 09:28:28 2007 From: has.sox at gmail.com (Daniel N) Date: Sat, 28 Jul 2007 23:28:28 +1000 Subject: [rspec-users] specing a call to render :layout => "some_layout" Message-ID: <2fff50390707280628g64c06e4dpfb48ed70194c3d94@mail.gmail.com> I'm trying to specify that an action should be rendered with a given layout one particular spec. What I've got at the moment is this. it "should render with the grabber layout" do controller.should_receive( :render ).with( :layout => "my_layout" ) do_get end This doesnt work even though this call to render is being executed. render :layout => "my_layout" Firstly I don't understand why this isn't working. I'm getting an object inspect with this message at the end expected :render with ({:layout=>"my_layout"}) but received it with (no > args) > I'd really like to understand why this isn't working, but I don't really like it anyway. I mean, I really want to spec that under a particular set of conditions it renders with a given layout. I can't imagine I'm the first person to come up against this one. How are other people handling this? Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070728/1a148ea7/attachment.html From dchelimsky at gmail.com Sat Jul 28 09:38:19 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 28 Jul 2007 08:38:19 -0500 Subject: [rspec-users] specing a call to render :layout => "some_layout" In-Reply-To: <2fff50390707280628g64c06e4dpfb48ed70194c3d94@mail.gmail.com> References: <2fff50390707280628g64c06e4dpfb48ed70194c3d94@mail.gmail.com> Message-ID: <57c63afe0707280638u5c8457a8xf11113d8c37700b8@mail.gmail.com> On 7/28/07, Daniel N wrote: > I'm trying to specify that an action should be rendered with a given layout > one particular spec. > > What I've got at the moment is this. > > it "should render with the grabber layout" do > controller.should_receive( :render ).with( :layout => "my_layout" ) > do_get > end > > This doesnt work even though this call to render is being executed. > > render :layout => "my_layout" > > Firstly I don't understand why this isn't working. I'm getting an object > inspect with this message at the end > > > expected :render with ({:layout=>"my_layout"}) but received it with (no > args) > > > > I'd really like to understand why this isn't working, but I don't really > like it anyway. I mean, I really want to spec that under a particular set > of conditions it renders with a given layout. > > I can't imagine I'm the first person to come up against this one. How are > other people handling this? I'm not sure what the particular problem is in your case, but there have been myriad problems with mocking render because render calls itself recursively and is a one-stop shop for rendering all sorts of things. RSpec's mock frameworks, as is the case with most mock frameworks (the one exception I know of being the new RR framework - see http://rubyforge.org/projects/pivotalrb/) do not support mocking one call to a method and passing the rest through. So while under some circumstances everything works fine, under others, not so much. This is resolved in trunk with the addition of the expect_render method, which uses composition to interact with a mock, but doesn't actually mock the method directly. You use it like this: controller.expect_render(:layout => false) Any calls to render that don't look like that will be passed through to the controller's render method. This will be part of the 1.0.6 release, which has been on hold for a few weeks pending some additional changes but I'm thinking of releasing it sooner than later. > > Cheers > Daniel > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Sat Jul 28 09:53:51 2007 From: has.sox at gmail.com (Daniel N) Date: Sat, 28 Jul 2007 23:53:51 +1000 Subject: [rspec-users] specing a call to render :layout => "some_layout" In-Reply-To: <57c63afe0707280638u5c8457a8xf11113d8c37700b8@mail.gmail.com> References: <2fff50390707280628g64c06e4dpfb48ed70194c3d94@mail.gmail.com> <57c63afe0707280638u5c8457a8xf11113d8c37700b8@mail.gmail.com> Message-ID: <2fff50390707280653k44eda72dhd54a62733d527dc@mail.gmail.com> On 7/28/07, David Chelimsky wrote: > > On 7/28/07, Daniel N wrote: > > I'm trying to specify that an action should be rendered with a given > layout > > one particular spec. > > > > What I've got at the moment is this. > > > > it "should render with the grabber layout" do > > controller.should_receive( :render ).with( :layout => "my_layout" ) > > do_get > > end > > > > This doesnt work even though this call to render is being executed. > > > > render :layout => "my_layout" > > > > Firstly I don't understand why this isn't working. I'm getting an > object > > inspect with this message at the end > > > > > expected :render with ({:layout=>"my_layout"}) but received it with > (no > > args) > > > > > > > I'd really like to understand why this isn't working, but I don't really > > like it anyway. I mean, I really want to spec that under a particular > set > > of conditions it renders with a given layout. > > > > I can't imagine I'm the first person to come up against this one. How > are > > other people handling this? > > I'm not sure what the particular problem is in your case, but there > have been myriad problems with mocking render because render calls > itself recursively and is a one-stop shop for rendering all sorts of > things. RSpec's mock frameworks, as is the case with most mock > frameworks (the one exception I know of being the new RR framework - > see http://rubyforge.org/projects/pivotalrb/) do not support mocking > one call to a method and passing the rest through. So while under some > circumstances everything works fine, under others, not so much. > > This is resolved in trunk with the addition of the expect_render > method, which uses composition to interact with a mock, but doesn't > actually mock the method directly. You use it like this: > > controller.expect_render(:layout => false) > > Any calls to render that don't look like that will be passed through > to the controller's render method. > > This will be part of the 1.0.6 release, which has been on hold for a > few weeks pending some additional changes but I'm thinking of > releasing it sooner than later. > > > > > > Cheers > > Daniel > > Thanx David. I just updated to trunk and it worked a treat. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070728/7c7f0417/attachment-0001.html From nathan.sutton at gmail.com Sun Jul 29 02:36:46 2007 From: nathan.sutton at gmail.com (Nathan Sutton) Date: Sun, 29 Jul 2007 01:36:46 -0500 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec Message-ID: One of the things that turned me on to BDD and RSpec was speccing views first, that the desired end would drive the development. In previous projects while using Test::Unit I would try to make educated guesses as to what would be needed in the model and controllers to derive the view without actually writing the view until afterwards. This is all because testing relied on each previous layer working for the next to work, first models, then controllers, then views. And while for the most part the educated guesses panned out, and I'd do the models/controllers/views incrementally, I'd repeat a specific process a lot. Test/write model(s) Test/write controller(s) Test/write view(s)...oops, I forgot something or I need some extra functionality out of the model (or controller) which I didn't guess the view would need. Lets go back to the model to test/add the functionality Lets test/add functionality in the controller to include this Lets test the functionality in the view that we had to go back and write support code for (if you even do this with Test::Unit, flooding your functional tests with ugly ugly ugly tests) Rinse and repeat, quickly trying to switch contexts from models to controllers to views. While testing helps you predict failures when making changes, it's not perfect, and predicting problems in the views is even more difficult with the current state of view testing in Test::Unit. While it is still rather agile, and changing the contexts isn't really much of a switch in this case, I think a lot could be avoided by doing views first and letting it drive the controllers and models. Then the cycle of incremental additions is to add features instead of adding things you forgot. Adding value, rather than recovering intended functionality that wasn't foreseen to be needed in your views. Maybe it's all in my head, but I enjoy adding new functionality more than spending time going back and adding backend functionality that wasn't foreseen to be needed by the frontend. So what am I on about? Well, I'm having trouble doing just that. I want to do View-Driven-Development by Behavior-Driven-Development, but I'm stumped really where to begin. Ideally I'd like to see a tutorial or something that walks though it, or browse through some projects using RSpec for the views, but I can't seem to find any. Maybe I'm not looking hard enough or I don't know where to look. Could anyone help me with this? Nathan "fowlduck" Sutton P.S. Excerpt from my crappy blog, if it matters, http:// www.saynotomilk.com/ From win at wincent.com Sun Jul 29 06:46:52 2007 From: win at wincent.com (Wincent Colaiuta) Date: Sun, 29 Jul 2007 12:46:52 +0200 Subject: [rspec-users] Coding standards and whitespace In-Reply-To: <57c63afe0707271438q54044d4ai5ca5cab2c05f3dbd@mail.gmail.com> References: <9989DB21-CFBE-4AC4-B9F4-A46D9A3E0A4A@wincent.com> <57c63afe0707271438q54044d4ai5ca5cab2c05f3dbd@mail.gmail.com> Message-ID: <6CDE2479-54C9-41C9-91EA-C4BE4D23B519@wincent.com> El 27/7/2007, a las 23:38, David Chelimsky escribi?: > On 7/26/07, Wincent Colaiuta wrote: >> Recently as a result of using Git I've noticed a number of >> inconsistencies in the RSpec codebase with respect to whitespace >> (mixed line endings, mixed use of spaces and tabs for indentation, >> and trailing whitespace at the end of lines). I never would have >> noticed, but Git produces nice colorized diff output which highlights >> these kinds of inconsistencies. >> >> I wanted to ask if the core RSpec team had established any >> conventions/standards for these things. The basic rationale is that >> if all contributors agree to a small number of conventions for >> whitespace there are less likely to be changesets with non- >> substantive whitespace differences (really, false alarms). > > Your thinking makes sense, but we haven't set a standard for this. Do > you know how to configure TextMate (which most of us use) to take care > of this automagically when saving files? I don't know of any *fully* automatic way to do this in TextMate but there are some things you can do to make it nearly automatic. In my experience I've observed a few things: * The initial "clean up" of a code base is the biggest task (although for a project the size of RSpec we are still only talking a few minutes' work); after that merely maintaining the standards is relatively easy (especially in the case of Git where if you do a "git diff" to see what you are about to commit any problems with the whitespace are immediately evident) * Project-wide Find and Replace does a pretty good job of handling most scenarios; for further "automation" you could record a TextMate macro and assign it to a key combo (for example, to handle trailing whitespace do a regular expression search for " +$" and replace all instances with nothing) * The way the Git community tends to work is to enforce this using repository hooks, and I imagine this could be done in Subversion too: the idea is that you have a pre-commit hook that can check the proposed commit against the standards and reject it if it fails (Git also has a "--no-verify" switch that you can pass if you want to skip the pre-commit hook) * The burden for enforcing the standards need not fall on the maintainers themselves; in the projects I've seen it is normal for a maintainer to say things like, "the patch looks good but can you fix up the whitespace and resubmit?" etc Of course, this is extremely easy and natural when using Git because the diff tools really put any discrepancies "in your face". In any case, I think you don't need to go "all the way" with this; a useful first step would be merely deciding upon some standards and publishing them. Even if you don't take any further steps (enforcement, hooks, automation etc) the mere act of publishing the standards and asking people to follow them would be useful. Cheers, Wincent From dchelimsky at gmail.com Sun Jul 29 08:57:54 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 29 Jul 2007 07:57:54 -0500 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: References: Message-ID: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> On 7/29/07, Nathan Sutton wrote: > I want to do View-Driven-Development by Behavior-Driven-Development, > but I'm stumped really where to begin. Ideally I'd like to see a > tutorial or something that walks though it, or browse through some > projects using RSpec for the views, but I can't seem to find any. > Maybe I'm not looking hard enough or I don't know where to look. http://blog.davidchelimsky.net/articles/2006/11/06/view-spec-tutorial Cheers, David From russell.tracey at gmail.com Sun Jul 29 15:50:30 2007 From: russell.tracey at gmail.com (Russell Tracey) Date: Sun, 29 Jul 2007 20:50:30 +0100 Subject: [rspec-users] Isolating rails model specs from their implementation Message-ID: I'm currently taking a Rails project management app I built when learning Rails and adding specs to it. During the course of building the app the requirement that project should be archiveable was added. So a project is in one of two states active or archived. This led to the creation of the following methods: Project.active_projects Project.archived_projects @project.active? @project.archived? @project.archive! @project.unarchive! The current implementation of this is using a separate table of "visibilities" as follows: # Implementation 1 (Current) Tables: Project id name visibility_status_id 1 ActiveProject 1 1 ArchivedProject 2 VisibilityStatuses id name 1 Live 2 Archived But the same behavior could be implemented using a datetime column as follows: # Implementation 2 Tables: Project id name archived_at 1 ActiveProject null 1 ArchivedProject 2007-07-29:18:57 Or in fact numerous other ways e.g. # Implementation 3 Army of cows: Each cow represents a project, the cows wear one of two hats to indicate the active/archived status of the project they represent. ...and so on. It's my understanding that model specs (and specs in general) should be shielded from the implementation details, so how do i check that Project.active_projects only returns active projects without looking at assuming something about the implementation? My initial thought is to check each of them using one of the other exposed methods above, in this case... Project.active_projects.all? {|p| p.active? } but then i can't work out how to spec all the other methods without going round in circles so that each spec would end up assuming that the other methods work (in this case that p.active? is working) or worse resorting to peeking at implementation details. Russell Tracey From philodespotos at gmail.com Sun Jul 29 16:16:15 2007 From: philodespotos at gmail.com (Kyle Hargraves) Date: Sun, 29 Jul 2007 15:16:15 -0500 Subject: [rspec-users] Isolating rails model specs from their implementation In-Reply-To: References: Message-ID: <46ACF58F.5060306@gmail.com> Russell Tracey wrote: > It's my understanding that model specs (and specs in general) should > be shielded from the implementation details, so how do i check that > Project.active_projects only returns active projects without looking > at assuming something about the implementation? My initial thought is > to check each of them using one of the other exposed methods above, in > this case... > > Project.active_projects.all? {|p| p.active? } > > but then i can't work out how to spec all the other methods without > going round in circles so that each spec would end up assuming that > the other methods work (in this case that p.active? is working) or > worse resorting to peeking at implementation details. Nothing is wrong with assuming that everything else works as it should. In fact, it's pretty much exactly what you want: you only care about the behaviour of the little facet of the model you're dealing with *right now*. If something else doesn't work, some other spec is responsible for demonstrating that it's misbehaving. As for the specific issue, I typically do something like: Spec that active? and archived? do what they should. Those probably actually do require some form of implementation details -- if X column has Y value, it's archived, otherwise not, etc. Then, spec archive! (and unarchive!): it "should archive projects" do @project.archive! project = find_that_project_again project.should be_archived end And finally, for your finders: before(:each) do active_projects = set_up_some_active_projects archived_projects = set_up_some_archived_projects end it "should return only active projects" do all_active = Project.active_projects.all? { |p| p.active? } all_active.should be_true end So the entirety really only hinges on active? and archived? working properly. And if active? is just !archived?, there's only one real spot from which errors will start cascading. HTH, Kyle From dchelimsky at gmail.com Sun Jul 29 16:21:18 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 29 Jul 2007 15:21:18 -0500 Subject: [rspec-users] Isolating rails model specs from their implementation In-Reply-To: References: Message-ID: <57c63afe0707291321y17a12cf2v64cd4e937d8c38a1@mail.gmail.com> On 7/29/07, Russell Tracey wrote: > I'm currently taking a Rails project management app I built when > learning Rails and adding specs to it. During the course of building > the app the requirement that project should be archiveable was added. > So a project is in one of two states active or archived. > > This led to the creation of the following methods: > > Project.active_projects > Project.archived_projects > > @project.active? > @project.archived? > @project.archive! > @project.unarchive! > > The current implementation of this is using a separate table of > "visibilities" as follows: > > # Implementation 1 (Current) > > Tables: > > Project > id name visibility_status_id > 1 ActiveProject 1 > 1 ArchivedProject 2 > > VisibilityStatuses > id name > 1 Live > 2 Archived > > But the same behavior could be implemented using a datetime column as follows: > > # Implementation 2 > > Tables: > > Project > id name archived_at > 1 ActiveProject null > 1 ArchivedProject 2007-07-29:18:57 > > Or in fact numerous other ways e.g. > > # Implementation 3 > > Army of cows: > > Each cow represents a project, the cows wear one of two hats > to indicate the active/archived status of the project they represent. > > ...and so on. > > It's my understanding that model specs (and specs in general) should > be shielded from the implementation details, so how do i check that > Project.active_projects only returns active projects without looking > at assuming something about the implementation? My initial thought is > to check each of them using one of the other exposed methods above, in > this case... > > Project.active_projects.all? {|p| p.active? } > > but then i can't work out how to spec all the other methods without > going round in circles so that each spec would end up assuming that > the other methods work (in this case that p.active? is working) or > worse resorting to peeking at implementation details. Keep in mind that back-filling examples to existing code is a very different process from writing the examples first, which is the situation for which RSpec is intended. In that case, you might start with one example like this: describe Project do it " should not be active by default" do project = Project.create project.should_not be_active end end Then the next example might be that when you activate it should be active: describe Project do it " should not be active by default" { ... } it "should be active after you activate it" do project = Project.create project.activate! project.should be_active end it "should show up in the list of active projects when activated" do project = Project.create project.activate! Project.active_projects.should include(project) end end etc. In this second pair of examples, we never "test" the activate! method in terms of looking at its internal effects (i.e. that it changes something in the database), but rather through the difference in the way the object behaves after having called the activate! method. Make sense? David From russell.tracey at gmail.com Sun Jul 29 17:09:20 2007 From: russell.tracey at gmail.com (Russell Tracey) Date: Sun, 29 Jul 2007 22:09:20 +0100 Subject: [rspec-users] Isolating rails model specs from their implementation In-Reply-To: <57c63afe0707291321y17a12cf2v64cd4e937d8c38a1@mail.gmail.com> References: <57c63afe0707291321y17a12cf2v64cd4e937d8c38a1@mail.gmail.com> Message-ID: On 29/07/07, David Chelimsky wrote: > On 7/29/07, Russell Tracey wrote: > > I'm currently taking a Rails project management app I built when > > learning Rails and adding specs to it. During the course of building > > the app the requirement that project should be archiveable was added. > > So a project is in one of two states active or archived. > > > > This led to the creation of the following methods: > > > > Project.active_projects > > Project.archived_projects > > > > @project.active? > > @project.archived? > > @project.archive! > > @project.unarchive! > > > > The current implementation of this is using a separate table of > > "visibilities" as follows: > > > > # Implementation 1 (Current) > > > > Tables: > > > > Project > > id name visibility_status_id > > 1 ActiveProject 1 > > 1 ArchivedProject 2 > > > > VisibilityStatuses > > id name > > 1 Live > > 2 Archived > > > > But the same behavior could be implemented using a datetime column as follows: > > > > # Implementation 2 > > > > Tables: > > > > Project > > id name archived_at > > 1 ActiveProject null > > 1 ArchivedProject 2007-07-29:18:57 > > > > Or in fact numerous other ways e.g. > > > > # Implementation 3 > > > > Army of cows: > > > > Each cow represents a project, the cows wear one of two hats > > to indicate the active/archived status of the project they represent. > > > > ...and so on. > > > > It's my understanding that model specs (and specs in general) should > > be shielded from the implementation details, so how do i check that > > Project.active_projects only returns active projects without looking > > at assuming something about the implementation? My initial thought is > > to check each of them using one of the other exposed methods above, in > > this case... > > > > Project.active_projects.all? {|p| p.active? } > > > > but then i can't work out how to spec all the other methods without > > going round in circles so that each spec would end up assuming that > > the other methods work (in this case that p.active? is working) or > > worse resorting to peeking at implementation details. > > Keep in mind that back-filling examples to existing code is a very > different process from writing the examples first, which is the > situation for which RSpec is intended. In that case, you might start > with one example like this: > > describe Project do > it " should not be active by default" do > project = Project.create > project.should_not be_active > end > end > > Then the next example might be that when you activate it should be active: > > describe Project do > it " should not be active by default" { ... } > > it "should be active after you activate it" do > project = Project.create > project.activate! > project.should be_active > end > > it "should show up in the list of active projects when activated" do > project = Project.create > project.activate! > Project.active_projects.should include(project) > end > end > > etc. > > In this second pair of examples, we never "test" the activate! method > in terms of looking at its internal effects (i.e. that it changes > something in the database), but rather through the difference in the > way the object behaves after having called the activate! method. > > Make sense? > > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Yes this is making more sense now, the only remaining thing i am wondering is, given the above examples, would specing that active?/archived? be possible without resorting to implementation details that Kyle wrote about. If i'm reading them correctly the examples above spec out the behavior of activate!, active_projects and the default state of a project after creation, but don't define the behavior of active? In this app the projects are actually "active" by default before being archived at some point later. So they are only ever in one of two states, active or archived. I'm thinking something like this describe Project do ... it " Not sure what this would be called?" do project = Project.create project.should be_active project.archive! project.should_not be_active end end From dchelimsky at gmail.com Sun Jul 29 17:45:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 29 Jul 2007 16:45:01 -0500 Subject: [rspec-users] Isolating rails model specs from their implementation In-Reply-To: References: <57c63afe0707291321y17a12cf2v64cd4e937d8c38a1@mail.gmail.com> Message-ID: <57c63afe0707291445t41675558m5213776a87b0ced9@mail.gmail.com> On 7/29/07, Russell Tracey wrote: > On 29/07/07, David Chelimsky wrote: > > On 7/29/07, Russell Tracey wrote: > > > I'm currently taking a Rails project management app I built when > > > learning Rails and adding specs to it. During the course of building > > > the app the requirement that project should be archiveable was added. > > > So a project is in one of two states active or archived. > > > > > > This led to the creation of the following methods: > > > > > > Project.active_projects > > > Project.archived_projects > > > > > > @project.active? > > > @project.archived? > > > @project.archive! > > > @project.unarchive! > > > > > > The current implementation of this is using a separate table of > > > "visibilities" as follows: > > > > > > # Implementation 1 (Current) > > > > > > Tables: > > > > > > Project > > > id name visibility_status_id > > > 1 ActiveProject 1 > > > 1 ArchivedProject 2 > > > > > > VisibilityStatuses > > > id name > > > 1 Live > > > 2 Archived > > > > > > But the same behavior could be implemented using a datetime column as follows: > > > > > > # Implementation 2 > > > > > > Tables: > > > > > > Project > > > id name archived_at > > > 1 ActiveProject null > > > 1 ArchivedProject 2007-07-29:18:57 > > > > > > Or in fact numerous other ways e.g. > > > > > > # Implementation 3 > > > > > > Army of cows: > > > > > > Each cow represents a project, the cows wear one of two hats > > > to indicate the active/archived status of the project they represent. > > > > > > ...and so on. > > > > > > It's my understanding that model specs (and specs in general) should > > > be shielded from the implementation details, so how do i check that > > > Project.active_projects only returns active projects without looking > > > at assuming something about the implementation? My initial thought is > > > to check each of them using one of the other exposed methods above, in > > > this case... > > > > > > Project.active_projects.all? {|p| p.active? } > > > > > > but then i can't work out how to spec all the other methods without > > > going round in circles so that each spec would end up assuming that > > > the other methods work (in this case that p.active? is working) or > > > worse resorting to peeking at implementation details. > > > > Keep in mind that back-filling examples to existing code is a very > > different process from writing the examples first, which is the > > situation for which RSpec is intended. In that case, you might start > > with one example like this: > > > > describe Project do > > it " should not be active by default" do > > project = Project.create > > project.should_not be_active > > end > > end > > > > Then the next example might be that when you activate it should be active: > > > > describe Project do > > it " should not be active by default" { ... } > > > > it "should be active after you activate it" do > > project = Project.create > > project.activate! > > project.should be_active > > end > > > > it "should show up in the list of active projects when activated" do > > project = Project.create > > project.activate! > > Project.active_projects.should include(project) > > end > > end > > > > etc. > > > > In this second pair of examples, we never "test" the activate! method > > in terms of looking at its internal effects (i.e. that it changes > > something in the database), but rather through the difference in the > > way the object behaves after having called the activate! method. > > > > Make sense? > > > > David > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > Yes this is making more sense now, the only remaining thing i am > wondering is, given the above examples, would specing that > active?/archived? be possible without resorting to implementation > details that Kyle wrote about. If i'm reading them correctly the > examples above spec out the behavior of activate!, active_projects and > the default state of a project after creation, but don't define the > behavior of active? > > In this app the projects are actually "active" by default before being > archived at some point later. So they are only ever in one of two > states, active or archived. > > I'm thinking something like this > > describe Project do > ... > it " Not sure what this would be called?" do > project = Project.create > project.should be_active > > project.archive! > > project.should_not be_active > end > end Changing state between expectations in one example is a TDD no-no. The reason is that if "project.should be_active" fails, you might do something to fix it and then find that "project.should_not be_active" fails. If you have them in separate examples then the fact that only one fails and not the other gives you better feedback: describe Project do it "should be active when first created" do project = Project.create project.should be_active end it "should not be active after it is archived" do project = Project.create project.archive! project.should_not be_active end end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Jul 29 17:49:36 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 29 Jul 2007 16:49:36 -0500 Subject: [rspec-users] Isolating rails model specs from their implementation In-Reply-To: <57c63afe0707291445t41675558m5213776a87b0ced9@mail.gmail.com> References: <57c63afe0707291321y17a12cf2v64cd4e937d8c38a1@mail.gmail.com> <57c63afe0707291445t41675558m5213776a87b0ced9@mail.gmail.com> Message-ID: <57c63afe0707291449x5ce20982x6bbe32c098b906dc@mail.gmail.com> On 7/29/07, David Chelimsky wrote: > On 7/29/07, Russell Tracey wrote: > > On 29/07/07, David Chelimsky wrote: > > > On 7/29/07, Russell Tracey wrote: > > > > I'm currently taking a Rails project management app I built when > > > > learning Rails and adding specs to it. During the course of building > > > > the app the requirement that project should be archiveable was added. > > > > So a project is in one of two states active or archived. > > > > > > > > This led to the creation of the following methods: > > > > > > > > Project.active_projects > > > > Project.archived_projects > > > > > > > > @project.active? > > > > @project.archived? > > > > @project.archive! > > > > @project.unarchive! > > > > > > > > The current implementation of this is using a separate table of > > > > "visibilities" as follows: > > > > > > > > # Implementation 1 (Current) > > > > > > > > Tables: > > > > > > > > Project > > > > id name visibility_status_id > > > > 1 ActiveProject 1 > > > > 1 ArchivedProject 2 > > > > > > > > VisibilityStatuses > > > > id name > > > > 1 Live > > > > 2 Archived > > > > > > > > But the same behavior could be implemented using a datetime column as follows: > > > > > > > > # Implementation 2 > > > > > > > > Tables: > > > > > > > > Project > > > > id name archived_at > > > > 1 ActiveProject null > > > > 1 ArchivedProject 2007-07-29:18:57 > > > > > > > > Or in fact numerous other ways e.g. > > > > > > > > # Implementation 3 > > > > > > > > Army of cows: > > > > > > > > Each cow represents a project, the cows wear one of two hats > > > > to indicate the active/archived status of the project they represent. > > > > > > > > ...and so on. > > > > > > > > It's my understanding that model specs (and specs in general) should > > > > be shielded from the implementation details, so how do i check that > > > > Project.active_projects only returns active projects without looking > > > > at assuming something about the implementation? My initial thought is > > > > to check each of them using one of the other exposed methods above, in > > > > this case... > > > > > > > > Project.active_projects.all? {|p| p.active? } > > > > > > > > but then i can't work out how to spec all the other methods without > > > > going round in circles so that each spec would end up assuming that > > > > the other methods work (in this case that p.active? is working) or > > > > worse resorting to peeking at implementation details. > > > > > > Keep in mind that back-filling examples to existing code is a very > > > different process from writing the examples first, which is the > > > situation for which RSpec is intended. In that case, you might start > > > with one example like this: > > > > > > describe Project do > > > it " should not be active by default" do > > > project = Project.create > > > project.should_not be_active > > > end > > > end > > > > > > Then the next example might be that when you activate it should be active: > > > > > > describe Project do > > > it " should not be active by default" { ... } > > > > > > it "should be active after you activate it" do > > > project = Project.create > > > project.activate! > > > project.should be_active > > > end > > > > > > it "should show up in the list of active projects when activated" do > > > project = Project.create > > > project.activate! > > > Project.active_projects.should include(project) > > > end > > > end > > > > > > etc. > > > > > > In this second pair of examples, we never "test" the activate! method > > > in terms of looking at its internal effects (i.e. that it changes > > > something in the database), but rather through the difference in the > > > way the object behaves after having called the activate! method. > > > > > > Make sense? > > > > > > David > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > Yes this is making more sense now, the only remaining thing i am > > wondering is, given the above examples, would specing that > > active?/archived? be possible without resorting to implementation > > details that Kyle wrote about. If i'm reading them correctly the > > examples above spec out the behavior of activate!, active_projects and > > the default state of a project after creation, but don't define the > > behavior of active? > > > > In this app the projects are actually "active" by default before being > > archived at some point later. So they are only ever in one of two > > states, active or archived. > > > > I'm thinking something like this > > > > describe Project do > > ... > > it " Not sure what this would be called?" do > > project = Project.create > > project.should be_active > > > > project.archive! > > > > project.should_not be_active > > end > > end > > Changing state between expectations in one example is a TDD no-no. The > reason is that if "project.should be_active" fails, you might do > something to fix it and then find that "project.should_not be_active" > fails. If you have them in separate examples then the fact that only > one fails and not the other gives you better feedback: > > describe Project do > it "should be active when first created" do > project = Project.create > project.should be_active > end > > it "should not be active after it is archived" do > project = Project.create > project.archive! > project.should_not be_active > end > end FYI - the two together also tell a more complete story: Project - should be active when first created - should not be active after it is archived Cheers, David From raasdnil at gmail.com Mon Jul 30 05:00:26 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Mon, 30 Jul 2007 19:00:26 +1000 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> Message-ID: <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> Dear Nathan, What you are sayiing is correct, and in terms of Ruby on Rails, BDD _IS_ View Driven development... or at least it should be IMHO. At the end of the day, the only thing that matters in a Rails App is the Behaviour shown to the user, who has as their only interface, the View. The user can not and should not interact with any models. The user MIGHT interact with a controller... (say, having a file download which doesn't get sent through a view), but really... views ARE the behaviour of a Rails App. I found the same thing as you... started with spec'ing my models, doing great, getting to controllers.. doing OK... getting to views and going "Where did I go wrong?" Starting with views and working "backwards" from a Test::Unit point of view has definately opened up a lot of RSpec doors for me. My $0.02. Mikel On 7/29/07, David Chelimsky wrote: > On 7/29/07, Nathan Sutton wrote: > > I want to do View-Driven-Development by Behavior-Driven-Development, > > but I'm stumped really where to begin. Ideally I'd like to see a > > tutorial or something that walks though it, or browse through some > > projects using RSpec for the views, but I can't seem to find any. > > Maybe I'm not looking hard enough or I don't know where to look. > > http://blog.davidchelimsky.net/articles/2006/11/06/view-spec-tutorial > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Mon Jul 30 05:29:56 2007 From: has.sox at gmail.com (Daniel N) Date: Mon, 30 Jul 2007 19:29:56 +1000 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> Message-ID: <2fff50390707300229n2942cf55p34a387de8c209e74@mail.gmail.com> On 7/30/07, Mikel Lindsaar wrote: > > Dear Nathan, > > What you are sayiing is correct, and in terms of Ruby on Rails, BDD > _IS_ View Driven development... or at least it should be IMHO. > > At the end of the day, the only thing that matters in a Rails App is > the Behaviour shown to the user, who has as their only interface, the > View. > > The user can not and should not interact with any models. The user > MIGHT interact with a controller... (say, having a file download which > doesn't get sent through a view), but really... views ARE the > behaviour of a Rails App. > > I found the same thing as you... started with spec'ing my models, > doing great, getting to controllers.. doing OK... getting to views and > going "Where did I go wrong?" > > Starting with views and working "backwards" from a Test::Unit point of > view has definately opened up a lot of RSpec doors for me. > > My $0.02. > > Mikel I think one thing that would make view first development a really powerful tool with rspec is a way to keep track of erroneous calls to model methods. One thing that I am consistently worried about is specing a method in one place via mocks, a la the view, but forgetting to include that method in the model. The way I get around this at the moment, is when I find a method that I want to have that isn't there yet, I open up the spec for the model and add an it "should have method bla" so that it shows up in the pending report. Of course this means that I have to have the model spec all setup in the first place kind of defeating the purpose of view first. Well almost. If the view is generated via an rspec generator then all that is setup. What would be fantastic is if mock had an option to report calls to non-existent methods. Something like mock( User, :report_pending_methods => :true ) Is there another way to do this that is already in practice? Cheers Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070730/5d218f2d/attachment.html From raasdnil at gmail.com Mon Jul 30 06:49:28 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Mon, 30 Jul 2007 20:49:28 +1000 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <2fff50390707300229n2942cf55p34a387de8c209e74@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <2fff50390707300229n2942cf55p34a387de8c209e74@mail.gmail.com> Message-ID: <57a815bf0707300349gc71c878s837548c50a20896b@mail.gmail.com> I find myself doing the same thing... the, open the model and type in the it shoulds... I ws thinking along the same line... probably all that would be needed is a rake task that hooks into the Mock class and runs all the specs taking not of all the stubs and mocks method calls that are made. Then it could PRODUCE the it shoulds... @model = mock_model(People, :id => 1, :name => "Bob") @model.should_receive(:alive?).and_return(true) # rake spec:find_fakes produces: describe People "automatically" do it "should have a name" it "should respond to alive?" end Now... that would be cool.... Regards Mikel On 7/30/07, Daniel N wrote: > > > On 7/30/07, Mikel Lindsaar wrote: > > Dear Nathan, > > > > What you are sayiing is correct, and in terms of Ruby on Rails, BDD > > _IS_ View Driven development... or at least it should be IMHO. > > > > At the end of the day, the only thing that matters in a Rails App is > > the Behaviour shown to the user, who has as their only interface, the > > View. > > > > The user can not and should not interact with any models. The user > > MIGHT interact with a controller... (say, having a file download which > > doesn't get sent through a view), but really... views ARE the > > behaviour of a Rails App. > > > > I found the same thing as you... started with spec'ing my models, > > doing great, getting to controllers.. doing OK... getting to views and > > going "Where did I go wrong?" > > > > Starting with views and working "backwards" from a Test::Unit point of > > view has definately opened up a lot of RSpec doors for me. > > > > My $0.02. > > > > Mikel > > I think one thing that would make view first development a really powerful > tool with rspec is a way to keep track of erroneous calls to model methods. > > One thing that I am consistently worried about is specing a method in one > place via mocks, a la the view, but forgetting to include that method in the > model. > > The way I get around this at the moment, is when I find a method that I want > to have that isn't there yet, I open up the spec for the model and add an > it "should have method bla" > > so that it shows up in the pending report. Of course this means that I have > to have the model spec all setup in the first place kind of defeating the > purpose of view first. Well almost. If the view is generated via an rspec > generator then all that is setup. > > What would be fantastic is if mock had an option to report calls to > non-existent methods. > > Something like mock( User, :report_pending_methods => :true ) > > Is there another way to do this that is already in practice? > > Cheers > Daniel > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Jul 30 07:10:07 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 30 Jul 2007 06:10:07 -0500 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> Message-ID: <57c63afe0707300410p3c0e6d40rfc4ce352056e214@mail.gmail.com> On 7/30/07, Mikel Lindsaar wrote: > Dear Nathan, > Starting with views and working "backwards" from a Test::Unit point of > view has definately opened up a lot of RSpec doors for me. I've definitely seen advice to start with models before, but I've not seen anything that says "if you're using Test::Unit, you should start with models". It's more a development philosophy than a tool issue. Cheers, David From raasdnil at gmail.com Mon Jul 30 07:23:59 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Mon, 30 Jul 2007 21:23:59 +1000 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <57c63afe0707300410p3c0e6d40rfc4ce352056e214@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <57c63afe0707300410p3c0e6d40rfc4ce352056e214@mail.gmail.com> Message-ID: <57a815bf0707300423n5e1089d4ic96eefc59c7e8750@mail.gmail.com> David, true :) I think I was more mixing up "Test::Unit" and the unit directory under test in terms of Rails... the unit tests are to the models... ergo... my definitions were mixed up :) Anyway... back to coding :) Mikel On 7/30/07, David Chelimsky wrote: > On 7/30/07, Mikel Lindsaar wrote: > > Dear Nathan, > > Starting with views and working "backwards" from a Test::Unit point of > > view has definately opened up a lot of RSpec doors for me. > > I've definitely seen advice to start with models before, but I've not > seen anything that says "if you're using Test::Unit, you should start > with models". It's more a development philosophy than a tool issue. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Jul 30 07:25:13 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 30 Jul 2007 06:25:13 -0500 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <57a815bf0707300423n5e1089d4ic96eefc59c7e8750@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <57c63afe0707300410p3c0e6d40rfc4ce352056e214@mail.gmail.com> <57a815bf0707300423n5e1089d4ic96eefc59c7e8750@mail.gmail.com> Message-ID: <57c63afe0707300425y5dbd9c56yda6b36284369b837@mail.gmail.com> On 7/30/07, Mikel Lindsaar wrote: > David, true :) > > I think I was more mixing up "Test::Unit" and the unit directory under > test in terms of Rails... the unit tests are to the models... ergo... > my definitions were mixed up :) Makes sense. Thanks for playing. Cheers, David > > Anyway... back to coding :) > > Mikel > > On 7/30/07, David Chelimsky wrote: > > On 7/30/07, Mikel Lindsaar wrote: > > > Dear Nathan, > > > Starting with views and working "backwards" from a Test::Unit point of > > > view has definately opened up a lot of RSpec doors for me. > > > > I've definitely seen advice to start with models before, but I've not > > seen anything that says "if you're using Test::Unit, you should start > > with models". It's more a development philosophy than a tool issue. > > > > Cheers, > > David > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Mon Jul 30 07:39:52 2007 From: has.sox at gmail.com (Daniel N) Date: Mon, 30 Jul 2007 21:39:52 +1000 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <57a815bf0707300349gc71c878s837548c50a20896b@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <2fff50390707300229n2942cf55p34a387de8c209e74@mail.gmail.com> <57a815bf0707300349gc71c878s837548c50a20896b@mail.gmail.com> Message-ID: <2fff50390707300439r3f4a81dcncb7095024b811436@mail.gmail.com> On 7/30/07, Mikel Lindsaar wrote: > > I find myself doing the same thing... the, open the model and type in > the it shoulds... I think it would need to do a bit more. If I call mock_model( User ) and the User class doesn't exist yet that will blow it up. I guess at that point you would need to create the User class. :( -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070730/0034b1ff/attachment.html From dchelimsky at gmail.com Mon Jul 30 07:43:01 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 30 Jul 2007 06:43:01 -0500 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <57a815bf0707300349gc71c878s837548c50a20896b@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <2fff50390707300229n2942cf55p34a387de8c209e74@mail.gmail.com> <57a815bf0707300349gc71c878s837548c50a20896b@mail.gmail.com> Message-ID: <57c63afe0707300443v175f54e6x4f522be457c7c8a3@mail.gmail.com> On 7/30/07, Mikel Lindsaar wrote: > I find myself doing the same thing... the, open the model and type in > the it shoulds... > > I ws thinking along the same line... probably all that would be needed > is a rake task that hooks into the Mock class and runs all the specs > taking not of all the stubs and mocks method calls that are made. > > Then it could PRODUCE the it shoulds... > > @model = mock_model(People, :id => 1, :name => "Bob") > @model.should_receive(:alive?).and_return(true) > > # rake spec:find_fakes > > produces: > > describe People "automatically" do > > it "should have a name" > > it "should respond to alive?" > > end > > Now... that would be cool.... I would tend to disagree. RSpec is a Behaviour Driven Development tool. The idea is that you write a small example of behaviour FIRST, and use that example to drive the implementation. The reason you use examples to drive implementation comes from the idea in Test Driven Development that it will lead to tighter, more focused and more flexible implementations. If your examples come after the code, whether they are generated or you write them yourself, then you are losing out quite a bit of value of the process with which RSpec is aligned. Secondly, having a name is not behaviour. Using it might be. Or how you set it might be. For example: describe Thing do it "should use the first initializer argument as its name" do Thing.new("Jo?o").name.should == "Jo?o" end it "should be alive when first created" do Thing.new.should be_alive end end Implicit in these examples are the fact that Thing has a name and responds to "alive?", but those are just artifacts in support of the behaviour. That all make sense? From has.sox at gmail.com Mon Jul 30 07:47:47 2007 From: has.sox at gmail.com (Daniel N) Date: Mon, 30 Jul 2007 21:47:47 +1000 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <57c63afe0707300443v175f54e6x4f522be457c7c8a3@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <2fff50390707300229n2942cf55p34a387de8c209e74@mail.gmail.com> <57a815bf0707300349gc71c878s837548c50a20896b@mail.gmail.com> <57c63afe0707300443v175f54e6x4f522be457c7c8a3@mail.gmail.com> Message-ID: <2fff50390707300447w675714d2n7259776546ed750d@mail.gmail.com> On 7/30/07, David Chelimsky wrote: > > On 7/30/07, Mikel Lindsaar wrote: > > I find myself doing the same thing... the, open the model and type in > > the it shoulds... > > > > I ws thinking along the same line... probably all that would be needed > > is a rake task that hooks into the Mock class and runs all the specs > > taking not of all the stubs and mocks method calls that are made. > > > > Then it could PRODUCE the it shoulds... > > > > @model = mock_model(People, :id => 1, :name => "Bob") > > @model.should_receive(:alive?).and_return(true) > > > > # rake spec:find_fakes > > > > produces: > > > > describe People "automatically" do > > > > it "should have a name" > > > > it "should respond to alive?" > > > > end > > > > Now... that would be cool.... > > I would tend to disagree. RSpec is a Behaviour Driven Development > tool. The idea is that you write a small example of behaviour FIRST, > and use that example to drive the implementation. The reason you use > examples to drive implementation comes from the idea in Test Driven > Development that it will lead to tighter, more focused and more > flexible implementations. > > If your examples come after the code, whether they are generated or > you write them yourself, then you are losing out quite a bit of value > of the process with which RSpec is aligned. > > Secondly, having a name is not behaviour. Using it might be. Or how > you set it might be. For example: > > describe Thing do > it "should use the first initializer argument as its name" do > Thing.new("Jo?o").name.should == "Jo?o" > end > > it "should be alive when first created" do > Thing.new.should be_alive > end > end > > Implicit in these examples are the fact that Thing has a name and > responds to "alive?", but those are just artifacts in support of the > behaviour. > > That all make sense? In a fairly abstract way. But how do you keep track of what methods have been stubbed or mocked? >From the above Thing.new.alive? will need to be defined. This seems to be the spec for Thing, but if in a view I said it "should do_stuff if @thing is alive" do @thing = mock_model( Thing ) @thing.stub!( :alive? ).and_return( true ) controller.should_receive( :do_stuff ) do_get end How do I run the view first without Thing, and also keep track of alive? being decalred on the Thing instance? -Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070730/f78d7756/attachment.html From dchelimsky at gmail.com Mon Jul 30 08:06:28 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 30 Jul 2007 07:06:28 -0500 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <2fff50390707300447w675714d2n7259776546ed750d@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <2fff50390707300229n2942cf55p34a387de8c209e74@mail.gmail.com> <57a815bf0707300349gc71c878s837548c50a20896b@mail.gmail.com> <57c63afe0707300443v175f54e6x4f522be457c7c8a3@mail.gmail.com> <2fff50390707300447w675714d2n7259776546ed750d@mail.gmail.com> Message-ID: <57c63afe0707300506h313c2046y2cd4c8b5423ebe72@mail.gmail.com> On 7/30/07, Daniel N wrote: > On 7/30/07, David Chelimsky wrote: > > On 7/30/07, Mikel Lindsaar wrote: > > > I find myself doing the same thing... the, open the model and type in > > > the it shoulds... > > > > > > I ws thinking along the same line... probably all that would be needed > > > is a rake task that hooks into the Mock class and runs all the specs > > > taking not of all the stubs and mocks method calls that are made. > > > > > > Then it could PRODUCE the it shoulds... > > > > > > @model = mock_model(People, :id => 1, :name => "Bob") > > > @model.should_receive(:alive?).and_return(true) > > > > > > # rake spec:find_fakes > > > > > > produces: > > > > > > describe People "automatically" do > > > > > > it "should have a name" > > > > > > it "should respond to alive?" > > > > > > end > > > > > > Now... that would be cool.... > > > > I would tend to disagree. RSpec is a Behaviour Driven Development > > tool. The idea is that you write a small example of behaviour FIRST, > > and use that example to drive the implementation. The reason you use > > examples to drive implementation comes from the idea in Test Driven > > Development that it will lead to tighter, more focused and more > > flexible implementations. > > > > If your examples come after the code, whether they are generated or > > you write them yourself, then you are losing out quite a bit of value > > of the process with which RSpec is aligned. > > > > Secondly, having a name is not behaviour. Using it might be. Or how > > you set it might be. For example: > > > > describe Thing do > > it "should use the first initializer argument as its name" do > > Thing.new("Jo?o").name.should == "Jo?o" > > end > > > > it "should be alive when first created" do > > Thing.new.should be_alive > > end > > end > > > > Implicit in these examples are the fact that Thing has a name and > > responds to "alive?", but those are just artifacts in support of the > > behaviour. > > > > That all make sense? > > In a fairly abstract way. But how do you keep track of what methods have > been stubbed or mocked? > > From the above Thing.new.alive? will need to be defined. This seems to be > the spec for Thing, but if in a view I said > > it "should do_stuff if @thing is alive" do > > @thing = mock_model( Thing ) > @thing.stub!( :alive? ).and_return( true ) > controller.should_receive( :do_stuff ) > do_get > > end > > How do I run the view first without Thing, If you're using mock_model and the constant Thing, then you have to create Thing to get that example to run. Admittedly, having to create that model class is a distraction from the flow, but it is a very small distraction that has never really bothered me that much. I imagine that we could tweak mock_model to accept a String, or perhaps somebody with stronger TextMate chops than mine could submit a patch to the TextMate bundle that would let you click on Thing and create a Thing model. > and also keep track of alive? > being decalred on the Thing instance? This is something that has come up on this list and in RFEs a few times. The most promising idea is to have a command line switch that would look at any mock that was passed a class name and ensure that the class responds to any mocked or stubbed methods. But even that would fall apart as soon as you start using any metaprogramming techniques to change the nature of an object at runtime. For me, the answer to keeping track of mocked methods is automated end-to-end tests. Either in browser, or something like Rails' integration tests (assuming Rails), or (soon) rbehave's story runner (which is now being integrated into rspec). Cheers, David From has.sox at gmail.com Mon Jul 30 08:29:39 2007 From: has.sox at gmail.com (Daniel N) Date: Mon, 30 Jul 2007 22:29:39 +1000 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <57c63afe0707300506h313c2046y2cd4c8b5423ebe72@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <2fff50390707300229n2942cf55p34a387de8c209e74@mail.gmail.com> <57a815bf0707300349gc71c878s837548c50a20896b@mail.gmail.com> <57c63afe0707300443v175f54e6x4f522be457c7c8a3@mail.gmail.com> <2fff50390707300447w675714d2n7259776546ed750d@mail.gmail.com> <57c63afe0707300506h313c2046y2cd4c8b5423ebe72@mail.gmail.com> Message-ID: <2fff50390707300529k5eebf183n58705f6c66a20721@mail.gmail.com> On 7/30/07, David Chelimsky wrote: > > On 7/30/07, Daniel N wrote: > > On 7/30/07, David Chelimsky wrote: > > > On 7/30/07, Mikel Lindsaar wrote: > > > > I find myself doing the same thing... the, open the model and type > in > > > > the it shoulds... > > > > > > > > I ws thinking along the same line... probably all that would be > needed > > > > is a rake task that hooks into the Mock class and runs all the specs > > > > taking not of all the stubs and mocks method calls that are made. > > > > > > > > Then it could PRODUCE the it shoulds... > > > > > > > > @model = mock_model(People, :id => 1, :name => "Bob") > > > > @model.should_receive(:alive?).and_return(true) > > > > > > > > # rake spec:find_fakes > > > > > > > > produces: > > > > > > > > describe People "automatically" do > > > > > > > > it "should have a name" > > > > > > > > it "should respond to alive?" > > > > > > > > end > > > > > > > > Now... that would be cool.... > > > > > > I would tend to disagree. RSpec is a Behaviour Driven Development > > > tool. The idea is that you write a small example of behaviour FIRST, > > > and use that example to drive the implementation. The reason you use > > > examples to drive implementation comes from the idea in Test Driven > > > Development that it will lead to tighter, more focused and more > > > flexible implementations. > > > > > > If your examples come after the code, whether they are generated or > > > you write them yourself, then you are losing out quite a bit of value > > > of the process with which RSpec is aligned. > > > > > > Secondly, having a name is not behaviour. Using it might be. Or how > > > you set it might be. For example: > > > > > > describe Thing do > > > it "should use the first initializer argument as its name" do > > > Thing.new("Jo?o").name.should == "Jo?o" > > > end > > > > > > it "should be alive when first created" do > > > Thing.new.should be_alive > > > end > > > end > > > > > > Implicit in these examples are the fact that Thing has a name and > > > responds to "alive?", but those are just artifacts in support of the > > > behaviour. > > > > > > That all make sense? > > > > In a fairly abstract way. But how do you keep track of what methods > have > > been stubbed or mocked? > > > > From the above Thing.new.alive? will need to be defined. This seems to > be > > the spec for Thing, but if in a view I said > > > > it "should do_stuff if @thing is alive" do > > > > @thing = mock_model( Thing ) > > @thing.stub!( :alive? ).and_return( true ) > > controller.should_receive( :do_stuff ) > > do_get > > > > end > > > > How do I run the view first without Thing, > > If you're using mock_model and the constant Thing, then you have to > create Thing to get that example to run. Admittedly, having to create > that model class is a distraction from the flow, but it is a very > small distraction that has never really bothered me that much. I > imagine that we could tweak mock_model to accept a String, or perhaps > somebody with stronger TextMate chops than mine could submit a patch > to the TextMate bundle that would let you click on Thing and create a > Thing model. > > > and also keep track of alive? > > being decalred on the Thing instance? > > This is something that has come up on this list and in RFEs a few > times. The most promising idea is to have a command line switch that > would look at any mock that was passed a class name and ensure that > the class responds to any mocked or stubbed methods. But even that > would fall apart as soon as you start using any metaprogramming > techniques to change the nature of an object at runtime. David, Is it not possible to check if a mocked model actually responds to a method call at the point of it being called? Then capture any that aren't on the original object and print out warnings similar to the pending notices? Please excuse my ignorance. I'm sure I've oversimplified this dramatically. ;) -Daniel For me, the answer to keeping track of mocked methods is automated > end-to-end tests. Either in browser, or something like Rails' > integration tests (assuming Rails), or (soon) rbehave's story runner > (which is now being integrated into rspec). > > Cheers, > David > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070730/4022c59b/attachment-0001.html From dchelimsky at gmail.com Mon Jul 30 08:36:00 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 30 Jul 2007 07:36:00 -0500 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <2fff50390707300529k5eebf183n58705f6c66a20721@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <2fff50390707300229n2942cf55p34a387de8c209e74@mail.gmail.com> <57a815bf0707300349gc71c878s837548c50a20896b@mail.gmail.com> <57c63afe0707300443v175f54e6x4f522be457c7c8a3@mail.gmail.com> <2fff50390707300447w675714d2n7259776546ed750d@mail.gmail.com> <57c63afe0707300506h313c2046y2cd4c8b5423ebe72@mail.gmail.com> <2fff50390707300529k5eebf183n58705f6c66a20721@mail.gmail.com> Message-ID: <57c63afe0707300536w4e7f45c8y77b9a3d295e3ddb9@mail.gmail.com> On 7/30/07, Daniel N wrote: > On 7/30/07, David Chelimsky wrote: > > On 7/30/07, Daniel N wrote: > > > On 7/30/07, David Chelimsky wrote: > > > > On 7/30/07, Mikel Lindsaar < raasdnil at gmail.com> wrote: > > > > > I find myself doing the same thing... the, open the model and type > in > > > > > the it shoulds... > > > > > > > > > > I ws thinking along the same line... probably all that would be > needed > > > > > is a rake task that hooks into the Mock class and runs all the specs > > > > > taking not of all the stubs and mocks method calls that are made. > > > > > > > > > > Then it could PRODUCE the it shoulds... > > > > > > > > > > @model = mock_model(People, :id => 1, :name => "Bob") > > > > > @model.should_receive(:alive?).and_return(true) > > > > > > > > > > # rake spec:find_fakes > > > > > > > > > > produces: > > > > > > > > > > describe People "automatically" do > > > > > > > > > > it "should have a name" > > > > > > > > > > it "should respond to alive?" > > > > > > > > > > end > > > > > > > > > > Now... that would be cool.... > > > > > > > > I would tend to disagree. RSpec is a Behaviour Driven Development > > > > tool. The idea is that you write a small example of behaviour FIRST, > > > > and use that example to drive the implementation. The reason you use > > > > examples to drive implementation comes from the idea in Test Driven > > > > Development that it will lead to tighter, more focused and more > > > > flexible implementations. > > > > > > > > If your examples come after the code, whether they are generated or > > > > you write them yourself, then you are losing out quite a bit of value > > > > of the process with which RSpec is aligned. > > > > > > > > Secondly, having a name is not behaviour. Using it might be. Or how > > > > you set it might be. For example: > > > > > > > > describe Thing do > > > > it "should use the first initializer argument as its name" do > > > > Thing.new("Jo?o").name.should == "Jo?o" > > > > end > > > > > > > > it "should be alive when first created" do > > > > Thing.new.should be_alive > > > > end > > > > end > > > > > > > > Implicit in these examples are the fact that Thing has a name and > > > > responds to "alive?", but those are just artifacts in support of the > > > > behaviour. > > > > > > > > That all make sense? > > > > > > In a fairly abstract way. But how do you keep track of what methods > have > > > been stubbed or mocked? > > > > > > From the above Thing.new.alive? will need to be defined. This seems to > be > > > the spec for Thing, but if in a view I said > > > > > > it "should do_stuff if @thing is alive" do > > > > > > @thing = mock_model( Thing ) > > > @thing.stub!( :alive? ).and_return( true ) > > > controller.should_receive( :do_stuff ) > > > do_get > > > > > > end > > > > > > How do I run the view first without Thing, > > > > If you're using mock_model and the constant Thing, then you have to > > create Thing to get that example to run. Admittedly, having to create > > that model class is a distraction from the flow, but it is a very > > small distraction that has never really bothered me that much. I > > imagine that we could tweak mock_model to accept a String, or perhaps > > somebody with stronger TextMate chops than mine could submit a patch > > to the TextMate bundle that would let you click on Thing and create a > > Thing model. > > > > > and also keep track of alive? > > > being decalred on the Thing instance? > > > > This is something that has come up on this list and in RFEs a few > > times. The most promising idea is to have a command line switch that > > would look at any mock that was passed a class name and ensure that > > the class responds to any mocked or stubbed methods. But even that > > would fall apart as soon as you start using any metaprogramming > > techniques to change the nature of an object at runtime. > > > David, > > Is it not possible to check if a mocked model actually responds to a method > call at the point of it being called? > > Then capture any that aren't on the original object and print out warnings > similar to the pending notices? > > Please excuse my ignorance. I'm sure I've oversimplified this dramatically. Actually, that doesn't sound ignorant at all. I was thinking about it differently. Wanna take a crack at a patch? Here's the relevant RFE: http://rubyforge.org/tracker/index.php?func=detail&aid=5064&group_id=797&atid=3152 > ;) > > -Daniel > > > For me, the answer to keeping track of mocked methods is automated > > end-to-end tests. Either in browser, or something like Rails' > > integration tests (assuming Rails), or (soon) rbehave's story runner > > (which is now being integrated into rspec). > > > > Cheers, > > David > > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From has.sox at gmail.com Mon Jul 30 08:40:16 2007 From: has.sox at gmail.com (Daniel N) Date: Mon, 30 Jul 2007 22:40:16 +1000 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <57c63afe0707300536w4e7f45c8y77b9a3d295e3ddb9@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <2fff50390707300229n2942cf55p34a387de8c209e74@mail.gmail.com> <57a815bf0707300349gc71c878s837548c50a20896b@mail.gmail.com> <57c63afe0707300443v175f54e6x4f522be457c7c8a3@mail.gmail.com> <2fff50390707300447w675714d2n7259776546ed750d@mail.gmail.com> <57c63afe0707300506h313c2046y2cd4c8b5423ebe72@mail.gmail.com> <2fff50390707300529k5eebf183n58705f6c66a20721@mail.gmail.com> <57c63afe0707300536w4e7f45c8y77b9a3d295e3ddb9@mail.gmail.com> Message-ID: <2fff50390707300540i5cad9c81n1173ecaf9ef6a78e@mail.gmail.com> On 7/30/07, David Chelimsky wrote: > > On 7/30/07, Daniel N wrote: > > On 7/30/07, David Chelimsky wrote: > > > On 7/30/07, Daniel N wrote: > > > > On 7/30/07, David Chelimsky wrote: > > > > > On 7/30/07, Mikel Lindsaar < raasdnil at gmail.com> wrote: > > > > > > I find myself doing the same thing... the, open the model and > type > > in > > > > > > the it shoulds... > > > > > > > > > > > > I ws thinking along the same line... probably all that would be > > needed > > > > > > is a rake task that hooks into the Mock class and runs all the > specs > > > > > > taking not of all the stubs and mocks method calls that are > made. > > > > > > > > > > > > Then it could PRODUCE the it shoulds... > > > > > > > > > > > > @model = mock_model(People, :id => 1, :name => "Bob") > > > > > > @model.should_receive(:alive?).and_return(true) > > > > > > > > > > > > # rake spec:find_fakes > > > > > > > > > > > > produces: > > > > > > > > > > > > describe People "automatically" do > > > > > > > > > > > > it "should have a name" > > > > > > > > > > > > it "should respond to alive?" > > > > > > > > > > > > end > > > > > > > > > > > > Now... that would be cool.... > > > > > > > > > > I would tend to disagree. RSpec is a Behaviour Driven Development > > > > > tool. The idea is that you write a small example of behaviour > FIRST, > > > > > and use that example to drive the implementation. The reason you > use > > > > > examples to drive implementation comes from the idea in Test > Driven > > > > > Development that it will lead to tighter, more focused and more > > > > > flexible implementations. > > > > > > > > > > If your examples come after the code, whether they are generated > or > > > > > you write them yourself, then you are losing out quite a bit of > value > > > > > of the process with which RSpec is aligned. > > > > > > > > > > Secondly, having a name is not behaviour. Using it might be. Or > how > > > > > you set it might be. For example: > > > > > > > > > > describe Thing do > > > > > it "should use the first initializer argument as its name" do > > > > > Thing.new("Jo?o").name.should == "Jo?o" > > > > > end > > > > > > > > > > it "should be alive when first created" do > > > > > Thing.new.should be_alive > > > > > end > > > > > end > > > > > > > > > > Implicit in these examples are the fact that Thing has a name and > > > > > responds to "alive?", but those are just artifacts in support of > the > > > > > behaviour. > > > > > > > > > > That all make sense? > > > > > > > > In a fairly abstract way. But how do you keep track of what methods > > have > > > > been stubbed or mocked? > > > > > > > > From the above Thing.new.alive? will need to be defined. This > seems to > > be > > > > the spec for Thing, but if in a view I said > > > > > > > > it "should do_stuff if @thing is alive" do > > > > > > > > @thing = mock_model( Thing ) > > > > @thing.stub!( :alive? ).and_return( true ) > > > > controller.should_receive( :do_stuff ) > > > > do_get > > > > > > > > end > > > > > > > > How do I run the view first without Thing, > > > > > > If you're using mock_model and the constant Thing, then you have to > > > create Thing to get that example to run. Admittedly, having to create > > > that model class is a distraction from the flow, but it is a very > > > small distraction that has never really bothered me that much. I > > > imagine that we could tweak mock_model to accept a String, or perhaps > > > somebody with stronger TextMate chops than mine could submit a patch > > > to the TextMate bundle that would let you click on Thing and create a > > > Thing model. > > > > > > > and also keep track of alive? > > > > being decalred on the Thing instance? > > > > > > This is something that has come up on this list and in RFEs a few > > > times. The most promising idea is to have a command line switch that > > > would look at any mock that was passed a class name and ensure that > > > the class responds to any mocked or stubbed methods. But even that > > > would fall apart as soon as you start using any metaprogramming > > > techniques to change the nature of an object at runtime. > > > > > > David, > > > > Is it not possible to check if a mocked model actually responds to a > method > > call at the point of it being called? > > > > Then capture any that aren't on the original object and print out > warnings > > similar to the pending notices? > > > > Please excuse my ignorance. I'm sure I've oversimplified this > dramatically. > > Actually, that doesn't sound ignorant at all. I was thinking about it > differently. > > Wanna take a crack at a patch? Here's the relevant RFE: > > > http://rubyforge.org/tracker/index.php?func=detail&aid=5064&group_id=797&atid=3152 Sure I'll try. I am not at all familiar with Rspec internals though. > ;) > > > > -Daniel > > > > > For me, the answer to keeping track of mocked methods is automated > > > end-to-end tests. Either in browser, or something like Rails' > > > integration tests (assuming Rails), or (soon) rbehave's story runner > > > (which is now being integrated into rspec). > > > > > > Cheers, > > > David > > > > > > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070730/c9666979/attachment.html From dchelimsky at gmail.com Mon Jul 30 08:44:39 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 30 Jul 2007 07:44:39 -0500 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <2fff50390707300540i5cad9c81n1173ecaf9ef6a78e@mail.gmail.com> References: <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <2fff50390707300229n2942cf55p34a387de8c209e74@mail.gmail.com> <57a815bf0707300349gc71c878s837548c50a20896b@mail.gmail.com> <57c63afe0707300443v175f54e6x4f522be457c7c8a3@mail.gmail.com> <2fff50390707300447w675714d2n7259776546ed750d@mail.gmail.com> <57c63afe0707300506h313c2046y2cd4c8b5423ebe72@mail.gmail.com> <2fff50390707300529k5eebf183n58705f6c66a20721@mail.gmail.com> <57c63afe0707300536w4e7f45c8y77b9a3d295e3ddb9@mail.gmail.com> <2fff50390707300540i5cad9c81n1173ecaf9ef6a78e@mail.gmail.com> Message-ID: <57c63afe0707300544v7349e8epcd8f1e7ddaf0e40f@mail.gmail.com> On 7/30/07, Daniel N wrote: > On 7/30/07, David Chelimsky wrote: > > On 7/30/07, Daniel N wrote: > > > On 7/30/07, David Chelimsky wrote: > > > > On 7/30/07, Daniel N < has.sox at gmail.com> wrote: > > > > > On 7/30/07, David Chelimsky wrote: > > > > > > On 7/30/07, Mikel Lindsaar < raasdnil at gmail.com> wrote: > > > > > > > I find myself doing the same thing... the, open the model and > type > > > in > > > > > > > the it shoulds... > > > > > > > > > > > > > > I ws thinking along the same line... probably all that would be > > > needed > > > > > > > is a rake task that hooks into the Mock class and runs all the > specs > > > > > > > taking not of all the stubs and mocks method calls that are > made. > > > > > > > > > > > > > > Then it could PRODUCE the it shoulds... > > > > > > > > > > > > > > @model = mock_model(People, :id => 1, :name => "Bob") > > > > > > > @model.should_receive(:alive?).and_return(true) > > > > > > > > > > > > > > # rake spec:find_fakes > > > > > > > > > > > > > > produces: > > > > > > > > > > > > > > describe People "automatically" do > > > > > > > > > > > > > > it "should have a name" > > > > > > > > > > > > > > it "should respond to alive?" > > > > > > > > > > > > > > end > > > > > > > > > > > > > > Now... that would be cool.... > > > > > > > > > > > > I would tend to disagree. RSpec is a Behaviour Driven Development > > > > > > tool. The idea is that you write a small example of behaviour > FIRST, > > > > > > and use that example to drive the implementation. The reason you > use > > > > > > examples to drive implementation comes from the idea in Test > Driven > > > > > > Development that it will lead to tighter, more focused and more > > > > > > flexible implementations. > > > > > > > > > > > > If your examples come after the code, whether they are generated > or > > > > > > you write them yourself, then you are losing out quite a bit of > value > > > > > > of the process with which RSpec is aligned. > > > > > > > > > > > > Secondly, having a name is not behaviour. Using it might be. Or > how > > > > > > you set it might be. For example: > > > > > > > > > > > > describe Thing do > > > > > > it "should use the first initializer argument as its name" do > > > > > > Thing.new("Jo?o").name.should == "Jo?o" > > > > > > end > > > > > > > > > > > > it "should be alive when first created" do > > > > > > Thing.new.should be_alive > > > > > > end > > > > > > end > > > > > > > > > > > > Implicit in these examples are the fact that Thing has a name and > > > > > > responds to "alive?", but those are just artifacts in support of > the > > > > > > behaviour. > > > > > > > > > > > > That all make sense? > > > > > > > > > > In a fairly abstract way. But how do you keep track of what methods > > > have > > > > > been stubbed or mocked? > > > > > > > > > > From the above Thing.new.alive? will need to be defined. This > seems to > > > be > > > > > the spec for Thing, but if in a view I said > > > > > > > > > > it "should do_stuff if @thing is alive" do > > > > > > > > > > @thing = mock_model( Thing ) > > > > > @thing.stub!( :alive? ).and_return( true ) > > > > > controller.should_receive( :do_stuff ) > > > > > do_get > > > > > > > > > > end > > > > > > > > > > How do I run the view first without Thing, > > > > > > > > If you're using mock_model and the constant Thing, then you have to > > > > create Thing to get that example to run. Admittedly, having to create > > > > that model class is a distraction from the flow, but it is a very > > > > small distraction that has never really bothered me that much. I > > > > imagine that we could tweak mock_model to accept a String, or perhaps > > > > somebody with stronger TextMate chops than mine could submit a patch > > > > to the TextMate bundle that would let you click on Thing and create a > > > > Thing model. > > > > > > > > > and also keep track of alive? > > > > > being decalred on the Thing instance? > > > > > > > > This is something that has come up on this list and in RFEs a few > > > > times. The most promising idea is to have a command line switch that > > > > would look at any mock that was passed a class name and ensure that > > > > the class responds to any mocked or stubbed methods. But even that > > > > would fall apart as soon as you start using any metaprogramming > > > > techniques to change the nature of an object at runtime. > > > > > > > > > David, > > > > > > Is it not possible to check if a mocked model actually responds to a > method > > > call at the point of it being called? > > > > > > Then capture any that aren't on the original object and print out > warnings > > > similar to the pending notices? > > > > > > Please excuse my ignorance. I'm sure I've oversimplified this > dramatically. > > > > Actually, that doesn't sound ignorant at all. I was thinking about it > > differently. > > > > Wanna take a crack at a patch? Here's the relevant RFE: > > > > > http://rubyforge.org/tracker/index.php?func=detail&aid=5064&group_id=797&atid=3152 > > > Sure I'll try. I am not at all familiar with Rspec internals though. This is specific to the mocking framework, and should work for any application (rails or not), so you should be able to just focus on that part of the system. > > > > ;) > > > > > > -Daniel > > > > > > > For me, the answer to keeping track of mocked methods is automated > > > > end-to-end tests. Either in browser, or something like Rails' > > > > integration tests (assuming Rails), or (soon) rbehave's story runner > > > > (which is now being integrated into rspec). > > > > > > > > Cheers, > > > > David > > > > > > > > > > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From raasdnil at gmail.com Mon Jul 30 09:19:31 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Mon, 30 Jul 2007 23:19:31 +1000 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <57c63afe0707300443v175f54e6x4f522be457c7c8a3@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <2fff50390707300229n2942cf55p34a387de8c209e74@mail.gmail.com> <57a815bf0707300349gc71c878s837548c50a20896b@mail.gmail.com> <57c63afe0707300443v175f54e6x4f522be457c7c8a3@mail.gmail.com> Message-ID: <57a815bf0707300619y5dcfdeb1w6c4e0f9a13eb7cc2@mail.gmail.com> > I would tend to disagree. RSpec is a Behaviour Driven Development > tool. The idea is that you write a small example of behaviour FIRST, > and use that example to drive the implementation. The reason you use > examples to drive implementation comes from the idea in Test Driven > Development that it will lead to tighter, more focused and more > flexible implementations. > > That all make sense? Yes, that makes sense. But I am thinking more of on the side of having the situation where you are spec'ing Thing and Thing has to call People or interact with people.... tracking those interactions and the interfaces used would be something needed... Because those interfaces are the tool we use to get the behaviour out of People. In the present (unless I am missing something) the cycle of action goes something like: I spec out the behaviours of a view (say it is the dashboard on 37signals). This view has a lot of interactions with other Classes.. all over the place. But right _now_ I am doing the view, so I mock out all of the other classes and just focus in on the View that I am working on. Good... all specs pass, the page looks presentable... now what? Well... go code up the controller responsible for the view. That's a no brainer, for the view's controller.... But then what is the best practice from here for all the other models it talks to? Walk through the view spec line by line finding each mock'd model and taking each one and coding the spec and then the code...? (sounds awfully unDRY... as, really, you have already specified a behaviour for the model by stubbing or mocking it out....) Surely this is a good task for a computer which is good at doing the very repetative and manual action of "Go find me all the behaviours specified out for this class that other classes need so that they can work". Assuming you went ahead and cleaned up all those views, what is the best way to know you didn't miss a class call? Or am I really just missing the point and all of this is what comes under the umbrella of integration testing? Having said all of the above, I am finding Rails RSpec has totally changed the way I think about coding and designing code... it is wonderful... Regards Mikel On 7/30/07, David Chelimsky wrote: > On 7/30/07, Mikel Lindsaar wrote: > > I find myself doing the same thing... the, open the model and type in > > the it shoulds... > > > > I ws thinking along the same line... probably all that would be needed > > is a rake task that hooks into the Mock class and runs all the specs > > taking not of all the stubs and mocks method calls that are made. > > > > Then it could PRODUCE the it shoulds... > > > > @model = mock_model(People, :id => 1, :name => "Bob") > > @model.should_receive(:alive?).and_return(true) > > > > # rake spec:find_fakes > > > > produces: > > > > describe People "automatically" do > > > > it "should have a name" > > > > it "should respond to alive?" > > > > end > > > > Now... that would be cool.... > > > If your examples come after the code, whether they are generated or > you write them yourself, then you are losing out quite a bit of value > of the process with which RSpec is aligned. > > Secondly, having a name is not behaviour. Using it might be. Or how > you set it might be. For example: > > describe Thing do > it "should use the first initializer argument as its name" do > Thing.new("Jo?o").name.should == "Jo?o" > end > > it "should be alive when first created" do > Thing.new.should be_alive > end > end > > Implicit in these examples are the fact that Thing has a name and > responds to "alive?", but those are just artifacts in support of the > behaviour. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Jul 30 09:31:50 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 30 Jul 2007 08:31:50 -0500 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <57a815bf0707300619y5dcfdeb1w6c4e0f9a13eb7cc2@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <2fff50390707300229n2942cf55p34a387de8c209e74@mail.gmail.com> <57a815bf0707300349gc71c878s837548c50a20896b@mail.gmail.com> <57c63afe0707300443v175f54e6x4f522be457c7c8a3@mail.gmail.com> <57a815bf0707300619y5dcfdeb1w6c4e0f9a13eb7cc2@mail.gmail.com> Message-ID: <57c63afe0707300631l3cc199b5m4c7e7428b4c63d25@mail.gmail.com> On 7/30/07, Mikel Lindsaar wrote: > > I would tend to disagree. RSpec is a Behaviour Driven Development > > tool. The idea is that you write a small example of behaviour FIRST, > > and use that example to drive the implementation. The reason you use > > examples to drive implementation comes from the idea in Test Driven > > Development that it will lead to tighter, more focused and more > > flexible implementations. > > > > That all make sense? > > Yes, that makes sense. > > But I am thinking more of on the side of having the situation where > you are spec'ing Thing and Thing has to call People or interact with > people.... tracking those interactions and the interfaces used would > be something needed... > > Because those interfaces are the tool we use to get the behaviour out of People. > > In the present (unless I am missing something) the cycle of action > goes something like: > > I spec out the behaviours of a view (say it is the dashboard on 37signals). > > This view has a lot of interactions with other Classes.. all over the > place. But right _now_ I am doing the view, so I mock out all of the > other classes and just focus in on the View that I am working on. > > Good... all specs pass, the page looks presentable... now what? > > Well... go code up the controller responsible for the view. That's a > no brainer, for the view's controller.... > > But then what is the best practice from here for all the other models > it talks to? > > Walk through the view spec line by line finding each mock'd model and > taking each one and coding the spec and then the code...? (sounds > awfully unDRY ... as, really, you have already specified a behaviour > for the model by stubbing or mocking it out....) That's an interesting perspective, but I'm not sure that I agree with it. Let's say, for example, that in the view we show one thing if a model is valid, but another if a model is not valid. Not terribly far fetched. Have we specified what it means to be valid? Absolutely not! If anything, what has been specified is a thin picture of an API, just the method names that should be supported. I don't think that is behaviour. > Surely this is a > good task for a computer which is good at doing the very repetative > and manual action of "Go find me all the behaviours specified out for > this class that other classes need so that they can work". > > Assuming you went ahead and cleaned up all those views, what is the > best way to know you didn't miss a class call? Or am I really just > missing the point and all of this is what comes under the umbrella of > integration testing? I tend to work in small, complete vertical slices rather than completing one layer at a time. So rather than doing the whole view first, I'd do one small aspect of it and then push right down to the controller action that supports that aspect of it, then push down to the model, then back up to the next little bit starting from the view. And yes, this is all much more sane if you're doing integration testing as well. Automated integration testing, that is - ultimately, running the app in production IS integration testing - but we'd prefer to avoid catching the things we missed in that particular framework. > Having said all of the above, I am finding Rails RSpec has totally > changed the way I think about coding and designing code... it is > wonderful... Glad to hear it. Cheers, David > > Regards > > > Mikel > > > > On 7/30/07, David Chelimsky wrote: > > On 7/30/07, Mikel Lindsaar wrote: > > > I find myself doing the same thing... the, open the model and type in > > > the it shoulds... > > > > > > I ws thinking along the same line... probably all that would be needed > > > is a rake task that hooks into the Mock class and runs all the specs > > > taking not of all the stubs and mocks method calls that are made. > > > > > > Then it could PRODUCE the it shoulds... > > > > > > @model = mock_model(People, :id => 1, :name => "Bob") > > > @model.should_receive(:alive?).and_return(true) > > > > > > # rake spec:find_fakes > > > > > > produces: > > > > > > describe People "automatically" do > > > > > > it "should have a name" > > > > > > it "should respond to alive?" > > > > > > end > > > > > > Now... that would be cool.... > > > > > > If your examples come after the code, whether they are generated or > > you write them yourself, then you are losing out quite a bit of value > > of the process with which RSpec is aligned. > > > > Secondly, having a name is not behaviour. Using it might be. Or how > > you set it might be. For example: > > > > describe Thing do > > it "should use the first initializer argument as its name" do > > Thing.new("Jo?o").name.should == "Jo?o" > > end > > > > it "should be alive when first created" do > > Thing.new.should be_alive > > end > > end > > > > Implicit in these examples are the fact that Thing has a name and > > responds to "alive?", but those are just artifacts in support of the > > behaviour. > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.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 dougcole at gmail.com Mon Jul 30 14:09:28 2007 From: dougcole at gmail.com (Doug Cole) Date: Mon, 30 Jul 2007 11:09:28 -0700 Subject: [rspec-users] Stubbing Observers in rails? Message-ID: <7b8d80330707301109t75d20824i3ac94e44994585cc@mail.gmail.com> In most of my tests I'd like to be able to stub out the observers for my models, but I'm not sure the best way to do this. I doesn't look like there is a way to stub all instance methods, and I don't seem to be able to stub early enough to stub out the observer as it's instantiated. I can think of several hackish ways to get around it, but I was wondering if anyone could suggest a good solution? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070730/18dc5925/attachment.html From dchelimsky at gmail.com Mon Jul 30 14:12:52 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 30 Jul 2007 13:12:52 -0500 Subject: [rspec-users] Stubbing Observers in rails? In-Reply-To: <7b8d80330707301109t75d20824i3ac94e44994585cc@mail.gmail.com> References: <7b8d80330707301109t75d20824i3ac94e44994585cc@mail.gmail.com> Message-ID: <57c63afe0707301112t57c3390bl31bb38478b15bb57@mail.gmail.com> On 7/30/07, Doug Cole wrote: > In most of my tests I'd like to be able to stub out the observers for my > models, but I'm not sure the best way to do this. I doesn't look like there > is a way to stub all instance methods, and I don't seem to be able to stub > early enough to stub out the observer as it's instantiated. I can think of > several hackish ways to get around it, but I was wondering if anyone could > suggest a good solution? Thanks! If you're looking to stub all instances, why not use (what) Rails (calls) mocks? > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From justnothing at tiscali.co.uk Mon Jul 30 16:03:20 2007 From: justnothing at tiscali.co.uk (David Green) Date: Mon, 30 Jul 2007 13:03:20 -0700 (PDT) Subject: [rspec-users] avoiding repitition Message-ID: <11882919.post@talk.nabble.com> as my rails application gets bigger, I find I'm writing the same generic specs for standard CRUD operations. with 8 controllers so far, and more to come, I'm keen to reduce the duplication. I asked before about generating specs dynamically in this thread : http://www.nabble.com/dynamic-specs-tf3927280.html#a11137640 but it doesn't seem possible completely possible. I'm sure this is an issue for all testing frameworks, not just rspec, so can any of the more seasoned programmers offer some insight into how they would approach the problem? thanks dave -- View this message in context: http://www.nabble.com/avoiding-repitition-tf4178856.html#a11882919 Sent from the rspec-users mailing list archive at Nabble.com. From raasdnil at gmail.com Mon Jul 30 20:30:27 2007 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Tue, 31 Jul 2007 10:30:27 +1000 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <57c63afe0707300631l3cc199b5m4c7e7428b4c63d25@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <2fff50390707300229n2942cf55p34a387de8c209e74@mail.gmail.com> <57a815bf0707300349gc71c878s837548c50a20896b@mail.gmail.com> <57c63afe0707300443v175f54e6x4f522be457c7c8a3@mail.gmail.com> <57a815bf0707300619y5dcfdeb1w6c4e0f9a13eb7cc2@mail.gmail.com> <57c63afe0707300631l3cc199b5m4c7e7428b4c63d25@mail.gmail.com> Message-ID: <57a815bf0707301730y640c56d4nd3815cbfe898b53e@mail.gmail.com> > I tend to work in small, complete vertical slices rather than > completing one layer at a time. So rather than doing the whole view > first, I'd do one small aspect of it and then push right down to the > controller action that supports that aspect of it, then push down to > the model, then back up to the next little bit starting from the view. Hmm... great discussion! The way you are talking sounds, actually, like the right way to do it in RSpec... vertical slices.... That way you are integrating (somewhat) at the same time as describing the behaviour of each layer on the way down. So, really, from one point in the view, you might have four or five vertical slices described on the way down... and that would tend to integrate itself somewhat through the process. Food for thought :) Regards Mikel On 7/30/07, David Chelimsky wrote: > On 7/30/07, Mikel Lindsaar wrote: > > > I would tend to disagree. RSpec is a Behaviour Driven Development > > > tool. The idea is that you write a small example of behaviour FIRST, > > > and use that example to drive the implementation. The reason you use > > > examples to drive implementation comes from the idea in Test Driven > > > Development that it will lead to tighter, more focused and more > > > flexible implementations. > > > > > > That all make sense? > > > > Yes, that makes sense. > > > > But I am thinking more of on the side of having the situation where > > you are spec'ing Thing and Thing has to call People or interact with > > people.... tracking those interactions and the interfaces used would > > be something needed... > > > > Because those interfaces are the tool we use to get the behaviour out of People. > > > > In the present (unless I am missing something) the cycle of action > > goes something like: > > > > I spec out the behaviours of a view (say it is the dashboard on 37signals). > > > > This view has a lot of interactions with other Classes.. all over the > > place. But right _now_ I am doing the view, so I mock out all of the > > other classes and just focus in on the View that I am working on. > > > > Good... all specs pass, the page looks presentable... now what? > > > > Well... go code up the controller responsible for the view. That's a > > no brainer, for the view's controller.... > > > > But then what is the best practice from here for all the other models > > it talks to? > > > > Walk through the view spec line by line finding each mock'd model and > > taking each one and coding the spec and then the code...? (sounds > > awfully unDRY ... as, really, you have already specified a behaviour > > for the model by stubbing or mocking it out....) > > That's an interesting perspective, but I'm not sure that I agree with > it. Let's say, for example, that in the view we show one thing if a > model is valid, but another if a model is not valid. Not terribly far > fetched. Have we specified what it means to be valid? Absolutely not! > > If anything, what has been specified is a thin picture of an API, just > the method names that should be supported. I don't think that is > behaviour. > > > Surely this is a > > good task for a computer which is good at doing the very repetative > > and manual action of "Go find me all the behaviours specified out for > > this class that other classes need so that they can work". > > > > Assuming you went ahead and cleaned up all those views, what is the > > best way to know you didn't miss a class call? Or am I really just > > missing the point and all of this is what comes under the umbrella of > > integration testing? > > I tend to work in small, complete vertical slices rather than > completing one layer at a time. So rather than doing the whole view > first, I'd do one small aspect of it and then push right down to the > controller action that supports that aspect of it, then push down to > the model, then back up to the next little bit starting from the view. > > And yes, this is all much more sane if you're doing integration > testing as well. Automated integration testing, that is - ultimately, > running the app in production IS integration testing - but we'd prefer > to avoid catching the things we missed in that particular framework. > > > Having said all of the above, I am finding Rails RSpec has totally > > changed the way I think about coding and designing code... it is > > wonderful... > > Glad to hear it. > > Cheers, > David > > > > > Regards > > > > > > Mikel > > > > > > > > On 7/30/07, David Chelimsky wrote: > > > On 7/30/07, Mikel Lindsaar wrote: > > > > I find myself doing the same thing... the, open the model and type in > > > > the it shoulds... > > > > > > > > I ws thinking along the same line... probably all that would be needed > > > > is a rake task that hooks into the Mock class and runs all the specs > > > > taking not of all the stubs and mocks method calls that are made. > > > > > > > > Then it could PRODUCE the it shoulds... > > > > > > > > @model = mock_model(People, :id => 1, :name => "Bob") > > > > @model.should_receive(:alive?).and_return(true) > > > > > > > > # rake spec:find_fakes > > > > > > > > produces: > > > > > > > > describe People "automatically" do > > > > > > > > it "should have a name" > > > > > > > > it "should respond to alive?" > > > > > > > > end > > > > > > > > Now... that would be cool.... > > > > > > > > > If your examples come after the code, whether they are generated or > > > you write them yourself, then you are losing out quite a bit of value > > > of the process with which RSpec is aligned. > > > > > > Secondly, having a name is not behaviour. Using it might be. Or how > > > you set it might be. For example: > > > > > > describe Thing do > > > it "should use the first initializer argument as its name" do > > > Thing.new("Jo?o").name.should == "Jo?o" > > > end > > > > > > it "should be alive when first created" do > > > Thing.new.should be_alive > > > end > > > end > > > > > > Implicit in these examples are the fact that Thing has a name and > > > responds to "alive?", but those are just artifacts in support of the > > > behaviour. > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From obiefernandez at gmail.com Mon Jul 30 22:48:03 2007 From: obiefernandez at gmail.com (Obie Fernandez) Date: Mon, 30 Jul 2007 22:48:03 -0400 Subject: [rspec-users] Any liberally-licensed open source projects out there that make good use of RSpec? Message-ID: <8bf510930707301948r36e2fbb7t7062175829eed85e@mail.gmail.com> I'm trolling for example RSpec code. Any pointers appreciated. Cheers, Obie From court3nay at gmail.com Mon Jul 30 23:27:49 2007 From: court3nay at gmail.com (court3nay) Date: Mon, 30 Jul 2007 20:27:49 -0700 Subject: [rspec-users] Any liberally-licensed open source projects out there that make good use of RSpec? In-Reply-To: <8bf510930707301948r36e2fbb7t7062175829eed85e@mail.gmail.com> References: <8bf510930707301948r36e2fbb7t7062175829eed85e@mail.gmail.com> Message-ID: <89BFD999-9504-4053-AE57-EC7EDCE31315@gmail.com> Caboose Sample app ------- Courtenay On Jul 30, 2007, at 7:48 PM, "Obie Fernandez" wrote: > I'm trolling for example RSpec code. Any pointers appreciated. > > Cheers, > Obie > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From linojon at gmail.com Tue Jul 31 00:20:03 2007 From: linojon at gmail.com (linojon) Date: Tue, 31 Jul 2007 00:20:03 -0400 Subject: [rspec-users] helper spec not finding rails core helpers Message-ID: <492C4BBF-9868-44DE-8915-9D0CAAC6F85C@gmail.com> Hi, My helper specs were going ok until I added a call to a rails DateHelper method in one of my helpers http://api.rubyonrails.com/classes/ActionView/Helpers/ DateHelper.html#M000574 The helper runs fine from my view templates, just dies in the spec test. I boiled my question down to a simple (not too useful) example. I'm not sure what I'm missing. # application_helper.rb module ApplicationHelper def app_foo t = Time.now distance_of_time_in_words( t, t + 50.minutes) return true end end # application_helper_spec.rb require File.dirname(__FILE__) + '/../spec_helper' describe ApplicationHelper do it "should find app_foo in application_helpers.rb" do app_foo.should be_true end end # error output NoMethodError in 'ApplicationHelper should find app_foo in application_helpers.rb' undefined method `distance_of_time_in_words' for [Dynamically generated class for RSpec example]:# From dchelimsky at gmail.com Tue Jul 31 05:50:33 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 31 Jul 2007 04:50:33 -0500 Subject: [rspec-users] helper spec not finding rails core helpers In-Reply-To: <492C4BBF-9868-44DE-8915-9D0CAAC6F85C@gmail.com> References: <492C4BBF-9868-44DE-8915-9D0CAAC6F85C@gmail.com> Message-ID: <57c63afe0707310250g29862fe8icd421d9c1e2b1d33@mail.gmail.com> On 7/30/07, linojon wrote: > Hi, > > My helper specs were going ok until I added a call to a rails > DateHelper method in one of my helpers > http://api.rubyonrails.com/classes/ActionView/Helpers/ > DateHelper.html#M000574 > > The helper runs fine from my view templates, just dies in the spec test. > > I boiled my question down to a simple (not too useful) example. I'm > not sure what I'm missing. > > # application_helper.rb > module ApplicationHelper > > def app_foo > t = Time.now > distance_of_time_in_words( t, t + 50.minutes) > return true > end > end > > # application_helper_spec.rb > require File.dirname(__FILE__) + '/../spec_helper' > > describe ApplicationHelper do > it "should find app_foo in application_helpers.rb" do > app_foo.should be_true > end > end > > # error output > NoMethodError in 'ApplicationHelper should find app_foo in > application_helpers.rb' > undefined method `distance_of_time_in_words' for [Dynamically > generated class for RSpec example]:# Please put bug reports, feature requests, and patches here: http://rubyforge.org/tracker/index.php?group_id=797 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Jul 31 06:20:28 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 31 Jul 2007 05:20:28 -0500 Subject: [rspec-users] helper spec not finding rails core helpers In-Reply-To: <57c63afe0707310250g29862fe8icd421d9c1e2b1d33@mail.gmail.com> References: <492C4BBF-9868-44DE-8915-9D0CAAC6F85C@gmail.com> <57c63afe0707310250g29862fe8icd421d9c1e2b1d33@mail.gmail.com> Message-ID: <57c63afe0707310320m49b51d5dqe57649184cc25299@mail.gmail.com> On 7/31/07, David Chelimsky wrote: > On 7/30/07, linojon wrote: > > Hi, > > > > My helper specs were going ok until I added a call to a rails > > DateHelper method in one of my helpers > > http://api.rubyonrails.com/classes/ActionView/Helpers/ > > DateHelper.html#M000574 > > > > The helper runs fine from my view templates, just dies in the spec test. > > > > I boiled my question down to a simple (not too useful) example. I'm > > not sure what I'm missing. > > > > # application_helper.rb > > module ApplicationHelper > > > > def app_foo > > t = Time.now > > distance_of_time_in_words( t, t + 50.minutes) > > return true > > end > > end > > > > # application_helper_spec.rb > > require File.dirname(__FILE__) + '/../spec_helper' > > > > describe ApplicationHelper do > > it "should find app_foo in application_helpers.rb" do > > app_foo.should be_true > > end > > end > > > > # error output > > NoMethodError in 'ApplicationHelper should find app_foo in > > application_helpers.rb' > > undefined method `distance_of_time_in_words' for [Dynamically > > generated class for RSpec example]:# > > Please put bug reports, feature requests, and patches here: > > http://rubyforge.org/tracker/index.php?group_id=797 I went ahead and entered and fixed this: http://rubyforge.org/tracker/index.php?func=detail&aid=12714&group_id=797&atid=3149 Please do report bugs to the tracker, however. I am not always able to jump on things I see on this list. Cheers, David > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From work at ashleymoran.me.uk Tue Jul 31 10:22:07 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 31 Jul 2007 15:22:07 +0100 Subject: [rspec-users] Isolating rails model specs from their implementation In-Reply-To: <57c63afe0707291445t41675558m5213776a87b0ced9@mail.gmail.com> References: <57c63afe0707291321y17a12cf2v64cd4e937d8c38a1@mail.gmail.com> <57c63afe0707291445t41675558m5213776a87b0ced9@mail.gmail.com> Message-ID: On 29 Jul 2007, at 22:45, David Chelimsky wrote: > Changing state between expectations in one example is a TDD no-no. The > reason is that if "project.should be_active" fails, you might do > something to fix it and then find that "project.should_not be_active" > fails. Glad I spotted this - I think I'm guilty of this one. I've dumped a copy on the RSpec style page on our wiki until I get chance to tidy it up Ashley From work at ashleymoran.me.uk Tue Jul 31 11:09:54 2007 From: work at ashleymoran.me.uk (Ashley Moran) Date: Tue, 31 Jul 2007 16:09:54 +0100 Subject: [rspec-users] View-Driven-Development by Behavior-Driven-Development and RSpec In-Reply-To: <57c63afe0707300410p3c0e6d40rfc4ce352056e214@mail.gmail.com> References: <57c63afe0707290557k36e2214br54ad890e364cd332@mail.gmail.com> <57a815bf0707300200r4089f203x56f08e57ee785568@mail.gmail.com> <57c63afe0707300410p3c0e6d40rfc4ce352056e214@mail.gmail.com> Message-ID: On 30 Jul 2007, at 12:10, David Chelimsky wrote: > I've definitely seen advice to start with models before, but I've not > seen anything that says "if you're using Test::Unit, you should start > with models". It's more a development philosophy than a tool issue. I see this debate come round now and again. I can see the perspective of view-driven development proponents, but I've always thought that the models are your, well, model of your problem domain, and that you need to understand that before you can create a consistent interface. Maybe this is because most of the work we do here is finance-related, and untangling the web of business relationships and deals and terms is a nightmare and not something you want to keep re-doing. Perhaps the advice to start with views applies more to sites where the view *is* the behaviour (eg a blog) rather where the view is more of a presentation layer? Ashley From jonathan at parkerhill.com Tue Jul 31 12:14:56 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 31 Jul 2007 12:14:56 -0400 Subject: [rspec-users] helper spec not finding rails core helpers In-Reply-To: <57c63afe0707310320m49b51d5dqe57649184cc25299@mail.gmail.com> References: <492C4BBF-9868-44DE-8915-9D0CAAC6F85C@gmail.com> <57c63afe0707310250g29862fe8icd421d9c1e2b1d33@mail.gmail.com> <57c63afe0707310320m49b51d5dqe57649184cc25299@mail.gmail.com> Message-ID: <2CD1D3C8-077D-48BE-A200-E6E65F6E839B@parkerhill.com> Thanks. I didnt know it was a bug. I thought I was doing something wrong. :) linoj On Jul 31, 2007, at 6:20 AM, David Chelimsky wrote: > On 7/31/07, David Chelimsky wrote: >> On 7/30/07, linojon wrote: >>> Hi, >>> >>> My helper specs were going ok until I added a call to a rails >>> DateHelper method in one of my helpers >>> http://api.rubyonrails.com/classes/ActionView/Helpers/ >>> DateHelper.html#M000574 >>> >>> The helper runs fine from my view templates, just dies in the >>> spec test. >>> >>> I boiled my question down to a simple (not too useful) example. I'm >>> not sure what I'm missing. >>> >>> # application_helper.rb >>> module ApplicationHelper >>> >>> def app_foo >>> t = Time.now >>> distance_of_time_in_words( t, t + 50.minutes) >>> return true >>> end >>> end >>> >>> # application_helper_spec.rb >>> require File.dirname(__FILE__) + '/../spec_helper' >>> >>> describe ApplicationHelper do >>> it "should find app_foo in application_helpers.rb" do >>> app_foo.should be_true >>> end >>> end >>> >>> # error output >>> NoMethodError in 'ApplicationHelper should find app_foo in >>> application_helpers.rb' >>> undefined method `distance_of_time_in_words' for [Dynamically >>> generated class for RSpec example]:# >> >> Please put bug reports, feature requests, and patches here: >> >> http://rubyforge.org/tracker/index.php?group_id=797 > > I went ahead and entered and fixed this: > > http://rubyforge.org/tracker/index.php? > func=detail&aid=12714&group_id=797&atid=3149 > > Please do report bugs to the tracker, however. I am not always able to > jump on things I see on this list. > > Cheers, > David > >> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dougcole at gmail.com Tue Jul 31 13:10:20 2007 From: dougcole at gmail.com (Doug Cole) Date: Tue, 31 Jul 2007 10:10:20 -0700 Subject: [rspec-users] Stubbing Observers in rails? Message-ID: <7b8d80330707311010w78ef5d64uf87b15080c3b215@mail.gmail.com> If I'm not mistaken those stub them out always - I'd like to be able to stub them out for most tests, but I would like to have them around when I want to write tests for the observers themselves! I imagine this is a fairly common use case for Observers and testing. >If you're looking to stub all instances, why not use (what) Rails (calls) mocks? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070731/8dad3d6a/attachment.html From dchelimsky at gmail.com Tue Jul 31 14:07:41 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 31 Jul 2007 13:07:41 -0500 Subject: [rspec-users] Stubbing Observers in rails? In-Reply-To: <7b8d80330707311010w78ef5d64uf87b15080c3b215@mail.gmail.com> References: <7b8d80330707311010w78ef5d64uf87b15080c3b215@mail.gmail.com> Message-ID: <57c63afe0707311107p4a690f90p48562b378c94e41a@mail.gmail.com> On 7/31/07, Doug Cole wrote: > If I'm not mistaken those stub them out always - I'd like to be able to stub > them out for most tests, but I would like to have them around when I want to > write tests for the observers themselves! I imagine this is a fairly common > use case for Observers and testing. There's an RFE for stubbing all instances: http://rubyforge.org/tracker/?func=detail&group_id=797&aid=6791&atid=3152 It's been there for a while. This is very low priority for me, so if you're interested in seeing it happen your best bet would be to submit a patch. Alternatively, I *think* that mocha supports this, so you could use mocha with RSpec instead of the rspec mock framework. Cheers, David > > > >If you're looking to stub all instances, why not use (what) Rails (calls) > mocks? > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jonathan at parkerhill.com Tue Jul 31 15:11:09 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 31 Jul 2007 15:11:09 -0400 Subject: [rspec-users] upgrading from CURRENT to trunk In-Reply-To: <57c63afe0707310320m49b51d5dqe57649184cc25299@mail.gmail.com> References: <492C4BBF-9868-44DE-8915-9D0CAAC6F85C@gmail.com> <57c63afe0707310250g29862fe8icd421d9c1e2b1d33@mail.gmail.com> <57c63afe0707310320m49b51d5dqe57649184cc25299@mail.gmail.com> Message-ID: <868AB963-DFA3-4956-893B-7EA23E76BDF6@parkerhill.com> I've been on CURRENT I tried to switch to trunk but its not completing. How do I install the trunk version? (for rails) (I apologize in advance for being clueless) Here's my steps: First, I brought everything I have up to date: $ sudo gem update ZenTest $ sudo gem update rspec $ script/plugin update rspec $ script/plugin update rspec_on_rails and realized I'm on CURRENT, so I then did: $ rm -rf vendor/plugins/rspec $ rm -rf vendor/plugins/rspec_on_rails $ script/plugin install svn://rubyforge.org/var/svn/rspec/trunk rspec_trunk ... Plugin not found: ["svn://rubyforge.org/var/svn/rspec/trunk", "rspec_trunk"] Unsure about that error, I then tried to build it $ cd vendor/plugins/rspec $ rake kept getting errors about missing gems, installed the gems and rake'd again until it told me to run: $ rake install_dependencies which does a bunch of stuff and then actually installs rails/1.2.2 under vendor/plugins/rspec/example_rails_app/vendor/rails/1.2.2/ and then also installs 1.2.3 ... and then also edge... UGH!! I stopped it before it finished, as i really dont want/need the sample app and rails versions From dchelimsky at gmail.com Tue Jul 31 15:14:31 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 31 Jul 2007 14:14:31 -0500 Subject: [rspec-users] upgrading from CURRENT to trunk In-Reply-To: <868AB963-DFA3-4956-893B-7EA23E76BDF6@parkerhill.com> References: <492C4BBF-9868-44DE-8915-9D0CAAC6F85C@gmail.com> <57c63afe0707310250g29862fe8icd421d9c1e2b1d33@mail.gmail.com> <57c63afe0707310320m49b51d5dqe57649184cc25299@mail.gmail.com> <868AB963-DFA3-4956-893B-7EA23E76BDF6@parkerhill.com> Message-ID: <57c63afe0707311214w6212bbb1sbac924bd6e6eb048@mail.gmail.com> On 7/31/07, Jonathan Linowes wrote: > I've been on CURRENT > I tried to switch to trunk but its not completing. > How do I install the trunk version? (for rails) > > (I apologize in advance for being clueless) > > Here's my steps: > > First, I brought everything I have up to date: > $ sudo gem update ZenTest > $ sudo gem update rspec > $ script/plugin update rspec > $ script/plugin update rspec_on_rails > > and realized I'm on CURRENT, so I then did: > > $ rm -rf vendor/plugins/rspec > $ rm -rf vendor/plugins/rspec_on_rails > $ script/plugin install svn://rubyforge.org/var/svn/rspec/trunk > rspec_trunk Try this: script/plugin install svn://rubyforge.org/var/svn/rspec/trunk rspec > ... > Plugin not found: ["svn://rubyforge.org/var/svn/rspec/trunk", > "rspec_trunk"] > > Unsure about that error, I then tried to build it > > $ cd vendor/plugins/rspec > $ rake > > kept getting errors about missing gems, installed the gems and rake'd > again until it told me to run: > > $ rake install_dependencies > > which does a bunch of stuff and then actually installs rails/1.2.2 > under vendor/plugins/rspec/example_rails_app/vendor/rails/1.2.2/ > and then also installs 1.2.3 ... and then also edge... UGH!! > I stopped it before it finished, as i really dont want/need the > sample app and rails versions > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dougcole at gmail.com Tue Jul 31 15:23:59 2007 From: dougcole at gmail.com (Doug Cole) Date: Tue, 31 Jul 2007 12:23:59 -0700 Subject: [rspec-users] rspec-users Digest, Vol 13, Issue 44 In-Reply-To: References: Message-ID: <7b8d80330707311223m2727a6b3o98beb372e35544eb@mail.gmail.com> Thanks. I was hoping someone else who was using observers and rspec had run into this before and had a solution, as I always prefer the lazy way when possible ;). I'll take a look at the rspec code base and see if I can figure it out well enough to submit a patch. Doug > > On 7/31/07, Doug Cole wrote: > > If I'm not mistaken those stub them out always - I'd like to be able to stub > > them out for most tests, but I would like to have them around when I want to > > write tests for the observers themselves! I imagine this is a fairly common > > use case for Observers and testing. > > There's an RFE for stubbing all instances: > > http://rubyforge.org/tracker/?func=detail&group_id=797&aid=6791&atid=3152 > > It's been there for a while. This is very low priority for me, so if > you're interested in seeing it happen your best bet would be to submit > a patch. > > Alternatively, I *think* that mocha supports this, so you could use > mocha with RSpec instead of the rspec mock framework. > > Cheers, > David > > > > > > > >If you're looking to stub all instances, why not use (what) Rails (calls) > > mocks? > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > From mailing_lists at railsnewbie.com Tue Jul 31 16:05:30 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 31 Jul 2007 16:05:30 -0400 Subject: [rspec-users] Any liberally-licensed open source projects out there that make good use of RSpec? In-Reply-To: <8bf510930707301948r36e2fbb7t7062175829eed85e@mail.gmail.com> References: <8bf510930707301948r36e2fbb7t7062175829eed85e@mail.gmail.com> Message-ID: <9B87F622-9B9F-49B9-9AF8-9B61FDC4B750@railsnewbie.com> Rails or non-rails related? Scott On Jul 30, 2007, at 10:48 PM, Obie Fernandez wrote: > I'm trolling for example RSpec code. Any pointers appreciated. > > Cheers, > Obie > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From badcarl at gmail.com Tue Jul 31 16:07:17 2007 From: badcarl at gmail.com (Carl Porth) Date: Tue, 31 Jul 2007 13:07:17 -0700 Subject: [rspec-users] Stubbing Observers in rails? In-Reply-To: <57c63afe0707311107p4a690f90p48562b378c94e41a@mail.gmail.com> References: <7b8d80330707311010w78ef5d64uf87b15080c3b215@mail.gmail.com> <57c63afe0707311107p4a690f90p48562b378c94e41a@mail.gmail.com> Message-ID: <2AB02F1D-909E-4405-AB13-2DC797527107@gmail.com> Mocha has an any_instance method that does this and flexmock has a new_instances method that does the same. I tried patching the rspec mocking framework to do this and got it working for new instances, but I couldn't get it working with passing arguments to the initialize method. That and the internals of the rspec mocking framework scare the bejeesus out of me. So I just use mocha for mocking and call it a day. Cheers, Carl On Jul 31, 2007, at 11:07 AM, David Chelimsky wrote: > On 7/31/07, Doug Cole wrote: >> If I'm not mistaken those stub them out always - I'd like to be >> able to stub >> them out for most tests, but I would like to have them around when >> I want to >> write tests for the observers themselves! I imagine this is a >> fairly common >> use case for Observers and testing. > > There's an RFE for stubbing all instances: > > http://rubyforge.org/tracker/? > func=detail&group_id=797&aid=6791&atid=3152 > > It's been there for a while. This is very low priority for me, so if > you're interested in seeing it happen your best bet would be to submit > a patch. > > Alternatively, I *think* that mocha supports this, so you could use > mocha with RSpec instead of the rspec mock framework. > > Cheers, > David > >> >> >>> If you're looking to stub all instances, why not use (what) Rails >>> (calls) >> mocks? >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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 robby.lists at planetargon.com Tue Jul 31 16:24:47 2007 From: robby.lists at planetargon.com (Robby Russell) Date: Tue, 31 Jul 2007 13:24:47 -0700 Subject: [rspec-users] upgrading from CURRENT to trunk In-Reply-To: <57c63afe0707311214w6212bbb1sbac924bd6e6eb048@mail.gmail.com> References: <492C4BBF-9868-44DE-8915-9D0CAAC6F85C@gmail.com> <57c63afe0707310250g29862fe8icd421d9c1e2b1d33@mail.gmail.com> <57c63afe0707310320m49b51d5dqe57649184cc25299@mail.gmail.com> <868AB963-DFA3-4956-893B-7EA23E76BDF6@parkerhill.com> <57c63afe0707311214w6212bbb1sbac924bd6e6eb048@mail.gmail.com> Message-ID: <46AF9A8F.9040004@planetargon.com> David Chelimsky wrote: > On 7/31/07, Jonathan Linowes wrote: >> I've been on CURRENT >> I tried to switch to trunk but its not completing. >> How do I install the trunk version? (for rails) >> >> (I apologize in advance for being clueless) >> >> Here's my steps: >> >> First, I brought everything I have up to date: >> $ sudo gem update ZenTest >> $ sudo gem update rspec >> $ script/plugin update rspec >> $ script/plugin update rspec_on_rails >> >> and realized I'm on CURRENT, so I then did: >> >> $ rm -rf vendor/plugins/rspec >> $ rm -rf vendor/plugins/rspec_on_rails >> $ script/plugin install svn://rubyforge.org/var/svn/rspec/trunk >> rspec_trunk > > Try this: > > script/plugin install svn://rubyforge.org/var/svn/rspec/trunk rspec > Might I take this opportunity to encourage you all to consider using piston for managing external dependencies within your repository. :-) http://piston.rubyforge.org/ http://rubyurl.com/qZi (article on using it) Cheers, Robby -- Robby Russell http://www.robbyonrails.com # my blog http://www.planetargon.com # my business http://www.programmingrails.com # my book From dchelimsky at gmail.com Tue Jul 31 16:33:38 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 31 Jul 2007 15:33:38 -0500 Subject: [rspec-users] upgrading from CURRENT to trunk In-Reply-To: <46AF9A8F.9040004@planetargon.com> References: <492C4BBF-9868-44DE-8915-9D0CAAC6F85C@gmail.com> <57c63afe0707310250g29862fe8icd421d9c1e2b1d33@mail.gmail.com> <57c63afe0707310320m49b51d5dqe57649184cc25299@mail.gmail.com> <868AB963-DFA3-4956-893B-7EA23E76BDF6@parkerhill.com> <57c63afe0707311214w6212bbb1sbac924bd6e6eb048@mail.gmail.com> <46AF9A8F.9040004@planetargon.com> Message-ID: <57c63afe0707311333l5c71e2e3g64d77a08b336c73c@mail.gmail.com> On 7/31/07, Robby Russell wrote: > David Chelimsky wrote: > > On 7/31/07, Jonathan Linowes wrote: > >> I've been on CURRENT > >> I tried to switch to trunk but its not completing. > >> How do I install the trunk version? (for rails) > >> > >> (I apologize in advance for being clueless) > >> > >> Here's my steps: > >> > >> First, I brought everything I have up to date: > >> $ sudo gem update ZenTest > >> $ sudo gem update rspec > >> $ script/plugin update rspec > >> $ script/plugin update rspec_on_rails > >> > >> and realized I'm on CURRENT, so I then did: > >> > >> $ rm -rf vendor/plugins/rspec > >> $ rm -rf vendor/plugins/rspec_on_rails > >> $ script/plugin install svn://rubyforge.org/var/svn/rspec/trunk > >> rspec_trunk > > > > Try this: > > > > script/plugin install svn://rubyforge.org/var/svn/rspec/trunk rspec > > > > Might I take this opportunity to encourage you all to consider using > piston for managing external dependencies within your repository. :-) Hear, hear! > > http://piston.rubyforge.org/ > http://rubyurl.com/qZi (article on using it) > > Cheers, > Robby > > > -- > Robby Russell > http://www.robbyonrails.com # my blog > http://www.planetargon.com # my business > http://www.programmingrails.com # my book > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Jul 31 16:40:02 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 31 Jul 2007 16:40:02 -0400 Subject: [rspec-users] Any liberally-licensed open source projects out there that make good use of RSpec? In-Reply-To: <8bf510930707301948r36e2fbb7t7062175829eed85e@mail.gmail.com> References: <8bf510930707301948r36e2fbb7t7062175829eed85e@mail.gmail.com> Message-ID: I've just started DatedBackup (an rsnapshot-like utility), which has about 500 LOC at the moment. It is licensed under the GPL, and has 190 example specs. If you are interested, download the trunk from Rubyforge: svn checkout svn://rubyforge.org/var/svn/datedbackup/trunk/ svn checkout http://datedbackup.rubyforge.org/svn/trunk/ It has a DSL baked in, which I know is up your alley. Of course, Rspec itself would probably be the model if you needed to look at specs. Best Regards, Scott On Jul 30, 2007, at 10:48 PM, Obie Fernandez wrote: > I'm trolling for example RSpec code. Any pointers appreciated. > > Cheers, > Obie > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Tue Jul 31 16:48:41 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 31 Jul 2007 22:48:41 +0200 Subject: [rspec-users] Coding standards and whitespace In-Reply-To: <6CDE2479-54C9-41C9-91EA-C4BE4D23B519@wincent.com> References: <9989DB21-CFBE-4AC4-B9F4-A46D9A3E0A4A@wincent.com> <57c63afe0707271438q54044d4ai5ca5cab2c05f3dbd@mail.gmail.com> <6CDE2479-54C9-41C9-91EA-C4BE4D23B519@wincent.com> Message-ID: <8d961d900707311348y7dcd014frd92fad28f79e5263@mail.gmail.com> The root Rakefile has a task :fix_cr_lf which I ran a while ago to fix newlines in .rb files. Perhaps it can be improved to scan over more files, and replace \t with ' ' too? I'll see what I can do. Thoughts? On 7/29/07, Wincent Colaiuta wrote: > El 27/7/2007, a las 23:38, David Chelimsky escribi?: > > > On 7/26/07, Wincent Colaiuta wrote: > >> Recently as a result of using Git I've noticed a number of > >> inconsistencies in the RSpec codebase with respect to whitespace > >> (mixed line endings, mixed use of spaces and tabs for indentation, > >> and trailing whitespace at the end of lines). I never would have > >> noticed, but Git produces nice colorized diff output which highlights > >> these kinds of inconsistencies. > >> > >> I wanted to ask if the core RSpec team had established any > >> conventions/standards for these things. The basic rationale is that > >> if all contributors agree to a small number of conventions for > >> whitespace there are less likely to be changesets with non- > >> substantive whitespace differences (really, false alarms). > > > > Your thinking makes sense, but we haven't set a standard for this. Do > > you know how to configure TextMate (which most of us use) to take care > > of this automagically when saving files? > > I don't know of any *fully* automatic way to do this in TextMate but > there are some things you can do to make it nearly automatic. In my > experience I've observed a few things: > > * The initial "clean up" of a code base is the biggest task (although > for a project the size of RSpec we are still only talking a few > minutes' work); after that merely maintaining the standards is > relatively easy (especially in the case of Git where if you do a "git > diff" to see what you are about to commit any problems with the > whitespace are immediately evident) > > * Project-wide Find and Replace does a pretty good job of handling > most scenarios; for further "automation" you could record a TextMate > macro and assign it to a key combo (for example, to handle trailing > whitespace do a regular expression search for " +$" and replace all > instances with nothing) > > * The way the Git community tends to work is to enforce this using > repository hooks, and I imagine this could be done in Subversion too: > the idea is that you have a pre-commit hook that can check the > proposed commit against the standards and reject it if it fails (Git > also has a "--no-verify" switch that you can pass if you want to skip > the pre-commit hook) > > * The burden for enforcing the standards need not fall on the > maintainers themselves; in the projects I've seen it is normal for a > maintainer to say things like, "the patch looks good but can you fix > up the whitespace and resubmit?" etc Of course, this is extremely > easy and natural when using Git because the diff tools really put any > discrepancies "in your face". > > In any case, I think you don't need to go "all the way" with this; a > useful first step would be merely deciding upon some standards and > publishing them. Even if you don't take any further steps > (enforcement, hooks, automation etc) the mere act of publishing the > standards and asking people to follow them would be useful. > > Cheers, > Wincent > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From win at wincent.com Tue Jul 31 17:18:51 2007 From: win at wincent.com (Wincent Colaiuta) Date: Tue, 31 Jul 2007 23:18:51 +0200 Subject: [rspec-users] Coding standards and whitespace In-Reply-To: <8d961d900707311348y7dcd014frd92fad28f79e5263@mail.gmail.com> References: <9989DB21-CFBE-4AC4-B9F4-A46D9A3E0A4A@wincent.com> <57c63afe0707271438q54044d4ai5ca5cab2c05f3dbd@mail.gmail.com> <6CDE2479-54C9-41C9-91EA-C4BE4D23B519@wincent.com> <8d961d900707311348y7dcd014frd92fad28f79e5263@mail.gmail.com> Message-ID: <61EE1B1A-54C9-4025-AFCD-09ABC121C1E3@wincent.com> El 31/7/2007, a las 22:48, aslak hellesoy escribi?: > The root Rakefile has a task :fix_cr_lf which I ran a while ago to fix > newlines in .rb files. Perhaps it can be improved to scan over more > files, and replace \t with ' ' too? > > I'll see what I can do. > > Thoughts? Sounds like a good idea. I would suggest that \t should be replaced with ' ' only if it is in the leading whitespace for a line; if it is elsewhere in the line it is probably being (mis)used for alignment and it's probably better to just print a warning showing the filename and then you'd have to visually inspect it as a straight transliteration might not be right (it might be equivalent to one space, not two). I think it's also worth looking for trailing whitespace as it is almost always an mistake which apports neither semantic meaning nor visual enhancement. Cheers, Wincent From aslak.hellesoy at gmail.com Tue Jul 31 17:41:19 2007 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 31 Jul 2007 23:41:19 +0200 Subject: [rspec-users] Coding standards and whitespace In-Reply-To: <61EE1B1A-54C9-4025-AFCD-09ABC121C1E3@wincent.com> References: <9989DB21-CFBE-4AC4-B9F4-A46D9A3E0A4A@wincent.com> <57c63afe0707271438q54044d4ai5ca5cab2c05f3dbd@mail.gmail.com> <6CDE2479-54C9-41C9-91EA-C4BE4D23B519@wincent.com> <8d961d900707311348y7dcd014frd92fad28f79e5263@mail.gmail.com> <61EE1B1A-54C9-4025-AFCD-09ABC121C1E3@wincent.com> Message-ID: <8d961d900707311441k7ec01c4dx70cd4da032ee44@mail.gmail.com> On 7/31/07, Wincent Colaiuta wrote: > El 31/7/2007, a las 22:48, aslak hellesoy escribi?: > > > The root Rakefile has a task :fix_cr_lf which I ran a while ago to fix > > newlines in .rb files. Perhaps it can be improved to scan over more > > files, and replace \t with ' ' too? > > > > I'll see what I can do. > > > > Thoughts? > > Sounds like a good idea. I would suggest that \t should be replaced > with ' ' only if it is in the leading whitespace for a line; if it > is elsewhere in the line it is probably being (mis)used for alignment > and it's probably better to just print a warning showing the filename > and then you'd have to visually inspect it as a straight > transliteration might not be right (it might be equivalent to one > space, not two). > Good point > I think it's also worth looking for trailing whitespace as it is > almost always an mistake which apports neither semantic meaning nor > visual enhancement. > Trailing whitespace is killed with the strip Aslak > Cheers, > Wincent > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Jul 31 22:10:11 2007 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 31 Jul 2007 22:10:11 -0400 Subject: [rspec-users] Unimplemented Spec idea Message-ID: <4E3A79FE-117E-446A-83B8-37436C565BD2@railsnewbie.com> I absolutely love the unimplemented spec idea, and tend to use it a lot. But occasionally it gets in my way, when I rush to write a spec, and then want to change it to a non-implemented spec. My normal solution is to comment out the do...end block. Is there a better way? Stealing an idea from Dan North, how about something like this: it "should do such and such", :pending => true do # unimplemented spec goes here end To make the spec run, simply remove the :pending key. I'm sure this would be rather trivial to implement as well. Thoughts? Scott From has.sox at gmail.com Tue Jul 31 22:13:47 2007 From: has.sox at gmail.com (Daniel N) Date: Wed, 1 Aug 2007 12:13:47 +1000 Subject: [rspec-users] Unimplemented Spec idea In-Reply-To: <4E3A79FE-117E-446A-83B8-37436C565BD2@railsnewbie.com> References: <4E3A79FE-117E-446A-83B8-37436C565BD2@railsnewbie.com> Message-ID: <2fff50390707311913i46083787k6ede3ee3fabd1f67@mail.gmail.com> On 8/1/07, Scott Taylor wrote: > > > I absolutely love the unimplemented spec idea, and tend to use it a > lot. But occasionally it gets in my way, when I rush to write a > spec, and then want to change it to a non-implemented spec. My > normal solution is to comment out the do...end block. Is there a > better way? > > Stealing an idea from Dan North, how about something like this: > > it "should do such and such", :pending => true do > # unimplemented spec goes here > end > > To make the spec run, simply remove the :pending key. I'm sure this > would be rather trivial to implement as well. > > Thoughts? > > Scott This is already included. At least it is in edge. You call the pending( "some reason" ) method at the top of your example to do this. it "should do stuff" do pending( "Don't run this yet" ) # specs go here for unimplemented feature end HTH Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070801/78bed70f/attachment.html From jonathan at parkerhill.com Tue Jul 31 22:24:41 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 31 Jul 2007 22:24:41 -0400 Subject: [rspec-users] helper spec not finding rails core helpers In-Reply-To: <57c63afe0707310320m49b51d5dqe57649184cc25299@mail.gmail.com> References: <492C4BBF-9868-44DE-8915-9D0CAAC6F85C@gmail.com> <57c63afe0707310250g29862fe8icd421d9c1e2b1d33@mail.gmail.com> <57c63afe0707310320m49b51d5dqe57649184cc25299@mail.gmail.com> Message-ID: I'm having trouble logging into RubyForge (might be my firewall, both firefox and safari are not taking its cookie). I wanted to add this comment to http://rubyforge.org/tracker/index.php? func=detail&aid=12714&group_id=797&atid=3149 ------------ The pagination helper has been removed from rails edge. To avoid a runtime error I commented out line 33 in rspec_on_rails/lib/rails/dsl/ behavior/helper.rb # include ActionView::Helpers::PaginationHelper On Jul 31, 2007, at 6:20 AM, David Chelimsky wrote: > On 7/31/07, David Chelimsky wrote: >> On 7/30/07, linojon wrote: >>> Hi, >>> >>> My helper specs were going ok until I added a call to a rails >>> DateHelper method in one of my helpers >>> http://api.rubyonrails.com/classes/ActionView/Helpers/ >>> DateHelper.html#M000574 >>> >>> The helper runs fine from my view templates, just dies in the >>> spec test. >>> >>> I boiled my question down to a simple (not too useful) example. I'm >>> not sure what I'm missing. >>> >>> # application_helper.rb >>> module ApplicationHelper >>> >>> def app_foo >>> t = Time.now >>> distance_of_time_in_words( t, t + 50.minutes) >>> return true >>> end >>> end >>> >>> # application_helper_spec.rb >>> require File.dirname(__FILE__) + '/../spec_helper' >>> >>> describe ApplicationHelper do >>> it "should find app_foo in application_helpers.rb" do >>> app_foo.should be_true >>> end >>> end >>> >>> # error output >>> NoMethodError in 'ApplicationHelper should find app_foo in >>> application_helpers.rb' >>> undefined method `distance_of_time_in_words' for [Dynamically >>> generated class for RSpec example]:# >> >> Please put bug reports, feature requests, and patches here: >> >> http://rubyforge.org/tracker/index.php?group_id=797 > > I went ahead and entered and fixed this: > > http://rubyforge.org/tracker/index.php? > func=detail&aid=12714&group_id=797&atid=3149 > > Please do report bugs to the tracker, however. I am not always able to > jump on things I see on this list. > > Cheers, > David > >> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Jul 31 22:28:58 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 31 Jul 2007 21:28:58 -0500 Subject: [rspec-users] Unimplemented Spec idea In-Reply-To: <2fff50390707311913i46083787k6ede3ee3fabd1f67@mail.gmail.com> References: <4E3A79FE-117E-446A-83B8-37436C565BD2@railsnewbie.com> <2fff50390707311913i46083787k6ede3ee3fabd1f67@mail.gmail.com> Message-ID: <57c63afe0707311928q7c578077n408de3fbb991a6bc@mail.gmail.com> On 7/31/07, Daniel N wrote: > > > On 8/1/07, Scott Taylor wrote: > > > > I absolutely love the unimplemented spec idea, and tend to use it a > > lot. But occasionally it gets in my way, when I rush to write a > > spec, and then want to change it to a non-implemented spec. My > > normal solution is to comment out the do...end block. Is there a > > better way? > > > > Stealing an idea from Dan North, how about something like this: > > > > it "should do such and such", :pending => true do > > # unimplemented spec goes here > > end > > > > To make the spec run, simply remove the :pending key. I'm sure this > > would be rather trivial to implement as well. > > > > Thoughts? > > > > Scott > > > This is already included. At least it is in edge. You call the pending( > "some reason" ) method at the top of your example to do this. > > it "should do stuff" do > pending( "Don't run this yet" ) > # specs go here for unimplemented feature > end You can also do this: it "should not do this buggy thing" do pending "awaiting bug fix" do # buggy code end end When the code in the block fails, the example shows up as pending. When it passes, it shows up as a failure, saying that the failure was expected but it passed instead. > > HTH > Daniel > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jonathan at parkerhill.com Tue Jul 31 22:48:11 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 31 Jul 2007 22:48:11 -0400 Subject: [rspec-users] installing trunk (was: upgrading from CURRENT to trunk) In-Reply-To: <57c63afe0707311214w6212bbb1sbac924bd6e6eb048@mail.gmail.com> References: <492C4BBF-9868-44DE-8915-9D0CAAC6F85C@gmail.com> <57c63afe0707310250g29862fe8icd421d9c1e2b1d33@mail.gmail.com> <57c63afe0707310320m49b51d5dqe57649184cc25299@mail.gmail.com> <868AB963-DFA3-4956-893B-7EA23E76BDF6@parkerhill.com> <57c63afe0707311214w6212bbb1sbac924bd6e6eb048@mail.gmail.com> Message-ID: <2DD2A0E0-D532-4080-82DF-DF360EBA56C5@parkerhill.com> Hi, I must be missing something obvious. $ rm -rf vendor/plugins/rspec $ script/plugin install svn://rubyforge.org/var/svn/rspec/trunk rspec Exported revision 2188. Plugin not found: ["svn://rubyforge.org/var/svn/rspec/trunk", "rspec"] $ ls vendor/plugins rspec/ (etc) $ ls vendor/plugins/rspec README Rakefile example_rails_app/ rspec/ spec_distributed/ RSpec.tmbundle/ doc/ pre_commit/ rspec_on_rails/ spec_ui/ but if i manually shuffle things around, then i'm ok: $ mv vendor/plugins/rspec ~/ $ mv ~/rspec/rspec vendor/plugins/ $ mv ~/rspec/rspec_on_rails vendor/plugins/ this works Probably a script or svn thing I'm doing wrong? From has.sox at gmail.com Tue Jul 31 23:04:27 2007 From: has.sox at gmail.com (Daniel N) Date: Wed, 1 Aug 2007 13:04:27 +1000 Subject: [rspec-users] Unimplemented Spec idea In-Reply-To: <57c63afe0707311928q7c578077n408de3fbb991a6bc@mail.gmail.com> References: <4E3A79FE-117E-446A-83B8-37436C565BD2@railsnewbie.com> <2fff50390707311913i46083787k6ede3ee3fabd1f67@mail.gmail.com> <57c63afe0707311928q7c578077n408de3fbb991a6bc@mail.gmail.com> Message-ID: <2fff50390707312004k6daa6ba2jc92180653c04a427@mail.gmail.com> On 8/1/07, David Chelimsky wrote: > > On 7/31/07, Daniel N wrote: > > > > > > On 8/1/07, Scott Taylor wrote: > > > > > > I absolutely love the unimplemented spec idea, and tend to use it a > > > lot. But occasionally it gets in my way, when I rush to write a > > > spec, and then want to change it to a non-implemented spec. My > > > normal solution is to comment out the do...end block. Is there a > > > better way? > > > > > > Stealing an idea from Dan North, how about something like this: > > > > > > it "should do such and such", :pending => true do > > > # unimplemented spec goes here > > > end > > > > > > To make the spec run, simply remove the :pending key. I'm sure this > > > would be rather trivial to implement as well. > > > > > > Thoughts? > > > > > > Scott > > > > > > This is already included. At least it is in edge. You call the > pending( > > "some reason" ) method at the top of your example to do this. > > > > it "should do stuff" do > > pending( "Don't run this yet" ) > > # specs go here for unimplemented feature > > end > > You can also do this: > > it "should not do this buggy thing" do > pending "awaiting bug fix" do > # buggy code > end > end > > When the code in the block fails, the example shows up as pending. > When it passes, it shows up as a failure, saying that the failure was > expected but it passed instead. That's good to know :) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070801/7d26b20c/attachment.html From dchelimsky at gmail.com Tue Jul 31 23:15:13 2007 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 31 Jul 2007 22:15:13 -0500 Subject: [rspec-users] installing trunk (was: upgrading from CURRENT to trunk) In-Reply-To: <2DD2A0E0-D532-4080-82DF-DF360EBA56C5@parkerhill.com> References: <492C4BBF-9868-44DE-8915-9D0CAAC6F85C@gmail.com> <57c63afe0707310250g29862fe8icd421d9c1e2b1d33@mail.gmail.com> <57c63afe0707310320m49b51d5dqe57649184cc25299@mail.gmail.com> <868AB963-DFA3-4956-893B-7EA23E76BDF6@parkerhill.com> <57c63afe0707311214w6212bbb1sbac924bd6e6eb048@mail.gmail.com> <2DD2A0E0-D532-4080-82DF-DF360EBA56C5@parkerhill.com> Message-ID: <57c63afe0707312015m7d263affwde57c5fd13de4c1b@mail.gmail.com> On 7/31/07, Jonathan Linowes wrote: > > Hi, I must be missing something obvious. > > $ rm -rf vendor/plugins/rspec > > $ script/plugin install svn://rubyforge.org/var/svn/rspec/trunk rspec > Exported revision 2188. > Plugin not found: ["svn://rubyforge.org/var/svn/rspec/trunk", "rspec"] > > $ ls vendor/plugins > rspec/ (etc) > > $ ls vendor/plugins/rspec > README Rakefile > example_rails_app/ rspec/ spec_distributed/ > RSpec.tmbundle/ doc/ > pre_commit/ rspec_on_rails/ spec_ui/ > > > but if i manually shuffle things around, then i'm ok: > > $ mv vendor/plugins/rspec ~/ > $ mv ~/rspec/rspec vendor/plugins/ > $ mv ~/rspec/rspec_on_rails vendor/plugins/ > > this works > > Probably a script or svn thing I'm doing wrong? Sorry - I typed it wrong. See http://rspec.rubyforge.org/documentation/rails/install.html. Instructions for trunk are further down the page. David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jonathan at parkerhill.com Tue Jul 31 23:33:51 2007 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 31 Jul 2007 23:33:51 -0400 Subject: [rspec-users] installing trunk (was: upgrading from CURRENT to trunk) In-Reply-To: <57c63afe0707312015m7d263affwde57c5fd13de4c1b@mail.gmail.com> References: <492C4BBF-9868-44DE-8915-9D0CAAC6F85C@gmail.com> <57c63afe0707310250g29862fe8icd421d9c1e2b1d33@mail.gmail.com> <57c63afe0707310320m49b51d5dqe57649184cc25299@mail.gmail.com> <868AB963-DFA3-4956-893B-7EA23E76BDF6@parkerhill.com> <57c63afe0707311214w6212bbb1sbac924bd6e6eb048@mail.gmail.com> <2DD2A0E0-D532-4080-82DF-DF360EBA56C5@parkerhill.com> <57c63afe0707312015m7d263affwde57c5fd13de4c1b@mail.gmail.com> Message-ID: <1F263445-5567-42C1-A53A-55EF2F7A5866@parkerhill.com> dang, I was looking at "Home >> Install" http://rspec.rubyforge.org/download.html and obviously missed that link Thank you and sorry to be a bother On Jul 31, 2007, at 11:15 PM, David Chelimsky wrote: > > Sorry - I typed it wrong. See > http://rspec.rubyforge.org/documentation/rails/install.html. > Instructions for trunk are further down the page. > > David > >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users