From carl.graff at cox.net Tue Sep 1 13:51:44 2009 From: carl.graff at cox.net (Carl Graff) Date: Tue, 01 Sep 2009 10:51:44 -0700 Subject: [rspec-users] Using ActiveRecord without Rails Message-ID: <4A9D5F30.9050501@cox.net> Hi, I often create integration programs in Ruby that utilize ActiveRecord without the full Rails stack. So I wonder what the best way would be to fully utilize Cucumber and RSpec for BDD in this context. 1. Should I still include rspec-rails so hopefully at least the Model support is available? 2. If so do I need to (or should I) create a similar directory structure to a Rails app? 3. Would it make any sense to use a generator to create the directory structure if not using views and a web server? ----------------------------- Of less importance: Actually I have considered creating/converting these integration applications as full blown Rails applications since they definitely have a model and controller aspect and the Rails framework provides so many built-in features and extensions. But I can?t find a way to run a Rails app without the use of a server which I really don?t need. Eventually it might be desirable that some or all of the integration logic be exposed as web services and if so perhaps a traditional Rails app deployed on a server to provide the web services would trump the overhead of requiring a server. ------------------------------ Thanks, Carl From rick.denatale at gmail.com Tue Sep 1 14:44:52 2009 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 1 Sep 2009 14:44:52 -0400 Subject: [rspec-users] Using ActiveRecord without Rails In-Reply-To: <4A9D5F30.9050501@cox.net> References: <4A9D5F30.9050501@cox.net> Message-ID: On Tue, Sep 1, 2009 at 1:51 PM, Carl Graff wrote: > Of less importance: > > Actually I have considered creating/converting these integration > applications as full blown Rails applications since they definitely have a > model and controller aspect and the Rails framework provides so many > built-in features and extensions. But I can?t find a way to run a Rails app > without the use of a server which I really don?t need. What's your development platform? There's really nothing special about a server. I run personal rails apps on my laptop, in my case under OS X, using passenger and apache, but I've done similar things on a linux development machine before. On OS X, the passenger preference pane makes this dead easy, and passenger runs the rails app on demand, and shuts it down when it's been idle. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale From matt at mattwynne.net Tue Sep 1 14:51:50 2009 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 1 Sep 2009 19:51:50 +0100 Subject: [rspec-users] Using ActiveRecord without Rails In-Reply-To: References: <4A9D5F30.9050501@cox.net> Message-ID: <5A9EBD13-B449-4A4C-AC1C-917F4B4C6A24@mattwynne.net> On 1 Sep 2009, at 19:44, Rick DeNatale wrote: > On Tue, Sep 1, 2009 at 1:51 PM, Carl Graff wrote: > > >> Of less importance: >> >> Actually I have considered creating/converting these integration >> applications as full blown Rails applications since they definitely >> have a >> model and controller aspect and the Rails framework provides so many >> built-in features and extensions. But I can?t find a way to run a >> Rails app >> without the use of a server which I really don?t need. > > What's your development platform? There's really nothing special > about a server. I run personal rails apps on my laptop, in my case > under OS X, using passenger and apache, but I've done similar things > on a linux development machine before. > > On OS X, the passenger preference pane makes this dead easy, and > passenger runs the rails app on demand, and shuts it down when it's > been idle. I think the OP means he doesn't know how to run his code in the rails app without firing up a web server. Carl, You need to take a look at script/runner which will show you how to do it. I personally would build my own app from a blank slate as I'd prefer it to be less cluttered, but if you're used to running in the rails environment, then go for it. > > -- > Rick DeNatale > > Blog: http://talklikeaduck.denhaven2.com/ > Twitter: http://twitter.com/RickDeNatale > WWR: http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn: http://www.linkedin.com/in/rickdenatale > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From alexch at gmail.com Tue Sep 1 15:21:46 2009 From: alexch at gmail.com (Alex Chaffee) Date: Tue, 1 Sep 2009 12:21:46 -0700 Subject: [rspec-users] Using ActiveRecord without Rails In-Reply-To: <4A9D5F30.9050501@cox.net> References: <4A9D5F30.9050501@cox.net> Message-ID: <7a93bd340909011221s7318d555kb3e13b2cb0ff2522@mail.gmail.com> > I often create integration programs in Ruby that utilize ActiveRecord without the full Rails stack. So I wonder what the best way would be to fully utilize Cucumber and RSpec for BDD in this context. > > 1. Should I still include rspec-rails so hopefully at least the Model support is available? I'd say no. All you get is "Model.should have(3).records" and "model.should have(3).errors_on(:attribute)" which is easy enough to live without or to copy and paste into your world. > 2. If so do I need to (or should I) create a similar directory structure to a Rails app? No need. I have my models in a "domain" subdirectory and it works just fine. You need to make sure they're 'require'd since Rails autoload magic is gone but that's not a big deal. > 3. Would it make any sense to use a generator to create the directory structure if not using views and a web server? Good Lord, no :-) > Actually I have considered creating/converting these integration applications as full blown Rails applications since they definitely have a model and controller aspect and the Rails framework provides so many built-in features and extensions. But I can?t find a way to run a Rails app without the use of a server which I really don?t need. > script/runner -e production 'puts User.count' > Eventually it might be desirable that some or all of the integration logic be exposed as web services and if so perhaps a traditional Rails app deployed on a server to provide the web services would trump the overhead of requiring a server. Check out Sinatra. You can use ActiveRecord inside a minimalist web server+router without all the Rails baggage. - A From cagraff at cox.net Tue Sep 1 15:16:03 2009 From: cagraff at cox.net (Carl Graff) Date: Tue, 01 Sep 2009 12:16:03 -0700 Subject: [rspec-users] Using ActiveRecord without Rails In-Reply-To: <5A9EBD13-B449-4A4C-AC1C-917F4B4C6A24@mattwynne.net> References: <4A9D5F30.9050501@cox.net> <5A9EBD13-B449-4A4C-AC1C-917F4B4C6A24@mattwynne.net> Message-ID: <4A9D72F3.4050008@cox.net> Matt Wynne wrote: > > On 1 Sep 2009, at 19:44, Rick DeNatale wrote: > >> On Tue, Sep 1, 2009 at 1:51 PM, Carl Graff wrote: >> >> >>> Of less importance: >>> >>> Actually I have considered creating/converting these integration >>> applications as full blown Rails applications since they definitely >>> have a >>> model and controller aspect and the Rails framework provides so many >>> built-in features and extensions. But I can?t find a way to run a >>> Rails app >>> without the use of a server which I really don?t need. >> >> What's your development platform? There's really nothing special >> about a server. I run personal rails apps on my laptop, in my case >> under OS X, using passenger and apache, but I've done similar things >> on a linux development machine before. >> >> On OS X, the passenger preference pane makes this dead easy, and >> passenger runs the rails app on demand, and shuts it down when it's >> been idle. > > I think the OP means he doesn't know how to run his code in the rails > app without firing up a web server. > > Carl, You need to take a look at script/runner which will show you how > to do it. I personally would build my own app from a blank slate as > I'd prefer it to be less cluttered, but if you're used to running in > the rails environment, then go for it. > >> >> -- >> Rick DeNatale >> >> Blog: http://talklikeaduck.denhaven2.com/ >> Twitter: http://twitter.com/RickDeNatale >> WWR: http://www.workingwithrails.com/person/9021-rick-denatale >> LinkedIn: http://www.linkedin.com/in/rickdenatale >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > My company only uses Windows so deployment is probably Apache/Mongrel or Glassfish with JRuby. Creating my own app by just including ActiveRecord is what I have done in the past, but while reading the RSpec book I noticed all the nice support using rpec-rails and wondered if I could use that and if so the rpec-rails functionality "seems" somewhat dependent on Rails convention and directory structure. I think I will abandon the idea of running a rails app outside of a app server - while it probably can be done I would be out on an island. I'm still debating whether to make this a Rails app with a server for reasons stated above or just a ruby app with activerecord and hopefully the use of some of the features offered by rpec-rails. I guess this all seems rather confusing but such is the world of integration. From cagraff at cox.net Tue Sep 1 15:35:58 2009 From: cagraff at cox.net (Carl Graff) Date: Tue, 01 Sep 2009 12:35:58 -0700 Subject: [rspec-users] Using ActiveRecord without Rails In-Reply-To: <7a93bd340909011221s7318d555kb3e13b2cb0ff2522@mail.gmail.com> References: <4A9D5F30.9050501@cox.net> <7a93bd340909011221s7318d555kb3e13b2cb0ff2522@mail.gmail.com> Message-ID: <4A9D779E.3040303@cox.net> Alex Chaffee wrote: >> I often create integration programs in Ruby that utilize ActiveRecord without the full Rails stack. So I wonder what the best way would be to fully utilize Cucumber and RSpec for BDD in this context. >> >> 1. Should I still include rspec-rails so hopefully at least the Model support is available? >> > > I'd say no. All you get is "Model.should have(3).records" and > "model.should have(3).errors_on(:attribute)" which is easy enough to > live without or to copy and paste into your world. > > >> 2. If so do I need to (or should I) create a similar directory structure to a Rails app? >> > > No need. I have my models in a "domain" subdirectory and it works just > fine. You need to make sure they're 'require'd since Rails autoload > magic is gone but that's not a big deal. > > >> 3. Would it make any sense to use a generator to create the directory structure if not using views and a web server? >> > > Good Lord, no :-) > > >> Actually I have considered creating/converting these integration applications as full blown Rails applications since they definitely have a model and controller aspect and the Rails framework provides so many built-in features and extensions. But I can?t find a way to run a Rails app without the use of a server which I really don?t need. >> >> > > script/runner -e production 'puts User.count' > > >> Eventually it might be desirable that some or all of the integration logic be exposed as web services and if so perhaps a traditional Rails app deployed on a server to provide the web services would trump the overhead of requiring a server. >> > > Check out Sinatra. You can use ActiveRecord inside a minimalist web > server+router without all the Rails baggage. > > - A > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > Wow you seem to have already been down this path and this is excellent advice - thanks!!! From alexch at gmail.com Tue Sep 1 17:56:45 2009 From: alexch at gmail.com (Alex Chaffee) Date: Tue, 1 Sep 2009 14:56:45 -0700 Subject: [rspec-users] Using ActiveRecord without Rails In-Reply-To: <4A9D779E.3040303@cox.net> References: <4A9D5F30.9050501@cox.net> <7a93bd340909011221s7318d555kb3e13b2cb0ff2522@mail.gmail.com> <4A9D779E.3040303@cox.net> Message-ID: <7a93bd340909011456g58b00b11yf150551d1bc45713@mail.gmail.com> > Wow you seem to have already been down this path and this is excellent > advice - thanks!!! :-) http://github.com/alexch/vegas From jjhageman at gmail.com Tue Sep 1 16:11:26 2009 From: jjhageman at gmail.com (Jeremy Hageman) Date: Tue, 1 Sep 2009 13:11:26 -0700 (PDT) Subject: [rspec-users] Fixture replacement vs mock model Message-ID: <164dea8a-2bbe-4a20-98dd-0c5fc3db2b0c@d4g2000prc.googlegroups.com> As someone relatively new to rspec, I am interested in hearing the wisdom of the group in the area of using a fixture replacement gem (such as machinist or factory girl) instead of mocking the model. To me it seems that using a fixture replacement, instead of a mock, would circumvent some of rspec's framework in a bad way. Or perhaps there are certain places where a fixture replacement can be beneficial, and certain places where only a mock will do? Do many of you guys in the group use a fixture replacement? From matt at mattwynne.net Tue Sep 1 18:21:10 2009 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 1 Sep 2009 23:21:10 +0100 Subject: [rspec-users] Fixture replacement vs mock model In-Reply-To: <164dea8a-2bbe-4a20-98dd-0c5fc3db2b0c@d4g2000prc.googlegroups.com> References: <164dea8a-2bbe-4a20-98dd-0c5fc3db2b0c@d4g2000prc.googlegroups.com> Message-ID: On 1 Sep 2009, at 21:11, Jeremy Hageman wrote: > As someone relatively new to rspec, I am interested in hearing the > wisdom of the group in the area of using a fixture replacement gem > (such as machinist or factory girl) instead of mocking the model. To > me it seems that using a fixture replacement, instead of a mock, would > circumvent some of rspec's framework in a bad way. Or perhaps there > are certain places where a fixture replacement can be beneficial, and > certain places where only a mock will do? > > Do many of you guys in the group use a fixture replacement? Yes, I do. My advice is: use mocks when you can, fixture replacements when you must. Tests using mocks are much faster (and therefore fun) to run, but sometimes ActiveRecord makes it pretty hard for you to separate the persistable behaviour of your model class from the business logic, meaning it's simpler (and therefore more fun) just to give it up and hit the database. Fixture replacements are also invaluable for writing acceptance tests in Cucumber. cheers, Matt From sfeley at gmail.com Tue Sep 1 18:26:54 2009 From: sfeley at gmail.com (Stephen Eley) Date: Tue, 1 Sep 2009 18:26:54 -0400 Subject: [rspec-users] Fixture replacement vs mock model In-Reply-To: <164dea8a-2bbe-4a20-98dd-0c5fc3db2b0c@d4g2000prc.googlegroups.com> References: <164dea8a-2bbe-4a20-98dd-0c5fc3db2b0c@d4g2000prc.googlegroups.com> Message-ID: <1fb4df0909011526m7c7467cbo86086b3edae44ee1@mail.gmail.com> On Tue, Sep 1, 2009 at 4:11 PM, Jeremy Hageman wrote: > As someone relatively new to rspec, I am interested in hearing the > wisdom of the group in the area of using a fixture replacement gem > (such as machinist or factory girl) instead of mocking the model. For what kind of test? -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From scott at railsnewbie.com Wed Sep 2 00:16:05 2009 From: scott at railsnewbie.com (Scott Taylor) Date: Wed, 02 Sep 2009 00:16:05 -0400 Subject: [rspec-users] Fixture replacement vs mock model In-Reply-To: <164dea8a-2bbe-4a20-98dd-0c5fc3db2b0c@d4g2000prc.googlegroups.com> References: <164dea8a-2bbe-4a20-98dd-0c5fc3db2b0c@d4g2000prc.googlegroups.com> Message-ID: <4A9DF185.7040607@railsnewbie.com> Jeremy Hageman wrote: > As someone relatively new to rspec, I am interested in hearing the > wisdom of the group in the area of using a fixture replacement gem > (such as machinist or factory girl) instead of mocking the model. To > me it seems that using a fixture replacement, instead of a mock, would > circumvent some of rspec's framework in a bad way. Or perhaps there > are certain places where a fixture replacement can be beneficial, and > certain places where only a mock will do? > > Do many of you guys in the group use a fixture replacement? > As the author of FixtureReplacement (which I guess coined the term), I use one (it) all of the time. Rails / AR is heavily centered around removing abstraction layers from the database - as such, most testing involves the database. Any one who has used mocking in this arena knows how brittle mocks in a rails app can become. Mocking is used outside of rails for two reasons. The first is as a design tool. The idea behind that is that by defining the interfaces before the details you'll end up with a cleaner, more intuitve interface. The second is where it is necessary to do so, e.g., external API's etc. But (full) mocking comes with a price - brittle specs. David C. has suggested in the past that after the implementation is complete, mocks could (and often should) be replaced with the real objects. Most mocks used in a rails project server neither of these purposes. Primarily they are used for speed - which so far has been the primary trade off with using a fixture replacement (such as FixtureReplacement, FactoryGirl, etc). Those who advocate mocking all find the need for a higher level coverage tool, such as cucumber, etc. Either way (until a better solution, such as guillotine becomes available), you'll end up running a slow-ish test suite. Regards, Scott From bcardarella at gmail.com Tue Sep 1 23:02:08 2009 From: bcardarella at gmail.com (Brian Cardarella) Date: Tue, 1 Sep 2009 20:02:08 -0700 (PDT) Subject: [rspec-users] Issue with ActiveRecord::Base.transaction in RSpec Message-ID: I have this example: http://pastie.org/602476 If I run it, it on the 2nd 'Country.count.should == 0' If I run the exact same code in 'script/console test' (so in the same environment) it works just fine. But not within an RSepc example. Any thoughts? From dchelimsky at gmail.com Wed Sep 2 03:11:08 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Sep 2009 02:11:08 -0500 Subject: [rspec-users] Issue with ActiveRecord::Base.transaction in RSpec In-Reply-To: References: Message-ID: <57c63afe0909020011s75a2b85cg7903c979282c7086@mail.gmail.com> On Tue, Sep 1, 2009 at 10:02 PM, Brian Cardarella wrote: > I have this example: > > http://pastie.org/602476 > > If I run it, it on the 2nd 'Country.count.should == 0' There's a verb missing :) I think you mean that "If I run it, it _fails_ on the 2nd ...", yes? What is the failure message you're getting? Does it say "expected 0, got 1" or is there some other error? > > If I run the exact same code in 'script/console test' (so in the same > environment) it works just fine. But not within an RSepc example. Any > thoughts? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bcardarella at gmail.com Wed Sep 2 03:19:13 2009 From: bcardarella at gmail.com (Brian Cardarella) Date: Wed, 2 Sep 2009 00:19:13 -0700 (PDT) Subject: [rspec-users] Issue with ActiveRecord::Base.transaction in RSpec In-Reply-To: <57c63afe0909020011s75a2b85cg7903c979282c7086@mail.gmail.com> References: <57c63afe0909020011s75a2b85cg7903c979282c7086@mail.gmail.com> Message-ID: <8f4cb85b-d7a5-4bb3-a8b1-6e97b236ee71@m38g2000yqd.googlegroups.com> Dave, Yes, verb failure :) I think this might be an issue of me using Sqlite3 as my DB. Let me port over to Postgres and test that out. Hopefully just a false alarm. - Brian On Sep 2, 3:11?am, David Chelimsky wrote: > On Tue, Sep 1, 2009 at 10:02 PM, Brian Cardarella wrote: > > I have this example: > > >http://pastie.org/602476 > > > If I run it, it on the 2nd 'Country.count.should == 0' > > There's a verb missing :) I think you mean that "If I run it, it > _fails_ on the 2nd ...", yes? > > What is the failure message you're getting? Does it say "expected 0, > got 1" or is there some other error? > > > > > If I run the exact same code in 'script/console test' (so in the same > > environment) it works just fine. But not within an RSepc example. Any > > thoughts? > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Sep 2 03:34:51 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Sep 2009 02:34:51 -0500 Subject: [rspec-users] Issue with ActiveRecord::Base.transaction in RSpec In-Reply-To: <8f4cb85b-d7a5-4bb3-a8b1-6e97b236ee71@m38g2000yqd.googlegroups.com> References: <57c63afe0909020011s75a2b85cg7903c979282c7086@mail.gmail.com> <8f4cb85b-d7a5-4bb3-a8b1-6e97b236ee71@m38g2000yqd.googlegroups.com> Message-ID: <57c63afe0909020034h2713a9e7l5c544529f4fbcc34@mail.gmail.com> On Wed, Sep 2, 2009 at 2:19 AM, Brian Cardarella wrote: > Dave, > > ? Yes, verb failure :) > > ? I think this might be an issue of me using Sqlite3 as my DB. Let me > port over to Postgres and test that out. Hopefully just a false alarm. Cool - let us know. Cheers, David > > - Brian > > On Sep 2, 3:11?am, David Chelimsky wrote: >> On Tue, Sep 1, 2009 at 10:02 PM, Brian Cardarella wrote: >> > I have this example: >> >> >http://pastie.org/602476 >> >> > If I run it, it on the 2nd 'Country.count.should == 0' >> >> There's a verb missing :) I think you mean that "If I run it, it >> _fails_ on the 2nd ...", yes? >> >> What is the failure message you're getting? Does it say "expected 0, >> got 1" or is there some other error? >> >> >> >> > If I run the exact same code in 'script/console test' (so in the same >> > environment) it works just fine. But not within an RSepc example. Any >> > thoughts? >> > _______________________________________________ >> > rspec-users mailing list >> > rspec-us... at rubyforge.org >> >http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jjhageman at gmail.com Wed Sep 2 03:34:58 2009 From: jjhageman at gmail.com (Jeremy Hageman) Date: Wed, 2 Sep 2009 00:34:58 -0700 (PDT) Subject: [rspec-users] Fixture replacement vs mock model In-Reply-To: <1fb4df0909011526m7c7467cbo86086b3edae44ee1@mail.gmail.com> References: <164dea8a-2bbe-4a20-98dd-0c5fc3db2b0c@d4g2000prc.googlegroups.com> <1fb4df0909011526m7c7467cbo86086b3edae44ee1@mail.gmail.com> Message-ID: <9a46c646-1602-4643-a8b1-7743f005f019@g19g2000yqo.googlegroups.com> On Sep 1, 3:26 pm, Stephen Eley wrote: > For what kind of test? The specific situation that started the question rolling around in my head was specing out a build method in a controller which creates an instance of a join model between two User instances. My setup includes AuthLogic and Machinist. I am using the suggested AuthLogic setup which has a current_user helper method in the app which returns the current user from the session. One of my main reasons for using a fixture replacement is because I can create a user object with Machinist and then set the user as logged in. To me this more closely models the structure of the app. But as someone new to rspec, I found it tricky to spec out the build method in the following controller code. Which leads me to believe I was using fixture replacements inappropriately and/or too often. # follows_controller.rb class FollowsController < ApplicationController def create @follow = current_user.follows.build(:followed_id => params [:followed_id]) if @follow.save flash[:notice] = "Following created." redirect_to user_path(params[:followed_id]) else flash[:error] = "Unable to follow." redirect_to user_path(params[:followed_id]) end end end Initially, I wanted to write expectations such as: current_user.follows.should_receive(:build) But this is not possible since current_user is a method unavailable to the specs. At this point I realize this situation is much better served by stubbing and mocking the functions and models. From bcardarella at gmail.com Wed Sep 2 03:38:01 2009 From: bcardarella at gmail.com (Brian Cardarella) Date: Wed, 2 Sep 2009 00:38:01 -0700 (PDT) Subject: [rspec-users] Issue with ActiveRecord::Base.transaction in RSpec In-Reply-To: <8f4cb85b-d7a5-4bb3-a8b1-6e97b236ee71@m38g2000yqd.googlegroups.com> References: <57c63afe0909020011s75a2b85cg7903c979282c7086@mail.gmail.com> <8f4cb85b-d7a5-4bb3-a8b1-6e97b236ee71@m38g2000yqd.googlegroups.com> Message-ID: <6bcedb60-53c6-45e7-bf58-34d17dd2cef9@h13g2000yqk.googlegroups.com> False alarm, it was because of Sqlite3. Sorry! - Brian On Sep 2, 3:19?am, Brian Cardarella wrote: > Dave, > > ? ?Yes, verb failure :) > > ? ?I think this might be an issue of me using Sqlite3 as my DB. Let me > port over to Postgres and test that out. Hopefully just a false alarm. > > - Brian > > On Sep 2, 3:11?am, David Chelimsky wrote: > > > > > On Tue, Sep 1, 2009 at 10:02 PM, Brian Cardarella wrote: > > > I have this example: > > > >http://pastie.org/602476 > > > > If I run it, it on the 2nd 'Country.count.should == 0' > > > There's a verb missing :) I think you mean that "If I run it, it > > _fails_ on the 2nd ...", yes? > > > What is the failure message you're getting? Does it say "expected 0, > > got 1" or is there some other error? > > > > If I run the exact same code in 'script/console test' (so in the same > > > environment) it works just fine. But not within an RSepc example. Any > > > thoughts? > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-us... at rubyforge.org > > >http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From jjhageman at gmail.com Wed Sep 2 03:34:02 2009 From: jjhageman at gmail.com (Jeremy Hageman) Date: Wed, 2 Sep 2009 00:34:02 -0700 (PDT) Subject: [rspec-users] Fixture replacement vs mock model In-Reply-To: <4A9DF185.7040607@railsnewbie.com> References: <164dea8a-2bbe-4a20-98dd-0c5fc3db2b0c@d4g2000prc.googlegroups.com> <4A9DF185.7040607@railsnewbie.com> Message-ID: Scott thanks for the insight. On Sep 1, 9:16?pm, Scott Taylor wrote: > Most mocks used in a rails project server neither of these purposes. ? > Primarily they are used for speed - which so far has been the primary > trade off with using a fixture replacement (such as FixtureReplacement, > FactoryGirl, etc). As someone who sound like they rely heavily on a fixture replacement, do you find you achieve the same level of isolation from dependencies when setting up your tests? I personally feel I run across more errors setting up my specs when I am primarily using a fixture replacement, as opposed to mocks. Though I realize this is probably do to a learning curve involved with using specs and a fixture replacement in harmony. From sfeley at gmail.com Wed Sep 2 09:06:44 2009 From: sfeley at gmail.com (Stephen Eley) Date: Wed, 2 Sep 2009 09:06:44 -0400 Subject: [rspec-users] Fixture replacement vs mock model In-Reply-To: <9a46c646-1602-4643-a8b1-7743f005f019@g19g2000yqo.googlegroups.com> References: <164dea8a-2bbe-4a20-98dd-0c5fc3db2b0c@d4g2000prc.googlegroups.com> <1fb4df0909011526m7c7467cbo86086b3edae44ee1@mail.gmail.com> <9a46c646-1602-4643-a8b1-7743f005f019@g19g2000yqo.googlegroups.com> Message-ID: <1fb4df0909020606q335b09fg4264a83b5ec4d967@mail.gmail.com> On Wed, Sep 2, 2009 at 3:34 AM, Jeremy Hageman wrote: > > But this is not possible since current_user is a method unavailable to > the specs. At this point I realize this situation is much better > served by stubbing and mocking the functions and models. Why isn't current_user available to your controller specs? If you defined it in ApplicationController, and your controller inherits from that, then it's just another method on your controller. You may or may not want to stub it for convenience, to return a mock or a factory model, but it should be accessible either way. As for which to use: I've done both, and at this moment I'm not sure I could pin down a rhyme or reason for you. It's whatever seems easier given my current thinking at the time, or sometimes doing neither. The important thing isn't really "how do I fake out the stuff that I'm *not* testing in this spec," but rather "why am I testing this code?" (i.e. "what do I think might break here?") and "what do I need to do to establish that this code works or doesn't work?" Mocks and factories are just details to get you there. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From lists at ruby-forum.com Wed Sep 2 11:32:23 2009 From: lists at ruby-forum.com (Enrico Hartung) Date: Wed, 2 Sep 2009 17:32:23 +0200 Subject: [rspec-users] uploads with webrat in stories In-Reply-To: References: <2CC8290E-BED9-49E7-8A15-7A4793B3B0BB@parkerhill.com> <48B8295A.5070601@benmabey.com> <443c240c0808291058ha4bfcc3q7eaa852eade0b7d4@mail.gmail.com> Message-ID: <4ed043e2ca5db65793d1890f1a7f2314@ruby-forum.com> This topic might be a little bit old, but since I run into this issue recently here's the solution: Due to a lack of multipart form support for integration tests in Action Pack Webrat's attach_file does not work with Rails 2.0.2. I posted a workaround on our blog: http://devblog.imedo.de/2009/9/2/file-uploads-with-webrat-in-ruby-on-rails-2-0-2. -- Posted via http://www.ruby-forum.com/. From jjhageman at gmail.com Wed Sep 2 15:31:45 2009 From: jjhageman at gmail.com (Jeremy Hageman) Date: Wed, 2 Sep 2009 12:31:45 -0700 (PDT) Subject: [rspec-users] Fixture replacement vs mock model In-Reply-To: <1fb4df0909020606q335b09fg4264a83b5ec4d967@mail.gmail.com> References: <164dea8a-2bbe-4a20-98dd-0c5fc3db2b0c@d4g2000prc.googlegroups.com> <1fb4df0909011526m7c7467cbo86086b3edae44ee1@mail.gmail.com> <9a46c646-1602-4643-a8b1-7743f005f019@g19g2000yqo.googlegroups.com> <1fb4df0909020606q335b09fg4264a83b5ec4d967@mail.gmail.com> Message-ID: On Sep 2, 6:06?am, Stephen Eley wrote: > Why isn't current_user available to your controller specs? ?If you > defined it in ApplicationController, and your controller inherits from > that, then it's just another method on your controller. ?You may or > may not want to stub it for convenience, to return a mock or a factory > model, but it should be accessible either way. Thanks for the insight. After poking around a little with debugger I can see that the controller has access to current_user, but the spec tests do not. So I copied the helper methods into a module and included them in the spec_helper. Now the tests have access to current_user. However, I still can't seem to get a should_receive expectation work for the build method without mocking everything out. Any ideas on what I'm missing. describe FollowsController do before(:each) do @user = User.make login_as(@user) end describe "POST create" do it "should build a follow" do current_user.follows.should_receive(:build) post :create, :followed_id => "999" end end end Spec::Mocks::MockExpectationError in 'FollowsController POST create should build a follow' expected :build with (any args) once, but received it 0 times From sixtimesnine at gmail.com Wed Sep 2 18:22:33 2009 From: sixtimesnine at gmail.com (theLemcke) Date: Wed, 2 Sep 2009 15:22:33 -0700 (PDT) Subject: [rspec-users] undefined local variable or method `__FILE' Message-ID: <2fbc586f-ac89-4fb6-add7-d61b1d4dc9c1@z4g2000prh.googlegroups.com> So I began with this setup: http://www.robbyonrails.com/articles/2008/01/22/installing-ruby-on-rails-and-postgresql-on-os-x-third-edition Created a basic rails setup, ran 'script/generate rspec' and 'script/ generate rspec_model Note' and tried to run 'note_spec.rb' and I encountered this error: /Users/sixtimesnine/Rails/TestApps/NotesApp/spec/spec_helper.rb:13: undefined local variable or method `__FILE' for main:Object (NameError) from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/ custom_require.rb:31:in `gem_original_require' from /opt/local/lib/ ruby/vendor_ruby/1.8/rubygems/custom_require.rb:31:in `require' from / Users/sixtimesnine/Rails/TestApps/NotesApp/spec/models/note_spec.rb:1 from /Users/sixtimesnine/Rails/TestApps/NotesApp/vendor/plugins/rspec/ lib/spec/runner/example_group_runner.rb:15:in `load' from /Users/ sixtimesnine/Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/ runner/example_group_runner.rb:15:in `load_files' from /Users/ sixtimesnine/Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/ runner/example_group_runner.rb:14:in `each' from /Users/sixtimesnine/ Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/runner/ example_group_runner.rb:14:in `load_files' from /Users/sixtimesnine/ Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/runner/ options.rb:107:in `run_examples' from /Users/sixtimesnine/Rails/ TestApps/NotesApp/vendor/plugins/rspec/lib/spec/runner/command_line.rb: 9:in `run' from /Users/sixtimesnine/Library/Application Support/ TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ runner.rb:37:in `run' from /Users/sixtimesnine/Library/Application Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ runner.rb:36:in `chdir' from /Users/sixtimesnine/Library/Application Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ runner.rb:36:in `run' from /Users/sixtimesnine/Library/Application Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ runner.rb:14:in `run_file' from /tmp/textmate-command-335.rb:3 Sorry if this is a double post From dchelimsky at gmail.com Wed Sep 2 18:28:05 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Sep 2009 17:28:05 -0500 Subject: [rspec-users] undefined local variable or method `__FILE' In-Reply-To: <2fbc586f-ac89-4fb6-add7-d61b1d4dc9c1@z4g2000prh.googlegroups.com> References: <2fbc586f-ac89-4fb6-add7-d61b1d4dc9c1@z4g2000prh.googlegroups.com> Message-ID: <57c63afe0909021528k6cd06a1ai68c42ed6133f0db2@mail.gmail.com> On Wed, Sep 2, 2009 at 5:22 PM, theLemcke wrote: > So I began with this setup: > http://www.robbyonrails.com/articles/2008/01/22/installing-ruby-on-rails-and-postgresql-on-os-x-third-edition > > Created a basic rails setup, ran 'script/generate rspec' and 'script/ > generate rspec_model Note' and tried to run 'note_spec.rb' and I > encountered this error: > > /Users/sixtimesnine/Rails/TestApps/NotesApp/spec/spec_helper.rb:13: > undefined local variable or method `__FILE' for main:Object This was a typo that was in a commit but not in a release - not sure how you ended up with it - but search for __FILE (without the trailing __). HTH > (NameError) from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/ > custom_require.rb:31:in `gem_original_require' from /opt/local/lib/ > ruby/vendor_ruby/1.8/rubygems/custom_require.rb:31:in `require' from / > Users/sixtimesnine/Rails/TestApps/NotesApp/spec/models/note_spec.rb:1 > from /Users/sixtimesnine/Rails/TestApps/NotesApp/vendor/plugins/rspec/ > lib/spec/runner/example_group_runner.rb:15:in `load' from /Users/ > sixtimesnine/Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/ > runner/example_group_runner.rb:15:in `load_files' from /Users/ > sixtimesnine/Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/ > runner/example_group_runner.rb:14:in `each' from /Users/sixtimesnine/ > Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/runner/ > example_group_runner.rb:14:in `load_files' from /Users/sixtimesnine/ > Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/runner/ > options.rb:107:in `run_examples' from /Users/sixtimesnine/Rails/ > TestApps/NotesApp/vendor/plugins/rspec/lib/spec/runner/command_line.rb: > 9:in `run' from /Users/sixtimesnine/Library/Application Support/ > TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ > runner.rb:37:in `run' from /Users/sixtimesnine/Library/Application > Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ > runner.rb:36:in `chdir' from /Users/sixtimesnine/Library/Application > Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ > runner.rb:36:in `run' from /Users/sixtimesnine/Library/Application > Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ > runner.rb:14:in `run_file' from /tmp/textmate-command-335.rb:3 > > Sorry if this is a double post > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sixtimesnine at gmail.com Wed Sep 2 18:03:24 2009 From: sixtimesnine at gmail.com (theLemcke) Date: Wed, 2 Sep 2009 15:03:24 -0700 (PDT) Subject: [rspec-users] undefined local variable or method `__FILE' Message-ID: <1bca485a-4754-4ff9-96e7-31e70ba474f9@u16g2000pru.googlegroups.com> I ran this install guide: http://www.robbyonrails.com/articles/2008/01/22/installing-ruby-on-rails-and-postgresql-on-os-x-third-edition Then generated a rails app, and ran 'script/generate rspec' and 'script/generate rspec_model Note' When I try to spec note_spec.rb I get this error: /Users/sixtimesnine/Rails/TestApps/NotesApp/spec/spec_helper.rb:13: undefined local variable or method `__FILE' for main:Object (NameError) from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/ custom_require.rb:31:in `gem_original_require' from /opt/local/lib/ ruby/vendor_ruby/1.8/rubygems/custom_require.rb:31:in `require' from / Users/sixtimesnine/Rails/TestApps/NotesApp/spec/models/note_spec.rb:1 from /Users/sixtimesnine/Rails/TestApps/NotesApp/vendor/plugins/rspec/ lib/spec/runner/example_group_runner.rb:15:in `load' from /Users/ sixtimesnine/Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/ runner/example_group_runner.rb:15:in `load_files' from /Users/ sixtimesnine/Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/ runner/example_group_runner.rb:14:in `each' from /Users/sixtimesnine/ Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/runner/ example_group_runner.rb:14:in `load_files' from /Users/sixtimesnine/ Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/runner/ options.rb:107:in `run_examples' from /Users/sixtimesnine/Rails/ TestApps/NotesApp/vendor/plugins/rspec/lib/spec/runner/command_line.rb: 9:in `run' from /Users/sixtimesnine/Library/Application Support/ TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ runner.rb:37:in `run' from /Users/sixtimesnine/Library/Application Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ runner.rb:36:in `chdir' from /Users/sixtimesnine/Library/Application Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ runner.rb:36:in `run' from /Users/sixtimesnine/Library/Application Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ runner.rb:14:in `run_file' from /tmp/textmate-command-320.rb:3 Any clues? From sixtimesnine at gmail.com Wed Sep 2 20:37:18 2009 From: sixtimesnine at gmail.com (theLemcke) Date: Wed, 2 Sep 2009 17:37:18 -0700 (PDT) Subject: [rspec-users] undefined local variable or method `__FILE' In-Reply-To: <1bca485a-4754-4ff9-96e7-31e70ba474f9@u16g2000pru.googlegroups.com> References: <1bca485a-4754-4ff9-96e7-31e70ba474f9@u16g2000pru.googlegroups.com> Message-ID: <47bae2c2-2a4c-48a1-8eaf-992ba3b7e1f1@r24g2000prf.googlegroups.com> Thanks a lot, that fixed it. Sorry about the double post, btw. On Sep 2, 3:03?pm, theLemcke wrote: > I ran this install guide:http://www.robbyonrails.com/articles/2008/01/22/installing-ruby-on-ra... > > Then generated a rails app, and ran 'script/generate rspec' and > 'script/generate rspec_model Note' > > When I try to spec note_spec.rb I get this error: > > /Users/sixtimesnine/Rails/TestApps/NotesApp/spec/spec_helper.rb:13: > undefined local variable or method `__FILE' for main:Object > (NameError) from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/ > custom_require.rb:31:in `gem_original_require' from /opt/local/lib/ > ruby/vendor_ruby/1.8/rubygems/custom_require.rb:31:in `require' from / > Users/sixtimesnine/Rails/TestApps/NotesApp/spec/models/note_spec.rb:1 > from /Users/sixtimesnine/Rails/TestApps/NotesApp/vendor/plugins/rspec/ > lib/spec/runner/example_group_runner.rb:15:in `load' from /Users/ > sixtimesnine/Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/ > runner/example_group_runner.rb:15:in `load_files' from /Users/ > sixtimesnine/Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/ > runner/example_group_runner.rb:14:in `each' from /Users/sixtimesnine/ > Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/runner/ > example_group_runner.rb:14:in `load_files' from /Users/sixtimesnine/ > Rails/TestApps/NotesApp/vendor/plugins/rspec/lib/spec/runner/ > options.rb:107:in `run_examples' from /Users/sixtimesnine/Rails/ > TestApps/NotesApp/vendor/plugins/rspec/lib/spec/runner/command_line.rb: > 9:in `run' from /Users/sixtimesnine/Library/Application Support/ > TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ > runner.rb:37:in `run' from /Users/sixtimesnine/Library/Application > Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ > runner.rb:36:in `chdir' from /Users/sixtimesnine/Library/Application > Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ > runner.rb:36:in `run' from /Users/sixtimesnine/Library/Application > Support/TextMate/Bundles/RSpec.tmbundle/Support/lib/spec/../spec/mate/ > runner.rb:14:in `run_file' from /tmp/textmate-command-320.rb:3 > > Any clues? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From amkirwan at gmail.com Wed Sep 2 23:29:01 2009 From: amkirwan at gmail.com (amkirwan) Date: Wed, 2 Sep 2009 20:29:01 -0700 (PDT) Subject: [rspec-users] Nested Partials Message-ID: What is the best way to spec nested partials in rails? Here is the generic type of nesting I am trying to spec. new.html.erb edit.html.erb _outer_partial.html.erb _inner_partial.html.erb From scott at railsnewbie.com Thu Sep 3 01:18:43 2009 From: scott at railsnewbie.com (Scott Taylor) Date: Thu, 03 Sep 2009 01:18:43 -0400 Subject: [rspec-users] Fixture replacement vs mock model In-Reply-To: References: <164dea8a-2bbe-4a20-98dd-0c5fc3db2b0c@d4g2000prc.googlegroups.com> <4A9DF185.7040607@railsnewbie.com> Message-ID: <4A9F51B3.2070406@railsnewbie.com> Jeremy Hageman wrote: > Scott thanks for the insight. > > On Sep 1, 9:16 pm, Scott Taylor wrote: > >> Most mocks used in a rails project server neither of these purposes. >> Primarily they are used for speed - which so far has been the primary >> trade off with using a fixture replacement (such as FixtureReplacement, >> FactoryGirl, etc). >> > > As someone who sound like they rely heavily on a fixture replacement, > do you find you achieve the same level of isolation from dependencies > when setting up your tests? As long as the (dependent) factory methods are generating valid objects (they will raise as they use create! and save! internally if they aren't), you should see exactly what you would from an invalid AR object. I usually run one test file at a time, too, which helps with the error count with dependencies, and only later when the class under test is passing, I'll go and run the whole suite. Autotest does the same thing if you don't like to do it manually. Scott From matt at mattwynne.net Thu Sep 3 17:15:40 2009 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 3 Sep 2009 22:15:40 +0100 Subject: [rspec-users] Nested Partials In-Reply-To: References: Message-ID: <86B8A747-F710-45E5-8B12-BF53D95763CE@mattwynne.net> On 3 Sep 2009, at 04:29, amkirwan wrote: > What is the best way to spec nested partials in rails? Here is the > generic type of nesting I am trying to spec. > > new.html.erb > edit.html.erb > _outer_partial.html.erb > _inner_partial.html.erb Can you be any more specific about the behaviour you want to spec? cheers, Matt +447974 430184 matt at mattwynne.net http://mattwynne.net From yura at brainhouse.ru Sat Sep 5 11:32:38 2009 From: yura at brainhouse.ru (Yury Kotlyarov) Date: Sat, 05 Sep 2009 19:32:38 +0400 Subject: [rspec-users] Testing multi-model-form views in Rails 2.3.3 and RSpec 1.2.7 In-Reply-To: <3111BCAF-0E68-414F-A5C0-D844DFF1320E@proactive.or.at> References: <35EA92F5-88FB-4421-BE14-667EE15BB0C9@proactive.or.at> <3111BCAF-0E68-414F-A5C0-D844DFF1320E@proactive.or.at> Message-ID: <4AA28496.6040908@brainhouse.ru> I have just the same problem. Any suggestion? TIA, Yury Christoph Schiessl wrote: > I've created a small application to demonstrate the problem in more > detail: > > http://github.com/cs/nested_attributes_spec_demo > > Just clone it, migrate the sqlite database and run `rake spec`. You'll > see 1 failing and 1 succeeding spec. The failing one uses Mocking to > the view. The succeeding example tests exactly the same thing but > actually creates real records in the database (as Matt suggested). I > hope there's a genius somewhere who's able to tell me what I'm doing > wrong or to fix the bug. > > Here's the shell script to get it running (for copy and paste): > > git clone git://github.com/cs/nested_attributes_spec_demo.git > cd nested_attributes_spec_demo > rake db:migrate > rake db:test:clone > rake spec > > On Aug 23, 2009, at 1:57 PM, Matt Wynne wrote: > >> >> On 23 Aug 2009, at 10:51, Christoph Schiessl wrote: >> >>> I have two models in a has_many relationship. The parent model >>> (Invoice) accepts the attributes for it's children (InvoiceItem). >>> The models and the associated controller (InvoicesController) are >>> absolutely standard stuff. This is the significant part of the model >>> code: >>> >>> class Invoice < ActiveRecord::Base >>> has_many :items, :class_name => "InvoiceItem", :dependent => :destroy >>> >>> accepts_nested_attributes_for :items, :allow_destroy => true, >>> :reject_if => Proc.new { |attributes| >>> attributes['quantity'].blank? && attributes['description'].blank? >>> && attributes['unit_price'].blank? >>> } >>> >>> validates_presence_of :recipient, :recipient_street >>> validates_presence_of :recipient_zipcode, :recipient_city >>> end >>> >>> class InvoiceItem < ActiveRecord::Base >>> belongs_to :invoice >>> validates_presence_of :invoice_id >>> validates_presence_of :quantity, :description, :unit_price >>> end >>> >>> Now, here's part of the view I'm trying to test: >>> >>> <% form_for @invoice, :html => {:multipart => true} do |f| %> >>>

