From lists at ruby-forum.com Mon Feb 1 04:30:26 2010 From: lists at ruby-forum.com (Amit Kulkarni) Date: Mon, 1 Feb 2010 10:30:26 +0100 Subject: [rspec-users] testing controllers using cucumber In-Reply-To: <2ADC6B7D-E312-49FC-B8A7-20A26582DDED@reprocessed.org> References: <2ADC6B7D-E312-49FC-B8A7-20A26582DDED@reprocessed.org> Message-ID: <17ceb2c39cb786ae6f03858257225c7c@ruby-forum.com> Oh ok. >From your code it seems that we are checking the whole app as you mentioned. I have tested controllers using rspec. So i am not getting which is better to use. Since with Rspec we test the objects and here using cucumber(good for writing scenarios and understanding)we are testing the GUI part(using webrat). So which is good to use and more effective -- Posted via http://www.ruby-forum.com/. From phillipkoebbe at gmail.com Mon Feb 1 09:53:32 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Mon, 01 Feb 2010 08:53:32 -0600 Subject: [rspec-users] somewhat confused by the help instructions... In-Reply-To: <57c63afe1001311808x7086cfefr3b1abe569a7150cf@mail.gmail.com> References: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> <57c63afe1001300638h15cc15eai8c97d15634197ec3@mail.gmail.com> <57c63afe1001311251i67a56d6am8bf1c32d1604b833@mail.gmail.com> <4B65FC61.6080209@gmail.com> <4B661224.6060002@gmail.com> <57c63afe1001311808x7086cfefr3b1abe569a7150cf@mail.gmail.com> Message-ID: <4B66EAEC.30906@gmail.com> David Chelimsky wrote: > Agreed: > > http://github.com/rspec/rspec-core/blob/master/features/command_line/example_name_option.feature Thanks, David. I don't want to sound all gushy or anything, but you have got to be one of the most helpful, courteous, knowledgable people I have encountered in all my days on the internet. Thanks for all that you do for all the communities you participate in. Peace, Phillip From phillipkoebbe at gmail.com Mon Feb 1 10:14:19 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Mon, 01 Feb 2010 09:14:19 -0600 Subject: [rspec-users] Testing controller plugin Message-ID: <4B66EFCB.2010302@gmail.com> I have just recently started creating some plugins, mainly of the controller variety. I have been looking for a tutorial or other documentation detailing how to go about testing these plugins with RSpec, but have not yet found anything helpful. Can anyone point me toward such a thing? Thanks, Phillip From matt at mattwynne.net Mon Feb 1 11:20:41 2010 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 1 Feb 2010 16:20:41 +0000 Subject: [rspec-users] Testing controller plugin In-Reply-To: <4B66EFCB.2010302@gmail.com> References: <4B66EFCB.2010302@gmail.com> Message-ID: On 1 Feb 2010, at 15:14, Phillip Koebbe wrote: > I have just recently started creating some plugins, mainly of the > controller variety. I have been looking for a tutorial or other > documentation detailing how to go about testing these plugins with > RSpec, but have not yet found anything helpful. Can anyone point me > toward such a thing? Create a controller in your specs which uses the plugin in an exemplary way, then asserts the behaviour of that controller. cheers, Matt http://mattwynne.net +447974 430184 From matt at mattwynne.net Mon Feb 1 11:20:58 2010 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 1 Feb 2010 16:20:58 +0000 Subject: [rspec-users] somewhat confused by the help instructions... In-Reply-To: <4B66EAEC.30906@gmail.com> References: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> <57c63afe1001300638h15cc15eai8c97d15634197ec3@mail.gmail.com> <57c63afe1001311251i67a56d6am8bf1c32d1604b833@mail.gmail.com> <4B65FC61.6080209@gmail.com> <4B661224.6060002@gmail.com> <57c63afe1001311808x7086cfefr3b1abe569a7150cf@mail.gmail.com> <4B66EAEC.30906@gmail.com> Message-ID: On 1 Feb 2010, at 14:53, Phillip Koebbe wrote: > > > David Chelimsky wrote: >> Agreed: >> >> http://github.com/rspec/rspec-core/blob/master/features/command_line/example_name_option.feature > > Thanks, David. > > I don't want to sound all gushy or anything, but you have got to be > one of the most helpful, courteous, knowledgable people I have > encountered in all my days on the internet. +1 > > Thanks for all that you do for all the communities you participate in. > > Peace, > Phillip > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From cwdinfo at gmail.com Mon Feb 1 12:24:21 2010 From: cwdinfo at gmail.com (steve ross) Date: Mon, 1 Feb 2010 09:24:21 -0800 Subject: [rspec-users] testing controllers using cucumber In-Reply-To: <17ceb2c39cb786ae6f03858257225c7c@ruby-forum.com> References: <2ADC6B7D-E312-49FC-B8A7-20A26582DDED@reprocessed.org> <17ceb2c39cb786ae6f03858257225c7c@ruby-forum.com> Message-ID: <44337845-3337-4DB7-BAFE-2438F1C66B2D@gmail.com> On Feb 1, 2010, at 1:30 AM, Amit Kulkarni wrote: > > Oh ok. >> From your code it seems that we are checking the whole app as you > mentioned. > I have tested controllers using rspec. > So i am not getting which is better to use. > Since with Rspec we test the objects and here using cucumber(good for > writing scenarios and understanding)we are testing the GUI part(using > webrat). > So which is good to use and more effective From my perspective, and this is just opinion, it depends on how granular you want your test and how fast it has to run. If you want to test the whole stack, then Cuke is great and it *will* exercise the controller. However, it does it more in the way a user might and can miss some edge cases. However, if you have a set of very specific behaviors like how a controller should respond to various mime types or what exceptions might be raised in certain circumstances, it might be better done using rSpec. Also, typically, a given rSpec test is faster because it doesn't have to load the whole Rails stack and you can mock or stub irrelevant parts. Just my $.02. From rick.denatale at gmail.com Mon Feb 1 14:36:19 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 1 Feb 2010 14:36:19 -0500 Subject: [rspec-users] somewhat confused by the help instructions... In-Reply-To: <4B66EAEC.30906@gmail.com> References: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> <57c63afe1001300638h15cc15eai8c97d15634197ec3@mail.gmail.com> <57c63afe1001311251i67a56d6am8bf1c32d1604b833@mail.gmail.com> <4B65FC61.6080209@gmail.com> <4B661224.6060002@gmail.com> <57c63afe1001311808x7086cfefr3b1abe569a7150cf@mail.gmail.com> <4B66EAEC.30906@gmail.com> Message-ID: On Mon, Feb 1, 2010 at 9:53 AM, Phillip Koebbe wrote: > I don't want to sound all gushy or anything, but you have got to be one of > the most helpful, courteous, knowledgable people I have encountered in all > my days on the internet. Not to mention that he plays a mean guitar! -- 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 joe at josephwilk.net Mon Feb 1 15:07:35 2010 From: joe at josephwilk.net (Joseph Wilk) Date: Mon, 01 Feb 2010 20:07:35 +0000 Subject: [rspec-users] somewhat confused by the help instructions... In-Reply-To: References: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> <57c63afe1001300638h15cc15eai8c97d15634197ec3@mail.gmail.com> <57c63afe1001311251i67a56d6am8bf1c32d1604b833@mail.gmail.com> <4B65FC61.6080209@gmail.com> <4B661224.6060002@gmail.com> <57c63afe1001311808x7086cfefr3b1abe569a7150cf@mail.gmail.com> <4B66EAEC.30906@gmail.com> Message-ID: <4B673487.9010104@josephwilk.net> On 01/02/2010 16:20, Matt Wynne wrote: > > On 1 Feb 2010, at 14:53, Phillip Koebbe wrote: > >> >> >> David Chelimsky wrote: >>> Agreed: >>> >>> http://github.com/rspec/rspec-core/blob/master/features/command_line/example_name_option.feature >>> >> >> Thanks, David. >> >> I don't want to sound all gushy or anything, but you have got to be >> one of the most helpful, courteous, knowledgable people I have >> encountered in all my days on the internet. > > +1 + 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000^100000000000000000000000 > >> >> Thanks for all that you do for all the communities you participate in. >> >> Peace, >> Phillip >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > cheers, > Matt > > http://mattwynne.net > +447974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jbrainsberger at gmail.com Mon Feb 1 19:30:13 2010 From: jbrainsberger at gmail.com (J. B. Rainsberger) Date: Mon, 1 Feb 2010 19:30:13 -0500 Subject: [rspec-users] GET a path in a controller spec In-Reply-To: References: Message-ID: On Sun, Jan 31, 2010 at 17:02, Nick Hoffman wrote: > One of my controller actions sends a redirect if the request URI begins > with /foods/search > > ?34 ?def search > ?35 ? ?return redirect_to "/#{params[:name]}" if > request.request_uri.match /^\/foods\/search/ > > Unfortunately, I can't figure out how to spec this. Do you want to check that search redirects, or the algorithm for computing the redirect path? I would probably check the algorithm separately, then stub the algorithm to check the redirect. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. From ssmithstone at me.com Tue Feb 2 04:24:22 2010 From: ssmithstone at me.com (Stephen Smithstone) Date: Tue, 02 Feb 2010 09:24:22 +0000 Subject: [rspec-users] Specting controller post Message-ID: <4B67EF46.2000604@me.com> An HTML attachment was scrubbed... URL: From jbrainsberger at gmail.com Tue Feb 2 07:07:56 2010 From: jbrainsberger at gmail.com (J. B. Rainsberger) Date: Tue, 2 Feb 2010 07:07:56 -0500 Subject: [rspec-users] Specting controller post In-Reply-To: <4B67EF46.2000604@me.com> References: <4B67EF46.2000604@me.com> Message-ID: On Tue, Feb 2, 2010 at 04:24, Stephen Smithstone wrote: > A bit stuck here being new to ruby and rspec Welcome. I hope you like the experience. Good news: we've seen what you've done a thousand times and so it's quite easy to explain. > it "should create new client" do > ??? // creates me a hash of generated values using Foregey > ??? client = Client.plan > ??? // specify that I should be creating a new client with the hash values > from client > ??? Client.should_receive(:new).with(client) > ??? //post to the server > ??? post 'create' , :client => client > end > > in my controller > > def create > ??? client = Client.new(params[:client]) > end > > now this is failing with > > Spec::Mocks::MockExpectationError: datetime, updated_at: datetime, title: string, lastname: string, firstname: > string, email: string) (class)> received :new with unexpected arguments > ? expected: ({:title=>"Mr", :firstname=>"Ernest", :lastname=>"Burke", > :email=>"rgarrett at blogtag.info"}) > ?????? got: ({"title"=>"Mr", "lastname"=>"Burke", "firstname"=>"Ernest", > "email"=>"rgarrett at blogtag.info"}) > > is there a way to specify to use symbols instead of the strings as keys, as > I dont want to be doing > > :client => { "title" => client.title , ............ } > > as the client model may change over time Try Client.should_receive(:new).with(client.attributes), because the #attributes method turns a model into a Hash of symbol to value. It uses string keys instead of symbol keys, but that shouldn't hurt you. Good luck. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. From stephen.smithstone at gmail.com Tue Feb 2 07:26:47 2010 From: stephen.smithstone at gmail.com (Stephen Smithstone) Date: Tue, 2 Feb 2010 12:26:47 +0000 Subject: [rspec-users] Specting controller post In-Reply-To: References: <4B67EF46.2000604@me.com> Message-ID: cheers for the response , seem that attributes is missing from hash on my system all i did was the blueprint with a standard hash client = { :title => "Mr } client.attributes NoMethodError: undefined method `attributes' for {:title=>"Mr"}:Hash is attributes added on by rails ? if so my setup must be wrong On 2 February 2010 12:07, J. B. Rainsberger wrote: > On Tue, Feb 2, 2010 at 04:24, Stephen Smithstone > wrote: > > > A bit stuck here being new to ruby and rspec > > Welcome. I hope you like the experience. Good news: we've seen what > you've done a thousand times and so it's quite easy to explain. > > > it "should create new client" do > > // creates me a hash of generated values using Foregey > > client = Client.plan > > // specify that I should be creating a new client with the hash > values > > from client > > Client.should_receive(:new).with(client) > > //post to the server > > post 'create' , :client => client > > end > > > > in my controller > > > > def create > > client = Client.new(params[:client]) > > end > > > > now this is failing with > > > > Spec::Mocks::MockExpectationError: > datetime, updated_at: datetime, title: string, lastname: string, > firstname: > > string, email: string) (class)> received :new with unexpected arguments > > expected: ({:title=>"Mr", :firstname=>"Ernest", :lastname=>"Burke", > > :email=>"rgarrett at blogtag.info"}) > > got: ({"title"=>"Mr", "lastname"=>"Burke", "firstname"=>"Ernest", > > "email"=>"rgarrett at blogtag.info"}) > > > > is there a way to specify to use symbols instead of the strings as keys, > as > > I dont want to be doing > > > > :client => { "title" => client.title , ............ } > > > > as the client model may change over time > > Try Client.should_receive(:new).with(client.attributes), because the > #attributes method turns a model into a Hash of symbol to value. It > uses string keys instead of symbol keys, but that shouldn't hurt you. > > Good luck. > -- > J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: > http://blog.thecodewhisperer.com > Diaspar Software Services :: http://www.diasparsoftware.com > Author, JUnit Recipes > 2005 Gordon Pask Award for contribution to Agile practice :: Agile > 2010: Learn. Practice. Explore. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stephen.smithstone at gmail.com Tue Feb 2 07:54:15 2010 From: stephen.smithstone at gmail.com (Stephen Smithstone) Date: Tue, 2 Feb 2010 12:54:15 +0000 Subject: [rspec-users] Specting controller post In-Reply-To: References: <4B67EF46.2000604@me.com> Message-ID: seems the blueprint is not inheriting from active record base so no #attributes on the class, have to look for another solution or pass in some parameters my self On 2 February 2010 12:26, Stephen Smithstone wrote: > cheers for the response , seem that attributes is missing from hash on my > system > > all i did was the blueprint with a standard hash > > client = { :title => "Mr } > > client.attributes > > NoMethodError: undefined method `attributes' for {:title=>"Mr"}:Hash > > is attributes added on by rails ? > > if so my setup must be wrong > > > On 2 February 2010 12:07, J. B. Rainsberger wrote: > >> On Tue, Feb 2, 2010 at 04:24, Stephen Smithstone >> wrote: >> >> > A bit stuck here being new to ruby and rspec >> >> Welcome. I hope you like the experience. Good news: we've seen what >> you've done a thousand times and so it's quite easy to explain. >> >> > it "should create new client" do >> > // creates me a hash of generated values using Foregey >> > client = Client.plan >> > // specify that I should be creating a new client with the hash >> values >> > from client >> > Client.should_receive(:new).with(client) >> > //post to the server >> > post 'create' , :client => client >> > end >> > >> > in my controller >> > >> > def create >> > client = Client.new(params[:client]) >> > end >> > >> > now this is failing with >> > >> > Spec::Mocks::MockExpectationError: > > datetime, updated_at: datetime, title: string, lastname: string, >> firstname: >> > string, email: string) (class)> received :new with unexpected arguments >> > expected: ({:title=>"Mr", :firstname=>"Ernest", :lastname=>"Burke", >> > :email=>"rgarrett at blogtag.info"}) >> > got: ({"title"=>"Mr", "lastname"=>"Burke", "firstname"=>"Ernest", >> > "email"=>"rgarrett at blogtag.info"}) >> > >> > is there a way to specify to use symbols instead of the strings as keys, >> as >> > I dont want to be doing >> > >> > :client => { "title" => client.title , ............ } >> > >> > as the client model may change over time >> >> Try Client.should_receive(:new).with(client.attributes), because the >> #attributes method turns a model into a Hash of symbol to value. It >> uses string keys instead of symbol keys, but that shouldn't hurt you. >> >> Good luck. >> -- >> J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: >> http://blog.thecodewhisperer.com >> Diaspar Software Services :: http://www.diasparsoftware.com >> Author, JUnit Recipes >> 2005 Gordon Pask Award for contribution to Agile practice :: Agile >> 2010: Learn. Practice. Explore. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From godfoca at gmail.com Tue Feb 2 08:19:17 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Tue, 2 Feb 2010 11:19:17 -0200 Subject: [rspec-users] Specting controller post In-Reply-To: References: <4B67EF46.2000604@me.com> Message-ID: The problem is that you're passing a hash with symbols as keys, and rails takes the params and converts it to a HashWithIndifferentAccess, which actually stores the keys as strings. One thing you might try to solve your problem is do this: it "should create new client" do client = Client.plan.with_indifferent_access Client.should_receive(:new).with(client) post 'create' , :client => client end I guess that will probably solve it. On an unrelated note?and here's to opening a huge can of worms :)?I usually dislike stubbing/mocking to do these simple tests. I tend to like testing more the behavior of my controllers, so for a valid create, I would write this test: it "adds a new client" do lambda { post :create, :client => Client.plan }.should change(Client, :count).by(1) end Since this doesn't rely on the implementation (calling Client.new(params) ? which might change to current_user.clients.new(params), and maybe some business logic is added along the way and it turns into current_user.add_client(params) at some point), it tells me that the action, provided valid parameters, is working, and at the same time will resist a refactoring. (This is considering your action is a "standard" create action for a rails controller) But again, this is *my* usual approach, there are good reasons both in favor of not mocking and in favor of mocking the behavior of your models. I just like the ones in favor of not mocking a bit more :) Cheers On Tue, Feb 2, 2010 at 10:26 AM, Stephen Smithstone wrote: > cheers for the response , seem that attributes is missing from hash on my > system > > all i did was the blueprint with a standard hash > > client = { :title => "Mr } > > client.attributes > > NoMethodError: undefined method `attributes' for {:title=>"Mr"}:Hash > > is attributes added on by rails ? > > if so my setup must be wrong > > On 2 February 2010 12:07, J. B. Rainsberger wrote: >> >> On Tue, Feb 2, 2010 at 04:24, Stephen Smithstone >> wrote: >> >> > A bit stuck here being new to ruby and rspec >> >> Welcome. I hope you like the experience. Good news: we've seen what >> you've done a thousand times and so it's quite easy to explain. >> >> > it "should create new client" do >> > ??? // creates me a hash of generated values using Foregey >> > ??? client = Client.plan >> > ??? // specify that I should be creating a new client with the hash >> > values >> > from client >> > ??? Client.should_receive(:new).with(client) >> > ??? //post to the server >> > ??? post 'create' , :client => client >> > end >> > >> > in my controller >> > >> > def create >> > ??? client = Client.new(params[:client]) >> > end >> > >> > now this is failing with >> > >> > Spec::Mocks::MockExpectationError: > > datetime, updated_at: datetime, title: string, lastname: string, >> > firstname: >> > string, email: string) (class)> received :new with unexpected arguments >> > ? expected: ({:title=>"Mr", :firstname=>"Ernest", :lastname=>"Burke", >> > :email=>"rgarrett at blogtag.info"}) >> > ?????? got: ({"title"=>"Mr", "lastname"=>"Burke", "firstname"=>"Ernest", >> > "email"=>"rgarrett at blogtag.info"}) >> > >> > is there a way to specify to use symbols instead of the strings as keys, >> > as >> > I dont want to be doing >> > >> > :client => { "title" => client.title , ............ } >> > >> > as the client model may change over time >> >> Try Client.should_receive(:new).with(client.attributes), because the >> #attributes method turns a model into a Hash of symbol to value. It >> uses string keys instead of symbol keys, but that shouldn't hurt you. >> >> Good luck. >> -- >> J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: >> http://blog.thecodewhisperer.com >> Diaspar Software Services :: http://www.diasparsoftware.com >> Author, JUnit Recipes >> 2005 Gordon Pask Award for contribution to Agile practice :: Agile >> 2010: Learn. Practice. Explore. >> _______________________________________________ >> 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 kmandrup at gmail.com Tue Feb 2 03:58:56 2010 From: kmandrup at gmail.com (Kristian Mandrup) Date: Tue, 2 Feb 2010 00:58:56 -0800 (PST) Subject: [rspec-users] CRITICAL: Rspec gem install > spec command not found! Message-ID: <38813865-89f3-4099-b2c2-6f4f90297367@q4g2000yqm.googlegroups.com> I have the beta release of the RSpec book. Trying to run the greeting example 'Hello World' Using brew as package manager Installed rspec gem using $ sudo gem install rspec kristian-mandrups-macbook-pro:rspec-coding kristianconsult$ gem list *** LOCAL GEMS *** abstract (1.0.0) actionmailer (3.0.pre, 2.3.5) ... cucumber (0.6.2) cucumber-rails (0.2.4) .. rspec (1.3.0) rspec-rails (1.3.2) ... My system used the spec in jruby first, so I removed jruby from the equation! kristian-mandrups-macbook-pro:rspec-coding kristianconsult$ spec -help -bash: spec: command not found Then trying uninstall kristian-mandrups-macbook-pro:rspec-coding kristianconsult$ sudo gem uninstall rspec Password: Select gem to uninstall: 1. rspec-1.3.0 2. rspec-1.3.0 3. All versions > 3 Remove executables: autospec, spec in addition to the gem? [Yn] Y ... $ Trying to reinstall $ sudo gem install rspec ************************************************** Thank you for installing rspec-1.3.0 Please be sure to read History.rdoc and Upgrade.rdoc for useful information about this release. ************************************************** Successfully installed rspec-1.3.0 1 gem installed Installing ri documentation for rspec-1.3.0... Updating class cache with 2074 classes... Installing RDoc documentation for rspec-1.3.0... Could not find main page README.rdoc kristian-mandrups-macbook-pro:rspec-coding kristianconsult$ spec -- help -bash: spec: command not found $ Where should the spec command be found? I created some rails generators myself with executables, so I assume the rspec gem install comes with a /bin directory with a spec executable? I really wanna start learning BDD today! Thanks! Kristian From stephen.smithstone at gmail.com Tue Feb 2 05:00:30 2010 From: stephen.smithstone at gmail.com (ssmithstone) Date: Tue, 2 Feb 2010 02:00:30 -0800 (PST) Subject: [rspec-users] specing controller post Message-ID: A bit stuck here being new to ruby and rspec Im trying to spec out a rails controller and using machinist to generate a model so in my spec i have it "should create new client" do // creates me a hash of generated values using Foregey client = Client.plan // specify that I should be creating a new client with the hash values from client Client.should_receive(:new).with(client) //post to the server using my client hash post 'create' , :client => client end in my controller def create client = Client.new(params[:client]) end now this is failing with Spec::Mocks::MockExpectationError: received :new with unexpected arguments expected: ({:title=>"Mr", :firstname=>"Ernest", :lastname=>"Burke", :email=>"rgarrett at blogtag.info"}) got: ({"title"=>"Mr", "lastname"=>"Burke", "firstname"=>"Ernest", "email"=>"rgarrett at blogtag.info"}) so why are my hash keys being transformed in string keys instead of keeping them as symbols, or am I doing this wrong ? Cheers From godfoca at gmail.com Tue Feb 2 08:22:04 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Tue, 2 Feb 2010 11:22:04 -0200 Subject: [rspec-users] Specting controller post In-Reply-To: References: <4B67EF46.2000604@me.com> Message-ID: On Tue, Feb 2, 2010 at 10:54 AM, Stephen Smithstone wrote: > seems the blueprint is not inheriting from active record base so no > #attributes on the class, have to look for another solution or pass in some > parameters my self Model#plan will just return a hash of attributes, using your blueprint. If you want an instance of the model, you can use Model#make, or Model#make_unsaved. (This is assuming you're using Machinist, given the api you're using) > On 2 February 2010 12:26, Stephen Smithstone > wrote: >> >> cheers for the response , seem that attributes is missing from hash on my >> system >> >> all i did was the blueprint with a standard hash >> >> client = { :title => "Mr } >> >> client.attributes >> >> NoMethodError: undefined method `attributes' for {:title=>"Mr"}:Hash >> >> is attributes added on by rails ? >> >> if so my setup must be wrong >> >> On 2 February 2010 12:07, J. B. Rainsberger >> wrote: >>> >>> On Tue, Feb 2, 2010 at 04:24, Stephen Smithstone >>> wrote: >>> >>> > A bit stuck here being new to ruby and rspec >>> >>> Welcome. I hope you like the experience. Good news: we've seen what >>> you've done a thousand times and so it's quite easy to explain. >>> >>> > it "should create new client" do >>> > ??? // creates me a hash of generated values using Foregey >>> > ??? client = Client.plan >>> > ??? // specify that I should be creating a new client with the hash >>> > values >>> > from client >>> > ??? Client.should_receive(:new).with(client) >>> > ??? //post to the server >>> > ??? post 'create' , :client => client >>> > end >>> > >>> > in my controller >>> > >>> > def create >>> > ??? client = Client.new(params[:client]) >>> > end >>> > >>> > now this is failing with >>> > >>> > Spec::Mocks::MockExpectationError: >> > datetime, updated_at: datetime, title: string, lastname: string, >>> > firstname: >>> > string, email: string) (class)> received :new with unexpected arguments >>> > ? expected: ({:title=>"Mr", :firstname=>"Ernest", :lastname=>"Burke", >>> > :email=>"rgarrett at blogtag.info"}) >>> > ?????? got: ({"title"=>"Mr", "lastname"=>"Burke", >>> > "firstname"=>"Ernest", >>> > "email"=>"rgarrett at blogtag.info"}) >>> > >>> > is there a way to specify to use symbols instead of the strings as >>> > keys, as >>> > I dont want to be doing >>> > >>> > :client => { "title" => client.title , ............ } >>> > >>> > as the client model may change over time >>> >>> Try Client.should_receive(:new).with(client.attributes), because the >>> #attributes method turns a model into a Hash of symbol to value. It >>> uses string keys instead of symbol keys, but that shouldn't hurt you. >>> >>> Good luck. >>> -- >>> J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: >>> http://blog.thecodewhisperer.com >>> Diaspar Software Services :: http://www.diasparsoftware.com >>> Author, JUnit Recipes >>> 2005 Gordon Pask Award for contribution to Agile practice :: Agile >>> 2010: Learn. Practice. Explore. >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Tue Feb 2 08:46:41 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 2 Feb 2010 13:46:41 +0000 Subject: [rspec-users] CRITICAL: Rspec gem install > spec command not found! In-Reply-To: <38813865-89f3-4099-b2c2-6f4f90297367@q4g2000yqm.googlegroups.com> References: <38813865-89f3-4099-b2c2-6f4f90297367@q4g2000yqm.googlegroups.com> Message-ID: On Feb 02, 2010, at 8:58 am, Kristian Mandrup wrote: > Using brew as package manager > kristian-mandrups-macbook-pro:rspec-coding kristianconsult$ spec -- > help > > -bash: spec: command not found > $ If you're using Homebrew[1] (?) you'll need to figure out where it's storing binaries. Run "find / -name spec" to locate the command. Then run "echo $PATH" and check that the directory containing "spec" is in the list. If not you'll need to add it in your .bashrc or something (I don't use bash). HTH Ashley [1] http://github.com/mxcl/homebrew -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From ssmithstone at me.com Tue Feb 2 08:50:33 2010 From: ssmithstone at me.com (Stephen Smithstone) Date: Tue, 02 Feb 2010 13:50:33 +0000 Subject: [rspec-users] Specting controller post In-Reply-To: References: <4B67EF46.2000604@me.com> Message-ID: <4B682DA9.5050900@me.com> An HTML attachment was scrubbed... URL: From jbrainsberger at gmail.com Tue Feb 2 09:18:51 2010 From: jbrainsberger at gmail.com (J. B. Rainsberger) Date: Tue, 2 Feb 2010 09:18:51 -0500 Subject: [rspec-users] Specting controller post In-Reply-To: References: <4B67EF46.2000604@me.com> Message-ID: On Tue, Feb 2, 2010 at 07:26, Stephen Smithstone wrote: > cheers for the response , seem that attributes is missing from hash on my > system You'll find #attributes on ActiveRecord::Base, and not Hash. Try this: it "should create new client" do // creates me a hash of generated values using Foregey client = Client.plan // specify that I should be creating a new client with the hash values from client Client.should_receive(:new).with(client.attributes) //post to the server post 'create' , :client => client end -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. From jbrainsberger at gmail.com Tue Feb 2 09:19:54 2010 From: jbrainsberger at gmail.com (J. B. Rainsberger) Date: Tue, 2 Feb 2010 09:19:54 -0500 Subject: [rspec-users] Specting controller post In-Reply-To: References: <4B67EF46.2000604@me.com> Message-ID: On Tue, Feb 2, 2010 at 09:18, J. B. Rainsberger wrote: > On Tue, Feb 2, 2010 at 07:26, Stephen Smithstone > wrote: > >> cheers for the response , seem that attributes is missing from hash on my >> system > > You'll find #attributes on ActiveRecord::Base, and not Hash. I responded too soon. Ignore my response. I don't know Machinist, and so I can't help you. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. From paul.t.hinze at gmail.com Tue Feb 2 09:58:34 2010 From: paul.t.hinze at gmail.com (Paul Hinze) Date: Tue, 2 Feb 2010 08:58:34 -0600 Subject: [rspec-users] Scaling shared behavior (was: Re: Message expectation that verifies result of passed block) In-Reply-To: References: <20100128132949.GV6554@malachai> <20100128211402.GY6554@malachai> Message-ID: <20100202145834.GA11524@malachai> A bit of a delayed reply, but I appreciate all the feedback everyone. What a helpful list this is! :) Nicol?s Sanguinetti on 2010-01-28 at 15:45: > You're definitely testing too much implementation and not enough behavior. This was the overwhelming opinion of the group, and I see what you are all saying. > Basically, what you want to spec, is that provided some options, when > you call a certain method of your form builder, you get a certain html > output. At least that's how I would approach the problem. > > it "produces a correctly formatted FOO input" do > html = @builder.foo_text(...) > html.should have_tag("label", :for => "foo") > html.should have_tag("input", :id => "foo") > end This is more or less exactly the structure that current specs have. And the (mistakenly-designed, I now realize) refactor I was hoping to make was to address the problem of _re-verifying_ all of the behavior of `question` in every formbuilder method. Here is how we're currently doing it: describe 'question', :shared_behavior => true do it 'marks the question required' do # stub question required in model xhtml = @builder.send(@current_method) # [A] xhtml.should have_tag('li.required') end # ... more examples describing question behavior [B] end describe '#question' do before { @current_method = 'question' } it_should_behave_like 'question' end describe '#text' do before { @current_method = 'text' } it_should_behave_like 'question' # ... examples describing text behavior end This worked great at first, until we got to the point of there being more than 50 examples at [B] for `question`, and there being more than 30 other methods. I also realized that some methods that share question behavior require certain options to properly pass through the question shared example group. So I had to add another argument to [A] and maintain this knowledge across the suite. Not only that, but I realized that question is not the only shared behavior. Add that to the mix and you start to get structures like this: describe 'collection', :shared => true do # ... examples describing collection behavior end describe '#collection' do before do @current_method = :collection @default_options = { :collection => [:foo, :bar, :baz] } end it_should_behave_like 'question' it_should_behave_like 'collection' end describe '#dependent_collection' do before do @current_method = :dependent_collection @default_options = { :collection => [:foo, :bar, :baz], :depends_on => :qux } end it_should_behave_like 'question' it_should_behave_like 'collection' # ... examples describing dependent_collection behavior end This gets unruly and difficult to read and maintain very quickly, and because our group has several devs who touch this code, the pattern is not always followed correctly. So now I sit with these disadvantages: 1) a relatively slow test suite for my formbuilder, since every detail of any shared behavior is verified over and over 2) some mysterious instance variables i need to maintain across all example groups in order to keep shared groups testing the right methods 3) strange and unintuitive coupling across the test suite The advantage we're getting, of course, is that behavior is properly speced with this structure (when we pull it off properly at least). I started this thread with the thought that I could simplify this by basically flipping out 'it_should_behave_like' with 'it_should_call', but you folks identified that as slipping down into verifying implementation rather than behavior. So the question that I pose to you, list, is this: is there any way to change the way we're dealing with this problem to minimize the disadvantages I mentioned above or is the answer "yup, that's pretty much how you would need to set this up"? Thanks again for all your feedback and attention folks, it has been incredibly helpful. Cheers, Paul From rogerpack2005 at gmail.com Tue Feb 2 14:46:37 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Tue, 2 Feb 2010 11:46:37 -0800 (PST) Subject: [rspec-users] somewhat confused by the help instructions... In-Reply-To: <57c63afe1001311251i67a56d6am8bf1c32d1604b833@mail.gmail.com> References: <2a39e8e4-72b7-4f37-9e1e-f358eebf5d3c@b2g2000yqi.googlegroups.com> <57c63afe1001292245o21772b63h843b7ea6d4b79d47@mail.gmail.com> <57c63afe1001300638h15cc15eai8c97d15634197ec3@mail.gmail.com> <57c63afe1001311251i67a56d6am8bf1c32d1604b833@mail.gmail.com> Message-ID: > > Done: > > http://github.com/rspec/rspec-core/blob/master/features/command_line/... Thanks for doing that. -r From me at franklakatos.com Tue Feb 2 19:00:25 2010 From: me at franklakatos.com (Frank Lakatos) Date: Tue, 2 Feb 2010 19:00:25 -0500 Subject: [rspec-users] When to use Factories, Mock Models, Mocks & Stubs Message-ID: Hi guys, been following for about 3 weeks, first question - I've been spending the last couple of months learning RSpec and Cucumber and I'm just finally starting to see the "big picture", at least I think I am. But I've got some questions I was hoping you guys can clear up. I'm sure this has been asked a lot, so please bare with me. Just let me know when my logic is wrong or when I'm way off course. You guys have been a kind group, so I'm not to concerned with sounding foolish. I've been using .should_receive and .stub to let my spec know that my controller is going to be making a method call. I know .should_receive will fail when you don't call that method (or if you call it more times than you said you would) and I use stub when It's going to get called an unpredictable amount of times, like in a before block. To me, it sounds like I don't really know what the difference is, and I just have some understanding of there symptoms. When i need to talk about a model, I usually use mock_model. I have Factory_girl, but I've heard that you should be careful when using Factory girl, as it ties you down to the requirements of the attributes, and not the overall functionality (although, that statement may not be true in itself). So normally, I use Factories in Cucumber, as that is concerned with more higher level usage features, and mock_models for controller/model specs. Alot of times, however, I feel like I'm doing way to much work to get the whole thing working. Maybe I am, maybe I'm not, only way is to show off what I'm doing. app/controller/projects_controller#create def create @client = current_user.company.clients.find(params[:project] [:client_id]) @project = @client.projects.build(params[:project]) if @client.save flash[:notice] = "Added: #{@project.name}" else render :new end end spec/controller/projects_controller_spec describe ProjectsController do describe "POST 'create'" do before do @current_user = mock_model(User) controller.stub(:current_user).and_return @current_user @company = mock_model(Company) @current_user.should_receive(:company).and_return @company @clients = mock("Client List") @company.should_receive(:clients).and_return @clients end describe "when client is found" do before do @client = mock_model(Client) @clients.should_receive(:find).and_return @client end describe "on successful save" do before do @projects = mock_model(ActiveRecord) @client.should_receive(:projects).and_return @projects @project = mock_model(Project) @projects.should_receive(:build).and_return @project @client.should_receive(:save).and_return true @project.should_receive(:name).and_return "New Project" end it "should set up the flash" do post "create", {:project => {:client_id => 1}} flash[:notice].should_not be_nil end end end end end Let me know how it sounds, and it looks like I'm doing so far Thanks, Frank From zenshade at gmail.com Tue Feb 2 22:51:02 2010 From: zenshade at gmail.com (Levi Conley) Date: Tue, 2 Feb 2010 22:51:02 -0500 Subject: [rspec-users] Passing parameters to Rspec scripts Message-ID: <655d96db1002021951v7c44ddadr4e1e3f281c7a1749@mail.gmail.com> Newbie here. I'm hoping someone can give me an outline of how to re-use rspec scripts by passing them parameters. The situation I have is testing a web application (using watir) for about 30 different customers. Some of the customers have unique features in their particular application instance, but much of the codebase is shared (about 90%). So what I need to be able to do is write rspec tests covering that shared codebase. But I need to in some way pass in the customer name so that watir can log into the right application instance. Any help with this is greatly appreciated. I still have much to learn about Rspec, but so far this seemingly simple task has me stumped. Thanks From erdoss at gmail.com Wed Feb 3 00:53:10 2010 From: erdoss at gmail.com (Andrei Erdoss) Date: Wed, 3 Feb 2010 07:53:10 +0200 Subject: [rspec-users] When to use Factories, Mock Models, Mocks & Stubs In-Reply-To: References: Message-ID: Hello Frank, >From my understanding these are the roles of should_receive and stub. should_receive checks to make sure that a method or a property is called. To this you can specify the arguments that it gets called (.with()), what it returns (.and_return) and how many times this happens (.once, .twice etc). stub on the other hand is a place holder for functions calls that have been tested already or are Rails defaults, which don't need to be tested. stubs are used in conjunction with mock_models, in order to provide for the functions or properties that are needed for the code to run, up to the test point. As far as mock_model and Factory_girl, I can say that mock_models are a much more lightweight structure than Factory_girl object. When testing controllers I try to use only mock_models. As far as models, I use Factory_girl only when dealing with the object being tested. The other complementary objects are mocked by using mock_model. On Wed, Feb 3, 2010 at 2:00 AM, Frank Lakatos wrote: > Hi guys, been following for about 3 weeks, first question - > > I've been spending the last couple of months learning RSpec and Cucumber > and I'm just finally starting to see the "big picture", at least I think I > am. But I've got some questions I was hoping you guys can clear up. I'm sure > this has been asked a lot, so please bare with me. Just let me know when my > logic is wrong or when I'm way off course. You guys have been a kind group, > so I'm not to concerned with sounding foolish. > > I've been using .should_receive and .stub to let my spec know that my > controller is going to be making a method call. I know .should_receive will > fail when you don't call that method (or if you call it more times than you > said you would) and I use stub when It's going to get called an > unpredictable amount of times, like in a before block. To me, it sounds like > I don't really know what the difference is, and I just have some > understanding of there symptoms. > > When i need to talk about a model, I usually use mock_model. I have > Factory_girl, but I've heard that you should be careful when using Factory > girl, as it ties you down to the requirements of the attributes, and not the > overall functionality (although, that statement may not be true in itself). > So normally, I use Factories in Cucumber, as that is concerned with more > higher level usage features, and mock_models for controller/model specs. > > Alot of times, however, I feel like I'm doing way to much work to get the > whole thing working. Maybe I am, maybe I'm not, only way is to show off what > I'm doing. > > app/controller/projects_controller#create > > def create > @client = > current_user.company.clients.find(params[:project][:client_id]) > @project = @client.projects.build(params[:project]) > if @client.save > flash[:notice] = "Added: #{@project.name}" > else > render :new > end > end > > > spec/controller/projects_controller_spec > > describe ProjectsController do > describe "POST 'create'" do > > before do > @current_user = mock_model(User) > controller.stub(:current_user).and_return @current_user > @company = mock_model(Company) > @current_user.should_receive(:company).and_return @company > @clients = mock("Client List") > @company.should_receive(:clients).and_return @clients > end > > describe "when client is found" do > > before do > @client = mock_model(Client) > @clients.should_receive(:find).and_return @client > end > > describe "on successful save" do > > before do > @projects = mock_model(ActiveRecord) > @client.should_receive(:projects).and_return @projects > @project = mock_model(Project) > @projects.should_receive(:build).and_return @project > @client.should_receive(:save).and_return true > @project.should_receive(:name).and_return "New Project" > end > > it "should set up the flash" do > post "create", {:project => {:client_id => 1}} > flash[:notice].should_not be_nil > end > > end > > end > > end > > > end > > > Let me know how it sounds, and it looks like I'm doing so far > > Thanks, > Frank > > > > > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Andrei Erdoss -------------- next part -------------- An HTML attachment was scrubbed... URL: From adam.sroka at gmail.com Wed Feb 3 01:06:05 2010 From: adam.sroka at gmail.com (Adam Sroka) Date: Tue, 2 Feb 2010 22:06:05 -0800 Subject: [rspec-users] When to use Factories, Mock Models, Mocks & Stubs In-Reply-To: References: Message-ID: <2ef359581002022206t79ca96etb7d35ba2129b8d97@mail.gmail.com> On Tue, Feb 2, 2010 at 9:53 PM, Andrei Erdoss wrote: > Hello Frank, > > From my understanding these are the roles of should_receive and stub. > > should_receive checks to make sure that a method or a property is called. To > this you can specify the arguments that it gets called (.with()), what it > returns (.and_return) and how many times this happens (.once, .twice etc). > > stub on the other hand is a place holder for functions calls that have been > tested already or are Rails defaults, which don't need to be tested. stubs > are used in conjunction with mock_models, in order to provide for the > functions or properties that are needed for the code to run, up to the test > point. > I think that it is best to think of these in terms of command query separation. In case you aren't familiar with that principle, it states that some methods are commands - they tell an object to do something but don't return anything interesting, and other methods are queries - they return some interesting value but have no side effects. should_receive is how we set an expectation for a command. We don't really care what a command returns but we do care that it gets called. should_receive literally says that the command should be called with the given parameters. stub is how we handle a query. We care what a query returns, or rather the code we are testing does, but we don't really care when it gets called (or how often) per se. If we depend on its result then it should be called, but the effect that the result has on the system we're testing is what we really care about. From matt at mattwynne.net Wed Feb 3 03:37:06 2010 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 3 Feb 2010 08:37:06 +0000 Subject: [rspec-users] Passing parameters to Rspec scripts In-Reply-To: <655d96db1002021951v7c44ddadr4e1e3f281c7a1749@mail.gmail.com> References: <655d96db1002021951v7c44ddadr4e1e3f281c7a1749@mail.gmail.com> Message-ID: One way would be to use an environment variable: $ CUSTOMER=foo spec spec Then read out the customer name in your specs: login = ENV['CUSTOMER'] Otherwise, I would guess you might be able to look at ARGV from within, say, spec_helper.rb but I've never tried it. On 3 Feb 2010, at 03:51, Levi Conley wrote: > Newbie here. I'm hoping someone can give me an outline of how to > re-use rspec scripts by passing them parameters. > > The situation I have is testing a web application (using watir) for > about 30 different customers. Some of the customers have unique > features in their particular application instance, but much of the > codebase is shared (about 90%). So what I need to be able to do is > write rspec tests covering that shared codebase. But I need to in > some way pass in the customer name so that watir can log into the > right application instance. > > Any help with this is greatly appreciated. I still have much to learn > about Rspec, but so far this seemingly simple task has me stumped. > > Thanks > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From ashley.moran at patchspace.co.uk Wed Feb 3 04:06:38 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 3 Feb 2010 09:06:38 +0000 Subject: [rspec-users] CRITICAL: Rspec gem install > spec command not found! In-Reply-To: <38813865-89f3-4099-b2c2-6f4f90297367@q4g2000yqm.googlegroups.com> References: <38813865-89f3-4099-b2c2-6f4f90297367@q4g2000yqm.googlegroups.com> Message-ID: <3ECB458D-D811-41C4-9D43-191A9E54D45A@patchspace.co.uk> On Feb 02, 2010, at 8:58 am, Kristian Mandrup wrote: > Where should the spec command be found? Did you find it? -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From jbrainsberger at gmail.com Wed Feb 3 06:35:32 2010 From: jbrainsberger at gmail.com (J. B. Rainsberger) Date: Wed, 3 Feb 2010 06:35:32 -0500 Subject: [rspec-users] When to use Factories, Mock Models, Mocks & Stubs In-Reply-To: References: Message-ID: On Tue, Feb 2, 2010 at 19:00, Frank Lakatos wrote: > Hi guys, been following for about 3 weeks, first question - This might help a little: http://bit.ly/ONpXE To bring things back to Rails, I use mock_model whenever I want to design controller behavior without relying on the underlying model behavior. I tend to start using mock_model and mostly stubbing model behavior, then as controller behavior begins to reveal itself as model behavior, I push that into the model and mock those methods more frequently. I find this rule of thumb helpful: stub unless you're certain to want to verify this time that the client invoke the server correctly, and never, never mock multiple methods at once. If you want to mock multiple methods, you probably have too complex an interaction. > app/controller/projects_controller#create > > ?def create > ? ? ?@client = > current_user.company.clients.find(params[:project][:client_id]) > ? ? ?@project = @client.projects.build(params[:project]) > ? ? ?if @client.save > ? ? ? ?flash[:notice] = "Added: #{@project.name}" > ? ? ?else > ? ? ? ?render :new > ? ? ?end > ?end > > spec/controller/projects_controller_spec > > describe ProjectsController do > ? ?describe "POST 'create'" do > > ? ?before do > ? ? ?@current_user = mock_model(User) > ? ? ?controller.stub(:current_user).and_return @current_user > ? ? ?@company = mock_model(Company) > ? ? ?@current_user.should_receive(:company).and_return @company > ? ? ?@clients = mock("Client List") > ? ? ? ?@company.should_receive(:clients).and_return @clients > ? ?end > > ? ?describe "when client is found" do > > ? ? ?before do > ? ? ? ?@client = mock_model(Client) > ? ? ? ?@clients.should_receive(:find).and_return @client > ? ? ?end > > ? ? ?describe "on successful save" do > > ? ? ? ?before do > ? ? ? ? ?@projects = mock_model(ActiveRecord) > ? ? ? ? ?@client.should_receive(:projects).and_return @projects > ? ? ? ? ?@project = mock_model(Project) > ? ? ? ? ?@projects.should_receive(:build).and_return @project > ? ? ? ? ?@client.should_receive(:save).and_return true > ? ? ? ? ?@project.should_receive(:name).and_return "New Project" > ? ? ? ?end > > ? ? ? ?it "should set up the flash" do > ? ? ? ? ?post "create", {:project => {:client_id => 1}} > ? ? ? ? ?flash[:notice].should_not be_nil > ? ? ? ?end > > ? ? ? end > > ? ?end > > ?end > > > end > > > Let me know how it sounds, and it looks like I'm doing so far Not bad, but I'd probably extract a method for current_user.company.clients.find(params[:project][:client_id]) and possibly for @client.projects.build(params[:project]) in order to reduce the number of details that have to go into a single spec. def find_client_for_current_user(client_id) current_user.company.clients.find(client_id) end def build_new_project(client, project_attributes) client.projects.build(project_attributes) end def create @client = find_client_for_current_user(params[:project][:client_id]) @project = build_new_project(@client, params[:project]) if @client.save flash[:notice] = "Added: #{@project.name}" else render :new end end Now I can write these specs: stub each of the methods in the first three columns... find_client | build_project | save || expected_result valid | valid | true || added project nil | valid | shouldn't happen || exception (?) valid | fails | shouldn't happen || exception (?) valid | valid | false || errors; render new and finally: 1. stub :find_client to answer mock_model(Client); controller should receive :build_new_project with the mock model 2. stub :find_client to answer nil; controller should not receive :build_new_project 3. stub :find_client to answer mock_model(Client); mock model should receive :save That's the initial spec list I'd write. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. From matt at mattwynne.net Wed Feb 3 09:18:04 2010 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 3 Feb 2010 14:18:04 +0000 Subject: [rspec-users] When to use Factories, Mock Models, Mocks & Stubs In-Reply-To: References: Message-ID: <9B8726F1-7FC0-40FA-9721-3C8CF72A8442@mattwynne.net> On 3 Feb 2010, at 11:35, J. B. Rainsberger wrote: > I find this rule of thumb helpful: stub unless you're certain to want > to verify this time that the client invoke the server correctly, and > never, never mock multiple methods at once. Right, because the mock (should_receive) is an assertion, and it's usually better to have one assertion per example. cheers, Matt http://mattwynne.net +447974 430184 From dchelimsky at gmail.com Wed Feb 3 09:32:50 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Feb 2010 08:32:50 -0600 Subject: [rspec-users] When to use Factories, Mock Models, Mocks & Stubs In-Reply-To: <9B8726F1-7FC0-40FA-9721-3C8CF72A8442@mattwynne.net> References: <9B8726F1-7FC0-40FA-9721-3C8CF72A8442@mattwynne.net> Message-ID: <57c63afe1002030632y4e42841av33977b9867f36a7e@mail.gmail.com> On Wed, Feb 3, 2010 at 8:18 AM, Matt Wynne wrote: > > On 3 Feb 2010, at 11:35, J. B. Rainsberger wrote: > >> I find this rule of thumb helpful: stub unless you're certain to want >> to verify this time that the client invoke the server correctly, and >> never, never mock multiple methods at once. > > Right, because the mock (should_receive) is an assertion, and it's usually > better to have one assertion per example. Over here to the east of the pond, we say "expectation." :) > cheers, > Matt > > http://mattwynne.net > +447974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From me at franklakatos.com Wed Feb 3 09:52:16 2010 From: me at franklakatos.com (me at franklakatos.com) Date: Wed, 03 Feb 2010 07:52:16 -0700 Subject: [rspec-users] When to use Factories, Mock Models, Mocks & Stubs In-Reply-To: <2ef359581002022206t79ca96etb7d35ba2129b8d97@mail.gmail.com> References: <2ef359581002022206t79ca96etb7d35ba2129b8d97@mail.gmail.com> Message-ID: <20100203075216.dsohkzwahc84k000@franklakatos.com> Ok, so these ideas seem kind of natural to me, which is nice: mock_models being used to mock non-tested models stub for queries and/or well-tested methods, should_receives for commands While reading over Dave Astlels, I kind of got concerned because of something he states that I feel I'm doing in my specs: "When you realize that it's all about specifying behaviour and not writing tests, your point of view shifts. Suddenly the idea of having a Test class for each of your production classes is ridiculously limiting. And the thought of testing each of your methods with its own test method (in a 1-1 relationship) will be laughable." This is what I am striving for, but being guided simply by rSpec error messages results me in writing specs like this... describe "POST 'create'" do before do @current_user = mock_model(User) controller.stub(:current_user).and_return @current_user @company = mock_model(Company) @current_user.should_receive(:company).and_return @company @clients = mock("Client List") @company.should_receive(:clients).and_return @clients end describe "when client is found" do before do @client = mock_model(Client) @clients.should_receive(:find).and_return @client end describe "on successful save" do before do @projects = mock_model(ActiveRecord) @client.should_receive(:projects).and_return @projects @project = mock_model(Project) @projects.should_receive(:build).and_return @project @client.should_receive(:save).and_return true @project.should_receive(:name).and_return "New Project" end it "should set up the flash" do post "create", {:project => {:client_id => 1}} flash[:notice].should_not be_nil end end end end ... for a controller that looks like this ... def create @client = current_user.company.clients.find(params[:project][:client_id]) @project = @client.projects.build(params[:project]) if @client.save flash[:notice] = "Added: #{@project.name}" else render :new end end Am I doing the 1-1 thing that BDD specifically set out to avoid? Quoting Adam Sroka : > On Tue, Feb 2, 2010 at 9:53 PM, Andrei Erdoss wrote: >> Hello Frank, >> >> From my understanding these are the roles of should_receive and stub. >> >> should_receive checks to make sure that a method or a property is called. To >> this you can specify the arguments that it gets called (.with()), what it >> returns (.and_return) and how many times this happens (.once, .twice etc). >> >> stub on the other hand is a place holder for functions calls that have been >> tested already or are Rails defaults, which don't need to be tested. stubs >> are used in conjunction with mock_models, in order to provide for the >> functions or properties that are needed for the code to run, up to the test >> point. >> > > I think that it is best to think of these in terms of command query > separation. In case you aren't familiar with that principle, it states > that some methods are commands - they tell an object to do something > but don't return anything interesting, and other methods are queries - > they return some interesting value but have no side effects. > > should_receive is how we set an expectation for a command. We don't > really care what a command returns but we do care that it gets called. > should_receive literally says that the command should be called with > the given parameters. > > stub is how we handle a query. We care what a query returns, or rather > the code we are testing does, but we don't really care when it gets > called (or how often) per se. If we depend on its result then it > should be called, but the effect that the result has on the system > we're testing is what we really care about. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Feb 3 10:44:45 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Feb 2010 09:44:45 -0600 Subject: [rspec-users] When to use Factories, Mock Models, Mocks & Stubs In-Reply-To: <20100203075216.dsohkzwahc84k000@franklakatos.com> References: <2ef359581002022206t79ca96etb7d35ba2129b8d97@mail.gmail.com> <20100203075216.dsohkzwahc84k000@franklakatos.com> Message-ID: <57c63afe1002030744s6b3efd2bi5163a0ccb841af39@mail.gmail.com> On Wed, Feb 3, 2010 at 8:52 AM, wrote: > Ok, so these ideas seem kind of natural to me, which is nice: > > mock_models being used to mock non-tested models > stub for queries and/or well-tested methods, should_receives for commands > > While reading over Dave Astlels, I kind of got concerned because of > something he states that I feel I'm doing in my specs: > > "When you realize that it's all about specifying behaviour and not writing > tests, your point of view shifts. Suddenly the idea of having a Test class > for each of your production classes is ridiculously limiting. And the > thought of testing each of your methods with its own test method (in a > 1-1 relationship) will be laughable." > > This is what I am striving for, but being guided simply by rSpec error > messages results me in writing specs like this... > > describe "POST 'create'" do > > ? ?before do > ? ? ?@current_user = mock_model(User) > ? ? ?controller.stub(:current_user).and_return @current_user > ? ? ?@company = mock_model(Company) > ? ? ?@current_user.should_receive(:company).and_return @company > ? ? ?@clients = mock("Client List") > ? ? ?@company.should_receive(:clients).and_return @clients > ? ?end > > ? ?describe "when client is found" do > > ? ? ?before do > ? ? ? ?@client = mock_model(Client) > ? ? ? ?@clients.should_receive(:find).and_return @client > ? ? ?end > > ? ? ?describe "on successful save" do > > ? ? ? ?before do > ? ? ? ? ?@projects = mock_model(ActiveRecord) This is a little odd. @projects is a collection, not a an instance, and mocking ActiveRecord explicitly seems a bit odd. I'd generally us a simple array: @projects = [] > ? ? ? ? ?@client.should_receive(:projects).and_return @projects > ? ? ? ? ?@project = mock_model(Project) > ? ? ? ? ?@projects.should_receive(:build).and_return @project > ? ? ? ? ?@client.should_receive(:save).and_return true > ? ? ? ? ?@project.should_receive(:name).and_return "New Project" > ? ? ? ?end > > ? ? ? ?it "should set up the flash" do > ? ? ? ? ?post "create", {:project => {:client_id => 1}} > ? ? ? ? ?flash[:notice].should_not be_nil > ? ? ? ?end > > ? ? ?end > > ? ?end > > > ?end > > > > ... for a controller that looks like this ... > > > def create > ? ? ?@client = > current_user.company.clients.find(params[:project][:client_id]) > ? ? ?@project = @client.projects.build(params[:project]) > ? ? ?if @client.save > ? ? ? ?flash[:notice] = "Added: #{@project.name}" > ? ? ?else > ? ? ? ?render :new > ? ? ?end > ?end > > > > Am I doing the 1-1 thing that BDD specifically set out to avoid? 1-1 example per method is probably a red flag, but 1-1 spec file per implementation file makes navigation easier, so I think it's actually a good thing. The underlying problem with 1-1 mappings stems from IDE's that will make an empty test case by reflecting on an untested object. You'd end up with 50 line long test methods named "testGetName" that actually contain 20 different tests in the one method. That's an extreme, but I used to see that sort of thing all the time when I was consulting, and it makes it very difficult to understand what is being tested and what went wrong when there is a failure. Make sense? - David > > > > > > > > > > Quoting Adam Sroka : > >> On Tue, Feb 2, 2010 at 9:53 PM, Andrei Erdoss wrote: >>> >>> Hello Frank, >>> >>> From my understanding these are the roles of should_receive and stub. >>> >>> should_receive checks to make sure that a method or a property is called. >>> To >>> this you can specify the arguments that it gets called (.with()), what it >>> returns (.and_return) and how many times this happens (.once, .twice >>> etc). >>> >>> stub on the other hand is a place holder for functions calls that have >>> been >>> tested already or are Rails defaults, which don't need to be tested. >>> stubs >>> are used in conjunction with mock_models, in order to provide for the >>> functions or properties that are needed for the code to run, up to the >>> test >>> point. >>> >> >> I think that it is best to think of these in terms of command query >> separation. In case you aren't familiar with that principle, it states >> that some methods are commands - they tell an object to do something >> but don't return anything interesting, and other methods are queries - >> they return some interesting value but have no side effects. >> >> should_receive is how we set an expectation for a command. We don't >> really care what a command returns but we do care that it gets called. >> should_receive literally says that the command should be called with >> the given parameters. >> >> stub is how we handle a query. We care what a query returns, or rather >> the code we are testing does, but we don't really care when it gets >> called (or how often) per se. If we depend on its result then it >> should be called, but the effect that the result has on the system >> we're testing is what we really care about. >> _______________________________________________ >> 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 me at franklakatos.com Wed Feb 3 11:07:09 2010 From: me at franklakatos.com (me at franklakatos.com) Date: Wed, 03 Feb 2010 09:07:09 -0700 Subject: [rspec-users] When to use Factories, Mock Models, Mocks & Stubs In-Reply-To: <57c63afe1002030744s6b3efd2bi5163a0ccb841af39@mail.gmail.com> References: <2ef359581002022206t79ca96etb7d35ba2129b8d97@mail.gmail.com> <20100203075216.dsohkzwahc84k000@franklakatos.com> <57c63afe1002030744s6b3efd2bi5163a0ccb841af39@mail.gmail.com> Message-ID: <20100203090709.madytmj0o8owso88@franklakatos.com> To say thank you for all your constuctive feedback would not be enough; all these insights are really helping me to get the provebial "it". Dave, I completely agree that the mock_model(ActiveRecord) was bizzare, but my specs kept failing because @projects was to receive .build, and it complained it didn't know about it. Using AR fixed that, but that must have been from a while ago, because I put [] back in it's place (which i had before) and the spec passes. I absolutely love the idea of encapsulated the daisy chained calls (c_u.comp.project) into a controller methods so all i gotta do is stub that out. So that makes me wonder -- as of right now, I write this long spec, which looks way more involved than the controller itself. And, I'd be lying if I said that I thought about my spec first before writing the app code. Is the idea that I should be trying to think of a simpler spec, which will force a simpler controller (like encapsulating functionality into more controller methods) Once again, thanks++ Frank Quoting David Chelimsky : > On Wed, Feb 3, 2010 at 8:52 AM, wrote: >> Ok, so these ideas seem kind of natural to me, which is nice: >> >> mock_models being used to mock non-tested models >> stub for queries and/or well-tested methods, should_receives for commands >> >> While reading over Dave Astlels, I kind of got concerned because of >> something he states that I feel I'm doing in my specs: >> >> "When you realize that it's all about specifying behaviour and not writing >> tests, your point of view shifts. Suddenly the idea of having a Test class >> for each of your production classes is ridiculously limiting. And the >> thought of testing each of your methods with its own test method (in a >> 1-1 relationship) will be laughable." >> >> This is what I am striving for, but being guided simply by rSpec error >> messages results me in writing specs like this... >> >> describe "POST 'create'" do >> >> ? ?before do >> ? ? ?@current_user = mock_model(User) >> ? ? ?controller.stub(:current_user).and_return @current_user >> ? ? ?@company = mock_model(Company) >> ? ? ?@current_user.should_receive(:company).and_return @company >> ? ? ?@clients = mock("Client List") >> ? ? ?@company.should_receive(:clients).and_return @clients >> ? ?end >> >> ? ?describe "when client is found" do >> >> ? ? ?before do >> ? ? ? ?@client = mock_model(Client) >> ? ? ? ?@clients.should_receive(:find).and_return @client >> ? ? ?end >> >> ? ? ?describe "on successful save" do >> >> ? ? ? ?before do >> ? ? ? ? ?@projects = mock_model(ActiveRecord) > > This is a little odd. @projects is a collection, not a an instance, > and mocking ActiveRecord explicitly seems a bit odd. I'd generally us > a simple array: > > @projects = [] > >> ? ? ? ? ?@client.should_receive(:projects).and_return @projects >> ? ? ? ? ?@project = mock_model(Project) >> ? ? ? ? ?@projects.should_receive(:build).and_return @project >> ? ? ? ? ?@client.should_receive(:save).and_return true >> ? ? ? ? ?@project.should_receive(:name).and_return "New Project" >> ? ? ? ?end >> >> ? ? ? ?it "should set up the flash" do >> ? ? ? ? ?post "create", {:project => {:client_id => 1}} >> ? ? ? ? ?flash[:notice].should_not be_nil >> ? ? ? ?end >> >> ? ? ?end >> >> ? ?end >> >> >> ?end >> >> >> >> ... for a controller that looks like this ... >> >> >> def create >> ? ? ?@client = >> current_user.company.clients.find(params[:project][:client_id]) >> ? ? ?@project = @client.projects.build(params[:project]) >> ? ? ?if @client.save >> ? ? ? ?flash[:notice] = "Added: #{@project.name}" >> ? ? ?else >> ? ? ? ?render :new >> ? ? ?end >> ?end >> >> >> >> Am I doing the 1-1 thing that BDD specifically set out to avoid? > > 1-1 example per method is probably a red flag, but 1-1 spec file per > implementation file makes navigation easier, so I think it's actually > a good thing. > > The underlying problem with 1-1 mappings stems from IDE's that will > make an empty test case by reflecting on an untested object. You'd end > up with 50 line long test methods named "testGetName" that actually > contain 20 different tests in the one method. That's an extreme, but I > used to see that sort of thing all the time when I was consulting, and > it makes it very difficult to understand what is being tested and what > went wrong when there is a failure. > > Make sense? > > - David >> >> >> >> >> >> >> >> >> >> Quoting Adam Sroka : >> >>> On Tue, Feb 2, 2010 at 9:53 PM, Andrei Erdoss wrote: >>>> >>>> Hello Frank, >>>> >>>> From my understanding these are the roles of should_receive and stub. >>>> >>>> should_receive checks to make sure that a method or a property is called. >>>> To >>>> this you can specify the arguments that it gets called (.with()), what it >>>> returns (.and_return) and how many times this happens (.once, .twice >>>> etc). >>>> >>>> stub on the other hand is a place holder for functions calls that have >>>> been >>>> tested already or are Rails defaults, which don't need to be tested. >>>> stubs >>>> are used in conjunction with mock_models, in order to provide for the >>>> functions or properties that are needed for the code to run, up to the >>>> test >>>> point. >>>> >>> >>> I think that it is best to think of these in terms of command query >>> separation. In case you aren't familiar with that principle, it states >>> that some methods are commands - they tell an object to do something >>> but don't return anything interesting, and other methods are queries - >>> they return some interesting value but have no side effects. >>> >>> should_receive is how we set an expectation for a command. We don't >>> really care what a command returns but we do care that it gets called. >>> should_receive literally says that the command should be called with >>> the given parameters. >>> >>> stub is how we handle a query. We care what a query returns, or rather >>> the code we are testing does, but we don't really care when it gets >>> called (or how often) per se. If we depend on its result then it >>> should be called, but the effect that the result has on the system >>> we're testing is what we really care about. >>> _______________________________________________ >>> 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 godfoca at gmail.com Wed Feb 3 11:35:01 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Wed, 3 Feb 2010 14:35:01 -0200 Subject: [rspec-users] When to use Factories, Mock Models, Mocks & Stubs In-Reply-To: <20100203090709.madytmj0o8owso88@franklakatos.com> References: <2ef359581002022206t79ca96etb7d35ba2129b8d97@mail.gmail.com> <20100203075216.dsohkzwahc84k000@franklakatos.com> <57c63afe1002030744s6b3efd2bi5163a0ccb841af39@mail.gmail.com> <20100203090709.madytmj0o8owso88@franklakatos.com> Message-ID: On Wed, Feb 3, 2010 at 2:07 PM, wrote: > I absolutely love the idea of encapsulated the daisy chained calls > (c_u.comp.project) into a controller methods so all i gotta do is stub that > out. Oooh, I hate that one :) You're adding lots of small methods that actually don't define how the class should behave, IMO. In fact, how a client or project is related to a user is a responsibility of the models, not the controllers. I would much rather turn @client = current_user.company.clients.find(params[:project][:client_id]) @project = @client.projects.build(params[:project]) into @client = current_user.find_client(params[:project][:client_id]) @project = @client.projects.new(params[:project]) And add the helper method on the models. Even more: @project = current_user.add_project(params[:project]) And let the handling of the client and the business rules ("a project must belong to a client") to the models, as well Then your controller would be a lot slimmer, and the tests for it much simpler. def create @project = current_user.add_project(params[:project]) if @project.save flash[:notice] = "Added '#{@project.name}'" redirect_to somewhere else render :new end end Cheers, -foca > > Once again, thanks++ > Frank > > > Quoting David Chelimsky : > >> On Wed, Feb 3, 2010 at 8:52 AM, ? wrote: >>> >>> Ok, so these ideas seem kind of natural to me, which is nice: >>> >>> mock_models being used to mock non-tested models >>> stub for queries and/or well-tested methods, should_receives for commands >>> >>> While reading over Dave Astlels, I kind of got concerned because of >>> something he states that I feel I'm doing in my specs: >>> >>> "When you realize that it's all about specifying behaviour and not >>> writing >>> tests, your point of view shifts. Suddenly the idea of having a Test >>> class >>> for each of your production classes is ridiculously limiting. And the >>> thought of testing each of your methods with its own test method (in a >>> 1-1 relationship) will be laughable." >>> >>> This is what I am striving for, but being guided simply by rSpec error >>> messages results me in writing specs like this... >>> >>> describe "POST 'create'" do >>> >>> ? ?before do >>> ? ? ?@current_user = mock_model(User) >>> ? ? ?controller.stub(:current_user).and_return @current_user >>> ? ? ?@company = mock_model(Company) >>> ? ? ?@current_user.should_receive(:company).and_return @company >>> ? ? ?@clients = mock("Client List") >>> ? ? ?@company.should_receive(:clients).and_return @clients >>> ? ?end >>> >>> ? ?describe "when client is found" do >>> >>> ? ? ?before do >>> ? ? ? ?@client = mock_model(Client) >>> ? ? ? ?@clients.should_receive(:find).and_return @client >>> ? ? ?end >>> >>> ? ? ?describe "on successful save" do >>> >>> ? ? ? ?before do >>> ? ? ? ? ?@projects = mock_model(ActiveRecord) >> >> This is a little odd. @projects is a collection, not a an instance, >> and mocking ActiveRecord explicitly seems a bit odd. I'd generally us >> a simple array: >> >> @projects = [] >> >>> ? ? ? ? ?@client.should_receive(:projects).and_return @projects >>> ? ? ? ? ?@project = mock_model(Project) >>> ? ? ? ? ?@projects.should_receive(:build).and_return @project >>> ? ? ? ? ?@client.should_receive(:save).and_return true >>> ? ? ? ? ?@project.should_receive(:name).and_return "New Project" >>> ? ? ? ?end >>> >>> ? ? ? ?it "should set up the flash" do >>> ? ? ? ? ?post "create", {:project => {:client_id => 1}} >>> ? ? ? ? ?flash[:notice].should_not be_nil >>> ? ? ? ?end >>> >>> ? ? ?end >>> >>> ? ?end >>> >>> >>> ?end >>> >>> >>> >>> ... for a controller that looks like this ... >>> >>> >>> def create >>> ? ? ?@client = >>> current_user.company.clients.find(params[:project][:client_id]) >>> ? ? ?@project = @client.projects.build(params[:project]) >>> ? ? ?if @client.save >>> ? ? ? ?flash[:notice] = "Added: #{@project.name}" >>> ? ? ?else >>> ? ? ? ?render :new >>> ? ? ?end >>> ?end >>> >>> >>> >>> Am I doing the 1-1 thing that BDD specifically set out to avoid? >> >> 1-1 example per method is probably a red flag, but 1-1 spec file per >> implementation file makes navigation easier, so I think it's actually >> a good thing. >> >> The underlying problem with 1-1 mappings stems from IDE's that will >> make an empty test case by reflecting on an untested object. You'd end >> up with 50 line long test methods named "testGetName" that actually >> contain 20 different tests in the one method. That's an extreme, but I >> used to see that sort of thing all the time when I was consulting, and >> it makes it very difficult to understand what is being tested and what >> went wrong when there is a failure. >> >> Make sense? >> >> - David >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> Quoting Adam Sroka : >>> >>>> On Tue, Feb 2, 2010 at 9:53 PM, Andrei Erdoss wrote: >>>>> >>>>> Hello Frank, >>>>> >>>>> From my understanding these are the roles of should_receive and stub. >>>>> >>>>> should_receive checks to make sure that a method or a property is >>>>> called. >>>>> To >>>>> this you can specify the arguments that it gets called (.with()), what >>>>> it >>>>> returns (.and_return) and how many times this happens (.once, .twice >>>>> etc). >>>>> >>>>> stub on the other hand is a place holder for functions calls that have >>>>> been >>>>> tested already or are Rails defaults, which don't need to be tested. >>>>> stubs >>>>> are used in conjunction with mock_models, in order to provide for the >>>>> functions or properties that are needed for the code to run, up to the >>>>> test >>>>> point. >>>>> >>>> >>>> I think that it is best to think of these in terms of command query >>>> separation. In case you aren't familiar with that principle, it states >>>> that some methods are commands - they tell an object to do something >>>> but don't return anything interesting, and other methods are queries - >>>> they return some interesting value but have no side effects. >>>> >>>> should_receive is how we set an expectation for a command. We don't >>>> really care what a command returns but we do care that it gets called. >>>> should_receive literally says that the command should be called with >>>> the given parameters. >>>> >>>> stub is how we handle a query. We care what a query returns, or rather >>>> the code we are testing does, but we don't really care when it gets >>>> called (or how often) per se. If we depend on its result then it >>>> should be called, but the effect that the result has on the system >>>> we're testing is what we really care about. >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> >>> >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From jbrainsberger at gmail.com Wed Feb 3 12:21:18 2010 From: jbrainsberger at gmail.com (J. B. Rainsberger) Date: Wed, 3 Feb 2010 12:21:18 -0500 Subject: [rspec-users] When to use Factories, Mock Models, Mocks & Stubs In-Reply-To: References: <2ef359581002022206t79ca96etb7d35ba2129b8d97@mail.gmail.com> <20100203075216.dsohkzwahc84k000@franklakatos.com> <57c63afe1002030744s6b3efd2bi5163a0ccb841af39@mail.gmail.com> <20100203090709.madytmj0o8owso88@franklakatos.com> Message-ID: 2010/2/3 Nicol?s Sanguinetti : > On Wed, Feb 3, 2010 at 2:07 PM, ? wrote: >> I absolutely love the idea of encapsulated the daisy chained calls >> (c_u.comp.project) into a controller methods so all i gotta do is stub that >> out. > > Oooh, I hate that one :) > > You're adding lots of small methods that actually don't define how the > class should behave, IMO. > In fact, how a client or project is related to a user is a > responsibility of the models, not the controllers. > > I would much rather turn > > @client = current_user.company.clients.find(params[:project][:client_id]) > @project = @client.projects.build(params[:project]) > > into > > @client = current_user.find_client(params[:project][:client_id]) > @project = @client.projects.new(params[:project]) > > And add the helper method on the models. I strongly agree. Extracting the methods to the controller is merely an intermediate step. If the methods belong on other objects, then that tends to become clear soon enough. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. From rogerpack2005 at gmail.com Wed Feb 3 17:36:52 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Wed, 3 Feb 2010 14:36:52 -0800 (PST) Subject: [rspec-users] spec_server for test-unit Message-ID: A bit off topic, but does anybody know if there's an equivalent to "spec_server" for test-unit style tests? Thanks. -r From dchelimsky at gmail.com Wed Feb 3 17:55:26 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 3 Feb 2010 16:55:26 -0600 Subject: [rspec-users] spec_server for test-unit In-Reply-To: References: Message-ID: <57c63afe1002031455s465750a7l755479fabb230e06@mail.gmail.com> On Wed, Feb 3, 2010 at 4:36 PM, rogerdpack wrote: > A bit off topic, but does anybody know if there's an equivalent to > "spec_server" for test-unit style tests? spec-server was deprecated and removed a few versions back in favor of spork, which works with rspec and test/unit AFAIK. From rogerpack2005 at gmail.com Wed Feb 3 21:41:56 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Wed, 3 Feb 2010 18:41:56 -0800 (PST) Subject: [rspec-users] spec_server for test-unit In-Reply-To: <57c63afe1002031455s465750a7l755479fabb230e06@mail.gmail.com> References: <57c63afe1002031455s465750a7l755479fabb230e06@mail.gmail.com> Message-ID: <6d93307f-322d-459f-9174-cbbc3fe89ec6@s12g2000yqj.googlegroups.com> > spec-server was deprecated and removed a few versions back in favor of > spork, which works with rspec and test/unit AFAIK. Right, I was just wondering if there was something that pre-dated spork, but for test-unit shtuffs...spork does support test-unit but only barely--trying to see if there's something else that's a bit more full featured. -rp From monch1962 at gmail.com Thu Feb 4 00:12:11 2010 From: monch1962 at gmail.com (David Mitchell) Date: Thu, 4 Feb 2010 16:12:11 +1100 Subject: [rspec-users] Best practices to managing RSpec code for very large projects? Message-ID: Hello group, I've searched through several months messages in the archive, but haven't found an answer to this... What is the 'best practice' way to structure RSpec code and documentation when testing a very large project, where the RSpec code base has to be maintained and extended over a long period? A bit of background: I've just be brought onto a (non-Ruby) project that has unit- and functional-test suites written using RSpec. It's a large project, and growing; there's currently >20,000 distinct unit-test cases in RSpec, and a smaller (but still considerable) number of functional-test cases. The quantity of these test cases is still growing quickly, but they've hit a bottleneck in creating new test cases without breaking existing test cases. Over the life of the project, there's been a number of people writing RSpec tests without any overriding guidance on things like: - appropriate naming of helper functions - use of private vs. protected vs. public methods to only expose functionality as required - ensuring the scope of code is managed correctly (e.g. code for testing databases should probably be held in a module named 'Database') - documentation, in any form e.g. what a helper function does, what its side effects are, coverage of modules & how to extend them, ... - use of 'raise' and 'warn' to highlight problems - etc., etc. As a result, what exists now is basically a huge mess. For example, we've got multiple helper functions named identically, that serve very different purposes e.g. 'it_should_be_nil', with one doing a string comparison, another covering the number of records returned in a database cursor, and so on. The scope of these functions is such that they're accessible from all the 'wrong' places, so it's quite possible that the wrong helper function could accidentally be referenced at any point and quite difficult to identify which one of several identically-named helper functions is going to be executed at any given point. Aside from some serious therapy, what I'm looking for is some sort of 'best practices' documentation covering how to use RSpec to create *and maintain* a very large population of test cases over an extended period of time. If I can get that, then I can at least start working in the right direction to ensure the problem doesn't get any worse, and then start fixing what exists now. Issues that are biting me right now include: - how to structure a hierarchy of RSpec modules to cover both unit- and functional-test requirements. For unit-testing, it seems to make sense to create a hierarchy along infrastructure lines, so there might be a module named 'Database' that includes all the generic database test functions (e.g. check table names, field names, field definitions, constraints, triggers, ... are all defined correctly), that is subclassed into distinct modules for each database instance being tested. However, for functional-testing, it seems to make more sense to create a hierarchy along business process lines, so that helper functions covering a particular set of business functionality are bundled together. Given you'll probably want to use a lot of the same methods in both your functional- and unit-test code, what's the best way to structure this hierarchy? - use of modules/namespaces to achieve sensible isolation of functionality (e.g. the 'it_should_be_nil' problem described above), while still having the code referencing functions in modules being readable - documentation requirements when building/maintaining a large RSpec test suite over an extended period of time, so that you don't wind up relying exclusively on knowledge held in the heads of key people, and new people can be brought up to date on "how it all hangs together" relatively quickly If anyone can point me to useful reference material along these lines, I'd greatly appreciate it. Thanks in advance David Mitchell -------------- next part -------------- An HTML attachment was scrubbed... URL: From jbrainsberger at gmail.com Thu Feb 4 09:09:45 2010 From: jbrainsberger at gmail.com (J. B. Rainsberger) Date: Thu, 4 Feb 2010 09:09:45 -0500 Subject: [rspec-users] Best practices to managing RSpec code for very large projects? In-Reply-To: References: Message-ID: On Thu, Feb 4, 2010 at 00:12, David Mitchell wrote: > What is the 'best practice' way to structure RSpec code and documentation > when testing a very large project, where the RSpec code base has to be > maintained and extended over a long period? I don't mean to be glib, but my blink reaction is that there's nothing different between maintaining a large suite of RSpec examples and any other large code base. I think all the design principles for large production code bases apply to large suites of RSpec examples. > Over the life of the project, there's been a number of people writing RSpec > tests without any overriding guidance on things like: > - appropriate naming of helper functions > - use of private vs. protected vs. public methods to only expose > functionality as required > - ensuring the scope of code is managed correctly (e.g. code for testing > databases should probably be held in a module named 'Database') > - documentation, in any form e.g. what a helper function does, what its side > effects are, coverage of modules & how to extend them, ... > - use of 'raise' and 'warn' to highlight problems > - etc., etc. I truly think the Four Elements of Simple Deign would help all those. > As a result, what exists now is basically a huge mess. ?For example, we've > got multiple helper functions named identically, that serve very different > purposes e.g. 'it_should_be_nil', with one doing a string comparison, > another covering the number of records returned in a database cursor, and so > on. ?The scope of these functions is such that they're accessible from all > the 'wrong' places, so it's quite possible that the wrong helper function > could accidentally be referenced at any point and quite difficult to > identify which one of several identically-named helper functions is going to > be executed at any given point. > Aside from some serious therapy, what I'm looking for is some sort of 'best > practices' documentation covering how to use RSpec to create *and maintain* > a very large population of test cases over an extended period of time. ?If I > can get that, then I can at least start working in the right direction to > ensure the problem doesn't get any worse, and then start fixing what exists > now. ?Issues that are biting me right now include: > - how to structure a hierarchy of RSpec modules to cover both unit- and > functional-test requirements. ?For unit-testing, it seems to make sense to > create a hierarchy along infrastructure lines, so there might be a module > named 'Database' that includes all the generic database test functions (e.g. > check table names, field names, field definitions, constraints, triggers, > ... are all defined correctly), that is subclassed into distinct modules for > each database instance being tested. ?However, for functional-testing, it > seems to make more sense to create a hierarchy along business process lines, > so that helper functions covering a particular set of business functionality > are bundled together. ?Given you'll probably want to use a lot of the same > methods in both your functional- and unit-test code, what's the best way to > structure this hierarchy? > - use of modules/namespaces to achieve sensible isolation of functionality > (e.g. the 'it_should_be_nil' problem described above), while still having > the code referencing functions in modules being readable > - documentation requirements when building/maintaining a large RSpec test > suite over an extended period of time, so that you don't wind up relying > exclusively on knowledge held in the heads of key people, and new people can > be brought up to date on "how it all hangs together" relatively quickly > If anyone can point me to useful reference material along these lines, I'd > greatly appreciate it. Have you read Feathers' "Working Effectively with Legacy Code"? I think that might help you recover from this mess. As for some Novice Rules to organize your examples, I recommend this: * Keep offline and online examples separate, so I can run all the examples that require expensive external resources separately from the one that don't. I use separate source folders for this. * Move test data creation into a folder like Rails' relatively new spec/support folder. Over time, introduce libraries like FactoryGirl to reduce the amount of code you write to create test data. * Refactor test facilities, like custom matchers, to spec/support to make them available to everyone. To fix the underlying problem, I recommend something bigger: invite your teams to spend 90 minutes, once per week, putting their examples up on a projector and play "What's not to like about this code?" Start refactoring it there and then. Doing this every week helps teams converge on their understanding of "good enough design" as well as helps them share information about how they organize their examples and the code that supports them. It simply sounds like your programmers don't discuss these ideas with each other enough, or if they do, they don't agree enough. Whatever changes you make to the code base don't matter if you don't also do something like this. Good luck. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. From dchelimsky at gmail.com Thu Feb 4 09:40:56 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 4 Feb 2010 08:40:56 -0600 Subject: [rspec-users] Best practices to managing RSpec code for very large projects? In-Reply-To: References: Message-ID: <57c63afe1002040640p12343214m41de0b0ab0640503@mail.gmail.com> On Thu, Feb 4, 2010 at 8:09 AM, J. B. Rainsberger wrote: > On Thu, Feb 4, 2010 at 00:12, David Mitchell wrote: > >> What is the 'best practice' way to structure RSpec code and documentation >> when testing a very large project, where the RSpec code base has to be >> maintained and extended over a long period? > > I don't mean to be glib, but my blink reaction is that there's nothing > different between maintaining a large suite of RSpec examples and any > other large code base. +1 I don't find this glib at all. The question is a difficult one to answer in a sentence or two, and I think you sum it up pretty well with this. Cheers, David > I think all the design principles for large > production code bases apply to large suites of RSpec examples. > >> Over the life of the project, there's been a number of people writing RSpec >> tests without any overriding guidance on things like: >> - appropriate naming of helper functions >> - use of private vs. protected vs. public methods to only expose >> functionality as required >> - ensuring the scope of code is managed correctly (e.g. code for testing >> databases should probably be held in a module named 'Database') >> - documentation, in any form e.g. what a helper function does, what its side >> effects are, coverage of modules & how to extend them, ... >> - use of 'raise' and 'warn' to highlight problems >> - etc., etc. > > I truly think the Four Elements of Simple Deign would help all those. > >> As a result, what exists now is basically a huge mess. ?For example, we've >> got multiple helper functions named identically, that serve very different >> purposes e.g. 'it_should_be_nil', with one doing a string comparison, >> another covering the number of records returned in a database cursor, and so >> on. ?The scope of these functions is such that they're accessible from all >> the 'wrong' places, so it's quite possible that the wrong helper function >> could accidentally be referenced at any point and quite difficult to >> identify which one of several identically-named helper functions is going to >> be executed at any given point. >> Aside from some serious therapy, what I'm looking for is some sort of 'best >> practices' documentation covering how to use RSpec to create *and maintain* >> a very large population of test cases over an extended period of time. ?If I >> can get that, then I can at least start working in the right direction to >> ensure the problem doesn't get any worse, and then start fixing what exists >> now. ?Issues that are biting me right now include: >> - how to structure a hierarchy of RSpec modules to cover both unit- and >> functional-test requirements. ?For unit-testing, it seems to make sense to >> create a hierarchy along infrastructure lines, so there might be a module >> named 'Database' that includes all the generic database test functions (e.g. >> check table names, field names, field definitions, constraints, triggers, >> ... are all defined correctly), that is subclassed into distinct modules for >> each database instance being tested. ?However, for functional-testing, it >> seems to make more sense to create a hierarchy along business process lines, >> so that helper functions covering a particular set of business functionality >> are bundled together. ?Given you'll probably want to use a lot of the same >> methods in both your functional- and unit-test code, what's the best way to >> structure this hierarchy? >> - use of modules/namespaces to achieve sensible isolation of functionality >> (e.g. the 'it_should_be_nil' problem described above), while still having >> the code referencing functions in modules being readable >> - documentation requirements when building/maintaining a large RSpec test >> suite over an extended period of time, so that you don't wind up relying >> exclusively on knowledge held in the heads of key people, and new people can >> be brought up to date on "how it all hangs together" relatively quickly >> If anyone can point me to useful reference material along these lines, I'd >> greatly appreciate it. > > Have you read Feathers' "Working Effectively with Legacy Code"? I > think that might help you recover from this mess. > > As for some Novice Rules to organize your examples, I recommend this: > > * Keep offline and online examples separate, so I can run all the > examples that require expensive external resources separately from the > one that don't. I use separate source folders for this. > * Move test data creation into a folder like Rails' relatively new > spec/support folder. Over time, introduce libraries like FactoryGirl > to reduce the amount of code you write to create test data. > * Refactor test facilities, like custom matchers, to spec/support to > make them available to everyone. > > To fix the underlying problem, I recommend something bigger: invite > your teams to spend 90 minutes, once per week, putting their examples > up on a projector and play "What's not to like about this code?" Start > refactoring it there and then. Doing this every week helps teams > converge on their understanding of "good enough design" as well as > helps them share information about how they organize their examples > and the code that supports them. It simply sounds like your > programmers don't discuss these ideas with each other enough, or if > they do, they don't agree enough. Whatever changes you make to the > code base don't matter if you don't also do something like this. > > Good luck. > -- > J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: > http://blog.thecodewhisperer.com > Diaspar Software Services :: http://www.diasparsoftware.com > Author, JUnit Recipes > 2005 Gordon Pask Award for contribution to Agile practice :: Agile > 2010: Learn. Practice. Explore. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Thu Feb 4 09:47:14 2010 From: lists at ruby-forum.com (Stuart Corbishley) Date: Thu, 4 Feb 2010 15:47:14 +0100 Subject: [rspec-users] rSpec 2 covered in the rSpec Book Message-ID: Is rSpec 2.0 going to be covered at all in the rSpec book, I'm expecting delivery of the book as soon as it goes to print, so just curious. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Feb 4 09:50:47 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 4 Feb 2010 08:50:47 -0600 Subject: [rspec-users] rSpec 2 covered in the rSpec Book In-Reply-To: References: Message-ID: <57c63afe1002040650x11a97697h25bc3f71cc873bd0@mail.gmail.com> On Thu, Feb 4, 2010 at 8:47 AM, Stuart Corbishley wrote: > Is rSpec 2.0 going to be covered at all in the rSpec book, I'm expecting > delivery of the book as soon as it goes to print, so just curious. Unfortunately, no. To cover rspec-2 in the book we'd have to push back delivery by a few months, which is a non-option at this point. The good news is that the differences are mostly internal, so all the examples that don't pertain to extending the internals will still work. From rick.denatale at gmail.com Thu Feb 4 09:51:08 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 4 Feb 2010 09:51:08 -0500 Subject: [rspec-users] Best practices to managing RSpec code for very large projects? In-Reply-To: <57c63afe1002040640p12343214m41de0b0ab0640503@mail.gmail.com> References: <57c63afe1002040640p12343214m41de0b0ab0640503@mail.gmail.com> Message-ID: On Thu, Feb 4, 2010 at 9:40 AM, David Chelimsky wrote: > On Thu, Feb 4, 2010 at 8:09 AM, J. B. Rainsberger > wrote: >> On Thu, Feb 4, 2010 at 00:12, David Mitchell wrote: >> >>> What is the 'best practice' way to structure RSpec code and documentation >>> when testing a very large project, where the RSpec code base has to be >>> maintained and extended over a long period? >> >> I don't mean to be glib, but my blink reaction is that there's nothing >> different between maintaining a large suite of RSpec examples and any >> other large code base. > > +1 > > I don't find this glib at all. The question is a difficult one to > answer in a sentence or two, and I think you sum it up pretty well > with this. Yep! It's just a small battle in the never-ending war against the increase of entropy. It may seem hard, but remember the more you fight it the more you delay the heat death of the universe! -- 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 lists at ruby-forum.com Thu Feb 4 10:00:18 2010 From: lists at ruby-forum.com (Stuart Corbishley) Date: Thu, 4 Feb 2010 16:00:18 +0100 Subject: [rspec-users] rSpec 2 covered in the rSpec Book In-Reply-To: <57c63afe1002040650x11a97697h25bc3f71cc873bd0@mail.gmail.com> References: <57c63afe1002040650x11a97697h25bc3f71cc873bd0@mail.gmail.com> Message-ID: David Chelimsky wrote: > On Thu, Feb 4, 2010 at 8:47 AM, Stuart Corbishley > wrote: >> Is rSpec 2.0 going to be covered at all in the rSpec book, I'm expecting >> delivery of the book as soon as it goes to print, so just curious. > > Unfortunately, no. To cover rspec-2 in the book we'd have to push back > delivery by a few months, which is a non-option at this point. > > The good news is that the differences are mostly internal, so all the > examples that don't pertain to extending the internals will still > work. Ok great! Looking forward to the book! -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Thu Feb 4 10:46:20 2010 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 4 Feb 2010 15:46:20 +0000 Subject: [rspec-users] Best practices to managing RSpec code for very large projects? In-Reply-To: References: Message-ID: <8F79B8D7-9728-435D-952D-13CE8EEA1461@mattwynne.net> On 4 Feb 2010, at 14:09, J. B. Rainsberger wrote: > On Thu, Feb 4, 2010 at 00:12, David Mitchell > wrote: > >> What is the 'best practice' way to structure RSpec code and >> documentation >> when testing a very large project, where the RSpec code base has to >> be >> maintained and extended over a long period? > > I don't mean to be glib, but my blink reaction is that there's nothing > different between maintaining a large suite of RSpec examples and any > other large code base. I think all the design principles for large > production code bases apply to large suites of RSpec examples. > >> Over the life of the project, there's been a number of people >> writing RSpec >> tests without any overriding guidance on things like: >> - appropriate naming of helper functions >> - use of private vs. protected vs. public methods to only expose >> functionality as required >> - ensuring the scope of code is managed correctly (e.g. code for >> testing >> databases should probably be held in a module named 'Database') >> - documentation, in any form e.g. what a helper function does, what >> its side >> effects are, coverage of modules & how to extend them, ... >> - use of 'raise' and 'warn' to highlight problems >> - etc., etc. > > I truly think the Four Elements of Simple Deign would help all those. > >> As a result, what exists now is basically a huge mess. For >> example, we've >> got multiple helper functions named identically, that serve very >> different >> purposes e.g. 'it_should_be_nil', with one doing a string comparison, >> another covering the number of records returned in a database >> cursor, and so >> on. The scope of these functions is such that they're accessible >> from all >> the 'wrong' places, so it's quite possible that the wrong helper >> function >> could accidentally be referenced at any point and quite difficult to >> identify which one of several identically-named helper functions is >> going to >> be executed at any given point. >> Aside from some serious therapy, what I'm looking for is some sort >> of 'best >> practices' documentation covering how to use RSpec to create *and >> maintain* >> a very large population of test cases over an extended period of >> time. If I >> can get that, then I can at least start working in the right >> direction to >> ensure the problem doesn't get any worse, and then start fixing >> what exists >> now. Issues that are biting me right now include: >> - how to structure a hierarchy of RSpec modules to cover both unit- >> and >> functional-test requirements. For unit-testing, it seems to make >> sense to >> create a hierarchy along infrastructure lines, so there might be a >> module >> named 'Database' that includes all the generic database test >> functions (e.g. >> check table names, field names, field definitions, constraints, >> triggers, >> ... are all defined correctly), that is subclassed into distinct >> modules for >> each database instance being tested. However, for functional- >> testing, it >> seems to make more sense to create a hierarchy along business >> process lines, >> so that helper functions covering a particular set of business >> functionality >> are bundled together. Given you'll probably want to use a lot of >> the same >> methods in both your functional- and unit-test code, what's the >> best way to >> structure this hierarchy? >> - use of modules/namespaces to achieve sensible isolation of >> functionality >> (e.g. the 'it_should_be_nil' problem described above), while still >> having >> the code referencing functions in modules being readable >> - documentation requirements when building/maintaining a large >> RSpec test >> suite over an extended period of time, so that you don't wind up >> relying >> exclusively on knowledge held in the heads of key people, and new >> people can >> be brought up to date on "how it all hangs together" relatively >> quickly >> If anyone can point me to useful reference material along these >> lines, I'd >> greatly appreciate it. Have you tried pair programming? > Have you read Feathers' "Working Effectively with Legacy Code"? I > think that might help you recover from this mess. > > As for some Novice Rules to organize your examples, I recommend this: > > * Keep offline and online examples separate, so I can run all the > examples that require expensive external resources separately from the > one that don't. I use separate source folders for this. > * Move test data creation into a folder like Rails' relatively new > spec/support folder. Over time, introduce libraries like FactoryGirl > to reduce the amount of code you write to create test data. > * Refactor test facilities, like custom matchers, to spec/support to > make them available to everyone. > > To fix the underlying problem, I recommend something bigger: invite > your teams to spend 90 minutes, once per week, putting their examples > up on a projector and play "What's not to like about this code?" Start > refactoring it there and then. Doing this every week helps teams > converge on their understanding of "good enough design" as well as > helps them share information about how they organize their examples > and the code that supports them. It simply sounds like your > programmers don't discuss these ideas with each other enough, or if > they do, they don't agree enough. Whatever changes you make to the > code base don't matter if you don't also do something like this. > > Good luck. > -- > J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: > http://blog.thecodewhisperer.com > Diaspar Software Services :: http://www.diasparsoftware.com > Author, JUnit Recipes > 2005 Gordon Pask Award for contribution to Agile practice :: Agile > 2010: Learn. Practice. Explore. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From zenshade at gmail.com Thu Feb 4 12:35:33 2010 From: zenshade at gmail.com (Levi Conley) Date: Thu, 4 Feb 2010 12:35:33 -0500 Subject: [rspec-users] Passing parameters to Rspec scripts In-Reply-To: References: <655d96db1002021951v7c44ddadr4e1e3f281c7a1749@mail.gmail.com> Message-ID: <655d96db1002040935o278339c9rcfea2279e22d84ff@mail.gmail.com> Thanks for the response. That's an interesting approach. I will try that and see how far I can get with it. If my ruby chops were a little better, I suspect I could find a more elegant solution. Any other ideas out there? On 2/3/10, Matt Wynne wrote: > One way would be to use an environment variable: > > $ CUSTOMER=foo spec spec > > Then read out the customer name in your specs: > > login = ENV['CUSTOMER'] > > Otherwise, I would guess you might be able to look at ARGV from > within, say, spec_helper.rb but I've never tried it. > > On 3 Feb 2010, at 03:51, Levi Conley wrote: > >> Newbie here. I'm hoping someone can give me an outline of how to >> re-use rspec scripts by passing them parameters. >> >> The situation I have is testing a web application (using watir) for >> about 30 different customers. Some of the customers have unique >> features in their particular application instance, but much of the >> codebase is shared (about 90%). So what I need to be able to do is >> write rspec tests covering that shared codebase. But I need to in >> some way pass in the customer name so that watir can log into the >> right application instance. >> >> Any help with this is greatly appreciated. I still have much to learn >> about Rspec, but so far this seemingly simple task has me stumped. >> >> Thanks >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > cheers, > Matt > > http://mattwynne.net > +447974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- My mother used to say to me, "In this world, Elwood, you must be oh so smart or oh so pleasant." Well, for years I was smart. I recommend pleasant. You may quote me. From jbrainsberger at gmail.com Thu Feb 4 16:11:30 2010 From: jbrainsberger at gmail.com (J. B. Rainsberger) Date: Thu, 4 Feb 2010 16:11:30 -0500 Subject: [rspec-users] Passing parameters to Rspec scripts In-Reply-To: <655d96db1002040935o278339c9rcfea2279e22d84ff@mail.gmail.com> References: <655d96db1002021951v7c44ddadr4e1e3f281c7a1749@mail.gmail.com> <655d96db1002040935o278339c9rcfea2279e22d84ff@mail.gmail.com> Message-ID: On Thu, Feb 4, 2010 at 12:35, Levi Conley wrote: > Thanks for the response. That's an interesting approach. ?I will try > that and see how far I can get with it. > > If my ruby chops were a little better, I suspect I could find a more > elegant solution. ?Any other ideas out there? It sounds like you want a configuration file of some kind. In Java, I'd suggest starting with a properties file. Could you externalize the per-customer differences to any kind of configuration file (yaml would be the standard, no?)? Then you could build a rake task to supply the right configuration file for each customer, or even iterate over them. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. From jbrainsberger at gmail.com Thu Feb 4 16:09:17 2010 From: jbrainsberger at gmail.com (J. B. Rainsberger) Date: Thu, 4 Feb 2010 16:09:17 -0500 Subject: [rspec-users] Best practices to managing RSpec code for very large projects? In-Reply-To: <57c63afe1002040640p12343214m41de0b0ab0640503@mail.gmail.com> References: <57c63afe1002040640p12343214m41de0b0ab0640503@mail.gmail.com> Message-ID: On Thu, Feb 4, 2010 at 09:40, David Chelimsky wrote: > On Thu, Feb 4, 2010 at 8:09 AM, J. B. Rainsberger > wrote: >> On Thu, Feb 4, 2010 at 00:12, David Mitchell wrote: >> >>> What is the 'best practice' way to structure RSpec code and documentation >>> when testing a very large project, where the RSpec code base has to be >>> maintained and extended over a long period? >> >> I don't mean to be glib, but my blink reaction is that there's nothing >> different between maintaining a large suite of RSpec examples and any >> other large code base. > > +1 > > I don't find this glib at all. The question is a difficult one to > answer in a sentence or two, and I think you sum it up pretty well > with this. Thanks for that. -- J. B. (Joe) Rainsberger :: http://www.jbrains.ca :: http://blog.thecodewhisperer.com Diaspar Software Services :: http://www.diasparsoftware.com Author, JUnit Recipes 2005 Gordon Pask Award for contribution to Agile practice :: Agile 2010: Learn. Practice. Explore. From steve at fenestra.com Thu Feb 4 16:43:22 2010 From: steve at fenestra.com (Steve Schafer) Date: Thu, 04 Feb 2010 16:43:22 -0500 Subject: [rspec-users] Best practices to managing RSpec code for verylar ge projects? In-Reply-To: References: <57c63afe100204064 0p12343214m41de0b0ab0640503@mail.gmail.com> <57c63afe1002040640p12343214m41de0b0ab0640503@mail.gmail.com> Message-ID: On Thu, 4 Feb 2010 09:51:08 -0500, you wrote: >It's just a small battle in the never-ending war against the increase >of entropy. > >It may seem hard, but remember the more you fight it the more you >delay the heat death of the universe! Actually, it's just the opposite: Any attempt to reduce local entropy results in a net increase in global entropy. So if you're interested in prolonging the life of the universe, the best thing to do is sit quietly in a corner and do nothing. -Steve From dchelimsky at gmail.com Thu Feb 4 21:09:41 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 4 Feb 2010 20:09:41 -0600 Subject: [rspec-users] spec_server for test-unit In-Reply-To: <6d93307f-322d-459f-9174-cbbc3fe89ec6@s12g2000yqj.googlegroups.com> References: <57c63afe1002031455s465750a7l755479fabb230e06@mail.gmail.com> <6d93307f-322d-459f-9174-cbbc3fe89ec6@s12g2000yqj.googlegroups.com> Message-ID: <57c63afe1002041809r400e966cif16b87bbb384dc06@mail.gmail.com> On Wed, Feb 3, 2010 at 8:41 PM, rogerdpack wrote: >> spec-server was deprecated and removed a few versions back in favor of >> spork, which works with rspec and test/unit AFAIK. > > Right, I was just wondering if there was something that pre-dated > spork, but for test-unit shtuffs...spork does support test-unit but > only barely--trying to see if there's something else that's a bit more > full featured. Take a look at http://tddmate.rubyforge.org/svn/trunk/ - it's a predecessor to spec_server. Not sure if it works outside textmate, but it might. From elc at mingins.com Thu Feb 4 21:43:08 2010 From: elc at mingins.com (Shane Mingins) Date: Fri, 5 Feb 2010 15:43:08 +1300 Subject: [rspec-users] rspec-core requires rspec-expectations Message-ID: <734573e81002041843w11ecbef6v413633bc6ee51cfd@mail.gmail.com> Hi Just wondering if anyone knows why I am getting this error now .... ?? gem install rspec-rails --version 1.2.9 --no-ri --no-rdoc ************************************************** Thank you for installing rspec-rails-1.2.9 If you are upgrading, do this in each of your rails apps that you want to upgrade: $ ruby script/generate rspec Please be sure to read History.rdoc and Upgrade.rdoc for useful information about this release. ************************************************** ERROR: Error installing rspec-rails: rspec-core requires rspec-expectations (>= 2.0.0.a2, runtime) cheers shane -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Fri Feb 5 09:10:55 2010 From: lists at ruby-forum.com (Saverio Miroddi) Date: Fri, 5 Feb 2010 15:10:55 +0100 Subject: [rspec-users] Stub activerecord find given instance? In-Reply-To: <6c35a5c91001241905r1205fc12me243fb28f1c2cca5@mail.gmail.com> References: <4A3616AC-32C2-478C-B20D-DF65FE1C031E@experthuman.com> <57c63afe0912140439y4c5a00fbtb65d155eccd5426f@mail.gmail.com> <57c63afe1001121949h444bc715x89fee7e8bc81f84c@mail.gmail.com> <6c35a5c91001241905r1205fc12me243fb28f1c2cca5@mail.gmail.com> Message-ID: <993e7531fc1e04502bc42c3a951b0749@ruby-forum.com> Thanks for the help - I'm going to look directly at the source code, though of course the recommendation of improving the tests rather than stretch the api itself is very welcome! If I'm going to find anything notable (I have kind of a hunch that I will), I'll post it. Saverio Paul Hinze wrote: > On Sun, Jan 24, 2010 at 5:10 PM, Saverio Miroddi > wrote: >> class MyController < ... >> ?def show >> ? ?m = MyModel.find( params[ :id ] ) >> ? ?mp = m.my_parent >> >> ? ?@m_value = m.value >> ? ?@mp_value = mp.value >> ?end >> end > > Hi Saverio, > > Following this thread, and still having trouble understanding what it > it you are trying to accomplish. > >> now, suppose I want to stub a behavior only for the child object ('m'). >> so my intention in the spec is to: >> >> - create the child and his parent >> - stub MyModel#value in the child >> - stub MyModel.find to return "m" _only_ when called with the child id, >> otherwise it should do its usual business. if I stub generically, >> m#my_parent would return "m" itself. > > The below test does not accomplish this third point... I'll explain > below. > >> the test would be: >> >> it "should display a stubbed value for the children" do >> ?mp = MyModel.create!( :value => 0xCAFEBABE ) >> ?m ?= MyModel.create!( :my_parent_id => mp.id, :value => 64738 ) >> >> ?m.stub!( :value ).with( m.id ).and_return( 42 ) > > Here you are creating a stub on the instance `m`, not stubbing > `MyModel.find` as you explain above. Perhaps you meant something more > like this? > > m.stub!(:value).and_return(42) > MyModel.stub!(:find).with(m.id).and_return(m) > -- Posted via http://www.ruby-forum.com/. From kmandrup at gmail.com Fri Feb 5 11:38:48 2010 From: kmandrup at gmail.com (Kristian Mandrup) Date: Fri, 5 Feb 2010 08:38:48 -0800 (PST) Subject: [rspec-users] RSpec Rails 3 generators - first draft Message-ID: <2123ed5a-6a11-472e-ab42-d1a86838e6dc@l26g2000yqd.googlegroups.com> I have just finished creating a working set of Rails 3 compatible generators for RSpec. http://github.com/kristianmandrup/rspec_rails3_gen Also available from gemcutter under the same name: rspec_rails3_gen They work pretty well, except for the hooks functionality which still needs some work hook_for :model, :scaffold, .... I hope to add hook support/integration real soon ;) At least this is a start.... but perhaps there are already rspec generators for rails 3 out there? Kristian From dchelimsky at gmail.com Fri Feb 5 17:17:49 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 5 Feb 2010 16:17:49 -0600 Subject: [rspec-users] RSpec Rails 3 generators - first draft In-Reply-To: <2123ed5a-6a11-472e-ab42-d1a86838e6dc@l26g2000yqd.googlegroups.com> References: <2123ed5a-6a11-472e-ab42-d1a86838e6dc@l26g2000yqd.googlegroups.com> Message-ID: <57c63afe1002051417s1e67cda3u15f22c6ac14095da@mail.gmail.com> On Fri, Feb 5, 2010 at 10:38 AM, Kristian Mandrup wrote: > I have just finished creating a working set of Rails 3 compatible > generators for RSpec. > > http://github.com/kristianmandrup/rspec_rails3_gen > > Also available from gemcutter under the same name: rspec_rails3_gen > > They work pretty well, except for the hooks functionality which still > needs some work > > hook_for :model, :scaffold, .... > > I hope to add hook support/integration real soon ;) > > At least this is a start.... but perhaps there are already rspec > generators for rails 3 out there? There are, in the rspec-rails-2.0.0a series (currently a4). They are borrowed from a lib Jos? Valim had up on his github account (but it's not there any longer). They are preliminary at this point, but have a look and feel free to send patches for anything that's missing: gem install rspec-rails --pre http://github.com/rspec/rspec-rails Cheers, David > > Kristian > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From merbjedi at gmail.com Sun Feb 7 04:48:31 2010 From: merbjedi at gmail.com (Jacques Crocker) Date: Sun, 7 Feb 2010 01:48:31 -0800 (PST) Subject: [rspec-users] Rails3 + RSpec2 sample project? Message-ID: <07fc69a2-0250-4714-923d-86dcb4bd55c0@b36g2000pri.googlegroups.com> If anyone has any sort of Rails3 + Rspec2 project sort of working, we should get a stripped down sample project on github. Martin did a great one for datamapper: http://github.com/snusnu/datamapper_on_rails3. I can help getting it organized / tested, but I havent been able to get things working quite yet. I know its all sort of still in flux at the moment. But any help would be appreciated on how to organize rspec with rails3. From dchelimsky at gmail.com Sun Feb 7 15:41:13 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 7 Feb 2010 14:41:13 -0600 Subject: [rspec-users] Rails3 + RSpec2 sample project? In-Reply-To: <07fc69a2-0250-4714-923d-86dcb4bd55c0@b36g2000pri.googlegroups.com> References: <07fc69a2-0250-4714-923d-86dcb4bd55c0@b36g2000pri.googlegroups.com> Message-ID: <57c63afe1002071241o40259470x1e673602b2a4e5cc@mail.gmail.com> On Sun, Feb 7, 2010 at 3:48 AM, Jacques Crocker wrote: > If anyone has any sort of Rails3 + Rspec2 project sort of working, we > should get a stripped down sample project on github. Martin did a > great one for datamapper: http://github.com/snusnu/datamapper_on_rails3. > I can help getting it organized / tested, but I havent been able to > get things working quite yet. > > I know its all sort of still in flux at the moment. But any help would > be appreciated on how to organize rspec with rails3. I don't have time to do a proper blog post right now, but I'll try to get something up in a day or two. In the mean time, assuming you have rails 3 pre already installed: rails foo cd foo echo "gem 'rspec-rails', '>=2.0.0.a5' :group => :test" >> Gemfile script/rails generate rspec:install rspec:install installs, among other things, a generator so you can just say: script/rails generate model thing name:string ... and you'll get a model spec instead of a rails unit test. The a5 release only supports model and request (integration - a la merb) specs, but controllers, views and helpers will be coming soon. Cheers, David From dchelimsky at gmail.com Sun Feb 7 15:41:50 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 7 Feb 2010 14:41:50 -0600 Subject: [rspec-users] Rails3 + RSpec2 sample project? In-Reply-To: <57c63afe1002071241o40259470x1e673602b2a4e5cc@mail.gmail.com> References: <07fc69a2-0250-4714-923d-86dcb4bd55c0@b36g2000pri.googlegroups.com> <57c63afe1002071241o40259470x1e673602b2a4e5cc@mail.gmail.com> Message-ID: <57c63afe1002071241h5901f932ia555e4202940c6bb@mail.gmail.com> On Sun, Feb 7, 2010 at 2:41 PM, David Chelimsky wrote: > On Sun, Feb 7, 2010 at 3:48 AM, Jacques Crocker wrote: >> If anyone has any sort of Rails3 + Rspec2 project sort of working, we >> should get a stripped down sample project on github. Martin did a >> great one for datamapper: http://github.com/snusnu/datamapper_on_rails3. >> I can help getting it organized / tested, but I havent been able to >> get things working quite yet. >> >> I know its all sort of still in flux at the moment. But any help would >> be appreciated on how to organize rspec with rails3. > > I don't have time to do a proper blog post right now, but I'll try to > get something up in a day or two. In the mean time, assuming you have > rails 3 pre already installed: > > rails foo > cd foo > echo "gem 'rspec-rails', '>=2.0.0.a5' :group => :test" >> Gemfile This should be: echo "gem 'rspec-rails', '>=2.0.0.a5', :group => :test" >> Gemfile (was missing a comma). > script/rails generate rspec:install > > rspec:install installs, among other things, a generator so you can just say: > > ?script/rails generate model thing name:string > > ... and you'll get a model spec instead of a rails unit test. > > The a5 release only supports model and request (integration - a la > merb) specs, but controllers, views and helpers will be coming soon. > > Cheers, > David > From ashley.moran at patchspace.co.uk Sun Feb 7 16:52:47 2010 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 7 Feb 2010 21:52:47 +0000 Subject: [rspec-users] Rails3 + RSpec2 sample project? In-Reply-To: <57c63afe1002071241o40259470x1e673602b2a4e5cc@mail.gmail.com> References: <07fc69a2-0250-4714-923d-86dcb4bd55c0@b36g2000pri.googlegroups.com> <57c63afe1002071241o40259470x1e673602b2a4e5cc@mail.gmail.com> Message-ID: <05DA9277-941C-4A7E-A587-99749006E685@patchspace.co.uk> On 7 Feb 2010, at 8:41 PM, David Chelimsky wrote: > The a5 release only supports model and request (integration - a la > merb) specs, but controllers, views and helpers will be coming soon. Well chop chop then, anyone would think you were working for free ;o) On a more serious note, I think the Rails 3 beta is the final trigger for me to switch from the (I'm sad to say) increasingly rusty Merb to Rails 3 / Ruby 1.9. It's clear there are a plenty of integration issues to work out. I'm currently spending at least half my time working on a project of my own, but I can't see that moving forwards until I have RSpec/Cucumber in place. So feel free to point me to relevant RSpec tickets and I'll work on those instead, in the mean time. Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran From phillipkoebbe at gmail.com Sun Feb 7 21:34:37 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Sun, 07 Feb 2010 20:34:37 -0600 Subject: [rspec-users] Testing controller plugin In-Reply-To: References: <4B66EFCB.2010302@gmail.com> Message-ID: <4B6F783D.2030504@gmail.com> Matt Wynne wrote: > On 1 Feb 2010, at 15:14, Phillip Koebbe wrote: > >> I have just recently started creating some plugins, mainly of the >> controller variety. I have been looking for a tutorial or other >> documentation detailing how to go about testing these plugins with >> RSpec, but have not yet found anything helpful. Can anyone point me >> toward such a thing? > > Create a controller in your specs which uses the plugin in an > exemplary way, then asserts the behaviour of that controller. > > Thanks, Matt. I have some parts of it working now, but am stumped when trying to call an action. I need to do a post :create, but post is not a known method. Do you happen to know of a controller plugin that used RSpec that I could peruse? Thanks, Phillip From matt at mattwynne.net Mon Feb 8 04:12:24 2010 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 8 Feb 2010 09:12:24 +0000 Subject: [rspec-users] Testing controller plugin In-Reply-To: <4B6F783D.2030504@gmail.com> References: <4B66EFCB.2010302@gmail.com> <4B6F783D.2030504@gmail.com> Message-ID: <3C5CA2B6-4252-4A69-8D03-D33DB0E52E9D@mattwynne.net> On 8 Feb 2010, at 02:34, Phillip Koebbe wrote: > > > Matt Wynne wrote: >> On 1 Feb 2010, at 15:14, Phillip Koebbe wrote: >> >>> I have just recently started creating some plugins, mainly of the >>> controller variety. I have been looking for a tutorial or other >>> documentation detailing how to go about testing these plugins with >>> RSpec, but have not yet found anything helpful. Can anyone point >>> me toward such a thing? >> >> Create a controller in your specs which uses the plugin in an >> exemplary way, then asserts the behaviour of that controller. >> >> > > Thanks, Matt. I have some parts of it working now, but am stumped > when trying to call an action. I need to do a post :create, but post > is not a known method. Do you happen to know of a controller plugin > that used RSpec that I could peruse? Yeah, you need to convince RSpec that the describe blocks you're using are describing an ExampleGroup that's about a Rails Controller, then it will mix in the right methods for you. I think you can do something like: describe MySpecialTestController, :type => :controller do end That's the general idea. I think someone else on the list will be able to help more than me with the specifics. As for a plug-in, I don't know any off-hand... try a few popular ones out on github and look for a spec directory in the root I guess. > > Thanks, > Phillip > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From phillipkoebbe at gmail.com Mon Feb 8 10:58:31 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Mon, 08 Feb 2010 09:58:31 -0600 Subject: [rspec-users] Testing controller plugin In-Reply-To: <3C5CA2B6-4252-4A69-8D03-D33DB0E52E9D@mattwynne.net> References: <4B66EFCB.2010302@gmail.com> <4B6F783D.2030504@gmail.com> <3C5CA2B6-4252-4A69-8D03-D33DB0E52E9D@mattwynne.net> Message-ID: <4B7034A7.9040103@gmail.com> Matt Wynne wrote: > > Yeah, you need to convince RSpec that the describe blocks you're using > are describing an ExampleGroup that's about a Rails Controller, then > it will mix in the right methods for you. I think you can do something > like: > > describe MySpecialTestController, :type => :controller do > end > > That's the general idea. I think someone else on the list will be able > to help more than me with the specifics. > > As for a plug-in, I don't know any off-hand... try a few popular ones > out on github and look for a spec directory in the root I guess. > Thanks, again, Matt for taking the time to respond. I was kind of surprised by how many plugins use test::unit. I did finally find subdomain_fu [1] and was able to get something working. However, this approach tests the controller in a project and requires rspec-rails to be installed for the project. I would really like to be able to test this independent of a project. So if anyone knows how to test a controller plugin with RSpec independent of a project, I'd really appreciate some pointers. Here's what I have right now: http://gist.github.com/298281 Thanks, Phillip [1] http://github.com/mbleigh/subdomain-fu From dchelimsky at gmail.com Mon Feb 8 11:53:01 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 8 Feb 2010 12:53:01 -0400 Subject: [rspec-users] Testing controller plugin In-Reply-To: <4B7034A7.9040103@gmail.com> References: <4B66EFCB.2010302@gmail.com> <4B6F783D.2030504@gmail.com> <3C5CA2B6-4252-4A69-8D03-D33DB0E52E9D@mattwynne.net> <4B7034A7.9040103@gmail.com> Message-ID: <57c63afe1002080853m25588f61k3a118809ece17576@mail.gmail.com> On Mon, Feb 8, 2010 at 11:58 AM, Phillip Koebbe wrote: > Matt Wynne wrote: >> >> Yeah, you need to convince RSpec that the describe blocks you're using are >> describing an ExampleGroup that's about a Rails Controller, then it will mix >> in the right methods for you. I think you can do something like: >> >> describe MySpecialTestController, :type => :controller do >> end >> >> That's the general idea. I think someone else on the list will be able to >> help more than me with the specifics. >> >> As for a plug-in, I don't know any off-hand... try a few popular ones out >> on github and look for a spec directory in the root I guess. >> > > Thanks, again, Matt for taking the time to respond. I was kind of surprised > by how many plugins use test::unit. I did finally find subdomain_fu [1] and > was able to get something working. However, this approach tests the > controller in a project and requires rspec-rails to be installed for the > project. I would really like to be able to test this independent of a > project. So if anyone knows how to test a controller plugin with RSpec > independent of a project, I'd really appreciate some pointers. The problem I've run into in trying to spec controller extensions in isolation is that Rails controllers are not self-contained objects: they need a bunch of surrounding state set up for them to work properly. The testing facilities that ship with Rails hide that all from you, but they do a lot of work for you in every test method, or rspec code example. In theory, you should be able to say: ================================= require 'rubygems' require 'action_controller/base' class SomeController < ActionController::Base def index render :text => "this text" end end describe SomeController do describe "index" do it "returns some text" do c = SomeController.new c.index.should == "this text" end end end ================================= When you do, however, you get this: uninitialized constant ActionController::Metal (NameError) Try to solve that and you'll be starting down a deep rabbit hole. And even if you do solve that, the next rails release may well break whatever you did to solve it. The safest bet is to spec your plugin in the context of a complete rails app. That said, I'd love to make this easier to do with rspec, but I won't have cycles to drive this for quite some time. If anyone else is interested in driving this, speak up and I'll be happy to assist. Cheers, David > > Here's what I have right now: > > http://gist.github.com/298281 > > Thanks, > Phillip > > > [1] http://github.com/mbleigh/subdomain-fu > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt at mattwynne.net Mon Feb 8 12:17:55 2010 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 8 Feb 2010 17:17:55 +0000 Subject: [rspec-users] Testing controller plugin In-Reply-To: <57c63afe1002080853m25588f61k3a118809ece17576@mail.gmail.com> References: <4B66EFCB.2010302@gmail.com> <4B6F783D.2030504@gmail.com> <3C5CA2B6-4252-4A69-8D03-D33DB0E52E9D@mattwynne.net> <4B7034A7.9040103@gmail.com> <57c63afe1002080853m25588f61k3a118809ece17576@mail.gmail.com> Message-ID: <33E97F76-01EA-46F9-BBF5-29F7CE542BC0@mattwynne.net> On 8 Feb 2010, at 16:53, David Chelimsky wrote: > On Mon, Feb 8, 2010 at 11:58 AM, Phillip Koebbe > wrote: >> Matt Wynne wrote: >>> >>> Yeah, you need to convince RSpec that the describe blocks you're >>> using are >>> describing an ExampleGroup that's about a Rails Controller, then >>> it will mix >>> in the right methods for you. I think you can do something like: >>> >>> describe MySpecialTestController, :type => :controller do >>> end >>> >>> That's the general idea. I think someone else on the list will be >>> able to >>> help more than me with the specifics. >>> >>> As for a plug-in, I don't know any off-hand... try a few popular >>> ones out >>> on github and look for a spec directory in the root I guess. >>> >> >> Thanks, again, Matt for taking the time to respond. I was kind of >> surprised >> by how many plugins use test::unit. I did finally find subdomain_fu >> [1] and >> was able to get something working. However, this approach tests the >> controller in a project and requires rspec-rails to be installed >> for the >> project. I would really like to be able to test this independent of a >> project. So if anyone knows how to test a controller plugin with >> RSpec >> independent of a project, I'd really appreciate some pointers. > > The problem I've run into in trying to spec controller extensions in > isolation is that Rails controllers are not self-contained objects: > they need a bunch of surrounding state set up for them to work > properly. The testing facilities that ship with Rails hide that all > from you, but they do a lot of work for you in every test method, or > rspec code example. > > In theory, you should be able to say: > > ================================= > require 'rubygems' > require 'action_controller/base' > > class SomeController < ActionController::Base > def index > render :text => "this text" > end > end > > describe SomeController do > describe "index" do > it "returns some text" do > c = SomeController.new > c.index.should == "this text" > end > end > end > ================================= > > When you do, however, you get this: > > uninitialized constant ActionController::Metal (NameError) > > Try to solve that and you'll be starting down a deep rabbit hole. And > even if you do solve that, the next rails release may well break > whatever you did to solve it. The safest bet is to spec your plugin in > the context of a complete rails app. So maybe we just need to build a library of helpers that make it easy to create a modified rails app in Cucumber features? > That said, I'd love to make this easier to do with rspec, but I won't > have cycles to drive this for quite some time. If anyone else is > interested in driving this, speak up and I'll be happy to assist. > > Cheers, > David > > >> >> Here's what I have right now: >> >> http://gist.github.com/298281 >> >> Thanks, >> Phillip >> >> >> [1] http://github.com/mbleigh/subdomain-fu >> _______________________________________________ >> 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 cheers, Matt http://mattwynne.net +447974 430184 From phillipkoebbe at gmail.com Mon Feb 8 12:20:37 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Mon, 08 Feb 2010 11:20:37 -0600 Subject: [rspec-users] Testing controller plugin In-Reply-To: <57c63afe1002080853m25588f61k3a118809ece17576@mail.gmail.com> References: <4B66EFCB.2010302@gmail.com> <4B6F783D.2030504@gmail.com> <3C5CA2B6-4252-4A69-8D03-D33DB0E52E9D@mattwynne.net> <4B7034A7.9040103@gmail.com> <57c63afe1002080853m25588f61k3a118809ece17576@mail.gmail.com> Message-ID: <4B7047E5.3070309@gmail.com> David Chelimsky wrote: > The problem I've run into in trying to spec controller extensions in > isolation is that Rails controllers are not self-contained objects: > they need a bunch of surrounding state set up for them to work > properly. The testing facilities that ship with Rails hide that all > from you, but they do a lot of work for you in every test method, or > rspec code example. > > In theory, you should be able to say: > > ================================= > require 'rubygems' > require 'action_controller/base' > > class SomeController< ActionController::Base > def index > render :text => "this text" > end > end > > describe SomeController do > describe "index" do > it "returns some text" do > c = SomeController.new > c.index.should == "this text" > end > end > end > ================================= > > When you do, however, you get this: > > uninitialized constant ActionController::Metal (NameError) > > Try to solve that and you'll be starting down a deep rabbit hole. And > even if you do solve that, the next rails release may well break > whatever you did to solve it. The safest bet is to spec your plugin in > the context of a complete rails app. > > That said, I'd love to make this easier to do with rspec, but I won't > have cycles to drive this for quite some time. If anyone else is > interested in driving this, speak up and I'll be happy to assist. > > Cheers, > David Well, there it is. :) Thanks, David. I prefer to avoid rabbit holes. Peace, Phillip From myron.marston at gmail.com Mon Feb 8 12:44:45 2010 From: myron.marston at gmail.com (Myron Marston) Date: Mon, 8 Feb 2010 09:44:45 -0800 (PST) Subject: [rspec-users] [rspec-rails] For helper specs, why is the helper cached in the class between running each example? Message-ID: <06f2353f-0fab-46f4-a648-512922ba6935@d37g2000yqa.googlegroups.com> I ran into a recent problem writing specs for a helper. I was testing a helper that uses the standard memoization technique of caching the result of an expensive calculation in an instance variable: def something_expensive @something_expensive ||= do_something_expensive end I have several different rspec examples for this one helper method, all of which mock out a method that do_something_expensive calls, which should in turn cause a different return value from #something_expensive. When I ran my specs, I wound up getting the same return value for each spec--the return value from the first spec that ran. After investigating it a bit, I ran across this[1] code in rspec-rails' ExampleHelperGroup: def helper self.class.helper end The #helper method simply delegates to the class's helper method, which memoizes the helper object in an instance variable. The result of this is that the helper is cached in the class between example runs, and because of the memoization in my helper method, subsequent specs were returning the same value. I found a work around: after(:each) do helper.instance_variable_set('@something_expensive', nil) end But it feel like a bit of a hack, and it's annoying/frustrating that I have to do this. My specs shouldn't have to be aware of the memoization and manually clear it to work. Why is the helper object cached in the class between running each example? This can accidentally lead to spec interdependencies (i.e. example B only passes if it runs after example A has run, because example A puts the helper object into a certain state that example B unknowingly depends on). Thanks, Myron [1] http://github.com/dchelimsky/rspec-rails/blob/1.3.2/lib/spec/rails/example/helper_example_group.rb#L89-91 From lists at ruby-forum.com Mon Feb 8 18:05:55 2010 From: lists at ruby-forum.com (Saverio Miroddi) Date: Tue, 9 Feb 2010 00:05:55 +0100 Subject: [rspec-users] Stub activerecord find given instance? In-Reply-To: <993e7531fc1e04502bc42c3a951b0749@ruby-forum.com> References: <4A3616AC-32C2-478C-B20D-DF65FE1C031E@experthuman.com> <57c63afe0912140439y4c5a00fbtb65d155eccd5426f@mail.gmail.com> <57c63afe1001121949h444bc715x89fee7e8bc81f84c@mail.gmail.com> <6c35a5c91001241905r1205fc12me243fb28f1c2cca5@mail.gmail.com> <993e7531fc1e04502bc42c3a951b0749@ruby-forum.com> Message-ID: Got at the bottom of it - as suggested, object.stub(:method).with(:value).and_return(:ret) multiple times with different :value [s], though it causes calls to :method to fail unless it has one the :value [s] passed. Thanks! Saverio Saverio Miroddi wrote: > Thanks for the help - I'm going to look directly at the source code, > though of course the recommendation of improving the tests rather than > stretch the api itself is very welcome! > > If I'm going to find anything notable (I have kind of a hunch that I > will), I'll post it. > > Saverio -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Feb 8 20:17:44 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 8 Feb 2010 21:17:44 -0400 Subject: [rspec-users] [rspec-rails] For helper specs, why is the helper cached in the class between running each example? In-Reply-To: <06f2353f-0fab-46f4-a648-512922ba6935@d37g2000yqa.googlegroups.com> References: <06f2353f-0fab-46f4-a648-512922ba6935@d37g2000yqa.googlegroups.com> Message-ID: <57c63afe1002081717la0a798fp6db0ad3780eb7f3c@mail.gmail.com> On Mon, Feb 8, 2010 at 1:44 PM, Myron Marston wrote: > I ran into a recent problem writing specs for a helper. ?I was testing > a helper that uses the standard memoization technique of caching the > result of an expensive calculation in an instance variable: > > ?def something_expensive > ? ?@something_expensive ||= do_something_expensive > ?end > > I have several different rspec examples for this one helper method, > all of which mock out a method that do_something_expensive calls, > which should in turn cause a different return value from > #something_expensive. ?When I ran my specs, I wound up getting the > same return value for each spec--the return value from the first spec > that ran. ?After investigating it a bit, I ran across this[1] code in > rspec-rails' ExampleHelperGroup: > > ? ? ? ?def helper > ? ? ? ? ?self.class.helper > ? ? ? ?end > > The #helper method simply delegates to the class's helper method, > which memoizes the helper object in an instance variable. ?The result > of this is that the helper is cached in the class between example > runs, and because of the memoization in my helper method, subsequent > specs were returning the same value. > > I found a work around: > > ? ?after(:each) do > ? ? ?helper.instance_variable_set('@something_expensive', nil) > ? ?end > > But it feel like a bit of a hack, and it's annoying/frustrating that I > have to do this. ?My specs shouldn't have to be aware of the > memoization and manually clear it to work. > > Why is the helper object cached in the class between running each > example? ?This can accidentally lead to spec interdependencies (i.e. > example B only passes if it runs after example A has run, because > example A puts the helper object into a certain state that example B > unknowingly depends on). Someone just submitted a ticket w/ a patch on this last week: https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/627 It'll be released with rspec-rails-1.3.3, some time in the next few days. Cheers, David > > Thanks, > Myron > > [1] http://github.com/dchelimsky/rspec-rails/blob/1.3.2/lib/spec/rails/example/helper_example_group.rb#L89-91 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From myron.marston at gmail.com Mon Feb 8 20:31:30 2010 From: myron.marston at gmail.com (Myron Marston) Date: Mon, 8 Feb 2010 17:31:30 -0800 (PST) Subject: [rspec-users] [rspec-rails] For helper specs, why is the helper cached in the class between running each example? In-Reply-To: <57c63afe1002081717la0a798fp6db0ad3780eb7f3c@mail.gmail.com> References: <06f2353f-0fab-46f4-a648-512922ba6935@d37g2000yqa.googlegroups.com> <57c63afe1002081717la0a798fp6db0ad3780eb7f3c@mail.gmail.com> Message-ID: <5d83cf25-8510-4ae8-a034-2ab65443c50d@b36g2000pri.googlegroups.com> Thanks, David. I searched the google group for discussions of my problem but forgot to search the github issues. I'll be sure to check there next time! On Feb 8, 5:17?pm, David Chelimsky wrote: > On Mon, Feb 8, 2010 at 1:44 PM, Myron Marston wrote: > > I ran into a recent problem writing specs for a helper. ?I was testing > > a helper that uses the standard memoization technique of caching the > > result of an expensive calculation in an instance variable: > > > ?def something_expensive > > ? ?@something_expensive ||= do_something_expensive > > ?end > > > I have several different rspec examples for this one helper method, > > all of which mock out a method that do_something_expensive calls, > > which should in turn cause a different return value from > > #something_expensive. ?When I ran my specs, I wound up getting the > > same return value for each spec--the return value from the first spec > > that ran. ?After investigating it a bit, I ran across this[1] code in > > rspec-rails' ExampleHelperGroup: > > > ? ? ? ?def helper > > ? ? ? ? ?self.class.helper > > ? ? ? ?end > > > The #helper method simply delegates to the class's helper method, > > which memoizes the helper object in an instance variable. ?The result > > of this is that the helper is cached in the class between example > > runs, and because of the memoization in my helper method, subsequent > > specs were returning the same value. > > > I found a work around: > > > ? ?after(:each) do > > ? ? ?helper.instance_variable_set('@something_expensive', nil) > > ? ?end > > > But it feel like a bit of a hack, and it's annoying/frustrating that I > > have to do this. ?My specs shouldn't have to be aware of the > > memoization and manually clear it to work. > > > Why is the helper object cached in the class between running each > > example? ?This can accidentally lead to spec interdependencies (i.e. > > example B only passes if it runs after example A has run, because > > example A puts the helper object into a certain state that example B > > unknowingly depends on). > > Someone just submitted a ticket w/ a patch on this last week: > > https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/627 > > It'll be released with rspec-rails-1.3.3, some time in the next few days. > > Cheers, > David > > > > > Thanks, > > Myron > > > [1]http://github.com/dchelimsky/rspec-rails/blob/1.3.2/lib/spec/rails/ex... > > _______________________________________________ > > 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 Mon Feb 8 20:33:23 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 8 Feb 2010 21:33:23 -0400 Subject: [rspec-users] [rspec-rails] For helper specs, why is the helper cached in the class between running each example? In-Reply-To: <5d83cf25-8510-4ae8-a034-2ab65443c50d@b36g2000pri.googlegroups.com> References: <06f2353f-0fab-46f4-a648-512922ba6935@d37g2000yqa.googlegroups.com> <57c63afe1002081717la0a798fp6db0ad3780eb7f3c@mail.gmail.com> <5d83cf25-8510-4ae8-a034-2ab65443c50d@b36g2000pri.googlegroups.com> Message-ID: <57c63afe1002081733i2e5fdcfbg8257a41f429cf75a@mail.gmail.com> On Mon, Feb 8, 2010 at 9:31 PM, Myron Marston wrote: > Thanks, David. ?I searched the google group for discussions of my > problem but forgot to search the github issues. ?I'll be sure to check > there next time! No worries - I was just surprised that this has been a theoretical problem for so long and three people bring it up within a week of each other! Glad we got it visible and fixed. Cheers, David > > On Feb 8, 5:17?pm, David Chelimsky wrote: >> On Mon, Feb 8, 2010 at 1:44 PM, Myron Marston wrote: >> > I ran into a recent problem writing specs for a helper. ?I was testing >> > a helper that uses the standard memoization technique of caching the >> > result of an expensive calculation in an instance variable: >> >> > ?def something_expensive >> > ? ?@something_expensive ||= do_something_expensive >> > ?end >> >> > I have several different rspec examples for this one helper method, >> > all of which mock out a method that do_something_expensive calls, >> > which should in turn cause a different return value from >> > #something_expensive. ?When I ran my specs, I wound up getting the >> > same return value for each spec--the return value from the first spec >> > that ran. ?After investigating it a bit, I ran across this[1] code in >> > rspec-rails' ExampleHelperGroup: >> >> > ? ? ? ?def helper >> > ? ? ? ? ?self.class.helper >> > ? ? ? ?end >> >> > The #helper method simply delegates to the class's helper method, >> > which memoizes the helper object in an instance variable. ?The result >> > of this is that the helper is cached in the class between example >> > runs, and because of the memoization in my helper method, subsequent >> > specs were returning the same value. >> >> > I found a work around: >> >> > ? ?after(:each) do >> > ? ? ?helper.instance_variable_set('@something_expensive', nil) >> > ? ?end >> >> > But it feel like a bit of a hack, and it's annoying/frustrating that I >> > have to do this. ?My specs shouldn't have to be aware of the >> > memoization and manually clear it to work. >> >> > Why is the helper object cached in the class between running each >> > example? ?This can accidentally lead to spec interdependencies (i.e. >> > example B only passes if it runs after example A has run, because >> > example A puts the helper object into a certain state that example B >> > unknowingly depends on). >> >> Someone just submitted a ticket w/ a patch on this last week: >> >> https://rspec.lighthouseapp.com/projects/5645-rspec/tickets/627 >> >> It'll be released with rspec-rails-1.3.3, some time in the next few days. >> >> Cheers, >> David >> >> >> >> > Thanks, >> > Myron >> >> > [1]http://github.com/dchelimsky/rspec-rails/blob/1.3.2/lib/spec/rails/ex... >> > _______________________________________________ >> > 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 lists at ruby-forum.com Tue Feb 9 11:10:20 2010 From: lists at ruby-forum.com (Erik Nost) Date: Tue, 9 Feb 2010 17:10:20 +0100 Subject: [rspec-users] Terminate on first failure? Message-ID: <3e4389f5a62192319236b88778821ee2@ruby-forum.com> We have thousands of code examples ('it' methods) in each of our rspec files, each of which is dependent upon the success of the previous one. These are wrapped in a few example groups ('desc' methods). There's no changing that; that's the way they were written. We are making significant changes to the code base, and the tests are failing. They are also taking a huge amount of time failing each of the successive code examples. Is there any way to get RSpec to terminate upon the first failure? Thanks, Pete -- Posted via http://www.ruby-forum.com/. From romanandreg at gmail.com Tue Feb 9 14:01:11 2010 From: romanandreg at gmail.com (=?ISO-8859-1?Q?Rom=E1n_Gonz=E1lez?=) Date: Tue, 9 Feb 2010 11:01:11 -0800 Subject: [rspec-users] Controller specs and Middleware on Rails Message-ID: Hey guys, I'm having some problems on my controller specs regarding authentication. Previously I was using restful_authentication on the project, but after a major refactoring we changed the authentication code to "Warden": http://github.com/hassox/warden (Rack Middleware authentication). When the controller specs are executed, they fail because there is not a variable on the request's env set by the Warden middleware. I've read on a previous message that I probably should use an integration test in order to tests this, I used cucumber and test everything successfully. However all my legacy rspec controller tests (that depended on a current_user) are now failing. Is there a way to patch the rSpec controller API to include this middleware on each test request? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Feb 9 17:00:46 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 9 Feb 2010 18:00:46 -0400 Subject: [rspec-users] Terminate on first failure? In-Reply-To: <3e4389f5a62192319236b88778821ee2@ruby-forum.com> References: <3e4389f5a62192319236b88778821ee2@ruby-forum.com> Message-ID: <57c63afe1002091400m35aca766jd402c10b1455d6d8@mail.gmail.com> On Tue, Feb 9, 2010 at 12:10 PM, Erik Nost wrote: > We have thousands of code examples ('it' methods) in each of our rspec > files, each of which is dependent upon the success of the previous one. > These are wrapped in a few example groups ('desc' methods). > > There's no changing that; that's the way they were written. > > We are making significant changes to the code base, and the tests are > failing. ?They are also taking a huge amount of time failing each of the > successive code examples. > > Is there any way to get RSpec to terminate upon the first failure? There's no way that I'm aware of to do this in rspec-1. There will likely be a way to do it in rspec-2, but not yet (some of the necessary pieces aren't in place). Once we get there, you'll be able to do something like: # purely hypothetical code - do not try this at home Rspec::Core.configure do |c| c.after(:each) do if running_example.metadata[:status] == 'failed' running_example.example_group.break end end end Coming soon, but not quite yet. Cheers, David From dchelimsky at gmail.com Tue Feb 9 16:54:28 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 9 Feb 2010 17:54:28 -0400 Subject: [rspec-users] Controller specs and Middleware on Rails In-Reply-To: References: Message-ID: <57c63afe1002091354m165600d3naaf25124d9592f50@mail.gmail.com> 2010/2/9 Rom?n Gonz?lez : > Hey guys, > I'm having some problems on my controller specs regarding authentication. > Previously I was using restful_authentication on the project, but after a > major refactoring we changed the authentication code to > "Warden":http://github.com/hassox/warden (Rack Middleware authentication). > When the controller specs are executed, they fail because there is not a > variable on the request's env set by the Warden middleware. I've read on a > previous message that I probably should use an integration test in order to > tests this, I used cucumber and test everything?successfully. However all my > legacy rspec controller tests (that depended on a current_user) are now > failing. > Is there a way to patch the rSpec controller API to include this middleware > on each test request? Controller specs don't go through rack in rails 2, so not really. There are integration specs, which wrap the rails integration test API so you can do anything you can do in a rails integration test. Just move the files over to spec/integration, convert the requests from "get :index" to "get 'path/to/index'"and you should be pretty much good to go. Let us know how that works out. Cheers, David From lists at ruby-forum.com Wed Feb 10 09:21:11 2010 From: lists at ruby-forum.com (Peter Nost) Date: Wed, 10 Feb 2010 15:21:11 +0100 Subject: [rspec-users] Terminate on first failure? In-Reply-To: <57c63afe1002091400m35aca766jd402c10b1455d6d8@mail.gmail.com> References: <3e4389f5a62192319236b88778821ee2@ruby-forum.com> <57c63afe1002091400m35aca766jd402c10b1455d6d8@mail.gmail.com> Message-ID: David Chelimsky wrote: > # purely hypothetical code - do not try this at home > Rspec::Core.configure do |c| > c.after(:each) do > if running_example.metadata[:status] == 'failed' > running_example.example_group.break > end > end > end > > Coming soon, but not quite yet. Very cool. Thanks, Pete -- Posted via http://www.ruby-forum.com/. From phillipkoebbe at gmail.com Wed Feb 10 22:17:36 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Wed, 10 Feb 2010 21:17:36 -0600 Subject: [rspec-users] Trying to spec all models Message-ID: <4B7376D0.3030602@gmail.com> When I do script/spec -c -f n spec/models/**/*_spec.rb I get /Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/options.rb:283:in `files_to_load': File or directory not found: spec/models/**/*_spec.rb (RuntimeError) Yet, if I go into irb and do Dir.glob('spec/models/**/*_spec.rb') I get ["spec/models/county_spec.rb", "spec/models/county_user_spec.rb", "spec/models/message_county_spec.rb", "spec/models/message_spec.rb", "spec/models/message_user_spec.rb", "spec/models/postman_spec.rb", "spec/models/user_spec.rb"] Does spec not glob? I'm working on a wrapper script and I'd like to be able to run all specs of a given type (controller, model, view) by passing a single switch (-c, -m, -v). It works when I have subdirectories (as I do with controllers), but it isn't working when I don't (as with models). The fact that glob picks up the files properly got me wondering, so I thought I'd ask. I could glob them myself and run them all individually, but then I wouldn't get the combined statistics at the end. Peace, Phillip From msassak at gmail.com Wed Feb 10 23:13:29 2010 From: msassak at gmail.com (Mike Sassak) Date: Wed, 10 Feb 2010 23:13:29 -0500 Subject: [rspec-users] Trying to spec all models In-Reply-To: <4B7376D0.3030602@gmail.com> References: <4B7376D0.3030602@gmail.com> Message-ID: <339800361002102013w7d3cb93eh55487a976514980c@mail.gmail.com> On Wed, Feb 10, 2010 at 10:17 PM, Phillip Koebbe wrote: > When I do > > script/spec -c -f n ?spec/models/**/*_spec.rb > > I get > > /Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/options.rb:283:in > `files_to_load': File or directory not found: spec/models/**/*_spec.rb > (RuntimeError) > > Yet, if I go into irb and do > > Dir.glob('spec/models/**/*_spec.rb') > > I get > > ["spec/models/county_spec.rb", "spec/models/county_user_spec.rb", > "spec/models/message_county_spec.rb", "spec/models/message_spec.rb", > "spec/models/message_user_spec.rb", "spec/models/postman_spec.rb", > "spec/models/user_spec.rb"] > > Does spec not glob? I'm working on a wrapper script and I'd like to be able > to run all specs of a given type (controller, model, view) by passing a > single switch (-c, -m, -v). It works when I have subdirectories (as I do > with controllers), but it isn't working when I don't (as with models). The > fact that glob picks up the files properly got me wondering, so I thought > I'd ask. > When running script/spec from the CLI the globbing rules will depend on the shell. Try searching Google for "bash globbing" (or whatever shell you're using). But if all you need is to run all the model specs, you could use "rake spec:models". That works well for me. Mike > I could glob them myself and run them all individually, but then I wouldn't > get the combined statistics at the end. > > Peace, > Phillip > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Feb 10 23:37:16 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 11 Feb 2010 00:37:16 -0400 Subject: [rspec-users] Trying to spec all models In-Reply-To: <339800361002102013w7d3cb93eh55487a976514980c@mail.gmail.com> References: <4B7376D0.3030602@gmail.com> <339800361002102013w7d3cb93eh55487a976514980c@mail.gmail.com> Message-ID: <57c63afe1002102037t66c94bd5h54e4ee4fb464b9f7@mail.gmail.com> On Thu, Feb 11, 2010 at 12:13 AM, Mike Sassak wrote: > On Wed, Feb 10, 2010 at 10:17 PM, Phillip Koebbe > wrote: >> When I do >> >> script/spec -c -f n ?spec/models/**/*_spec.rb >> >> I get >> >> /Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/options.rb:283:in >> `files_to_load': File or directory not found: spec/models/**/*_spec.rb >> (RuntimeError) >> >> Yet, if I go into irb and do >> >> Dir.glob('spec/models/**/*_spec.rb') >> >> I get >> >> ["spec/models/county_spec.rb", "spec/models/county_user_spec.rb", >> "spec/models/message_county_spec.rb", "spec/models/message_spec.rb", >> "spec/models/message_user_spec.rb", "spec/models/postman_spec.rb", >> "spec/models/user_spec.rb"] >> >> Does spec not glob? I'm working on a wrapper script and I'd like to be able >> to run all specs of a given type (controller, model, view) by passing a >> single switch (-c, -m, -v). It works when I have subdirectories (as I do >> with controllers), but it isn't working when I don't (as with models). The >> fact that glob picks up the files properly got me wondering, so I thought >> I'd ask. >> > > When running script/spec from the CLI the globbing rules will depend > on the shell. Try searching Google for "bash globbing" (or whatever > shell you're using). But if all you need is to run all the model > specs, you could use "rake spec:models". That works well for me. Or just "script/spec spec/models" > > Mike > >> I could glob them myself and run them all individually, but then I wouldn't >> get the combined statistics at the end. >> >> Peace, >> Phillip >> >> >> _______________________________________________ >> 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 grail at goldweb.com.au Wed Feb 10 23:46:58 2010 From: grail at goldweb.com.au (Alex Satrapa) Date: Thu, 11 Feb 2010 15:46:58 +1100 Subject: [rspec-users] OT: Identifying unused code? Message-ID: I'm sure this has been covered before, but after some time all I've been able to find on the intarwebs are references to the use of code coverage tests to identify code that is not used by any current tests. I guess the assumption is that you've specced your application completely, and any code left over doesn't contribute to any of the specified functionality. However at some point in the future, I may decide to remove a feature. Perhaps my excision is not complete, and I leave a few specs in that relate to that code, but don't immediately appear to be related to the feature I wished to remove. So I'm left with 100% code coverage, due to a few specs hanging around which cover functions that are no longer actually required. Have you run across this situation? What do you do to prevent the "zombie" code hanging around and gnawing on your brain? Alex From matt at mattwynne.net Thu Feb 11 05:00:26 2010 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 11 Feb 2010 10:00:26 +0000 Subject: [rspec-users] OT: Identifying unused code? In-Reply-To: References: Message-ID: On 11 Feb 2010, at 04:46, Alex Satrapa wrote: > I'm sure this has been covered before, but after some time all I've > been able to find on the intarwebs are references to the use of code > coverage tests to identify code that is not used by any current tests. > > I guess the assumption is that you've specced your application > completely, and any code left over doesn't contribute to any of the > specified functionality. > > However at some point in the future, I may decide to remove a > feature. Perhaps my excision is not complete, and I leave a few > specs in that relate to that code, but don't immediately appear to > be related to the feature I wished to remove. So I'm left with 100% > code coverage, due to a few specs hanging around which cover > functions that are no longer actually required. > > Have you run across this situation? What do you do to prevent the > "zombie" code hanging around and gnawing on your brain? Cucumber. If I remove a feature from the application, I have to remove a scenario or two from the cukes. I can use rcov to tell me the code that's covered by those scenarios before I remove them, which gives me an indicator as to what *might* need to be removed. If I've been good and driven all of the application behaviour using Cucumber, I can then run rcov after the scenarios are gone, and I should see that any unused code is not covered at all. I can then either try to figure out what specs cover that code, or just remove the unused code and let the specs tell me themselves. Pair programming is also an excellent weapon against slop, as you'll have at least double the confidence that the code you're looking at is indeed unused, and double the courage to delete it. cheers, Matt http://mattwynne.net +447974 430184 From phillipkoebbe at gmail.com Thu Feb 11 06:15:34 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 11 Feb 2010 05:15:34 -0600 Subject: [rspec-users] Trying to spec all models In-Reply-To: <57c63afe1002102037t66c94bd5h54e4ee4fb464b9f7@mail.gmail.com> References: <4B7376D0.3030602@gmail.com> <339800361002102013w7d3cb93eh55487a976514980c@mail.gmail.com> <57c63afe1002102037t66c94bd5h54e4ee4fb464b9f7@mail.gmail.com> Message-ID: <4B73E6D6.1080802@gmail.com> David Chelimsky wrote: > On Thu, Feb 11, 2010 at 12:13 AM, Mike Sassak wrote: > >> On Wed, Feb 10, 2010 at 10:17 PM, Phillip Koebbe >> wrote: >> >>> When I do >>> >>> script/spec -c -f n spec/models/**/*_spec.rb >>> >>> I get >>> >>> /Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/options.rb:283:in >>> `files_to_load': File or directory not found: spec/models/**/*_spec.rb >>> (RuntimeError) >>> >>> Yet, if I go into irb and do >>> >>> Dir.glob('spec/models/**/*_spec.rb') >>> >>> I get >>> >>> ["spec/models/county_spec.rb", "spec/models/county_user_spec.rb", >>> "spec/models/message_county_spec.rb", "spec/models/message_spec.rb", >>> "spec/models/message_user_spec.rb", "spec/models/postman_spec.rb", >>> "spec/models/user_spec.rb"] >>> >>> Does spec not glob? I'm working on a wrapper script and I'd like to be able >>> to run all specs of a given type (controller, model, view) by passing a >>> single switch (-c, -m, -v). It works when I have subdirectories (as I do >>> with controllers), but it isn't working when I don't (as with models). The >>> fact that glob picks up the files properly got me wondering, so I thought >>> I'd ask. >>> >>> >> When running script/spec from the CLI the globbing rules will depend >> on the shell. Try searching Google for "bash globbing" (or whatever >> shell you're using). But if all you need is to run all the model >> specs, you could use "rake spec:models". That works well for me. >> > > Or just "script/spec spec/models" > > Thanks for the replies. It's not as simple as I just want to spec all models. As I mentioned, I'm writing a wrapper script to automate some things that I repeatedly find myself doing or wanting to do. I am trying to do a very simple **/* pattern when I don't pass a pattern as an argument. I don't really want to have a conditional that says rake spec:models unless pattern when the rest of my code actually calls script/spec. David's suggestion might work though. Right now, I do file = ARGV.at(0) if ARGV.size > 0 file = '**/*' unless file spec_path = "#{spec_path}/#{file}#{filename_partial}.rb" file can be "user", "admin/message", "admin/*", "*/message", or whatever I need it to be. That's why I'm looking for the easiest way to run all of a given type. Eventually I'm going to add support for ~, like with Cucumber tags, except for specs. I did this in a wrapper for Cucumber features and it is working out well for me. I'll keep kicking it around. I'm confident a reasonable solution is not far off. Peace, Phillip From diptip18 at gmail.com Thu Feb 11 09:00:23 2010 From: diptip18 at gmail.com (dipti) Date: Thu, 11 Feb 2010 06:00:23 -0800 (PST) Subject: [rspec-users] accept user input Message-ID: <4bf0eeb5-2374-49d7-b2f3-e3249f716892@t17g2000prg.googlegroups.com> How to accept input from command prompt by user From dchelimsky at gmail.com Thu Feb 11 09:08:10 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 11 Feb 2010 10:08:10 -0400 Subject: [rspec-users] accept user input In-Reply-To: <4bf0eeb5-2374-49d7-b2f3-e3249f716892@t17g2000prg.googlegroups.com> References: <4bf0eeb5-2374-49d7-b2f3-e3249f716892@t17g2000prg.googlegroups.com> Message-ID: <57c63afe1002110608k5ea9f2fdl693deb619dc2794b@mail.gmail.com> On Thu, Feb 11, 2010 at 10:00 AM, dipti wrote: > How to accept input from command prompt by user Are you asking how to do this in Ruby or how to spec it w/ Rspec? From andy.koch at pc-doctor.com Thu Feb 11 12:56:07 2010 From: andy.koch at pc-doctor.com (Andy Koch) Date: Thu, 11 Feb 2010 09:56:07 -0800 (PST) Subject: [rspec-users] autospec exiting without results Message-ID: <9e44e64c-93ea-4132-9183-e996a2823e7b@v20g2000prb.googlegroups.com> Hi, trying to get autospec working on a new Mac (snow lep) but when running autospec on cmd it just exists with no result or output of any kind rake spec runs all tests as expected I've followed the Rspec wiki and looked through some blog posts related but nothing gained any ideas what might be amiss? any help much appreciated thank you From dchelimsky at gmail.com Thu Feb 11 13:15:13 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 11 Feb 2010 14:15:13 -0400 Subject: [rspec-users] autospec exiting without results In-Reply-To: <9e44e64c-93ea-4132-9183-e996a2823e7b@v20g2000prb.googlegroups.com> References: <9e44e64c-93ea-4132-9183-e996a2823e7b@v20g2000prb.googlegroups.com> Message-ID: <57c63afe1002111015g5a3a77cx7645247bf8d93e23@mail.gmail.com> On Thu, Feb 11, 2010 at 1:56 PM, Andy Koch wrote: > Hi, > > trying to get autospec working on a new Mac (snow lep) but when > running autospec on cmd it just exists with no result or output of any > kind > > rake spec runs all tests as expected > > I've followed the Rspec wiki and looked through some blog posts > related but nothing gained > > any ideas what might be amiss? > > any help much appreciated > > thank you If this is a rails app you also need the autotest-rails gem. From romanandreg at gmail.com Thu Feb 11 13:38:32 2010 From: romanandreg at gmail.com (=?ISO-8859-1?Q?Rom=E1n_Gonz=E1lez?=) Date: Thu, 11 Feb 2010 10:38:32 -0800 Subject: [rspec-users] Controller specs and Middleware on Rails In-Reply-To: <57c63afe1002091354m165600d3naaf25124d9592f50@mail.gmail.com> References: <57c63afe1002091354m165600d3naaf25124d9592f50@mail.gmail.com> Message-ID: Hey David, Basically I didn't try that out. Before I received your response I just re-defined all the actions related to authentication with warden, with a nahive implementation of authentication to make the specs run. Not the best solution, but it works. Thanks anyway for the help given. Regards. On Tue, Feb 9, 2010 at 1:54 PM, David Chelimsky wrote: > 2010/2/9 Rom?n Gonz?lez : > > Hey guys, > > I'm having some problems on my controller specs regarding authentication. > > Previously I was using restful_authentication on the project, but after a > > major refactoring we changed the authentication code to > > "Warden":http://github.com/hassox/warden (Rack Middleware > authentication). > > When the controller specs are executed, they fail because there is not a > > variable on the request's env set by the Warden middleware. I've read on > a > > previous message that I probably should use an integration test in order > to > > tests this, I used cucumber and test everything successfully. However all > my > > legacy rspec controller tests (that depended on a current_user) are now > > failing. > > Is there a way to patch the rSpec controller API to include this > middleware > > on each test request? > > Controller specs don't go through rack in rails 2, so not really. > > There are integration specs, which wrap the rails integration test API > so you can do anything you can do in a rails integration test. Just > move the files over to spec/integration, convert the requests from > "get :index" to "get 'path/to/index'"and you should be pretty much > good to go. > > Let us know how that works out. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From andy.koch at pc-doctor.com Thu Feb 11 15:11:42 2010 From: andy.koch at pc-doctor.com (Andy Koch) Date: Thu, 11 Feb 2010 12:11:42 -0800 (PST) Subject: [rspec-users] autospec exiting without results In-Reply-To: <57c63afe1002111015g5a3a77cx7645247bf8d93e23@mail.gmail.com> References: <9e44e64c-93ea-4132-9183-e996a2823e7b@v20g2000prb.googlegroups.com> <57c63afe1002111015g5a3a77cx7645247bf8d93e23@mail.gmail.com> Message-ID: <3bdf8ec6-062d-4b7d-8e29-d707cd08b104@g8g2000pri.googlegroups.com> have that gem installed, still no luck On Feb 11, 10:15?am, David Chelimsky wrote: > On Thu, Feb 11, 2010 at 1:56 PM, Andy Koch wrote: > > Hi, > > > trying to get autospec working on a new Mac (snow lep) but when > > running autospec on cmd it just exists with no result or output of any > > kind > > > rake spec runs all tests as expected > > > I've followed the Rspec wiki and looked through some blog posts > > related but nothing gained > > > any ideas what might be amiss? > > > any help much appreciated > > > thank you > > If this is a rails app you also need the autotest-rails gem. > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Feb 11 16:00:27 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 11 Feb 2010 17:00:27 -0400 Subject: [rspec-users] autospec exiting without results In-Reply-To: <3bdf8ec6-062d-4b7d-8e29-d707cd08b104@g8g2000pri.googlegroups.com> References: <9e44e64c-93ea-4132-9183-e996a2823e7b@v20g2000prb.googlegroups.com> <57c63afe1002111015g5a3a77cx7645247bf8d93e23@mail.gmail.com> <3bdf8ec6-062d-4b7d-8e29-d707cd08b104@g8g2000pri.googlegroups.com> Message-ID: <57c63afe1002111300s66ecbf97q9ae9be8ddc6b0e10@mail.gmail.com> On Thu, Feb 11, 2010 at 4:11 PM, Andy Koch wrote: > have that gem installed, still no luck versions of rspec, rails, etc? > > On Feb 11, 10:15?am, David Chelimsky wrote: >> On Thu, Feb 11, 2010 at 1:56 PM, Andy Koch wrote: >> > Hi, >> >> > trying to get autospec working on a new Mac (snow lep) but when >> > running autospec on cmd it just exists with no result or output of any >> > kind >> >> > rake spec runs all tests as expected >> >> > I've followed the Rspec wiki and looked through some blog posts >> > related but nothing gained >> >> > any ideas what might be amiss? >> >> > any help much appreciated >> >> > thank you >> >> If this is a rails app you also need the autotest-rails gem. From mike.vogel at emc.com Tue Feb 16 08:09:04 2010 From: mike.vogel at emc.com (mikev) Date: Tue, 16 Feb 2010 05:09:04 -0800 (PST) Subject: [rspec-users] hash_include with regular expression Message-ID: I'm trying to match a string in a hash passed to :find using a regular expression since I don't want to know all the other details of the :conditions passed to find. I've tried variations on the following with no success, e.g., not using hash_including and putting both hashes into a single hash_include. c = /.*a.snapshot_id = 1.*/ SomeClass.should_receive(:find).with(:all, hash_including(:conditions=>c), hash_including(:include=>'')).and_return([mock_class]) The rspec fails with the following: expected: (:all, hash_including(:conditions=>/.*da.snapshot_id = 1.*/), hash_including(:include=>"")) got: (:all, {:conditions=>" a.snapshot_id = 1 OTHER CRITERIA... ", :include=>""}) From avdi at avdi.org Tue Feb 16 10:13:51 2010 From: avdi at avdi.org (Avdi Grimm) Date: Tue, 16 Feb 2010 10:13:51 -0500 Subject: [rspec-users] Looking for a new NullDB maintainer Message-ID: The time has come to turn NullDB maintenance over to someone new. See this post for details: http://avdi.org/devblog/2010/02/16/looking-for-a-new-nulldb-maintainer/ Please get in touch if you'd be interested in taking over maintenance for the NullDB project. Thanks! -- Avdi Home: http://avdi.org Developer Blog: http://avdi.org/devblog/ The Lazy Faire: http://thelazyfaire.org Twitter: http://twitter.com/avdi Journal: http://avdi.livejournal.com From ben.fyvie at champsoftware.com Tue Feb 16 11:48:55 2010 From: ben.fyvie at champsoftware.com (Ben Fyvie) Date: Tue, 16 Feb 2010 10:48:55 -0600 Subject: [rspec-users] adding to the callbacks that rspec-rails adds Message-ID: <0F0D0BA33A9B48A0964B14FE8F1DD40E@champ.net> I have some code that adds to the callbacks that rspec-rails adds by default to setup and teardown fixtures. My code looks something like: module Test module Unit class TestCase append_before(:each) do Test::Unit::AfterFixturesLoaded.custom_stuff1 end append_after(:each) do Test::Unit::AfterFixturesLoaded.custom_stuff2 end end class AfterFixturesLoaded def self.custom_stuff1 #do some stuff here end def self.custom_stuff2 #do some other stuff here end end end end This code works fine if I put it in the config\initializers directory in the rails app, but then running the app fails because it doesn't load test unit. So my question is where can I put this code so that it will always be included when running rspec? Thanks! Ben Fyvie -------------- next part -------------- An HTML attachment was scrubbed... URL: From katari at gmail.com Tue Feb 16 12:03:12 2010 From: katari at gmail.com (katari at gmail.com) Date: Tue, 16 Feb 2010 09:03:12 -0800 (PST) Subject: [rspec-users] running rspec complains about missing cucumber-rails Message-ID: <3e3e6eb9-89d0-4267-ae0b-5ae4536fd632@s33g2000prm.googlegroups.com> Hello, I can run cucumber tests, but when I run a rspec command (>ruby script \spec spec\views\category_metr ics\show.html.erb_spec.rb --backtrace), I am getting an error that the rails-cucumber gem is not found: no such file to load -- cucumber-rails C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_re quire' C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `polyglot_origin al_require' C:/Ruby/lib/ruby/gems/1.8/gems/polyglot-0.2.9/lib/polyglot.rb:70:in `require' C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/ dependenci es.rb:158:in `require' C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/rails/gem_dependency.rb: 208:in `l oad' C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:307:in `load_gems' C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:307:in `each' C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:307:in `load_gems' C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:169:in `process' C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:113:in `send' C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:113:in `run' C:/projects/price_prod/branches/dev_kk/config/environment.rb:9 C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_re quire' C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' script/spec:7 Missing these required gems: cucumber-rails = 0.2.4 You're running: ruby 1.8.6.287 at C:/Ruby/bin/ruby.exe rubygems 1.3.5 at C:/Documents and Settings/Home/.gem/ruby/1.8, C:/ Ruby/lib/ru by/gems/1.8 Run `rake gems:install` to install the missing gems. I am on windows xp, with following environment: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32] Rails 2.3.4 Running rake gems RAILS_ENV = test produces the following - [F] haml = 2.0.9 - [F] authlogic = 2.1.3 - [R] activesupport - [F] rspec-rails = 1.3.2 - [F] rspec >= 1.3.0 - [R] rack >= 1.0.0 - [F] rspec = 1.3.0 - [F] cucumber = 0.6.2 - [I] term-ansicolor >= 1.0.4 - [I] treetop >= 1.4.2 - [I] polyglot >= 0.2.5 - [I] polyglot >= 0.2.9 - [R] builder >= 2.1.2 - [I] diff-lcs >= 1.1.2 - [I] json_pure >= 1.2.0 - [F] cucumber-rails = 0.2.4 - [F] cucumber >= 0.6.2 - [I] term-ansicolor >= 1.0.4 - [I] treetop >= 1.4.2 - [I] polyglot >= 0.2.5 - [I] polyglot >= 0.2.9 - [R] builder >= 2.1.2 - [I] diff-lcs >= 1.1.2 - [I] json_pure >= 1.2.0 - [F] webrat = 0.7.0 - [I] nokogiri >= 1.2.0 - [R] rack >= 1.0 - [I] rack-test >= 0.5.3 - [R] rack >= 1.0 - [F] spork = 0.7.5 - [F] database_cleaner = 0.4.3 - [F] thoughtbot-factory_girl = 1.2.2 I = Installed F = Frozen R = Framework (loaded before rails starts) From patrick99e99 at gmail.com Tue Feb 16 18:42:56 2010 From: patrick99e99 at gmail.com (patrick99e99) Date: Tue, 16 Feb 2010 15:42:56 -0800 (PST) Subject: [rspec-users] Trying to write a failing test-- but am failing! Message-ID: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> I am new to BDD, so am not quite sure how I am supposed to write a test like this.. I get: "ActiveRecord::RecordInvalid in 'User should fail when passwords do not match' Validation failed: Password doesn't match confirmation" If anyone can guide me in the right direction, I'd appreciate it.. -patrick require 'spec_helper' describe User do before(:each) do @valid_attributes = { :login => 'test_name', :password => 'password', :password_confirmation => 'password' } @invalid_attributes = @valid_attributes.merge(:password => 'not_the_same_password') end it "should create a valid user" do User.create!(@valid_attributes).should be_true end it "should fail when passwords do not match" do User.create!(@invalid_attributes).should be_false end end From dchelimsky at gmail.com Tue Feb 16 20:19:58 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 16 Feb 2010 19:19:58 -0600 Subject: [rspec-users] Trying to write a failing test-- but am failing! In-Reply-To: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> References: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> Message-ID: <57c63afe1002161719g4098b957of4b8b615672dd275@mail.gmail.com> On Tue, Feb 16, 2010 at 5:42 PM, patrick99e99 wrote: > I am new to BDD, so am not quite sure how I am supposed to write a > test like this.. ?I get: > "ActiveRecord::RecordInvalid in 'User should fail when passwords do > not match' > Validation failed: Password doesn't match confirmation" > > If anyone can guide me in the right direction, I'd appreciate it.. > > -patrick > > require 'spec_helper' > > describe User do > > ?before(:each) do > ? ? @valid_attributes = { > ? ? ?:login => 'test_name', > ? ? ?:password => 'password', > ? ? ?:password_confirmation => 'password' > ? ?} > > ? ? ?@invalid_attributes = @valid_attributes.merge(:password => > 'not_the_same_password') > ?end > > ?it "should create a valid user" do > ? ?User.create!(@valid_attributes).should be_true > ?end > > ?it "should fail when passwords do not match" do > ? ?User.create!(@invalid_attributes).should be_false > ?end The create! method is designed to raise an error if validation fails. You can get this to work in one of two ways: User.create(@invalid_attributes).should be_false # using create instead of create! or expect do User.create!(@invalid_attributes) end.to raise_exception(ActiveRecord::RecordInvalid) HTH, David > > end > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From patrick99e99 at gmail.com Tue Feb 16 21:02:07 2010 From: patrick99e99 at gmail.com (patrick99e99) Date: Tue, 16 Feb 2010 18:02:07 -0800 (PST) Subject: [rspec-users] Trying to write a failing test-- but am failing! In-Reply-To: <57c63afe1002161719g4098b957of4b8b615672dd275@mail.gmail.com> References: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> <57c63afe1002161719g4098b957of4b8b615672dd275@mail.gmail.com> Message-ID: <2e6d532f-ed36-47ac-aeb4-ef8ce759c48e@b7g2000pro.googlegroups.com> Hi, > User.create(@invalid_attributes).should be_false # using create > instead of create! Hmmm.. when I tried this, I get: 'User should fail when passwords do not match' FAILED expected # to be false > expect do > User.create!(@invalid_attributes) > end.to raise_exception(ActiveRecord::RecordInvalid) > And when I tried it this way, I got the same error as before-- ActiveRecord::RecordInvalid in 'User should create a valid user' Validation failed: Password doesn't match confirmation -patrick From patrick99e99 at gmail.com Tue Feb 16 21:15:40 2010 From: patrick99e99 at gmail.com (patrick99e99) Date: Tue, 16 Feb 2010 18:15:40 -0800 (PST) Subject: [rspec-users] Trying to write a failing test-- but am failing! In-Reply-To: <57c63afe1002161719g4098b957of4b8b615672dd275@mail.gmail.com> References: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> <57c63afe1002161719g4098b957of4b8b615672dd275@mail.gmail.com> Message-ID: <0ee18c5b-6c35-4e47-b961-e82f653e1695@s33g2000prm.googlegroups.com> Hi, > The create! method is designed to raise an error if validation fails. > You can get this to work in one of two ways: > > User.create(@invalid_attributes).should be_false # using create > instead of create! Hmm, when I try that-- It still doesn't work... it "should fail when passwords do not match" do User.create(@invalid_attributes).should be_false end 'User should fail when passwords do not match' FAILED expected # to be false > expect do > ? User.create!(@invalid_attributes) > end.to raise_exception(ActiveRecord::RecordInvalid) And when I tried that way, I got the same error I was getting originally: it "should fail when passwords do not match" do expect do User.create! (@invalid_attributes) end.to raise_exception(ActiveRecord::RecordInvalid) end ActiveRecord::RecordInvalid in 'User should create a valid user' Validation failed: Password doesn't match confirmation -p From dchelimsky at gmail.com Tue Feb 16 21:18:51 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 16 Feb 2010 20:18:51 -0600 Subject: [rspec-users] Trying to write a failing test-- but am failing! In-Reply-To: <2e6d532f-ed36-47ac-aeb4-ef8ce759c48e@b7g2000pro.googlegroups.com> References: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> <57c63afe1002161719g4098b957of4b8b615672dd275@mail.gmail.com> <2e6d532f-ed36-47ac-aeb4-ef8ce759c48e@b7g2000pro.googlegroups.com> Message-ID: <57c63afe1002161818i16ad6e9dk62cbd515a9d1be00@mail.gmail.com> On Tue, Feb 16, 2010 at 8:02 PM, patrick99e99 wrote: > Hi, > >> User.create(@invalid_attributes).should be_false # using create >> instead of create! > > Hmmm.. ?when I tried this, I get: Oops - it's this: user = User.create(@invalid_attributes) user.should_not be_valid > > 'User should fail when passwords do not match' FAILED > expected # "e75e945946e0b31163c09da22ab0e8b725a89301d82275d0a90...", > password_salt: "ivSY-ZjPwOiOoRfPfvAR", persistence_token: > "9fa3b87bd2b8eb0d2ed600a0009f00ea4224de07954e96d7197...", > single_access_token: "dGscUBSr_qJ3TTcHXpT3", perishable_token: nil, > login_count: 0, failed_login_count: 0, last_request_at: nil, > current_login_at: nil, last_login_at: nil, current_login_ip: nil, > last_login_ip: nil, contact_id: nil, access_level_id: nil, active: > false, created_at: nil, updated_at: nil> to be false > >> expect do >> ? User.create!(@invalid_attributes) >> end.to raise_exception(ActiveRecord::RecordInvalid) >> > > And when I tried it this way, I got the same error as before-- > > ActiveRecord::RecordInvalid in 'User should create a valid user' > Validation failed: Password doesn't match confirmation Try raise_error instead of raise_exception. If that works, you're using an older version of rspec. If not, I'm not sure what's going on. > > -patrick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From patrick99e99 at gmail.com Tue Feb 16 21:27:13 2010 From: patrick99e99 at gmail.com (patrick99e99) Date: Tue, 16 Feb 2010 18:27:13 -0800 (PST) Subject: [rspec-users] Trying to write a failing test-- but am failing! In-Reply-To: <57c63afe1002161818i16ad6e9dk62cbd515a9d1be00@mail.gmail.com> References: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> <57c63afe1002161719g4098b957of4b8b615672dd275@mail.gmail.com> <2e6d532f-ed36-47ac-aeb4-ef8ce759c48e@b7g2000pro.googlegroups.com> <57c63afe1002161818i16ad6e9dk62cbd515a9d1be00@mail.gmail.com> Message-ID: <1f4948fe-ed93-4514-9310-29f7c5dcf86d@w27g2000pre.googlegroups.com> Hi again, > user = User.create(@invalid_attributes) > user.should_not be_valid This gives me: NoMethodError in 'User should fail when passwords do not match' undefined method `handling_predicate!' for # > Try raise_error instead of raise_exception. If that works, you're > using an older version of rspec. If not, I'm not sure what's going on. Yeah, I wasn't carefully reading that error-- it was: ActiveRecord::RecordInvalid in 'User should create a valid user' I accidentally had @invalid = @valid.merge!(..new password..), and that was breaking the should be valid test, the invalid one works with the expect block. So that way works... Thank you. -patrick From dchelimsky at gmail.com Tue Feb 16 21:50:20 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 16 Feb 2010 20:50:20 -0600 Subject: [rspec-users] Trying to write a failing test-- but am failing! In-Reply-To: <1f4948fe-ed93-4514-9310-29f7c5dcf86d@w27g2000pre.googlegroups.com> References: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> <57c63afe1002161719g4098b957of4b8b615672dd275@mail.gmail.com> <2e6d532f-ed36-47ac-aeb4-ef8ce759c48e@b7g2000pro.googlegroups.com> <57c63afe1002161818i16ad6e9dk62cbd515a9d1be00@mail.gmail.com> <1f4948fe-ed93-4514-9310-29f7c5dcf86d@w27g2000pre.googlegroups.com> Message-ID: <57c63afe1002161850x523fa81bmee2b2b0b2b43e5e6@mail.gmail.com> On Tue, Feb 16, 2010 at 8:27 PM, patrick99e99 wrote: > Hi again, > >> user = User.create(@invalid_attributes) >> user.should_not be_valid > > This gives me: > > NoMethodError in 'User should fail when passwords do not match' > undefined method `handling_predicate!' for # 0x104d8a518 @args=[:be_valid]> This suggests that you're mixing versions of rspec and rspec-rails that are incompatible. What versions are you using, and do you have any installed in vendor/plugins in addition to vendor/gems? >> Try raise_error instead of raise_exception. If that works, you're >> using an older version of rspec. If not, I'm not sure what's going on. > > Yeah, I wasn't carefully reading that error-- it was: > ActiveRecord::RecordInvalid in 'User should create a valid user' > > I accidentally had @invalid = @valid.merge!(..new password..), and > that was breaking the should be valid test, the invalid one works with > the expect block. ?So that way works... ?Thank you. From patrick99e99 at gmail.com Tue Feb 16 21:55:58 2010 From: patrick99e99 at gmail.com (patrick99e99) Date: Tue, 16 Feb 2010 18:55:58 -0800 (PST) Subject: [rspec-users] Trying to write a failing test-- but am failing! In-Reply-To: <57c63afe1002161850x523fa81bmee2b2b0b2b43e5e6@mail.gmail.com> References: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> <57c63afe1002161719g4098b957of4b8b615672dd275@mail.gmail.com> <2e6d532f-ed36-47ac-aeb4-ef8ce759c48e@b7g2000pro.googlegroups.com> <57c63afe1002161818i16ad6e9dk62cbd515a9d1be00@mail.gmail.com> <1f4948fe-ed93-4514-9310-29f7c5dcf86d@w27g2000pre.googlegroups.com> <57c63afe1002161850x523fa81bmee2b2b0b2b43e5e6@mail.gmail.com> Message-ID: <192a062a-4ad4-4b47-bb98-008edb823383@f17g2000prh.googlegroups.com> > This suggests that you're mixing versions of rspec and rspec-rails > that are incompatible. What versions are you using, and do you have > any installed in vendor/plugins in addition to vendor/gems? Well, I did run rake gems:unpack:dependencies, which I believe is what the rspec book had said to do... So, there is rspec and rspec-rails in vendor/gems both are 1.2.9... but if I do spec --version, I get 1.3.0 -patrick From dchelimsky at gmail.com Tue Feb 16 22:55:35 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 16 Feb 2010 21:55:35 -0600 Subject: [rspec-users] Trying to write a failing test-- but am failing! In-Reply-To: <192a062a-4ad4-4b47-bb98-008edb823383@f17g2000prh.googlegroups.com> References: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> <57c63afe1002161719g4098b957of4b8b615672dd275@mail.gmail.com> <2e6d532f-ed36-47ac-aeb4-ef8ce759c48e@b7g2000pro.googlegroups.com> <57c63afe1002161818i16ad6e9dk62cbd515a9d1be00@mail.gmail.com> <1f4948fe-ed93-4514-9310-29f7c5dcf86d@w27g2000pre.googlegroups.com> <57c63afe1002161850x523fa81bmee2b2b0b2b43e5e6@mail.gmail.com> <192a062a-4ad4-4b47-bb98-008edb823383@f17g2000prh.googlegroups.com> Message-ID: <57c63afe1002161955w23b954b4r9e4b9fcdc3c20d@mail.gmail.com> On Tue, Feb 16, 2010 at 8:55 PM, patrick99e99 wrote: >> This suggests that you're mixing versions of rspec and rspec-rails >> that are incompatible. What versions are you using, and do you have >> any installed in vendor/plugins in addition to vendor/gems? > > Well, I did run rake gems:unpack:dependencies, which I believe is what > the rspec book had said to do... > > So, there is rspec and rspec-rails in vendor/gems > > both are 1.2.9... ?but if I do spec --version, I get 1.3.0 What command are you running? From patrick99e99 at gmail.com Tue Feb 16 23:24:05 2010 From: patrick99e99 at gmail.com (patrick99e99) Date: Tue, 16 Feb 2010 20:24:05 -0800 (PST) Subject: [rspec-users] Trying to write a failing test-- but am failing! In-Reply-To: <57c63afe1002161955w23b954b4r9e4b9fcdc3c20d@mail.gmail.com> References: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> <57c63afe1002161719g4098b957of4b8b615672dd275@mail.gmail.com> <2e6d532f-ed36-47ac-aeb4-ef8ce759c48e@b7g2000pro.googlegroups.com> <57c63afe1002161818i16ad6e9dk62cbd515a9d1be00@mail.gmail.com> <1f4948fe-ed93-4514-9310-29f7c5dcf86d@w27g2000pre.googlegroups.com> <57c63afe1002161850x523fa81bmee2b2b0b2b43e5e6@mail.gmail.com> <192a062a-4ad4-4b47-bb98-008edb823383@f17g2000prh.googlegroups.com> <57c63afe1002161955w23b954b4r9e4b9fcdc3c20d@mail.gmail.com> Message-ID: <0b0e8aa3-1caa-463c-a94b-29f32b1a9661@v20g2000prb.googlegroups.com> > What command are you running? I have just been doing script/autospec .. I actually posted on the rspecbook forum (haven't heard anything yet, so I'll ask here) regarding autospec.. When I ran it, it told me that features were being skipped unless I supplied an environment variable AUTOFEATURE=true... So, I exported that variable in my bashrc file, but I find that my tests automatically rerun themselves every second with autofeature turned on... So even if I am not updating/saving files, the tests just keep getting executed over and over.. Is there a reason for this? When I watched BDDCasts, they were using autospec with their features, and it didn't appear to behave that way for them, so I was wondering. -patrick From nmkolev at gmail.com Wed Feb 17 06:44:56 2010 From: nmkolev at gmail.com (Nickolay Kolev) Date: Wed, 17 Feb 2010 03:44:56 -0800 (PST) Subject: [rspec-users] Stubbing @instance.association.build Message-ID: <5aa72627-f06b-44e8-9447-5147f7088a44@c16g2000yqd.googlegroups.com> Hi all, I am trying to spec a controller for a nested resource: http://gist.github.com/306521 Running the spec as it is in the gist results in undefined method `save' for nil:NilClass (line 66 in the gist) So should_receive is interfering with the build message resulting in @course ending up nil. Is there a way to stub "build" so that the assertion works *and* does not result in @course == nil? Many thanks in advance, Nickolay From dchelimsky at gmail.com Wed Feb 17 07:53:48 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Feb 2010 06:53:48 -0600 Subject: [rspec-users] Stubbing @instance.association.build In-Reply-To: <5aa72627-f06b-44e8-9447-5147f7088a44@c16g2000yqd.googlegroups.com> References: <5aa72627-f06b-44e8-9447-5147f7088a44@c16g2000yqd.googlegroups.com> Message-ID: <57c63afe1002170453x2b709021k9ed84ea5e737b9f0@mail.gmail.com> On Wed, Feb 17, 2010 at 5:44 AM, Nickolay Kolev wrote: > Hi all, > > I am trying to spec a controller for a nested resource: > > http://gist.github.com/306521 > > Running the spec as it is in the gist results in > > undefined method `save' for nil:NilClass (line 66 in the gist) > > So should_receive is interfering with the build message resulting in > @course ending up nil. > > Is there a way to stub "build" so that the assertion works *and* does > not result in @course == nil? > > Many thanks in advance, > Nickolay I don't see @new_course getting defined anywhere. Try assigning it a non-nil value in each of the POST examples (or in before(:each) in that group). From dchelimsky at gmail.com Wed Feb 17 07:59:39 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Feb 2010 06:59:39 -0600 Subject: [rspec-users] adding to the callbacks that rspec-rails adds In-Reply-To: <0F0D0BA33A9B48A0964B14FE8F1DD40E@champ.net> References: <0F0D0BA33A9B48A0964B14FE8F1DD40E@champ.net> Message-ID: <57c63afe1002170459s3d7c8311r1e51f090ba70e70e@mail.gmail.com> On Tue, Feb 16, 2010 at 10:48 AM, Ben Fyvie wrote: > I have some code that adds to the callbacks that rspec-rails adds by default > to href="http://github.com/dchelimsky/rspec-rails/blob/master/lib/spec/rails/interop/testcase.rb">setup > and teardown fixtures. > > > > My code looks something like: > > > > ??? module Test > > ????? module Unit > > > > ??????? class TestCase > > ????????? append_before(:each) do > > ?????????? Test::Unit::AfterFixturesLoaded.custom_stuff1 > > ????????? end > > > > ????????? append_after(:each) do > > ??????????? Test::Unit::AfterFixturesLoaded.custom_stuff2 > > ????????? end > > ??????? end > > > > ??????? class AfterFixturesLoaded > > > > ????????? def self.custom_stuff1 > > ??????????? #do some stuff here > > ????????? end > > > > ????????? def self.custom_stuff2 > > ??????????? #do some other stuff here > > ????????? end > > ??????? end > > > > ????? end > > ??? end > > > > This code works fine if I put it in the config\initializers directory in the > rails app, but then running the app fails because it doesn't load test unit. > So my question is where can I put this code so that it will always be > included when running rspec? The convention is to put support files in spec/support/, and require .rb files in that directory from spec/spec_helper.rb. The spec/spec_helper.rb file generated by rspec-rails when you execute "script/generate rspec" ("script/rails g rspec:install" in rails 3) includes a line that handles the require for you. HTH, David From dchelimsky at gmail.com Wed Feb 17 08:26:37 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Feb 2010 07:26:37 -0600 Subject: [rspec-users] hash_include with regular expression In-Reply-To: References: Message-ID: <57c63afe1002170526n69fc4f96u32c54009b2eaf323@mail.gmail.com> On Tue, Feb 16, 2010 at 7:09 AM, mikev wrote: > > I'm trying to match a string in a hash passed to :find using a regular > expression since I don't want to know all the other details of > the :conditions passed to find. ?I've tried variations on the > following with no success, e.g., not using hash_including and putting > both hashes into a single hash_include. > > c = /.*a.snapshot_id = 1.*/ > SomeClass.should_receive(:find).with(:all, > hash_including(:conditions=>c), > hash_including(:include=>'')).and_return([mock_class]) > > The rspec fails with the following: > ?expected: (:all, hash_including(:conditions=>/.*da.snapshot_id = > 1.*/), > ? ? ? ? ? ? ? ? ? ? ? ? ? ?hash_including(:include=>"")) > ? got: (:all, {:conditions=>" a.snapshot_id = 1 OTHER CRITERIA... > ", :include=>""}) hash_including doesn't evaluate regexps because you might actually be assigning a regexp to a key in a hash: foo.should_receive(:bar).with(hash_including(:exp => /match me/)) foo.bar(:a => 1, :exp => /match me/) You can, however, pass a block to should_receive (or stub) and rspec will pass it the arguments it gets. For example: SomeClass.should_receive(:find) {|scope, options| scope.should == :all options[:conditions].should match(/.*a.snapshot_id = 1.*/) } SomeClass.find(:all, :conditions => "a.foo = 'bar' and a.snapshot = 1") Off topic, but if you're using a more recent version of rails (not sure when this was introduced), the convention is SomeClass.all instead of SomeClass.find(:all). That would simplify the expectation a bit: SomeClass.should_receive(:all) {|options| options[:conditions].should match(/.*a.snapshot_id = 1.*/) } HTH, David From nmkolev at gmail.com Wed Feb 17 09:03:48 2010 From: nmkolev at gmail.com (Nickolay Kolev) Date: Wed, 17 Feb 2010 06:03:48 -0800 (PST) Subject: [rspec-users] Stubbing @instance.association.build In-Reply-To: <57c63afe1002170453x2b709021k9ed84ea5e737b9f0@mail.gmail.com> References: <5aa72627-f06b-44e8-9447-5147f7088a44@c16g2000yqd.googlegroups.com> <57c63afe1002170453x2b709021k9ed84ea5e737b9f0@mail.gmail.com> Message-ID: > I don't see @new_course getting defined anywhere. Try assigning it a > non-nil value in each of the POST examples (or in before(:each) in > that group). Thanks, David! Am I right in assuming that I have to check that @new_course received a "save" and returned true in the same it-block? This works: it "should build the new course" do @teacher.courses.should_receive(:build).with(@valid_course_attributes).and_return(@new_course) @new_course.should_receive(:save).and_return(true) do_post end This does not (naturally): it "should build the new course" do @teacher.courses.should_receive(:build).with(@valid_course_attributes).and_return(@new_course) do_post end it "should build the new course" do @new_course.should_receive(:save).and_return(true) do_post end Is there a way to propagate the @new_course instance variable to the next it-block? Best, Nickolay From dchelimsky at gmail.com Wed Feb 17 09:11:17 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Feb 2010 08:11:17 -0600 Subject: [rspec-users] Stubbing @instance.association.build In-Reply-To: References: <5aa72627-f06b-44e8-9447-5147f7088a44@c16g2000yqd.googlegroups.com> <57c63afe1002170453x2b709021k9ed84ea5e737b9f0@mail.gmail.com> Message-ID: <57c63afe1002170611w5ec45347x184a33d4a5f13b2e@mail.gmail.com> On Wed, Feb 17, 2010 at 8:03 AM, Nickolay Kolev wrote: >> I don't see @new_course getting defined anywhere. Try assigning it a >> non-nil value in each of the POST examples (or in before(:each) in >> that group). > > Thanks, David! > > Am I right in assuming that I have to check that @new_course received > a "save" and returned true in the same it-block? > > This works: > > it "should build the new course" do > > @teacher.courses.should_receive(:build).with(@valid_course_attributes).and_return(@new_course) > ?@new_course.should_receive(:save).and_return(true) > ?do_post > end This is not working for the reason that I think you think it's working. and_return is not an expectation - it is a command telling @teacher to return @new_course when it receives :build. You have to define @new_course in the spec. The reason this is working in this case is that @new_course == nil, so and_return(@new_course) is returning nil and then @new_course.should_receive(:save) is telling nil to expect :save. > This does not (naturally): > > it "should build the new course" do > > @teacher.courses.should_receive(:build).with(@valid_course_attributes).and_return(@new_course) > ?do_post > end > > it "should build the new course" do > ?@new_course.should_receive(:save).and_return(true) > ?do_post > end > > Is there a way to propagate the @new_course instance variable to the > next it-block? Nope. But you can define @new_course before(:each) example: before(:each) { @new_course = stub_model(Course) } Then it will be non-nil and all should be well. That all make sense? David From dchelimsky at gmail.com Wed Feb 17 09:13:06 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Feb 2010 08:13:06 -0600 Subject: [rspec-users] Trying to write a failing test-- but am failing! In-Reply-To: <0b0e8aa3-1caa-463c-a94b-29f32b1a9661@v20g2000prb.googlegroups.com> References: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> <57c63afe1002161719g4098b957of4b8b615672dd275@mail.gmail.com> <2e6d532f-ed36-47ac-aeb4-ef8ce759c48e@b7g2000pro.googlegroups.com> <57c63afe1002161818i16ad6e9dk62cbd515a9d1be00@mail.gmail.com> <1f4948fe-ed93-4514-9310-29f7c5dcf86d@w27g2000pre.googlegroups.com> <57c63afe1002161850x523fa81bmee2b2b0b2b43e5e6@mail.gmail.com> <192a062a-4ad4-4b47-bb98-008edb823383@f17g2000prh.googlegroups.com> <57c63afe1002161955w23b954b4r9e4b9fcdc3c20d@mail.gmail.com> <0b0e8aa3-1caa-463c-a94b-29f32b1a9661@v20g2000prb.googlegroups.com> Message-ID: <57c63afe1002170613x3659a897w640bb8b724b49c9@mail.gmail.com> On Tue, Feb 16, 2010 at 10:24 PM, patrick99e99 wrote: >> What command are you running? > > I have just been doing script/autospec > > .. ?I actually posted on the rspecbook forum (haven't heard anything > yet, so I'll ask here) regarding autospec.. ?When I ran it, it told me > that features were being skipped unless I supplied an environment > variable AUTOFEATURE=true... ?So, I exported that variable in my > bashrc file, but I find that my tests automatically rerun themselves > every second with autofeature turned on... ?So even if I am not > updating/saving files, the tests just keep getting executed over and > over.. ?Is there a reason for this? ?When I watched BDDCasts, they > were using autospec with their features, and it didn't appear to > behave that way for them, so I was wondering. That's likely because cucumber is generating a rerun.txt file and autotest is picking that up for some reason. > > -patrick > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From nmkolev at gmail.com Wed Feb 17 09:31:48 2010 From: nmkolev at gmail.com (Nickolay Kolev) Date: Wed, 17 Feb 2010 06:31:48 -0800 (PST) Subject: [rspec-users] Stubbing @instance.association.build In-Reply-To: <57c63afe1002170611w5ec45347x184a33d4a5f13b2e@mail.gmail.com> References: <5aa72627-f06b-44e8-9447-5147f7088a44@c16g2000yqd.googlegroups.com> <57c63afe1002170453x2b709021k9ed84ea5e737b9f0@mail.gmail.com> <57c63afe1002170611w5ec45347x184a33d4a5f13b2e@mail.gmail.com> Message-ID: <2d504f5d-26e1-49ed-bf4c-c7c6d21e6f93@k41g2000yqm.googlegroups.com> > This is not working for the reason that I think you think it's > working. and_return is not an expectation - it is a command telling > @teacher to return @new_course when it receives :build. You have to > define @new_course in the spec. I did the following: http://gist.github.com/306521 and it works as expected. make_unsaved is a class method added by Machinist. What is the scope of instance variables defined in a before(:each) block? They are available to all it-blocks, yet changes made to an instance variable in one it-block are reverted before the next one, correct? Best, Nickolay From katari at gmail.com Wed Feb 17 10:07:38 2010 From: katari at gmail.com (katari at gmail.com) Date: Wed, 17 Feb 2010 07:07:38 -0800 (PST) Subject: [rspec-users] running rspec complains about missing cucumber-rails In-Reply-To: <3e3e6eb9-89d0-4267-ae0b-5ae4536fd632@s33g2000prm.googlegroups.com> References: <3e3e6eb9-89d0-4267-ae0b-5ae4536fd632@s33g2000prm.googlegroups.com> Message-ID: I think I have solved this. I was using config.gem for cucumber and cucumber-rails. Setting :lib => false solves this problem. Would you consider specifying this on http://wiki.github.com/aslakhellesoy/cucumber/ruby-on-rails? Kaushik On Feb 16, 9:03?am, "kat... at gmail.com" wrote: > Hello, > I can run cucumber tests, but when I run a rspec command (>ruby script > \spec spec\views\category_metr > ics\show.html.erb_spec.rb ?--backtrace), I am getting an error that > the rails-cucumber gem is not found: > > no such file to load -- cucumber-rails > C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in > `gem_original_re > quire' > C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in > `polyglot_origin > al_require' > C:/Ruby/lib/ruby/gems/1.8/gems/polyglot-0.2.9/lib/polyglot.rb:70:in > `require' > C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/ > dependenci > es.rb:158:in `require' > C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/rails/gem_dependency.rb: > 208:in `l > oad' > C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:307:in > `load_gems' > > C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:307:in > `each' > C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:307:in > `load_gems' > > C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:169:in > `process' > C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:113:in > `send' > C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:113:in > `run' > C:/projects/price_prod/branches/dev_kk/config/environment.rb:9 > C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in > `gem_original_re > quire' > C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in > `require' > script/spec:7 > Missing these required gems: > ? cucumber-rails ?= 0.2.4 > > You're running: > ? ruby 1.8.6.287 at C:/Ruby/bin/ruby.exe > ? rubygems 1.3.5 at C:/Documents and Settings/Home/.gem/ruby/1.8, C:/ > Ruby/lib/ru > by/gems/1.8 > > Run `rake gems:install` to install the missing gems. > > I am on windows xp, with following environment: > > ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32] > Rails 2.3.4 > > Running rake gems RAILS_ENV = test produces the following > ?- [F] haml = 2.0.9 > ?- [F] authlogic = 2.1.3 > ? ? - [R] activesupport > ?- [F] rspec-rails = 1.3.2 > ? ? - [F] rspec >= 1.3.0 > ? ? - [R] rack >= 1.0.0 > ?- [F] rspec = 1.3.0 > ?- [F] cucumber = 0.6.2 > ? ? - [I] term-ansicolor >= 1.0.4 > ? ? - [I] treetop >= 1.4.2 > ? ? ? ?- [I] polyglot >= 0.2.5 > ? ? - [I] polyglot >= 0.2.9 > ? ? - [R] builder >= 2.1.2 > ? ? - [I] diff-lcs >= 1.1.2 > ? ? - [I] json_pure >= 1.2.0 > ?- [F] cucumber-rails = 0.2.4 > ? ? - [F] cucumber >= 0.6.2 > ? ? ? ?- [I] term-ansicolor >= 1.0.4 > ? ? ? ?- [I] treetop >= 1.4.2 > ? ? ? ? ? - [I] polyglot >= 0.2.5 > ? ? ? ?- [I] polyglot >= 0.2.9 > ? ? ? ?- [R] builder >= 2.1.2 > ? ? ? ?- [I] diff-lcs >= 1.1.2 > ? ? ? ?- [I] json_pure >= 1.2.0 > ?- [F] webrat = 0.7.0 > ? ? - [I] nokogiri >= 1.2.0 > ? ? - [R] rack >= 1.0 > ? ? - [I] rack-test >= 0.5.3 > ? ? ? ?- [R] rack >= 1.0 > ?- [F] spork = 0.7.5 > ?- [F] database_cleaner = 0.4.3 > ?- [F] thoughtbot-factory_girl = 1.2.2 > > I = Installed > F = Frozen > R = Framework (loaded before rails starts) > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Feb 17 10:44:07 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Feb 2010 09:44:07 -0600 Subject: [rspec-users] Stubbing @instance.association.build In-Reply-To: <2d504f5d-26e1-49ed-bf4c-c7c6d21e6f93@k41g2000yqm.googlegroups.com> References: <5aa72627-f06b-44e8-9447-5147f7088a44@c16g2000yqd.googlegroups.com> <57c63afe1002170453x2b709021k9ed84ea5e737b9f0@mail.gmail.com> <57c63afe1002170611w5ec45347x184a33d4a5f13b2e@mail.gmail.com> <2d504f5d-26e1-49ed-bf4c-c7c6d21e6f93@k41g2000yqm.googlegroups.com> Message-ID: <57c63afe1002170744j22dfb25cp2c3fe8b97c904195@mail.gmail.com> On Wed, Feb 17, 2010 at 8:31 AM, Nickolay Kolev wrote: >> This is not working for the reason that I think you think it's >> working. and_return is not an expectation - it is a command telling >> @teacher to return @new_course when it receives :build. You have to >> define @new_course in the spec. > > I did the following: > > http://gist.github.com/306521 > > and it works as expected. make_unsaved is a class method added by > Machinist. > > What is the scope of instance variables defined in a before(:each) > block? They are available to all it-blocks, yet changes made to an > instance variable in one it-block are reverted before the next one, > correct? Close, but not exactly. Each example is run in its own world. Any before(:each) blocks are run before each example in the same world, so the instance variables are not shared in any way at all from example to example. So the following will pass if examples are run in any order: before(:each) { @foo = 1 } it("does something") { @foo +=1; @foo.should == 2} it("does something else") { @foo.should == 1 } You _can_ run a before block only once by using before(:all), but that leads to all sorts of problems related to state-sharing across examples and should generally be avoided. HTH, David From dchelimsky at gmail.com Wed Feb 17 10:45:02 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Feb 2010 09:45:02 -0600 Subject: [rspec-users] running rspec complains about missing cucumber-rails In-Reply-To: References: <3e3e6eb9-89d0-4267-ae0b-5ae4536fd632@s33g2000prm.googlegroups.com> Message-ID: <57c63afe1002170745l32e46695q7b3b9b430d58642@mail.gmail.com> On Wed, Feb 17, 2010 at 9:07 AM, katari at gmail.com wrote: > I think I have solved this. > > I was using config.gem for cucumber and cucumber-rails. Setting :lib > => false solves this problem. > > Would you consider specifying this on http://wiki.github.com/aslakhellesoy/cucumber/ruby-on-rails? It's a wiki! Have at it :) Cheers, David > > Kaushik > > On Feb 16, 9:03?am, "kat... at gmail.com" wrote: >> Hello, >> I can run cucumber tests, but when I run a rspec command (>ruby script >> \spec spec\views\category_metr >> ics\show.html.erb_spec.rb ?--backtrace), I am getting an error that >> the rails-cucumber gem is not found: >> >> no such file to load -- cucumber-rails >> C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in >> `gem_original_re >> quire' >> C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in >> `polyglot_origin >> al_require' >> C:/Ruby/lib/ruby/gems/1.8/gems/polyglot-0.2.9/lib/polyglot.rb:70:in >> `require' >> C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/ >> dependenci >> es.rb:158:in `require' >> C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/rails/gem_dependency.rb: >> 208:in `l >> oad' >> C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:307:in >> `load_gems' >> >> C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:307:in >> `each' >> C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:307:in >> `load_gems' >> >> C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:169:in >> `process' >> C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:113:in >> `send' >> C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:113:in >> `run' >> C:/projects/price_prod/branches/dev_kk/config/environment.rb:9 >> C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in >> `gem_original_re >> quire' >> C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in >> `require' >> script/spec:7 >> Missing these required gems: >> ? cucumber-rails ?= 0.2.4 >> >> You're running: >> ? ruby 1.8.6.287 at C:/Ruby/bin/ruby.exe >> ? rubygems 1.3.5 at C:/Documents and Settings/Home/.gem/ruby/1.8, C:/ >> Ruby/lib/ru >> by/gems/1.8 >> >> Run `rake gems:install` to install the missing gems. >> >> I am on windows xp, with following environment: >> >> ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32] >> Rails 2.3.4 >> >> Running rake gems RAILS_ENV = test produces the following >> ?- [F] haml = 2.0.9 >> ?- [F] authlogic = 2.1.3 >> ? ? - [R] activesupport >> ?- [F] rspec-rails = 1.3.2 >> ? ? - [F] rspec >= 1.3.0 >> ? ? - [R] rack >= 1.0.0 >> ?- [F] rspec = 1.3.0 >> ?- [F] cucumber = 0.6.2 >> ? ? - [I] term-ansicolor >= 1.0.4 >> ? ? - [I] treetop >= 1.4.2 >> ? ? ? ?- [I] polyglot >= 0.2.5 >> ? ? - [I] polyglot >= 0.2.9 >> ? ? - [R] builder >= 2.1.2 >> ? ? - [I] diff-lcs >= 1.1.2 >> ? ? - [I] json_pure >= 1.2.0 >> ?- [F] cucumber-rails = 0.2.4 >> ? ? - [F] cucumber >= 0.6.2 >> ? ? ? ?- [I] term-ansicolor >= 1.0.4 >> ? ? ? ?- [I] treetop >= 1.4.2 >> ? ? ? ? ? - [I] polyglot >= 0.2.5 >> ? ? ? ?- [I] polyglot >= 0.2.9 >> ? ? ? ?- [R] builder >= 2.1.2 >> ? ? ? ?- [I] diff-lcs >= 1.1.2 >> ? ? ? ?- [I] json_pure >= 1.2.0 >> ?- [F] webrat = 0.7.0 >> ? ? - [I] nokogiri >= 1.2.0 >> ? ? - [R] rack >= 1.0 >> ? ? - [I] rack-test >= 0.5.3 >> ? ? ? ?- [R] rack >= 1.0 >> ?- [F] spork = 0.7.5 >> ?- [F] database_cleaner = 0.4.3 >> ?- [F] thoughtbot-factory_girl = 1.2.2 >> >> I = Installed >> F = Frozen >> R = Framework (loaded before rails starts) >> >> _______________________________________________ >> 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 erdoss at gmail.com Wed Feb 17 11:00:01 2010 From: erdoss at gmail.com (Andrei Erdoss) Date: Wed, 17 Feb 2010 18:00:01 +0200 Subject: [rspec-users] Trying to write a failing test-- but am failing! In-Reply-To: <57c63afe1002170613x3659a897w640bb8b724b49c9@mail.gmail.com> References: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> <57c63afe1002161719g4098b957of4b8b615672dd275@mail.gmail.com> <2e6d532f-ed36-47ac-aeb4-ef8ce759c48e@b7g2000pro.googlegroups.com> <57c63afe1002161818i16ad6e9dk62cbd515a9d1be00@mail.gmail.com> <1f4948fe-ed93-4514-9310-29f7c5dcf86d@w27g2000pre.googlegroups.com> <57c63afe1002161850x523fa81bmee2b2b0b2b43e5e6@mail.gmail.com> <192a062a-4ad4-4b47-bb98-008edb823383@f17g2000prh.googlegroups.com> <57c63afe1002161955w23b954b4r9e4b9fcdc3c20d@mail.gmail.com> <0b0e8aa3-1caa-463c-a94b-29f32b1a9661@v20g2000prb.googlegroups.com> <57c63afe1002170613x3659a897w640bb8b724b49c9@mail.gmail.com> Message-ID: I also get the infinite looping of the cucumber features being run. The way I stopped it is by adding this: Autotest.add_hook :initialize do |at| %w{.svn .hg .git vendor rerun.txt}.each {|exception| at.add_exception(exception) } end to ~/.autotest Is there a better to do this? On Wed, Feb 17, 2010 at 4:13 PM, David Chelimsky wrote: > On Tue, Feb 16, 2010 at 10:24 PM, patrick99e99 > wrote: > >> What command are you running? > > > > I have just been doing script/autospec > > > > .. I actually posted on the rspecbook forum (haven't heard anything > > yet, so I'll ask here) regarding autospec.. When I ran it, it told me > > that features were being skipped unless I supplied an environment > > variable AUTOFEATURE=true... So, I exported that variable in my > > bashrc file, but I find that my tests automatically rerun themselves > > every second with autofeature turned on... So even if I am not > > updating/saving files, the tests just keep getting executed over and > > over.. Is there a reason for this? When I watched BDDCasts, they > > were using autospec with their features, and it didn't appear to > > behave that way for them, so I was wondering. > > That's likely because cucumber is generating a rerun.txt file and > autotest is picking that up for some reason. > > > > > > -patrick > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Andrei Erdoss -------------- next part -------------- An HTML attachment was scrubbed... URL: From patrick99e99 at gmail.com Wed Feb 17 13:24:42 2010 From: patrick99e99 at gmail.com (patrick99e99) Date: Wed, 17 Feb 2010 10:24:42 -0800 (PST) Subject: [rspec-users] Trying to write a failing test-- but am failing! In-Reply-To: <57c63afe1002170613x3659a897w640bb8b724b49c9@mail.gmail.com> References: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> <57c63afe1002161719g4098b957of4b8b615672dd275@mail.gmail.com> <2e6d532f-ed36-47ac-aeb4-ef8ce759c48e@b7g2000pro.googlegroups.com> <57c63afe1002161818i16ad6e9dk62cbd515a9d1be00@mail.gmail.com> <1f4948fe-ed93-4514-9310-29f7c5dcf86d@w27g2000pre.googlegroups.com> <57c63afe1002161850x523fa81bmee2b2b0b2b43e5e6@mail.gmail.com> <192a062a-4ad4-4b47-bb98-008edb823383@f17g2000prh.googlegroups.com> <57c63afe1002161955w23b954b4r9e4b9fcdc3c20d@mail.gmail.com> <0b0e8aa3-1caa-463c-a94b-29f32b1a9661@v20g2000prb.googlegroups.com> <57c63afe1002170613x3659a897w640bb8b724b49c9@mail.gmail.com> Message-ID: <87f581da-7a92-4796-8ff1-8576f4d10be6@q2g2000pre.googlegroups.com> > That's likely because cucumber is generating a rerun.txt file and > autotest is picking that up for some reason. Ah.. I do see that in my project directory there is a rerun.txt file... How did that get created, and is the solution just to delete it? -patrick From dchelimsky at gmail.com Wed Feb 17 13:30:09 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Feb 2010 12:30:09 -0600 Subject: [rspec-users] Trying to write a failing test-- but am failing! In-Reply-To: <87f581da-7a92-4796-8ff1-8576f4d10be6@q2g2000pre.googlegroups.com> References: <1a9e8b9a-7520-4816-92b9-660cf75df88e@f17g2000prh.googlegroups.com> <2e6d532f-ed36-47ac-aeb4-ef8ce759c48e@b7g2000pro.googlegroups.com> <57c63afe1002161818i16ad6e9dk62cbd515a9d1be00@mail.gmail.com> <1f4948fe-ed93-4514-9310-29f7c5dcf86d@w27g2000pre.googlegroups.com> <57c63afe1002161850x523fa81bmee2b2b0b2b43e5e6@mail.gmail.com> <192a062a-4ad4-4b47-bb98-008edb823383@f17g2000prh.googlegroups.com> <57c63afe1002161955w23b954b4r9e4b9fcdc3c20d@mail.gmail.com> <0b0e8aa3-1caa-463c-a94b-29f32b1a9661@v20g2000prb.googlegroups.com> <57c63afe1002170613x3659a897w640bb8b724b49c9@mail.gmail.com> <87f581da-7a92-4796-8ff1-8576f4d10be6@q2g2000pre.googlegroups.com> Message-ID: <57c63afe1002171030n608011d0p3ae56bb656726dea@mail.gmail.com> On Wed, Feb 17, 2010 at 12:24 PM, patrick99e99 wrote: >> That's likely because cucumber is generating a rerun.txt file and >> autotest is picking that up for some reason. > > Ah.. ?I do see that in my project directory there is a rerun.txt > file... ?How did that get created, and is the solution just to delete > it? Cucumber generates that for you. Take a look at your cucumber.yml file and you should see some stuff about it. If you have any problems please ask the cucumber mailing list for help: http://groups.google.com/group/cukes Cheers, David From ed.howland at gmail.com Wed Feb 17 13:47:41 2010 From: ed.howland at gmail.com (Ed Howland) Date: Wed, 17 Feb 2010 13:47:41 -0500 Subject: [rspec-users] have_tag missing assert_select outside of controller/view tests Message-ID: <3df642dd1002171047q520dce9dx5ff9211b5110fd00@mail.gmail.com> Hi, I'm trying to write an example that uses response.should have_tag('div') outside of a Rails view test. I read somewhere that as long as you have an instance variable named @response and it respondes to .body with some HTML, it should work, but I get this failure: undefined method `assert_select' for # wrote: > I am new to BDD, so am not quite sure how I am supposed to write a > test like this.. ?I get: > "ActiveRecord::RecordInvalid in 'User should fail when passwords do > not match' > Validation failed: Password doesn't match confirmation" > > If anyone can guide me in the right direction, I'd appreciate it.. > > -patrick > > require 'spec_helper' > > describe User do > > ?before(:each) do > ? ? @valid_attributes = { > ? ? ?:login => 'test_name', > ? ? ?:password => 'password', > ? ? ?:password_confirmation => 'password' > ? ?} > > ? ? ?@invalid_attributes = @valid_attributes.merge(:password => > 'not_the_same_password') > ?end > > ?it "should create a valid user" do > ? ?User.create!(@valid_attributes).should be_true > ?end > > ?it "should fail when passwords do not match" do > ? ?User.create!(@invalid_attributes).should be_false > ?end > > end > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Feb 17 15:38:50 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 17 Feb 2010 14:38:50 -0600 Subject: [rspec-users] have_tag missing assert_select outside of controller/view tests In-Reply-To: <3df642dd1002171047q520dce9dx5ff9211b5110fd00@mail.gmail.com> References: <3df642dd1002171047q520dce9dx5ff9211b5110fd00@mail.gmail.com> Message-ID: <57c63afe1002171238l789a4957v797a7bab3d55a738@mail.gmail.com> On Wed, Feb 17, 2010 at 12:47 PM, Ed Howland wrote: > Hi, > > I'm trying to write an example that uses response.should have_tag('div') > outside of a Rails view test. I read somewhere that as long as you > have an instance variable named @response and it respondes to .body > with some HTML, it should work, but I get this failure: have_tag is on its way to its death. It won't exist in rspec-rails-2, though I hesitate to deprecate it in rspec-rails-1.x since many folks won't be able to upgrade directly anyhow. I'd recommend using webrat's have_selector instead. > > undefined method `assert_select' for # > Also, has anyone cooked this up to work with Sinatra, or are you > restricted to using Rails? Seems that some Nokogiri wiz could work up > a substitute for ActiveSupport. > > Thanks, > Ed > > Ed Howland > http://greenprogrammer.wordpress.com > http://twitter.com/ed_howland > > > > On Tue, Feb 16, 2010 at 6:42 PM, patrick99e99 wrote: >> I am new to BDD, so am not quite sure how I am supposed to write a >> test like this.. ?I get: >> "ActiveRecord::RecordInvalid in 'User should fail when passwords do >> not match' >> Validation failed: Password doesn't match confirmation" >> >> If anyone can guide me in the right direction, I'd appreciate it.. >> >> -patrick >> >> require 'spec_helper' >> >> describe User do >> >> ?before(:each) do >> ? ? @valid_attributes = { >> ? ? ?:login => 'test_name', >> ? ? ?:password => 'password', >> ? ? ?:password_confirmation => 'password' >> ? ?} >> >> ? ? ?@invalid_attributes = @valid_attributes.merge(:password => >> 'not_the_same_password') >> ?end >> >> ?it "should create a valid user" do >> ? ?User.create!(@valid_attributes).should be_true >> ?end >> >> ?it "should fail when passwords do not match" do >> ? ?User.create!(@invalid_attributes).should be_false >> ?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 ed.howland at gmail.com Wed Feb 17 20:56:07 2010 From: ed.howland at gmail.com (Ed Howland) Date: Wed, 17 Feb 2010 20:56:07 -0500 Subject: [rspec-users] have_tag missing assert_select outside of controller/view tests In-Reply-To: <57c63afe1002171238l789a4957v797a7bab3d55a738@mail.gmail.com> References: <3df642dd1002171047q520dce9dx5ff9211b5110fd00@mail.gmail.com> <57c63afe1002171238l789a4957v797a7bab3d55a738@mail.gmail.com> Message-ID: <3df642dd1002171756n229fdcb7ya67d4d4119e07a3d@mail.gmail.com> Thanks, David. I hope that is less/non dependent on Rails/ActiveSupport. It seems to depend on Nokogiri, and hopefully uses some duck-typeable response object. I guess they use response_body. I've concocted a strange brew of RSpec, Johnson and envjs. It can already execute normal Javascript methods, jQuery, and AJAX calls. The only missing piece is the assert_select-like framework: it "should make an ajax call and format some content" do click_async "a#edit" response.should have_selector('div') # this last part, I need end I don't know if anyone else is working on this front, but it is getting us closer to having a pure Ruby/non-browser spec framework Cheers, Ed Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland On Wed, Feb 17, 2010 at 3:38 PM, David Chelimsky wrote: > On Wed, Feb 17, 2010 at 12:47 PM, Ed Howland wrote: >> Hi, >> >> I'm trying to write an example that uses response.should have_tag('div') >> outside of a Rails view test. I read somewhere that as long as you >> have an instance variable named @response and it respondes to .body >> with some HTML, it should work, but I get this failure: > > have_tag is on its way to its death. It won't exist in rspec-rails-2, > though I hesitate to deprecate it in rspec-rails-1.x since many folks > won't be able to upgrade directly anyhow. > > I'd recommend using webrat's have_selector instead. > >> >> undefined method `assert_select' for #> >> Also, has anyone cooked this up to work with Sinatra, or are you >> restricted to using Rails? Seems that some Nokogiri wiz could work up >> a substitute for ActiveSupport. >> >> Thanks, >> Ed >> >> Ed Howland >> http://greenprogrammer.wordpress.com >> http://twitter.com/ed_howland >> >> >> >> On Tue, Feb 16, 2010 at 6:42 PM, patrick99e99 wrote: >>> I am new to BDD, so am not quite sure how I am supposed to write a >>> test like this.. ?I get: >>> "ActiveRecord::RecordInvalid in 'User should fail when passwords do >>> not match' >>> Validation failed: Password doesn't match confirmation" >>> >>> If anyone can guide me in the right direction, I'd appreciate it.. >>> >>> -patrick >>> >>> require 'spec_helper' >>> >>> describe User do >>> >>> ?before(:each) do >>> ? ? @valid_attributes = { >>> ? ? ?:login => 'test_name', >>> ? ? ?:password => 'password', >>> ? ? ?:password_confirmation => 'password' >>> ? ?} >>> >>> ? ? ?@invalid_attributes = @valid_attributes.merge(:password => >>> 'not_the_same_password') >>> ?end >>> >>> ?it "should create a valid user" do >>> ? ?User.create!(@valid_attributes).should be_true >>> ?end >>> >>> ?it "should fail when passwords do not match" do >>> ? ?User.create!(@invalid_attributes).should be_false >>> ?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 nmkolev at gmail.com Thu Feb 18 02:22:52 2010 From: nmkolev at gmail.com (Nickolay Kolev) Date: Wed, 17 Feb 2010 23:22:52 -0800 (PST) Subject: [rspec-users] Stubbing @instance.association.build In-Reply-To: <57c63afe1002170744j22dfb25cp2c3fe8b97c904195@mail.gmail.com> References: <5aa72627-f06b-44e8-9447-5147f7088a44@c16g2000yqd.googlegroups.com> <57c63afe1002170453x2b709021k9ed84ea5e737b9f0@mail.gmail.com> <57c63afe1002170611w5ec45347x184a33d4a5f13b2e@mail.gmail.com> <2d504f5d-26e1-49ed-bf4c-c7c6d21e6f93@k41g2000yqm.googlegroups.com> <57c63afe1002170744j22dfb25cp2c3fe8b97c904195@mail.gmail.com> Message-ID: <47067241-8d8a-41fc-a88c-5d70c4084ea7@15g2000yqa.googlegroups.com> Thanks for the explanation, David! Makes sense now. Best, Nickolay From patrick99e99 at gmail.com Thu Feb 18 03:25:16 2010 From: patrick99e99 at gmail.com (patrick99e99) Date: Thu, 18 Feb 2010 00:25:16 -0800 (PST) Subject: [rspec-users] please help me learn how to use rspec! Message-ID: <3cc64e0c-fc4e-4674-a981-f345e4f603a4@k5g2000pra.googlegroups.com> Hi, So-- I am very very new to BDD.. and I am trying to go over and write some tests for existing code that has been problematic... I am struggling with knowing exactly how to write the proper specs. So I wrote out a list of things this controller action should do, but as far as how to really hook in and test the individual components, I am a bit hazy, so I am hoping some people here can chime in and school me. http://gist.github.com/307464 To give some background on what is going on in this code-- I have a form that lists contacts which is used in two different contexts-- One for newsletter mailings lists, and the other for shipping labels (pdf list). So I have a controller action called 'result_list' that is part of my contacts_controller (in my routes, it's a :collection => :put). This action looks if there is a newsletter_id param, and if so, it knows to look up a newsletter, otherwise it looks up a pdf list. If this newsletter/pdf list is not currently being modified / sent / etc, then a rake task is launched which adds or removes additional contacts to the list. After that is complete, if javascript is disabled, it redirects back to the contacts path, and if it's an ajax request (which it most likely will be, it renders nothing-- there is unobtrusive js that handles updating the page). ... So, if someone could please point me in the right direction as far as what my test code SHOULD look like, I'd greatly appreciate it. I have no idea how to test if a rake task fails or not.. I have no idea how to hook into the controller code and determine whether the result_lis variable is a PdfList class or a Newsletter class... And I have no idea how to test whether a http request redirects to contacts_path, or if an ajax request renders nothing! I feel like, I know what I want to test, but I just have no idea how to test it... Thank you for any guidance. -patrick From phillipkoebbe at gmail.com Thu Feb 18 07:34:37 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 18 Feb 2010 06:34:37 -0600 Subject: [rspec-users] please help me learn how to use rspec! In-Reply-To: <3cc64e0c-fc4e-4674-a981-f345e4f603a4@k5g2000pra.googlegroups.com> References: <3cc64e0c-fc4e-4674-a981-f345e4f603a4@k5g2000pra.googlegroups.com> Message-ID: <4B7D33DD.6030803@gmail.com> patrick99e99 wrote: > Hi, > > So-- I am very very new to BDD.. and I am trying to go over and write > > The best place to start is the RSpec Book. http://www.pragprog.com/titles/achbd/the-rspec-book Peace, Phillip From me at franklakatos.com Thu Feb 18 11:25:15 2010 From: me at franklakatos.com (me at franklakatos.com) Date: Thu, 18 Feb 2010 09:25:15 -0700 Subject: [rspec-users] Question About Cleaning Up Specs? Message-ID: <20100218092515.kh60xeme0c4ggcg0@franklakatos.com> I know we are suppose to keep specs obvious and readable, but is it normal (or there any opposition) to stubbing every method call that you needed in a before block and simply over-riding the same method with a should_receive in the actual tested it()? Example describe "#create" do it "should find a user" @user = mock_model(User) User.should_receive(:find).and_return @user @posts = [] @post = mock_model(Post) @posts.stub(:build).and_return @post post "create" end it "should build a post from that user" do @user = mock_model(User) User.stub(:find).and_return @user @posts = [] @post = mock_model(Post) @posts.should_receive(:build).and_return @post post "create" end end ... would become .. describe "#create" do before do @user = mock_model(User) User.stub(:find).and_return @user @posts = [] @post = mock_model(Post) @posts.stub(:build).and_return @post end it "should find a user" User.should_receive(:find).and_return @user post "create" end it "should build a post from that user" do @posts.should_receive(:build).and_return @post post "create" end end Note that I stubbed both method calls in the before, but only should_require'd them in the appropriate it()? Let me know if that's good practice From matt at mattwynne.net Thu Feb 18 11:45:45 2010 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 18 Feb 2010 16:45:45 +0000 Subject: [rspec-users] Question About Cleaning Up Specs? In-Reply-To: <20100218092515.kh60xeme0c4ggcg0@franklakatos.com> References: <20100218092515.kh60xeme0c4ggcg0@franklakatos.com> Message-ID: <82A1C252-DA96-464C-8062-15B7970E5970@mattwynne.net> On 18 Feb 2010, at 16:25, me at franklakatos.com wrote: > I know we are suppose to keep specs obvious and readable, but is it > normal (or there any opposition) to stubbing every method call that > you needed in a before block and simply over-riding the same method > with a should_receive in the actual tested it()? > > Example > > describe "#create" do > it "should find a user" > @user = mock_model(User) > User.should_receive(:find).and_return @user > @posts = [] > @post = mock_model(Post) > @posts.stub(:build).and_return @post > post "create" > end > > it "should build a post from that user" do > @user = mock_model(User) > User.stub(:find).and_return @user > @posts = [] > @post = mock_model(Post) > @posts.should_receive(:build).and_return @post > post "create" > end > end > > ... would become .. > > > describe "#create" do > before do > @user = mock_model(User) > User.stub(:find).and_return @user > @posts = [] > @post = mock_model(Post) > @posts.stub(:build).and_return @post > end > > it "should find a user" > User.should_receive(:find).and_return @user > post "create" > end > > it "should build a post from that user" do > @posts.should_receive(:build).and_return @post > post "create" > end > end > > Note that I stubbed both method calls in the before, but only > should_require'd them in the appropriate it()? > > Let me know if that's good practice That's exactly what I do. > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From joahking at gmail.com Thu Feb 18 11:57:27 2010 From: joahking at gmail.com (Joaquin Rivera Padron) Date: Thu, 18 Feb 2010 17:57:27 +0100 Subject: [rspec-users] Question About Cleaning Up Specs? In-Reply-To: <82A1C252-DA96-464C-8062-15B7970E5970@mattwynne.net> References: <20100218092515.kh60xeme0c4ggcg0@franklakatos.com> <82A1C252-DA96-464C-8062-15B7970E5970@mattwynne.net> Message-ID: <8277b7f41002180857u33dbc4cbo15b18185112110a0@mail.gmail.com> those who knows more say the idea is to keep in the example only what is important for the example (but they surely say it even better than me) which is what you are doing +1, greetings, joaquin 2010/2/18 Matt Wynne > > On 18 Feb 2010, at 16:25, me at franklakatos.com wrote: > > I know we are suppose to keep specs obvious and readable, but is it normal >> (or there any opposition) to stubbing every method call that you needed in a >> before block and simply over-riding the same method with a should_receive in >> the actual tested it()? >> >> Example >> >> describe "#create" do >> it "should find a user" >> @user = mock_model(User) >> User.should_receive(:find).and_return @user >> @posts = [] >> @post = mock_model(Post) >> @posts.stub(:build).and_return @post >> post "create" >> end >> >> it "should build a post from that user" do >> @user = mock_model(User) >> User.stub(:find).and_return @user >> @posts = [] >> @post = mock_model(Post) >> @posts.should_receive(:build).and_return @post >> post "create" >> end >> end >> >> ... would become .. >> >> >> describe "#create" do >> before do >> @user = mock_model(User) >> User.stub(:find).and_return @user >> @posts = [] >> @post = mock_model(Post) >> @posts.stub(:build).and_return @post >> end >> >> it "should find a user" >> User.should_receive(:find).and_return @user >> post "create" >> end >> >> it "should build a post from that user" do >> @posts.should_receive(:build).and_return @post >> post "create" >> end >> end >> >> Note that I stubbed both method calls in the before, but only >> should_require'd them in the appropriate it()? >> >> Let me know if that's good practice >> > > That's exactly what I do. > > > >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > cheers, > Matt > > http://mattwynne.net > +447974 430184 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- www.least-significant-bit.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From phillipkoebbe at gmail.com Thu Feb 18 12:13:18 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 18 Feb 2010 11:13:18 -0600 Subject: [rspec-users] Question About Cleaning Up Specs? In-Reply-To: <8277b7f41002180857u33dbc4cbo15b18185112110a0@mail.gmail.com> References: <20100218092515.kh60xeme0c4ggcg0@franklakatos.com> <82A1C252-DA96-464C-8062-15B7970E5970@mattwynne.net> <8277b7f41002180857u33dbc4cbo15b18185112110a0@mail.gmail.com> Message-ID: <4B7D752E.30709@gmail.com> Joaquin Rivera Padron wrote: > those who knows more say the idea is to keep in the example only what > is important for the example (but they surely say it even better than > me) which is what you are doing +1, > > greetings, > joaquin > > 2010/2/18 Matt Wynne > > > > On 18 Feb 2010, at 16:25, me at franklakatos.com > wrote: > > I know we are suppose to keep specs obvious and readable, but > is it normal (or there any opposition) to stubbing every > method call that you needed in a before block and simply > over-riding the same method with a should_receive in the > actual tested it()? > > Example > > describe "#create" do > it "should find a user" > @user = mock_model(User) > User.should_receive(:find).and_return @user > @posts = [] > @post = mock_model(Post) > @posts.stub(:build).and_return @post > post "create" > end > > it "should build a post from that user" do > @user = mock_model(User) > User.stub(:find).and_return @user > @posts = [] > @post = mock_model(Post) > @posts.should_receive(:build).and_return @post > post "create" > end > end > > ... would become .. > > > describe "#create" do > before do > @user = mock_model(User) > User.stub(:find).and_return @user > @posts = [] > @post = mock_model(Post) > @posts.stub(:build).and_return @post > end > > it "should find a user" > User.should_receive(:find).and_return @user > post "create" > end > > it "should build a post from that user" do > @posts.should_receive(:build).and_return @post > post "create" > end > end > I often have a before :each that initializes objects to some default state and then change whatever is necessary in the individual examples. +1 here as well. Peace, Phillip From ed.howland at gmail.com Thu Feb 18 12:19:05 2010 From: ed.howland at gmail.com (Ed Howland) Date: Thu, 18 Feb 2010 12:19:05 -0500 Subject: [rspec-users] have_tag missing assert_select outside of controller/view tests In-Reply-To: <3df642dd1002171756n229fdcb7ya67d4d4119e07a3d@mail.gmail.com> References: <3df642dd1002171047q520dce9dx5ff9211b5110fd00@mail.gmail.com> <57c63afe1002171238l789a4957v797a7bab3d55a738@mail.gmail.com> <3df642dd1002171756n229fdcb7ya67d4d4119e07a3d@mail.gmail.com> Message-ID: <3df642dd1002180919s1b2f8d69nc0ffbf88444bb139@mail.gmail.com> Thanks for the advice, Webrat's have_select or does work with any object that responds to :body. so I've now got it working with Steven Parkes's Env.js port to Johnson w/TraceMonkey. RSpec on Javascript w/o a browser. Sweet. Cheers, Ed Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland On Wed, Feb 17, 2010 at 8:56 PM, Ed Howland wrote: > Thanks, David. > > I hope that is less/non dependent on Rails/ActiveSupport. It seems to > depend on Nokogiri, and hopefully uses some duck-typeable response > object. I guess they use response_body. > > I've concocted a strange brew of RSpec, Johnson and envjs. It can already > execute normal Javascript methods, jQuery, and AJAX calls. The only > missing piece is the assert_select-like framework: > > it "should make an ajax call and format some content" do > ? ?click_async "a#edit" > ? ?response.should have_selector('div') # this last part, I need > end > > I don't know if anyone else is working on this front, but it is > getting us closer to having a pure Ruby/non-browser spec framework > > Cheers, > Ed > > Ed Howland > http://greenprogrammer.wordpress.com > http://twitter.com/ed_howland > > > > On Wed, Feb 17, 2010 at 3:38 PM, David Chelimsky wrote: >> On Wed, Feb 17, 2010 at 12:47 PM, Ed Howland wrote: >>> Hi, >>> >>> I'm trying to write an example that uses response.should have_tag('div') >>> outside of a Rails view test. I read somewhere that as long as you >>> have an instance variable named @response and it respondes to .body >>> with some HTML, it should work, but I get this failure: >> >> have_tag is on its way to its death. It won't exist in rspec-rails-2, >> though I hesitate to deprecate it in rspec-rails-1.x since many folks >> won't be able to upgrade directly anyhow. >> >> I'd recommend using webrat's have_selector instead. >> >>> >>> undefined method `assert_select' for #>> >>> Also, has anyone cooked this up to work with Sinatra, or are you >>> restricted to using Rails? Seems that some Nokogiri wiz could work up >>> a substitute for ActiveSupport. >>> >>> Thanks, >>> Ed >>> >>> Ed Howland >>> http://greenprogrammer.wordpress.com >>> http://twitter.com/ed_howland >>> >>> >>> >>> On Tue, Feb 16, 2010 at 6:42 PM, patrick99e99 wrote: >>>> I am new to BDD, so am not quite sure how I am supposed to write a >>>> test like this.. ?I get: >>>> "ActiveRecord::RecordInvalid in 'User should fail when passwords do >>>> not match' >>>> Validation failed: Password doesn't match confirmation" >>>> >>>> If anyone can guide me in the right direction, I'd appreciate it.. >>>> >>>> -patrick >>>> >>>> require 'spec_helper' >>>> >>>> describe User do >>>> >>>> ?before(:each) do >>>> ? ? @valid_attributes = { >>>> ? ? ?:login => 'test_name', >>>> ? ? ?:password => 'password', >>>> ? ? ?:password_confirmation => 'password' >>>> ? ?} >>>> >>>> ? ? ?@invalid_attributes = @valid_attributes.merge(:password => >>>> 'not_the_same_password') >>>> ?end >>>> >>>> ?it "should create a valid user" do >>>> ? ?User.create!(@valid_attributes).should be_true >>>> ?end >>>> >>>> ?it "should fail when passwords do not match" do >>>> ? ?User.create!(@invalid_attributes).should be_false >>>> ?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 patrick99e99 at gmail.com Thu Feb 18 12:48:07 2010 From: patrick99e99 at gmail.com (patrick99e99) Date: Thu, 18 Feb 2010 09:48:07 -0800 (PST) Subject: [rspec-users] please help me learn how to use rspec! In-Reply-To: <4B7D33DD.6030803@gmail.com> References: <3cc64e0c-fc4e-4674-a981-f345e4f603a4@k5g2000pra.googlegroups.com> <4B7D33DD.6030803@gmail.com> Message-ID: Yeah, I have the book.. have read it.. also have watched peepcode's three screencasts on rspec, also have watched the first 7 episodes of BDDCasts. I just am still fuzzy on lots of things, and am hoping someone will be kind enough to go through my spec file and show me what kind of code they would write to get it to accomplish what it needs to. -patrick On Feb 18, 4:34?am, Phillip Koebbe wrote: > patrick99e99 wrote: > > Hi, > > > So-- I am very very new to BDD.. and I am trying to go over and write > > The best place to start is the RSpec Book. > > http://www.pragprog.com/titles/achbd/the-rspec-book > > Peace, > Phillip > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From celoserpa at gmail.com Thu Feb 18 12:58:33 2010 From: celoserpa at gmail.com (Marcelo de Moraes Serpa) Date: Thu, 18 Feb 2010 15:58:33 -0200 Subject: [rspec-users] How to spec accessing a constant In-Reply-To: References: <4D8A62C5-3AC9-4D2F-B052-862D2AC1DCFC@deadorange.com> <61c885db0810151339h6c2ef226g385be032d55fa0c9@mail.gmail.com> <61c885db0810151859r14ff5a5ai389bc1726456d4a9@mail.gmail.com> <61c885db0810161212l15e6cfa6h704cb1088a0b94eb@mail.gmail.com> Message-ID: <1e5bcefd1002180958p7090dc54kd3e647156805c729@mail.gmail.com> Why don't you open the class, and set the constant like so: class TheClass CONSTANT = 'value_it_should_have_for_the_current_spec' end This worked for me. Marcelo. On Thu, Oct 16, 2008 at 7:24 PM, Nick Hoffman wrote: > On 2008-10-16, at 15:12, Craig Demyanovich wrote: > >> Cool. Having seen something a little more concrete, I like your design >> decisions. In this case, I'd go with Scott's recommendation of hiding the >> constant behind a method. >> >> Regards, >> Craig >> > > Thanks for taking a look, Craig, and giving me your opinion. > > > Cheers, > Nick > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From celoserpa at gmail.com Thu Feb 18 14:33:47 2010 From: celoserpa at gmail.com (Marcelo de Moraes Serpa) Date: Thu, 18 Feb 2010 17:33:47 -0200 Subject: [rspec-users] Recall a example inside another (just like in Cucumber) Message-ID: <1e5bcefd1002181133l2f1079aepe09601a33e6e1a29@mail.gmail.com> Hello guys, I was spec'ing a model and just tried to do something like this it "should create a payment with period_start & period_end set correctly" do it "should create a new payment for an approved transaction" previous_payment = Payment.find(Payment.last.id-1) just_created_payment = Payment.last #Here, check below for a documentation of how period_start and #period_end should be set as of now: payment.period_start.should == previous_payment.period_end payment.period_end.should == previous_payment.period_end + (@subscription.billing_cycle.months).months end Calling an already defined example, since this one requires all the tests/objects from the "should created a new payment for an approved transaction". I know I could just recreted all objects locally or just use a before block, but I think it would be useful if we could do like this just like Cucumber allows with steps. Cheers, Marcelo. -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Thu Feb 18 15:11:44 2010 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 18 Feb 2010 20:11:44 +0000 Subject: [rspec-users] Recall a example inside another (just like in Cucumber) In-Reply-To: <1e5bcefd1002181133l2f1079aepe09601a33e6e1a29@mail.gmail.com> References: <1e5bcefd1002181133l2f1079aepe09601a33e6e1a29@mail.gmail.com> Message-ID: <435B87EE-BA4D-40C5-800F-60FCA72FD05F@mattwynne.net> On 18 Feb 2010, at 19:33, Marcelo de Moraes Serpa wrote: > Hello guys, > > I was spec'ing a model and just tried to do something like this > > it "should create a payment with period_start & period_end set > correctly" do > it "should create a new payment for an approved transaction" > > previous_payment = Payment.find(Payment.last.id-1) > just_created_payment = Payment.last > #Here, check below for a documentation of how period_start and > #period_end should be set as of now: > payment.period_start.should == previous_payment.period_end > payment.period_end.should == previous_payment.period_end + > (@subscription.billing_cycle.months).months > > > end > > Calling an already defined example, since this one requires all the > tests/objects from the "should created a new payment for an approved > transaction". > > I know I could just recreted all objects locally or just use a > before block, but I think it would be useful if we could do like > this just like Cucumber allows with steps. Why not move the code that's common to the two examples out into a before block? > > Cheers, > > Marcelo. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From phillipkoebbe at gmail.com Thu Feb 18 15:20:13 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 18 Feb 2010 14:20:13 -0600 Subject: [rspec-users] Recall a example inside another (just like in Cucumber) In-Reply-To: <435B87EE-BA4D-40C5-800F-60FCA72FD05F@mattwynne.net> References: <1e5bcefd1002181133l2f1079aepe09601a33e6e1a29@mail.gmail.com> <435B87EE-BA4D-40C5-800F-60FCA72FD05F@mattwynne.net> Message-ID: <4B7DA0FD.5090203@gmail.com> > On 18 Feb 2010, at 19:33, Marcelo de Moraes Serpa wrote: > >> Hello guys, >> >> I was spec'ing a model and just tried to do something like this >> >> it "should create a payment with period_start & period_end set >> correctly" do >> it "should create a new payment for an approved transaction" >> >> previous_payment = Payment.find(Payment.last.id-1) >> just_created_payment = Payment.last >> #Here, check below for a documentation of how period_start and >> #period_end should be set as of now: >> payment.period_start.should == previous_payment.period_end >> payment.period_end.should == previous_payment.period_end + >> (@subscription.billing_cycle.months).months >> >> >> end >> >> Calling an already defined example, since this one requires all the >> tests/objects from the "should created a new payment for an approved >> transaction". >> >> I know I could just recreted all objects locally or just use a before >> block, but I think it would be useful if we could do like this just >> like Cucumber allows with steps. > > Why not move the code that's common to the two examples out into a > before block? > Or a shared example? I haven't used them much, so I'm only guessing that it would work. Peace, Phillip From ssmithstone at me.com Thu Feb 18 16:17:39 2010 From: ssmithstone at me.com (Stephen Smithstone) Date: Thu, 18 Feb 2010 21:17:39 +0000 Subject: [rspec-users] please help me learn how to use rspec! In-Reply-To: <3cc64e0c-fc4e-4674-a981-f345e4f603a4@k5g2000pra.googlegroups.com> References: <3cc64e0c-fc4e-4674-a981-f345e4f603a4@k5g2000pra.googlegroups.com> Message-ID: <4B7DAE73.9050101@me.com> An HTML attachment was scrubbed... URL: From ssmithstone at me.com Thu Feb 18 17:05:42 2010 From: ssmithstone at me.com (Stephen Smithstone) Date: Thu, 18 Feb 2010 22:05:42 +0000 Subject: [rspec-users] please help me learn how to use rspec! In-Reply-To: <4B7DAE73.9050101@me.com> References: <3cc64e0c-fc4e-4674-a981-f345e4f603a4@k5g2000pra.googlegroups.com> <4B7DAE73.9050101@me.com> Message-ID: <4B7DB9B6.3000208@me.com> An HTML attachment was scrubbed... URL: From erikpukinskis at gmail.com Fri Feb 19 03:59:06 2010 From: erikpukinskis at gmail.com (Erik Pukinskis) Date: Fri, 19 Feb 2010 00:59:06 -0800 Subject: [rspec-users] Do you still Write Tests First on code that is churning hard? Message-ID: Hello Specmeisters! I have a bit of a philosophical question for the TDD witches and wizards out there. I'm working on some code that is really churning... It's doing complicated calculations, but the actual desired results are a moving target. The acceptable values, and even the structure of the software's output are changing constantly. The internal architecture is changing rapidly, and I'm constantly throwing away methods I no longer need. This has resulted in me no longer writing specs on this part of my codebase. They just become obsolete very very fast. Changing the specs constantly feels like a pointless doubling of my effort. Specs seem to help with debugging and verification that the software is performing as expected. But I'm spending most of my time trying to figure out what I should be expecting. I verify that things are working quickly and informally, because it's likely the definition of "working" will change before the week is up. Am I being stupid? Is it really a pointless doubling, or am I creating more debugging time for myself than I'm saving without writing specs? Should I be more religious about Test First? Thanks in advance for the insights, Erik From court3nay at gmail.com Fri Feb 19 04:41:08 2010 From: court3nay at gmail.com (Courtenay) Date: Fri, 19 Feb 2010 01:41:08 -0800 Subject: [rspec-users] Do you still Write Tests First on code that is churning hard? In-Reply-To: References: Message-ID: <4b430c8f1002190141x4ad3da4ake5ef388ba3498356@mail.gmail.com> Testing should answer this question for you, regularly: How do you know it works? Courtenay On Fri, Feb 19, 2010 at 12:59 AM, Erik Pukinskis wrote: > Hello Specmeisters! > > I have a bit of a philosophical question for the TDD witches and > wizards out there. ?I'm working on some code that is really > churning... It's doing complicated calculations, but the actual > desired results are a moving target. The acceptable values, and even > the structure of the software's output are changing constantly. ?The > internal architecture is changing rapidly, and I'm constantly throwing > away methods I no longer need. > > This has resulted in me no longer writing specs on this part of my > codebase. ?They just become obsolete very very fast. ?Changing the > specs constantly feels like a pointless doubling of my effort. ?Specs > seem to help with debugging and verification that the software is > performing as expected. ?But I'm spending most of my time trying to > figure out what I should be expecting. ?I verify that things are > working quickly and informally, because it's likely the definition of > "working" will change before the week is up. > > Am I being stupid? ?Is it really a pointless doubling, or am I > creating more debugging time for myself than I'm saving without > writing specs? ?Should I be more religious about Test First? > > Thanks in advance for the insights, > Erik > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From joahking at gmail.com Fri Feb 19 04:48:02 2010 From: joahking at gmail.com (Joaquin Rivera Padron) Date: Fri, 19 Feb 2010 10:48:02 +0100 Subject: [rspec-users] Do you still Write Tests First on code that is churning hard? In-Reply-To: References: Message-ID: <8277b7f41002190148o767891cbve09fe0058da317cb@mail.gmail.com> hi there, well I'm not a meister myself, but spec-ing something you don't know the outside result is a bit hard for me. I normally work in two modes: * hacking mode: that's when I'm trying to "see" if I can do something, if the result will run, getting to know the problem and such. In these mode I "only" write specs that keep me going further, but those look more like test units. This specs or test-units-specs are something I see as tests that later are a kind of code history ("residual tests" keeps coming to the top of my head) and keep them as long as they don't start becoming a PITA and of course are still valid :-) after I know my hack will do, and know the problem better I switch to typical outside in * bdd developing mode so the thing is outside in only works if you know the outside. And also try to spec only the "right" amount. But for maths calculations I would for sure TEST some thougts, hth joaquin 2010/2/19 Erik Pukinskis > Hello Specmeisters! > > I have a bit of a philosophical question for the TDD witches and > wizards out there. I'm working on some code that is really > churning... It's doing complicated calculations, but the actual > desired results are a moving target. The acceptable values, and even > the structure of the software's output are changing constantly. The > internal architecture is changing rapidly, and I'm constantly throwing > away methods I no longer need. > > This has resulted in me no longer writing specs on this part of my > codebase. They just become obsolete very very fast. Changing the > specs constantly feels like a pointless doubling of my effort. Specs > seem to help with debugging and verification that the software is > performing as expected. But I'm spending most of my time trying to > figure out what I should be expecting. I verify that things are > working quickly and informally, because it's likely the definition of > "working" will change before the week is up. > > Am I being stupid? Is it really a pointless doubling, or am I > creating more debugging time for myself than I'm saving without > writing specs? Should I be more religious about Test First? > > Thanks in advance for the insights, > Erik > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- www.least-significant-bit.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Fri Feb 19 07:21:36 2010 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 19 Feb 2010 12:21:36 +0000 Subject: [rspec-users] Do you still Write Tests First on code that is churning hard? In-Reply-To: References: Message-ID: On 19 Feb 2010, at 08:59, Erik Pukinskis wrote: > Hello Specmeisters! > > I have a bit of a philosophical question for the TDD witches and > wizards out there. I'm working on some code that is really > churning... It's doing complicated calculations, but the actual > desired results are a moving target. The acceptable values, and even > the structure of the software's output are changing constantly. The > internal architecture is changing rapidly, and I'm constantly throwing > away methods I no longer need. > > This has resulted in me no longer writing specs on this part of my > codebase. They just become obsolete very very fast. Changing the > specs constantly feels like a pointless doubling of my effort. Specs > seem to help with debugging and verification that the software is > performing as expected. But I'm spending most of my time trying to > figure out what I should be expecting. I verify that things are > working quickly and informally, because it's likely the definition of > "working" will change before the week is up. > > Am I being stupid? Is it really a pointless doubling, or am I > creating more debugging time for myself than I'm saving without > writing specs? Should I be more religious about Test First? > > Thanks in advance for the insights, > Erik Here are some rules of thumb I would use: If requirements are churning, I would try to use high-level acceptance tests (e.g. with Cucumber) to firm them up. If I can't firm up my requirements, it's because we're still going though a discovery process - we don't understand what the problem is, let alone the solution - and that means it's too early to write any production code. I would happily write code without tests at this point, but I'm going to be loud and clear about the fact that the code I'm writing is a spike, and will have to be thrown away and re-written before we go live. This kind of code is much more valuable than you think - most of the value is in the learning that goes into your heads as you do it, rather than in the cobbled-together, un-tested code you write. Writing code like this can be fun, but never be tempted to check it in! Once the requirements start to stabilise (but are still changing) I often go through a process where the design is still churning as I try to work out how I best want to solve the problem. At this point I would rely on those high-level acceptance tests to cover me and only write specs for parts of the design as it started to stabilise. The thing you have to remember is the point of TDD/BDD is to surface uncertainly and misunderstanding early. Once you get past the discovery stage, having the discipline to write tests first will reduce churn, because you ask more questions (and make more decisions) before you actually sit down and write code. If you don't have enough information to make those decisions though, don't be afraid or ashamed to write a spike, but make sure everyone on your team understands the distinction between that and production code. cheers, Matt http://mattwynne.net +447974 430184 From me at franklakatos.com Fri Feb 19 08:40:14 2010 From: me at franklakatos.com (me at franklakatos.com) Date: Fri, 19 Feb 2010 08:40:14 -0500 Subject: [rspec-users] Do you still Write Tests First on code that is churning hard? In-Reply-To: References: Message-ID: <7CD3299B-7A2D-4654-8B46-9F92E659B456@franklakatos.com> I kind of follow a similar principle here. Many times I will write app code because in not sure how to pull of the functionality I'm try to do. Once I can confirm that I'm getting the expected results, I take a mental note of what I did, remove the code, and drive it out again with the spec. I like this method a lot because the repetition helps me to lock in the logic. Kinda like how people say you really know a topic if you can teach it to someone else. The spec almost because that someone else I'm teaching. So in short, I think you're safe in your approach, but don't leave the code-first spec-second code in production. -------------- Frank Lakatos Catchon Media frank at catchonmedia.com http://www.catchonmedia.com On Feb 19, 2010, at 7:21 AM, Matt Wynne wrote: From mailinglists at patmaddox.com Fri Feb 19 20:04:12 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Fri, 19 Feb 2010 17:04:12 -0800 Subject: [rspec-users] adding to the callbacks that rspec-rails adds In-Reply-To: <0F0D0BA33A9B48A0964B14FE8F1DD40E@champ.net> References: <0F0D0BA33A9B48A0964B14FE8F1DD40E@champ.net> Message-ID: <9079A1F2-5D34-4A40-AA46-F387A395FFAA@patmaddox.com> Look in spec/spec_helper.rb for the configuration block, and hook up your custom stuff there: Spec::Runner.configured do |config| config.before(:each) { AfterFixturesLoaded.custom_stuff1 } config.after(:each) { AfterFixturesLoaded.custom_stuff1 } end Pat On Feb 16, 2010, at 8:48 AM, Ben Fyvie wrote: > I have some code that adds to the callbacks that rspec-rails adds by default to setup and teardown fixtures. > > My code looks something like: > > module Test > module Unit > > class TestCase > append_before(:each) do > Test::Unit::AfterFixturesLoaded.custom_stuff1 > end > > append_after(:each) do > Test::Unit::AfterFixturesLoaded.custom_stuff2 > end > end > > class AfterFixturesLoaded > > def self.custom_stuff1 > #do some stuff here > end > > def self.custom_stuff2 > #do some other stuff here > end > end > > end > end > > This code works fine if I put it in the config\initializers directory in the rails app, but then running the app fails because it doesn't load test unit. So my question is where can I put this code so that it will always be included when running rspec? > > Thanks! > Ben Fyvie > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From mailinglists at patmaddox.com Fri Feb 19 20:13:02 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Fri, 19 Feb 2010 17:13:02 -0800 Subject: [rspec-users] Question About Cleaning Up Specs? In-Reply-To: <20100218092515.kh60xeme0c4ggcg0@franklakatos.com> References: <20100218092515.kh60xeme0c4ggcg0@franklakatos.com> Message-ID: <0EF2D231-C38A-4333-BED0-44FF27946448@patmaddox.com> I disagree with the crowd on the basis that these examples are lazy. Very close to what I do though. Imagine you had one other example in there: it "should assign the post to the view" do post :create assigns[:post].should == @post end Then you wouldn't really need the other should_receive examples. Why? Well, there's no way for that object to be returned other than via your User.find().build chain, is there? I would still write the should_receive's, but they would include the arguments I expect the method to receive. That's the point where something could get screwed up. But hopefully you can see why, if you've created a chain of stubbed methods, you only need to verify the end result of the chain, and everything up to it is verified implicitly. Pat On Feb 18, 2010, at 8:25 AM, me at franklakatos.com wrote: > I know we are suppose to keep specs obvious and readable, but is it normal (or there any opposition) to stubbing every method call that you needed in a before block and simply over-riding the same method with a should_receive in the actual tested it()? > > Example > > describe "#create" do > it "should find a user" > @user = mock_model(User) > User.should_receive(:find).and_return @user > @posts = [] > @post = mock_model(Post) > @posts.stub(:build).and_return @post > post "create" > end > > it "should build a post from that user" do > @user = mock_model(User) > User.stub(:find).and_return @user > @posts = [] > @post = mock_model(Post) > @posts.should_receive(:build).and_return @post > post "create" > end > end > > ... would become .. > > > describe "#create" do > before do > @user = mock_model(User) > User.stub(:find).and_return @user > @posts = [] > @post = mock_model(Post) > @posts.stub(:build).and_return @post > end > > it "should find a user" > User.should_receive(:find).and_return @user > post "create" > end > > it "should build a post from that user" do > @posts.should_receive(:build).and_return @post > post "create" > end > end > > Note that I stubbed both method calls in the before, but only should_require'd them in the appropriate it()? > > Let me know if that's good practice > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From rick.denatale at gmail.com Fri Feb 19 20:27:10 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Fri, 19 Feb 2010 20:27:10 -0500 Subject: [rspec-users] Question About Cleaning Up Specs? In-Reply-To: <0EF2D231-C38A-4333-BED0-44FF27946448@patmaddox.com> References: <20100218092515.kh60xeme0c4ggcg0@franklakatos.com> <0EF2D231-C38A-4333-BED0-44FF27946448@patmaddox.com> Message-ID: On Fri, Feb 19, 2010 at 8:13 PM, Pat Maddox wrote: > I disagree with the crowd on the basis that these examples are lazy. ?Very close to what I do though. > > Imagine you had one other example in there: > > it "should assign the post to the view" do > ?post :create > ?assigns[:post].should == @post > end > > Then you wouldn't really need the other should_receive examples. ?Why? ?Well, there's no way for that object to be returned other than via your User.find().build chain, is there? Well actually you'd need a User.find().build chain which arranged for the stub @user to return @posts from a call to posts. > I would still write the should_receive's, but they would include the arguments I expect the method to receive. ?That's the point where something could get screwed up. Right, you would want to prove that you were finding the right user in this case, although I'd guess in most conventional rails apps these days you'd actually stub the controllers current_user method to return @user rather than stubbing User.find -- 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 dbatshaw at gmail.com Fri Feb 19 19:53:03 2010 From: dbatshaw at gmail.com (drewB) Date: Fri, 19 Feb 2010 16:53:03 -0800 (PST) Subject: [rspec-users] Adding path for autotest to monitor Message-ID: <677b8ecc-6f75-4281-844d-7c41b623cbe0@t11g2000vbc.googlegroups.com> I am using autotest with RSpec (autospec) and for some reason it doesn't monitor files under the integration folder. Does anyone know how to config autotest to monitor additional paths? I tried playing with add_mapping in my .autotest but was not able to get it to work. Thanks! P.S. I know that using cucumber for integration testing is the best practice for RSpec. Just know that I have a good reason for not using it right now. From dchelimsky at gmail.com Fri Feb 19 21:26:46 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 19 Feb 2010 20:26:46 -0600 Subject: [rspec-users] Adding path for autotest to monitor In-Reply-To: <677b8ecc-6f75-4281-844d-7c41b623cbe0@t11g2000vbc.googlegroups.com> References: <677b8ecc-6f75-4281-844d-7c41b623cbe0@t11g2000vbc.googlegroups.com> Message-ID: <57c63afe1002191826p35683352g8bb7bf45ae8ab7db@mail.gmail.com> On Fri, Feb 19, 2010 at 6:53 PM, drewB wrote: > I am using autotest with RSpec (autospec) and for some reason it > doesn't monitor files under the integration folder. ?Does anyone know > how to config autotest to monitor additional paths? ?I tried playing > with add_mapping in my .autotest but was not able to get it to work. Take a look at http://blog.davidchelimsky.net/2008/01/15/rspec-1-1-2-and-zentest-3-8-0/ and see if that helps. > > Thanks! > > P.S. I know that using cucumber for integration testing is the best > practice for RSpec. ?Just know that I have a good reason for not using > it right now. From matt at mattwynne.net Sat Feb 20 17:09:15 2010 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 20 Feb 2010 22:09:15 +0000 Subject: [rspec-users] Suggested shorthand for and_return when stubbing Message-ID: <4327D96E-BE73-4B4D-8C44-7DF75B210C27@mattwynne.net> I keep wanting to do this, and I don't think it's possible so I thought I'd suggest it. Similarly to the way I can specify stub values as hash key/value pairs when constructing a test double, I'd like to be able to the same when subsequently calling stub on that double: me.stub(:name => 'Matt') That's as opposed to me.stub(:name).and_return('Matt') Thoughts? cheers, Matt http://mattwynne.net +447974 430184 From dchelimsky at gmail.com Sat Feb 20 18:22:09 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 20 Feb 2010 17:22:09 -0600 Subject: [rspec-users] Suggested shorthand for and_return when stubbing In-Reply-To: <4327D96E-BE73-4B4D-8C44-7DF75B210C27@mattwynne.net> References: <4327D96E-BE73-4B4D-8C44-7DF75B210C27@mattwynne.net> Message-ID: <57c63afe1002201522n5278a551w7488773a3049f2b3@mail.gmail.com> On Sat, Feb 20, 2010 at 4:09 PM, Matt Wynne wrote: > I keep wanting to do this, and I don't think it's possible so I thought I'd > suggest it. Similarly to the way I can specify stub values as hash key/value > pairs when constructing a test double, I'd like to be able to the same when > subsequently calling stub on that double: > > ? ?me.stub(:name => 'Matt') > > That's as opposed to > > ? ?me.stub(:name).and_return('Matt') > > Thoughts? Have you tried it? It already works. You can do this, in fact: me.stub(:name => 'David', :predictor_of_matts_future_requests => true) Also, try this one: me.stub(:name) { 'Matt' } That's actually my preference, because it gives you access to args: me.stub(:sum) {|a,b| a + b} me.sum(3,4) => 7 HTH, David From me at franklakatos.com Sat Feb 20 18:27:44 2010 From: me at franklakatos.com (Frank Lakatos) Date: Sat, 20 Feb 2010 18:27:44 -0500 Subject: [rspec-users] Suggested shorthand for and_return when stubbing In-Reply-To: <57c63afe1002201522n5278a551w7488773a3049f2b3@mail.gmail.com> References: <4327D96E-BE73-4B4D-8C44-7DF75B210C27@mattwynne.net> <57c63afe1002201522n5278a551w7488773a3049f2b3@mail.gmail.com> Message-ID: <7CA6B2B7-1625-4358-8F15-8FA119904AE3@franklakatos.com> me.stub(:sum) {|a,b| a + b} = really slick trick! On Feb 20, 2010, at 6:22 PM, David Chelimsky wrote: > On Sat, Feb 20, 2010 at 4:09 PM, Matt Wynne > wrote: >> I keep wanting to do this, and I don't think it's possible so I >> thought I'd >> suggest it. Similarly to the way I can specify stub values as hash >> key/value >> pairs when constructing a test double, I'd like to be able to the >> same when >> subsequently calling stub on that double: >> >> me.stub(:name => 'Matt') >> >> That's as opposed to >> >> me.stub(:name).and_return('Matt') >> >> Thoughts? > > Have you tried it? It already works. You can do this, in fact: > > me.stub(:name => 'David', :predictor_of_matts_future_requests => > true) > > Also, try this one: > > me.stub(:name) { 'Matt' } > > That's actually my preference, because it gives you access to args: > > me.stub(:sum) {|a,b| a + b} > me.sum(3,4) > => 7 > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sat Feb 20 18:32:57 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 20 Feb 2010 17:32:57 -0600 Subject: [rspec-users] Suggested shorthand for and_return when stubbing In-Reply-To: <7CA6B2B7-1625-4358-8F15-8FA119904AE3@franklakatos.com> References: <4327D96E-BE73-4B4D-8C44-7DF75B210C27@mattwynne.net> <57c63afe1002201522n5278a551w7488773a3049f2b3@mail.gmail.com> <7CA6B2B7-1625-4358-8F15-8FA119904AE3@franklakatos.com> Message-ID: <57c63afe1002201532k1345ba8bm4210f1ed9312696a@mail.gmail.com> On Sat, Feb 20, 2010 at 5:27 PM, Frank Lakatos wrote: > ?me.stub(:sum) {|a,b| a + b} = really slick trick! It's an easy way to do a Fake (http://xunitpatterns.com/Fake%20Object.html), at the method level (all of those patterns are really method level patters, not object level patterns). Another use is for expectations: foo.should_receive(:bar) do |a, b| a.should be_x b.should be_y end > > > On Feb 20, 2010, at 6:22 PM, David Chelimsky wrote: > >> On Sat, Feb 20, 2010 at 4:09 PM, Matt Wynne wrote: >>> >>> I keep wanting to do this, and I don't think it's possible so I thought >>> I'd >>> suggest it. Similarly to the way I can specify stub values as hash >>> key/value >>> pairs when constructing a test double, I'd like to be able to the same >>> when >>> subsequently calling stub on that double: >>> >>> ? me.stub(:name => 'Matt') >>> >>> That's as opposed to >>> >>> ? me.stub(:name).and_return('Matt') >>> >>> Thoughts? >> >> Have you tried it? It already works. You can do this, in fact: >> >> ?me.stub(:name => 'David', :predictor_of_matts_future_requests => true) >> >> Also, try this one: >> >> ?me.stub(:name) { 'Matt' } >> >> That's actually my preference, because it gives you access to args: >> >> ?me.stub(:sum) {|a,b| a + b} >> ?me.sum(3,4) >> ?=> 7 >> >> HTH, >> David >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt at mattwynne.net Sat Feb 20 19:15:16 2010 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 21 Feb 2010 00:15:16 +0000 Subject: [rspec-users] Suggested shorthand for and_return when stubbing In-Reply-To: <57c63afe1002201522n5278a551w7488773a3049f2b3@mail.gmail.com> References: <4327D96E-BE73-4B4D-8C44-7DF75B210C27@mattwynne.net> <57c63afe1002201522n5278a551w7488773a3049f2b3@mail.gmail.com> Message-ID: On 20 Feb 2010, at 23:22, David Chelimsky wrote: > On Sat, Feb 20, 2010 at 4:09 PM, Matt Wynne > wrote: >> I keep wanting to do this, and I don't think it's possible so I >> thought I'd >> suggest it. Similarly to the way I can specify stub values as hash >> key/value >> pairs when constructing a test double, I'd like to be able to the >> same when >> subsequently calling stub on that double: >> >> me.stub(:name => 'Matt') >> >> That's as opposed to >> >> me.stub(:name).and_return('Matt') >> >> Thoughts? > > Have you tried it? It already works. You can do this, in fact: > > me.stub(:name => 'David', :predictor_of_matts_future_requests => > true) > > Also, try this one: > > me.stub(:name) { 'Matt' } > > That's actually my preference, because it gives you access to args: > > me.stub(:sum) {|a,b| a + b} > me.sum(3,4) > => 7 Ha ha. I should have known :) > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From apremdas at gmail.com Sun Feb 21 05:52:02 2010 From: apremdas at gmail.com (Andrew Premdas) Date: Sun, 21 Feb 2010 10:52:02 +0000 Subject: [rspec-users] GET a path in a controller spec In-Reply-To: References: Message-ID: <88fd8ddc1002210252u317db09br1aa40bbf5bfc8743@mail.gmail.com> On 31 January 2010 22:02, Nick Hoffman wrote: > One of my controller actions sends a redirect if the request URI begins > with /foods/search > > 34 def search > 35 return redirect_to "/#{params[:name]}" if > request.request_uri.match /^\/foods\/search/ > > Unfortunately, I can't figure out how to spec this. > > >From everything that I've read while researching this problem, it seems > that #get and #post only accept the action to call, and a hash of > parameters. IE: > get :action, :some => 'param' > As a result, I can't do this: > 121 it 'redirects /foods/search/almonds to /almonds' do > 122 get '/foods/search/almonds' > 123 response.should redirect_to "/almonds" > 124 end > > How can I spec this? > > Thanks for your help, > Nick > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > You might find this easier to do as an integration test. I'd use cucumber for this. Personally I think speccing controllers is pretty hard for the benefits it gives, and if you keep your controllers real simple and thin and use cucumber you can discard most controller specs. -------------- next part -------------- An HTML attachment was scrubbed... URL: From apremdas at gmail.com Sun Feb 21 05:37:14 2010 From: apremdas at gmail.com (Andrew Premdas) Date: Sun, 21 Feb 2010 10:37:14 +0000 Subject: [rspec-users] Do you still Write Tests First on code that is churning hard? In-Reply-To: References: Message-ID: <88fd8ddc1002210237m39085abbo6c43a7dc34130463@mail.gmail.com> On 19 February 2010 08:59, Erik Pukinskis wrote: > Hello Specmeisters! > > I have a bit of a philosophical question for the TDD witches and > wizards out there. I'm working on some code that is really > churning... It's doing complicated calculations, but the actual > desired results are a moving target. The acceptable values, and even > the structure of the software's output are changing constantly. The > internal architecture is changing rapidly, and I'm constantly throwing > away methods I no longer need. > > This has resulted in me no longer writing specs on this part of my > codebase. They just become obsolete very very fast. Changing the > specs constantly feels like a pointless doubling of my effort. Specs > seem to help with debugging and verification that the software is > performing as expected. But I'm spending most of my time trying to > figure out what I should be expecting. I verify that things are > working quickly and informally, because it's likely the definition of > "working" will change before the week is up. > > Am I being stupid? Is it really a pointless doubling, or am I > creating more debugging time for myself than I'm saving without > writing specs? Should I be more religious about Test First? > > Thanks in advance for the insights, > Erik > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I think you can consider writing a completely separate spike to explore your subject, so long as you make absolutely certain that you do not merge it into production code. To avoid that temptation it really should be seperate. Speculating a bit however, I think your process for developing this part of your code maybe very wrong. It sounds like your looking for justification for hacking - which generally is a bad sign - and that maybe you need to take a step back and look at different approaches. Maybe instead of focusing on results you could focus on process e.g. to calculate foo I first need to bar etc. or perhaps you need to go more granular and create some tools to simplify your calculations. Finally if you have any long methods in your calculations (> than 5 lines) refactor them. Decomposing them into smaller methods could reveal alot about the structure of your problem HTH Andrew -------------- next part -------------- An HTML attachment was scrubbed... URL: From marcus at ahnve.com Sun Feb 21 15:57:55 2010 From: marcus at ahnve.com (Marcus Ahnve) Date: Sun, 21 Feb 2010 21:57:55 +0100 Subject: [rspec-users] Problem running spec command for directory Message-ID: <4d4e79cc1002211257x38cc452w8206354f53cf7061@mail.gmail.com> Hi, I have a problem running the spec command in Rspec 1.3.0 with a directory as parameter. A spec for a MongoMapper document that works when run directly such as $ spec spec/model/attendant_spec.rb works fine. But the very same spec run glob-style: $ spec spec fails with MongoMapper validations seemingly added twice - full output at http://pastie.org/835775. According to the stack trace files seems to be required in the same order as when run individually, but clearly something else is messed up. Is there something one should know about when running specs by glob? Thanks for any help /Marcus -- Marcus Ahnve http://marcus.ahnve.net phone: +46 8 56 22 33 94 twitter: mahnve From dchelimsky at gmail.com Sun Feb 21 16:14:10 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 21 Feb 2010 15:14:10 -0600 Subject: [rspec-users] Problem running spec command for directory In-Reply-To: <4d4e79cc1002211257x38cc452w8206354f53cf7061@mail.gmail.com> References: <4d4e79cc1002211257x38cc452w8206354f53cf7061@mail.gmail.com> Message-ID: <57c63afe1002211314h1d4796e4gd7ae9926be46e9a2@mail.gmail.com> On Sun, Feb 21, 2010 at 2:57 PM, Marcus Ahnve wrote: > Hi, > > I have a problem running the spec command in Rspec 1.3.0 with a > directory as parameter. > > A spec for a MongoMapper document that works when run directly such as > > $ spec spec/model/attendant_spec.rb > > works fine. But the very same spec run glob-style: > > $ spec spec > > fails with MongoMapper validations seemingly added twice - full output > at http://pastie.org/835775. > > According to the stack trace files seems to be required in the same > order as when run individually, but clearly something else is messed > up. > > Is there something one should know about when running specs by glob? > > Thanks for any help /Marcus Looks like there are a bunch of relative paths in the stack trace - like this: from /home/mahnve/src/agilasverige/app/agilasverige/spec/model/../spec_helper.rb This means that files may be reloaded depending on where they're ref'd from. Rspec adds ./lib and ./spec to the $LOAD_PATH, so you should be able to require things directly. For example: require "spec_helper" ... will require ./spec/spec_helper.rb. HTH, David > > -- > Marcus Ahnve > http://marcus.ahnve.net > phone: +46 8 56 22 33 94 > twitter: mahnve > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dbatshaw at gmail.com Sun Feb 21 16:49:59 2010 From: dbatshaw at gmail.com (drewB) Date: Sun, 21 Feb 2010 13:49:59 -0800 (PST) Subject: [rspec-users] Adding path for autotest to monitor In-Reply-To: <57c63afe1002191826p35683352g8bb7bf45ae8ab7db@mail.gmail.com> References: <677b8ecc-6f75-4281-844d-7c41b623cbe0@t11g2000vbc.googlegroups.com> <57c63afe1002191826p35683352g8bb7bf45ae8ab7db@mail.gmail.com> Message-ID: Thanks David. I was able to key of some of what you said in the blog. The solution for me was to add the following to my .autotest: Autotest.add_hook :initialize do |at| at.add_mapping(%r%^spec/(integration)/.*rb$%) { |filename, _| filename } end On Feb 19, 6:26?pm, David Chelimsky wrote: > On Fri, Feb 19, 2010 at 6:53 PM, drewB wrote: > > I am using autotest with RSpec (autospec) and for some reason it > > doesn't monitor files under the integration folder. ?Does anyone know > > how to config autotest to monitor additional paths? ?I tried playing > > with add_mapping in my .autotest but was not able to get it to work. > > Take a look athttp://blog.davidchelimsky.net/2008/01/15/rspec-1-1-2-and-zentest-3-8-0/ > and see if that helps. > > > > > Thanks! > > > P.S. I know that using cucumber for integration testing is the best > > practice for RSpec. ?Just know that I have a good reason for not using > > it right now. > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From dbatshaw at gmail.com Sun Feb 21 18:25:50 2010 From: dbatshaw at gmail.com (drewB) Date: Sun, 21 Feb 2010 15:25:50 -0800 (PST) Subject: [rspec-users] undefined method `has' in integration test Message-ID: <6b294417-355e-4b66-afa2-ba0e61901bfe@k11g2000vbe.googlegroups.com> Whenever I use a matcher like response.should have_text in an integration test I receive the following error: undefined method `has' for # Any idea why that is and how to fix it? Thanks! From godfoca at gmail.com Sun Feb 21 18:30:36 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Sun, 21 Feb 2010 21:30:36 -0200 Subject: [rspec-users] undefined method `has' in integration test In-Reply-To: <6b294417-355e-4b66-afa2-ba0e61901bfe@k11g2000vbe.googlegroups.com> References: <6b294417-355e-4b66-afa2-ba0e61901bfe@k11g2000vbe.googlegroups.com> Message-ID: On Sun, Feb 21, 2010 at 9:25 PM, drewB wrote: > Whenever I use a matcher like response.should have_text in an > integration test I receive the following error: > > undefined method `has' for # 0x7fe07d184038> > > Any idea why that is and how to fix it? I think?not sure?those matchers are provided by webrat, so probably you're not requiring it? > Thanks! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Feb 21 18:50:19 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 21 Feb 2010 17:50:19 -0600 Subject: [rspec-users] undefined method `has' in integration test In-Reply-To: <6b294417-355e-4b66-afa2-ba0e61901bfe@k11g2000vbe.googlegroups.com> References: <6b294417-355e-4b66-afa2-ba0e61901bfe@k11g2000vbe.googlegroups.com> Message-ID: <57c63afe1002211550l75387571mfa1f0d214f42d8c4@mail.gmail.com> On Sun, Feb 21, 2010 at 5:25 PM, drewB wrote: > Whenever I use a matcher like response.should have_text in an > integration test I receive the following error: > > undefined method `has' for # 0x7fe07d184038> > > Any idea why that is and how to fix it? What versions of rails, rspec, and ruby are you using? Also, where is the file in question and how are you running it? From dbatshaw at gmail.com Sun Feb 21 19:23:55 2010 From: dbatshaw at gmail.com (drewB) Date: Sun, 21 Feb 2010 16:23:55 -0800 (PST) Subject: [rspec-users] undefined method `has' in integration test In-Reply-To: <57c63afe1002211550l75387571mfa1f0d214f42d8c4@mail.gmail.com> References: <6b294417-355e-4b66-afa2-ba0e61901bfe@k11g2000vbe.googlegroups.com> <57c63afe1002211550l75387571mfa1f0d214f42d8c4@mail.gmail.com> Message-ID: I require webrat in spec_helper (Spork.prefork). versions: rails 2.1.2 rspec 1.3.0 rspec-rails 1.3.2 ruby 1.8.7 The file is located at 'spec/integration/landing_page/ Ianding_page_spec.rb'. I am running 'spec spec/integration/ landing_page/landing_page_spec.rb' I am also using the rspec-integration plugin (http://github.com/ tricycle/rspec-integration). While investigating further, I found that removing the plugin causes other matchers to stop working (e.g. response.should be_success). I am guessing that no matchers are available by default when using rspec for integration testing (outside of cucumber) at least the way I have it set up. On Feb 21, 3:50?pm, David Chelimsky wrote: > On Sun, Feb 21, 2010 at 5:25 PM, drewB wrote: > > Whenever I use a matcher like response.should have_text in an > > integration test I receive the following error: > > > undefined method `has' for # > 0x7fe07d184038> > > > Any idea why that is and how to fix it? > > What versions of rails, rspec, and ruby are you using? Also, where is > the file in question and how are you running it? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From mailinglists at patmaddox.com Mon Feb 22 02:29:20 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Sun, 21 Feb 2010 23:29:20 -0800 Subject: [rspec-users] GET a path in a controller spec In-Reply-To: <88fd8ddc1002210252u317db09br1aa40bbf5bfc8743@mail.gmail.com> References: <88fd8ddc1002210252u317db09br1aa40bbf5bfc8743@mail.gmail.com> Message-ID: <0B99ACBD-D61E-4694-B19A-8B64CDA1E292@patmaddox.com> Extract redirect logic to an object or helper and test that. UrlRewriter.new.rewrite('/foods/search/almonds').should == '/almonds' helper.rewrite_url('/foods/search/almonds').should == '/almonds' and then you will see that this should probably be called higher up in the call stack, in a before_filter. Or even higher up, at your web server, nullifying the need for any ruby code in the first place. Cucumber works, too. "There's more than one way to kill a cat than by stuffing it with butter." Pat On Feb 21, 2010, at 2:52 AM, Andrew Premdas wrote: > > > On 31 January 2010 22:02, Nick Hoffman wrote: > One of my controller actions sends a redirect if the request URI begins > with /foods/search > > 34 def search > 35 return redirect_to "/#{params[:name]}" if > request.request_uri.match /^\/foods\/search/ > > Unfortunately, I can't figure out how to spec this. > > >From everything that I've read while researching this problem, it seems > that #get and #post only accept the action to call, and a hash of > parameters. IE: > get :action, :some => 'param' > As a result, I can't do this: > 121 it 'redirects /foods/search/almonds to /almonds' do > 122 get '/foods/search/almonds' > 123 response.should redirect_to "/almonds" > 124 end > > How can I spec this? > > Thanks for your help, > Nick > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > You might find this easier to do as an integration test. I'd use cucumber for this. Personally I think speccing controllers is pretty hard for the benefits it gives, and if you keep your controllers real simple and thin and use cucumber you can discard most controller specs. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From cernenus at gmail.com Mon Feb 22 12:29:28 2010 From: cernenus at gmail.com (Chuck van der Linden) Date: Mon, 22 Feb 2010 09:29:28 -0800 Subject: [rspec-users] Do you still Write Tests First on code that is churning hard? Message-ID: <9f9c63d61002220929v31ea3b43i643d0874671a02bf@mail.gmail.com> > > Date: Sun, 21 Feb 2010 10:37:14 +0000 > From: Andrew Premdas > To: rspec-users > Subject: Re: [rspec-users] Do you still Write Tests First on code that > is churning hard? > Message-ID: > <88fd8ddc1002210237m39085abbo6c43a7dc34130463 at mail.gmail.com> > Content-Type: text/plain; charset="iso-8859-1" > > On 19 February 2010 08:59, Erik Pukinskis wrote: > > > Hello Specmeisters! > > > > I have a bit of a philosophical question for the TDD witches and > > wizards out there. I'm working on some code that is really > > churning... It's doing complicated calculations, but the actual > > desired results are a moving target. The acceptable values, and even > > the structure of the software's output are changing constantly. The > > internal architecture is changing rapidly, and I'm constantly throwing > > away methods I no longer need. > > > > This has resulted in me no longer writing specs on this part of my > > codebase. They just become obsolete very very fast. Changing the > > specs constantly feels like a pointless doubling of my effort. Specs > > seem to help with debugging and verification that the software is > > performing as expected. But I'm spending most of my time trying to > > figure out what I should be expecting. I verify that things are > > working quickly and informally, because it's likely the definition of > > "working" will change before the week is up. > > > > Am I being stupid? Is it really a pointless doubling, or am I > > creating more debugging time for myself than I'm saving without > > writing specs? Should I be more religious about Test First? > > > > Thanks in advance for the insights, > > Erik > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > I think you can consider writing a completely separate spike to explore > your > subject, so long as you make absolutely certain that you do not merge it > into production code. To avoid that temptation it really should be > seperate. > Speculating a bit however, I think your process for developing this part of > your code maybe very wrong. It sounds like your looking for justification > for hacking - which generally is a bad sign - and that maybe you need to > take a step back and look at different approaches. Maybe instead of > focusing > on results you could focus on process e.g. to calculate foo I first need to > bar etc. or perhaps you need to go more granular and create some tools to > simplify your calculations. Finally if you have any long methods in your > calculations (> than 5 lines) refactor them. Decomposing them into smaller > methods could reveal alot about the structure of your problem > > HTH > > Andrew > I'm a bit with Andrew on this. I think you are not asking the right question. In TDD/BDD I view writing the tests/spec as PART of writing the code, so if you are questioning the value of spending the time to write the specs, and lamenting that you feel this is wasted effort, I have to ask why are you not questioning the value of even writing code when the target is changing so frequently? Why don't you feel that the code itself that you've had to discard/rewrite/refactor so much has not also been wasted effort? How is what you are doing going to deliver value to the end user? If this is a case where someone else can't make up their minds what they want, then potentially it might be a situation where writing the code itself is just a waste of time, much less writing the specs, and you need to spend your effort elsewhere until what is needed is better known. OTOH, if this is a situation where you are doing a lot of experimentation and discovery, and the writing of the code is necessary to figure out 'what will work', then the writing of tests might not add value and just being slowing you down. I'd base that judgement on the degree to which the code itself is considered disposable and the likelyhood that it won't ever make it into production 'as is'. In that case, then there may not be much value to fleshing out anything but the high level spec definitions (just as a means of keeping straight what you are trying to do this iteration, and potentially a type of documentation to others of what 'approach number 27' is supposed to take for inputs and produce for outputs. Kent Beck touches on this in his 'flight of the startup' blog post http://www.threeriversinstitute.org/blog/?p=251 and a followup 'developing for the flight of the startup' http://www.threeriversinstitute.org/blog/?p=252 and he makes some good points about when it pays to be dogmatic about some agile practices such as TDD, and when it's better to put some of those practices aside depending on what it is that you are trying to deliver to the customer at a particular point in the project. If you are currently in the phases Kent describes as Taxi and Takeoff, then you could very well be right to dispense with a majority of tests and other practices that are needed for maintainable high quality code. (because you're not trying to deliver highly maintainable code.) OTOH if you are in the Climb or Cruise stages, then I'd be greatly concerned that 'what we are building' is in such a constant state of flux, and I'd suggest something has a smell that's ungood. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattriches at gmail.com Mon Feb 22 13:54:02 2010 From: mattriches at gmail.com (Matt Riches) Date: Mon, 22 Feb 2010 18:54:02 +0000 Subject: [rspec-users] Best approach to spec'ing this Message-ID: <5d86970f1002221054j681e9ee8pe0ca9b24b00c9c3c@mail.gmail.com> I am hoping that this is an easy question to answer! I have 2 models, related via an association model, such that models a and b use has_many to refer to each other, and also the association. (Thats as simple as the code is) When I try to write a simple spec to access model 2 from model 1 I am getting a failure "uninitialized constant in Model1::Association Before I go back to this tomorrow, what is the best way of speccing models that are connected via associations. Should I be Mocking and stubbing the assosciation model and the child model, or requiring the actual models, and pulling some seed data in form the database? Thanks Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: From erdoss at gmail.com Mon Feb 22 14:35:52 2010 From: erdoss at gmail.com (Andrei Erdoss) Date: Mon, 22 Feb 2010 21:35:52 +0200 Subject: [rspec-users] Best approach to spec'ing this In-Reply-To: <5d86970f1002221054j681e9ee8pe0ca9b24b00c9c3c@mail.gmail.com> References: <5d86970f1002221054j681e9ee8pe0ca9b24b00c9c3c@mail.gmail.com> Message-ID: What I do is to mock and stub the associated models. The current model that I work on is called, usually using a Factory Girl. Hope this helps. On Mon, Feb 22, 2010 at 8:54 PM, Matt Riches wrote: > I am hoping that this is an easy question to answer! > > I have 2 models, related via an association model, such that models a and b > use has_many to refer to each other, and also the association. > > (Thats as simple as the code is) > > When I try to write a simple spec to access model 2 from model 1 I am > getting a failure "uninitialized constant in Model1::Association > > Before I go back to this tomorrow, what is the best way of speccing models > that are connected via associations. Should I be Mocking and stubbing the > assosciation model and the child model, or requiring the actual models, and > pulling some seed data in form the database? > > Thanks > > Matt > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Andrei Erdoss -------------- next part -------------- An HTML attachment was scrubbed... URL: From harmaarts at gmail.com Mon Feb 22 14:45:51 2010 From: harmaarts at gmail.com (Harm) Date: Mon, 22 Feb 2010 11:45:51 -0800 (PST) Subject: [rspec-users] Module instance variable remains set Message-ID: Hi, I have an issue with rSpec when spec'ing a module. The module in question looks like this: module Sheep def self.sound @sound ||= produce_sound() end end This module is used all around the application (and corresponding specs) and somehow values of @sound leak between each spec. The only way I found to fix it is to manually set the instance variable (with instance_variable_set) to nil. Obviously this is Bad. Is there a way to do this globally or better yet to prevent this? With kind regards, Harm From noreply at mail.goodreads.com Mon Feb 22 14:19:03 2010 From: noreply at mail.goodreads.com (Pat) Date: Mon, 22 Feb 2010 11:19:03 -0800 Subject: [rspec-users] Check out my shelves Message-ID: <4b82d8a7a076c_6cd515a5d795e9ac1382853d2@legolas.colo.tmail> Hi rspec, Check out the books I added on Goodreads. http://www.goodreads.com/friend/i?n=rspec users&e=rspec-users at rubyforge.org&i=LTM2MDQzNDk4OTE6MzY4 - Pat (pat.eyler at gmail.com) Goodreads is a community for book lovers. It's a great way to get book recommendations from your friends and others. You can keep a list of books to read, join book clubs, and even take the never-ending book trivia quiz. _____________________________ To opt-out of future invites to Goodreads please follow this link: http://www.goodreads.com/user/block_email?inviter_id=2749163 This email was sent by request to rspec-users at rubyforge.org. -------------- next part -------------- An HTML attachment was scrubbed... URL: From harmaarts at gmail.com Mon Feb 22 14:49:07 2010 From: harmaarts at gmail.com (Harm) Date: Mon, 22 Feb 2010 11:49:07 -0800 (PST) Subject: [rspec-users] Module instance variable remains set In-Reply-To: References: Message-ID: Addendum: I'm using rspec 1.3.0, rspec-rails 1.3.2 and ruby 1.9.1p129 On Feb 22, 8:45?pm, Harm wrote: > Hi, > > I have an issue with rSpec when spec'ing a module. The module in > question looks like this: > > module Sheep > ? def self.sound > ? ? @sound ||= produce_sound() > ? end > end > > This module is used all around the application (and corresponding > specs) and somehow values of @sound leak between each spec. The only > way I found to fix it is to manually set the instance variable (with > instance_variable_set) to nil. Obviously this is Bad. Is there a way > to do this globally or better yet to prevent this? > > With kind regards, > Harm > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From scott at railsnewbie.com Mon Feb 22 15:07:47 2010 From: scott at railsnewbie.com (Scott Taylor) Date: Mon, 22 Feb 2010 15:07:47 -0500 Subject: [rspec-users] Best approach to spec'ing this In-Reply-To: <5d86970f1002221054j681e9ee8pe0ca9b24b00c9c3c@mail.gmail.com> References: <5d86970f1002221054j681e9ee8pe0ca9b24b00c9c3c@mail.gmail.com> Message-ID: <11A54325-F368-4BC7-97C4-2DE62008ABDC@railsnewbie.com> On Feb 22, 2010, at 1:54 PM, Matt Riches wrote: > I am hoping that this is an easy question to answer! > > I have 2 models, related via an association model, such that models a and b use has_many to refer to each other, and also the association. has_many :through with an extra table, or HABTM? gist the relevant code. Best, Scott > > (Thats as simple as the code is) > > When I try to write a simple spec to access model 2 from model 1 I am getting a failure "uninitialized constant in Model1::Association > > Before I go back to this tomorrow, what is the best way of speccing models that are connected via associations. Should I be Mocking and stubbing the assosciation model and the child model, or requiring the actual models, and pulling some seed data in form the database? > > Thanks > > Matt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mattriches at gmail.com Mon Feb 22 16:04:04 2010 From: mattriches at gmail.com (Matt Riches) Date: Mon, 22 Feb 2010 21:04:04 +0000 Subject: [rspec-users] Best approach to spec'ing this In-Reply-To: <11A54325-F368-4BC7-97C4-2DE62008ABDC@railsnewbie.com> References: <5d86970f1002221054j681e9ee8pe0ca9b24b00c9c3c@mail.gmail.com> <11A54325-F368-4BC7-97C4-2DE62008ABDC@railsnewbie.com> Message-ID: <5d86970f1002221304h4f45da86ve223340a023b61@mail.gmail.com> > > > I am hoping that this is an easy question to answer! > > > > I have 2 models, related via an association model, such that models a and > b use has_many to refer to each other, and also the association. > > has_many :through with an extra table, or HABTM? > > Im home now and dont have the code in front of me, but it was using :through and the extra table, if that has any bearing? > gist the relevant code. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dbatshaw at gmail.com Mon Feb 22 16:24:54 2010 From: dbatshaw at gmail.com (drewB) Date: Mon, 22 Feb 2010 13:24:54 -0800 (PST) Subject: [rspec-users] undefined method `has' in integration test In-Reply-To: References: <6b294417-355e-4b66-afa2-ba0e61901bfe@k11g2000vbe.googlegroups.com> <57c63afe1002211550l75387571mfa1f0d214f42d8c4@mail.gmail.com> Message-ID: <600ec342-d2e6-46ee-86e2-a9b4c3ddcaeb@t42g2000vbt.googlegroups.com> Any thoughts on how to get the matchers included? On Feb 21, 4:23?pm, drewB wrote: > I require webrat in spec_helper (Spork.prefork). > > versions: > > rails 2.1.2 > rspec 1.3.0 > rspec-rails 1.3.2 > ruby 1.8.7 > > The file is located at 'spec/integration/landing_page/ > Ianding_page_spec.rb'. I am running 'spec spec/integration/ > landing_page/landing_page_spec.rb' > > I am also using the rspec-integration plugin (http://github.com/ > tricycle/rspec-integration). ?While investigating further, I found > that removing the plugin causes other matchers to stop working (e.g. > response.should be_success). ?I am guessing that no matchers are > available by default when using rspec for integration testing (outside > of cucumber) at least the way I have it set up. > > On Feb 21, 3:50?pm, David Chelimsky wrote:> On Sun, Feb 21, 2010 at 5:25 PM, drewB wrote: > > > Whenever I use a matcher like response.should have_text in an > > > integration test I receive the following error: > > > > undefined method `has' for # > > 0x7fe07d184038> > > > > Any idea why that is and how to fix it? > > > What versions of rails, rspec, and ruby are you using? Also, where is > > the file in question and how are you running it? > > _______________________________________________ > > 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 matt at mattwynne.net Mon Feb 22 17:10:51 2010 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 22 Feb 2010 22:10:51 +0000 Subject: [rspec-users] Module instance variable remains set In-Reply-To: References: Message-ID: On 22 Feb 2010, at 19:45, Harm wrote: > Hi, > > I have an issue with rSpec when spec'ing a module. The module in > question looks like this: > > module Sheep > def self.sound > @sound ||= produce_sound() > end > end > > This module is used all around the application (and corresponding > specs) and somehow values of @sound leak between each spec. The only > way I found to fix it is to manually set the instance variable (with > instance_variable_set) to nil. Obviously this is Bad. Is there a way > to do this globally or better yet to prevent this? By using class methods like this, you're always going to have leaky state. Here's one way to work around this: class Sheep class << self def reset! @instance = nil end private def method_missing(message, *args) instance.send(message, *args) end def instance @instance ||= new end end def sound @sound ||= produce_sound() end end Now you can call Sheep.reset! between examples, and you'll get a brand new Sheep instance each time. The old Sheep.sound API will still work fine. The added bonus is you can now spec the Sheep class properly too, without having to worry about leaky state there either. > > With kind regards, > Harm > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From rick.denatale at gmail.com Mon Feb 22 18:07:18 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 22 Feb 2010 18:07:18 -0500 Subject: [rspec-users] Of ActiveRecord, arel, and train wrecks Message-ID: I thought that it might be worth starting a discussion about the best approaches to deal with spec'ing what's becoming more and more common in apps using active record. It started with named scopes, now we have arel, and the old find calls with parameters are being deprecated. When I watched Ryan Bate's latest opus http://railscasts.com/episodes/202-active-record-queries-in-rails-3 this morning I decided it might be good to bring my concerns up. The problem of course is that we're going to get used to writing more code like this: Article.where("published_at <= ?", Time.now).includes(:comments) >From one aspect, I find all this very nice. It makes writing queries easier and much more readable. On the other hand these are the kind of "train wreck" violations of the "strong suggestion of Demeter" which makes mocking and stubbing difficult among other things. Thoughts? -- 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 scott at railsnewbie.com Mon Feb 22 18:16:26 2010 From: scott at railsnewbie.com (Scott Taylor) Date: Mon, 22 Feb 2010 18:16:26 -0500 Subject: [rspec-users] Of ActiveRecord, arel, and train wrecks In-Reply-To: References: Message-ID: <1F0A15C9-04AF-46C6-A583-D8163A156B47@railsnewbie.com> On Feb 22, 2010, at 6:07 PM, Rick DeNatale wrote: > I thought that it might be worth starting a discussion about the best > approaches to deal with spec'ing what's becoming more and more common > in apps using active record. > > It started with named scopes, now we have arel, and the old find calls > with parameters are being deprecated. > > When I watched Ryan Bate's latest opus > http://railscasts.com/episodes/202-active-record-queries-in-rails-3 > this morning I decided it might be good to bring my concerns up. > > The problem of course is that we're going to get used to writing more > code like this: > > Article.where("published_at <= ?", Time.now).includes(:comments) > >> From one aspect, I find all this very nice. It makes writing queries > easier and much more readable. > > On the other hand these are the kind of "train wreck" violations of > the "strong suggestion of Demeter" which makes mocking and stubbing > difficult among other things. > > Thoughts? I haven't spent enough time with it yet to know, but I suspect that surface mocking (what is usually called stubbing in this community) is going to get harder with the demeter violations. OTOH, I guess as there is more structure to a query, it might be easier to create a more general & dynamic mock library for it - something like lafcadio's mocking library or fakefs. With a mocking library like that out there, we'll have faster test suites. I'm hoping that it totally obliviates the need for a library like guillotine (http://github.com/smtlaissezfaire/guillotine). Scott > > -- > 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 rick.denatale at gmail.com Mon Feb 22 18:35:10 2010 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 22 Feb 2010 18:35:10 -0500 Subject: [rspec-users] Of ActiveRecord, arel, and train wrecks In-Reply-To: <1F0A15C9-04AF-46C6-A583-D8163A156B47@railsnewbie.com> References: <1F0A15C9-04AF-46C6-A583-D8163A156B47@railsnewbie.com> Message-ID: On Mon, Feb 22, 2010 at 6:16 PM, Scott Taylor wrote: > I haven't spent enough time with it yet to know, but I suspect that surface mocking (what is usually called stubbing in this community) is going to get harder with the demeter violations. > One of the things that I tend to do, is to not use chained scopes in controllers, but define model methods which use them, which allows for stubbing/mocking those methods, and keeps the train wrecks isolated. -- 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 mailinglists at patmaddox.com Mon Feb 22 18:40:31 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Mon, 22 Feb 2010 15:40:31 -0800 Subject: [rspec-users] Of ActiveRecord, arel, and train wrecks In-Reply-To: References: Message-ID: <5B84CE55-F655-4732-8C23-81607FCA4FB2@patmaddox.com> From a mocking / stubbing perspective, how is this different from Article.all(:conditions => ['published_at <= ?', Time.now], :include => :comments) ? i.e. in both cases wouldn't you do class Article def self.active_published all :conditions => ['published_at <= ?', Time.now], :include => :comments # where("published_at <= ?", Time.now).includes(:comments) end end and mock the call to Article.active_published instead? Pat On Feb 22, 2010, at 3:07 PM, Rick DeNatale wrote: > I thought that it might be worth starting a discussion about the best > approaches to deal with spec'ing what's becoming more and more common > in apps using active record. > > It started with named scopes, now we have arel, and the old find calls > with parameters are being deprecated. > > When I watched Ryan Bate's latest opus > http://railscasts.com/episodes/202-active-record-queries-in-rails-3 > this morning I decided it might be good to bring my concerns up. > > The problem of course is that we're going to get used to writing more > code like this: > > Article.where("published_at <= ?", Time.now).includes(:comments) > >> From one aspect, I find all this very nice. It makes writing queries > easier and much more readable. > > On the other hand these are the kind of "train wreck" violations of > the "strong suggestion of Demeter" which makes mocking and stubbing > difficult among other things. > > Thoughts? > > -- > 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 eydaimon at gmail.com Mon Feb 22 17:11:39 2010 From: eydaimon at gmail.com (anywho) Date: Mon, 22 Feb 2010 14:11:39 -0800 (PST) Subject: [rspec-users] Rails3 + RSpec2 sample project? In-Reply-To: <57c63afe1002071241h5901f932ia555e4202940c6bb@mail.gmail.com> References: <07fc69a2-0250-4714-923d-86dcb4bd55c0@b36g2000pri.googlegroups.com> <57c63afe1002071241o40259470x1e673602b2a4e5cc@mail.gmail.com> <57c63afe1002071241h5901f932ia555e4202940c6bb@mail.gmail.com> Message-ID: <6c949782-5635-423e-aaf2-705abf675190@t32g2000pre.googlegroups.com> I'm using this setup with rails 3/1.9.1 and this aforementioned gem. However, when running rake spec, I get this error: no such file to load -- test/unit/assertionfailederror seems 1.9.1 no longer has this file. I tested running it with commenting out this requirement and simply adding the below to the rake file, and everything runs fine then. Suggestions welcome on how to best approach this. Short of branching rspec, I'm not sure what to do here. The file with the offending code is: rspec/rails/matchers.rb module Test module Unit # Thrown by Test::Unit::Assertions when an assertion fails. class AssertionFailedError < StandardError end end end On Feb 7, 12:41?pm, David Chelimsky wrote: > On Sun, Feb 7, 2010 at 2:41 PM, David Chelimsky wrote: > > On Sun, Feb 7, 2010 at 3:48 AM, Jacques Crocker wrote: > >> If anyone has any sort of Rails3 + Rspec2 project sort of working, we > >> should get a stripped down sample project on github. Martin did a > >> great one for datamapper:http://github.com/snusnu/datamapper_on_rails3. > >> I can help getting it organized / tested, but I havent been able to > >> get things working quite yet. > > >> I know its all sort of still in flux at the moment. But any help would > >> be appreciated on how to organize rspec with rails3. > > > I don't have time to do a proper blog post right now, but I'll try to > > get something up in a day or two. In the mean time, assuming you have > > rails 3 pre already installed: > > > rails foo > > cd foo > > echo "gem 'rspec-rails', '>=2.0.0.a5' :group => :test" >> Gemfile > > This should be: > > ? echo "gem 'rspec-rails', '>=2.0.0.a5', :group => :test" >> Gemfile > > (was missing a comma). > > > script/rails generate rspec:install > > > rspec:install installs, among other things, a generator so you can just say: > > > ?script/rails generate model thing name:string > > > ... and you'll get a model spec instead of a rails unit test. > > > The a5 release only supports model and request (integration - a la > > merb) specs, but controllers, views and helpers will be coming soon. > > > Cheers, > > David > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From jseidel at edpci.net Tue Feb 23 06:41:52 2010 From: jseidel at edpci.net (Jon Seidel CMC) Date: Tue, 23 Feb 2010 03:41:52 -0800 Subject: [rspec-users] [BDD] Problems on rspec.info site Message-ID: Hi... I've been studying rspec and found some problems on the rspec.info site: 1. Bad link. On page http://rspec.info/rails/writing/views.html, the link to "Spec::Rails::Expectations" (http://rspec.info/rdoc-rails/index.html) gets a 404 error. 2. Bad core team links. On the community page (http://rspec.info/community/), there are several link errors. Steven Baker (Server not found), Aslak Hellesoy (Bad gateway), Pat Maddox (Server not found). 3. I couldn't find any way to submit errors/comments on the site. The community page suggests that you "...contact the RSpec team." but has no links/directions on how to accomplish this. 4. There's no search feature 5. The hypertext links are so subtle (no underlining, no color) as to be invisible. HTH...jon Jon Seidel, CMC? EDP Consulting, Inc. / www.edpci.com / www.4MyPasswords.com Technology that means Business - Since 1979 3373 Guido Street Oakland, CA 94602 phone: 510-530-6314 fax: 510-531-1522 The Certified Management Consultant (CMC) mark is awarded to consultants who meet the strict standards defined by the Institute of Management Consultants USA, including examination by their peers, client evaluations, and a written examination evidencing their understanding of the IMC USA's Code of Ethics. Check out IMC USA for more information. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Feb 23 09:24:33 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 23 Feb 2010 08:24:33 -0600 Subject: [rspec-users] [BDD] Problems on rspec.info site In-Reply-To: References: Message-ID: <57c63afe1002230624v2b2fb7a0xa9fe0148ea32a6f7@mail.gmail.com> On Tue, Feb 23, 2010 at 5:41 AM, Jon Seidel CMC wrote: > Hi... I've been studying rspec and found some problems on the rspec.info > site: > > 1. Bad link. On page http://rspec.info/rails/writing/views.html, the link to > "Spec::Rails::Expectations" (http://rspec.info/rdoc-rails/index.html) gets a > 404 error. > > 2. Bad core team links. On the community page > (http://rspec.info/community/), there are several link errors. Steven Baker > (Server not found), Aslak Hellesoy (Bad gateway), Pat Maddox (Server not > found). Thanks - I've fixed all these bad links. I'll address the other issues later. > 3. I couldn't find any way to submit errors/comments on the site. The > community page suggests that you "...contact the RSpec team." but has no > links/directions on how to accomplish this. > > 4. There's no search feature > > 5. The hypertext links are so subtle (no underlining, no color) as to be > invisible. > > HTH...jon > > Jon Seidel, CMC? > EDP Consulting, Inc. / www.edpci.com / www.4MyPasswords.com > Technology that means Business - Since 1979 > 3373 Guido Street > Oakland, CA 94602 > phone: 510-530-6314 > fax: 510-531-1522 > > The Certified Management Consultant (CMC) mark is awarded to consultants who > meet the strict standards defined by the Institute of Management Consultants > USA, including examination by their peers, client evaluations, and a written > examination evidencing their understanding of the IMC USA's Code of Ethics. > > Check out IMC USA for more information. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From scott at railsnewbie.com Tue Feb 23 12:30:02 2010 From: scott at railsnewbie.com (Scott Taylor) Date: Tue, 23 Feb 2010 12:30:02 -0500 Subject: [rspec-users] Shared Helpers Message-ID: Has there been any development on shared helpers / it_should_behave_like feature in rspec? I forget the reasons, but I remember a patch for something like this was rejected: it_should_behave_like "an_entry", :locals => { :entry => Entry.new } OR: before do @entry = Entry.new end it_should_behave_like "an_entry", :locals => lambda { { :entry => @entry } } Is there any code which now deals with the variable passing issue in rspec? Best, Scott From matt at mattwynne.net Tue Feb 23 12:41:10 2010 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 23 Feb 2010 17:41:10 +0000 Subject: [rspec-users] Shared Helpers In-Reply-To: References: Message-ID: <30318B30-F687-42DE-872B-9A07E6BD37DC@mattwynne.net> On 23 Feb 2010, at 17:30, Scott Taylor wrote: > > Has there been any development on shared helpers / > it_should_behave_like feature in rspec? > > I forget the reasons, but I remember a patch for something like this > was rejected: > > it_should_behave_like "an_entry", :locals => { :entry => > Entry.new } > > OR: > > before do > @entry = Entry.new > end > > it_should_behave_like "an_entry", :locals => lambda { > { > :entry => @entry > } > } > > Is there any code which now deals with the variable passing issue in > rspec? > > Best, > > Scott FWIW, what I've done in this situation is expect that the ExampleGroup I've mixed the shared behaviour into to define a method, and call that from the shared examples - if it's not defined you'll find out pretty quickly. Another approach is to just expect the @variable to be set: describe "an entry" do before @entry or raise("You need to set @entry to use this shared example group") end end It's not great, but it makes the shared example group a little more self-documenting than if you just shared the instance variable without the check. cheers, Matt http://mattwynne.net +447974 430184 From ohthepete at gmail.com Tue Feb 23 13:18:34 2010 From: ohthepete at gmail.com (Pete Hodgson) Date: Tue, 23 Feb 2010 10:18:34 -0800 Subject: [rspec-users] Applying an rspec matcher against the elements of a collection Message-ID: <8a99cf8f1002231018n42f00ce9w9d271d704ba6b386@mail.gmail.com> Hi all, I've tried to figure out whether rspec has any features to make it easier to make assertions against the elements of a collection, but I haven't had any luck finding anything so far. I thought I'd explain the problem here, and propose a potential feature that might mitigate it. Let's say I have a Person class: class Person < Struct.new( :name, :age ) VOTING_AGE = 18 def self.get_voters( people ) people.reject{ |person| person.age < VOTING_AGE } end end As you can see we have a method here which filters a collection of people, returning only those people old enough to vote. If I were to test this method in rspec I might write: describe 'Person vote filtering' do it 'filters out people younger than voting age' do people = [ Person.new( 'jenny', 18 ), Person.new( 'dave', 12 ), Person.new( 'paul', 19 ), Person.new( 'lisa', 17 ) ] voters = Person.get_voters( people ) voter_names = voters.map{ |p| p.name } voter_names.should == ['jenny','paul'] end end This works, but having to manually pull out the voter names into a seperate collection just in order to check who was filtered and who wasn't has always seemed clunky to me. What I would prefer is to be able to check whether the collection contains person who matching my expectations. Say I have a custom matcher: Spec::Matchers.define :be_named do |expected| match do |actual| actual.name == expected end end Then I'd like to be able to write something like voters.should( have(2).people ) voters.should( have_one_that( be_named('jenny') ) ) voters.should( have_one_that( be_named('paul') ) ) or even: voters.should( have_elements_that( be_named( 'jenny' ), be_named( 'paul' ) ) To me this is a lot clearer - although the method names and how they're composed into the DSL could clearly use some work ;). Now, for the trivial case I've been using as an example it would probably be overkill, but I often find myself writing fairly convuluted code at the end of a test just to figure out whether a collection contains an element that matches some complex predicate. It seems to me that if rspec had the generic ability to apply matchers to the elements of a collection it would raise the level of expressiveness for this kind of tests. Thoughts? Does Rspec already support something like this that I'm just not aware of? If I were to write a patch implementing this would it have any chance of being accepted? Cheers, Pete From mailinglists at patmaddox.com Tue Feb 23 13:34:35 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Tue, 23 Feb 2010 10:34:35 -0800 Subject: [rspec-users] Shared Helpers In-Reply-To: References: Message-ID: <2760EABA-EF4F-470E-A836-5E355BC7DEA2@patmaddox.com> I just use a factory method. describe 'Authorize.net CIM gateway', :shared => true do describe 'saving a card' do describe 'preconditions' do it "should raise an error if the card is not saved" do lambda { gateway.save_credit_card(Factory.build(:credit_card, :user => Factory(:user))) }.should raise_error(ArgumentError, /unsaved record/) end end describe 'first card saved on an account' do it "should set the authorize_id on the credit card" do credit_card = Factory :credit_card, :user => Factory(:user) gateway.save_credit_card credit_card credit_card.authorize_id.should be_present end it "should return true for a successful response" do credit_card = Factory :credit_card, :user => Factory(:user) gateway.save_credit_card(credit_card).should be_true end it "should mark the card as having a validated card code" do card = Factory :credit_card, :card_code_validated => false gateway.save_credit_card card card.should be_card_code_validated end end # etc etc etc etc end end describe Payment::AuthorizeNetCim::FakeGateway do def gateway @gateway ||= Payment::AuthorizeNetCim::FakeGateway.new end it_should_behave_like 'Authorize.net CIM gateway' # some extra custom examples end I prefer this to requiring an instance variable, because you get built in error-handling for free. If you don't implement the factory method, you get "undefined method: gateway" rather than the less obvious undefined method on NilClass error. Also, your :locals => { :entry => Entry.new } syntax is going to be no good because you'll only have one instance of Entry that gets reused across examples. No bueno. You'd have to do :locals => lambda { { :entry => Entry.new } } and now it's just getting ugly. If you think defining methods is too heavy (which I wouldn't agree with, but okay) then maybe use the let method? describe Entry do before do let(:entry) { Entry.new ) end it_should_behave_like "an_entry" end How's that look? Pat On Feb 23, 2010, at 9:30 AM, Scott Taylor wrote: > > Has there been any development on shared helpers / it_should_behave_like feature in rspec? > > I forget the reasons, but I remember a patch for something like this was rejected: > > it_should_behave_like "an_entry", :locals => { :entry => Entry.new } > > OR: > > before do > @entry = Entry.new > end > > it_should_behave_like "an_entry", :locals => lambda { > { > :entry => @entry > } > } > > Is there any code which now deals with the variable passing issue in rspec? > > Best, > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From godfoca at gmail.com Tue Feb 23 13:49:54 2010 From: godfoca at gmail.com (=?ISO-8859-1?Q?Nicol=E1s_Sanguinetti?=) Date: Tue, 23 Feb 2010 16:49:54 -0200 Subject: [rspec-users] Shared Helpers In-Reply-To: <30318B30-F687-42DE-872B-9A07E6BD37DC@mattwynne.net> References: <30318B30-F687-42DE-872B-9A07E6BD37DC@mattwynne.net> Message-ID: On Tue, Feb 23, 2010 at 3:41 PM, Matt Wynne wrote: > > On 23 Feb 2010, at 17:30, Scott Taylor wrote: > >> >> Has there been any development on shared helpers / it_should_behave_like >> feature in rspec? >> >> I forget the reasons, but I remember a patch for something like this was >> rejected: >> >> ? it_should_behave_like "an_entry", :locals => { :entry => Entry.new } >> >> OR: >> >> ? before do >> ? ? @entry = Entry.new >> ? end >> >> ? it_should_behave_like "an_entry", :locals => lambda { >> ? ? { >> ? ? ? :entry => @entry >> ? ? } >> ? } >> >> Is there any code which now deals with the variable passing issue in >> rspec? >> >> Best, >> >> Scott > > FWIW, what I've done in this situation is expect that the ExampleGroup I've > mixed the shared behaviour into to define a method, and call that from the > shared examples - if it's not defined you'll find out pretty quickly. > Another approach is to just expect the @variable to be set: > > ?describe "an entry" do > ? ?before > ? ? ?@entry or raise("You need to set @entry to use this shared example > group") > ? ?end > ?end > > It's not great, but it makes the shared example group a little more > self-documenting than if you just shared the instance variable without the > check. > > cheers, > Matt We do what Matt does, plus we document on top of the shared examples the interface the example group needs: # You need to provide an method that returns a record without # saving, in an invalid state, for this mixin to work. shared_examples_for "a model that can disable validations" do context "when checking for a record's validity" do it "always returns true if you disabled validations" do described_class.disable_validations! invalid_record.should be_valid end it "falls back to the usual behavior if you enable validations" do described_class.enable_validations! invalid_record.should_not be_valid end end ... end describe User do let :invalid_record do User.make_unsaved(:invalid) end it_should_behave_like "a model that can disable validations" end Cheers, -foca > http://mattwynne.net > +447974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From rlwinter at gmail.com Tue Feb 23 14:11:06 2010 From: rlwinter at gmail.com (rlw) Date: Tue, 23 Feb 2010 11:11:06 -0800 (PST) Subject: [rspec-users] Is there a way to terminate a long running spec job... Message-ID: and still get the output of accumulated errors? My environment is awful, slow, and not modifiable. (Just don't go there! At least I get to program in Ruby, which makes up for everything else.) So when I see some errors in a 300 example test file, it takes a long time (many minutes) for the file to finish out and give me some meaningful output to start debugging. Is there a way to send a signal to the rspec process and have it terminate and printout the accumulated errors up to that point? TIA, -Robert From matt at mattwynne.net Tue Feb 23 14:53:07 2010 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 23 Feb 2010 19:53:07 +0000 Subject: [rspec-users] Is there a way to terminate a long running spec job... In-Reply-To: References: Message-ID: <246DFC73-B776-4CFD-80C5-496C112A7D51@mattwynne.net> On 23 Feb 2010, at 19:11, rlw wrote: > and still get the output of accumulated errors? > > My environment is awful, slow, and not modifiable. (Just don't go > there! At least I get to program in Ruby, which makes up for > everything else.) So when I see some errors in a 300 example test > file, it takes a long time (many minutes) for the file to finish out > and give me some meaningful output to start debugging. Is there a way > to send a signal to the rspec process and have it terminate and > printout the accumulated errors up to that point? > > TIA, > -Robert Why don't you fiddle with the formatters to output the failures into another file, and then just tail that file for your meaningful output? cheers, Matt http://mattwynne.net +447974 430184 From rlwinter at gmail.com Tue Feb 23 16:39:59 2010 From: rlwinter at gmail.com (rlw) Date: Tue, 23 Feb 2010 13:39:59 -0800 (PST) Subject: [rspec-users] Is there a way to terminate a long running spec job... In-Reply-To: <246DFC73-B776-4CFD-80C5-496C112A7D51@mattwynne.net> References: <246DFC73-B776-4CFD-80C5-496C112A7D51@mattwynne.net> Message-ID: <8a4bdf9d-4bca-4050-aec6-f2d4ce23713d@y33g2000yqb.googlegroups.com> This sounds relatively straightforward - I didn't know it was a possibility to dump the errors out as things were running. Anyone have sample code? TIA, -Robert On Feb 23, 2:53?pm, Matt Wynne wrote: > Why don't you fiddle with the formatters to output the failures into ? > another file, and then just tail that file for your meaningful output? > > cheers, > Matt > > http://mattwynne.net > +447974 430184 > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From mailinglists at patmaddox.com Tue Feb 23 16:43:02 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Tue, 23 Feb 2010 13:43:02 -0800 Subject: [rspec-users] Applying an rspec matcher against the elements of a collection In-Reply-To: <8a99cf8f1002231018n42f00ce9w9d271d704ba6b386@mail.gmail.com> References: <8a99cf8f1002231018n42f00ce9w9d271d704ba6b386@mail.gmail.com> Message-ID: <74CA84BB-9BBE-49C9-9FB9-0F4DA4ABD827@patmaddox.com> I'm going to argue that your design is off, and then ignore the rest of your post :) class Person < Struct.new(:name, :age) VOTING_AGE = 18 def voter? age >= VOTING_AGE end end Now your tests become very simple: Person.new('Jenny', 17).should_not be_voter Person.new('Bob', 18).should be_voter Why you want a Person.get_voters method to select voters from a list, I'm not really sure. You can always just do: voters = collection_of_people.select {|p| p.voter?} Also, RSpec has two mechanisms for testing collections the way you want (so I guess I'm not ignoring your post after all). If you only care about inclusion, you can use the include matcher: jenny = Person.new('Jenny', 17) bob = Person.new('Bob', 18) sally = Person.new('Sally', 20) voters = Person.get_voters(jenny, bob, sally) voters.should include(bob, sally) voters.should_not include(jenny) there is also the set equality matcher, which checks that the contents of two collections are equal irrespective of order: voters.should =~ [bob, sally] Pat On Feb 23, 2010, at 10:18 AM, Pete Hodgson wrote: > Hi all, > I've tried to figure out whether rspec has any features to make it > easier to make assertions against the elements of a collection, but I > haven't had any luck finding anything so far. I thought I'd explain > the problem here, and propose a potential feature that might mitigate > it. > > Let's say I have a Person class: > > class Person < Struct.new( :name, :age ) > > VOTING_AGE = 18 > def self.get_voters( people ) > people.reject{ |person| person.age < VOTING_AGE } > end > > end > > As you can see we have a method here which filters a collection of > people, returning only those people old enough to vote. If I were to > test this method in rspec I might write: > > describe 'Person vote filtering' do > it 'filters out people younger than voting age' do > people = [ > Person.new( 'jenny', 18 ), > Person.new( 'dave', 12 ), > Person.new( 'paul', 19 ), > Person.new( 'lisa', 17 ) > ] > > voters = Person.get_voters( people ) > > voter_names = voters.map{ |p| p.name } > voter_names.should == ['jenny','paul'] > end > end > > This works, but having to manually pull out the voter names into a > seperate collection just in order to check who was filtered and who > wasn't has always seemed clunky to me. What I would prefer is to be > able to check whether the collection contains person who matching my > expectations. Say I have a custom matcher: > > Spec::Matchers.define :be_named do |expected| > match do |actual| > actual.name == expected > end > end > > Then I'd like to be able to write something like > > voters.should( have(2).people ) > voters.should( have_one_that( be_named('jenny') ) ) > voters.should( have_one_that( be_named('paul') ) ) > > or even: > > voters.should( have_elements_that( > be_named( 'jenny' ), > be_named( 'paul' ) > ) > > To me this is a lot clearer - although the method names and how > they're composed into the DSL could clearly use some work ;). > > Now, for the trivial case I've been using as an example it would > probably be overkill, but I often find myself writing fairly > convuluted code at the end of a test just to figure out whether a > collection contains an element that matches some complex predicate. It > seems to me that if rspec had the generic ability to apply matchers to > the elements of a collection it would raise the level of > expressiveness for this kind of tests. > > Thoughts? Does Rspec already support something like this that I'm just > not aware of? If I were to write a patch implementing this would it > have any chance of being accepted? > > Cheers, > Pete > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ohthepete at gmail.com Tue Feb 23 17:53:20 2010 From: ohthepete at gmail.com (Pete Hodgson) Date: Tue, 23 Feb 2010 14:53:20 -0800 (PST) Subject: [rspec-users] Applying an rspec matcher against the elements of a collection In-Reply-To: <74CA84BB-9BBE-49C9-9FB9-0F4DA4ABD827@patmaddox.com> References: <8a99cf8f1002231018n42f00ce9w9d271d704ba6b386@mail.gmail.com> <74CA84BB-9BBE-49C9-9FB9-0F4DA4ABD827@patmaddox.com> Message-ID: Pat, Thanks for the response. On Feb 23, 1:43?pm, Pat Maddox wrote: > I'm going to argue that your design is off, and then ignore the rest of your post :) Fair enough :) The 'design' in my example was made up on the spot to try and illustrate the kind of issues I've been coming up against without lots of irrelevant detail. I agree that the code has all sorts of silly issues. > > Also, RSpec has two mechanisms for testing collections the way you want (so I guess I'm not ignoring your post after all). > Thanks for pointing me towards the include and =~ matchers. This was part of what I was looking for, and would solve a lot of the issues I've hit in the past. That said, I still feel that it would be helpful to have some way of applying a matcher against the elements of a collection. I will just have to come up with a more plausible example... :) Cheers, Pete From mguterl at gmail.com Tue Feb 23 20:26:57 2010 From: mguterl at gmail.com (Michael Guterl) Date: Tue, 23 Feb 2010 20:26:57 -0500 Subject: [rspec-users] Applying an rspec matcher against the elements of a collection In-Reply-To: <74CA84BB-9BBE-49C9-9FB9-0F4DA4ABD827@patmaddox.com> References: <8a99cf8f1002231018n42f00ce9w9d271d704ba6b386@mail.gmail.com> <74CA84BB-9BBE-49C9-9FB9-0F4DA4ABD827@patmaddox.com> Message-ID: <944a03771002231726v106f8588h1131ce58a4987fb5@mail.gmail.com> On Tue, Feb 23, 2010 at 4:43 PM, Pat Maddox wrote: > > there is also the set equality matcher, which checks that the contents of two collections are equal irrespective of order: > > voters.should =~ [bob, sally] > I can't believe I didn't know =~ could be used for comparing collections regardless of order, this is awesome! Thanks, Michael Guterl From grafton at gmail.com Wed Feb 24 00:19:30 2010 From: grafton at gmail.com (Mike Grafton) Date: Tue, 23 Feb 2010 21:19:30 -0800 Subject: [rspec-users] Testing code that integrates with Rspec Message-ID: Hey all, I've been using Rspec for a while now, but this is the first time I've run up against the following problem: how do you use Rspec to test code that uses Rspec? Basically my code takes as input a representation of example groups, and it should dynamically create those example groups and then run them. I borrowed this code from a open-source project that doesn't appear to have tests for it; the code works, but I'd like to get it under test so I can improve it. Going through the Rspec code (v 1.3.0), it appears that this should be possible. There's Spec::Runner::Options, which looks to be a decent entry point for kicking off an Rspec run (with #run_examples). It has something attached to it called a Reporter, which looks like an observer that, if I could mock it, I could sense exactly what my run of Rspec did. Unfortunately, when I wrote a spec to invoke this code, both the code under test and the spec itself seemed to talk to the same Reporter (the one that got created first, for the the spec). So my spec and my code are entangled. Any suggestions? Here's a gist with a stripped down version of my code and a description of what output it produced. I can work on this gist to make it actually runnable if anybody is interested. Thanks a bunch, Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: From diwakar at angleritech.com Wed Feb 24 01:54:19 2010 From: diwakar at angleritech.com (Diwakar, ANGLER - EIT) Date: Wed, 24 Feb 2010 12:24:19 +0530 Subject: [rspec-users] where can I find a discusion happened earlier Message-ID: <16F1D498F4CD4545BB3C49972B5082716DE838@itech.angleritech.com> I need a look on a definition given for rspec and cucumber earlier by a member in rspec group. Where can I find it Regards, Diwakar -------------- next part -------------- An HTML attachment was scrubbed... URL: From grafton at gmail.com Wed Feb 24 02:07:15 2010 From: grafton at gmail.com (Mike Grafton) Date: Tue, 23 Feb 2010 23:07:15 -0800 (PST) Subject: [rspec-users] Testing code that integrates with Rspec In-Reply-To: References: Message-ID: Oops, forgot the gist: http://gist.github.com/312383 Thanks, Mike On Feb 23, 9:19?pm, Mike Grafton wrote: > Hey all, > > I've been using Rspec for a while now, but this is the first time I've run > up against the following problem: how do you use Rspec to test code that > uses Rspec? > > Basically my code takes as input a representation of example groups, and it > should dynamically create those example groups and then run them. I borrowed > this code from a open-source project that doesn't appear to have tests for > it; the code works, but I'd like to get it under test so I can improve it. > > Going through the Rspec code (v 1.3.0), it appears that this should be > possible. ?There's Spec::Runner::Options, which looks to be a decent entry > point for kicking off an Rspec run (with #run_examples). It has something > attached to it called a Reporter, which looks like an observer that, if I > could mock it, I could sense exactly what my run of Rspec did. > > Unfortunately, when I wrote a spec to invoke this code, both the code under > test and the spec itself seemed to talk to the same Reporter (the one that > got created first, for the the spec). So my spec and my code are entangled. > > Any suggestions? > > Here's a gist with a stripped down version of my code and a description of > what output it produced. I can work on this gist to make it actually > runnable if anybody is interested. > > Thanks a bunch, > Mike > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Wed Feb 24 03:39:06 2010 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 24 Feb 2010 08:39:06 +0000 Subject: [rspec-users] where can I find a discusion happened earlier In-Reply-To: <16F1D498F4CD4545BB3C49972B5082716DE838@itech.angleritech.com> References: <16F1D498F4CD4545BB3C49972B5082716DE838@itech.angleritech.com> Message-ID: http://groups.google.com/group/rspec On 24 Feb 2010, at 06:54, Diwakar, ANGLER - EIT wrote: > I need a look on a definition given for rspec and cucumber earlier > by a member in rspec group. Where can I find it > > Regards, > Diwakar > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From david.mh.tong at gmail.com Wed Feb 24 03:23:01 2010 From: david.mh.tong at gmail.com (Dave) Date: Wed, 24 Feb 2010 00:23:01 -0800 (PST) Subject: [rspec-users] Rspec + Shoulda + FactoryGirl = undefined method `reflect_on_association' Message-ID: I have Rspec + Shoulda + FactoryGirl and I am receiving the following error when attempting to call Shoulda's have_many or belong_to methods. All Shoulda methods used in the "validations" group work fine: > NoMethodError in 'A Project > associations should When you call a > matcher in an example without a > String, like this: > > specify { object.should matcher } > > or this: > > it { should matcher } > > RSpec expects the matcher to have a > #description method. You should either add a String to the example this > matcher is being used in, or give it a > description method. Then you won't > have to suffer this lengthy warning > again. ' undefined method > `reflect_on_association' for > # /vendor/plugins/active_matchers/lib/ matchers/association_matcher.rb:37:in > `confirm_association' > /vendor/plugins/active_matchers/lib/matchers/ association_matcher.rb:36:in > `each' > /vendor/plugins/active_matchers/lib/matchers/ association_matcher.rb:36:in > `confirm_association' > /vendor/plugins/active_matchers/lib/matchers/ association_matcher.rb:11:in > `matches?' > ./spec/models/project_spec.rb:7: Thanks in advance spec/spec_helper.rb ================================================================== require 'shoulda' spec/models/project_spec.rb ================================================================== require File.dirname(__FILE__) + '/../spec_helper' describe "A Project" do describe "associations" do subject { Factory(:project) } it { should have_many(:tasks) } it { should belong_to(:project_status) } end describe "validations" do subject { Factory(:project) } it { should validate_presence_of(:name) } it { should validate_uniqueness_of(:name).case_insensitive } it { should allow_mass_assignment_of(:name) } end end From dchelimsky at gmail.com Wed Feb 24 09:15:07 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 24 Feb 2010 08:15:07 -0600 Subject: [rspec-users] Rspec + Shoulda + FactoryGirl = undefined method `reflect_on_association' In-Reply-To: References: Message-ID: <57c63afe1002240615u747dc225r4f0a315ca496920e@mail.gmail.com> On Wed, Feb 24, 2010 at 2:23 AM, Dave wrote: > I have Rspec + Shoulda + FactoryGirl and I am receiving the following > error when attempting to call Shoulda's have_many or belong_to > methods. All Shoulda methods used in the "validations" group work > fine: > > ? ?> ? NoMethodError in 'A Project > ? ?> associations should When you call a > ? ?> matcher in an example without a > ? ?> String, like this: > ? ?> > ? ?> ? specify { object.should matcher } > ? ?> > ? ?> ? or this: > ? ?> > ? ?> ? it { should matcher } > ? ?> > ? ?> ? RSpec expects the matcher to have a > ? ?> #description method. You should either ? add a String to the > example this > ? ?> matcher is being used in, or give it a > ? ?> description method. Then you won't > ? ?> have to suffer this lengthy warning > ? ?> again. ? ' ? undefined method > ? ?> `reflect_on_association' for > ? ?> # ? /vendor/plugins/active_matchers/lib/ > matchers/association_matcher.rb:37:in What's active_matchers? I don't think that's part of rspec, shoulda, or factory_girl. > ? ?> `confirm_association' > ? ?> /vendor/plugins/active_matchers/lib/matchers/ > association_matcher.rb:36:in > ? ?> `each' > ? ?> /vendor/plugins/active_matchers/lib/matchers/ > association_matcher.rb:36:in > ? ?> `confirm_association' > ? ?> /vendor/plugins/active_matchers/lib/matchers/ > association_matcher.rb:11:in > ? ?> `matches?' > ? ?> ./spec/models/project_spec.rb:7: > > Thanks in advance > > spec/spec_helper.rb > ================================================================== > > ? ?require 'shoulda' > > spec/models/project_spec.rb > ================================================================== > > ? ?require File.dirname(__FILE__) + '/../spec_helper' > > ? ?describe "A Project" do > ? ? ?describe "associations" do > > ? ? ? ?subject { Factory(:project) } > > ? ? ? ?it { should have_many(:tasks) } > ? ? ? ?it { should belong_to(:project_status) } > ? ? ?end > > ? ? ?describe "validations" do > ? ? ? ?subject { Factory(:project) } > > ? ? ? ?it { should validate_presence_of(:name) } > > ? ? ? ?it { should validate_uniqueness_of(:name).case_insensitive } > > ? ? ? ?it { should allow_mass_assignment_of(:name) } > ? ? ?end > ? ?end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailinglists at patmaddox.com Wed Feb 24 10:51:53 2010 From: mailinglists at patmaddox.com (Pat Maddox) Date: Wed, 24 Feb 2010 07:51:53 -0800 Subject: [rspec-users] Applying an rspec matcher against the elements of a collection In-Reply-To: References: <8a99cf8f1002231018n42f00ce9w9d271d704ba6b386@mail.gmail.com> <74CA84BB-9BBE-49C9-9FB9-0F4DA4ABD827@patmaddox.com> Message-ID: <225758D2-84D6-4653-887E-B60603A11B71@patmaddox.com> I missed one other one that you'll find handy. voters.should have(2).items Take a look at http://rspec.rubyforge.org/rspec/1.3.0/classes/Spec/Matchers.html because there's a lot of useful stuff... On Feb 23, 2010, at 2:53 PM, Pete Hodgson wrote: > Pat, Thanks for the response. > > On Feb 23, 1:43 pm, Pat Maddox wrote: >> I'm going to argue that your design is off, and then ignore the rest of your post :) > > Fair enough :) The 'design' in my example was made up on the spot to > try and illustrate the kind of issues I've been coming up against > without lots of irrelevant detail. I agree that the code has all sorts > of silly issues. > >> >> Also, RSpec has two mechanisms for testing collections the way you want (so I guess I'm not ignoring your post after all). >> > > Thanks for pointing me towards the include and =~ matchers. This was > part of what I was looking for, and would solve a lot of the issues > I've hit in the past. > > That said, I still feel that it would be helpful to have some way of > applying a matcher against the elements of a collection. I will just > have to come up with a more plausible example... :) > > Cheers, > Pete > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From marcus at ahnve.com Wed Feb 24 10:51:46 2010 From: marcus at ahnve.com (Marcus Ahnve) Date: Wed, 24 Feb 2010 16:51:46 +0100 Subject: [rspec-users] Problem running spec command for directory In-Reply-To: <57c63afe1002211314h1d4796e4gd7ae9926be46e9a2@mail.gmail.com> References: <4d4e79cc1002211257x38cc452w8206354f53cf7061@mail.gmail.com> <57c63afe1002211314h1d4796e4gd7ae9926be46e9a2@mail.gmail.com> Message-ID: <20100224155146.GG24476@spacelab.se.valtech.com> On Sun, Feb 21, 2010 at 03:14:10PM -0600, David Chelimsky wrote: > On Sun, Feb 21, 2010 at 2:57 PM, Marcus Ahnve wrote: > > Hi, > > > > I have a problem running the spec command in Rspec 1.3.0 with a > > directory as parameter. > > > > A spec for a MongoMapper document that works when run directly such as > > > > $ spec spec/model/attendant_spec.rb > > > > works fine. But the very same spec run glob-style: > > > > $ spec spec > > > > fails with MongoMapper validations seemingly added twice - full output > > at http://pastie.org/835775. > > > > According to the stack trace files seems to be required in the same > > order as when run individually, but clearly something else is messed > > up. > > > > Is there something one should know about when running specs by glob? > > > > Thanks for any help /Marcus > > Looks like there are a bunch of relative paths in the stack trace - like this: > > from /home/mahnve/src/agilasverige/app/agilasverige/spec/model/../spec_helper.rb > > This means that files may be reloaded depending on where they're ref'd from. > > Rspec adds ./lib and ./spec to the $LOAD_PATH, so you should be able > to require things directly. For example: > > require "spec_helper" > > ... will require ./spec/spec_helper.rb. > > HTH, > David It was indeed a relative path that was the culprit. Thanks for the help. Cheers /Marcus -- Marcus Ahnve http://marcus.ahnve.net phone: +46 8 56 22 33 94 twitter: mahnve From david.mh.tong at gmail.com Thu Feb 25 07:52:58 2010 From: david.mh.tong at gmail.com (Dave) Date: Thu, 25 Feb 2010 04:52:58 -0800 (PST) Subject: [rspec-users] [SOLVED] Rspec + Shoulda + FactoryGirl = undefined method `reflect_on_association' In-Reply-To: <57c63afe1002240615u747dc225r4f0a315ca496920e@mail.gmail.com> References: <57c63afe1002240615u747dc225r4f0a315ca496920e@mail.gmail.com> Message-ID: <63d0d225-4215-408e-baa1-b93b41ff2a35@q2g2000pre.googlegroups.com> Thank you so much. I have been staring at this for way too long and missed the obvious. I had a redundant active_matchers plugin that was conflicting with shoulda. Cheers, Dave On Feb 25, 1:15?am, David Chelimsky wrote: > On Wed, Feb 24, 2010 at 2:23 AM, Dave wrote: > > I have Rspec + Shoulda + FactoryGirl and I am receiving the following > > error when attempting to call Shoulda's have_many or belong_to > > methods. All Shoulda methods used in the "validations" group work > > fine: > > > ? ?> ? NoMethodError in 'A Project > > ? ?> associations should When you call a > > ? ?> matcher in an example without a > > ? ?> String, like this: > > ? ?> > > ? ?> ? specify { object.should matcher } > > ? ?> > > ? ?> ? or this: > > ? ?> > > ? ?> ? it { should matcher } > > ? ?> > > ? ?> ? RSpec expects the matcher to have a > > ? ?> #description method. You should either ? add a String to the > > example this > > ? ?> matcher is being used in, or give it a > > ? ?> description method. Then you won't > > ? ?> have to suffer this lengthy warning > > ? ?> again. ? ' ? undefined method > > ? ?> `reflect_on_association' for > > ? ?> # ? /vendor/plugins/active_matchers/lib/ > > matchers/association_matcher.rb:37:in > > What's active_matchers? I don't think that's part of rspec, shoulda, > or factory_girl. > > > > > ? ?> `confirm_association' > > ? ?> /vendor/plugins/active_matchers/lib/matchers/ > > association_matcher.rb:36:in > > ? ?> `each' > > ? ?> /vendor/plugins/active_matchers/lib/matchers/ > > association_matcher.rb:36:in > > ? ?> `confirm_association' > > ? ?> /vendor/plugins/active_matchers/lib/matchers/ > > association_matcher.rb:11:in > > ? ?> `matches?' > > ? ?> ./spec/models/project_spec.rb:7: > > > Thanks in advance > > > spec/spec_helper.rb > > ================================================================== > > > ? ?require 'shoulda' > > > spec/models/project_spec.rb > > ================================================================== > > > ? ?require File.dirname(__FILE__) + '/../spec_helper' > > > ? ?describe "A Project" do > > ? ? ?describe "associations" do > > > ? ? ? ?subject { Factory(:project) } > > > ? ? ? ?it { should have_many(:tasks) } > > ? ? ? ?it { should belong_to(:project_status) } > > ? ? ?end > > > ? ? ?describe "validations" do > > ? ? ? ?subject { Factory(:project) } > > > ? ? ? ?it { should validate_presence_of(:name) } > > > ? ? ? ?it { should validate_uniqueness_of(:name).case_insensitive } > > > ? ? ? ?it { should allow_mass_assignment_of(:name) } > > ? ? ?end > > ? ?end > > _______________________________________________ > > 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 rogerpack2005 at gmail.com Thu Feb 25 10:29:14 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Thu, 25 Feb 2010 07:29:14 -0800 (PST) Subject: [rspec-users] rspec "output which test it is running before running it" Message-ID: <14db71a2-1541-498b-8e5b-7f8003732460@v13g2000yqv.googlegroups.com> I'm trying to find a spec parameter that will do something like the following $ spec file.spec Spec: running "it should pass spec x" . Spec: running "it should pass spec y" . That type of thing. The use case is that "one" of my tests is outputting some weird stuff and I want to narrow down on which one it is easily. Does such a thing exist? If not would a patch for it be welcome? Thanks. -r From dchelimsky at gmail.com Thu Feb 25 10:41:54 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Feb 2010 09:41:54 -0600 Subject: [rspec-users] rspec "output which test it is running before running it" In-Reply-To: <14db71a2-1541-498b-8e5b-7f8003732460@v13g2000yqv.googlegroups.com> References: <14db71a2-1541-498b-8e5b-7f8003732460@v13g2000yqv.googlegroups.com> Message-ID: <4C610C25-42D6-4CD6-A547-715DF655CBAA@gmail.com> On Feb 25, 2010, at 9:29 AM, rogerdpack wrote: > I'm trying to find a spec parameter that will do something like the > following > > $ spec file.spec > > Spec: running "it should pass spec x" > . > Spec: running "it should pass spec y" > . > In rspec-1: spec spec --format nested In rspec-2; rspec spec --format doc HTH, David > > That type of thing. > > The use case is that "one" of my tests is outputting some weird stuff > and I want to narrow down on which one it is easily. > > Does such a thing exist? If not would a patch for it be welcome? > Thanks. > -r > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Thu Feb 25 10:44:09 2010 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 25 Feb 2010 15:44:09 +0000 Subject: [rspec-users] rspec "output which test it is running before running it" In-Reply-To: <14db71a2-1541-498b-8e5b-7f8003732460@v13g2000yqv.googlegroups.com> References: <14db71a2-1541-498b-8e5b-7f8003732460@v13g2000yqv.googlegroups.com> Message-ID: Do you mean --format specdoc ? On 25 Feb 2010, at 15:29, rogerdpack wrote: > I'm trying to find a spec parameter that will do something like the > following > > $ spec file.spec > > Spec: running "it should pass spec x" > . > Spec: running "it should pass spec y" > . > > > That type of thing. > > The use case is that "one" of my tests is outputting some weird stuff > and I want to narrow down on which one it is easily. > > Does such a thing exist? If not would a patch for it be welcome? > Thanks. > -r > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users cheers, Matt http://mattwynne.net +447974 430184 From rogerpack2005 at gmail.com Thu Feb 25 12:34:10 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Thu, 25 Feb 2010 09:34:10 -0800 (PST) Subject: [rspec-users] rspec "output which test it is running before running it" In-Reply-To: <4C610C25-42D6-4CD6-A547-715DF655CBAA@gmail.com> References: <14db71a2-1541-498b-8e5b-7f8003732460@v13g2000yqv.googlegroups.com> <4C610C25-42D6-4CD6-A547-715DF655CBAA@gmail.com> Message-ID: <93ec7494-33cd-4d84-bfaf-338cddfa5b48@e1g2000yqh.googlegroups.com> > spec spec --format nested Cool thanks! -r From rogerpack2005 at gmail.com Thu Feb 25 12:43:11 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Thu, 25 Feb 2010 09:43:11 -0800 (PST) Subject: [rspec-users] specify multiple names Message-ID: I noticed this in the help -e, --example [NAME|FILE_NAME] Execute example(s) with matching name(s). To me, this seems to imply I can pass more than one name. But that didn't help me figure out exactly how to do so. Anybody could help me out there? What I'd like to do is figure out how to make the help text more instructive. Thanks. -rp From rogerpack2005 at gmail.com Thu Feb 25 12:47:23 2010 From: rogerpack2005 at gmail.com (rogerdpack) Date: Thu, 25 Feb 2010 09:47:23 -0800 (PST) Subject: [rspec-users] rspec "output which test it is running before running it" In-Reply-To: References: <14db71a2-1541-498b-8e5b-7f8003732460@v13g2000yqv.googlegroups.com> Message-ID: On Feb 25, 8:44?am, Matt Wynne wrote: > Do you mean --format specdoc ? Interesting. It appears that with both specdoc and --format nested, it outputs the test name *after* running it. I would have expected the opposite. Is this expected? Thanks. -r From dchelimsky at gmail.com Thu Feb 25 13:28:43 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Feb 2010 12:28:43 -0600 Subject: [rspec-users] rspec "output which test it is running before running it" In-Reply-To: References: <14db71a2-1541-498b-8e5b-7f8003732460@v13g2000yqv.googlegroups.com> Message-ID: <57c63afe1002251028j798376e6q693be92ccb0a9e77@mail.gmail.com> On Thu, Feb 25, 2010 at 11:47 AM, rogerdpack wrote: > On Feb 25, 8:44?am, Matt Wynne wrote: >> Do you mean --format specdoc ? > > Interesting. > It appears that with both specdoc and --format nested, it outputs the > test name *after* running it. ?I would have expected the opposite. ?Is > this expected? Actually it is (now that you mention it). The reason is that each example reports whether it passed or failed, which it clearly can't know until it's run. Another solution for your issue would be to write a custom formatter: http://wiki.github.com/dchelimsky/rspec/custom-formatters HTH, David > Thanks. > -r > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From phillipkoebbe at gmail.com Thu Feb 25 13:35:10 2010 From: phillipkoebbe at gmail.com (Phillip Koebbe) Date: Thu, 25 Feb 2010 12:35:10 -0600 Subject: [rspec-users] rspec "output which test it is running before running it" In-Reply-To: References: <14db71a2-1541-498b-8e5b-7f8003732460@v13g2000yqv.googlegroups.com> Message-ID: <4B86C2DE.9080102@gmail.com> rogerdpack wrote: > Interesting. > It appears that with both specdoc and --format nested, it outputs the > test name *after* running it. I would have expected the opposite. Is > this expected? > Thanks. > -r > Yes. RSpec needs to know if the test passed or failed so it knows how to color it. At least, that's my layman's guess. Peace, Phillip From sean at clipperadams.com Thu Feb 25 14:57:52 2010 From: sean at clipperadams.com (Sean DeNigris) Date: Thu, 25 Feb 2010 11:57:52 -0800 (PST) Subject: [rspec-users] Matching Rails response to visible text Message-ID: Hi, I did a bit of experimenting/Googling for what seems like a common operation, but didn't like what I found (mostly hand-rolled regexes)... I want to verify response text, but don't care about the structure. The text happens to be in a table, but appears to the user as pure text. E.g. table with columns first_name = "Jim" and last_name = "Johnson" looks to the reader like "Jim Johnson" I want to say something like response.should include_text("Jim Johnson"), but the html tags throw the match off. Any suggestions? Sean From sean at clipperadams.com Thu Feb 25 15:22:05 2010 From: sean at clipperadams.com (Sean DeNigris) Date: Thu, 25 Feb 2010 12:22:05 -0800 (PST) Subject: [rspec-users] Matching Rails response to visible text In-Reply-To: References: Message-ID: <13665966-f7f0-452f-b1cf-e4126db16068@i39g2000yqm.googlegroups.com> Never mind, found it in the webrat specs 10 seconds after I posted... guess it's time for a break, lol... response.should contain 'Jim Johnson' - Sean From dchelimsky at gmail.com Thu Feb 25 15:21:30 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Feb 2010 14:21:30 -0600 Subject: [rspec-users] Matching Rails response to visible text In-Reply-To: References: Message-ID: <57c63afe1002251221h2b3f402ajd9e3440ad6072852@mail.gmail.com> On Thu, Feb 25, 2010 at 1:57 PM, Sean DeNigris wrote: > Hi, > > I did a bit of experimenting/Googling for what seems like a common > operation, but didn't like what I found (mostly hand-rolled > regexes)... > > I want to verify response text, but don't care about the structure. > The text happens to be in a table, but appears to the user as pure > text. > > E.g. table with columns first_name = "Jim" and last_name = "Johnson" > looks to the reader like "Jim Johnson" > I want to say something like response.should include_text("Jim > Johnson"), but the html tags throw the match off. > > Any suggestions? Use the webrat contain matcher: response.body.should contain("Jim Johnson") > > Sean > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From somethingnoonehasthoughtof at gmail.com Thu Feb 25 17:44:08 2010 From: somethingnoonehasthoughtof at gmail.com (lawwantsin) Date: Thu, 25 Feb 2010 14:44:08 -0800 (PST) Subject: [rspec-users] should_receive not receiving on a returned instance variable Message-ID: <54fe5057-2409-4325-9fc8-d5289b77fb2a@x22g2000yqx.googlegroups.com> i'm calling a very simple should_receive method on a returned instance and it's saying the implementation code is not calling it. i get this error in my specs alot. i've read the rspec beta book and it doesn't mention examples like this. i couldn't find any solutions on the forum yet so i wanted to reach out. it seems like i'm just not getting something about the rspec api. ==SPEC== before :all do @scene = Factory.create(:scene) @project = Project.create(:working_title => "test") @project.scenes << [@scene] @project.save end it 'should call done! on @scene' do @project.stub_chain(:scenes, :find).and_return(@scene) @scene.should_receive(:done!).and_return(true) xhr :post, :done, {:id => @scene.id, :project_id => @project.id} end ==IMPLEMENTATION== class ScenesController < ApplicationController before_filter :get_project def done @scene = @project.scenes.find(params[:id]) if @scene.done! render else render_alert("Scene cannot be marked done.") end end end ==OUTPUT== Spec::Mocks::MockExpectationError in 'ScenesController#done # expected :done! with (any args) once, but received it 0 times note: @project is assigned through a before_filter (defined in ApplicationController) which finds the project using params[:project_id]. it's a nested resources thang... you know this isn't specific to the state machine plugin. it's the same for any instance i return from another operation within a spec. it's as though the @scene returned isn't receving anything, but some other @scene (somewhere else) is receving the done! method just fine. the sad part is, even though the spec fails, the code works in production. decouplization does come with headaches. any help with my practices wrong would definitely be appreciated and probably clear up the same issue a dozen other times in the code. thank you all. VERSIONS osx 10.6.2 rspec 1.3 rspec-rails 1.3.2 rails 2.3.5 factory-girl 1.2.2 aasm plugin From dchelimsky at gmail.com Thu Feb 25 22:53:07 2010 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 25 Feb 2010 21:53:07 -0600 Subject: [rspec-users] should_receive not receiving on a returned instance variable In-Reply-To: <54fe5057-2409-4325-9fc8-d5289b77fb2a@x22g2000yqx.googlegroups.com> References: <54fe5057-2409-4325-9fc8-d5289b77fb2a@x22g2000yqx.googlegroups.com> Message-ID: <57c63afe1002251953j424dd257r602a7c7bd7e0d1e8@mail.gmail.com> On Thu, Feb 25, 2010 at 4:44 PM, lawwantsin wrote: > i'm calling a very simple should_receive method on a returned instance > and it's saying the implementation code is not calling it. ?i get this > error in my specs alot. ?i've read the rspec beta book and it doesn't > mention examples like this. ?i couldn't find any solutions on the > forum yet so i wanted to reach out. ?it seems like i'm just not > getting something about the rspec api. > > ==SPEC== > > ? before :all do Use before(:each), especially when you're dealing with real data that gets cleaned out after each example. > ? ? @scene = ?Factory.create(:scene) > ? ? @project = Project.create(:working_title => "test") I'd use factories for both @scene and @project: @scene = Factory(:scene) @project = Factory(:project, :working_title => "test") > ? ? @project.scenes << [@scene] > ? ? @project.save > ?end > > ? ?it 'should call done! on @scene' do > ? ? ?@project.stub_chain(:scenes, :find).and_return(@scene) > ? ? ?@scene.should_receive(:done!).and_return(true) > ? ? ? ?xhr :post, :done, {:id => @scene.id, :project_id => > @project.id} > ? ?end > > ==IMPLEMENTATION== > class ScenesController < ApplicationController > > ?before_filter :get_project > > ?def done > ? ?@scene = @project.scenes.find(params[:id]) This @project is not the same @project that is defined in the spec, which is likely the root of the problem. For them to be the same object, you'll need to stub whatever method is used in the before filter. Possibly this in the before block in the spec: before(:each) do @project = Factory(:project, :working_title => "test") Project.stub(:find) { @project } end HTH, David > ? ?if @scene.done! > ? ? ?render > ? ?else > ? ? ?render_alert("Scene cannot be marked done.") > ? ?end > ?end > > end > > ==OUTPUT== > > Spec::Mocks::MockExpectationError in 'ScenesController#done > # expected :done! with (any args) once, but > received it 0 times > > note: @project is assigned through a before_filter (defined in > ApplicationController) which finds the project using > params[:project_id]. ?it's a nested resources thang... you know > > this isn't specific to the state machine plugin. ?it's the same for > any instance i return from another operation within a spec. ?it's as > though the @scene returned isn't receving anything, but some other > @scene (somewhere else) is receving the done! method just fine. > > the sad part is, even though the spec fails, the code works in > production. ?decouplization does come with headaches. ?any help with > my practices wrong would definitely be appreciated and probably clear > up the same issue a dozen other times in the code. ?thank you all. > > VERSIONS > osx 10.6.2 > rspec 1.3 > rspec-rails 1.3.2 > rails 2.3.5 > factory-girl 1.2.2 > aasm plugin From lists at ruby-forum.com Fri Feb 26 14:44:08 2010 From: lists at ruby-forum.com (Jason Fb) Date: Fri, 26 Feb 2010 20:44:08 +0100 Subject: [rspec-users] Error: undefined method `use_transactional_fixtures In-Reply-To: References: Message-ID: <3a38e959bd5cc6e4b1509ebce4791eff@ruby-forum.com> This happens when you generate tests pre-Rails 2.3 then upgrade to Rails 2.3. go to test/test_helper.rb and change: class Test::Unit::testCase to: class ActiveSupport::TestCase http://www.datatravels.com/technotes/2009/04/21/rails-error-undefined-method-use_transactional_fix/ waseem ahmad wrote: > Hi, > > I get this error when I do > > $spec /spec/any_spec > > /home/waseem/app/spec/spec_helper.rb:14: undefined method > `use_transactional_fixtures=' for > # > (NoMethodError) > from > /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner.rb:184:in > `configure' > from /home/waseem/app/spec/spec_helper.rb:10 > from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in > `gem_original_require' > from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in > `require' > from ./spec/controllers/user_sessions_controller_spec.rb:1 > from > /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in > `load' > from > /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in > `load_files' > from > /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in > `each' > from > /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in > `load_files' > from > /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/options.rb:98:in > `run_examples' > from > /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/command_line.rb:10:in > `run' > from /usr/lib/ruby/gems/1.8/gems/rspec-1.1.11/bin/spec:4 > from /usr/bin/spec:19:in `load' > from /usr/bin/spec:19 > > I googled it and got > http://ryandaigle.com/articles/2008/11/19/what-s-new-in-edge-rails-application-rb-duality-is-no-moresee > Maxim's comment > > What could be possibly wrong? -- Posted via http://www.ruby-forum.com/. From ed.howland at gmail.com Fri Feb 26 23:17:38 2010 From: ed.howland at gmail.com (Ed Howland) Date: Fri, 26 Feb 2010 23:17:38 -0500 Subject: [rspec-users] Cucumber Scenario syntax In-Reply-To: References: <57c63afe0809120851n2433d156wb7df4a4b42d752b0@mail.gmail.com> <57c63afe0809120914x53c56984r6cafc56d0cc53f2b@mail.gmail.com> <8F463ACB-3755-47DE-8EAB-2D004A566828@tiggerpalace.com> <57c63afe0809120926w33a1ce19t19f92da55600aeb@mail.gmail.com> <4D880123-03BD-400C-938F-94B0EA64FC66@tiggerpalace.com> Message-ID: <3df642dd1002262017k51908286va9a74a4816978cc8@mail.gmail.com> Hi, Searched for this everywhere, so here goes. I am having trouble matching multiline strings with leading whitespace in them using the """ operator. E.g. Then the output should be """ Usage: mygem [options] destination Template Options: -r, --ruby install the ruby template --ruby-19 install the ruby-19 template General options: -f, --force force overwriting files, don't ask -s, --skip skip file if it exists -q, --quiet runs quietly, no output -V, --verbose Show lots of output -v, --version Show this version -p, --pretend dry run, show what would have happened -x, --debug Show debugging output -h, --help Show this help """ I am generating this (almost) t am I doing wrongexact output with 5 leading space before the options, but the expected string is collapsing them down to one leading space: Diff: @@ -1,15 +1,14 @@ +Ok + Usage: mygem [options] destination -Template Options: - -r, --ruby install the ruby template - --ruby-19 install the ruby-19 template General options: - -f, --force force overwriting files, don't ask - -s, --skip skip file if it exists - -q, --quiet runs quietly, no output - -V, --verbose Show lots of output - -v, --version Show this version - -p, --pretend dry run, show what would have happened - -x, --debug Show debugging output - -h, --help Show this help + -f, --force force overwriting files, don't ask + -s, --skip skip file if it exists + -q, --quiet runs quietly, no output + -V, --verbose Show lots of output + -v, --version Show this version + -p, --pretend dry run, show what would have happened + -x, --debug Show debugging output + -h, --help Show this help What am I doing wrong? Thanks Cheers, Ed Ed Howland http://greenprogrammer.wordpress.com http://twitter.com/ed_howland From aslak.hellesoy at gmail.com Sat Feb 27 04:30:57 2010 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 27 Feb 2010 10:30:57 +0100 Subject: [rspec-users] Cucumber Scenario syntax In-Reply-To: <3df642dd1002262017k51908286va9a74a4816978cc8@mail.gmail.com> References: <57c63afe0809120851n2433d156wb7df4a4b42d752b0@mail.gmail.com> <57c63afe0809120914x53c56984r6cafc56d0cc53f2b@mail.gmail.com> <8F463ACB-3755-47DE-8EAB-2D004A566828@tiggerpalace.com> <57c63afe0809120926w33a1ce19t19f92da55600aeb@mail.gmail.com> <4D880123-03BD-400C-938F-94B0EA64FC66@tiggerpalace.com> <3df642dd1002262017k51908286va9a74a4816978cc8@mail.gmail.com> Message-ID: <8d961d901002270130pe3867f4o1d6225fd3f973f32@mail.gmail.com> On Sat, Feb 27, 2010 at 5:17 AM, Ed Howland wrote: > Hi, > > Searched for this everywhere, so here goes. > > I am having trouble matching multiline strings with leading whitespace > in them using the """ operator. > > Cucumber intentionally removes all the space characters left of the leftmost triple quote. Just indent everything relative to the leftmost triple quote and you'll be ok. Aslak > E.g. > Then the output should be > """ > Usage: > mygem [options] destination > Template Options: > -r, --ruby install the ruby template > --ruby-19 install the ruby-19 template > General options: > -f, --force force overwriting files, don't ask > -s, --skip skip file if it exists > -q, --quiet runs quietly, no output > -V, --verbose Show lots of output > -v, --version Show this version > -p, --pretend dry run, show what would have happened > -x, --debug Show debugging output > -h, --help Show this help > """ > > I am generating this (almost) t am I doing wrongexact output with 5 > leading space before the options, but the expected string is > collapsing them down to one leading space: > Diff: > > > @@ -1,15 +1,14 @@ > +Ok > + > Usage: > mygem [options] destination > -Template Options: > - -r, --ruby install the ruby template > - --ruby-19 install the ruby-19 template > General options: > - -f, --force force overwriting files, don't ask > - -s, --skip skip file if it exists > - -q, --quiet runs quietly, no output > - -V, --verbose Show lots of output > - -v, --version Show this version > - -p, --pretend dry run, show what would have > happened > - -x, --debug Show debugging output > - -h, --help Show this help > + -f, --force force overwriting files, don't > ask > + -s, --skip skip file if it exists > + -q, --quiet runs quietly, no output > + -V, --verbose Show lots of output > + -v, --version Show this version > + -p, --pretend dry run, show what would > have happened > + -x, --debug Show debugging output > + -h, --help Show this help > > > What am I doing wrong? > > Thanks > > Cheers, > Ed > > Ed Howland > http://greenprogrammer.wordpress.com > http://twitter.com/ed_howland > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Sun Feb 28 16:53:06 2010 From: lists at ruby-forum.com (Tumas Bajoras) Date: Sun, 28 Feb 2010 22:53:06 +0100 Subject: [rspec-users] STDIN gets method issue with rspec In-Reply-To: <57c63afe1001230436k4de8cae6l3d0a31634b726137@mail.gmail.com> References: <99bb0f4f1001221146p30315958xdc20ec764dd7aa1f@mail.gmail.com> <57c63afe1001230436k4de8cae6l3d0a31634b726137@mail.gmail.com> Message-ID: <24a8c02d60e3805fd67abc3ae47c88ab@ruby-forum.com> David Chelimsky wrote: > On Fri, Jan 22, 2010 at 1:46 PM, gokul murthy > wrote: >> Please kindly advise me, how to write spec for this. > Even though it seems simple, you've chosen a rather complex situation > to try to learn Rspec from. Did you pick this because you really need > to solve it, or is this just an academic exercise? If the latter, > let's start somewhere simpler, and get to things like simulating IO > later :) > > It is always easiest to start with examples in which you can create an > object with some state, send it a message (call a method), and set > expectations about the result: given/when/then. > > describe Person, "full name" do > context "with a first and last name" do > it "concats the names with a space between them" do > #given > person = Person.new(:first_name => "Gokul", :last_name => > "Murthy") > # when > full_name = person.full_name > #then > full_name.should == "Gokul Murthy" > end > end > end > > I separated out the When and Then to make it clear which is which, but > in practice I'd likely just write this: > > it "concats the names with a space between them" do > person = Person.new(:first_name => "Gokul", :last_name => > "Murthy") > person.full_name.should == "Gokul Murthy" > end > > Now we have a pretty clear picture of how we want to create a Person > and how we want to ask for its name, and what our expected outcome is. > > If you really want to know about specifying IO, let me know and I'll > show you a couple of ways to do it, but they are much less > straightforward. > > Cheers, > David Hey, I am learning RSpec as well and it would be great if you could show how to test IO. Thanks, Tumas -- Posted via http://www.ruby-forum.com/.