text fields for recipient, recipient_street, recipient_zipcode, >>> recipient_city and so on go here

>>> <% f.fields_for :items do |form_item| %> >>>

text fields for quantity, description, unit_price and so on go >>> here

>>> <% # exception is thrown in the next line: %> >>> <% unless form_item.object.new_record? %> >>>
<%= form_item.check_box :_delete %> >>> <%= form_item.label :_delete, "Remove" %> >>> <% end %> >>> <% end %> >>> <% end %> >>> >>> Everything is working just fine if i test it manually in the browser. >>> However, I don't get any rspec tests to work. >>> >>> describe "/invoices/_form.html.erb" do >>> before do >>> @items = [mock_model(InvoiceItem), mock_model(InvoiceItem)] >>> assigns[:invoice] = @invoice = mock_model(Invoice, :items => @items) >>> render >>> end >>> it "renders the invoice form" do >>> response.should have_tag("form") >>> end >>> end >>> >>> When i run `rake spec:views` i get the following error (line numbers >>> do not match with supplied sample code): >>> >>> ActionView::TemplateError in '/invoices/_form.html.erb renders the >>> invoice form' >>> You have a nil object when you didn't expect it! >>> You might have expected an instance of ActiveRecord::Base. >>> The error occurred while evaluating nil.new_record? >>> On line #3 of app/views/invoices/_form.html.erb >>> >>> 1: <% form_for @invoice, :html => {:multipart => true} do |f| %> >>> 2: <% f.fields_for :items do |form_item| %> >>> 3: <% unless form_item.object.new_record? %> >>> 4:
<%= form_item.check_box :_delete %> >>> 5: <%= form_item.label :_delete, "Remove" %> >>> 6: <% end %> >>> >>> app/views/invoices/_form.html.erb:3 >>> app/views/invoices/_form.html.erb:2 >>> app/views/invoices/_form.html.erb:1 >>> /spec/views/invoices/_form.html.erb_spec.rb:7 >>> /usr/local/lib/ruby/1.8/timeout.rb:53:in `timeout' >>> vendor/plugins/rspec/bin/spec:4 >>> >>> So, how do i prevent this? I can't imagine that no one has tried that >>> before. I appreciate ANY advice or pointers greatly! >> >> I'm just going to make a guess, but I'd say this could be to do with >> ActiveRecord's association proxy. I've had a few issues in the past >> trying to fake it with an array, as you've done here. >> >> It's ugly, I know, but could you try building a real Invoice instance >> in the database (use FactoryGirl, Fixjour or something) and adding a >> couple of InvoiceItems to it in your before block? If that works it >> would help us to narrow down the problem. >> >> cheers, >> Matt >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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 chs at proactive.or.at Sat Sep 5 17:33:45 2009 From: chs at proactive.or.at (Christoph Schiessl) Date: Sat, 5 Sep 2009 23:33:45 +0200 Subject: [rspec-users] Testing multi-model-form views in Rails 2.3.3 and RSpec 1.2.7 In-Reply-To: <4AA28496.6040908@brainhouse.ru> References: <35EA92F5-88FB-4421-BE14-667EE15BB0C9@proactive.or.at> <3111BCAF-0E68-414F-A5C0-D844DFF1320E@proactive.or.at> <4AA28496.6040908@brainhouse.ru> Message-ID: <0B060E81-82E1-4454-A672-DC9CF5DDFB16@proactive.or.at> Well, I'm still looking for a solution. Best regards, Christoph On Sep 5, 2009, at 5:32 PM, Yury Kotlyarov wrote: > I have just the same problem. Any suggestion? > > TIA, > Yury > > > Christoph Schiessl wrote: >> I've created a small application to demonstrate the problem in more >> detail: >> >> http://github.com/cs/nested_attributes_spec_demo >> >> Just clone it, migrate the sqlite database and run `rake spec`. >> You'll >> see 1 failing and 1 succeeding spec. The failing one uses Mocking to >> the view. The succeeding example tests exactly the same thing but >> actually creates real records in the database (as Matt suggested). I >> hope there's a genius somewhere who's able to tell me what I'm doing >> wrong or to fix the bug. >> >> Here's the shell script to get it running (for copy and paste): >> >> git clone git://github.com/cs/nested_attributes_spec_demo.git >> cd nested_attributes_spec_demo >> rake db:migrate >> rake db:test:clone >> rake spec >> >> On Aug 23, 2009, at 1:57 PM, Matt Wynne wrote: >> >>> >>> On 23 Aug 2009, at 10:51, Christoph Schiessl wrote: >>> >>>> I have two models in a has_many relationship. The parent model >>>> (Invoice) accepts the attributes for it's children (InvoiceItem). >>>> The models and the associated controller (InvoicesController) are >>>> absolutely standard stuff. This is the significant part of the >>>> model >>>> code: >>>> >>>> class Invoice < ActiveRecord::Base >>>> has_many :items, :class_name => "InvoiceItem", :dependent >>>> => :destroy >>>> >>>> accepts_nested_attributes_for :items, :allow_destroy => true, >>>> :reject_if => Proc.new { |attributes| >>>> attributes['quantity'].blank? && attributes['description'].blank? >>>> && attributes['unit_price'].blank? >>>> } >>>> >>>> validates_presence_of :recipient, :recipient_street >>>> validates_presence_of :recipient_zipcode, :recipient_city >>>> end >>>> >>>> class InvoiceItem < ActiveRecord::Base >>>> belongs_to :invoice >>>> validates_presence_of :invoice_id >>>> validates_presence_of :quantity, :description, :unit_price >>>> end >>>> >>>> Now, here's part of the view I'm trying to test: >>>> >>>> <% form_for @invoice, :html => {:multipart => true} do |f| %> >>>>

text fields for recipient, recipient_street, recipient_zipcode, >>>> recipient_city and so on go here

>>>> <% f.fields_for :items do |form_item| %> >>>>

text fields for quantity, description, unit_price and so on go >>>> here

>>>> <% # exception is thrown in the next line: %> >>>> <% unless form_item.object.new_record? %> >>>>
<%= form_item.check_box :_delete %> >>>> <%= form_item.label :_delete, "Remove" %> >>>> <% end %> >>>> <% end %> >>>> <% end %> >>>> >>>> Everything is working just fine if i test it manually in the >>>> browser. >>>> However, I don't get any rspec tests to work. >>>> >>>> describe "/invoices/_form.html.erb" do >>>> before do >>>> @items = [mock_model(InvoiceItem), mock_model(InvoiceItem)] >>>> assigns[:invoice] = @invoice = mock_model(Invoice, :items => >>>> @items) >>>> render >>>> end >>>> it "renders the invoice form" do >>>> response.should have_tag("form") >>>> end >>>> end >>>> >>>> When i run `rake spec:views` i get the following error (line >>>> numbers >>>> do not match with supplied sample code): >>>> >>>> ActionView::TemplateError in '/invoices/_form.html.erb renders the >>>> invoice form' >>>> You have a nil object when you didn't expect it! >>>> You might have expected an instance of ActiveRecord::Base. >>>> The error occurred while evaluating nil.new_record? >>>> On line #3 of app/views/invoices/_form.html.erb >>>> >>>> 1: <% form_for @invoice, :html => {:multipart => true} do |f| %> >>>> 2: <% f.fields_for :items do |form_item| %> >>>> 3: <% unless form_item.object.new_record? %> >>>> 4:
<%= form_item.check_box :_delete %> >>>> 5: <%= form_item.label :_delete, "Remove" %> >>>> 6: <% end %> >>>> >>>> app/views/invoices/_form.html.erb:3 >>>> app/views/invoices/_form.html.erb:2 >>>> app/views/invoices/_form.html.erb:1 >>>> /spec/views/invoices/_form.html.erb_spec.rb:7 >>>> /usr/local/lib/ruby/1.8/timeout.rb:53:in `timeout' >>>> vendor/plugins/rspec/bin/spec:4 >>>> >>>> So, how do i prevent this? I can't imagine that no one has tried >>>> that >>>> before. I appreciate ANY advice or pointers greatly! >>> >>> I'm just going to make a guess, but I'd say this could be to do with >>> ActiveRecord's association proxy. I've had a few issues in the past >>> trying to fake it with an array, as you've done here. >>> >>> It's ugly, I know, but could you try building a real Invoice >>> instance >>> in the database (use FactoryGirl, Fixjour or something) and adding a >>> couple of InvoiceItems to it in your before block? If that works it >>> would help us to narrow down the problem. >>> >>> cheers, >>> Matt >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.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 pcreux at gmail.com Tue Sep 8 15:53:58 2009 From: pcreux at gmail.com (Philippe Creux) Date: Tue, 8 Sep 2009 12:53:58 -0700 Subject: [rspec-users] Issue with the "class" method of a mocked model Message-ID: <26bb8f3a0909081253s7a941389n408584da32d3fcba@mail.gmail.com> Hi everybody, I run into an issue with the "class" method of a mocked model. The following expectation fails: @user = mock_model(Author) is_author(user).should == true def is_author(user) case user when Author return true else return false end end However, it works well when running the app. I guess that the problem comes from the mock as it compares the mocked-model.class with the real-model.class. Do you have any idea to fix that? For now, I use "Author.class.to_s" but I don't like to make my code ugly for the mock to work. :) Cheers, ? http://pcreux.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Sep 8 17:50:01 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 8 Sep 2009 16:50:01 -0500 Subject: [rspec-users] Issue with the "class" method of a mocked model In-Reply-To: <26bb8f3a0909081253s7a941389n408584da32d3fcba@mail.gmail.com> References: <26bb8f3a0909081253s7a941389n408584da32d3fcba@mail.gmail.com> Message-ID: <57c63afe0909081450k3d57b25et199d91baab629375@mail.gmail.com> On Tue, Sep 8, 2009 at 2:53 PM, Philippe Creux wrote: > Hi everybody, > > I run into an issue with the "class" method of a mocked model. The following > expectation fails: > > @user = mock_model(Author) > is_author(user).should == true > > def is_author(user) > ? case user > ??? when Author > ????? return true > ? else > ??? return false > ? end > end > > However, it works well when running the app. I guess that the problem comes > from the mock as it compares the mocked-model.class with the > real-model.class. Do you have any idea to fix that? First, don't use mock_model. It is an RSpec mock object, not an Author. You can either use a real Author, or stub_model(Author), which is actually an Author, but decorated with some additional stub-friendly behaviour. HTH, David > > For now, I use "Author.class.to_s" but I don't like to make my code ugly for > the mock to work. :) > > Cheers, > > ? > http://pcreux.com > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cremes.devlist at mac.com Wed Sep 9 17:37:13 2009 From: cremes.devlist at mac.com (Chuck Remes) Date: Wed, 09 Sep 2009 16:37:13 -0500 Subject: [rspec-users] [Q] mock expectation with +self+ Message-ID: <8392161F-D1D7-44D6-89EB-3CD298257D04@mac.com> I am trying to spec out a method that is using the 'beam' gem to fire an event. When the method fires the event, it should pass the current +self+ as an argument. e.g. def foo Beam.fire :my_event, self end it "should fire :my_event and pass self" do Beam.should_receive(:fire).with(:my_event, ????) foo end How can I set a mock expectation to work resolve self correctly? I suspect it isn't possible but I'd like confirmation before I waste too much time on this. From cremes.devlist at mac.com Wed Sep 9 17:46:40 2009 From: cremes.devlist at mac.com (Chuck Remes) Date: Wed, 09 Sep 2009 16:46:40 -0500 Subject: [rspec-users] [Q] mock expectation with +self+ In-Reply-To: <8392161F-D1D7-44D6-89EB-3CD298257D04@mac.com> References: <8392161F-D1D7-44D6-89EB-3CD298257D04@mac.com> Message-ID: On Sep 9, 2009, at 4:37 PM, Chuck Remes wrote: > I am trying to spec out a method that is using the 'beam' gem to > fire an event. When the method fires the event, it should pass the > current +self+ as an argument. > > e.g. > > def foo > Beam.fire :my_event, self > end > > it "should fire :my_event and pass self" do > Beam.should_receive(:fire).with(:my_event, ????) > foo > end > > How can I set a mock expectation to work resolve self correctly? I > suspect it isn't possible but I'd like confirmation before I waste > too much time on this. Ugh, never mind. :-\ I should have thought a little harder before posting... sorry for the noise. cr class Bar def foo Beacon.fire :my_event, self end end it "should fire :my_evnet and pass self" do @klass = Bar.new Beacon.should_receive(:fire).with(:my_event, @klass) @klass.foo end From james.herdman at gmail.com Fri Sep 11 10:27:15 2009 From: james.herdman at gmail.com (James H) Date: Fri, 11 Sep 2009 07:27:15 -0700 (PDT) Subject: [rspec-users] JRuby and RSpec for Rails Message-ID: <3a45526a-f798-4339-9746-4cbebc40763c@m11g2000yqf.googlegroups.com> Hi friends. I have a Rails project I'm working on that uses JRuby, and consequently I use a few Java libs in this project. I often don't want to run these examples when I'm using Autospec, nor do I necessarily want to use JRuby during testing as it's much slower than MRI for specs. I went ahead and cordoned off my specs into their own subdirectory in the main "spec" directory hoping this would shield them from running when I invoke "rake spec". This does not seem to be the case though. I figure the next logical thing to do would be to have my own custom "describe" blocks that informed RSpec that I want to skip them unless RUBY_PLATFORM is set to "java". Does this sound like a reasonable strategy? I'm not really sure how to implement the "skip me if I'm not being run with JRuby" part of this strategy. I could use some advice. Thank you, James From bcolfer at shopping.com Fri Sep 11 13:34:42 2009 From: bcolfer at shopping.com (Colfer, Brian) Date: Fri, 11 Sep 2009 11:34:42 -0600 Subject: [rspec-users] JRuby and RSpec for Rails In-Reply-To: <3a45526a-f798-4339-9746-4cbebc40763c@m11g2000yqf.googlegroups.com> References: <3a45526a-f798-4339-9746-4cbebc40763c@m11g2000yqf.googlegroups.com> Message-ID: <5A95EAE4A3FE1645992FAF868AD6DCDC0AB90F15@DEN-EXM-06.corp.ebay.com> It seems a reasonable approach ... Have you looked at Celerity to drive the app? From jRuby? Brian -----Original Message----- From: rspec-users-bounces at rubyforge.org [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of James H Sent: Friday, September 11, 2009 7:27 AM To: rspec-users at rubyforge.org Subject: [rspec-users] JRuby and RSpec for Rails Hi friends. I have a Rails project I'm working on that uses JRuby, and consequently I use a few Java libs in this project. I often don't want to run these examples when I'm using Autospec, nor do I necessarily want to use JRuby during testing as it's much slower than MRI for specs. I went ahead and cordoned off my specs into their own subdirectory in the main "spec" directory hoping this would shield them from running when I invoke "rake spec". This does not seem to be the case though. I figure the next logical thing to do would be to have my own custom "describe" blocks that informed RSpec that I want to skip them unless RUBY_PLATFORM is set to "java". Does this sound like a reasonable strategy? I'm not really sure how to implement the "skip me if I'm not being run with JRuby" part of this strategy. I could use some advice. Thank you, James _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Fri Sep 11 16:28:22 2009 From: lists at ruby-forum.com (Giuseppe Bertini) Date: Fri, 11 Sep 2009 22:28:22 +0200 Subject: [rspec-users] controller specs with non-RESTful routes Message-ID: <0a7959070e320038d584186684c70880@ruby-forum.com> Hello list, this should be an easy one, but I seem to be stuck. What is the proper way to mimic a POST request for a named, non-RESTful route? here's the route and the rest of the setup: map.accept_invitation '/accept_invitation/:id', :controller => "invitations", :action => "accept", :method => "post" class InvitationsController < ApplicationController def accept end end describe InvitationsController do describe "POST 'accept'" do it "should be successful" do post :accept, :id => 1 response.should be_success end end end When I run this spec, I get: No route matches {:controller=>"invitations", :action=>"accept", :id=>"1"} Can anyone please suggest what I should be writing instead to test this request? Thanks in advance! Giuseppe -- Posted via http://www.ruby-forum.com/. From david at humblehacker.com Fri Sep 11 20:58:34 2009 From: david at humblehacker.com (David Whetstone) Date: Fri, 11 Sep 2009 17:58:34 -0700 Subject: [rspec-users] Suggestion: a more visual RSpec Message-ID: <6EF00D2F-2AC1-4303-973D-FAEFFFFFFDA7@humblehacker.com> IDEA ---- I've just gotten started using RSpec, and in the process of writing some tests, I came to a realization. Despite having various formatters, like HTML, RSpec is essentially text-based. That is, regardless of the capabilities of other output formats, descriptions are limited to the least-common-denominator form of plain text. I find, however, that some things are just better described _visually_ -- for a few reasons: -- "A picture is worth a thousand words." Sometimes it's just tedious to describe an object textually, while a graphic representation can be, erm, _illustrative_. -- Sometimes many descriptions in a spec can differ by only a few words. This makes it cumbersome to determine at a glance what a particular test is doing. Mixing graphics with text goes a long way towards improving this situation. POTENTIAL IMPLEMENTATION ------------------------ If you've come this far with me, and can see some benefit to this, then let's discuss how this might work. I've taken some time to hack in a rudimentary ability to mix graphics into descriptions. Of course, this could only work for graphics capable formatters, like HTMLFormatter. Here's an example from one of my spec files: describe "'Unification'" do describe "Given a FeatureStructure with references, and one without," do let (:fs1) {newfs(:agreement => {:REF1 => {:number => "sg"}}, :subject => {:agreement => :REF1})} let (:fs2) {newfs(:agreement => {:person => "3"})} describe "fs1 = !L(fs1)! and fs2 = !L(fs2)!," do describe "fs1.unify!(fs2)" do let (:expected) {newfs(:agreement => {:REF1 => {:number => "sg", :person => "3"}}, :subject => {:agreement => :REF1})} it "should be !L(expected)!" do result = fs1.unify!(fs2) result.should == expected result.should be_identical_to(fs1) result.should be_identical_to(fs2) end end end end Now, what I've done here is modify HTMLFormatter so that descriptions can use textile formatting. Then I've augmented the textile !! image markers to accept an object reference and a formatter to use. You can see this in the line: describe "fs1 = !L(fs1)! and fs2 = !L(fs2)!," do for example. !L(fs1)! says to format the object (fs1) using LaTeX (L). This means that the object returned by fs1 must have a to_latex method. Another possible format could be DOT (D): !D(fs1)!. The output of the above spec snippet can be found here: http://humblehacker.com/boardimages/visual_rspec_example.png PERFORMANCE ----------- Needless to say, running latex and post-processing the dvi to obtain a suitable image does not come cheap -- it is drastically slower than the same spec with no images at all. I wouldn't recommend throwing images into every spec just because you can. But for those cases where visual representations are clearly superior, the performance degradation is IMHO justifiable. And running without the HTML formatter does not suffer from this performance issue, but does present a less informative description. CONCLUSION ---------- I'm not married to this particular implementation, the result of a series of compromises made while trying to add this ability with few changes to RSpec. Being able to produce the output above is really what I'm after. In addition to the above, I would also like to see the ability to similarly control the output of failure messages. I have not yet attempted to implement this. I'm very interested to hear your opinions on what I've presented here. Comments? From bcardarella at gmail.com Sun Sep 13 11:05:35 2009 From: bcardarella at gmail.com (Brian Cardarella) Date: Sun, 13 Sep 2009 08:05:35 -0700 (PDT) Subject: [rspec-users] Example's scope in the matcher? Message-ID: <4f9b388e-bdf4-48db-8ea8-aeb641d631f8@t13g2000yqn.googlegroups.com> If I'm writing a matcher is there anyway to access the scope of the example from within the matcher? (something that already exists in rspec, not passing a new binding to the matcher) From dchelimsky at gmail.com Sun Sep 13 12:23:45 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 13 Sep 2009 11:23:45 -0500 Subject: [rspec-users] Example's scope in the matcher? In-Reply-To: <4f9b388e-bdf4-48db-8ea8-aeb641d631f8@t13g2000yqn.googlegroups.com> References: <4f9b388e-bdf4-48db-8ea8-aeb641d631f8@t13g2000yqn.googlegroups.com> Message-ID: <57c63afe0909130923k1f512f11m61fe8da2354e6972@mail.gmail.com> On Sun, Sep 13, 2009 at 10:05 AM, Brian Cardarella wrote: > If I'm writing a matcher is there anyway to access the scope of the > example from within the matcher? (something that already exists in > rspec, not passing a new binding to the matcher) There is nothing implicit as of yet. You _can_ wrap a matcher in a method that refs the example in such that you don't have to pass it in where it's used: def match_something scope = self Spec::Matchers::Matcher.new :match_something do match do |actual| #access scope here end end end Not exactly what you're looking for, but cleaner than having to say "thing.should somehow_match(whatever, self)" HTH, David From sfeley at gmail.com Sun Sep 13 22:10:30 2009 From: sfeley at gmail.com (Stephen Eley) Date: Sun, 13 Sep 2009 22:10:30 -0400 Subject: [rspec-users] Suggestion: a more visual RSpec In-Reply-To: <6EF00D2F-2AC1-4303-973D-FAEFFFFFFDA7@humblehacker.com> References: <6EF00D2F-2AC1-4303-973D-FAEFFFFFFDA7@humblehacker.com> Message-ID: <1fb4df0909131910i7b1fe4cdt8bf7bcc0c44242db@mail.gmail.com> On Fri, Sep 11, 2009 at 8:58 PM, David Whetstone wrote: > > I'm not married to this particular implementation, the result of a series of > compromises made while trying to add this ability with few changes to RSpec. > ?Being able to produce the output above is really what I'm after. ?In > addition to the above, I would also like to see the ability to similarly > control the output of failure messages. ?I have not yet attempted to > implement this. > > I'm very interested to hear your opinions on what I've presented here. > ?Comments? Your output example looks very very cool. It also looks very niche, however -- I'm not sure what sort of problem domain this is, but it seems to be something to do with math or formal logic, and my own background is weak enough that the graphical notation doesn't clarify anything for me at all. I don't think this is a bad idea, but it's probably useful to a small enough subset of people that doing it as an extension to RSpec (a new class of formatter instead of a hacked-up HTMLFormatter?) or a decorator *around* RSpec (i.e., translating the inputs and outputs) might make more sense than changing RSpec itself. Either way, if you intended to pursue this idea further you might want to consider developing a DSL (domain specific language) suitable for the sort of notation you want. You've kinda-sorta done that with your placeholders like "!L(fs1)!" and friends, but it's not really a *good* DSL. The actual intention has been shifted to an object method far removed from your description, and what's left isn't meaningful to humans. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From matt at mattwynne.net Mon Sep 14 05:43:42 2009 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 14 Sep 2009 10:43:42 +0100 Subject: [rspec-users] controller specs with non-RESTful routes In-Reply-To: <0a7959070e320038d584186684c70880@ruby-forum.com> References: <0a7959070e320038d584186684c70880@ruby-forum.com> Message-ID: On 11 Sep 2009, at 21:28, Giuseppe Bertini wrote: > Hello list, > this should be an easy one, but I seem to be stuck. > What is the proper way to mimic a POST request for a named, non- > RESTful > route? > > here's the route and the rest of the setup: > > map.accept_invitation '/accept_invitation/:id', :controller => > "invitations", :action => "accept", :method => "post" > > class InvitationsController < ApplicationController > def accept > end > end > > describe InvitationsController do > describe "POST 'accept'" do > it "should be successful" do > post :accept, :id => 1 > response.should be_success > end > end > end > > When I run this spec, I get: > No route matches {:controller=>"invitations", :action=>"accept", > :id=>"1"} > > Can anyone please suggest what I should be writing instead to test > this > request? Looks about right to me. Must be something silly that you've missed, but I'm afraid I can't see it. cheers, Matt +447974 430184 matt at mattwynne.net http://mattwynne.net From dchelimsky at gmail.com Mon Sep 14 05:52:08 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 14 Sep 2009 04:52:08 -0500 Subject: [rspec-users] controller specs with non-RESTful routes In-Reply-To: <0a7959070e320038d584186684c70880@ruby-forum.com> References: <0a7959070e320038d584186684c70880@ruby-forum.com> Message-ID: <57c63afe0909140252r13298a7n976662e0ca2aa43e@mail.gmail.com> On Fri, Sep 11, 2009 at 3:28 PM, Giuseppe Bertini wrote: > Hello list, > this should be an easy one, but I seem to be stuck. > What is the proper way to mimic a POST request for a named, non-RESTful > route? > > here's the route and the rest of the setup: > > map.accept_invitation '/accept_invitation/:id', :controller => > "invitations", :action => "accept", :method => "post" > > class InvitationsController < ApplicationController > ?def accept > ?end > end > > describe InvitationsController do > ?describe "POST 'accept'" do > ? ?it "should be successful" do > ? ? ?post :accept, :id => 1 > ? ? ?response.should be_success > ? ?end > ?end > end > > When I run this spec, I get: > No route matches {:controller=>"invitations", :action=>"accept", > :id=>"1"} I just fired up a brand new rails app and copied the above into config/routes.rb, app/controllers/invitations_controller.rb, and spec/controllers/invitations_controller_spec.rb, ran the spec and it passed with flying color (green). I'm using rails-2.3.4, ruby-1.8.7, rspec-1.2.8 and rspec-rails-1.2.7.1. Which versions are you using? Cheers, David > > Can anyone please suggest what I should be writing instead to test this > request? > > Thanks in advance! > Giuseppe > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Sep 14 14:32:40 2009 From: lists at ruby-forum.com (Steffen Hiller) Date: Mon, 14 Sep 2009 20:32:40 +0200 Subject: [rspec-users] After upgrade to newest TM Bundle I get "Invalid char" error Message-ID: <65513368cdc355dea3800b087e2cc2ee@ruby-forum.com> Hey, I finally upgraded from a rather old RSpec Textmate Bundle to the newest version. (master:efe49e) But when running any commands such as "Run Examples" or "Alternate File" I get: /usr/bin/ruby:1: Invalid char `\312' in expression /usr/bin/ruby:1: Invalid char `\376' in expression /usr/bin/ruby:1: Invalid char `\272' in expression /usr/bin/ruby:1: Invalid char `\276' in expression Anybody has any idea??? Using latest Textmate Version 1.5.8 (1509) and Max OS Leopard. Other Bundles still work fine. Reloaded Bundles + Restarted Textmate. Thanks! Steffen -- Posted via http://www.ruby-forum.com/. From chad.humphries at gmail.com Mon Sep 14 18:04:38 2009 From: chad.humphries at gmail.com (Chad Humphries) Date: Mon, 14 Sep 2009 18:04:38 -0400 Subject: [rspec-users] After upgrade to newest TM Bundle I get "Invalid char" error In-Reply-To: <65513368cdc355dea3800b087e2cc2ee@ruby-forum.com> References: <65513368cdc355dea3800b087e2cc2ee@ruby-forum.com> Message-ID: <964F9F03-8879-4B0D-8651-AD060EDF1C1C@gmail.com> Steffen, What ruby version do you have? i.e. /usr/bin/ruby -v -- Chad On Sep 14, 2009, at 2:32 PM, Steffen Hiller wrote: > Hey, > > I finally upgraded from a rather old RSpec Textmate Bundle to the > newest > version. (master:efe49e) > > But when running any commands such as "Run Examples" or "Alternate > File" > I get: > > /usr/bin/ruby:1: Invalid char `\312' in expression > /usr/bin/ruby:1: Invalid char `\376' in expression > /usr/bin/ruby:1: Invalid char `\272' in expression > /usr/bin/ruby:1: Invalid char `\276' in expression > > Anybody has any idea??? > > Using latest Textmate Version 1.5.8 (1509) and Max OS Leopard. > Other Bundles still work fine. Reloaded Bundles + Restarted Textmate. > > Thanks! > Steffen > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Mon Sep 14 18:10:16 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 14 Sep 2009 17:10:16 -0500 Subject: [rspec-users] After upgrade to newest TM Bundle I get "Invalid char" error In-Reply-To: <65513368cdc355dea3800b087e2cc2ee@ruby-forum.com> References: <65513368cdc355dea3800b087e2cc2ee@ruby-forum.com> Message-ID: <57c63afe0909141510j3e02ce70ka17aa2dd3b99c4c4@mail.gmail.com> On Mon, Sep 14, 2009 at 1:32 PM, Steffen Hiller wrote: > Hey, > > I finally upgraded from a rather old RSpec Textmate Bundle to the newest > version. (master:efe49e) My apologies, but the rspec bundle in the official textmate repo is quite dated. For the short term, please use the textmate bundle from github. I'll soon (ish) either get the textmate repo version up to date or ask them to eliminate it, since it's pretty easy to just get it from github. Cheers, David > > But when running any commands such as "Run Examples" or "Alternate File" > I get: > > /usr/bin/ruby:1: Invalid char `\312' in expression > /usr/bin/ruby:1: Invalid char `\376' in expression > /usr/bin/ruby:1: Invalid char `\272' in expression > /usr/bin/ruby:1: Invalid char `\276' in expression > > Anybody has any idea??? > > Using latest Textmate Version 1.5.8 (1509) and Max OS Leopard. > Other Bundles still work fine. Reloaded Bundles + Restarted Textmate. > > Thanks! > Steffen > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Sep 14 20:45:22 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 14 Sep 2009 19:45:22 -0500 Subject: [rspec-users] [ANN] rspec and rspec-rails 1.2.9.rc1 Released Message-ID: <57c63afe0909141745w658307bbyde59fa132f85a1c5@mail.gmail.com> rspec and rspec-rails version 1.2.9.rc1 have been released! =========================================================== We're using the new rubygems prerelease feature to do proper release candidates. This feature was introduced to rubygems a couple of versions back, but I'd recommend updating to rubygems-1.3.5 before installing the rspec prerelease gems. For those unfamiliar with this new rubygems feature, you have to add the --prerelease flat in order to see and install these gems: $ gem search --remote --prerelease rspec *** REMOTE GEMS *** rspec (1.2.9.rc1) rspec-rails (1.2.9.rc1) $ [sudo] gem install --prerelease rspec $ [sudo] gem install --prerelease rspec-rails This way only those who choose to install the prerelease gems will get them, while those who exclude the --prerelease flag will get the previous final release (rspec-1.2.8, rspec-rails-1.2.7.1). Once you install the prerelease gems, Rubygems will treat 1.2.9.rc1 as a higher version than 1.2.8, but a lower version than 1.2.9. That way when we do the final release you'll be able to just install 1.2.9 and it will take its rightful place ahead of 1.2.9.rc1 without you having to uninstall rc1. I invite you to install these prerelease gems and report any issues you run into to http://rspec.lighthouseapp.com/rspec. Advanced thanks to those who help the rest by breaking these in. Cheers, David =========================================================== Behaviour Driven Development for Ruby and Ruby on Rails ### rspec-1.2.9-rc1 * enhancements * manage backtrace-ignore patterns with Spec::Runner.configure (Martin Emde). Closes #870. * friendly mock argument expectation failure message (Tim Harper). Closes #868. * added double() as alias for stub() and mock() * failure messages for doubles, mocks and stubs use the right name * add let() method to assign memoized attributes (suggestion from Stuart Halloway). Closes #857. * add its method so you can say: describe Array do its(:length) { should == 0 } (Stephen Touset). Closes #833 * spec command automatically uses spec/spec.opts if it is present (suggestion from Yehuda Katz) * rspec now adds PROJECT_ROOT/lib and PROJECT_ROOT/spec to the load path * determines PROJECT_ROOT by recursing up until it finds a directory that has a ./spec directory (thanks to Scott Taylor) * supports require 'spec_helper' * supports running specs from the PROJECT_ROOT or any directory below it * closes #733 * not really a bug fix or enhancement * temporarily moved heckle feature to features-pending (waiting to see what happens with http://rubyforge.org/tracker/index.php?func=detail&aid=26786&group_id=1513&atid=5921) ### rspec-rails-1.2.9-rc1 * enhancements * added route_to and be_routable matchers (Randy Harmon). Closes #843. * Provide better failure message for render_template when redirected (Josh Nichols). Closes #885. * generated specs require 'spec_helper' * bug fixes * pass the correct args to super in controller#render depending on the rails version (Lucas Carlson). Closes #865. * use Rack::Utils.parse_query to convert query strings to hashes. Closes #872. * errors correctly bubble up when a controller spec in isolation mode requests a non-existent action/template * no error if either action or template exist * error if neither exist * Closes #888. * removals * spec_server has been removed in favor of spork. * You can still use the --drb flag, but you've got to install the spork gem. * Windows users who cannot use the spork gem can install the spec_server from * http://github.com/dchelimsky/spec_server * * * * * * * From tmp008 at allproducts.info Tue Sep 15 15:12:05 2009 From: tmp008 at allproducts.info (Anton Trapp) Date: Tue, 15 Sep 2009 12:12:05 -0700 (PDT) Subject: [rspec-users] Halting rake rspec Message-ID: <25459998.post@talk.nabble.com> Short question: How can I stop a rspec rake task without having to wait for about 5 minutes (1 ctrl-c keypress autorepeat for every test case)? -- View this message in context: http://www.nabble.com/Halting-rake-rspec-tp25459998p25459998.html Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Tue Sep 15 15:36:24 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 15 Sep 2009 14:36:24 -0500 Subject: [rspec-users] Halting rake rspec In-Reply-To: <25459998.post@talk.nabble.com> References: <25459998.post@talk.nabble.com> Message-ID: <57c63afe0909151236o4aedff13x49fe6568d02cf196@mail.gmail.com> Right now there is no way. Please file a feature request at http://rspec.lighthouseapp.com. Cheers, David On Tue, Sep 15, 2009 at 2:12 PM, Anton Trapp wrote: > > Short question: How can I stop a rspec rake task without having to wait for > about 5 minutes (1 ctrl-c keypress autorepeat for every test case)? > -- > View this message in context: http://www.nabble.com/Halting-rake-rspec-tp25459998p25459998.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sfeley at gmail.com Tue Sep 15 15:42:00 2009 From: sfeley at gmail.com (Stephen Eley) Date: Tue, 15 Sep 2009 15:42:00 -0400 Subject: [rspec-users] Halting rake rspec In-Reply-To: <25459998.post@talk.nabble.com> References: <25459998.post@talk.nabble.com> Message-ID: <1fb4df0909151242m3ea2f588t2f230075df292dcb@mail.gmail.com> On Tue, Sep 15, 2009 at 3:12 PM, Anton Trapp wrote: > > Short question: How can I stop a rspec rake task without having to wait for > about 5 minutes (1 ctrl-c keypress autorepeat for every test case)? 1. ps ax | grep rake 2. (look at the process id in the lefthand column) 3. kill -9 [process id] >8-> -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From chris.webstar at gmail.com Tue Sep 15 20:21:20 2009 From: chris.webstar at gmail.com (Chris Hoeppner) Date: Wed, 16 Sep 2009 01:21:20 +0100 Subject: [rspec-users] Halting rake rspec In-Reply-To: <1fb4df0909151242m3ea2f588t2f230075df292dcb@mail.gmail.com> References: <25459998.post@talk.nabble.com> <1fb4df0909151242m3ea2f588t2f230075df292dcb@mail.gmail.com> Message-ID: <4AB02F80.2060104@gmail.com> Unix always has an answer =) Stephen Eley escribi?: > On Tue, Sep 15, 2009 at 3:12 PM, Anton Trapp wrote: > >> Short question: How can I stop a rspec rake task without having to wait for >> about 5 minutes (1 ctrl-c keypress autorepeat for every test case)? >> > > 1. ps ax | grep rake > 2. (look at the process id in the lefthand column) > 3. kill -9 [process id] > > >> 8-> >> From ben at benmabey.com Tue Sep 15 20:51:13 2009 From: ben at benmabey.com (Ben Mabey) Date: Tue, 15 Sep 2009 18:51:13 -0600 Subject: [rspec-users] Problems while loading 'spec/stubs/cucumber' In-Reply-To: References: Message-ID: <4AB03681.3070809@benmabey.com> Rodrigo Flores wrote: > Hi > > I'm reading the rspec book and I'm having problems when I require the > file 'spec/stubs/cucumber'. When I go to an IRB prompt and type > require 'spec/stubs/cucumber' after requiring another libraries [1] I > get the false in 'spec/expectations' and an error in > 'spec/stubs/cucumber'. The error message is [2]. Any ideas? I'm using > rspec 1.2.8. > > > Thanks in advance > > > > > [1] > > require 'rubygems' > require 'spec' > require 'spec/expectations' > require 'spec/stubs/cucumber' > > [2] > NoMethodError: undefined method `Before' for main:Object > from > /home/rodrigo/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/stubs/cucumber.rb:3 > from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in > `gem_original_require' > from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in > `require' > from (irb):9 > from :0 > That file is only meant to be used when running Cucumber. So you would place the require in your features/support/env.rb file for example. Without having Cucumber loaded first the Before method will not be defined and the above error is expected. If you are just wanting to play around with rspec matchers in IRB then the top three requires is all you will need. So, you could say: require 'rubygems' require 'spec' require 'spec/expectations' 42.should == 42 HTH, Ben From dchelimsky at gmail.com Tue Sep 15 20:55:24 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 15 Sep 2009 19:55:24 -0500 Subject: [rspec-users] Problems while loading 'spec/stubs/cucumber' In-Reply-To: <4AB03681.3070809@benmabey.com> References: <4AB03681.3070809@benmabey.com> Message-ID: <57c63afe0909151755k3867c70eid2531f7c25a7cd1b@mail.gmail.com> On Tue, Sep 15, 2009 at 7:51 PM, Ben Mabey wrote: > Rodrigo Flores wrote: >> >> Hi >> >> I'm reading the rspec book and I'm having problems when I require the file >> 'spec/stubs/cucumber'. When I go to an IRB prompt and type require >> 'spec/stubs/cucumber' after requiring another libraries [1] I get the false >> in 'spec/expectations' and an error in 'spec/stubs/cucumber'. The error >> message is [2]. Any ideas? I'm using rspec 1.2.8. >> >> >> Thanks in advance >> >> >> >> >> [1] >> >> require 'rubygems' >> require 'spec' >> require 'spec/expectations' >> require 'spec/stubs/cucumber' >> >> [2] >> NoMethodError: undefined method `Before' for main:Object >> from >> /home/rodrigo/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/stubs/cucumber.rb:3 >> from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in >> `gem_original_require' >> from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in >> `require' >> from (irb):9 >> from :0 >> > > That file is only meant to be used when running Cucumber. ?So you would > place the require in your features/support/env.rb file for example. ?Without > having Cucumber loaded first the Before method will not be defined and the > above error is expected. > > If you are just wanting to play around with rspec matchers in IRB then the > top three requires is all you will need. ?So, you could say: > > require 'rubygems' > require 'spec' > require 'spec/expectations' > > 42.should == 42 FYI - if you want access to all the matchers: require 'rubygems' require 'spec/expectations' include Spec::Matchers 42.should be(42) > > HTH, > Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tmp008 at allproducts.info Wed Sep 16 01:01:45 2009 From: tmp008 at allproducts.info (Anton Trapp) Date: Tue, 15 Sep 2009 22:01:45 -0700 (PDT) Subject: [rspec-users] Halting rake rspec In-Reply-To: <25459998.post@talk.nabble.com> References: <25459998.post@talk.nabble.com> Message-ID: <25465982.post@talk.nabble.com> Thank you for both answers! -- View this message in context: http://www.nabble.com/Halting-rake-rspec-tp25459998p25465982.html Sent from the rspec-users mailing list archive at Nabble.com. From tmp008 at allproducts.info Wed Sep 16 01:04:52 2009 From: tmp008 at allproducts.info (Anton Trapp) Date: Tue, 15 Sep 2009 22:04:52 -0700 (PDT) Subject: [rspec-users] How to report rspec bugs in lighthouse? Message-ID: <25466003.post@talk.nabble.com> http://rspec.lighthouseapp.com -> Sign up -> The page at signup was not found Where is the bug tracker for lighthouse and hopefully lighthouse is not used to track the bugs ;) -- View this message in context: http://www.nabble.com/How-to-report-rspec-bugs-in-lighthouse--tp25466003p25466003.html Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Wed Sep 16 01:08:26 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 16 Sep 2009 00:08:26 -0500 Subject: [rspec-users] How to report rspec bugs in lighthouse? In-Reply-To: <25466003.post@talk.nabble.com> References: <25466003.post@talk.nabble.com> Message-ID: <57c63afe0909152208x2075db5aq62d455f6ce271ff2@mail.gmail.com> On Wed, Sep 16, 2009 at 12:04 AM, Anton Trapp wrote: > > http://rspec.lighthouseapp.com -> Sign up -> The page at signup was not found > > Where is the bug tracker for lighthouse and hopefully lighthouse is not used > to track the bugs ;) http://help.lighthouseapp.com/ HTH, David From tmp008 at allproducts.info Wed Sep 16 02:06:28 2009 From: tmp008 at allproducts.info (Anton Trapp) Date: Tue, 15 Sep 2009 23:06:28 -0700 (PDT) Subject: [rspec-users] How to report rspec bugs in lighthouse? In-Reply-To: <57c63afe0909152208x2075db5aq62d455f6ce271ff2@mail.gmail.com> References: <25466003.post@talk.nabble.com> <57c63afe0909152208x2075db5aq62d455f6ce271ff2@mail.gmail.com> Message-ID: <25466484.post@talk.nabble.com> Thanks! Didn't thought that the registration works there ;) David Chelimsky-2 wrote: > > On Wed, Sep 16, 2009 at 12:04 AM, Anton Trapp > wrote: >> >> http://rspec.lighthouseapp.com -> Sign up -> The page at signup was not >> found >> >> Where is the bug tracker for lighthouse and hopefully lighthouse is not >> used >> to track the bugs ;) > > http://help.lighthouseapp.com/ > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -- View this message in context: http://www.nabble.com/How-to-report-rspec-bugs-in-lighthouse--tp25466003p25466484.html Sent from the rspec-users mailing list archive at Nabble.com. From ramon.tayag at gmail.com Wed Sep 16 04:34:41 2009 From: ramon.tayag at gmail.com (Ramon Tayag) Date: Wed, 16 Sep 2009 16:34:41 +0800 Subject: [rspec-users] Expectation test: error says it's different, but it's printed the same way Message-ID: I put an expectation test, but it complains two things are different when it prints it out in the error in the exact same way: http://pastie.org/618481 or below: ## the test describe ".process_aftersale" do before do @orders = [Order.make, Order.make] Order.stub!(:paid).and_return(@orders) @orders.stub!(:updated_on).and_return(@orders) end .... it "should send 1 week after sale letters" do @orders.should_receive(:updated_on).once.with([1.week.ago]) Order.process_aftersale end ... end ## The error - note that the dates are the same 1) Spec::Mocks::MockExpectationError in 'Order.process_aftersale should send 1 week after sale letters' ## expected :updated_on with ([Wed, 09 Sep 2009 14:59:59 HKT +08:00]) but received it with ([Wed, 09 Sep 2009 14:59:59 HKT +08:00]) ./spec/models/order_spec.rb:42: ## the method in Order def self.process_aftersale self.paid.updated_on(1.week.ago).each do |o| MailingsWorker.asynch_deliver_order_aftersale_to_inquire(:order_id => o.id) end end ============== I may be doing things wrong, so please let me know if I am. Thanks! Ramon Tayag From dchelimsky at gmail.com Wed Sep 16 09:08:20 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 16 Sep 2009 08:08:20 -0500 Subject: [rspec-users] Expectation test: error says it's different, but it's printed the same way In-Reply-To: References: Message-ID: <57c63afe0909160608sc269c44y669df962df08a65d@mail.gmail.com> On Wed, Sep 16, 2009 at 3:34 AM, Ramon Tayag wrote: > I put an expectation test, but it complains two things are different > when it prints it out in the error in the exact same way: > http://pastie.org/618481 Printing is printing. Time is _not_ time. The problem is that the times are off by milliseconds that aren't accounted for in time.to_s. The usual solution is to either stub Time.now or introduce a time generator, but you're not using Time.now, so that won't work. Options include: 1. examine the submitted argument directly @orders.should_receive(:updated_on) do |actual| expected = 1.week.ago.to_i actual.to_i.should be_between(expected - 1000, expected) end That will expect the time within 1 second of 1.week.ago. 2. introduce a custom argument matcher class Roughly def initialize(expected) @expected = expected.to_i end def ==(actual) actual.to_i.between?(@expected - 1000, @expected) end end def roughly(expected) Roughly.new(expected) end @orders.should_receive(:updated_on).with(roughly(1.week.ago)) And for extra credit, you can even make this one more flexible and provide a lower and upper bound using a fluent interface: @orders.should_receive(:updated_on).with(within(1.second).of(1.week.ago)) HTH, David > > or below: > > ## the test > ?describe ".process_aftersale" do > ? ?before do > ? ? ?@orders = [Order.make, Order.make] > ? ? ?Order.stub!(:paid).and_return(@orders) > ? ? ?@orders.stub!(:updated_on).and_return(@orders) > ? ?end > > ? ?.... > > ? ?it "should send 1 week after sale letters" do > ? ? ?@orders.should_receive(:updated_on).once.with([1.week.ago]) > ? ? ?Order.process_aftersale > ? ?end > > ? ?... > ?end > > ## The error - note that the dates are the same > 1) > Spec::Mocks::MockExpectationError in 'Order.process_aftersale should > send 1 week after sale letters' > ## expected :updated_on with > ([Wed, 09 Sep 2009 14:59:59 HKT +08:00]) but received it with ([Wed, > 09 Sep 2009 14:59:59 HKT +08:00]) > ./spec/models/order_spec.rb:42: > > > ## the method in Order > ?def self.process_aftersale > ? ?self.paid.updated_on(1.week.ago).each do |o| > ? ? ?MailingsWorker.asynch_deliver_order_aftersale_to_inquire(:order_id > => o.id) > ? ?end > ?end > > ============== > > I may be doing things wrong, so please let me know if I am. > > Thanks! > Ramon Tayag > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jbrainsberger at gmail.com Wed Sep 16 13:59:18 2009 From: jbrainsberger at gmail.com (J. B. Rainsberger) Date: Wed, 16 Sep 2009 12:59:18 -0500 Subject: [rspec-users] Expectation test: error says it's different, but it's printed the same way In-Reply-To: <57c63afe0909160608sc269c44y669df962df08a65d@mail.gmail.com> References: <57c63afe0909160608sc269c44y669df962df08a65d@mail.gmail.com> Message-ID: <578E30FC-B6A0-46BF-B1B3-DAF498CEF710@gmail.com> On 2009-09-16, at 08:08 , David Chelimsky wrote: > On Wed, Sep 16, 2009 at 3:34 AM, Ramon Tayag > wrote: >> I put an expectation test, but it complains two things are different >> when it prints it out in the error in the exact same way: >> http://pastie.org/618481 > > Printing is printing. Time is _not_ time. The problem is that the > times are off by milliseconds that aren't accounted for in time.to_s. > > The usual solution is to either stub Time.now or introduce a time > generator, but you're not using Time.now, so that won't work. Options > include: > > 1. examine the submitted argument directly > > @orders.should_receive(:updated_on) do |actual| > expected = 1.week.ago.to_i > actual.to_i.should be_between(expected - 1000, expected) > end > > That will expect the time within 1 second of 1.week.ago. > > 2. introduce a custom argument matcher > > class Roughly > def initialize(expected) > @expected = expected.to_i > end > > def ==(actual) > actual.to_i.between?(@expected - 1000, @expected) > end > end > > def roughly(expected) > Roughly.new(expected) > end > > @orders.should_receive(:updated_on).with(roughly(1.week.ago)) > > And for extra credit, you can even make this one more flexible and > provide a lower and upper bound using a fluent interface: > > @orders.should_receive(:updated_on).with(within(1.second).of > (1.week.ago)) I highly recommend a small refactoring to increase the clarity of your code and reduce the coupling with the system clock. I posted my suggestion at http://pastie.org/619142. By doing this, you make it easy to stub/expect @orders in your #process_aftersale test, and make it easy to test #ready_for_aftersale_letter without wanting to use a stub or mock. To test #ready_for_aftersale_letter, simply use 1.week.ago, 8.days.ago and 6.days.ago as your test cases. Noticing this, you probably want to try 7.days.ago + 1.millisecond and make sure that behaves the way you'd expect, because you probably want to ensure that you use 1.week.ago.at_midnight, and not just 1.week.ago. Question: if I buy from you on September 15, 2009 at 17:50, when is my order ready for an aftersale letter? (a) September 22, 2009 at 17:50, (b) September 22, 2009 at 00:00, (c) September 22, 2009 at 09:00, (d) September 23, 2009 at 00:00, or some other time entirely? Write a test for that. Take care. ---- J. B. (Joe) Rainsberger :: http://www.jbrains.ca Your guide to software craftsmanship JUnit Recipes: Practical Methods for Programmer Testing 2005 Gordon Pask Award for contributions to Agile Software Practice From jonathan at linowes.com Wed Sep 16 17:36:51 2009 From: jonathan at linowes.com (Jonathan Linowes) Date: Wed, 16 Sep 2009 17:36:51 -0400 Subject: [rspec-users] turning on observers Message-ID: hi, I'm trying to run specs for an observer thats included with a plugin. There's no guarantee the app has set the observer in its environment.rb. I'm presently doing this but expect there's a more elegant solution unless ActiveRecord::Base.observers.include? :subscription_observer puts "Cannot run specs on SubscriptionObserver. Please add the following to environment.rb" puts " config.active_record.observers = :subscription_observer" else describe SubscriptionObserver do ... end end By the way, I did try enabling the observer for the duration of the spec but that didnt work, eg before :all do ActiveRecord::Base.observers = [:subscription_observer] end thx --linoj From enrico.teotti at gmail.com Thu Sep 17 22:33:16 2009 From: enrico.teotti at gmail.com (Enrico Teotti) Date: Fri, 18 Sep 2009 12:33:16 +1000 Subject: [rspec-users] params_for and :requirements from DB Message-ID: Hi, I have a named route with a requirement generated from database (MyModel.valid_values query returns /my_value_foo/): route.my_named_route 'my-controller/:my_value', :action => "my_action", :requirements => { :my_value => MyModel.valid_values } but the test: params_from(:get, "/my-controller/my_value_foo").should == {:controller => "my_controller", :action => "my_action", :my_value => "my_value_foo"} returns a "No route matches"... I checked in the test that MyModel.valid_values is returning what I expect, so I can't think of why it's failing. Any tips? In the browser the route works fine. Cheers, Enrico From hayafirst at gmail.com Fri Sep 18 11:42:42 2009 From: hayafirst at gmail.com (Yi Wen) Date: Fri, 18 Sep 2009 10:42:42 -0500 Subject: [rspec-users] predicate matching Message-ID: Hi all, I noticed that if I have a method named has_somthing? and I do: object.should_not have_somthing and it failed (as expected) when the method returns nil. But if the method is something? and I do: object.should_not be_something, and it succeeded (not what I expected) when something? returns nil Is this intended behavior or something I did was wrong? Thanks Yi From dchelimsky at gmail.com Fri Sep 18 12:06:26 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 18 Sep 2009 11:06:26 -0500 Subject: [rspec-users] predicate matching In-Reply-To: References: Message-ID: <57c63afe0909180906p3bc270eg43672e463d9c2c62@mail.gmail.com> On Fri, Sep 18, 2009 at 10:42 AM, Yi Wen wrote: > Hi all, > > I noticed that if I have a method named has_somthing? and I do: > object.should_not have_somthing and it failed (as expected) when the method > returns nil. Actually, this should pass. The have_xxx and be_xxx matchers should pass/fail based on truthiness, not true/false explicitly. For example: >> require 'ostruct' => true >> require 'spec/expectations' => true >> include Spec::Matchers => Object >> obj = OpenStruct.new(:has_foo? => nil) => # >> obj.has_foo? => nil >> obj.should_not have_foo => nil >> obj.should have_foo Spec::Expectations::ExpectationNotMetError: expected #has_foo?(nil) to return true, got false The message is admittedly wrong (should say "got nil" at the end, or something else entirely), but the pass/fail is correct. So it sounds like you're experiencing a bug of some kind on the has_xxx matcher, not the be_xxx matcher, which is appears to be behaving correctly based on what you wrote below. Please file a bug if you can provide an example that I can run that I can see behaving incorrectly. HTH, David > > But if the method is something? and I do: > object.should_not be_something, and it succeeded (not what I expected) when > something? returns nil > > Is this intended behavior or something I did was wrong? Thanks > > Yi > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From hayafirst at gmail.com Fri Sep 18 11:48:36 2009 From: hayafirst at gmail.com (Yi Wen) Date: Fri, 18 Sep 2009 10:48:36 -0500 Subject: [rspec-users] predicate matching In-Reply-To: References: Message-ID: Sorry for the spam, but I was wrong: the *should_not have_something* also passed when the method returned nil. On Sep 18, 2009, at 10:42 AM, Yi Wen wrote: > Hi all, > > I noticed that if I have a method named has_somthing? and I do: > object.should_not have_somthing and it failed (as expected) when the > method returns nil. > > But if the method is something? and I do: > object.should_not be_something, and it succeeded (not what I > expected) when something? returns nil > > Is this intended behavior or something I did was wrong? Thanks > > Yi From hayafirst at gmail.com Fri Sep 18 12:31:07 2009 From: hayafirst at gmail.com (Yi Wen) Date: Fri, 18 Sep 2009 11:31:07 -0500 Subject: [rspec-users] predicate matching In-Reply-To: <57c63afe0909180906p3bc270eg43672e463d9c2c62@mail.gmail.com> References: <57c63afe0909180906p3bc270eg43672e463d9c2c62@mail.gmail.com> Message-ID: <4E81939F-BD6C-4FCE-9149-6181190481F9@gmail.com> Ok, I guess in reality it will never make a difference if a predicate returns a nil or a false. The behavior annoys me a little bit when I write a test that passes when the method itself does nothing (so that it returns nil). Any thoughts? Thanks Yi On Sep 18, 2009, at 11:06 AM, David Chelimsky wrote: > On Fri, Sep 18, 2009 at 10:42 AM, Yi Wen wrote: >> Hi all, >> >> I noticed that if I have a method named has_somthing? and I do: >> object.should_not have_somthing and it failed (as expected) when >> the method >> returns nil. > > Actually, this should pass. The have_xxx and be_xxx matchers should > pass/fail based on truthiness, not true/false explicitly. For example: > >>> require 'ostruct' > => true >>> require 'spec/expectations' > => true >>> include Spec::Matchers > => Object >>> obj = OpenStruct.new(:has_foo? => nil) > => # >>> obj.has_foo? > => nil >>> obj.should_not have_foo > => nil >>> obj.should have_foo > Spec::Expectations::ExpectationNotMetError: expected #has_foo?(nil) to > return true, got false > > The message is admittedly wrong (should say "got nil" at the end, or > something else entirely), but the pass/fail is correct. > > So it sounds like you're experiencing a bug of some kind on the > has_xxx matcher, not the be_xxx matcher, which is appears to be > behaving correctly based on what you wrote below. Please file a bug if > you can provide an example that I can run that I can see behaving > incorrectly. > > HTH, > David > > > > >> >> But if the method is something? and I do: >> object.should_not be_something, and it succeeded (not what I >> expected) when >> something? returns nil >> >> Is this intended behavior or something I did was wrong? Thanks > > > > >> >> Yi >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.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 Sep 18 12:41:32 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 18 Sep 2009 11:41:32 -0500 Subject: [rspec-users] predicate matching In-Reply-To: <4E81939F-BD6C-4FCE-9149-6181190481F9@gmail.com> References: <57c63afe0909180906p3bc270eg43672e463d9c2c62@mail.gmail.com> <4E81939F-BD6C-4FCE-9149-6181190481F9@gmail.com> Message-ID: <57c63afe0909180941o3b659541ue90bdbbbce00ec84@mail.gmail.com> On Fri, Sep 18, 2009 at 11:31 AM, Yi Wen wrote: > Ok, I guess in reality it will never make a difference if a predicate > returns a nil or a false. > > The behavior annoys me a little bit when I write a test that passes when the > method itself does nothing (so that it returns nil). Any thoughts? Remember that each example runs _in a context_. Any one example need not tell the whole story, but a mere part of it. If an example says "thing.should_not have_foo" and thing#has_foo? doesn't do anything, then that's all the implementation that is necessary for _that example_ to pass. But that shouldn't be the only example. Consider: describe Thing do context "without foo" do it "says it does not have foo" do thing = Thing.new thing.should_not have_foo end end context "with foo" do it "says it has foo" do thing = Thing.new.with_foo thing.should have_foo end end end The first example will pass with an empty #has_foo? method, but the second one won't. Together they tell a more complete story. If, considering the above, this continues to bother you, then write an explicit example: thing.has_xxx?.should_not == nil HTH, David > > Thanks > > Yi > > > On Sep 18, 2009, at 11:06 AM, David Chelimsky wrote: > >> On Fri, Sep 18, 2009 at 10:42 AM, Yi Wen wrote: >>> >>> Hi all, >>> >>> I noticed that if I have a method named has_somthing? and I do: >>> object.should_not have_somthing and it failed (as expected) when the >>> method >>> returns nil. >> >> Actually, this should pass. The have_xxx and be_xxx matchers should >> pass/fail based on truthiness, not true/false explicitly. For example: >> >>>> require 'ostruct' >> >> => true >>>> >>>> require 'spec/expectations' >> >> => true >>>> >>>> include Spec::Matchers >> >> => Object >>>> >>>> obj = OpenStruct.new(:has_foo? => nil) >> >> => # >>>> >>>> obj.has_foo? >> >> => nil >>>> >>>> obj.should_not have_foo >> >> => nil >>>> >>>> obj.should have_foo >> >> Spec::Expectations::ExpectationNotMetError: expected #has_foo?(nil) to >> return true, got false >> >> The message is admittedly wrong (should say "got nil" at the end, or >> something else entirely), but the pass/fail is correct. >> >> So it sounds like you're experiencing a bug of some kind on the >> has_xxx matcher, not the be_xxx matcher, which is appears to be >> behaving correctly based on what you wrote below. Please file a bug if >> you can provide an example that I can run that I can see behaving >> incorrectly. >> >> HTH, >> David >> >> >> >> >>> >>> But if the method is something? and I do: >>> object.should_not be_something, and it succeeded (not what I expected) >>> when >>> something? returns nil >>> >>> Is this intended behavior or something I did was wrong? Thanks >> >> >> >> >>> >>> Yi >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Fri Sep 18 10:25:13 2009 From: lists at ruby-forum.com (Jorge Martin) Date: Fri, 18 Sep 2009 16:25:13 +0200 Subject: [rspec-users] Incompatible version? Message-ID: <3a5466acf1e40b1cf9690dbc55db8285@ruby-forum.com> I'm trying to use Rspe but I have this message error: undefined method `evaluate_value_proc' for class `Spec::Matchers::Change' (NameError) _______________________________________________ I have this gems: rspec 1.2.8, 1.1.12 rspec-rails 2.3.7.2, 2.2.12 cucumber 0.3.101, 0.3.100 _______________________________________________ Is there a incompatible version bettwen rspec and rspec-rails? Thanks a lot. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Sep 18 14:41:02 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 18 Sep 2009 13:41:02 -0500 Subject: [rspec-users] Incompatible version? In-Reply-To: <3a5466acf1e40b1cf9690dbc55db8285@ruby-forum.com> References: <3a5466acf1e40b1cf9690dbc55db8285@ruby-forum.com> Message-ID: <57c63afe0909181141j2106274k81a7be15e01a2a42@mail.gmail.com> On Fri, Sep 18, 2009 at 9:25 AM, Jorge Martin wrote: > I'm trying to use Rspe but I have this message error: > > undefined method `evaluate_value_proc' for class > `Spec::Matchers::Change' (NameError) > _______________________________________________ > > I have this gems: > > rspec ? ? ? 1.2.8, ? 1.1.12 > rspec-rails 2.3.7.2, 2.2.12 Not sure where you got these from but the current rspec-rails release is 1.2.7.1. > cucumber ? ?0.3.101, 0.3.100 > > _______________________________________________ > > > Is there a incompatible version bettwen rspec and rspec-rails? > Thanks a lot. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nick.rutherford at gmail.com Sun Sep 20 10:38:37 2009 From: nick.rutherford at gmail.com (nruth) Date: Sun, 20 Sep 2009 07:38:37 -0700 (PDT) Subject: [rspec-users] describe block proc parameter as alternative to before blocks? Message-ID: I've been reading through the Rspec book to see if I missed any tricks, and the discussion of before block use for context setup in sec 12.6 struck me as interesting and something I had a knee-jerk reaction to. I think that when you are using nested examples to describe a context change it is bad practice to allow any example within that group to run outside of that context. This could happen simply because you forgot to copy and paste (ouch) the setup code into your expectation. before blocks solve this problem, but they are so tightly coupled to the describe call in this case, why not make them a describe method parameter? Ideally they would be the block passed to describe, but we can't do that since the example group is using that already. So I would propose something like this sketch: describe "a new capacity 10 stack", :context => lambda {@stack = Stack.new(:capacity => 10)} do describe "with 4 pushed ints", :context => lambda { 4.times { @stack << rand(:int) } } do it "should allow push and return the new size" do @stack.push(rand(:int)).should == 5 end end end And the :context would just be executed as if it were a before block. Of course you can arrange your specs so that the before block is directly after the describe, or similar, but this seems a nice alternative to me. It's a nubile idea though. Thoughts? From dchelimsky at gmail.com Sun Sep 20 16:56:15 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 20 Sep 2009 15:56:15 -0500 Subject: [rspec-users] describe block proc parameter as alternative to before blocks? In-Reply-To: References: Message-ID: <57c63afe0909201356r7b56dd6auadf8a9e72ff911a8@mail.gmail.com> On Sun, Sep 20, 2009 at 9:38 AM, nruth wrote: > I've been reading through the Rspec book to see if I missed any > tricks, and the discussion of before block use for context setup in > sec 12.6 struck me as interesting and something I had a knee-jerk > reaction to. > > I think that when you are using nested examples to describe a context > change it is bad practice to allow any example within that group to > run outside of that context. This could happen simply because you > forgot to copy and paste (ouch) the setup code into your expectation. > > before blocks solve this problem, but they are so tightly coupled to > the describe call in this case, why not make them a describe method > parameter? Ideally they would be the block passed to describe, but we > can't do that since the example group is using that already. > > So I would propose something like this sketch: > > describe "a new capacity 10 stack", :context => lambda {@stack = > Stack.new(:capacity => 10)} do > ?describe "with 4 pushed ints", :context => lambda { 4.times { @stack > << rand(:int) } } do > ? ?it "should allow push and return the new size" do > ? ? ?@stack.push(rand(:int)).should == 5 > ? ?end > ?end > end > > And the :context would just be executed as if it were a before block. > > Of course you can arrange your specs so that the before block is > directly after the describe, or similar, but this seems a nice > alternative to me. The order of the before blocks, relative to the examples, is irrelevant. An example group loads up all of its examples and before and after blocks before anything is run. In other words, these two will have the same effect: describe Thing do before(:each) { @thing = Thing.new } it "does something" do @thing.should do_something end end describe Thing do it "does something" do @thing.should do_something end before(:each) { @thing = Thing.new } end This is not the first time your idea has come up, and I've not included it before because I want to avoid assigning specific meaning to keys in the hash passed to describe(). rspec-2 will be using that hash as part of a plugin API, so the more I can leave available, the better. I'll be posting more about that soon, but first things first - gotta get the book off to the printer :) Cheers, David > > It's a nubile idea though. Thoughts? From nick.rutherford at gmail.com Sun Sep 20 21:34:23 2009 From: nick.rutherford at gmail.com (nruth) Date: Sun, 20 Sep 2009 18:34:23 -0700 (PDT) Subject: [rspec-users] describe block proc parameter as alternative to before blocks? In-Reply-To: <57c63afe0909201356r7b56dd6auadf8a9e72ff911a8@mail.gmail.com> References: <57c63afe0909201356r7b56dd6auadf8a9e72ff911a8@mail.gmail.com> Message-ID: <16c60ac5-528d-41c7-a431-d636fdcddb48@p36g2000vbn.googlegroups.com> David Thanks for the reply. I think I wasn't clear with my original post: before blocks work fine, this is just a readability/comprehension/maintenance concern. We're using a describe (or context) block to name (or document) a state, then using a separate before block to set up that state (context). If that before block were to go astray the documentation would cease to be correct. It seems better to have this done in one place rather than two, as separate description statements and setup code could lead to confusion or errors through fragmented example groups. I'm not sure how helpful it would be if the setup takes more than half a line of code. Referencing a definition elsewhere wouldn't help readability, though would still make it clear that the describe was for that particular setup state. Before blocks do have the same effect, and if positioned sensibly should avoid these problems. It's not a big deal, and the onus should probably be on the spec author rather than the tools to produce clean and consistent specs? I'm not surprised it's come up before, but I didn't find anything searching the group. Cheers Nick On Sep 20, 9:56?pm, David Chelimsky wrote: > On Sun, Sep 20, 2009 at 9:38 AM, nruth wrote: > > I've been reading through the Rspec book to see if I missed any > > tricks, and the discussion of before block use for context setup in > > sec 12.6 struck me as interesting and something I had a knee-jerk > > reaction to. > > > I think that when you are using nested examples to describe a context > > change it is bad practice to allow any example within that group to > > run outside of that context. This could happen simply because you > > forgot to copy and paste (ouch) the setup code into your expectation. > > > before blocks solve this problem, but they are so tightly coupled to > > the describe call in this case, why not make them a describe method > > parameter? Ideally they would be the block passed to describe, but we > > can't do that since the example group is using that already. > > > So I would propose something like this sketch: > > > describe "a new capacity 10 stack", :context => lambda {@stack = > > Stack.new(:capacity => 10)} do > > ?describe "with 4 pushed ints", :context => lambda { 4.times { @stack > > << rand(:int) } } do > > ? ?it "should allow push and return the new size" do > > ? ? ?@stack.push(rand(:int)).should == 5 > > ? ?end > > ?end > > end > > > And the :context would just be executed as if it were a before block. > > > Of course you can arrange your specs so that the before block is > > directly after the describe, or similar, but this seems a nice > > alternative to me. > > The order of the before blocks, relative to the examples, is > irrelevant. An example group loads up all of its examples and before > and after blocks before anything is run. In other words, these two > will have the same effect: > > describe Thing do > ? before(:each) { @thing = Thing.new } > ? it "does something" do > ? ? @thing.should do_something > ? end > end > > describe Thing do > ? it "does something" do > ? ? @thing.should do_something > ? end > ? before(:each) { @thing = Thing.new } > end > > This is not the first time your idea has come up, and I've not > included it before because I want to avoid assigning specific meaning > to keys in the hash passed to describe(). rspec-2 will be using that > hash as part of a plugin API, so the more I can leave available, the > better. I'll be posting more about that soon, but first things first - > gotta get the book off to the printer :) > > Cheers, > David > > > > > It's a nubile idea though. Thoughts? > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From nick.rutherford at gmail.com Sun Sep 20 21:50:17 2009 From: nick.rutherford at gmail.com (nruth) Date: Sun, 20 Sep 2009 18:50:17 -0700 (PDT) Subject: [rspec-users] describe block proc parameter as alternative to before blocks? In-Reply-To: <57c63afe0909201356r7b56dd6auadf8a9e72ff911a8@mail.gmail.com> References: <57c63afe0909201356r7b56dd6auadf8a9e72ff911a8@mail.gmail.com> Message-ID: <6c039188-0468-42c6-b063-1c7b4b267d9d@l31g2000vbp.googlegroups.com> My last reply seems to have been swallowed by the Ajax monster. In brief, my suggestion is just for readability/maintenance. I feel the describe/context and before blocks are the same thing put in two places, one being documentation and the other implementation. Splitting them up like this seems like asking for trouble. That said, before blocks do achieve the same result, albeit somewhat inside out, and if put just after the describe it's clear what is going on. It's fair enough (particularly at this stage of development) to say that the onus should be on the spec author rather than the tools to write legible specs. Thanks for the reply Cheers Nick On Sep 20, 9:56?pm, David Chelimsky wrote: > On Sun, Sep 20, 2009 at 9:38 AM, nruth wrote: > > I've been reading through the Rspec book to see if I missed any > > tricks, and the discussion of before block use for context setup in > > sec 12.6 struck me as interesting and something I had a knee-jerk > > reaction to. > > > I think that when you are using nested examples to describe a context > > change it is bad practice to allow any example within that group to > > run outside of that context. This could happen simply because you > > forgot to copy and paste (ouch) the setup code into your expectation. > > > before blocks solve this problem, but they are so tightly coupled to > > the describe call in this case, why not make them a describe method > > parameter? Ideally they would be the block passed to describe, but we > > can't do that since the example group is using that already. > > > So I would propose something like this sketch: > > > describe "a new capacity 10 stack", :context => lambda {@stack = > > Stack.new(:capacity => 10)} do > > ?describe "with 4 pushed ints", :context => lambda { 4.times { @stack > > << rand(:int) } } do > > ? ?it "should allow push and return the new size" do > > ? ? ?@stack.push(rand(:int)).should == 5 > > ? ?end > > ?end > > end > > > And the :context would just be executed as if it were a before block. > > > Of course you can arrange your specs so that the before block is > > directly after the describe, or similar, but this seems a nice > > alternative to me. > > The order of the before blocks, relative to the examples, is > irrelevant. An example group loads up all of its examples and before > and after blocks before anything is run. In other words, these two > will have the same effect: > > describe Thing do > ? before(:each) { @thing = Thing.new } > ? it "does something" do > ? ? @thing.should do_something > ? end > end > > describe Thing do > ? it "does something" do > ? ? @thing.should do_something > ? end > ? before(:each) { @thing = Thing.new } > end > > This is not the first time your idea has come up, and I've not > included it before because I want to avoid assigning specific meaning > to keys in the hash passed to describe(). rspec-2 will be using that > hash as part of a plugin API, so the more I can leave available, the > better. I'll be posting more about that soon, but first things first - > gotta get the book off to the printer :) > > Cheers, > David > > > > > It's a nubile idea though. Thoughts? > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Mon Sep 21 02:42:00 2009 From: lists at ruby-forum.com (Mithun Perera) Date: Mon, 21 Sep 2009 08:42:00 +0200 Subject: [rspec-users] Need Help Message-ID: <4edfa1d1a36284246d74ad1b254f8541@ruby-forum.com> Hi all, I am an university student and these days i am on training period. So i want to know about ruby on on rails "cucumber and Rspec". If somebody know about these fields please help me. If not please send me an tutorials for basic functionality of the cucumber and Rspec. Thank you. regards, Mithun Perera -- Posted via http://www.ruby-forum.com/. From nick.rutherford at gmail.com Mon Sep 21 09:56:53 2009 From: nick.rutherford at gmail.com (nruth) Date: Mon, 21 Sep 2009 06:56:53 -0700 (PDT) Subject: [rspec-users] describe block proc parameter as alternative to before blocks? In-Reply-To: <6c039188-0468-42c6-b063-1c7b4b267d9d@l31g2000vbp.googlegroups.com> References: <57c63afe0909201356r7b56dd6auadf8a9e72ff911a8@mail.gmail.com> <6c039188-0468-42c6-b063-1c7b4b267d9d@l31g2000vbp.googlegroups.com> Message-ID: <03232a6e-8f60-41d7-9ffe-f858a425a642@p36g2000vbn.googlegroups.com> Sorry for the double post. Seems I haven't acquired the patience for mailing lists yet :) I had another idea which might scratch the itch, or might seem horrible: Take this example from some rails controller specs describe SiteImagesController, request = "get :index" do context "As a visitor:" do before(:each) {stub_admin_check @controller, false} should_not_execute :index, request end I was just looking at this and thought why not switch the string to the context helper. Something more like context as_a_visitor do should_not_execute :index, request end where as_a_visitor handles the stubbing and returns the documentation string? On Sep 21, 2:50?am, nruth wrote: > My last reply seems to have been swallowed by the Ajax monster. > > In brief, my suggestion is just for readability/maintenance. I feel > the describe/context and before blocks are the same thing put in two > places, one being documentation and the other implementation. > Splitting them up like this seems like asking for trouble. > > That said, before blocks do achieve the same result, albeit somewhat > inside out, and if put just after the describe it's clear what is > going on. > > It's fair enough (particularly at this stage of development) to say > that the onus should be on the spec author rather than the tools to > write legible specs. > > Thanks for the reply > Cheers > > Nick > > On Sep 20, 9:56?pm, David Chelimsky wrote: > > > > > On Sun, Sep 20, 2009 at 9:38 AM, nruth wrote: > > > I've been reading through the Rspec book to see if I missed any > > > tricks, and the discussion of before block use for context setup in > > > sec 12.6 struck me as interesting and something I had a knee-jerk > > > reaction to. > > > > I think that when you are using nested examples to describe a context > > > change it is bad practice to allow any example within that group to > > > run outside of that context. This could happen simply because you > > > forgot to copy and paste (ouch) the setup code into your expectation. > > > > before blocks solve this problem, but they are so tightly coupled to > > > the describe call in this case, why not make them a describe method > > > parameter? Ideally they would be the block passed to describe, but we > > > can't do that since the example group is using that already. > > > > So I would propose something like this sketch: > > > > describe "a new capacity 10 stack", :context => lambda {@stack = > > > Stack.new(:capacity => 10)} do > > > ?describe "with 4 pushed ints", :context => lambda { 4.times { @stack > > > << rand(:int) } } do > > > ? ?it "should allow push and return the new size" do > > > ? ? ?@stack.push(rand(:int)).should == 5 > > > ? ?end > > > ?end > > > end > > > > And the :context would just be executed as if it were a before block. > > > > Of course you can arrange your specs so that the before block is > > > directly after the describe, or similar, but this seems a nice > > > alternative to me. > > > The order of the before blocks, relative to the examples, is > > irrelevant. An example group loads up all of its examples and before > > and after blocks before anything is run. In other words, these two > > will have the same effect: > > > describe Thing do > > ? before(:each) { @thing = Thing.new } > > ? it "does something" do > > ? ? @thing.should do_something > > ? end > > end > > > describe Thing do > > ? it "does something" do > > ? ? @thing.should do_something > > ? end > > ? before(:each) { @thing = Thing.new } > > end > > > This is not the first time your idea has come up, and I've not > > included it before because I want to avoid assigning specific meaning > > to keys in the hash passed to describe(). rspec-2 will be using that > > hash as part of a plugin API, so the more I can leave available, the > > better. I'll be posting more about that soon, but first things first - > > gotta get the book off to the printer :) > > > Cheers, > > David > > > > It's a nubile idea though. Thoughts? > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Mon Sep 21 10:50:02 2009 From: lists at ruby-forum.com (Jorge Martin) Date: Mon, 21 Sep 2009 16:50:02 +0200 Subject: [rspec-users] Incompatible version? In-Reply-To: <3a5466acf1e40b1cf9690dbc55db8285@ruby-forum.com> References: <3a5466acf1e40b1cf9690dbc55db8285@ruby-forum.com> Message-ID: with: rspec (1.2.8, 1.1.12) rails (2.3.3, 2.3.2) rspec-rails (1.2.7.1, 1.1.12) cucumber (0.3.101, 0.3.100, 0.3.93, 0.3.92) and running the last selenium client it works -- Posted via http://www.ruby-forum.com/. From nick.rutherford at gmail.com Mon Sep 21 10:58:49 2009 From: nick.rutherford at gmail.com (nruth) Date: Mon, 21 Sep 2009 07:58:49 -0700 (PDT) Subject: [rspec-users] Need Help In-Reply-To: <50873a360909210108ue0403fdy99f23c6b065ff6db@mail.gmail.com> References: <4edfa1d1a36284246d74ad1b254f8541@ruby-forum.com> <50873a360909210108ue0403fdy99f23c6b065ff6db@mail.gmail.com> Message-ID: <77791865-ef35-47b0-94fd-c126beb747be@l34g2000vba.googlegroups.com> If you want a quick intro it's worth looking on http://www.slideshare.net/ for some intro talks at the many Rails conventions that have been held recently. Try searching for cucumber or rspec and see what falls out. There are videos of presentations out there too, for example http://www.engineyard.com/blog/community/scotland-on-rails/ in particular http://scotland-on-rails.s3.amazonaws.com/1A06_JosephWilk-SOR.mp4 The respective homepages should give some info on their wikis too. The cucumber page in particular has a few links to videos and blog articles etc. The RSpec book is great if you want to learn more, but is a time and money investment so I'd suggest taking a look round before jumping on that. Good luck! Nick On Sep 21, 9:08?am, doug livesey wrote: > If you go to peepcode.com, they have some excellent resources on RSpec & > Cucumber, and there is always The RSpec Book (from the pragmatic > programmers).HTH, > ? ?Doug. > > 2009/9/21 Mithun Perera > > > > > Hi all, > > I am an university student and these days i am on training period. So i > > want to know about ruby on on rails "cucumber and Rspec". If somebody > > know about these fields please help me. If not please send me an > > tutorials for basic functionality of the cucumber and Rspec. > > Thank you. > > regards, > > Mithun Perera > > -- > > Posted viahttp://www.ruby-forum.com/. > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From cstephens4 at gmail.com Mon Sep 21 17:48:53 2009 From: cstephens4 at gmail.com (Calvin) Date: Mon, 21 Sep 2009 14:48:53 -0700 (PDT) Subject: [rspec-users] Am I on the right track? Message-ID: <34423e39-ff6b-41aa-9e70-a633f04dd6c0@2g2000prl.googlegroups.com> Hi, I am pretty new to RSpec and I wonder if some code I have written is leading me in the right direction. Any advice is greatly appreciated! here is the code from calculator.rb class Calculator def equation(val1, val2) result = val1 + val2 return result end end and here is the code from my calculator_spec.rb require 'calculator' describe Calculator do it "should perform calculations" do calc = Calculator.new result = calc.equation(1, 5) result.should == 6 end end From zach.dennis at gmail.com Mon Sep 21 22:22:49 2009 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 21 Sep 2009 21:22:49 -0500 Subject: [rspec-users] describe block proc parameter as alternative to before blocks? In-Reply-To: <16c60ac5-528d-41c7-a431-d636fdcddb48@p36g2000vbn.googlegroups.com> References: <57c63afe0909201356r7b56dd6auadf8a9e72ff911a8@mail.gmail.com> <16c60ac5-528d-41c7-a431-d636fdcddb48@p36g2000vbn.googlegroups.com> Message-ID: <85d99afe0909211922t5151bc79ob662283bf0889e35@mail.gmail.com> On Sun, Sep 20, 2009 at 8:34 PM, nruth wrote: > David > Thanks for the reply. > > I think I wasn't clear with my original post: before blocks work fine, > this is just a readability/comprehension/maintenance concern. > > We're using a describe (or context) block to name (or document) a > state, then using a separate before block to set up that state > (context). If that before block were to go astray the documentation > would cease to be correct. > It seems better to have this done in one place rather than two, as > separate description statements and setup code could lead to confusion > or errors through fragmented example groups. > > I'm not sure how helpful it would be if the setup takes more than half > a line of code. Referencing a definition elsewhere wouldn't help > readability, though would still make it clear that the describe was > for that particular setup state. > > Before blocks do have the same effect, and if positioned sensibly > should avoid these problems. before blocks are also limited in where you can put them. They must be specified very close the context in which they are to be applied. If you provide a helper method as the context you create the need to further separate an important part of an example from its context. I also feel you lose a lot in what you describe and how you describe it when you restrict it to ruby method names. > It's not a big deal, and the onus should probably be on the spec > author rather than the tools to produce clean and consistent specs? I think it's important for people to pay attention when they write code. Based on some of the code I've seen over the past few years I'm not sure everyone would agree with me. :) > I'm not surprised it's come up before, but I didn't find anything > searching the group. > > Cheers > > Nick > > On Sep 20, 9:56?pm, David Chelimsky wrote: >> On Sun, Sep 20, 2009 at 9:38 AM, nruth wrote: >> > I've been reading through the Rspec book to see if I missed any >> > tricks, and the discussion of before block use for context setup in >> > sec 12.6 struck me as interesting and something I had a knee-jerk >> > reaction to. >> >> > I think that when you are using nested examples to describe a context >> > change it is bad practice to allow any example within that group to >> > run outside of that context. This could happen simply because you >> > forgot to copy and paste (ouch) the setup code into your expectation. >> >> > before blocks solve this problem, but they are so tightly coupled to >> > the describe call in this case, why not make them a describe method >> > parameter? Ideally they would be the block passed to describe, but we >> > can't do that since the example group is using that already. >> >> > So I would propose something like this sketch: >> >> > describe "a new capacity 10 stack", :context => lambda {@stack = >> > Stack.new(:capacity => 10)} do >> > ?describe "with 4 pushed ints", :context => lambda { 4.times { @stack >> > << rand(:int) } } do >> > ? ?it "should allow push and return the new size" do >> > ? ? ?@stack.push(rand(:int)).should == 5 >> > ? ?end >> > ?end >> > end >> >> > And the :context would just be executed as if it were a before block. >> >> > Of course you can arrange your specs so that the before block is >> > directly after the describe, or similar, but this seems a nice >> > alternative to me. >> >> The order of the before blocks, relative to the examples, is >> irrelevant. An example group loads up all of its examples and before >> and after blocks before anything is run. In other words, these two >> will have the same effect: >> >> describe Thing do >> ? before(:each) { @thing = Thing.new } >> ? it "does something" do >> ? ? @thing.should do_something >> ? end >> end >> >> describe Thing do >> ? it "does something" do >> ? ? @thing.should do_something >> ? end >> ? before(:each) { @thing = Thing.new } >> end >> >> This is not the first time your idea has come up, and I've not >> included it before because I want to avoid assigning specific meaning >> to keys in the hash passed to describe(). rspec-2 will be using that >> hash as part of a plugin API, so the more I can leave available, the >> better. I'll be posting more about that soon, but first things first - >> gotta get the book off to the printer :) >> >> Cheers, >> David >> >> >> >> > It's a nubile idea though. Thoughts? >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com (personal) http://www.mutuallyhuman.com (hire me) http://ideafoundry.info/behavior-driven-development (first rate BDD training) @zachdennis (twitter) From zach.dennis at gmail.com Mon Sep 21 22:34:02 2009 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 21 Sep 2009 21:34:02 -0500 Subject: [rspec-users] describe block proc parameter as alternative to before blocks? In-Reply-To: <03232a6e-8f60-41d7-9ffe-f858a425a642@p36g2000vbn.googlegroups.com> References: <57c63afe0909201356r7b56dd6auadf8a9e72ff911a8@mail.gmail.com> <6c039188-0468-42c6-b063-1c7b4b267d9d@l31g2000vbp.googlegroups.com> <03232a6e-8f60-41d7-9ffe-f858a425a642@p36g2000vbn.googlegroups.com> Message-ID: <85d99afe0909211934k616b6552kf96da55c1da45b34@mail.gmail.com> On Mon, Sep 21, 2009 at 8:56 AM, nruth wrote: > Sorry for the double post. Seems I haven't acquired the patience for > mailing lists yet :) > > I had another idea which might scratch the itch, or might seem > horrible: > > Take this example from some rails controller specs > > describe SiteImagesController, request = "get :index" do > ?context "As a visitor:" do > ? ?before(:each) {stub_admin_check @controller, false} > ? ?should_not_execute :index, request > ?end > > I was just looking at this and thought why not switch the string to > the context helper. > > Something more like > > context as_a_visitor do > ?should_not_execute :index, request > end > > where as_a_visitor handles the stubbing and returns the documentation > string? I kind of partially responded to this in my other response. Sorry for splitting these up..... If as_a_visitor is to return the documentation string I think we've created a very unnatural thing (at least for me, but maybe I'm conditioned), for the return value of a helper to be used to describe an example or set of examples. This moves the real, descriptive, meaningful description away from the examples themselves, and hides them in this context helper method which may be defined in the same file, or maybe its defined in another file. Instead of having the most meaningful description with your examples you've got it somewhere else, and now to understand the example with the most clarity the author intended to give it, it needs to go search it out somewhere else. For me I put a lot of emphasis on readability of the specs, and not just on the description's readability (which is great, but its not the only thing). At some point the implementation of the examples including before/after blocks need to communicate a important part of the story for an example in a coherent and readable manner. I rather like having a before/after block within a context, even though it takes up at most 2 additional lines (the before/do and the end), because the meat of the before/after block should be code that helps a reader of the spec more clearly understand what's involved with these examples with a low amount of effort (they shouldn't need to go search for helpers to understand intent). If we remove that from being close to the examples it applies to then I think we would be creating a separation between the spec some of its most useful parts. > > > > On Sep 21, 2:50?am, nruth wrote: >> My last reply seems to have been swallowed by the Ajax monster. >> >> In brief, my suggestion is just for readability/maintenance. I feel >> the describe/context and before blocks are the same thing put in two >> places, one being documentation and the other implementation. >> Splitting them up like this seems like asking for trouble. >> >> That said, before blocks do achieve the same result, albeit somewhat >> inside out, and if put just after the describe it's clear what is >> going on. >> >> It's fair enough (particularly at this stage of development) to say >> that the onus should be on the spec author rather than the tools to >> write legible specs. >> >> Thanks for the reply >> Cheers >> >> Nick >> >> On Sep 20, 9:56?pm, David Chelimsky wrote: >> >> >> >> > On Sun, Sep 20, 2009 at 9:38 AM, nruth wrote: >> > > I've been reading through the Rspec book to see if I missed any >> > > tricks, and the discussion of before block use for context setup in >> > > sec 12.6 struck me as interesting and something I had a knee-jerk >> > > reaction to. >> >> > > I think that when you are using nested examples to describe a context >> > > change it is bad practice to allow any example within that group to >> > > run outside of that context. This could happen simply because you >> > > forgot to copy and paste (ouch) the setup code into your expectation. >> >> > > before blocks solve this problem, but they are so tightly coupled to >> > > the describe call in this case, why not make them a describe method >> > > parameter? Ideally they would be the block passed to describe, but we >> > > can't do that since the example group is using that already. >> >> > > So I would propose something like this sketch: >> >> > > describe "a new capacity 10 stack", :context => lambda {@stack = >> > > Stack.new(:capacity => 10)} do >> > > ?describe "with 4 pushed ints", :context => lambda { 4.times { @stack >> > > << rand(:int) } } do >> > > ? ?it "should allow push and return the new size" do >> > > ? ? ?@stack.push(rand(:int)).should == 5 >> > > ? ?end >> > > ?end >> > > end >> >> > > And the :context would just be executed as if it were a before block. >> >> > > Of course you can arrange your specs so that the before block is >> > > directly after the describe, or similar, but this seems a nice >> > > alternative to me. >> >> > The order of the before blocks, relative to the examples, is >> > irrelevant. An example group loads up all of its examples and before >> > and after blocks before anything is run. In other words, these two >> > will have the same effect: >> >> > describe Thing do >> > ? before(:each) { @thing = Thing.new } >> > ? it "does something" do >> > ? ? @thing.should do_something >> > ? end >> > end >> >> > describe Thing do >> > ? it "does something" do >> > ? ? @thing.should do_something >> > ? end >> > ? before(:each) { @thing = Thing.new } >> > end >> >> > This is not the first time your idea has come up, and I've not >> > included it before because I want to avoid assigning specific meaning >> > to keys in the hash passed to describe(). rspec-2 will be using that >> > hash as part of a plugin API, so the more I can leave available, the >> > better. I'll be posting more about that soon, but first things first - >> > gotta get the book off to the printer :) >> >> > Cheers, >> > David >> >> > > It's a nubile idea though. Thoughts? >> >> > _______________________________________________ >> > rspec-users mailing list >> > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com (personal) http://www.mutuallyhuman.com (hire me) http://ideafoundry.info/behavior-driven-development (first rate BDD training) @zachdennis (twitter) From sfeley at gmail.com Mon Sep 21 22:47:19 2009 From: sfeley at gmail.com (Stephen Eley) Date: Mon, 21 Sep 2009 22:47:19 -0400 Subject: [rspec-users] Am I on the right track? In-Reply-To: <34423e39-ff6b-41aa-9e70-a633f04dd6c0@2g2000prl.googlegroups.com> References: <34423e39-ff6b-41aa-9e70-a633f04dd6c0@2g2000prl.googlegroups.com> Message-ID: <1fb4df0909211947x738d7392l6a52caa0b3ac34f3@mail.gmail.com> On Mon, Sep 21, 2009 at 5:48 PM, Calvin wrote: > > I am pretty new to RSpec and I wonder if some code I have written is > leading me in the right direction. Any advice is greatly appreciated! As a beginner exercise, this code looks perfectly functional to me. But I believe you left out the interesting parts: * Which did you write first? The spec or the implementation? * Is the behavior description, "it should perform calculations," clear and precise? If I didn't have access to the code, would I be able to read that description and know something useful about the class's behavior? * Why did you choose the method name "equation"? If I simply knew that name, would I be able to tell what that method does? * What is it you _really_ want this class to do? Does the specification help you verify that it acts according to your intention? * Why do you want it to do that? (Okay, granted, this may be more of a Cucumber question than an RSpec question.) >8-> -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From aaron.gibralter at gmail.com Tue Sep 22 00:22:02 2009 From: aaron.gibralter at gmail.com (Aaron Gibralter) Date: Tue, 22 Sep 2009 00:22:02 -0400 Subject: [rspec-users] rspec-rails and rack middleware Message-ID: <265b23d80909212122x45242403ve5bc7c1321ec915c@mail.gmail.com> It doesn't seem like my controller specs are calling my middleware on requests. Has anyone figured out a good way to test middlware with rspec? I'm thinking something like rails' rails/actionpack/test/controller/session/mem_cache_store_test.rb but with rspec... any thoughts? Thanks! Best, Aaron -------------- next part -------------- An HTML attachment was scrubbed... URL: From sfeley at gmail.com Tue Sep 22 00:57:58 2009 From: sfeley at gmail.com (Stephen Eley) Date: Tue, 22 Sep 2009 00:57:58 -0400 Subject: [rspec-users] rspec-rails and rack middleware In-Reply-To: <265b23d80909212122x45242403ve5bc7c1321ec915c@mail.gmail.com> References: <265b23d80909212122x45242403ve5bc7c1321ec915c@mail.gmail.com> Message-ID: <1fb4df0909212157s1f569182qf0f4fe96530c4aad@mail.gmail.com> On Tue, Sep 22, 2009 at 12:22 AM, Aaron Gibralter wrote: > It doesn't seem like my controller specs are calling my middleware on > requests. Has anyone figured out a good way to test middlware with rspec? Rack::Test is your friend: http://github.com/brynary/rack-test If you Google it, there's a fair amount of lore out there already on using it in various contexts. (And yes, the methods it provides work just as well in RSpec.) -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From sfeley at gmail.com Tue Sep 22 01:14:20 2009 From: sfeley at gmail.com (Stephen Eley) Date: Tue, 22 Sep 2009 01:14:20 -0400 Subject: [rspec-users] describe block proc parameter as alternative to before blocks? In-Reply-To: <16c60ac5-528d-41c7-a431-d636fdcddb48@p36g2000vbn.googlegroups.com> References: <57c63afe0909201356r7b56dd6auadf8a9e72ff911a8@mail.gmail.com> <16c60ac5-528d-41c7-a431-d636fdcddb48@p36g2000vbn.googlegroups.com> Message-ID: <1fb4df0909212214h2ff87bccncf8257a06eff7c78@mail.gmail.com> On Sun, Sep 20, 2009 at 9:34 PM, nruth wrote: > > I think I wasn't clear with my original post: before blocks work fine, > this is just a readability/comprehension/maintenance concern. Peanut gallery: I personally find the separate "before" block clearer, more readable, and more aesthetically appealing than an inline ":context => lambda {something}". Lambda is an ugly word. I know we inherited it from Lisp and that the fundamental concept of closures is a beautiful thing, responsible for puppies and rainbows and ActiveRecord, but still. It doesn't _feel_ good to have to add jargon on top of a block just to say "I know this is a dynamic language, but this here? This part is _really_ dynamic." Putting lambdas and Proc.news into my Ruby code always makes me feel like I just scuffed my clean white shoes. (The 'stabby' operator in Ruby 1.9 is only marginally better.) Context? "Context" isn't an ugly word but it's a really ambiguous one. It means so many things, depending on...well, the context. Whereas if I see a bunch of code with "before" or "before(:each)" at the top, I can make a _really_ good guess just from looking at it what it's supposed to do, and when. It may not be attached umbilically to the describe statement, but it's still in there, doing what it does, and I keep mine right underneath the describe where I can see it. (I confess I'm not really sure what you mean by the before block "going astray." If you find that your test code is getting out from under your fence at night, roaming the neighborhood, perhaps you aren't feeding it often enough?) -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From lists at ruby-forum.com Tue Sep 22 01:34:48 2009 From: lists at ruby-forum.com (Mithun Perera) Date: Tue, 22 Sep 2009 07:34:48 +0200 Subject: [rspec-users] Need Help In-Reply-To: <4edfa1d1a36284246d74ad1b254f8541@ruby-forum.com> References: <4edfa1d1a36284246d74ad1b254f8541@ruby-forum.com> Message-ID: <98286041539419c67480f06ee7ee4dbb@ruby-forum.com> Mithun Perera wrote: > Hi all, > I am an university student and these days i am on training period. So i > want to know about ruby on on rails "cucumber and Rspec". If somebody > know about these fields please help me. If not please send me an > tutorials for basic functionality of the cucumber and Rspec. > Thank you. > regards, > Mithun Perera Hi all, I found one tutorial. http://www.ultrasaurus.com/sarahblog/2008/12/rails-2-day-3-behavior-driven-development/#setup if u found new one please kind enough to send me reply. Mithun Perera -- Posted via http://www.ruby-forum.com/. From sfeley at gmail.com Tue Sep 22 01:38:37 2009 From: sfeley at gmail.com (Stephen Eley) Date: Tue, 22 Sep 2009 01:38:37 -0400 Subject: [rspec-users] describe block proc parameter as alternative to before blocks? In-Reply-To: <16c60ac5-528d-41c7-a431-d636fdcddb48@p36g2000vbn.googlegroups.com> References: <57c63afe0909201356r7b56dd6auadf8a9e72ff911a8@mail.gmail.com> <16c60ac5-528d-41c7-a431-d636fdcddb48@p36g2000vbn.googlegroups.com> Message-ID: <1fb4df0909212238w661b2af9x76adb09efffe4b74@mail.gmail.com> On Sun, Sep 20, 2009 at 9:34 PM, nruth wrote: > > We're using a describe (or context) block to name (or document) a > state, then using a separate before block to set up that state > (context). If that before block were to go astray the documentation > would cease to be correct. On further reading and thinking, I think I might see some of the confusion. You're not quite correct that the describe and the before are "separate blocks." The before block lives *inside* the describe block, and composes part of what is described. The describe block is more than "documentation." It's a class definition. (Literally.) Class definitions do more than just provide names; they bundle up behavior. The before block can (not literally, but effectively) be considered as a sort of constructor method for the class, similar to 'def initialize' in a non-RSpec class but with more chaining built in. Nested example groups are subclasses that invoke the superclasses's constructors automatically, etc. This is all very clean, mostly traditional object-oriented language behavior. Your suggestion of putting the initializer as a block value to a hash option is more complicated; it's like saying normal Ruby classes should not have an 'initialize' method, but instead should be declared like 'class Foo :constructor => lambda{initializer code here}'. Ruby's insistence that you should call 'new' but implement 'initialize' is confusing enough. The lambda-option style doesn't make it clearer. Does that make sense? "Describe" and "before" aren't disconnected entities. They're body and organ. One is a part of the other. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From matt at mattwynne.net Tue Sep 22 03:17:31 2009 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 22 Sep 2009 08:17:31 +0100 Subject: [rspec-users] Need Help In-Reply-To: <98286041539419c67480f06ee7ee4dbb@ruby-forum.com> References: <4edfa1d1a36284246d74ad1b254f8541@ruby-forum.com> <98286041539419c67480f06ee7ee4dbb@ruby-forum.com> Message-ID: <93415EEB-A5CC-4B6D-8D61-BEB44DDC0366@mattwynne.net> On 22 Sep 2009, at 06:34, Mithun Perera wrote: > Mithun Perera wrote: >> Hi all, >> I am an university student and these days i am on training period. >> So i >> want to know about ruby on on rails "cucumber and Rspec". If somebody >> know about these fields please help me. If not please send me an >> tutorials for basic functionality of the cucumber and Rspec. >> Thank you. >> regards, >> Mithun Perera > > Hi all, > I found one tutorial. > http://www.ultrasaurus.com/sarahblog/2008/12/rails-2-day-3-behavior-driven-development/#setup > > if u found new one please kind enough to send me reply. Try http://cukes.info - there are plenty of links there that should help you. cheers, Matt http://mattwynne.net +447974 430184 From aaron.gibralter at gmail.com Tue Sep 22 08:24:29 2009 From: aaron.gibralter at gmail.com (Aaron Gibralter) Date: Tue, 22 Sep 2009 08:24:29 -0400 Subject: [rspec-users] rspec-rails and rack middleware Message-ID: <265b23d80909220524k1eb53e44xed8ed9fa22b11140@mail.gmail.com> Ah ok. I tried that, but I can't seem to figure out what to use for the def app ... end method in my spec though. The app is my Rails app... for now I have something like: http://www.pastie.org/625791 I can get the dummy_app to work, but now I'm trying to figure out how to use my Rails app. I'll keep playing around and see if I can come up with anything. Thanks! -Aaron --------- Rack::Test is your friend: http://github.com/brynary/rack-test If you Google it, there's a fair amount of lore out there already on using it in various contexts. (And yes, the methods it provides work just as well in RSpec.) -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick.rutherford at gmail.com Tue Sep 22 08:55:09 2009 From: nick.rutherford at gmail.com (nruth) Date: Tue, 22 Sep 2009 05:55:09 -0700 (PDT) Subject: [rspec-users] describe block proc parameter as alternative to before blocks? In-Reply-To: <1fb4df0909212238w661b2af9x76adb09efffe4b74@mail.gmail.com> References: <57c63afe0909201356r7b56dd6auadf8a9e72ff911a8@mail.gmail.com> <16c60ac5-528d-41c7-a431-d636fdcddb48@p36g2000vbn.googlegroups.com> <1fb4df0909212238w661b2af9x76adb09efffe4b74@mail.gmail.com> Message-ID: I agree that lambda'ing here would not help readability, I thought that when I wrote it; it would quickly spiral out of control and make things look horrible. While I certainly appreciate the before / initialize parallel, I hadn't thought of it like that before. I don't think about ruby when writing specs, I think about nesting concepts and readability (and what I am making, ofc), that's why I use rspec. Well, that and being told to when I started :) I write describe/context blocks to describe context, not to define classes. That's where I'm coming from when saying I want my context call and its setup to be on one line, rather than the setup being portrayed as encapsulated by the concept rather than part of it. Looking at it as a class definition is making this seem a lot less weird now. I don't know if that's a good thing or not, but thanks. Before blocks are in common use and people know to look for them so don't introduce an alternative to confuse things -- yep, very valid point. I guess the short answer is no, stop being silly, this works well within the language limitations, and the suggested alternative will end up looking the same or worse. Still, I found it interesting. Thanks for the feedback. Running under the fence indeed, which hedge do these faults and failures creep out from ;) Nick On Sep 22, 6:38?am, Stephen Eley wrote: > On Sun, Sep 20, 2009 at 9:34 PM, nruth wrote: > > > We're using a describe (or context) block to name (or document) a > > state, then using a separate before block to set up that state > > (context). If that before block were to go astray the documentation > > would cease to be correct. > > On further reading and thinking, I think I might see some of the > confusion. ?You're not quite correct that the describe and the before > are "separate blocks." ?The before block lives *inside* the describe > block, and composes part of what is described. > > The describe block is more than "documentation." ?It's a class > definition. ?(Literally.) ?Class definitions do more than just provide > names; they bundle up behavior. ?The before block can (not literally, > but effectively) be considered as a sort of constructor method for the > class, similar to 'def initialize' in a non-RSpec class but with more > chaining built in. ?Nested example groups are subclasses that invoke > the superclasses's constructors automatically, etc. > > This is all very clean, mostly traditional object-oriented language > behavior. ?Your suggestion of putting the initializer as a block value > to a hash option is more complicated; it's like saying normal Ruby > classes should not have an 'initialize' method, but instead should be > declared like 'class Foo :constructor => lambda{initializer code > here}'. ?Ruby's insistence that you should call 'new' but implement > 'initialize' is confusing enough. ?The lambda-option style doesn't > make it clearer. > > Does that make sense? ?"Describe" and "before" aren't disconnected > entities. ?They're body and organ. ?One is a part of the other. > > -- > Have Fun, > ? ?Steve Eley (sfe... at gmail.com) > ? ?ESCAPE POD - The Science Fiction Podcast Magazine > ? ?http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From sfeley at gmail.com Tue Sep 22 09:52:37 2009 From: sfeley at gmail.com (Stephen Eley) Date: Tue, 22 Sep 2009 09:52:37 -0400 Subject: [rspec-users] describe block proc parameter as alternative to before blocks? In-Reply-To: References: <57c63afe0909201356r7b56dd6auadf8a9e72ff911a8@mail.gmail.com> <16c60ac5-528d-41c7-a431-d636fdcddb48@p36g2000vbn.googlegroups.com> <1fb4df0909212238w661b2af9x76adb09efffe4b74@mail.gmail.com> Message-ID: <1fb4df0909220652s2cea70e9n1363abf9057f9921@mail.gmail.com> On Tue, Sep 22, 2009 at 8:55 AM, nruth wrote: > > I guess the short answer is no, stop being silly, [...] It wasn't silly at all to raise the question. I apologize sincerely if I gave the impression that I was trying to be insulting. It's _very_ worthwhile to ask questions about The Way Things Are Done and to discuss alternatives. If we stop doing that, the culture fossilizes. And then it's no fun any more. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From sfeley at gmail.com Tue Sep 22 10:25:34 2009 From: sfeley at gmail.com (Stephen Eley) Date: Tue, 22 Sep 2009 10:25:34 -0400 Subject: [rspec-users] rspec-rails and rack middleware In-Reply-To: <265b23d80909220524k1eb53e44xed8ed9fa22b11140@mail.gmail.com> References: <265b23d80909220524k1eb53e44xed8ed9fa22b11140@mail.gmail.com> Message-ID: <1fb4df0909220725xbb51501ja2c8018555052136@mail.gmail.com> On Tue, Sep 22, 2009 at 8:24 AM, Aaron Gibralter wrote: > > I can get the dummy_app to work, but now I'm trying to figure out how to use > my Rails app. I'll keep playing around and see if I can come up with > anything. It sounds like you're trying to do integration testing (all the pieces of the system working together) instead of unit testing (testing each piece of the system). My suggestion would be to let your middleware specs test your middleware, and your controller specs test just the controller. You can set up stubs or tweak the request to feed it whatever this middleware is supposed to do. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From cstephens4 at gmail.com Tue Sep 22 10:53:16 2009 From: cstephens4 at gmail.com (Calvin) Date: Tue, 22 Sep 2009 07:53:16 -0700 (PDT) Subject: [rspec-users] Am I on the right track? In-Reply-To: <1fb4df0909211947x738d7392l6a52caa0b3ac34f3@mail.gmail.com> References: <34423e39-ff6b-41aa-9e70-a633f04dd6c0@2g2000prl.googlegroups.com> <1fb4df0909211947x738d7392l6a52caa0b3ac34f3@mail.gmail.com> Message-ID: <078d27ff-2640-423a-a55b-ad4ef02b69ec@p10g2000prm.googlegroups.com> Hi Steve, I wrote the spec first and then the implementation. I think I could have written a better behavior description. I don't think the method name is as good or specific as it could be. I just wanted the class to be able to add two numbers... so maybe the specification could reflect that more... and I want the class to add two numbers because I wanted to practice using rspec and figured a simple program would be good to start out with. - Calvin On Sep 21, 7:47?pm, Stephen Eley wrote: > On Mon, Sep 21, 2009 at 5:48 PM, Calvin wrote: > > > I am pretty new to RSpec and I wonder if some code I have written is > > leading me in the right direction. Any advice is greatly appreciated! > > As a beginner exercise, this code looks perfectly functional to me. > But I believe you left out the interesting parts: > > * Which did you write first? ?The spec or the implementation? > > * Is the behavior description, "it should perform calculations," clear > and precise? ?If I didn't have access to the code, would I be able to > read that description and know something useful about the class's > behavior? > > * Why did you choose the method name "equation"? ?If I simply knew > that name, would I be able to tell what that method does? > > * What is it you _really_ want this class to do? ?Does the > specification help you verify that it acts according to your > intention? > > * Why do you want it to do that? ?(Okay, granted, this may be more of > a Cucumber question than an RSpec question.) ?>8-> > > -- > Have Fun, > ? ?Steve Eley (sfe... at gmail.com) > ? ?ESCAPE POD - The Science Fiction Podcast Magazine > ? ?http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From aaron.gibralter at gmail.com Tue Sep 22 12:06:15 2009 From: aaron.gibralter at gmail.com (Aaron Gibralter) Date: Tue, 22 Sep 2009 12:06:15 -0400 Subject: [rspec-users] rspec-rails and rack middleware In-Reply-To: <1fb4df0909220725xbb51501ja2c8018555052136@mail.gmail.com> References: <265b23d80909220524k1eb53e44xed8ed9fa22b11140@mail.gmail.com> <1fb4df0909220725xbb51501ja2c8018555052136@mail.gmail.com> Message-ID: <265b23d80909220906y319d7385t24c94c2661a93dfc@mail.gmail.com> Ah true, I definitely just realized that. The reason I was trying to use rails though was to provide endpoints for the calls passing through my middleware. For that though, I can just use the dummy app. Thank you! On Tue, Sep 22, 2009 at 10:25 AM, Stephen Eley wrote: > On Tue, Sep 22, 2009 at 8:24 AM, Aaron Gibralter > wrote: > > > > I can get the dummy_app to work, but now I'm trying to figure out how to > use > > my Rails app. I'll keep playing around and see if I can come up with > > anything. > > It sounds like you're trying to do integration testing (all the pieces > of the system working together) instead of unit testing (testing each > piece of the system). My suggestion would be to let your middleware > specs test your middleware, and your controller specs test just the > controller. You can set up stubs or tweak the request to feed it > whatever this middleware is supposed to do. > > > -- > Have Fun, > Steve Eley (sfeley at gmail.com) > ESCAPE POD - The Science Fiction Podcast Magazine > http://www.escapepod.org > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed Sep 23 00:24:20 2009 From: lists at ruby-forum.com (Mithun Perera) Date: Wed, 23 Sep 2009 06:24:20 +0200 Subject: [rspec-users] Cucumber senario Message-ID: Hi all, here is a scenario for create new Task Scenario: Create Valid Task Given I have no tasks And I am on the list of tasks When I follow "New Task" And I fill in "Description" with "Hello" And I press "Create" Then I should see "Task was successfully created." And I should see "Hello" And I should have 1 task according to that i want to write a senario for edit. if any body knows how to write that please help me. Thanks regards, mithun perera. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Wed Sep 23 00:46:38 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 22 Sep 2009 23:46:38 -0500 Subject: [rspec-users] Cucumber senario In-Reply-To: References: Message-ID: <57c63afe0909222146g142c4387wac52049a701dae01@mail.gmail.com> On Tue, Sep 22, 2009 at 11:24 PM, Mithun Perera wrote: > Hi all, > here is a scenario for create new Task > > Scenario: Create Valid Task > ?Given I have no tasks > ?And I am on the list of tasks > ?When I follow "New Task" > ?And I fill in "Description" with "Hello" > ?And I press "Create" > ?Then I should see "Task was successfully created." > ?And I should see "Hello" > ?And I should have 1 task > > according to that i want to write a senario for edit. if any body knows > how to write that please help me. > Thanks > regards, > mithun perera. Hi, Please send cucumber questions to http://groups.google.com/group/cukes. Cheers, David From nick.rutherford at gmail.com Wed Sep 23 08:15:54 2009 From: nick.rutherford at gmail.com (nruth) Date: Wed, 23 Sep 2009 05:15:54 -0700 (PDT) Subject: [rspec-users] describe block proc parameter as alternative to before blocks? In-Reply-To: <1fb4df0909220652s2cea70e9n1363abf9057f9921@mail.gmail.com> References: <57c63afe0909201356r7b56dd6auadf8a9e72ff911a8@mail.gmail.com> <16c60ac5-528d-41c7-a431-d636fdcddb48@p36g2000vbn.googlegroups.com> <1fb4df0909212238w661b2af9x76adb09efffe4b74@mail.gmail.com> <1fb4df0909220652s2cea70e9n1363abf9057f9921@mail.gmail.com> Message-ID: <80203061-bb90-4834-8f4a-3fe217232c8d@n2g2000vba.googlegroups.com> Stephen No worries, I didn't get that impression. I was just gibing myself. On the up side David's plugin system sounds pretty nice, and I wonder whether that will change the face of this at all. It may enable myself or someone else to create some kind of context spec chimera after all. :) Cheers Nick On Sep 22, 2:52?pm, Stephen Eley wrote: > On Tue, Sep 22, 2009 at 8:55 AM, nruth wrote: > > > I guess the short answer is no, stop being silly, [...] > > It wasn't silly at all to raise the question. ?I apologize sincerely > if I gave the impression that I was trying to be insulting. ?It's > _very_ worthwhile to ask questions about The Way Things Are Done and > to discuss alternatives. ?If we stop doing that, the culture > fossilizes. ?And then it's no fun any more. > > -- > Have Fun, > ? ?Steve Eley (sfe... at gmail.com) > ? ?ESCAPE POD - The Science Fiction Podcast Magazine > ? ?http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Sep 23 11:09:58 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Sep 2009 10:09:58 -0500 Subject: [rspec-users] How to use --pattern ? In-Reply-To: <4ABA34D5.1040708@haskinferguson.net> References: <4ABA34D5.1040708@haskinferguson.net> Message-ID: <57c63afe0909230809q6a167bc7td48dbb59fc5ae616@mail.gmail.com> On Wed, Sep 23, 2009 at 9:46 AM, Denis Haskin wrote: > (asked this yesterday on #rspec, no response...) > > Am I missing something obvious about --pattern?? It seems to only run the > first spec that matches the pattern; I expected it to run all that match. > > I tried: > spec spec/models --pattern line_item > spec spec/models --pattern \*line_item\* > spec spec/models --pattern '*line_item*' > > all to no avail... The pattern is passed to Dir.glob, referenced from the ./spec directory in the project. It needs to be in the correct format given those considerations. The three variations you tried all look for files matching line_item in the ./spec directory, not its subdirectories. Try this: spec spec/models --pattern "**/line_item*" > > Maybe I'll go look at the source.? That would be a concept. > > dwh > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dansteinicke at gmail.com Wed Sep 23 13:16:06 2009 From: dansteinicke at gmail.com (DanS) Date: Wed, 23 Sep 2009 10:16:06 -0700 (PDT) Subject: [rspec-users] bmabey-fakefs Not Found Error when installing rspec 1.2.9.rc1 Message-ID: I'm trying to install rspec so I can work with the new book chapter. This what the console shows after running "rake install_gem" Successfully built RubyGem Name: rspec Version: 1.2.9.rc1 File: rspec-1.2.9.rc1.gem mv rspec-1.2.9.rc1.gem pkg/rspec-1.2.9.rc1.gem sudo gem install bmabey-fakefs --version '>=0.1.1' ERROR: could not find gem bmabey-fakefs locally or in a repository I went and installed bmabey-fakefs from: http://github.com/bmabey/fakefs but I still get the same error after installing bmabey-fakefs. I notice that "gem list" command shows this as "fakefs" and not "bmabey- fakefs" but I don't know if this naming difference matters, or what to do about it if it does. Can anyone tell me how to solve this? Or if I can safely ignore this? Any help appreciated. Dan From dchelimsky at gmail.com Wed Sep 23 13:40:20 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Sep 2009 12:40:20 -0500 Subject: [rspec-users] bmabey-fakefs Not Found Error when installing rspec 1.2.9.rc1 In-Reply-To: References: Message-ID: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> On Wed, Sep 23, 2009 at 12:16 PM, DanS wrote: > I'm trying to install rspec so I can work with the new book chapter. > This what the console shows after running "rake install_gem" > > ?Successfully built RubyGem > ?Name: rspec > ?Version: 1.2.9.rc1 > ?File: rspec-1.2.9.rc1.gem > mv rspec-1.2.9.rc1.gem pkg/rspec-1.2.9.rc1.gem > sudo gem install ?bmabey-fakefs --version '>=0.1.1' > ERROR: ?could not find gem bmabey-fakefs locally or in a repository > > I went and installed bmabey-fakefs from: > http://github.com/bmabey/fakefs > > but I still get the same error after installing bmabey-fakefs. ?I > notice that "gem list" command shows this as "fakefs" and not "bmabey- > fakefs" but I don't know if this naming difference matters, or what to > do about it if it does. > > Can anyone tell me how to solve this? ?Or if I can safely ignore this? 2 things you can do. Install from rubyforge: [sudo] gem install rspec --prerelease or .... if you clone the git rep, just install it w/ the gem command: rake gem [sudo] gem install pkg/rspec-1.2.9.rc1.gem > Any help appreciated. > > Dan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Sep 23 14:38:50 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Sep 2009 13:38:50 -0500 Subject: [rspec-users] -- example ? (was Re: How to use --pattern ?) In-Reply-To: <4ABA67E8.7000704@haskinferguson.net> References: <4ABA34D5.1040708@haskinferguson.net> <57c63afe0909230809q6a167bc7td48dbb59fc5ae616@mail.gmail.com> <4ABA67E8.7000704@haskinferguson.net> Message-ID: <57c63afe0909231138r3d1ed331l417c242a04db9c28@mail.gmail.com> On Wed, Sep 23, 2009 at 1:24 PM, Denis Haskin wrote: > Aah... thank you. > > It looks like what I really want is --example (I want to be able to run a > selected few examples).? But that also seems to have some weirdess: > > $ spec spec/models --example spec/models/discount_spec.rb > Finished in 1.527043 seconds > 0 examples, 0 failures > > I can see from the log that application initialization is happening, but > none of the examples are being run. > > Suggestions? spec --help ;) Cheers, David > > Thanks, > > dwh > > > > David Chelimsky wrote: > > On Wed, Sep 23, 2009 at 9:46 AM, Denis Haskin > wrote: > > > (asked this yesterday on #rspec, no response...) > > Am I missing something obvious about --pattern?? It seems to only run the > first spec that matches the pattern; I expected it to run all that match. > > I tried: > spec spec/models --pattern line_item > spec spec/models --pattern \*line_item\* > spec spec/models --pattern '*line_item*' > > all to no avail... > > > The pattern is passed to Dir.glob, referenced from the ./spec > directory in the project. It needs to be in the correct format given > those considerations. The three variations you tried all look for > files matching line_item in the ./spec directory, not its > subdirectories. Try this: > > spec spec/models --pattern "**/line_item*" > > > > Maybe I'll go look at the source.? That would be a concept. > > dwh > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.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 dansteinicke at gmail.com Wed Sep 23 14:54:04 2009 From: dansteinicke at gmail.com (DanS) Date: Wed, 23 Sep 2009 11:54:04 -0700 (PDT) Subject: [rspec-users] bmabey-fakefs Not Found Error when installing rspec 1.2.9.rc1 In-Reply-To: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> References: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> Message-ID: <6fd2edbe-444f-4a19-8697-3f8cf766adb8@o35g2000vbi.googlegroups.com> Thanks so much for the help on this. > [sudo] gem install rspec --prerelease This seemed to install version 1.2.8 not the 1.2.9.rc1 I was looking for. > > if you clone the git rep, just install it w/ the gem command: > > rake gem > [sudo] gem install pkg/rspec-1.2.9.rc1.gem This way did the trick for me. :) Thanks again for the help. Dan From dansteinicke at gmail.com Wed Sep 23 14:54:18 2009 From: dansteinicke at gmail.com (DanS) Date: Wed, 23 Sep 2009 11:54:18 -0700 (PDT) Subject: [rspec-users] bmabey-fakefs Not Found Error when installing rspec 1.2.9.rc1 In-Reply-To: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> References: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> Message-ID: <3979712d-71c3-4a4b-a06d-31b7b04cf68d@l34g2000vba.googlegroups.com> Thanks so much for the help on this. > [sudo] gem install rspec --prerelease This seemed to install version 1.2.8 not the 1.2.9.rc1 I was looking for. > > if you clone the git rep, just install it w/ the gem command: > > rake gem > [sudo] gem install pkg/rspec-1.2.9.rc1.gem This way did the trick for me. :) Thanks again for the help. Dan From denis at haskinferguson.net Wed Sep 23 15:00:28 2009 From: denis at haskinferguson.net (Denis Haskin) Date: Wed, 23 Sep 2009 15:00:28 -0400 Subject: [rspec-users] -- example ? (was Re: How to use --pattern ?) In-Reply-To: <57c63afe0909231138r3d1ed331l417c242a04db9c28@mail.gmail.com> References: <4ABA34D5.1040708@haskinferguson.net> <57c63afe0909230809q6a167bc7td48dbb59fc5ae616@mail.gmail.com> <4ABA67E8.7000704@haskinferguson.net> <57c63afe0909231138r3d1ed331l417c242a04db9c28@mail.gmail.com> Message-ID: <4ABA704C.6030100@haskinferguson.net> Reverse-engineering with --format e, it turns out --example is the *whole* example name, e.g. "LineItem should allow a offer code to be associated with it" So is there any *easy* way to run just a few files? Thx, dwh From dansteinicke at gmail.com Wed Sep 23 14:53:50 2009 From: dansteinicke at gmail.com (DanS) Date: Wed, 23 Sep 2009 11:53:50 -0700 (PDT) Subject: [rspec-users] bmabey-fakefs Not Found Error when installing rspec 1.2.9.rc1 In-Reply-To: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> References: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> Message-ID: <7b69236a-1ece-4f67-b5db-01875639a40f@s6g2000vbp.googlegroups.com> Thanks so much for the help on this. > [sudo] gem install rspec --prerelease This seemed to install version 1.2.8 not the 1.2.9.rc1 I was looking for. > > if you clone the git rep, just install it w/ the gem command: > > rake gem > [sudo] gem install pkg/rspec-1.2.9.rc1.gem This way did the trick for me. :) Thanks again for the help. Dan From dchelimsky at gmail.com Wed Sep 23 15:26:36 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Sep 2009 14:26:36 -0500 Subject: [rspec-users] bmabey-fakefs Not Found Error when installing rspec 1.2.9.rc1 In-Reply-To: <7b69236a-1ece-4f67-b5db-01875639a40f@s6g2000vbp.googlegroups.com> References: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> <7b69236a-1ece-4f67-b5db-01875639a40f@s6g2000vbp.googlegroups.com> Message-ID: <57c63afe0909231226i277eca6ap92269daa7df57dc7@mail.gmail.com> On Wed, Sep 23, 2009 at 1:53 PM, DanS wrote: > Thanks so much for the help on this. > >> [sudo] gem install rspec --prerelease > > This seemed to install version 1.2.8 not the 1.2.9.rc1 I was looking > for. What OS and ruby/rubygems version? The --prerelease flag is a fairly recent addition and may not work everywhere yet. > >> >> if you clone the git rep, just install it w/ the gem command: >> >> rake gem >> [sudo] gem install pkg/rspec-1.2.9.rc1.gem > This way did the trick for me. :) > > Thanks again for the help. > > Dan > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Sep 23 15:40:20 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Sep 2009 14:40:20 -0500 Subject: [rspec-users] -- example ? (was Re: How to use --pattern ?) In-Reply-To: <4ABA704C.6030100@haskinferguson.net> References: <4ABA34D5.1040708@haskinferguson.net> <57c63afe0909230809q6a167bc7td48dbb59fc5ae616@mail.gmail.com> <4ABA67E8.7000704@haskinferguson.net> <57c63afe0909231138r3d1ed331l417c242a04db9c28@mail.gmail.com> <4ABA704C.6030100@haskinferguson.net> Message-ID: <57c63afe0909231240s1b89c223hf466fa4bef4e032f@mail.gmail.com> On Wed, Sep 23, 2009 at 2:00 PM, Denis Haskin wrote: > Reverse-engineering with --format e, it turns out --example is the *whole* > example name, e.g. > "LineItem should allow a offer code to be associated with it" > > So is there any *easy* way to run just a few files? Right now there is not, though there will be better ways in the future. For now, the best thing to do is probably set up a rake task. The --pattern option can take a comma separated list of patterns, so you can just list out the files you want. You can also set up the rake task so it gets the pattern list from a file that lists the files you want one per line. Something like: Spec::Rake::SpecTask.new(:focused) do |t| t.spec_files = File.readlines('spec_files.txt').collect{|f| f.strip} end Then you can run 'rake spec:focused' and just copy the file names you want into spec_files.txt. That's probably the lowest overhead because it's easy to change what you're running but then stay focused on that set of files until you're ready to change. HTH, David > > Thx, > > dwh > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sfeley at gmail.com Wed Sep 23 15:45:03 2009 From: sfeley at gmail.com (Stephen Eley) Date: Wed, 23 Sep 2009 15:45:03 -0400 Subject: [rspec-users] bmabey-fakefs Not Found Error when installing rspec 1.2.9.rc1 In-Reply-To: References: Message-ID: <1fb4df0909231245x626ba50ci40e3e07cde04d05b@mail.gmail.com> On Wed, Sep 23, 2009 at 1:16 PM, DanS wrote: > > but I still get the same error after installing bmabey-fakefs. ?I > notice that "gem list" command shows this as "fakefs" and not "bmabey- > fakefs" but I don't know if this naming difference matters, or what to > do about it if it does. I'm glad you got the problem fixed by another route, but if it comes up again (or for the benefit of others): Most likely you hadn't added Github as a gem repository. The gem naming scheme you saw, "bmabey-fakefs," is how Github names all gems served out of its repository. It's not necessarily a _good_ way, and it's caused all sorts of headaches, but they stand by it due to their principle that no single Github repo is the "authoritative" one for a gem. To solve this problem permanently, run this on the command line at some point: > sudo gem sources --add http://gems.github.com If you just want to add Github to the repo list on a case-by-case basis, do this instead the next time you install a Github gem: > sudo gem install bmabey-fakefs --source http://gems.github.com -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From dansteinicke at gmail.com Wed Sep 23 16:20:09 2009 From: dansteinicke at gmail.com (DanS) Date: Wed, 23 Sep 2009 13:20:09 -0700 (PDT) Subject: [rspec-users] bmabey-fakefs Not Found Error when installing rspec 1.2.9.rc1 In-Reply-To: <57c63afe0909231226i277eca6ap92269daa7df57dc7@mail.gmail.com> References: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> <7b69236a-1ece-4f67-b5db-01875639a40f@s6g2000vbp.googlegroups.com> <57c63afe0909231226i277eca6ap92269daa7df57dc7@mail.gmail.com> Message-ID: > What OS and ruby/rubygems version? The --prerelease flag is a fairly > recent addition and may not work everywhere yet. Mac OS X 10.5.8 ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] gem 1.3.5 From dchelimsky at gmail.com Wed Sep 23 16:25:26 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Sep 2009 15:25:26 -0500 Subject: [rspec-users] bmabey-fakefs Not Found Error when installing rspec 1.2.9.rc1 In-Reply-To: References: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> <7b69236a-1ece-4f67-b5db-01875639a40f@s6g2000vbp.googlegroups.com> <57c63afe0909231226i277eca6ap92269daa7df57dc7@mail.gmail.com> Message-ID: <57c63afe0909231325i30c9f218l20734fe6f4518c3d@mail.gmail.com> On Wed, Sep 23, 2009 at 3:20 PM, DanS wrote: >> What OS and ruby/rubygems version? The --prerelease flag is a fairly >> recent addition and may not work everywhere yet. > > Mac OS X 10.5.8 > ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] > gem 1.3.5 And what do you see if you type this: gem q -rn rspec --prerelease From dansteinicke at gmail.com Wed Sep 23 16:41:02 2009 From: dansteinicke at gmail.com (DanS) Date: Wed, 23 Sep 2009 13:41:02 -0700 (PDT) Subject: [rspec-users] bmabey-fakefs Not Found Error when installing rspec 1.2.9.rc1 In-Reply-To: <57c63afe0909231325i30c9f218l20734fe6f4518c3d@mail.gmail.com> References: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> <7b69236a-1ece-4f67-b5db-01875639a40f@s6g2000vbp.googlegroups.com> <57c63afe0909231226i277eca6ap92269daa7df57dc7@mail.gmail.com> <57c63afe0909231325i30c9f218l20734fe6f4518c3d@mail.gmail.com> Message-ID: <720b376e-5d55-4d7b-a5d3-e1be3b949207@f10g2000vbf.googlegroups.com> > And what do you see if you type this: > > gem q -rn rspec --prerelease *** REMOTE GEMS *** ERROR: While executing gem ... (Gem::OperationNotSupportedError) Prereleases not supported on legacy repositories From dchelimsky at gmail.com Wed Sep 23 16:42:29 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Sep 2009 15:42:29 -0500 Subject: [rspec-users] bmabey-fakefs Not Found Error when installing rspec 1.2.9.rc1 In-Reply-To: <720b376e-5d55-4d7b-a5d3-e1be3b949207@f10g2000vbf.googlegroups.com> References: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> <7b69236a-1ece-4f67-b5db-01875639a40f@s6g2000vbp.googlegroups.com> <57c63afe0909231226i277eca6ap92269daa7df57dc7@mail.gmail.com> <57c63afe0909231325i30c9f218l20734fe6f4518c3d@mail.gmail.com> <720b376e-5d55-4d7b-a5d3-e1be3b949207@f10g2000vbf.googlegroups.com> Message-ID: <57c63afe0909231342m738038d3sb4f0e286e956730a@mail.gmail.com> On Wed, Sep 23, 2009 at 3:41 PM, DanS wrote: >> And what do you see if you type this: >> >> gem q -rn rspec --prerelease > > *** REMOTE GEMS *** > > ERROR: ?While executing gem ... (Gem::OperationNotSupportedError) > ? ?Prereleases not supported on legacy repositories Well that explains why you're not seeing --prerelease gems. What do you get from this: gem sources From dansteinicke at gmail.com Wed Sep 23 16:53:55 2009 From: dansteinicke at gmail.com (DanS) Date: Wed, 23 Sep 2009 13:53:55 -0700 (PDT) Subject: [rspec-users] bmabey-fakefs Not Found Error when installing rspec 1.2.9.rc1 In-Reply-To: <57c63afe0909231342m738038d3sb4f0e286e956730a@mail.gmail.com> References: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> <7b69236a-1ece-4f67-b5db-01875639a40f@s6g2000vbp.googlegroups.com> <57c63afe0909231226i277eca6ap92269daa7df57dc7@mail.gmail.com> <57c63afe0909231325i30c9f218l20734fe6f4518c3d@mail.gmail.com> <720b376e-5d55-4d7b-a5d3-e1be3b949207@f10g2000vbf.googlegroups.com> <57c63afe0909231342m738038d3sb4f0e286e956730a@mail.gmail.com> Message-ID: <01a5ceeb-0eee-44dc-ade0-8efa8b59a777@b18g2000vbl.googlegroups.com> > Well that explains why you're not seeing --prerelease gems. What do > you get from this: > > gem sources *** CURRENT SOURCES *** http://gems.rubyforge.org http://gems.rubyonrails.org http://gems.github.com -This is after I followed Stephen Eley's advice (thanks Stephen) and added github as a source. Not sure if that was there prior to that. From dchelimsky at gmail.com Wed Sep 23 17:00:31 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Sep 2009 16:00:31 -0500 Subject: [rspec-users] bmabey-fakefs Not Found Error when installing rspec 1.2.9.rc1 In-Reply-To: <01a5ceeb-0eee-44dc-ade0-8efa8b59a777@b18g2000vbl.googlegroups.com> References: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> <7b69236a-1ece-4f67-b5db-01875639a40f@s6g2000vbp.googlegroups.com> <57c63afe0909231226i277eca6ap92269daa7df57dc7@mail.gmail.com> <57c63afe0909231325i30c9f218l20734fe6f4518c3d@mail.gmail.com> <720b376e-5d55-4d7b-a5d3-e1be3b949207@f10g2000vbf.googlegroups.com> <57c63afe0909231342m738038d3sb4f0e286e956730a@mail.gmail.com> <01a5ceeb-0eee-44dc-ade0-8efa8b59a777@b18g2000vbl.googlegroups.com> Message-ID: <57c63afe0909231400p1696446bhbd978a0015323e26@mail.gmail.com> On Wed, Sep 23, 2009 at 3:53 PM, DanS wrote: >> Well that explains why you're not seeing --prerelease gems. What do >> you get from this: >> >> gem sources > > *** CURRENT SOURCES *** > > http://gems.rubyforge.org > http://gems.rubyonrails.org > http://gems.github.com > > -This is after I followed Stephen Eley's advice (thanks Stephen) and > added github as a source. ?Not sure if that was there prior to that. I've got this: $ gem sources *** CURRENT SOURCES *** http://gemcutter.org http://gems.rubyforge.org/ http://gems.github.com/ My guess is that the server at http://gems.rubyonrails.org needs to be updated. If you don't need that I'd remove it from your source list. You can always get gems from there with --source http://gems.rubyforge.org/ on the command line. $ gem sources -r http://gems.rubyonrails.org $ gem q -rn rspec --prerelease ???? From dansteinicke at gmail.com Wed Sep 23 17:23:01 2009 From: dansteinicke at gmail.com (DanS) Date: Wed, 23 Sep 2009 14:23:01 -0700 (PDT) Subject: [rspec-users] bmabey-fakefs Not Found Error when installing rspec 1.2.9.rc1 In-Reply-To: <57c63afe0909231400p1696446bhbd978a0015323e26@mail.gmail.com> References: <57c63afe0909231040r45d753bct9007663ce8d569bb@mail.gmail.com> <7b69236a-1ece-4f67-b5db-01875639a40f@s6g2000vbp.googlegroups.com> <57c63afe0909231226i277eca6ap92269daa7df57dc7@mail.gmail.com> <57c63afe0909231325i30c9f218l20734fe6f4518c3d@mail.gmail.com> <720b376e-5d55-4d7b-a5d3-e1be3b949207@f10g2000vbf.googlegroups.com> <57c63afe0909231342m738038d3sb4f0e286e956730a@mail.gmail.com> <01a5ceeb-0eee-44dc-ade0-8efa8b59a777@b18g2000vbl.googlegroups.com> <57c63afe0909231400p1696446bhbd978a0015323e26@mail.gmail.com> Message-ID: > My guess is that the server at http://gems.rubyonrails.org needs to be > updated. If you don't need that I'd remove it from your source list. > You can always get gems from there with --sourcehttp://gems.rubyforge.org/on the command line. > > $ gem sources -r ?http://gems.rubyonrails.org > $ gem q -rn rspec --prerelease > > ???? Success! After removing http://gems.rubyonrails.org as a source... gem q -rn rspec --prerelease *** REMOTE GEMS *** rspec (1.2.9.rc1, 1.2.7.rc1) rspec-rails (1.2.9.rc1, 1.2.7.rc1) Thanks for all the help. Hope it ends up helping some other folks too. From lists at ruby-forum.com Wed Sep 23 18:55:01 2009 From: lists at ruby-forum.com (Joel Young) Date: Thu, 24 Sep 2009 00:55:01 +0200 Subject: [rspec-users] TextMate bundle and Rails controller specs Message-ID: <5f107a7c989e81d893b754a8c15cecd7@ruby-forum.com> I've been following along with the examples in The RSpec Book (beta 10, Pragmatic Programmers), and I get a failure in the controller tests when I run them in TextMate, but not from the command line. I have the following code: app/controllers/messages_controller.rb: class MessagesController < ApplicationController def create Message.new params[:message] end end spec/controllers/messages_controller_spec.rb: require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe MessagesController, "POST create" do it "should build a new message" do Message.should_receive(:new).with("body" => "a quick brown fox") post :create, :message => { "body" => "a quick brown fox" } end it "should save the message" end If I run either rake spec or script/spec spec/controllers/messages_controller_spec.rb, I get 0 failures and 1 pending. In TextMate (after pulling the latest changes from git://github.com/dchelimsky/rspec-tmbundle.git), I get: MessagesController POST create should build a new message No action responded to create. Actions: add_helper, add_helper_for, flash, forget_variables_added_to_assigns, register_verify_after_each, render_proxy, template, unregister_verify_after_each, verify_rendered, and verify_rendered_proc /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:617 :in `call_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:610 :in `perform_action_without_benchmark' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/benchmarking.rb:68 :in `perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/benchmark.rb:17 :in `ms' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/benchmark.rb:17 :in `ms' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/benchmarking.rb:68 :in `perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/rescue.rb:160 :in `perform_action_without_flash' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/flash.rb:141 :in `perform_action' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:523 :in `send' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:523 :in `process_without_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:606 :in `sass_old_process' /Library/Ruby/Gems/1.8/gems/haml-2.2.5/lib/sass/plugin/rails.rb:19 :in `process' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/test_process.rb:559 :in `process_with_test' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/test_process.rb:439 :in `process' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/test_process.rb:395 :in `post' /Volumes/Users/joelyou/rspec/views_example/spec/controllers/messages_controller_spec.rb:7 /tmp/textmate-command-45977.rb:3 Ideas? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Sep 24 10:00:43 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 24 Sep 2009 09:00:43 -0500 Subject: [rspec-users] Issues with rspec 1.2.8 and ruby 1.9 In-Reply-To: <21f5fc600909240618l41c1f8c7of36e79d78612bd9c@mail.gmail.com> References: <21f5fc600909240618l41c1f8c7of36e79d78612bd9c@mail.gmail.com> Message-ID: <57c63afe0909240700p1b892c6ds26d7829b7bf2fff3@mail.gmail.com> On Thu, Sep 24, 2009 at 8:18 AM, Xavier To wrote: > Hi, > > I just tried upgrading to ruby 1.9 and rspec has been giving me strange > errors when I run them with "rake spec". I get for almost every test gives > me a "can't modify frozen object" > > The other thing that confuses me is the fact that running script/spec > spec/**/*.rb on the same project using ruby 1.9.1 doesn't give me any errors > at all but runs about 10 tests less... > > I posted the both outputs here http://gist.github.com/192712 > > Here's my environment info : > > xto at Phoenix:~$ ruby -v > ruby 1.9.1p243 (2009-07-16 revision 24175) [i686-linux] > > xto at Phoenix:~$ sudo gem19 list > [sudo] password for xto: > > *** LOCAL GEMS *** > > actionmailer (2.3.4, 2.3.2) > actionpack (2.3.4, 2.3.2) > activerecord (2.3.4, 2.3.2) > activeresource (2.3.4, 2.3.2) > activesupport (2.3.4, 2.3.2) > authlogic (2.1.2) > daemons (1.0.10) > eventmachine (0.12.8) > fastthread (1.0.7) > febeling-rubyzip (0.9.2) > gem-sane-binary (0.1.1) > hoe (2.3.3) > mysql (2.8.1) > passenger (2.2.5) > rack (1.0.0) > rails (2.3.4, 2.3.2) > rake (0.8.7) > rspec (1.2.8) > rspec-rails (1.2.7.1) > rubyforge (1.0.5) > rubygems-update (1.3.5) > spork (0.7.1) > test-unit (1.2.3) > thin (1.2.4) > ZenTest (4.1.4) > > Commands ran: > rake spec > script/spec spec/**/*.rb > > If there any more info needed to enlightnen me on this issue, let me know. Please post at least one of the examples (with the implementation code) that is failing this way, and also please run the spec w/ --backtrace and post the full backtrace for the same example you're posting. Thx > > Thanks for taking the time to check this out. > > Xavier > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From eric at ingroup.com Thu Sep 24 20:13:54 2009 From: eric at ingroup.com (Eric Hahn) Date: Thu, 24 Sep 2009 17:13:54 -0700 Subject: [rspec-users] DRYing out controller specs? Message-ID: <0182C5CBA6D9D040B7F41888529D1905BFD255C456@EXVMBX016-2.exch016.msoutlookonline.net> I'd like to DRY out my controller specs but am having difficulties doing so and am hopeful that a more experienced rspec expert can shed some much-needed light on my woes... The controllers themselves are using josevalim's wonderful inherited_resources gem, so they are incredibly small - I'm basically looking for something like this on the rspec side... I'm hoping to find a way to: * Define a set of shared examples for each of the 7 common RESTful actions (index, show, new, edit, create, update, destroy) * include those shared examples in a number of controllers (ApplesController, OrangesController) * obviously have the shared examples know about the model names, something like: assigns[@model_name.to_sym].should be_new_record # GET .../new * not so obviously have the description of the example reflect the model names: it "should delete the #{@model_name}" do * be very DRY: Ideally, apples_controller_spec and oranges_controller_spec would be small: mostly about initialization of config (e.g. the model name) and include the various shared specs which tested the controller. I've played around with a lot of approaches, but cannot figure out a clean pattern in which variables such as @model_name are scoped visible to the 'it' descriptions AND the example blocks. I'm probably missing some wonderful clean ruby-way of doing this. Thoughts/advice much appreciated! -Eric From sfeley at gmail.com Thu Sep 24 22:04:47 2009 From: sfeley at gmail.com (Stephen Eley) Date: Thu, 24 Sep 2009 22:04:47 -0400 Subject: [rspec-users] DRYing out controller specs? In-Reply-To: <0182C5CBA6D9D040B7F41888529D1905BFD255C456@EXVMBX016-2.exch016.msoutlookonline.net> References: <0182C5CBA6D9D040B7F41888529D1905BFD255C456@EXVMBX016-2.exch016.msoutlookonline.net> Message-ID: <1fb4df0909241904v7531db12saaf79901d5ac3d84@mail.gmail.com> On Thu, Sep 24, 2009 at 8:13 PM, Eric Hahn wrote: > > The controllers themselves are using josevalim's wonderful inherited_resources gem, so they are incredibly small - I'm basically looking for something like this on the rspec side... (*googling*) Aha. Looks a lot like the old make_resourceful, resource_controller, and resources_controller plugins. Not sure I agree with his choice to drive it by class inheritance rather than module inclusion, though. Seems like it might be pretty fragile -- which he corroborates with his note that RSpec in standard controller isolation mode breaks it. > I've played around with a lot of approaches, but cannot figure out a clean pattern in which variables such as @model_name are scoped visible to the 'it' descriptions AND the example blocks. ?I'm probably missing some wonderful clean ruby-way of doing this. Class variables may be your friend here, since the "it" descriptions are really akin to method definitions and therefore declared at the class level. That said, though: I have to wonder if it's a good idea to have so much magic that all of your controller specs now declare themselves almost completely in shared examples. That makes the behavior specification invisible, at least at a fast code glance. Half the reason I write specs is because typing them makes me take a moment to think about the behavior I want. If your controllers are _so_ uniform that you not only don't have to write them, you don't have to write the _specs_ for them -- then why test them? Why not just make sure your inherited_resources suite has a thorough set of specs, and trust it to act consistently, only spec'ing the variances? (Yes, this is sort of a cynic's view. It's the same reason I eventually stopped using make_resourceful -- too much magic. The actual meat of my controllers was so well-hidden that I found myself looking at the plugin's docs constantly just to remember what my own application did.) -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From lists at ruby-forum.com Fri Sep 25 03:07:46 2009 From: lists at ruby-forum.com (Mithun Perera) Date: Fri, 25 Sep 2009 09:07:46 +0200 Subject: [rspec-users] Need Help In-Reply-To: <98286041539419c67480f06ee7ee4dbb@ruby-forum.com> References: <4edfa1d1a36284246d74ad1b254f8541@ruby-forum.com> <98286041539419c67480f06ee7ee4dbb@ruby-forum.com> Message-ID: <43266d4809196c801e9fc4ac97c1e873@ruby-forum.com> Mithun Perera wrote: > Mithun Perera wrote: >> Hi all, >> I am an university student and these days i am on training period. So i >> want to know about ruby on on rails "cucumber and Rspec". If somebody >> know about these fields please help me. If not please send me an >> tutorials for basic functionality of the cucumber and Rspec. >> Thank you. >> regards, >> Mithun Perera > > Hi all, > I found one tutorial. > http://www.ultrasaurus.com/sarahblog/2008/12/rails-2-day-3-behavior-driven-development/#setup > > if u found new one please kind enough to send me reply. > > Mithun Perera Hi all, Again i found a blog for tutorials for cucumber http://jeewanthajtk.blogspot.com/ here ther is a subject called Working with Ruby on Rails Cucumber From the Beginning(Part I) try this if u need help. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Sep 25 05:56:25 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 25 Sep 2009 04:56:25 -0500 Subject: [rspec-users] How to spec transaction in Controller ? In-Reply-To: <1686952703@web.de> References: <1686952703@web.de> Message-ID: <57c63afe0909250256he025804u15dae10f2c3ec957@mail.gmail.com> On Fri, Sep 25, 2009 at 3:06 AM, Andrea Jahn wrote: > Hi, > > in my Controller I have some tansactions. I'm trying to write specs, which test the two program pathes (an exception is thrown or no exception is thrown). But the test seems always to go into the path, where the exception is catched. > > Here's an example for the delete action > (destroy method is overwritten, so :dependent => :destroy is not possible here) Off topic, but ActiveRecord offers a number of ways to interact with model and transaction life cycles. The fact that you are overriding destroy rather than hooking into the destroy cycle means you're bypassing a lot of functionality that you now have to implement yourself (hence the problem you are describing in this post). If there is any way for you to use those hooks instead, I'd strongly recommend it. > > The test case? "should flash the notice" fails, because not the program path of success is executed, but the rescue path is executed. > > Perhaps my exception handling is generally wrong ? > > Thanks > Andrea > > plannings_controller.rb > ----------------------- > > ????? def destroy > ??????? @planning = Physical::Planning::Planning.find(params[:id]) > > ??????? respond_to do |format| > ????????? begin > ??????????? ActiveRecord::Base.transaction do > ????????????? @planning.destroy > ????????????? @planning.planned_amounts.each { |planned_amount| planned_amount.destroy } > ??????????? end Even if you've overridden destroy, why not just include this code in the custom destroy method? Then the controller could just call @planning.destroy and that method can worry about transactions. > ??????????? # success > ??????????? flash[:notice] = "The #{Physical::Planning::Planning::DISPLAY_NAME.downcase} '" + @planning.title + "' was successfully deleted." > ??????????? format.html { redirec t_to(planning_plannings_url) } > ??????????? format.xml? { head :ok } > ????????? rescue => e > ??????????? # DB raised errors > ??????????? flash[:error] = "The #{Physical::Planning::Planning::DISPLAY_NAME.downcase} '" + (@planning.nil? ? "" : @planning.title) + "' could not be deleted. Error:" + e > ??????????? format.html { redirect_to(planning_plannings_url) } > ??????????? format.xml? { render :xml => @planning.errors, :status => :unprocessable_entity } > ????????? end > ??????? end > ????? end > > > > plannings_co ntroller_spec.rb > ---------------------------- > > describe Physical::Planning::PlanningsController, "DELETE" do > ? include PlanningMacros > > ? should_require_login :put, :delete > ? should_require_authorization :put, :delete > > ? context "when the user is logged in" do > ??? before(:each) do > ????? do_login > ????? do_authorization > > ????? @planning = mock_model(Physical::Planning::Planning, valid_planning_attributes) > ????? @planned_amount = mock_model(Physical::Planning::PlannedAmount, valid_planned_amount_attributes) > > ????? @planning.stub!(:destroy) > ????? @planning.stub!(:planned_amounts).and_return([@planned_amount]) > > ????? Physical::Planning::Planning.stub!(:find).and_return(@planning) > > ????? @plan ning.errors.stub!(:full_messages).and_return([]) > ??? end > > ??? # delete successfully > ??? # ------------------- > > ??? context "and the Planning deletes successfully" do > > ????? .... > > ????? it "should destroy the Physical::Planning::Planning in a transaction" do > ??????? Physical::Planning::Planning.should_receive(:transaction).any_number_of_times.and_yield( > ????????? @planning.should_receive(:destroy) > ??????? ) This ^^ isn't doing anything. any_number_of_times includes 0, which is the number of times Planning (the class object) receives transaction (the controller calls ActiveRecord::Base.transaction). I'd recommend leaving out any_number_of_times. By default, should_receive expects exactly one call, which is the right number in this case. And it should be on ActiveRecord::Base, given the current state of the implementation. This, however, is a great example of how writing examples first can have a positive impact on design. If I were writing this, I never would have specified transactions in a controller action. This example would simply be: it "should destroy the Physical::Planning::Planning in a transaction" do @planning.should_receive(:destroy) do_put_delete end Then the implementation would only need call @planning.destroy to pass the example. The transactional nature of the destroy method would be specified in the model spec, and now any other code that gets written later that needs to destroy a Planning instance can just send it destroy() and you won't have to duplicate this transaction code in each of those cases. HTH, David > ??????? do_put_delete > ????? end > > ????? it "should destroy the PlannedAmounts of the Physical::Planning::Planning in a transaction" do > ??????? Physical::Planning::Planning.should_receive (:transaction).any_number_of_times.and_yield( > ????????? @planned_amount.should_receive(:destroy) > ??????? ) > ??????? do_put_delete > ????? end > > ????? it "should flash the notice" do > ??????? do_put_delete > ??????? flash[:notice].should match(/was successfully deleted/) > ????? end > > ????? ... > > ??? end > > ??? # delete fails > ??? # ------------ > ??? context "and the Planning fails to delete" do > > ????? it "should flash error message because of database exception" do > ??????? Physical::Planning::Planning.should_receive(:transaction).any_ number_of_times.and_yield( > ????????? @planning.should_receive(:destroy).and_raise(ActiveRecord::RecordInvalid.new(@planning)) > ??????? ) > ??????? do_put_delete > ??????? flash[:error].should match(/could not be deleted/) > ????? end > ??? end > ? end > end From matt at mattwynne.net Fri Sep 25 09:04:14 2009 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 25 Sep 2009 14:04:14 +0100 Subject: [rspec-users] Need Help In-Reply-To: <43266d4809196c801e9fc4ac97c1e873@ruby-forum.com> References: <4edfa1d1a36284246d74ad1b254f8541@ruby-forum.com> <98286041539419c67480f06ee7ee4dbb@ruby-forum.com> <43266d4809196c801e9fc4ac97c1e873@ruby-forum.com> Message-ID: <25FFFD4C-C26D-4E3F-B7E6-2CEB7657AF15@mattwynne.net> On 25 Sep 2009, at 08:07, Mithun Perera wrote: > Mithun Perera wrote: >> Mithun Perera wrote: >>> Hi all, >>> I am an university student and these days i am on training period. >>> So i >>> want to know about ruby on on rails "cucumber and Rspec". If >>> somebody >>> know about these fields please help me. If not please send me an >>> tutorials for basic functionality of the cucumber and Rspec. >>> Thank you. >>> regards, >>> Mithun Perera >> >> Hi all, >> I found one tutorial. >> http://www.ultrasaurus.com/sarahblog/2008/12/rails-2-day-3-behavior-driven-development/#setup >> >> if u found new one please kind enough to send me reply. >> >> Mithun Perera > > > > Hi all, > > Again i found a blog for tutorials for cucumber > http://jeewanthajtk.blogspot.com/ > here ther is a subject called Working with Ruby on Rails Cucumber From > the Beginning(Part I) > > try this if u need help. Actually I that blog post a pretty crappy introduction to Cucumber: it's poorly written and has some inaccurate content. I would recommend the screencasts on the Cucumber homepage: http://cukes.info/ Particularly this one: http://railscasts.com/episodes/155-beginning-with-cucumber cheers, Matt http://mattwynne.net +447974 430184 From lists at ruby-forum.com Sat Sep 26 02:56:14 2009 From: lists at ruby-forum.com (Giuseppe Bertini) Date: Sat, 26 Sep 2009 08:56:14 +0200 Subject: [rspec-users] controller specs with non-RESTful routes In-Reply-To: <0a7959070e320038d584186684c70880@ruby-forum.com> References: <0a7959070e320038d584186684c70880@ruby-forum.com> Message-ID: <4053820556ad980f7d781655aeb99b40@ruby-forum.com> Pretty please? :) -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sat Sep 26 05:15:12 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 26 Sep 2009 04:15:12 -0500 Subject: [rspec-users] controller specs with non-RESTful routes In-Reply-To: <4053820556ad980f7d781655aeb99b40@ruby-forum.com> References: <0a7959070e320038d584186684c70880@ruby-forum.com> <4053820556ad980f7d781655aeb99b40@ruby-forum.com> Message-ID: <57c63afe0909260215v4e0f6f28k16dcd5f496d5a452@mail.gmail.com> On Sat, Sep 26, 2009 at 1:56 AM, Giuseppe Bertini wrote: > Pretty please? :) Huh? Pretty please what? Matt and I have both responded. In my case I asked you about the versions you have. You didn't quote any of the previous posts in this thread, so I have no idea what you're asking for at this point. Did you receive our responses? From lists at ruby-forum.com Sat Sep 26 09:10:48 2009 From: lists at ruby-forum.com (Giuseppe Bertini) Date: Sat, 26 Sep 2009 15:10:48 +0200 Subject: [rspec-users] controller specs with non-RESTful routes In-Reply-To: <57c63afe0909260215v4e0f6f28k16dcd5f496d5a452@mail.gmail.com> References: <0a7959070e320038d584186684c70880@ruby-forum.com> <4053820556ad980f7d781655aeb99b40@ruby-forum.com> <57c63afe0909260215v4e0f6f28k16dcd5f496d5a452@mail.gmail.com> Message-ID: > Huh? Pretty please what? Matt and I have both responded. In my case I > asked you about the versions you have. You didn't quote any of the > previous posts in this thread, so I have no idea what you're asking > for at this point. Did you receive our responses? So sorry, I must be missing something. I am looking right now at this page: http://www.ruby-forum.com/topic/195172 And what I see is my original post, my own "pretty please" and your "Huh?", period. Looking at the index page (http://www.ruby-forum.com/forum/32) does not help. I'm wondering--am I looking at the wrong forum page? But then, why do I see your latest response (and received the email notification I requested), but not the previous? Sorry for the trouble, I would appreciate if you could point me to the proper URL, if this is the problem. Thanks a bunch, Giuseppe -- Posted via http://www.ruby-forum.com/. From borjam at dagi3d.net Sat Sep 26 10:04:55 2009 From: borjam at dagi3d.net (=?UTF-8?Q?Borja_Mart=C3=ADn?=) Date: Sat, 26 Sep 2009 16:04:55 +0200 Subject: [rspec-users] undefined method `and_return' In-Reply-To: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> References: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> Message-ID: <8d8b110e0909260704h7335d0aand57bb2f4d42a1e95@mail.gmail.com> Hi, I got the same error while writing an extension for Spree and found this thread through Google. It seems it's caused by the jeremymcanally-stump[1] gem used by the application. You should use the syntax shown in the documentation http://github.com/jeremymcanally/stump Regards On Wed, Aug 26, 2009 at 1:19 AM, Oliver Barnes wrote: > Hello, > > I'm struggling with this controller spec for a few hours now > > http://pastie.org/594775 > > which is failing with an error I can't find any references about, > neither on the list nor on the web in general: > > Admin::ImagesController handling PUT /images/1 with successful update > should find the image requested > undefined method `and_return' for # > > /Users/oliver/Sites/spree/spec/controllers/admin/images_controller_spec.rb:17 > /tmp/textmate-command-1859.rb:3 > 15 before(:each) do > 16 @image = mock_model(Image, :to_param => "1") > 17 Image.stub!(:find).and_return(@image) > 18 end > > why would and_return() not be recognized, while stub!() is? > > has anybody experienced this problem before? I'm using rspec and > rspec-rails at version 1.2.6, with Rails 2.3.2, while customizing > Spree 0.8.99 > > thanks > Oliver > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- def dagi3d(me) case me when :web then "http://dagi3d.net" when :twitter then "http://twitter.com/dagi3d" end end -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sat Sep 26 10:28:12 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 26 Sep 2009 09:28:12 -0500 Subject: [rspec-users] controller specs with non-RESTful routes In-Reply-To: References: <0a7959070e320038d584186684c70880@ruby-forum.com> <4053820556ad980f7d781655aeb99b40@ruby-forum.com> <57c63afe0909260215v4e0f6f28k16dcd5f496d5a452@mail.gmail.com> Message-ID: <57c63afe0909260728i3f990004x535bca99b318c012@mail.gmail.com> On Sat, Sep 26, 2009 at 8:10 AM, Giuseppe Bertini wrote: >> Huh? Pretty please what? Matt and I have both responded. In my case I >> asked you about the versions you have. You didn't quote any of the >> previous posts in this thread, so I have no idea what you're asking >> for at this point. Did you receive our responses? > > So sorry, I must be missing something. > I am looking right now at this page: > > http://www.ruby-forum.com/topic/195172 Well - that _should_ be one of two correct URLs. The forum is mirrored w/ a google group. I see there are posts missing from the forum, but I see all the posts in the google group: http://groups.google.com/group/rspec/browse_thread/thread/8c079724053b5ce7 We don't offer much help, as Matt doesn't see a problem and I can't reproduce it - but at least we tried to play :) > > And what I see is my original post, my own "pretty please" and your > "Huh?", period. > > Looking at the index page (http://www.ruby-forum.com/forum/32) does not > help. > > I'm wondering--am I looking at the wrong forum page? But then, why do I > see your latest response (and received the email notification I > requested), but not the previous? > > Sorry for the trouble, I would appreciate if you could point me to the > proper URL, if this is the problem. > > Thanks a bunch, > Giuseppe > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sfeley at gmail.com Sat Sep 26 10:53:09 2009 From: sfeley at gmail.com (Stephen Eley) Date: Sat, 26 Sep 2009 10:53:09 -0400 Subject: [rspec-users] controller specs with non-RESTful routes In-Reply-To: <57c63afe0909260728i3f990004x535bca99b318c012@mail.gmail.com> References: <0a7959070e320038d584186684c70880@ruby-forum.com> <4053820556ad980f7d781655aeb99b40@ruby-forum.com> <57c63afe0909260215v4e0f6f28k16dcd5f496d5a452@mail.gmail.com> <57c63afe0909260728i3f990004x535bca99b318c012@mail.gmail.com> Message-ID: <1fb4df0909260753j7508ef5bt3c9bba8c87284a34@mail.gmail.com> On Sat, Sep 26, 2009 at 10:28 AM, David Chelimsky wrote: > > We don't offer much help, as Matt doesn't see a problem and I can't > reproduce it - but at least we tried to play :) I'll take a turn! Helps me procrastinate on my own stuff. >8-> Giuseppe: have you tried running 'rake routes' to see what the application thinks you valid routes are? Reconciling that with what's going on in routes.rb is a good next step. Also, when testing behavior has me stumped, I often remember far too late to open up my Web browser and poke at the pages directly, as a human being. I'll often see error messages that way that RSpec doesn't think to show me, or I can view source and see what the links in my form _really_ are. Those aren't direct answers (I'm with Matt, I don't see anything wrong here unless something else in routes.rb is conflicting with the line you posted) but they've been useful tactics for me in the past. -- Have Fun, ? Steve Eley (sfeley at gmail.com) ? ESCAPE POD - The Science Fiction Podcast Magazine ? http://www.escapepod.org From giuseppe.bertini at gmail.com Sat Sep 26 10:44:29 2009 From: giuseppe.bertini at gmail.com (giuseb) Date: Sat, 26 Sep 2009 07:44:29 -0700 (PDT) Subject: [rspec-users] controller specs with non-RESTful routes In-Reply-To: <57c63afe0909260728i3f990004x535bca99b318c012@mail.gmail.com> References: <0a7959070e320038d584186684c70880@ruby-forum.com> <4053820556ad980f7d781655aeb99b40@ruby-forum.com> <57c63afe0909260215v4e0f6f28k16dcd5f496d5a452@mail.gmail.com> <57c63afe0909260728i3f990004x535bca99b318c012@mail.gmail.com> Message-ID: <03efcbb2-78a5-4048-b5b4-4f4894b63c0b@d4g2000vbm.googlegroups.com> > > So sorry, I must be missing something. > > I am looking right now at this page: > > >http://www.ruby-forum.com/topic/195172 > > Well - that _should_ be one of two correct URLs. The forum is mirrored > w/ a google group. I see there are posts missing from the forum, but I > see all the posts in the google group Yes, now I see, thanks. So, back to the original issue, I have rails 2.3.4, rspec 1.2.8, rspec- rails 1.2.7.1, ruby 1.8.6 (universal darwin9.0) I too have created a new app with only the above-mentioned code added to the rails-generated and rspec-generated stuff. I am still getting the "No route matches..." error I have posted the app here: git://github.com/giuseb/spec_named_route.git I am somewhat nervous that this is going to turn out a silly mistake on my part as Matt suggested, but still... Giuseppe From dchelimsky at gmail.com Sat Sep 26 11:00:21 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 26 Sep 2009 10:00:21 -0500 Subject: [rspec-users] controller specs with non-RESTful routes In-Reply-To: <03efcbb2-78a5-4048-b5b4-4f4894b63c0b@d4g2000vbm.googlegroups.com> References: <0a7959070e320038d584186684c70880@ruby-forum.com> <4053820556ad980f7d781655aeb99b40@ruby-forum.com> <57c63afe0909260215v4e0f6f28k16dcd5f496d5a452@mail.gmail.com> <57c63afe0909260728i3f990004x535bca99b318c012@mail.gmail.com> <03efcbb2-78a5-4048-b5b4-4f4894b63c0b@d4g2000vbm.googlegroups.com> Message-ID: <57c63afe0909260800o2d6ea839ge38d5d2583afde8e@mail.gmail.com> On Sat, Sep 26, 2009 at 9:44 AM, giuseb wrote: >> > So sorry, I must be missing something. >> > I am looking right now at this page: >> >> >http://www.ruby-forum.com/topic/195172 >> >> Well - that _should_ be one of two correct URLs. The forum is mirrored >> w/ a google group. I see there are posts missing from the forum, but I >> see all the posts in the google group > > Yes, now I see, thanks. > So, back to the original issue, I have rails 2.3.4, rspec 1.2.8, rspec- > rails 1.2.7.1, ruby 1.8.6 (universal darwin9.0) > > I too have created a new app with only the above-mentioned code added > to the rails-generated and rspec-generated stuff. I am still getting > the "No route matches..." error > > I have posted the app here: > git://github.com/giuseb/spec_named_route.git > > I am somewhat nervous that this is going to turn out a silly mistake > on my part as Matt suggested, but still... > > Giuseppe Thanks for posting the app - that was very helpful. I've got good news and bad news: The good news is that I hadn't set up my routes as cleanly as yours, and when I did I was able to reproduce the error. The bad news is that this is a deficiency the underlying Rails testing framework that rspec-rails wraps. I tried the same example in a rails functional test and got the same failure: class InvitationsControllerTest < ActionController::TestCase test "the post accept invitation should be successful" do get :accept, :id => "1" assert_response :success end end test_the_post_accept_invitation_should_be_successful(InvitationsControllerTest): ActionController::RoutingError: No route matches {:action=>"accept", :controller=>"invitations", :id=>"1"} /test/functional/invitations_controller_test.rb:6:in `test_the_post_accept_invitation_should_be_successful' You wanna raise a ticket in the rails lighthouse? From giuseppe.bertini at gmail.com Sat Sep 26 12:49:02 2009 From: giuseppe.bertini at gmail.com (giuseb) Date: Sat, 26 Sep 2009 09:49:02 -0700 (PDT) Subject: [rspec-users] controller specs with non-RESTful routes In-Reply-To: <57c63afe0909260800o2d6ea839ge38d5d2583afde8e@mail.gmail.com> References: <0a7959070e320038d584186684c70880@ruby-forum.com> <4053820556ad980f7d781655aeb99b40@ruby-forum.com> <57c63afe0909260215v4e0f6f28k16dcd5f496d5a452@mail.gmail.com> <57c63afe0909260728i3f990004x535bca99b318c012@mail.gmail.com> <03efcbb2-78a5-4048-b5b4-4f4894b63c0b@d4g2000vbm.googlegroups.com> <57c63afe0909260800o2d6ea839ge38d5d2583afde8e@mail.gmail.com> Message-ID: > The bad news is that this is a deficiency the underlying Rails testing > framework that rspec-rails wraps. I tried the same example in a rails > functional test and got the same failure: > > class InvitationsControllerTest < ActionController::TestCase > > ? test "the post accept invitation should be successful" do > ? ? get :accept, :id => "1" > ? ? assert_response :success > ? end > end > > test_the_post_accept_invitation_should_be_successful(InvitationsControllerTest): > ActionController::RoutingError: No route matches {:action=>"accept", > :controller=>"invitations", :id=>"1"} > ? ? /test/functional/invitations_controller_test.rb:6:in > `test_the_post_accept_invitation_should_be_successful' > > You wanna raise a ticket in the rails lighthouse? I just did--my very first ticket!! Two more things: - I noticed that you tested a get request, while i was doing post. Tried them both again, same outcome. - what did your "unclean" routes look like that did NOT cause the problem? Thanks, Giuseppe From dchelimsky at gmail.com Sat Sep 26 13:41:40 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 26 Sep 2009 12:41:40 -0500 Subject: [rspec-users] controller specs with non-RESTful routes In-Reply-To: References: <0a7959070e320038d584186684c70880@ruby-forum.com> <4053820556ad980f7d781655aeb99b40@ruby-forum.com> <57c63afe0909260215v4e0f6f28k16dcd5f496d5a452@mail.gmail.com> <57c63afe0909260728i3f990004x535bca99b318c012@mail.gmail.com> <03efcbb2-78a5-4048-b5b4-4f4894b63c0b@d4g2000vbm.googlegroups.com> <57c63afe0909260800o2d6ea839ge38d5d2583afde8e@mail.gmail.com> Message-ID: <57c63afe0909261041h41ce29c3i2e1471d27c378c78@mail.gmail.com> On Sat, Sep 26, 2009 at 11:49 AM, giuseb wrote: >> The bad news is that this is a deficiency the underlying Rails testing >> framework that rspec-rails wraps. I tried the same example in a rails >> functional test and got the same failure: >> >> class InvitationsControllerTest < ActionController::TestCase >> >> ? test "the post accept invitation should be successful" do >> ? ? get :accept, :id => "1" >> ? ? assert_response :success >> ? end >> end >> >> test_the_post_accept_invitation_should_be_successful(InvitationsControllerTest): >> ActionController::RoutingError: No route matches {:action=>"accept", >> :controller=>"invitations", :id=>"1"} >> ? ? /test/functional/invitations_controller_test.rb:6:in >> `test_the_post_accept_invitation_should_be_successful' >> >> You wanna raise a ticket in the rails lighthouse? > > I just did--my very first ticket!! > > Two more things: > - I noticed that you tested a get request, while i was doing post. Oh yeah - I had tried both and copied the wrong one in the email :) > Tried them both again, same outcome. > - what did your "unclean" routes look like that did NOT cause the > problem? Just the defaults: map.connect ':controller/:action/:id' HTH > > Thanks, > Giuseppe > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From giuseppe.bertini at gmail.com Sat Sep 26 18:03:58 2009 From: giuseppe.bertini at gmail.com (giuseb) Date: Sat, 26 Sep 2009 15:03:58 -0700 (PDT) Subject: [rspec-users] controller specs with non-RESTful routes In-Reply-To: <1fb4df0909260753j7508ef5bt3c9bba8c87284a34@mail.gmail.com> References: <0a7959070e320038d584186684c70880@ruby-forum.com> <4053820556ad980f7d781655aeb99b40@ruby-forum.com> <57c63afe0909260215v4e0f6f28k16dcd5f496d5a452@mail.gmail.com> <57c63afe0909260728i3f990004x535bca99b318c012@mail.gmail.com> <1fb4df0909260753j7508ef5bt3c9bba8c87284a34@mail.gmail.com> Message-ID: <87252342-b391-4e57-bd83-e5b7bd45de73@h30g2000vbr.googlegroups.com> Steve, > Giuseppe: have you tried running 'rake routes' to see what the > application thinks you valid routes are? ?Reconciling that with what's > going on in routes.rb is a good next step. The following line is the whole of the 'rake routes' output: accept_invitation /accept_invitation/:id {:action=>"accept", :method=>"get", :controller=>"invitations"} > Also, when testing behavior has me stumped, I often remember far too > late to open up my Web browser and poke at the pages directly, as a > human being. I did visit: http://localhost:3000/accept_invitation/1 and the request gets properly routed by the app. As David pointed out earlier today, this behavior appears to be related to rails' testing framework, rather than to rspec. I have raised a ticket in the rails lighthouse: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3263-failing-functional-test-of-a-named-route Cheers, Giuseppe From bcardarella at gmail.com Sun Sep 27 22:10:20 2009 From: bcardarella at gmail.com (Brian Cardarella) Date: Sun, 27 Sep 2009 19:10:20 -0700 (PDT) Subject: [rspec-users] rspec-rails question Message-ID: <860e329d-d1fe-45d2-84b7-a4313408faba@m20g2000vbp.googlegroups.com> I have this controller test: http://pastie.org/632880 And the show method has not been written for the HomeController yet. However, the test still passes. Why? From dchelimsky at gmail.com Sun Sep 27 23:05:48 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 27 Sep 2009 22:05:48 -0500 Subject: [rspec-users] rspec-rails question In-Reply-To: <860e329d-d1fe-45d2-84b7-a4313408faba@m20g2000vbp.googlegroups.com> References: <860e329d-d1fe-45d2-84b7-a4313408faba@m20g2000vbp.googlegroups.com> Message-ID: <57c63afe0909272005q2644e533vf3dec4ee3a7d24de@mail.gmail.com> On Sun, Sep 27, 2009 at 9:10 PM, Brian Cardarella wrote: > I have this controller test: http://pastie.org/632880 ?And the show > method has not been written for the HomeController yet. However, the > test still passes. Why? Hey Brian, This is due to a bug that has already been fixed: https://rspec.lighthouseapp.com/projects/5645/tickets/888 It is fixed in the 1.2.9.rc1 gems, so if you grab those you should be good: [sudo] gem install rspec-rails --prerelease Cheers, David From ed.howland at gmail.com Mon Sep 28 00:24:29 2009 From: ed.howland at gmail.com (Ed Howland) Date: Sun, 27 Sep 2009 23:24:29 -0500 Subject: [rspec-users] Mailing list for BDD? Message-ID: <3df642dd0909272124t593c1399xa97729860a9ff9c4@mail.gmail.com> Sorry for the cross post, but does anyone know of a list dedicated to just BDD? Seems like all the discussion is happening over on rspec-users, some on the tdd list. My interest is in the abstract concept of behavior driven design/development, as expressed by Dave Astels and Dan North and others.As opposed to a specific framework, like rSpec, ScrewUnit and others. Would it be appropriate to create such a list, if none exists? Thanks. -- Ed Howland http://greenprogrammer.blogspot.com http://twitter.com/ed_howland From bcardarella at gmail.com Mon Sep 28 00:36:37 2009 From: bcardarella at gmail.com (Brian Cardarella) Date: Sun, 27 Sep 2009 21:36:37 -0700 (PDT) Subject: [rspec-users] rspec-rails question In-Reply-To: <57c63afe0909272005q2644e533vf3dec4ee3a7d24de@mail.gmail.com> References: <860e329d-d1fe-45d2-84b7-a4313408faba@m20g2000vbp.googlegroups.com> <57c63afe0909272005q2644e533vf3dec4ee3a7d24de@mail.gmail.com> Message-ID: Excellent, that did the trick. Thanks Dave! On Sep 27, 11:05?pm, David Chelimsky wrote: > On Sun, Sep 27, 2009 at 9:10 PM, Brian Cardarella wrote: > > I have this controller test:http://pastie.org/632880?And the show > > method has not been written for the HomeController yet. However, the > > test still passes. Why? > > Hey Brian, > > This is due to a bug that has already been fixed: > > https://rspec.lighthouseapp.com/projects/5645/tickets/888 > > It is fixed in the 1.2.9.rc1 gems, so if you grab those you should be good: > > [sudo] gem install rspec-rails --prerelease > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From ben at benmabey.com Mon Sep 28 00:53:34 2009 From: ben at benmabey.com (Ben Mabey) Date: Sun, 27 Sep 2009 22:53:34 -0600 Subject: [rspec-users] Mailing list for BDD? In-Reply-To: <3df642dd0909272124t593c1399xa97729860a9ff9c4@mail.gmail.com> References: <3df642dd0909272124t593c1399xa97729860a9ff9c4@mail.gmail.com> Message-ID: <4AC0414E.4040707@benmabey.com> Ed Howland wrote: > Sorry for the cross post, but does anyone know of a list dedicated to > just BDD? Seems like all the discussion is happening over on > rspec-users, some on the tdd list. > > My interest is in the abstract concept of behavior driven > design/development, as expressed by Dave Astels and Dan North and > others.As opposed to a specific framework, like rSpec, ScrewUnit and > others. > > Would it be appropriate to create such a list, if none exists? > > Thanks. > http://groups.google.com/group/behaviordrivendevelopment From dchelimsky at gmail.com Mon Sep 28 03:20:42 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 28 Sep 2009 02:20:42 -0500 Subject: [rspec-users] rspec-rails question In-Reply-To: References: <860e329d-d1fe-45d2-84b7-a4313408faba@m20g2000vbp.googlegroups.com> <57c63afe0909272005q2644e533vf3dec4ee3a7d24de@mail.gmail.com> Message-ID: <57c63afe0909280020t34d50869i51051697cb7308f4@mail.gmail.com> Glad to hear it. Please let me know how the 1.2.9.rc1 gems are working otherwise for you. I've gotten zero feedback, positive or negative, on these release candidate gems and I'd like to do the release sometime this week. Cheers, David On Sun, Sep 27, 2009 at 11:36 PM, Brian Cardarella wrote: > Excellent, that did the trick. Thanks Dave! > > On Sep 27, 11:05?pm, David Chelimsky wrote: >> On Sun, Sep 27, 2009 at 9:10 PM, Brian Cardarella wrote: >> > I have this controller test:http://pastie.org/632880?And the show >> > method has not been written for the HomeController yet. However, the >> > test still passes. Why? >> >> Hey Brian, >> >> This is due to a bug that has already been fixed: >> >> https://rspec.lighthouseapp.com/projects/5645/tickets/888 >> >> It is fixed in the 1.2.9.rc1 gems, so if you grab those you should be good: >> >> [sudo] gem install rspec-rails --prerelease >> >> Cheers, >> David >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Sep 28 03:22:02 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 28 Sep 2009 02:22:02 -0500 Subject: [rspec-users] feedback on 1.2.9.rc1 Message-ID: <57c63afe0909280022l1f20a681p5d36d13b2b762c05@mail.gmail.com> Hey all, I haven't received any feedback on the rspec and rspec-rails-1.2.9.rc1 gems. Is anybody using them? Any issues? TIA, David From ashley.moran at patchspace.co.uk Mon Sep 28 11:11:53 2009 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 28 Sep 2009 16:11:53 +0100 Subject: [rspec-users] feedback on 1.2.9.rc1 In-Reply-To: <57c63afe0909280022l1f20a681p5d36d13b2b762c05@mail.gmail.com> References: <57c63afe0909280022l1f20a681p5d36d13b2b762c05@mail.gmail.com> Message-ID: <7C7A5606-A6F6-43DB-941D-7554D9E954C0@patchspace.co.uk> On Sep 28, 2009, at 8:22 am, David Chelimsky wrote: > I haven't received any feedback on the rspec and rspec-rails-1.2.9.rc1 > gems. Is anybody using them? Any issues? I was going to upgrade to test it, but MacPorts rubygems is still on 1.3.4, is there a downside to installing this pr-release gem without upgrading to gems 1.3.5? Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran http://aviewfromafar.net/ From oli.azevedo.barnes at gmail.com Mon Sep 28 13:02:44 2009 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Mon, 28 Sep 2009 14:02:44 -0300 Subject: [rspec-users] undefined method `and_return' In-Reply-To: <8d8b110e0909260704h7335d0aand57bb2f4d42a1e95@mail.gmail.com> References: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> <8d8b110e0909260704h7335d0aand57bb2f4d42a1e95@mail.gmail.com> Message-ID: <6466d9040909281002u48b7799ekc259015d07882866@mail.gmail.com> thanks! had given up on this already. changing to the new syntax Image.stub!(:find, :return => @image) did get me past the error. I still can't get this spec to pass though: http://pastie.org/633580 updated spec: http://pastie.org/633584 and the controller being spec'ed: http://pastie.org/633586 2009/9/26 Borja Mart?n : > Hi, > I got the same error while writing an extension for Spree and found this > thread through Google. It seems it's caused by the jeremymcanally-stump[1] > gem used by the application. You should use the syntax shown in the > documentation > > http://github.com/jeremymcanally/stump > > Regards > > On Wed, Aug 26, 2009 at 1:19 AM, Oliver Barnes > wrote: >> >> Hello, >> >> I'm struggling with this controller spec for a few hours now >> >> http://pastie.org/594775 >> >> which is failing with an error I can't find any references about, >> neither on the list nor on the web in general: >> >> Admin::ImagesController handling PUT /images/1 with successful update >> should find the image requested >> undefined method `and_return' for # >> >> /Users/oliver/Sites/spree/spec/controllers/admin/images_controller_spec.rb:17 >> /tmp/textmate-command-1859.rb:3 >> 15 ? ? ?before(:each) do >> 16 ? ? ? ?@image = mock_model(Image, :to_param => "1") >> 17 ? ? ? ?Image.stub!(:find).and_return(@image) >> 18 ? ? ?end >> >> why would and_return() not be recognized, while stub!() is? >> >> has anybody experienced this problem before? I'm using rspec and >> rspec-rails at version 1.2.6, with Rails 2.3.2, while customizing >> Spree 0.8.99 >> >> thanks >> Oliver >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > def dagi3d(me) > ?case me > ? ?when :web then ?"http://dagi3d.net" > ? ?when :twitter then "http://twitter.com/dagi3d" > ?end > end > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Sep 28 23:36:36 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 28 Sep 2009 22:36:36 -0500 Subject: [rspec-users] feedback on 1.2.9.rc1 In-Reply-To: <7C7A5606-A6F6-43DB-941D-7554D9E954C0@patchspace.co.uk> References: <57c63afe0909280022l1f20a681p5d36d13b2b762c05@mail.gmail.com> <7C7A5606-A6F6-43DB-941D-7554D9E954C0@patchspace.co.uk> Message-ID: <57c63afe0909282036s52bc74eci538981285fe7707@mail.gmail.com> On Mon, Sep 28, 2009 at 10:11 AM, Ashley Moran wrote: > > On Sep 28, 2009, at 8:22 am, David Chelimsky wrote: > >> I haven't received any feedback on the rspec and rspec-rails-1.2.9.rc1 >> gems. Is anybody using them? Any issues? > > I was going to upgrade to test it, but MacPorts rubygems is still on 1.3.4, > is there a downside to installing this pr-release gem without upgrading to > gems 1.3.5? I ran into some problems using rubygems to uninstall prerelease gems but I don't remember when that got fixed. If you're feeling bold, I'd say go for it, and then if you run into trouble you can always manually remove them from your system gems directories. It might even work just fine :) > > Ashley > > -- > http://www.patchspace.co.uk/ > http://www.linkedin.com/in/ashleymoran > http://aviewfromafar.net/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Sep 28 23:48:46 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 28 Sep 2009 22:48:46 -0500 Subject: [rspec-users] undefined method `and_return' In-Reply-To: <6466d9040909281002u48b7799ekc259015d07882866@mail.gmail.com> References: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> <8d8b110e0909260704h7335d0aand57bb2f4d42a1e95@mail.gmail.com> <6466d9040909281002u48b7799ekc259015d07882866@mail.gmail.com> Message-ID: <57c63afe0909282048y15c8a229s9a8eb0515edc820b@mail.gmail.com> On Mon, Sep 28, 2009 at 12:02 PM, Oliver Barnes wrote: > thanks! had given up on this already. changing to the new syntax > > ?Image.stub!(:find, :return => @image) Not sure where you got this syntax from, but it doesn't do anything. Options are: Image.stub(:find).and_return(@image) Image.stub(:find => @image) Image.stub(:find) { @image } You can also use stub! in all 3 forms. > > did get me past the error. > > I still can't get this spec to pass though: > > http://pastie.org/633580 > > updated spec: > > http://pastie.org/633584 > > and the controller being spec'ed: > > http://pastie.org/633586 > > > > > > 2009/9/26 Borja Mart?n : >> Hi, >> I got the same error while writing an extension for Spree and found this >> thread through Google. It seems it's caused by the jeremymcanally-stump[1] >> gem used by the application. You should use the syntax shown in the >> documentation >> >> http://github.com/jeremymcanally/stump >> >> Regards >> >> On Wed, Aug 26, 2009 at 1:19 AM, Oliver Barnes >> wrote: >>> >>> Hello, >>> >>> I'm struggling with this controller spec for a few hours now >>> >>> http://pastie.org/594775 >>> >>> which is failing with an error I can't find any references about, >>> neither on the list nor on the web in general: >>> >>> Admin::ImagesController handling PUT /images/1 with successful update >>> should find the image requested >>> undefined method `and_return' for # >>> >>> /Users/oliver/Sites/spree/spec/controllers/admin/images_controller_spec.rb:17 >>> /tmp/textmate-command-1859.rb:3 >>> 15 ? ? ?before(:each) do >>> 16 ? ? ? ?@image = mock_model(Image, :to_param => "1") >>> 17 ? ? ? ?Image.stub!(:find).and_return(@image) >>> 18 ? ? ?end >>> >>> why would and_return() not be recognized, while stub!() is? >>> >>> has anybody experienced this problem before? I'm using rspec and >>> rspec-rails at version 1.2.6, with Rails 2.3.2, while customizing >>> Spree 0.8.99 >>> >>> thanks >>> Oliver >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> >> -- >> def dagi3d(me) >> ?case me >> ? ?when :web then ?"http://dagi3d.net" >> ? ?when :twitter then "http://twitter.com/dagi3d" >> ?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 oli.azevedo.barnes at gmail.com Tue Sep 29 00:35:40 2009 From: oli.azevedo.barnes at gmail.com (Oliver Barnes) Date: Tue, 29 Sep 2009 01:35:40 -0300 Subject: [rspec-users] undefined method `and_return' In-Reply-To: <57c63afe0909282048y15c8a229s9a8eb0515edc820b@mail.gmail.com> References: <6466d9040908251619l4b533971m14d95f5730fae493@mail.gmail.com> <8d8b110e0909260704h7335d0aand57bb2f4d42a1e95@mail.gmail.com> <6466d9040909281002u48b7799ekc259015d07882866@mail.gmail.com> <57c63afe0909282048y15c8a229s9a8eb0515edc820b@mail.gmail.com> Message-ID: <6466d9040909282135p5f92701bnc4c869ff23d51e26@mail.gmail.com> Hi David, I followed Borja's suggestion (message before mine). he had the same problem on a spree project, and traced it down to its use of the stump gem's helpers, which require a different syntax http://github.com/jeremymcanally/stump 2009/9/29 David Chelimsky : > On Mon, Sep 28, 2009 at 12:02 PM, Oliver Barnes > wrote: >> thanks! had given up on this already. changing to the new syntax >> >> ?Image.stub!(:find, :return => @image) > > Not sure where you got this syntax from, but it doesn't do anything. > Options are: > > Image.stub(:find).and_return(@image) > Image.stub(:find => @image) > Image.stub(:find) { @image } > > You can also use stub! in all 3 forms. > >> >> did get me past the error. >> >> I still can't get this spec to pass though: >> >> http://pastie.org/633580 >> >> updated spec: >> >> http://pastie.org/633584 >> >> and the controller being spec'ed: >> >> http://pastie.org/633586 >> >> >> >> >> >> 2009/9/26 Borja Mart?n : >>> Hi, >>> I got the same error while writing an extension for Spree and found this >>> thread through Google. It seems it's caused by the jeremymcanally-stump[1] >>> gem used by the application. You should use the syntax shown in the >>> documentation >>> >>> http://github.com/jeremymcanally/stump >>> >>> Regards >>> >>> On Wed, Aug 26, 2009 at 1:19 AM, Oliver Barnes >>> wrote: >>>> >>>> Hello, >>>> >>>> I'm struggling with this controller spec for a few hours now >>>> >>>> http://pastie.org/594775 >>>> >>>> which is failing with an error I can't find any references about, >>>> neither on the list nor on the web in general: >>>> >>>> Admin::ImagesController handling PUT /images/1 with successful update >>>> should find the image requested >>>> undefined method `and_return' for # >>>> >>>> /Users/oliver/Sites/spree/spec/controllers/admin/images_controller_spec.rb:17 >>>> /tmp/textmate-command-1859.rb:3 >>>> 15 ? ? ?before(:each) do >>>> 16 ? ? ? ?@image = mock_model(Image, :to_param => "1") >>>> 17 ? ? ? ?Image.stub!(:find).and_return(@image) >>>> 18 ? ? ?end >>>> >>>> why would and_return() not be recognized, while stub!() is? >>>> >>>> has anybody experienced this problem before? I'm using rspec and >>>> rspec-rails at version 1.2.6, with Rails 2.3.2, while customizing >>>> Spree 0.8.99 >>>> >>>> thanks >>>> Oliver >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> >>> >>> -- >>> def dagi3d(me) >>> ?case me >>> ? ?when :web then ?"http://dagi3d.net" >>> ? ?when :twitter then "http://twitter.com/dagi3d" >>> ?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 >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From enrico.teotti at gmail.com Tue Sep 29 04:08:14 2009 From: enrico.teotti at gmail.com (Enrico Teotti) Date: Tue, 29 Sep 2009 18:08:14 +1000 Subject: [rspec-users] params_for and :requirements from DB In-Reply-To: References: Message-ID: I was wrong, the Model.valid_values wasn't returning the good stuff. So: step 1. Model.should_receive!(:valid_values).and_return(/my_value_foo/) step 2. (and this is a must) ActionController::Routing::Routes.reload! and it all works like a charm. enrico From elliot.winkler at gmail.com Tue Sep 29 14:07:35 2009 From: elliot.winkler at gmail.com (Elliot Winkler) Date: Tue, 29 Sep 2009 11:07:35 -0700 (PDT) Subject: [rspec-users] spec --drb always has a successful exit code even when specs fail Message-ID: <0343374e-1cf0-4c03-9be3-3b97ac85bd45@o41g2000yqb.googlegroups.com> Okay, so what I'm trying to do is write a rake task that runs my specs and then, if they succeed, run svn commit. (In lieu of continuous integration since I want it to happen semi-manually for now.) So basically I'm running 'rake spec' and then checking the exit status. However, I seem to have to run into a bug with RSpec. This is similar to this bug report in Cucumber [1]. I'm using spork to run my specs, so naturally I'm using the --drb option. However, I've noticed that when doing so (tested using just 'spec SOME_FILE --drb'), 'spec' will always return an exit code of 0. Ultimately this means that 'rake spec' always returns an exit code of 0 too. I've tried to take the patch applied to Cucumber and apply it to RSpec but obviously the two are not built quite the same. I've looked inside the RSpec code and here's what I think I've figured out so far. So it looks like when --drb is passed, OptionParser#parse_drb is eventually called. And it looks like what that does is tell spork to run the tests via DRb, and then since tests are already being run, it tells itself to not run the tests by saying @options.examples_should_not_be_run. Simple enough. However, jump to Options#run_examples. That returns true if the examples should not be run. But uh-oh, that means Spec::Runner::CommandLine.run (and also Spec::Runner.run) returns true. Which means that 'spec' is essentially saying 'exit true', and then when Spec::Runner.autorun is called the same thing happens. Does this look right or am I off track here? If so, how complicated would it be to fix RSpec so the exit status depends on whatever spork returns? -- Elliot [1]: https://rspec.lighthouseapp.com/projects/16211/tickets/355-exit-code-is-always-0-with-drb-despite-failure From ignu.smith at gmail.com Tue Sep 29 22:37:44 2009 From: ignu.smith at gmail.com (ignu) Date: Tue, 29 Sep 2009 19:37:44 -0700 (PDT) Subject: [rspec-users] Can't run specs after upgrading gems... get 0 tests, 0 assertions... Message-ID: <128f4f21-00e0-4627-ab9a-71049b10cb80@l13g2000yqb.googlegroups.com> So after I updated all my gems, I started getting: /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/ dependencies.rb:105:in `const_missing': uninitialized constant Test::Unit::TestResult::TestResultFailureSupport (NameError) from /Library/Ruby/Gems/1.8/gems/test-unit-2.0.3/lib/test/unit/ testresult.rb:28 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/ active_support/dependencies.rb:158:in `require' from /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/interop/test.rb: 8 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/ active_support/dependencies.rb:158:in `require' from /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/test/unit.rb:1 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/ active_support/dependencies.rb:158:in `require' from /Library/Ruby/Gems/1.8/gems/rspec-rails-1.2.7.1/lib/spec/ rails.rb:13 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/ active_support/dependencies.rb:158:in `require' from /Users/ignu/code/surveighor/spec/spec_helper.rb:6 Then I added config.gem 'test-unit', :lib => 'test/unit' to environment.rb Now I get: 0 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications And I can't figure out why. :-( Any ideas? From dchelimsky at gmail.com Tue Sep 29 23:49:35 2009 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 29 Sep 2009 22:49:35 -0500 Subject: [rspec-users] Can't run specs after upgrading gems... get 0 tests, 0 assertions... In-Reply-To: <128f4f21-00e0-4627-ab9a-71049b10cb80@l13g2000yqb.googlegroups.com> References: <128f4f21-00e0-4627-ab9a-71049b10cb80@l13g2000yqb.googlegroups.com> Message-ID: <57c63afe0909292049p2aea80c5kfd0818bcff872ef8@mail.gmail.com> On Tue, Sep 29, 2009 at 9:37 PM, ignu wrote: > > So after I updated all my gems, I started getting: > > /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/ > dependencies.rb:105:in `const_missing': uninitialized constant > Test::Unit::TestResult::TestResultFailureSupport (NameError) > ? ? ? ?from /Library/Ruby/Gems/1.8/gems/test-unit-2.0.3/lib/test/unit/ > testresult.rb:28 > ? ? ? ?from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `gem_original_require' > ? ? ? ?from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `require' > ? ? ? ?from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/ > active_support/dependencies.rb:158:in `require' > ? ? ? ?from /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/interop/test.rb: > 8 > ? ? ? ?from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `gem_original_require' > ? ? ? ?from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `require' > ? ? ? ?from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/ > active_support/dependencies.rb:158:in `require' > ? ? ? ?from /Library/Ruby/Gems/1.8/gems/rspec-1.2.8/lib/spec/test/unit.rb:1 > ? ? ? ?from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `gem_original_require' > ? ? ? ?from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `require' > ? ? ? ?from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/ > active_support/dependencies.rb:158:in `require' > ? ? ? ?from /Library/Ruby/Gems/1.8/gems/rspec-rails-1.2.7.1/lib/spec/ > rails.rb:13 > ? ? ? ?from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `gem_original_require' > ? ? ? ?from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in > `require' > ? ? ? ?from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/ > active_support/dependencies.rb:158:in `require' > ? ? ? ?from /Users/ignu/code/surveighor/spec/spec_helper.rb:6 What versions of rails, rspec and rspec-rails were you using successfully before you did this upgrade? Did you run "script/generate rspec"? Were you seeing test/unit output before the upgrade? > > > Then I added > > ?config.gem 'test-unit', :lib => 'test/unit' > > to environment.rb > > Now I get: > > ?0 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, 0 > omissions, 0 notifications > > And I can't figure out why. ?:-( > > Any ideas? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Wed Sep 30 01:53:58 2009 From: lists at ruby-forum.com (Mithun Perera) Date: Wed, 30 Sep 2009 07:53:58 +0200 Subject: [rspec-users] Need immeadiate help Message-ID: Hi all, I am going to do testing using Rspec. But i have no idea about that . so i need good tutorial for that. if anybody has such tutorials please help me by sending them. thanks, mithun -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Wed Sep 30 02:59:09 2009 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 30 Sep 2009 07:59:09 +0100 Subject: [rspec-users] Need immeadiate help In-Reply-To: References: Message-ID: <3063B0A7-53D9-4C59-8BAE-241E80CE16F7@mattwynne.net> On 30 Sep 2009, at 06:53, Mithun Perera wrote: > Hi all, > I am going to do testing using Rspec. But i have no idea about > that . so > i need good tutorial for that. if anybody has such tutorials please > help me by sending them. > thanks, > mithun http://blog.davidchelimsky.net/2007/05/14/an-introduction-to-rspec-part-i/ cheers, Matt http://mattwynne.net +447974 430184 From lists at ruby-forum.com Wed Sep 30 07:37:39 2009 From: lists at ruby-forum.com (Mithun Perera) Date: Wed, 30 Sep 2009 13:37:39 +0200 Subject: [rspec-users] Need immeadiate help In-Reply-To: <3063B0A7-53D9-4C59-8BAE-241E80CE16F7@mattwynne.net> References: <3063B0A7-53D9-4C59-8BAE-241E80CE16F7@mattwynne.net> Message-ID: <745c2ad845760ff7d93f9a82fa24597c@ruby-forum.com> Matt Wynne wrote: > On 30 Sep 2009, at 06:53, Mithun Perera wrote: > >> Hi all, >> I am going to do testing using Rspec. But i have no idea about >> that . so >> i need good tutorial for that. if anybody has such tutorials please >> help me by sending them. >> thanks, >> mithun > > http://blog.davidchelimsky.net/2007/05/14/an-introduction-to-rspec-part-i/ > > > > cheers, > Matt > > http://mattwynne.net > +447974 430184 thanks Matt Any other tutorial because i go through it..... but no idea. cheers, jeewantha -- Posted via http://www.ruby-forum.com/. From jarkster at gmail.com Wed Sep 30 08:32:08 2009 From: jarkster at gmail.com (Jarkko Laine) Date: Wed, 30 Sep 2009 15:32:08 +0300 Subject: [rspec-users] Need immeadiate help In-Reply-To: <745c2ad845760ff7d93f9a82fa24597c@ruby-forum.com> References: <3063B0A7-53D9-4C59-8BAE-241E80CE16F7@mattwynne.net> <745c2ad845760ff7d93f9a82fa24597c@ruby-forum.com> Message-ID: On 30.9.2009, at 14.37, Mithun Perera wrote: > thanks Matt > Any other tutorial because i go through it..... but no idea. > cheers, http://lmgtfy.com/?q=rspec+introduction+tutorial //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi From richard.e.hart at googlemail.com Wed Sep 30 19:56:31 2009 From: richard.e.hart at googlemail.com (Hates_) Date: Wed, 30 Sep 2009 16:56:31 -0700 (PDT) Subject: [rspec-users] Grabbing the controller name before a new test case Message-ID: <43dab9cd-e17c-42ba-ba43-7fb55ffe9940@e12g2000yqi.googlegroups.com> I currently have: describe Publishers::PagesController I want to be able to grab the path "publishers/pages/ and use that to generate a load of tests automatically. Problem is I can't figure out how to do it outside of my "it" block. Any help is greatly appreciated. Richard