From pergesu at gmail.com Tue Jul 1 02:10:46 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 30 Jun 2008 23:10:46 -0700 Subject: [rspec-users] Odd Date-based spec failing In-Reply-To: References: <5e2dde260806301940i7342b4ddw2a6c4c2158d51c8a@mail.gmail.com> Message-ID: <810a540e0806302310l50ce8434v1923aa413d38645@mail.gmail.com> What do you see when you puts the values of end_date, start_date, and Date.today inside of #percentage_complete? On Mon, Jun 30, 2008 at 7:43 PM, Matt Darby wrote: > On Jul 1, 2008, at 10:10 PM, Camilo Torres wrote: > >> It seems your Phase.percentage_complete is not working as you expect. >> It clearly returns 100 when you are specting 83. The test clearly said >> that. >> >> ?What is the implementation of your percentage_complete method? > > It only fails when run via 'rake spec:models'; otherwise, it passes. > > def percentage_complete > # Returns an integer representation of a percentage (i.e. '78') > > return 100 if Date.today >= self.end_date > > length_in_days = (self.end_date - self.start_date).to_f > days_into_phase = (Date.today - self.start_date).to_f > > ((days_into_phase / length_in_days) * 100.0).round > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt at matt-darby.com Tue Jul 1 08:06:18 2008 From: matt at matt-darby.com (Matt Darby) Date: Tue, 1 Jul 2008 08:06:18 -0400 Subject: [rspec-users] Odd Date-based spec failing In-Reply-To: <810a540e0806302310l50ce8434v1923aa413d38645@mail.gmail.com> References: <5e2dde260806301940i7342b4ddw2a6c4c2158d51c8a@mail.gmail.com> <810a540e0806302310l50ce8434v1923aa413d38645@mail.gmail.com> Message-ID: <79205FC9-628C-4595-A65C-D5CFA9325A6C@matt-darby.com> On Jul 1, 2008, at 2:10 AM, Pat Maddox wrote: > What do you see when you puts the values of end_date, start_date, and > Date.today inside of #percentage_complete? When run via TextMate/Rspec Bundle: Date.today = 2008-07-01 self.start_date = 2008-06-26 self.end_date = 2008-07-02 When run via 'rake spec:models' Date.today = 2008-07-01 self.start_date = 0825-09-17 self.end_date = 2008-07-02 Pretty obvious what the bug is suddenly, but would cause this? Come to think of it, I'd seen this before in rare random cases in other Date-based specs in the past, though currently everything else is passing. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom at experthuman.com Tue Jul 1 08:23:02 2008 From: tom at experthuman.com (Tom Stuart) Date: Tue, 1 Jul 2008 13:23:02 +0100 Subject: [rspec-users] Odd Date-based spec failing In-Reply-To: <79205FC9-628C-4595-A65C-D5CFA9325A6C@matt-darby.com> References: <5e2dde260806301940i7342b4ddw2a6c4c2158d51c8a@mail.gmail.com> <810a540e0806302310l50ce8434v1923aa413d38645@mail.gmail.com> <79205FC9-628C-4595-A65C-D5CFA9325A6C@matt-darby.com> Message-ID: <24E4D2F0-172E-48AD-B28D-E84FC9E7882E@experthuman.com> On 1 Jul 2008, at 13:06, Matt Darby wrote: > When run via 'rake spec:models' > Date.today = 2008-07-01 > self.start_date = 0825-09-17 > self.end_date = 2008-07-02 > > Pretty obvious what the bug is suddenly, but would cause this? Not a solution, but a clue: $ ./script/console >> Date.today.minus_with_duration(5.days) => Thu, 26 Jun 2008 >> Date.today.minus_without_duration(5.days.to_i) => Sun, 17 Sep 0825 Is this a load-order problem? Perhaps ActiveSupport::CoreExtensions::Date::Calculations isn't kicking in correctly. Cheers, -Tom From matt at matt-darby.com Tue Jul 1 11:21:52 2008 From: matt at matt-darby.com (Matt Darby) Date: Tue, 1 Jul 2008 11:21:52 -0400 Subject: [rspec-users] Odd Date-based spec failing In-Reply-To: <24E4D2F0-172E-48AD-B28D-E84FC9E7882E@experthuman.com> References: <5e2dde260806301940i7342b4ddw2a6c4c2158d51c8a@mail.gmail.com> <810a540e0806302310l50ce8434v1923aa413d38645@mail.gmail.com> <79205FC9-628C-4595-A65C-D5CFA9325A6C@matt-darby.com> <24E4D2F0-172E-48AD-B28D-E84FC9E7882E@experthuman.com> Message-ID: <3B6415BF-3E17-4B5C-A74E-9DA66161D0EC@matt-darby.com> On Jul 1, 2008, at 8:23 AM, Tom Stuart wrote: > $ ./script/console > >> Date.today.minus_with_duration(5.days) > => Thu, 26 Jun 2008 > >> Date.today.minus_without_duration(5.days.to_i) > => Sun, 17 Sep 0825 > > Is this a load-order problem? Perhaps > ActiveSupport::CoreExtensions::Date::Calculations isn't kicking in > correctly. Hrm, quite interesting there. So would this be considered a Rails issue? From marcio.rails at gmail.com Tue Jul 1 13:59:16 2008 From: marcio.rails at gmail.com (marcio) Date: Tue, 1 Jul 2008 10:59:16 -0700 (PDT) Subject: [rspec-users] jumping authentication spec Message-ID: <1595bf9a-32e8-410d-925e-4832ededfb94@56g2000hsm.googlegroups.com> hi everyone! i ve been working in my new rspec scaffold generator. I have made all the neccesary specs over all controllers and models. I am working with restful_authenticated plugin. I have already coded the spects of it too. But now im trying to test my controllers and i dont know the way to "jump" my authentication system when i run rake spec. The errors described are reffered to this plugin and i would like to ignore it. I think the solution might be mocking the user and turning "true" to the login? method... i have tryied with the login? method and nothing happened. Am i in the right way? have anybody had this problem before? Thanks a lot. Marcio. From dchelimsky at gmail.com Tue Jul 1 14:08:55 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 1 Jul 2008 13:08:55 -0500 Subject: [rspec-users] jumping authentication spec In-Reply-To: <1595bf9a-32e8-410d-925e-4832ededfb94@56g2000hsm.googlegroups.com> References: <1595bf9a-32e8-410d-925e-4832ededfb94@56g2000hsm.googlegroups.com> Message-ID: <9ACC0CA1-00E3-49EE-87B7-0ADC9A80F111@gmail.com> On Jul 1, 2008, at 12:59 PM, marcio wrote: > hi everyone! i ve been working in my new rspec scaffold generator. > I have made all the neccesary specs over all controllers and models. > I am working with restful_authenticated plugin. I have already coded > the spects of it too. But now im trying to test my controllers and i > dont know the way to "jump" my authentication system when i run rake > spec. The errors described are reffered to this plugin and i would > like to ignore it. > I think the solution might be mocking the user and turning "true" to > the login? method... i have tryied with the login? method and nothing > happened. Am i in the right way? > have anybody had this problem before? Mocking the user sounds like the right approach. If you post some code we can help you more specifically. Cheers, David > > > Thanks a lot. > > Marcio. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From court3nay at gmail.com Tue Jul 1 14:18:22 2008 From: court3nay at gmail.com (Courtenay) Date: Tue, 1 Jul 2008 11:18:22 -0700 Subject: [rspec-users] jumping authentication spec In-Reply-To: <9ACC0CA1-00E3-49EE-87B7-0ADC9A80F111@gmail.com> References: <1595bf9a-32e8-410d-925e-4832ededfb94@56g2000hsm.googlegroups.com> <9ACC0CA1-00E3-49EE-87B7-0ADC9A80F111@gmail.com> Message-ID: <4b430c8f0807011118t4f8f4434u5354bbd63ca02693@mail.gmail.com> On Tue, Jul 1, 2008 at 11:08 AM, David Chelimsky wrote: > On Jul 1, 2008, at 12:59 PM, marcio wrote: > >> hi everyone! i ve been working in my new rspec scaffold generator. >> I have made all the neccesary specs over all controllers and models. >> I am working with restful_authenticated plugin. I have already coded >> the spects of it too. But now im trying to test my controllers and i >> dont know the way to "jump" my authentication system when i run rake >> spec. The errors described are reffered to this plugin and i would >> like to ignore it. >> I think the solution might be mocking the user and turning "true" to >> the login? method... i have tryied with the login? method and nothing >> happened. Am i in the right way? >> have anybody had this problem before? > > Mocking the user sounds like the right approach. If you post some code we > can help you more specifically. > > Cheers, > David > I used to do it like @controller.stub!(:login_required) @controller.stub!(:current_user).and_return mock_model(User) is this still valid? From ivorpaul at gmail.com Tue Jul 1 16:48:00 2008 From: ivorpaul at gmail.com (Ivor Paul) Date: Tue, 1 Jul 2008 22:48:00 +0200 Subject: [rspec-users] matchers not working...? Message-ID: Hi. I am pretty new to rspec so forgive my ignorance. I am getting errors that seem to be the matchers not working - example: vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:478:in `const_missing': uninitialized constant Spec::Rails::Example::ModelExampleGroup::Be_nil I have seen the same error with other matchers like be_valid etc. Does anyone have an idea what could be causing this? I am using the rspec and rspec_on_rails plugins. Pretty much the latest versions. Rails 2.0.2 Regards Ivor From dchelimsky at gmail.com Tue Jul 1 16:57:38 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 1 Jul 2008 15:57:38 -0500 Subject: [rspec-users] matchers not working...? In-Reply-To: References: Message-ID: On Jul 1, 2008, at 3:48 PM, Ivor Paul wrote: > I am getting errors that seem to be the matchers not working - > example: > > vendor/rails/activerecord/lib/../../activesupport/lib/active_support/ > dependencies.rb:478:in > `const_missing': uninitialized constant > Spec::Rails::Example::ModelExampleGroup::Be_nil > > I have seen the same error with other matchers like be_valid etc. Does the code say Be_nil instead of be_nil? > Does anyone have an idea what could be causing this? How are you invoking rspec? With rake? ruby? script/spec? or autotest? > I am using the rspec and rspec_on_rails plugins. Pretty much the > latest versions. Rails 2.0.2 With the 1.1.4 release we changed rspec_on_rails to rspec-rails, so I'm guessing you have the latest code that's still in subversion at rubyforge, but not the latest from github. Would you mind giving the code from github a shot? Install instructions can be found at http://github.com/dchelimsky/rspec-rails/wikis/home Cheers, David > Regards > Ivor From chris at cobaltedge.com Tue Jul 1 19:37:03 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Tue, 1 Jul 2008 16:37:03 -0700 Subject: [rspec-users] Cookies - how to set in controller specs? Message-ID: <443c240c0807011637i61a2764bl3dfe460e3ae8745a@mail.gmail.com> I've been searching Google, the mailing list, etc, etc. and can't for the life of me get a cookie to be set in a controller spec. From everything I've read on the web, it appears all I need to do is the typical: cookies[:name] = value or cookies[:name] = { :value => something, :expires => 1.year.from_now } I have also see things like doing "@request.cookies[:name]..." or setting the value to doing CGI::Cookie.new(...), and so on. I do not want to mock cookies, I want to actually test them, as that is the logic I'm trying to test. I know that my actual code works as I've run through this by directly testing in the browser, but of course I want specs to test it. Can someone show a test of setting a cookie, getting a page/action (and then optionally testing cookie after that)? -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From dchelimsky at gmail.com Wed Jul 2 07:06:38 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Jul 2008 06:06:38 -0500 Subject: [rspec-users] Cookies - how to set in controller specs? In-Reply-To: <443c240c0807011637i61a2764bl3dfe460e3ae8745a@mail.gmail.com> References: <443c240c0807011637i61a2764bl3dfe460e3ae8745a@mail.gmail.com> Message-ID: <57c63afe0807020406s5ef2209em34d32dffc5d6dbb0@mail.gmail.com> On Tue, Jul 1, 2008 at 6:37 PM, Christopher Bailey wrote: > I've been searching Google, the mailing list, etc, etc. and can't for > the life of me get a cookie to be set in a controller spec. From > everything I've read on the web, it appears all I need to do is the > typical: > > cookies[:name] = value > > or > > cookies[:name] = { :value => something, :expires => 1.year.from_now } > > I have also see things like doing "@request.cookies[:name]..." or > setting the value to doing CGI::Cookie.new(...), and so on. > > I do not want to mock cookies, I want to actually test them, as that > is the logic I'm trying to test. I know that my actual code works as > I've run through this by directly testing in the browser, but of > course I want specs to test it. Can someone show a test of setting a > cookie, getting a page/action (and then optionally testing cookie > after that)? This is just one of those goofy things in Rails testing. I'm not sure the best way to make it easier in rspec without breaking existing examples in the process. Regardless, here's how you interact with cookies from an example: To set a cookie: request.cookies[:cookie_key] = CGI::Cookie.new('cookie_key', 'cookie value') To read a cookie response.cookies[:cookie_key].should == ["expected value"] or cookies[:cookie_key].should == ["expected value"] Rails provides a cookies object that is actually response.cookies, so you don't *have* to reference it through the response object. I would, however, as I've been known to try to set a cookie in an example using cookies when I should have been using request.cookies. So I try to keep them explicit. HTH, David From dchelimsky at gmail.com Wed Jul 2 07:15:10 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Jul 2008 06:15:10 -0500 Subject: [rspec-users] Stopping Example Execution? In-Reply-To: References: Message-ID: <57c63afe0807020415m9df6bdfmfed02ba908746e00@mail.gmail.com> On Mon, Jun 30, 2008 at 5:11 PM, Britt Mileshosky wrote: > > n Sun, Jun 29, 2008 at 12:20 PM, David Chelimsky wrote: > On Jun 29, 2008, at 11:18 AM, Britt Mileshosky wrote: > > However, do you see where something like a return statement or end example statement could be beneficial? > If you are working from the top down with your controller action execution, then you only need to test your expectation > and then bail out of your action. No need to further test or meet requirements on anything else in that action because your > single test has been met. > > - in my example for making sure I find a user, I'd like to end execution once I DID find the user, i shouldn't have to satisfy > requirements about finding an account and a person... I'll write those expectations later in another nested describe group, as you > can see here, in a top down process > > PeopleController with a logged in user > - should find user > > PeopleController with a logged in user who has an account > - should find account > > PeopleController with a logged in user who doesnt have an account > - shouldn't find account > - should redirect ... > > PeopleController with a logged in user who has an account the person belongs to > - should find person > - should assign person for the view > > PeopleController with a logged in user who has an account the requested person does not belong to > - should not find person > - should ... > > My instinct about this is that it would encourage long methods because it would make it less painful to test them, so I would be adverse to anything that let's you short circuit the method. > > Anybody else have opinions on that? > > > > I'm just catching up on email now after being sick for the past six days, but health aside my opinion is that I agree with David's opinion. Rather than focusing on how-to write easier tests that complain less, start focusing on how-to write the right tests that complain when necessary. > > One of the benefits associated with feeling the pain of a test is that it may be a sign to re-assess and refactor your code. This usually happens early enough that it only takes a few minutes. Short circuiting essentially gives you the ability to not feel the pain. Its like CIPA [0], but for code. I would fear that the code would get so bad that by the time the test cried with pain your code was already beyond easy repair and instead required invasive surgery. > > Tests are part of the nervous system of your application. When they hurt, they're telling you something isn't right and that it should be addressed, > > > > I wouldn't really say that anything I have been presenting has been a result of 'pains', > more so an observation on how an example group with other example groups can be much more readable > for myself and for other developers when they need to read the specs. Stubbing everything at the top doesn't > make complete sense. Why not stub inside the example group that has a NICE describe statement telling you > what this stubbing is related to. We can't do this because the first examples will blow up due to having to execute > all the code. > > Take the 2 examples: > > ------------------------------------------------------------------------------------------------------------------------ > PeopleController > # stub everything way up here at the top where these > # definitions are out of context (by means of position) with following examples > # > # stub controller requirments > # stub logged in requirement > # stub account requirement > # stub no account requirement > # stub account owns person > # stub account doesn't own person > > > PeopleController with before filters > - should require user > > PeopleController with a logged in user > - should find user > > PeopleController with a logged in user who has an account > - should find account > > PeopleController with a logged in user who doesnt have an account > - shouldn't find account > - should redirect ... > > PeopleController with a logged in user who has an account the person belongs to > - should find person > - should assign person for the view > > PeopleController with a logged in user who has an account the requested person does not belong to > - should not find person > - should ... > > ------------------------------------------------------------------------------------------------------------------------ > PeopleController > # stub the minimum needed to get to the first example group up and running > > PeopleController with before filters > - should require user > > PeopleController with a logged in user > # stub logged in requirement > - should find user > > PeopleController with a logged in user who has an account > # stub account requirement > - should find account > > PeopleController with a logged in user who doesnt have an account > # stub no account requirement > - shouldn't find account > - should redirect ... > > PeopleController with a logged in user who has an account the person belongs to > # stub account owns person > - should find person > - should assign person for the view > > PeopleController with a logged in user who has an account the requested person does not belong to > # stub account doesn't own person > - should not find person > - should ... > > ------------------------------------------------------------------------------------------------------------------------ > > I prefer the second group, but unfortunately I am not able to write my specs in this organized fashion. > Just sayin. I appreciate the communication value you're looking for, and you can get it by stubbing everything you need to keep execution going before(:each) example and then set message expectations (should_receive) inside each example that help tell the story of that example. PeopleController # stub everything way up here at the top where these # definitions are out of context (by means of position) with following examples # # stub controller requirments # stub logged in requirement # stub account requirement # stub no account requirement # stub account owns person # stub account doesn't own person PeopleController with before filters - should require user PeopleController with a logged in user # expect logged in query - should find user PeopleController with a logged in user who has an account # expect logged in query # expect account query - should find account etc HTH, David > > Britt From ivorpaul at gmail.com Wed Jul 2 08:02:27 2008 From: ivorpaul at gmail.com (Ivor Paul) Date: Wed, 2 Jul 2008 14:02:27 +0200 Subject: [rspec-users] matchers not working...? In-Reply-To: References: Message-ID: Hi David thanks for the response! This is what the error looks like for be_valid /activesupport/lib/active_support/dependencies.rb:478:in `const_missing': uninitialized constant Spec::Rails::Example::ModelExampleGroup::Be_valid and for be_nil /activesupport/lib/active_support/dependencies.rb:478:in `const_missing': uninitialized constant Spec::Rails::Example::ModelExampleGroup::Be_nil I invoke the tests using rake spec. I also get this error when I use ./script/spec path/to/file. We were using svn externals for the plugins. I will give github a try and let you know what happens. Thanks for the help. Ivor On Tue, Jul 1, 2008 at 10:57 PM, David Chelimsky wrote: > On Jul 1, 2008, at 3:48 PM, Ivor Paul wrote: > >> I am getting errors that seem to be the matchers not working - example: >> >> >> vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:478:in >> `const_missing': uninitialized constant >> Spec::Rails::Example::ModelExampleGroup::Be_nil >> >> I have seen the same error with other matchers like be_valid etc. > > Does the code say Be_nil instead of be_nil? > >> Does anyone have an idea what could be causing this? > > How are you invoking rspec? With rake? ruby? script/spec? or autotest? > >> I am using the rspec and rspec_on_rails plugins. Pretty much the >> latest versions. Rails 2.0.2 > > With the 1.1.4 release we changed rspec_on_rails to rspec-rails, so I'm > guessing you have the latest code that's still in subversion at rubyforge, > but not the latest from github. > > Would you mind giving the code from github a shot? Install instructions can > be found at http://github.com/dchelimsky/rspec-rails/wikis/home > > Cheers, > David > >> Regards >> Ivor > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From chris at cobaltedge.com Wed Jul 2 12:15:27 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Wed, 2 Jul 2008 09:15:27 -0700 Subject: [rspec-users] Cookies - how to set in controller specs? In-Reply-To: <57c63afe0807020406s5ef2209em34d32dffc5d6dbb0@mail.gmail.com> References: <443c240c0807011637i61a2764bl3dfe460e3ae8745a@mail.gmail.com> <57c63afe0807020406s5ef2209em34d32dffc5d6dbb0@mail.gmail.com> Message-ID: <443c240c0807020915h1ba1817nd8c6b7286d04600e@mail.gmail.com> On Wed, Jul 2, 2008 at 4:06 AM, David Chelimsky wrote: > > This is just one of those goofy things in Rails testing. I'm not sure > the best way to make it easier in rspec without breaking existing > examples in the process. Regardless, here's how you interact with > cookies from an example: > > To set a cookie: > > request.cookies[:cookie_key] = CGI::Cookie.new('cookie_key', 'cookie value') When I do this, in order to get to this cookie in my controller code, I have to do cookies[:cookie_key][:cookie_key] Basically, it appears that what it does is assign that key a hash of its own. That makes sense of course, as I realize a cookie is really a hash of name, value, path, expires, and so on. However, it doesn't jive with the retrieval, as you shouldn't have to double reference it (which I believe is essentially the point of the [] method on ActionController::CookieJar and is not how things are documented). However, what's really behaving weird, is if I do: cookies[:cookie_key] = "1234" Then, in my controller code, if I look at "cookies", it shows that cookies is a hash, and if I call .keys on it, it spits out ":cookie_key", and if I call .values on it, it says "1234", but if I then go and do cookies[:cookie_key], it gives me nil. Again, I have to suspect something weird going on with Rails test environment/RSpec, since all this works fine outside of tests. Any suggestions on how to debug this further or what might be wrong? I should note I'm using Rails 2.1, and RSpec and rspec-rails from about a week ago (from GitHub). > To read a cookie > > response.cookies[:cookie_key].should == ["expected value"] > > or > > cookies[:cookie_key].should == ["expected value"] > > Rails provides a cookies object that is actually response.cookies, so > you don't *have* to reference it through the response object. I would, > however, as I've been known to try to set a cookie in an example using > cookies when I should have been using request.cookies. So I try to > keep them explicit. > > HTH, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From dchelimsky at gmail.com Wed Jul 2 12:41:40 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Jul 2008 11:41:40 -0500 Subject: [rspec-users] Cookies - how to set in controller specs? In-Reply-To: <443c240c0807020915h1ba1817nd8c6b7286d04600e@mail.gmail.com> References: <443c240c0807011637i61a2764bl3dfe460e3ae8745a@mail.gmail.com> <57c63afe0807020406s5ef2209em34d32dffc5d6dbb0@mail.gmail.com> <443c240c0807020915h1ba1817nd8c6b7286d04600e@mail.gmail.com> Message-ID: On Jul 2, 2008, at 11:15 AM, Christopher Bailey wrote: > On Wed, Jul 2, 2008 at 4:06 AM, David Chelimsky > wrote: > >> >> This is just one of those goofy things in Rails testing. I'm not sure >> the best way to make it easier in rspec without breaking existing >> examples in the process. Regardless, here's how you interact with >> cookies from an example: >> >> To set a cookie: >> >> request.cookies[:cookie_key] = CGI::Cookie.new('cookie_key', >> 'cookie value') > > When I do this, in order to get to this cookie in my controller code, > I have to do > > cookies[:cookie_key][:cookie_key] Sorry Christopher - try this: request.cookies[:cookie_key] = 'cookie value' Cheers, David > Basically, it appears that what it does is assign that key a hash of > its own. That makes sense of course, as I realize a cookie is really > a hash of name, value, path, expires, and so on. However, it doesn't > jive with the retrieval, as you shouldn't have to double reference it > (which I believe is essentially the point of the [] method on > ActionController::CookieJar and is not how things are documented). > > However, what's really behaving weird, is if I do: > > cookies[:cookie_key] = "1234" > > Then, in my controller code, if I look at "cookies", it shows that > cookies is a hash, and if I call .keys on it, it spits out > ":cookie_key", and if I call .values on it, it says "1234", but if I > then go and do cookies[:cookie_key], it gives me nil. > > Again, I have to suspect something weird going on with Rails test > environment/RSpec, since all this works fine outside of tests. Any > suggestions on how to debug this further or what might be wrong? > > I should note I'm using Rails 2.1, and RSpec and rspec-rails from > about a week ago (from GitHub). > >> To read a cookie >> >> response.cookies[:cookie_key].should == ["expected value"] >> >> or >> >> cookies[:cookie_key].should == ["expected value"] >> >> Rails provides a cookies object that is actually response.cookies, so >> you don't *have* to reference it through the response object. I >> would, >> however, as I've been known to try to set a cookie in an example >> using >> cookies when I should have been using request.cookies. So I try to >> keep them explicit. >> >> HTH, >> David >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Christopher Bailey > Cobalt Edge LLC > http://cobaltedge.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From chris at cobaltedge.com Wed Jul 2 12:57:35 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Wed, 2 Jul 2008 09:57:35 -0700 Subject: [rspec-users] Cookies - how to set in controller specs? In-Reply-To: References: <443c240c0807011637i61a2764bl3dfe460e3ae8745a@mail.gmail.com> <57c63afe0807020406s5ef2209em34d32dffc5d6dbb0@mail.gmail.com> <443c240c0807020915h1ba1817nd8c6b7286d04600e@mail.gmail.com> Message-ID: <443c240c0807020957y47bfa81ds35423ee533cb8de6@mail.gmail.com> On Wed, Jul 2, 2008 at 9:41 AM, David Chelimsky wrote: > On Jul 2, 2008, at 11:15 AM, Christopher Bailey wrote: > >> On Wed, Jul 2, 2008 at 4:06 AM, David Chelimsky >> wrote: >> >>> >>> This is just one of those goofy things in Rails testing. I'm not sure >>> the best way to make it easier in rspec without breaking existing >>> examples in the process. Regardless, here's how you interact with >>> cookies from an example: >>> >>> To set a cookie: >>> >>> request.cookies[:cookie_key] = CGI::Cookie.new('cookie_key', 'cookie >>> value') >> >> When I do this, in order to get to this cookie in my controller code, >> I have to do >> >> cookies[:cookie_key][:cookie_key] > > Sorry Christopher - try this: > > request.cookies[:cookie_key] = 'cookie value' I tried that (see below in my email - I just mistakenly wrote it without the "request." at the beginning). When I do this, it appears to set it, but then trying to retrieve it in my controller fails (even though the key is there, and the value is there, when then requesting cookies[:cookie_key] I get no value back). Pretty weird. > Cheers, > David > >> Basically, it appears that what it does is assign that key a hash of >> its own. That makes sense of course, as I realize a cookie is really >> a hash of name, value, path, expires, and so on. However, it doesn't >> jive with the retrieval, as you shouldn't have to double reference it >> (which I believe is essentially the point of the [] method on >> ActionController::CookieJar and is not how things are documented). >> >> However, what's really behaving weird, is if I do: >> >> cookies[:cookie_key] = "1234" >> >> Then, in my controller code, if I look at "cookies", it shows that >> cookies is a hash, and if I call .keys on it, it spits out >> ":cookie_key", and if I call .values on it, it says "1234", but if I >> then go and do cookies[:cookie_key], it gives me nil. >> >> Again, I have to suspect something weird going on with Rails test >> environment/RSpec, since all this works fine outside of tests. Any >> suggestions on how to debug this further or what might be wrong? >> >> I should note I'm using Rails 2.1, and RSpec and rspec-rails from >> about a week ago (from GitHub). >> >>> To read a cookie >>> >>> response.cookies[:cookie_key].should == ["expected value"] >>> >>> or >>> >>> cookies[:cookie_key].should == ["expected value"] >>> >>> Rails provides a cookies object that is actually response.cookies, so >>> you don't *have* to reference it through the response object. I would, >>> however, as I've been known to try to set a cookie in an example using >>> cookies when I should have been using request.cookies. So I try to >>> keep them explicit. >>> >>> HTH, >>> David >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> >> >> -- >> Christopher Bailey >> Cobalt Edge LLC >> http://cobaltedge.com >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From mileshosky at hotmail.com Wed Jul 2 13:13:59 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Wed, 2 Jul 2008 10:13:59 -0700 Subject: [rspec-users] Stopping Example Execution? In-Reply-To: <57c63afe0807020415m9df6bdfmfed02ba908746e00@mail.gmail.com> References: <57c63afe0807020415m9df6bdfmfed02ba908746e00@mail.gmail.com> Message-ID: ---------------------------------------- > Date: Wed, 2 Jul 2008 06:15:10 -0500 > From: dchelimsky at gmail.com > To: rspec-users at rubyforge.org > Subject: Re: [rspec-users] Stopping Example Execution? > > On Mon, Jun 30, 2008 at 5:11 PM, Britt Mileshosky > wrote: >> >> n Sun, Jun 29, 2008 at 12:20 PM, David Chelimsky wrote: >> On Jun 29, 2008, at 11:18 AM, Britt Mileshosky wrote: >> >> However, do you see where something like a return statement or end example statement could be beneficial? >> If you are working from the top down with your controller action execution, then you only need to test your expectation >> and then bail out of your action. No need to further test or meet requirements on anything else in that action because your >> single test has been met. >> >> - in my example for making sure I find a user, I'd like to end execution once I DID find the user, i shouldn't have to satisfy >> requirements about finding an account and a person... I'll write those expectations later in another nested describe group, as you >> can see here, in a top down process >> >> PeopleController with a logged in user >> - should find user >> >> PeopleController with a logged in user who has an account >> - should find account >> >> PeopleController with a logged in user who doesnt have an account >> - shouldn't find account >> - should redirect ... >> >> PeopleController with a logged in user who has an account the person belongs to >> - should find person >> - should assign person for the view >> >> PeopleController with a logged in user who has an account the requested person does not belong to >> - should not find person >> - should ... >> >> My instinct about this is that it would encourage long methods because it would make it less painful to test them, so I would be adverse to anything that let's you short circuit the method. >> >> Anybody else have opinions on that? >> >> >> >> I'm just catching up on email now after being sick for the past six days, but health aside my opinion is that I agree with David's opinion. Rather than focusing on how-to write easier tests that complain less, start focusing on how-to write the right tests that complain when necessary. >> >> One of the benefits associated with feeling the pain of a test is that it may be a sign to re-assess and refactor your code. This usually happens early enough that it only takes a few minutes. Short circuiting essentially gives you the ability to not feel the pain. Its like CIPA [0], but for code. I would fear that the code would get so bad that by the time the test cried with pain your code was already beyond easy repair and instead required invasive surgery. >> >> Tests are part of the nervous system of your application. When they hurt, they're telling you something isn't right and that it should be addressed, >> >> >> >> I wouldn't really say that anything I have been presenting has been a result of 'pains', >> more so an observation on how an example group with other example groups can be much more readable >> for myself and for other developers when they need to read the specs. Stubbing everything at the top doesn't >> make complete sense. Why not stub inside the example group that has a NICE describe statement telling you >> what this stubbing is related to. We can't do this because the first examples will blow up due to having to execute >> all the code. >> >> Take the 2 examples: >> >> ------------------------------------------------------------------------------------------------------------------------ >> PeopleController >> # stub everything way up here at the top where these >> # definitions are out of context (by means of position) with following examples >> # >> # stub controller requirments >> # stub logged in requirement >> # stub account requirement >> # stub no account requirement >> # stub account owns person >> # stub account doesn't own person >> >> >> PeopleController with before filters >> - should require user >> >> PeopleController with a logged in user >> - should find user >> >> PeopleController with a logged in user who has an account >> - should find account >> >> PeopleController with a logged in user who doesnt have an account >> - shouldn't find account >> - should redirect ... >> >> PeopleController with a logged in user who has an account the person belongs to >> - should find person >> - should assign person for the view >> >> PeopleController with a logged in user who has an account the requested person does not belong to >> - should not find person >> - should ... >> >> ------------------------------------------------------------------------------------------------------------------------ >> PeopleController >> # stub the minimum needed to get to the first example group up and running >> >> PeopleController with before filters >> - should require user >> >> PeopleController with a logged in user >> # stub logged in requirement >> - should find user >> >> PeopleController with a logged in user who has an account >> # stub account requirement >> - should find account >> >> PeopleController with a logged in user who doesnt have an account >> # stub no account requirement >> - shouldn't find account >> - should redirect ... >> >> PeopleController with a logged in user who has an account the person belongs to >> # stub account owns person >> - should find person >> - should assign person for the view >> >> PeopleController with a logged in user who has an account the requested person does not belong to >> # stub account doesn't own person >> - should not find person >> - should ... >> >> ------------------------------------------------------------------------------------------------------------------------ >> >> I prefer the second group, but unfortunately I am not able to write my specs in this organized fashion. >> Just sayin. > > I appreciate the communication value you're looking for, and you can > get it by stubbing everything you need to keep execution going > before(:each) example and then set message expectations > (should_receive) inside each example that help tell the story of that > example. > > PeopleController > # stub everything way up here at the top where these > # definitions are out of context (by means of position) with following examples > # > # stub controller requirments > # stub logged in requirement > # stub account requirement > # stub no account requirement > # stub account owns person > # stub account doesn't own person > > PeopleController with before filters > - should require user > > PeopleController with a logged in user > # expect logged in query > - should find user > > PeopleController with a logged in user who has an account > # expect logged in query > # expect account query > - should find account > > etc > > HTH, > David Yep, thats exactly what I've been practicing, and while its not exactly what I want, it does work nicely. Thank you David _________________________________________________________________ The i?m Talkaton. Can 30-days of conversation change the world? http://www.imtalkathon.com/?source=EML_WLH_Talkathon_ChangeWorld From cdemyanovich at gmail.com Wed Jul 2 13:33:05 2008 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Wed, 2 Jul 2008 13:33:05 -0400 Subject: [rspec-users] Cookies - how to set in controller specs? In-Reply-To: <443c240c0807020957y47bfa81ds35423ee533cb8de6@mail.gmail.com> References: <443c240c0807011637i61a2764bl3dfe460e3ae8745a@mail.gmail.com> <57c63afe0807020406s5ef2209em34d32dffc5d6dbb0@mail.gmail.com> <443c240c0807020915h1ba1817nd8c6b7286d04600e@mail.gmail.com> <443c240c0807020957y47bfa81ds35423ee533cb8de6@mail.gmail.com> Message-ID: <61c885db0807021033g785716d8l16c463b594c0a078@mail.gmail.com> My pair and I struggled with this a little bit last week. We decided to just use a hash to represent cookies in specs, since that's how we're interacting with it. You can see the specs that we wrote here: http://pastie.org/226443 . Regards, Craig From chris at cobaltedge.com Wed Jul 2 13:42:24 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Wed, 2 Jul 2008 10:42:24 -0700 Subject: [rspec-users] Cookies - how to set in controller specs? In-Reply-To: <443c240c0807020957y47bfa81ds35423ee533cb8de6@mail.gmail.com> References: <443c240c0807011637i61a2764bl3dfe460e3ae8745a@mail.gmail.com> <57c63afe0807020406s5ef2209em34d32dffc5d6dbb0@mail.gmail.com> <443c240c0807020915h1ba1817nd8c6b7286d04600e@mail.gmail.com> <443c240c0807020957y47bfa81ds35423ee533cb8de6@mail.gmail.com> Message-ID: <443c240c0807021042k5a243dbapcce1e64c8089ea1@mail.gmail.com> First, nevermind! Oy! I finally figured it out. The reason it wasn't working in my controller code was that I was checking for "cookies[:cookie_key]", not "request.cookies[:cookie_key]"! It's a bit strange how that manifested, given the fact that referencing just "cookies" was a hash with values, but alas, that's what was happening. So, thank you very much for your time (that I essentially wasted :( On Wed, Jul 2, 2008 at 9:57 AM, Christopher Bailey wrote: > On Wed, Jul 2, 2008 at 9:41 AM, David Chelimsky wrote: >> On Jul 2, 2008, at 11:15 AM, Christopher Bailey wrote: >> >>> On Wed, Jul 2, 2008 at 4:06 AM, David Chelimsky >>> wrote: >>> >>>> >>>> This is just one of those goofy things in Rails testing. I'm not sure >>>> the best way to make it easier in rspec without breaking existing >>>> examples in the process. Regardless, here's how you interact with >>>> cookies from an example: >>>> >>>> To set a cookie: >>>> >>>> request.cookies[:cookie_key] = CGI::Cookie.new('cookie_key', 'cookie >>>> value') >>> >>> When I do this, in order to get to this cookie in my controller code, >>> I have to do >>> >>> cookies[:cookie_key][:cookie_key] >> >> Sorry Christopher - try this: >> >> request.cookies[:cookie_key] = 'cookie value' > > I tried that (see below in my email - I just mistakenly wrote it > without the "request." at the beginning). When I do this, it appears > to set it, but then trying to retrieve it in my controller fails (even > though the key is there, and the value is there, when then requesting > cookies[:cookie_key] I get no value back). Pretty weird. > > >> Cheers, >> David >> >>> Basically, it appears that what it does is assign that key a hash of >>> its own. That makes sense of course, as I realize a cookie is really >>> a hash of name, value, path, expires, and so on. However, it doesn't >>> jive with the retrieval, as you shouldn't have to double reference it >>> (which I believe is essentially the point of the [] method on >>> ActionController::CookieJar and is not how things are documented). >>> >>> However, what's really behaving weird, is if I do: >>> >>> cookies[:cookie_key] = "1234" >>> >>> Then, in my controller code, if I look at "cookies", it shows that >>> cookies is a hash, and if I call .keys on it, it spits out >>> ":cookie_key", and if I call .values on it, it says "1234", but if I >>> then go and do cookies[:cookie_key], it gives me nil. >>> >>> Again, I have to suspect something weird going on with Rails test >>> environment/RSpec, since all this works fine outside of tests. Any >>> suggestions on how to debug this further or what might be wrong? >>> >>> I should note I'm using Rails 2.1, and RSpec and rspec-rails from >>> about a week ago (from GitHub). >>> >>>> To read a cookie >>>> >>>> response.cookies[:cookie_key].should == ["expected value"] >>>> >>>> or >>>> >>>> cookies[:cookie_key].should == ["expected value"] >>>> >>>> Rails provides a cookies object that is actually response.cookies, so >>>> you don't *have* to reference it through the response object. I would, >>>> however, as I've been known to try to set a cookie in an example using >>>> cookies when I should have been using request.cookies. So I try to >>>> keep them explicit. >>>> >>>> HTH, >>>> David >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> >>> >>> >>> -- >>> Christopher Bailey >>> Cobalt Edge LLC >>> http://cobaltedge.com >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Christopher Bailey > Cobalt Edge LLC > http://cobaltedge.com > -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From dchelimsky at gmail.com Wed Jul 2 13:52:08 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Jul 2008 12:52:08 -0500 Subject: [rspec-users] Cookies - how to set in controller specs? In-Reply-To: <443c240c0807021042k5a243dbapcce1e64c8089ea1@mail.gmail.com> References: <443c240c0807011637i61a2764bl3dfe460e3ae8745a@mail.gmail.com> <57c63afe0807020406s5ef2209em34d32dffc5d6dbb0@mail.gmail.com> <443c240c0807020915h1ba1817nd8c6b7286d04600e@mail.gmail.com> <443c240c0807020957y47bfa81ds35423ee533cb8de6@mail.gmail.com> <443c240c0807021042k5a243dbapcce1e64c8089ea1@mail.gmail.com> Message-ID: <91498BAC-722B-4924-BF50-43CB0C61071C@gmail.com> On Jul 2, 2008, at 12:42 PM, Christopher Bailey wrote: > First, nevermind! Oy! I finally figured it out. The reason it > wasn't working in my controller code was that I was checking for > "cookies[:cookie_key]", not "request.cookies[:cookie_key]"! It's a > bit strange how that manifested, given the fact that referencing just > "cookies" was a hash with values, but alas, that's what was happening. According to the rails API docs you shouldn't have to do that: http://api.rubyonrails.org/classes/ActionController/Cookies.html I figured out how to make this work. Here were the steps I took to get there and the solution: def some_action puts cookies.inspect, cookies[:cookie_key], cookies.class end => {:cookie_key=>"cookie value"} => nil => ActionController::CookieJar So the object is not a Hash, it's a CookieJar, which acts as a proxy to a Hash. And guess what it does when it accesses the Hash? @cookies[name.to_s] :) So ......... This will actually work! I've proven it with an example that I've added to rspec-rails - http://github.com/dchelimsky/rspec-rails/tree/master/spec/rails/example/controller_spec_spec.rb (look for "should support setting a cookie in the request"): request.cookies['cookie_key'] = CGI::Cookie.new('cookie_key','cookie value') That will let you access the cookies as documented in the action. I'm going to add some sort of support to rspec to make this a bit more user-friendly and less error prone. I'll follow up when I've done so. Cheers, David > > > So, thank you very much for your time (that I essentially wasted :( > > On Wed, Jul 2, 2008 at 9:57 AM, Christopher Bailey > wrote: >> On Wed, Jul 2, 2008 at 9:41 AM, David Chelimsky >> wrote: >>> On Jul 2, 2008, at 11:15 AM, Christopher Bailey wrote: >>> >>>> On Wed, Jul 2, 2008 at 4:06 AM, David Chelimsky >>> > >>>> wrote: >>>> >>>>> >>>>> This is just one of those goofy things in Rails testing. I'm not >>>>> sure >>>>> the best way to make it easier in rspec without breaking existing >>>>> examples in the process. Regardless, here's how you interact with >>>>> cookies from an example: >>>>> >>>>> To set a cookie: >>>>> >>>>> request.cookies[:cookie_key] = CGI::Cookie.new('cookie_key', >>>>> 'cookie >>>>> value') >>>> >>>> When I do this, in order to get to this cookie in my controller >>>> code, >>>> I have to do >>>> >>>> cookies[:cookie_key][:cookie_key] >>> >>> Sorry Christopher - try this: >>> >>> request.cookies[:cookie_key] = 'cookie value' >> >> I tried that (see below in my email - I just mistakenly wrote it >> without the "request." at the beginning). When I do this, it appears >> to set it, but then trying to retrieve it in my controller fails >> (even >> though the key is there, and the value is there, when then requesting >> cookies[:cookie_key] I get no value back). Pretty weird. >> >> >>> Cheers, >>> David >>> >>>> Basically, it appears that what it does is assign that key a hash >>>> of >>>> its own. That makes sense of course, as I realize a cookie is >>>> really >>>> a hash of name, value, path, expires, and so on. However, it >>>> doesn't >>>> jive with the retrieval, as you shouldn't have to double >>>> reference it >>>> (which I believe is essentially the point of the [] method on >>>> ActionController::CookieJar and is not how things are documented). >>>> >>>> However, what's really behaving weird, is if I do: >>>> >>>> cookies[:cookie_key] = "1234" >>>> >>>> Then, in my controller code, if I look at "cookies", it shows that >>>> cookies is a hash, and if I call .keys on it, it spits out >>>> ":cookie_key", and if I call .values on it, it says "1234", but >>>> if I >>>> then go and do cookies[:cookie_key], it gives me nil. >>>> >>>> Again, I have to suspect something weird going on with Rails test >>>> environment/RSpec, since all this works fine outside of tests. Any >>>> suggestions on how to debug this further or what might be wrong? >>>> >>>> I should note I'm using Rails 2.1, and RSpec and rspec-rails from >>>> about a week ago (from GitHub). >>>> >>>>> To read a cookie >>>>> >>>>> response.cookies[:cookie_key].should == ["expected value"] >>>>> >>>>> or >>>>> >>>>> cookies[:cookie_key].should == ["expected value"] >>>>> >>>>> Rails provides a cookies object that is actually >>>>> response.cookies, so >>>>> you don't *have* to reference it through the response object. I >>>>> would, >>>>> however, as I've been known to try to set a cookie in an example >>>>> using >>>>> cookies when I should have been using request.cookies. So I try to >>>>> keep them explicit. >>>>> >>>>> HTH, >>>>> David >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>> >>>> >>>> >>>> -- >>>> Christopher Bailey >>>> Cobalt Edge LLC >>>> http://cobaltedge.com >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> >> >> -- >> Christopher Bailey >> Cobalt Edge LLC >> http://cobaltedge.com >> > > > > -- > Christopher Bailey > Cobalt Edge LLC > http://cobaltedge.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From chris at cobaltedge.com Wed Jul 2 14:21:12 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Wed, 2 Jul 2008 11:21:12 -0700 Subject: [rspec-users] Cookies - how to set in controller specs? In-Reply-To: <91498BAC-722B-4924-BF50-43CB0C61071C@gmail.com> References: <443c240c0807011637i61a2764bl3dfe460e3ae8745a@mail.gmail.com> <57c63afe0807020406s5ef2209em34d32dffc5d6dbb0@mail.gmail.com> <443c240c0807020915h1ba1817nd8c6b7286d04600e@mail.gmail.com> <443c240c0807020957y47bfa81ds35423ee533cb8de6@mail.gmail.com> <443c240c0807021042k5a243dbapcce1e64c8089ea1@mail.gmail.com> <91498BAC-722B-4924-BF50-43CB0C61071C@gmail.com> Message-ID: <443c240c0807021121m64669937i79961a8de044188f@mail.gmail.com> On Wed, Jul 2, 2008 at 10:52 AM, David Chelimsky wrote: > On Jul 2, 2008, at 12:42 PM, Christopher Bailey wrote: > >> First, nevermind! Oy! I finally figured it out. The reason it >> wasn't working in my controller code was that I was checking for >> "cookies[:cookie_key]", not "request.cookies[:cookie_key]"! It's a >> bit strange how that manifested, given the fact that referencing just >> "cookies" was a hash with values, but alas, that's what was happening. > > According to the rails API docs you shouldn't have to do that: > > http://api.rubyonrails.org/classes/ActionController/Cookies.html > > I figured out how to make this work. Here were the steps I took to get there > and the solution: > > def some_action > puts cookies.inspect, cookies[:cookie_key], cookies.class > end > > => {:cookie_key=>"cookie value"} > => nil > => ActionController::CookieJar > > So the object is not a Hash, it's a CookieJar, which acts as a proxy to a > Hash. And guess what it does when it accesses the Hash? > > @cookies[name.to_s] > > :) > > So ......... > > This will actually work! I've proven it with an example that I've added to > rspec-rails - > http://github.com/dchelimsky/rspec-rails/tree/master/spec/rails/example/controller_spec_spec.rb (look > for "should support setting a cookie in the request"): > > request.cookies['cookie_key'] = CGI::Cookie.new('cookie_key','cookie > value') > > That will let you access the cookies as documented in the action. > > I'm going to add some sort of support to rspec to make this a bit more > user-friendly and less error prone. I'll follow up when I've done so. And really, from my interpretation and experiments, if you look at CookieJar, you can set the value by just passing a string, or a hash. Passing an actual CGI::Cookie object you're sort of getting lucky due to how CGI::Cookie.new happens to parse the "value" key/value pair in the Hash that it gets sent by CookieJar.[]= method. Unless I'm not reading it right, what happens when you do: request.cookies['cookie_key'] = CGI::Cookie.new('cookie_key','cookie value') is that in CookieJar.[]=, it will wind up doing: CGI::Cookie.new( { "name" => name.to_s, "value" => the_cookie_object_you_passed } ) If you try that in script/console for example, you'll find that CGI::Cookie.new happens to parse the value (your cookie object instance) properly and extract out the actual value. But instead, you can just simplify that all by simply doing: request.cookies['cookie_key'] = 'cookie value' This seems like one of those cases where people were trying to be too tricky with Ruby code, and mixing symbols and strings in unclear ways and so on. > Cheers, > David > > >> >> >> So, thank you very much for your time (that I essentially wasted :( >> >> On Wed, Jul 2, 2008 at 9:57 AM, Christopher Bailey >> wrote: >>> >>> On Wed, Jul 2, 2008 at 9:41 AM, David Chelimsky >>> wrote: >>>> >>>> On Jul 2, 2008, at 11:15 AM, Christopher Bailey wrote: >>>> >>>>> On Wed, Jul 2, 2008 at 4:06 AM, David Chelimsky >>>>> wrote: >>>>> >>>>>> >>>>>> This is just one of those goofy things in Rails testing. I'm not sure >>>>>> the best way to make it easier in rspec without breaking existing >>>>>> examples in the process. Regardless, here's how you interact with >>>>>> cookies from an example: >>>>>> >>>>>> To set a cookie: >>>>>> >>>>>> request.cookies[:cookie_key] = CGI::Cookie.new('cookie_key', 'cookie >>>>>> value') >>>>> >>>>> When I do this, in order to get to this cookie in my controller code, >>>>> I have to do >>>>> >>>>> cookies[:cookie_key][:cookie_key] >>>> >>>> Sorry Christopher - try this: >>>> >>>> request.cookies[:cookie_key] = 'cookie value' >>> >>> I tried that (see below in my email - I just mistakenly wrote it >>> without the "request." at the beginning). When I do this, it appears >>> to set it, but then trying to retrieve it in my controller fails (even >>> though the key is there, and the value is there, when then requesting >>> cookies[:cookie_key] I get no value back). Pretty weird. >>> >>> >>>> Cheers, >>>> David >>>> >>>>> Basically, it appears that what it does is assign that key a hash of >>>>> its own. That makes sense of course, as I realize a cookie is really >>>>> a hash of name, value, path, expires, and so on. However, it doesn't >>>>> jive with the retrieval, as you shouldn't have to double reference it >>>>> (which I believe is essentially the point of the [] method on >>>>> ActionController::CookieJar and is not how things are documented). >>>>> >>>>> However, what's really behaving weird, is if I do: >>>>> >>>>> cookies[:cookie_key] = "1234" >>>>> >>>>> Then, in my controller code, if I look at "cookies", it shows that >>>>> cookies is a hash, and if I call .keys on it, it spits out >>>>> ":cookie_key", and if I call .values on it, it says "1234", but if I >>>>> then go and do cookies[:cookie_key], it gives me nil. >>>>> >>>>> Again, I have to suspect something weird going on with Rails test >>>>> environment/RSpec, since all this works fine outside of tests. Any >>>>> suggestions on how to debug this further or what might be wrong? >>>>> >>>>> I should note I'm using Rails 2.1, and RSpec and rspec-rails from >>>>> about a week ago (from GitHub). >>>>> >>>>>> To read a cookie >>>>>> >>>>>> response.cookies[:cookie_key].should == ["expected value"] >>>>>> >>>>>> or >>>>>> >>>>>> cookies[:cookie_key].should == ["expected value"] >>>>>> >>>>>> Rails provides a cookies object that is actually response.cookies, so >>>>>> you don't *have* to reference it through the response object. I would, >>>>>> however, as I've been known to try to set a cookie in an example using >>>>>> cookies when I should have been using request.cookies. So I try to >>>>>> keep them explicit. >>>>>> >>>>>> HTH, >>>>>> David >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Christopher Bailey >>>>> Cobalt Edge LLC >>>>> http://cobaltedge.com >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> >>> >>> >>> -- >>> Christopher Bailey >>> Cobalt Edge LLC >>> http://cobaltedge.com >>> >> >> >> >> -- >> Christopher Bailey >> Cobalt Edge LLC >> http://cobaltedge.com >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From dchelimsky at gmail.com Wed Jul 2 14:27:06 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Jul 2008 13:27:06 -0500 Subject: [rspec-users] Cookies - how to set in controller specs? In-Reply-To: <443c240c0807021121m64669937i79961a8de044188f@mail.gmail.com> References: <443c240c0807011637i61a2764bl3dfe460e3ae8745a@mail.gmail.com> <57c63afe0807020406s5ef2209em34d32dffc5d6dbb0@mail.gmail.com> <443c240c0807020915h1ba1817nd8c6b7286d04600e@mail.gmail.com> <443c240c0807020957y47bfa81ds35423ee533cb8de6@mail.gmail.com> <443c240c0807021042k5a243dbapcce1e64c8089ea1@mail.gmail.com> <91498BAC-722B-4924-BF50-43CB0C61071C@gmail.com> <443c240c0807021121m64669937i79961a8de044188f@mail.gmail.com> Message-ID: <08DD9E54-26E2-4052-8D71-8DFC83CDAF4E@gmail.com> On Jul 2, 2008, at 1:21 PM, Christopher Bailey wrote: > On Wed, Jul 2, 2008 at 10:52 AM, David Chelimsky > wrote: >> On Jul 2, 2008, at 12:42 PM, Christopher Bailey wrote: >> >>> First, nevermind! Oy! I finally figured it out. The reason it >>> wasn't working in my controller code was that I was checking for >>> "cookies[:cookie_key]", not "request.cookies[:cookie_key]"! It's a >>> bit strange how that manifested, given the fact that referencing >>> just >>> "cookies" was a hash with values, but alas, that's what was >>> happening. >> >> According to the rails API docs you shouldn't have to do that: >> >> http://api.rubyonrails.org/classes/ActionController/Cookies.html >> >> I figured out how to make this work. Here were the steps I took to >> get there >> and the solution: >> >> def some_action >> puts cookies.inspect, cookies[:cookie_key], cookies.class >> end >> >> => {:cookie_key=>"cookie value"} >> => nil >> => ActionController::CookieJar >> >> So the object is not a Hash, it's a CookieJar, which acts as a >> proxy to a >> Hash. And guess what it does when it accesses the Hash? >> >> @cookies[name.to_s] >> >> :) >> >> So ......... >> >> This will actually work! I've proven it with an example that I've >> added to >> rspec-rails - >> http://github.com/dchelimsky/rspec-rails/tree/master/spec/rails/example/controller_spec_spec.rb >> (look >> for "should support setting a cookie in the request"): >> >> request.cookies['cookie_key'] = CGI::Cookie.new('cookie_key','cookie >> value') >> >> That will let you access the cookies as documented in the action. >> >> I'm going to add some sort of support to rspec to make this a bit >> more >> user-friendly and less error prone. I'll follow up when I've done so. > > And really, from my interpretation and experiments, if you look at > CookieJar, you can set the value by just passing a string, or a hash. > Passing an actual CGI::Cookie object you're sort of getting lucky due > to how CGI::Cookie.new happens to parse the "value" key/value pair in > the Hash that it gets sent by CookieJar.[]= method. Unless I'm not > reading it right, what happens when you do: > > request.cookies['cookie_key'] = > CGI::Cookie.new('cookie_key','cookie value') > > is that in CookieJar.[]=, it will wind up doing: > > CGI::Cookie.new( { "name" => name.to_s, "value" => > the_cookie_object_you_passed } ) > > If you try that in script/console for example, you'll find that > CGI::Cookie.new happens to parse the value (your cookie object > instance) properly and extract out the actual value. But instead, you > can just simplify that all by simply doing: > > request.cookies['cookie_key'] = 'cookie value' > > This seems like one of those cases where people were trying to be too > tricky with Ruby code, and mixing symbols and strings in unclear ways > and so on. I'm thinking of replacing the existing cookies() method (in the example) with one that returns a CookieJarProxy that will allow you to do any of the following: cookies['cookie_key'] = 'cookie value' cookies[:cookie_key] = 'cookie value' cookies['cookie_key'].should == 'cookie value' cookies[:cookie_key].should == 'cookie value' WDYT about that? > > > >> Cheers, >> David >> >> >>> >>> >>> So, thank you very much for your time (that I essentially wasted :( >>> >>> On Wed, Jul 2, 2008 at 9:57 AM, Christopher Bailey >> > >>> wrote: >>>> >>>> On Wed, Jul 2, 2008 at 9:41 AM, David Chelimsky >>> > >>>> wrote: >>>>> >>>>> On Jul 2, 2008, at 11:15 AM, Christopher Bailey wrote: >>>>> >>>>>> On Wed, Jul 2, 2008 at 4:06 AM, David Chelimsky >>>>> > >>>>>> wrote: >>>>>> >>>>>>> >>>>>>> This is just one of those goofy things in Rails testing. I'm >>>>>>> not sure >>>>>>> the best way to make it easier in rspec without breaking >>>>>>> existing >>>>>>> examples in the process. Regardless, here's how you interact >>>>>>> with >>>>>>> cookies from an example: >>>>>>> >>>>>>> To set a cookie: >>>>>>> >>>>>>> request.cookies[:cookie_key] = CGI::Cookie.new('cookie_key', >>>>>>> 'cookie >>>>>>> value') >>>>>> >>>>>> When I do this, in order to get to this cookie in my controller >>>>>> code, >>>>>> I have to do >>>>>> >>>>>> cookies[:cookie_key][:cookie_key] >>>>> >>>>> Sorry Christopher - try this: >>>>> >>>>> request.cookies[:cookie_key] = 'cookie value' >>>> >>>> I tried that (see below in my email - I just mistakenly wrote it >>>> without the "request." at the beginning). When I do this, it >>>> appears >>>> to set it, but then trying to retrieve it in my controller fails >>>> (even >>>> though the key is there, and the value is there, when then >>>> requesting >>>> cookies[:cookie_key] I get no value back). Pretty weird. >>>> >>>> >>>>> Cheers, >>>>> David >>>>> >>>>>> Basically, it appears that what it does is assign that key a >>>>>> hash of >>>>>> its own. That makes sense of course, as I realize a cookie is >>>>>> really >>>>>> a hash of name, value, path, expires, and so on. However, it >>>>>> doesn't >>>>>> jive with the retrieval, as you shouldn't have to double >>>>>> reference it >>>>>> (which I believe is essentially the point of the [] method on >>>>>> ActionController::CookieJar and is not how things are >>>>>> documented). >>>>>> >>>>>> However, what's really behaving weird, is if I do: >>>>>> >>>>>> cookies[:cookie_key] = "1234" >>>>>> >>>>>> Then, in my controller code, if I look at "cookies", it shows >>>>>> that >>>>>> cookies is a hash, and if I call .keys on it, it spits out >>>>>> ":cookie_key", and if I call .values on it, it says "1234", but >>>>>> if I >>>>>> then go and do cookies[:cookie_key], it gives me nil. >>>>>> >>>>>> Again, I have to suspect something weird going on with Rails test >>>>>> environment/RSpec, since all this works fine outside of tests. >>>>>> Any >>>>>> suggestions on how to debug this further or what might be wrong? >>>>>> >>>>>> I should note I'm using Rails 2.1, and RSpec and rspec-rails from >>>>>> about a week ago (from GitHub). >>>>>> >>>>>>> To read a cookie >>>>>>> >>>>>>> response.cookies[:cookie_key].should == ["expected value"] >>>>>>> >>>>>>> or >>>>>>> >>>>>>> cookies[:cookie_key].should == ["expected value"] >>>>>>> >>>>>>> Rails provides a cookies object that is actually >>>>>>> response.cookies, so >>>>>>> you don't *have* to reference it through the response object. >>>>>>> I would, >>>>>>> however, as I've been known to try to set a cookie in an >>>>>>> example using >>>>>>> cookies when I should have been using request.cookies. So I >>>>>>> try to >>>>>>> keep them explicit. >>>>>>> >>>>>>> HTH, >>>>>>> David >>>>>>> _______________________________________________ >>>>>>> rspec-users mailing list >>>>>>> rspec-users at rubyforge.org >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Christopher Bailey >>>>>> Cobalt Edge LLC >>>>>> http://cobaltedge.com >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>> >>>> >>>> >>>> -- >>>> Christopher Bailey >>>> Cobalt Edge LLC >>>> http://cobaltedge.com >>>> >>> >>> >>> >>> -- >>> Christopher Bailey >>> Cobalt Edge LLC >>> http://cobaltedge.com >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Christopher Bailey > Cobalt Edge LLC > http://cobaltedge.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Jul 2 14:37:19 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Jul 2008 13:37:19 -0500 Subject: [rspec-users] Cookies - how to set in controller specs? In-Reply-To: <443c240c0807021121m64669937i79961a8de044188f@mail.gmail.com> References: <443c240c0807011637i61a2764bl3dfe460e3ae8745a@mail.gmail.com> <57c63afe0807020406s5ef2209em34d32dffc5d6dbb0@mail.gmail.com> <443c240c0807020915h1ba1817nd8c6b7286d04600e@mail.gmail.com> <443c240c0807020957y47bfa81ds35423ee533cb8de6@mail.gmail.com> <443c240c0807021042k5a243dbapcce1e64c8089ea1@mail.gmail.com> <91498BAC-722B-4924-BF50-43CB0C61071C@gmail.com> <443c240c0807021121m64669937i79961a8de044188f@mail.gmail.com> Message-ID: <21C595CB-5516-4F52-A48F-D8B3B8C25BDC@gmail.com> On Jul 2, 2008, at 1:21 PM, Christopher Bailey wrote: > On Wed, Jul 2, 2008 at 10:52 AM, David Chelimsky > wrote: >> On Jul 2, 2008, at 12:42 PM, Christopher Bailey wrote: >> >>> First, nevermind! Oy! I finally figured it out. The reason it >>> wasn't working in my controller code was that I was checking for >>> "cookies[:cookie_key]", not "request.cookies[:cookie_key]"! It's a >>> bit strange how that manifested, given the fact that referencing >>> just >>> "cookies" was a hash with values, but alas, that's what was >>> happening. >> >> According to the rails API docs you shouldn't have to do that: >> >> http://api.rubyonrails.org/classes/ActionController/Cookies.html >> >> I figured out how to make this work. Here were the steps I took to >> get there >> and the solution: >> >> def some_action >> puts cookies.inspect, cookies[:cookie_key], cookies.class >> end >> >> => {:cookie_key=>"cookie value"} >> => nil >> => ActionController::CookieJar >> >> So the object is not a Hash, it's a CookieJar, which acts as a >> proxy to a >> Hash. And guess what it does when it accesses the Hash? >> >> @cookies[name.to_s] >> >> :) >> >> So ......... >> >> This will actually work! I've proven it with an example that I've >> added to >> rspec-rails - >> http://github.com/dchelimsky/rspec-rails/tree/master/spec/rails/example/controller_spec_spec.rb >> (look >> for "should support setting a cookie in the request"): >> >> request.cookies['cookie_key'] = CGI::Cookie.new('cookie_key','cookie >> value') >> >> That will let you access the cookies as documented in the action. >> >> I'm going to add some sort of support to rspec to make this a bit >> more >> user-friendly and less error prone. I'll follow up when I've done so. > > And really, from my interpretation and experiments, if you look at > CookieJar, you can set the value by just passing a string, or a hash. > Passing an actual CGI::Cookie object you're sort of getting lucky due > to how CGI::Cookie.new happens to parse the "value" key/value pair in > the Hash that it gets sent by CookieJar.[]= method. Unless I'm not > reading it right, what happens when you do: > > request.cookies['cookie_key'] = > CGI::Cookie.new('cookie_key','cookie value') > > is that in CookieJar.[]=, it will wind up doing: > > CGI::Cookie.new( { "name" => name.to_s, "value" => > the_cookie_object_you_passed } ) > > If you try that in script/console for example, you'll find that > CGI::Cookie.new happens to parse the value (your cookie object > instance) properly and extract out the actual value. But instead, you > can just simplify that all by simply doing: > > request.cookies['cookie_key'] = 'cookie value' This doesn't work for me unless I reference request.cookies in the controller, which I shouldn't have to do according to the rails docs. So for the moment, I'm sticking with: request.cookies['cookie_key'] = CGI::Cookie.new('cookie_key', 'cookie value') > This seems like one of those cases where people were trying to be too > tricky with Ruby code, and mixing symbols and strings in unclear ways > and so on. Totally agree. >>> So, thank you very much for your time (that I essentially wasted :( This is NOT at all a waste of time. Cheers, David >>> >>> >>> On Wed, Jul 2, 2008 at 9:57 AM, Christopher Bailey >> > >>> wrote: >>>> >>>> On Wed, Jul 2, 2008 at 9:41 AM, David Chelimsky >>> > >>>> wrote: >>>>> >>>>> On Jul 2, 2008, at 11:15 AM, Christopher Bailey wrote: >>>>> >>>>>> On Wed, Jul 2, 2008 at 4:06 AM, David Chelimsky >>>>> > >>>>>> wrote: >>>>>> >>>>>>> >>>>>>> This is just one of those goofy things in Rails testing. I'm >>>>>>> not sure >>>>>>> the best way to make it easier in rspec without breaking >>>>>>> existing >>>>>>> examples in the process. Regardless, here's how you interact >>>>>>> with >>>>>>> cookies from an example: >>>>>>> >>>>>>> To set a cookie: >>>>>>> >>>>>>> request.cookies[:cookie_key] = CGI::Cookie.new('cookie_key', >>>>>>> 'cookie >>>>>>> value') >>>>>> >>>>>> When I do this, in order to get to this cookie in my controller >>>>>> code, >>>>>> I have to do >>>>>> >>>>>> cookies[:cookie_key][:cookie_key] >>>>> >>>>> Sorry Christopher - try this: >>>>> >>>>> request.cookies[:cookie_key] = 'cookie value' >>>> >>>> I tried that (see below in my email - I just mistakenly wrote it >>>> without the "request." at the beginning). When I do this, it >>>> appears >>>> to set it, but then trying to retrieve it in my controller fails >>>> (even >>>> though the key is there, and the value is there, when then >>>> requesting >>>> cookies[:cookie_key] I get no value back). Pretty weird. >>>> >>>> >>>>> Cheers, >>>>> David >>>>> >>>>>> Basically, it appears that what it does is assign that key a >>>>>> hash of >>>>>> its own. That makes sense of course, as I realize a cookie is >>>>>> really >>>>>> a hash of name, value, path, expires, and so on. However, it >>>>>> doesn't >>>>>> jive with the retrieval, as you shouldn't have to double >>>>>> reference it >>>>>> (which I believe is essentially the point of the [] method on >>>>>> ActionController::CookieJar and is not how things are >>>>>> documented). >>>>>> >>>>>> However, what's really behaving weird, is if I do: >>>>>> >>>>>> cookies[:cookie_key] = "1234" >>>>>> >>>>>> Then, in my controller code, if I look at "cookies", it shows >>>>>> that >>>>>> cookies is a hash, and if I call .keys on it, it spits out >>>>>> ":cookie_key", and if I call .values on it, it says "1234", but >>>>>> if I >>>>>> then go and do cookies[:cookie_key], it gives me nil. >>>>>> >>>>>> Again, I have to suspect something weird going on with Rails test >>>>>> environment/RSpec, since all this works fine outside of tests. >>>>>> Any >>>>>> suggestions on how to debug this further or what might be wrong? >>>>>> >>>>>> I should note I'm using Rails 2.1, and RSpec and rspec-rails from >>>>>> about a week ago (from GitHub). >>>>>> >>>>>>> To read a cookie >>>>>>> >>>>>>> response.cookies[:cookie_key].should == ["expected value"] >>>>>>> >>>>>>> or >>>>>>> >>>>>>> cookies[:cookie_key].should == ["expected value"] >>>>>>> >>>>>>> Rails provides a cookies object that is actually >>>>>>> response.cookies, so >>>>>>> you don't *have* to reference it through the response object. >>>>>>> I would, >>>>>>> however, as I've been known to try to set a cookie in an >>>>>>> example using >>>>>>> cookies when I should have been using request.cookies. So I >>>>>>> try to >>>>>>> keep them explicit. >>>>>>> >>>>>>> HTH, >>>>>>> David >>>>>>> _______________________________________________ >>>>>>> rspec-users mailing list >>>>>>> rspec-users at rubyforge.org >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Christopher Bailey >>>>>> Cobalt Edge LLC >>>>>> http://cobaltedge.com >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>> >>>> >>>> >>>> -- >>>> Christopher Bailey >>>> Cobalt Edge LLC >>>> http://cobaltedge.com >>>> >>> >>> >>> >>> -- >>> Christopher Bailey >>> Cobalt Edge LLC >>> http://cobaltedge.com >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Christopher Bailey > Cobalt Edge LLC > http://cobaltedge.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From cdemyanovich at gmail.com Wed Jul 2 14:44:01 2008 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Wed, 2 Jul 2008 14:44:01 -0400 Subject: [rspec-users] Cookies - how to set in controller specs? In-Reply-To: <08DD9E54-26E2-4052-8D71-8DFC83CDAF4E@gmail.com> References: <443c240c0807011637i61a2764bl3dfe460e3ae8745a@mail.gmail.com> <57c63afe0807020406s5ef2209em34d32dffc5d6dbb0@mail.gmail.com> <443c240c0807020915h1ba1817nd8c6b7286d04600e@mail.gmail.com> <443c240c0807020957y47bfa81ds35423ee533cb8de6@mail.gmail.com> <443c240c0807021042k5a243dbapcce1e64c8089ea1@mail.gmail.com> <91498BAC-722B-4924-BF50-43CB0C61071C@gmail.com> <443c240c0807021121m64669937i79961a8de044188f@mail.gmail.com> <08DD9E54-26E2-4052-8D71-8DFC83CDAF4E@gmail.com> Message-ID: <61c885db0807021144w47ec4accid4d176f9eb35a56b@mail.gmail.com> > I'm thinking of replacing the existing cookies() method (in the example) > with one that returns a CookieJarProxy that will allow you to do any of the > following: > > cookies['cookie_key'] = 'cookie value' > cookies[:cookie_key] = 'cookie value' > > cookies['cookie_key'].should == 'cookie value' > cookies[:cookie_key].should == 'cookie value' > > WDYT about that? David, do you plan to allow checks that other values are set as we'd expect? Other values include: * :value * :path * :domain * :expires * :secure * :http_only http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=M000352&name=cookies For example, I'd like to verify that I update the value and expiration date: it "resets the cookie with the value and new expiration date" do get_index cookies[:project_sort][:value].should == "name" cookies[:project_sort][:expires].beginning_of_day.should == 1.year.from_now.beginning_of_day end Thanks, Craig From dchelimsky at gmail.com Wed Jul 2 14:45:13 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Jul 2008 13:45:13 -0500 Subject: [rspec-users] Cookies - how to set in controller specs? In-Reply-To: <61c885db0807021144w47ec4accid4d176f9eb35a56b@mail.gmail.com> References: <443c240c0807011637i61a2764bl3dfe460e3ae8745a@mail.gmail.com> <57c63afe0807020406s5ef2209em34d32dffc5d6dbb0@mail.gmail.com> <443c240c0807020915h1ba1817nd8c6b7286d04600e@mail.gmail.com> <443c240c0807020957y47bfa81ds35423ee533cb8de6@mail.gmail.com> <443c240c0807021042k5a243dbapcce1e64c8089ea1@mail.gmail.com> <91498BAC-722B-4924-BF50-43CB0C61071C@gmail.com> <443c240c0807021121m64669937i79961a8de044188f@mail.gmail.com> <08DD9E54-26E2-4052-8D71-8DFC83CDAF4E@gmail.com> <61c885db0807021144w47ec4accid4d176f9eb35a56b@mail.gmail.com> Message-ID: <91E5FC73-62E4-49C1-9FB9-DCEA9FF5151C@gmail.com> On Jul 2, 2008, at 1:44 PM, Craig Demyanovich wrote: >> I'm thinking of replacing the existing cookies() method (in the >> example) >> with one that returns a CookieJarProxy that will allow you to do >> any of the >> following: >> >> cookies['cookie_key'] = 'cookie value' >> cookies[:cookie_key] = 'cookie value' >> >> cookies['cookie_key'].should == 'cookie value' >> cookies[:cookie_key].should == 'cookie value' >> >> WDYT about that? > > David, do you plan to allow checks that other values are set as we'd > expect? Other values include: > > * :value > * :path > * :domain > * :expires > * :secure > * :http_only > > http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=M000352&name=cookies > > For example, I'd like to verify that I update the value and > expiration date: > > it "resets the cookie with the value and new expiration date" do > get_index > cookies[:project_sort][:value].should == "name" > cookies[:project_sort][:expires].beginning_of_day.should == > 1.year.from_now.beginning_of_day I had not planned that, no :) Let me get the basics working first and we can talk about beefing it up like this later. > > end > > Thanks, > Craig > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jimfreeze at gmail.com Wed Jul 2 15:53:11 2008 From: jimfreeze at gmail.com (Jim Freeze) Date: Wed, 2 Jul 2008 14:53:11 -0500 Subject: [rspec-users] [ANN] Lone Star Ruby Conference 2008 - Registration Now Open Message-ID: <5cd596d60807021253u3775bf75vdfaf242d6e5ad384@mail.gmail.com> (Pardon the interruption) Greetings The Lone Star Ruby Conference, held in Austin, TX on September 4-6, is NOW OPEN for registration. This year we have an amazing line-up of speakers, in addition to Matz, the author of Ruby. We have even added a second track to give you more choices of talks to attend. Also, there is a full day of training on Thursday, Sept 4, where you can sign up for some of the best Ruby training around. Check out the website for details http://LoneStarRubyConf.com and be sure to sign up early before all the seats are gone. -- Jim Freeze Lone Star Ruby Conference http://LoneStarRubyConf.com From srogers1 at gmail.com Wed Jul 2 17:52:40 2008 From: srogers1 at gmail.com (Steve Rogers) Date: Wed, 2 Jul 2008 16:52:40 -0500 Subject: [rspec-users] View spec issue Message-ID: <62579436-FEBE-44D5-8B02-1533FA9517BF@gmail.com> I've been having some view spec issues, and I think I finally traced it to ground - it seems like setting a value in assigns like: assigns[:foo] = "baz" doesn't get used to build the path prefix for a route like: map.resources :widgets , :path_prefix => ':foo' To test it out, I created an empty rails project, rspec-generated a controller/model/specs and all the tests worked. I then added a path prefix and modified the code and specs - everything works except for the view specs. There just doesn't seem to be a way to make it happy about any named route in a view. A route like: < %= link_to 'New widget', new_widget_path %> gets an error like: ActionView::TemplateError in '/widgets/index.html.erb should render list of widgets' new_widget_url failed to generate from {:controller=>"widgets", :action=>"new"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: [:foo, "widgets", "new"] - are they all satisfied? Anyone else seeing something like that? I'm using the head version of rspec/rspec-rails from github and Rails 2.1 SR From ml at e4net.com Wed Jul 2 20:12:43 2008 From: ml at e4net.com (Jim Morris) Date: Wed, 02 Jul 2008 17:12:43 -0700 Subject: [rspec-users] unable to access flash from rails helper spec since upgrade to 1.1.4 Message-ID: <486C197B.2000307@e4net.com> Hi, Many moons ago I wrote this blog entry... http://blog.wolfman.com/articles/2007/07/14/using-rspec-to-test-haml-helpers I just upgraded that rails project to use rspec 1.1.4 and associated rspec_rails. It seems that my helper when called from the helper specs no longer are able to access flash, controller etc as they did before. I already prepended all helper calls with helper. so I fixed those changes, but I have been unable to figure out how to access flash etc... Here is a simplified example... in ApplicationHelper.rb def test_flash for name in [:notice, :warning, :error] if flash[name] return "#{flash[name]}" end end nil end In my rails/spec/helpers/application_helper_spec.rb require File.dirname(__FILE__) + '/../spec_helper' describe ApplicationHelper do it "should test flash" do for name in [:notice, :warning, :error] flash[name]= "flash #{name.to_s} message" helper.test_flash.should match(/.*#{name}.*/) flash[name]= nil end end end I get this error trace... 1) NoMethodError in 'ApplicationHelper should test flash' You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.[] /.../app/helpers/application_helper.rb:23:in `test_flash' ... flash is nil, this used to work, so what is the new magic incantation to get this to work again? Thanks -- Jim Morris, http://blog.wolfman.com From mileshosky at hotmail.com Wed Jul 2 22:58:00 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Wed, 2 Jul 2008 19:58:00 -0700 Subject: [rspec-users] Stopping Example Execution? In-Reply-To: References: <57c63afe0807020415m9df6bdfmfed02ba908746e00@mail.gmail.com> Message-ID: ---------------------------------------- > From: mileshosky at hotmail.com > To: rspec-users at rubyforge.org > Date: Wed, 2 Jul 2008 10:13:59 -0700 > Subject: Re: [rspec-users] Stopping Example Execution? > > > > ---------------------------------------- >> Date: Wed, 2 Jul 2008 06:15:10 -0500 >> From: dchelimsky at gmail.com >> To: rspec-users at rubyforge.org >> Subject: Re: [rspec-users] Stopping Example Execution? >> >> On Mon, Jun 30, 2008 at 5:11 PM, Britt Mileshosky >> wrote: >>> >>> n Sun, Jun 29, 2008 at 12:20 PM, David Chelimsky wrote: >>> On Jun 29, 2008, at 11:18 AM, Britt Mileshosky wrote: >>> >>> However, do you see where something like a return statement or end example statement could be beneficial? >>> If you are working from the top down with your controller action execution, then you only need to test your expectation >>> and then bail out of your action. No need to further test or meet requirements on anything else in that action because your >>> single test has been met. >>> >>> - in my example for making sure I find a user, I'd like to end execution once I DID find the user, i shouldn't have to satisfy >>> requirements about finding an account and a person... I'll write those expectations later in another nested describe group, as you >>> can see here, in a top down process >>> >>> PeopleController with a logged in user >>> - should find user >>> >>> PeopleController with a logged in user who has an account >>> - should find account >>> >>> PeopleController with a logged in user who doesnt have an account >>> - shouldn't find account >>> - should redirect ... >>> >>> PeopleController with a logged in user who has an account the person belongs to >>> - should find person >>> - should assign person for the view >>> >>> PeopleController with a logged in user who has an account the requested person does not belong to >>> - should not find person >>> - should ... >>> >>> My instinct about this is that it would encourage long methods because it would make it less painful to test them, so I would be adverse to anything that let's you short circuit the method. >>> >>> Anybody else have opinions on that? >>> >>> >>> >>> I'm just catching up on email now after being sick for the past six days, but health aside my opinion is that I agree with David's opinion. Rather than focusing on how-to write easier tests that complain less, start focusing on how-to write the right tests that complain when necessary. >>> >>> One of the benefits associated with feeling the pain of a test is that it may be a sign to re-assess and refactor your code. This usually happens early enough that it only takes a few minutes. Short circuiting essentially gives you the ability to not feel the pain. Its like CIPA [0], but for code. I would fear that the code would get so bad that by the time the test cried with pain your code was already beyond easy repair and instead required invasive surgery. >>> >>> Tests are part of the nervous system of your application. When they hurt, they're telling you something isn't right and that it should be addressed, >>> >>> >>> >>> I wouldn't really say that anything I have been presenting has been a result of 'pains', >>> more so an observation on how an example group with other example groups can be much more readable >>> for myself and for other developers when they need to read the specs. Stubbing everything at the top doesn't >>> make complete sense. Why not stub inside the example group that has a NICE describe statement telling you >>> what this stubbing is related to. We can't do this because the first examples will blow up due to having to execute >>> all the code. >>> >>> Take the 2 examples: >>> >>> ------------------------------------------------------------------------------------------------------------------------ >>> PeopleController >>> # stub everything way up here at the top where these >>> # definitions are out of context (by means of position) with following examples >>> # >>> # stub controller requirments >>> # stub logged in requirement >>> # stub account requirement >>> # stub no account requirement >>> # stub account owns person >>> # stub account doesn't own person >>> >>> >>> PeopleController with before filters >>> - should require user >>> >>> PeopleController with a logged in user >>> - should find user >>> >>> PeopleController with a logged in user who has an account >>> - should find account >>> >>> PeopleController with a logged in user who doesnt have an account >>> - shouldn't find account >>> - should redirect ... >>> >>> PeopleController with a logged in user who has an account the person belongs to >>> - should find person >>> - should assign person for the view >>> >>> PeopleController with a logged in user who has an account the requested person does not belong to >>> - should not find person >>> - should ... >>> >>> ------------------------------------------------------------------------------------------------------------------------ >>> PeopleController >>> # stub the minimum needed to get to the first example group up and running >>> >>> PeopleController with before filters >>> - should require user >>> >>> PeopleController with a logged in user >>> # stub logged in requirement >>> - should find user >>> >>> PeopleController with a logged in user who has an account >>> # stub account requirement >>> - should find account >>> >>> PeopleController with a logged in user who doesnt have an account >>> # stub no account requirement >>> - shouldn't find account >>> - should redirect ... >>> >>> PeopleController with a logged in user who has an account the person belongs to >>> # stub account owns person >>> - should find person >>> - should assign person for the view >>> >>> PeopleController with a logged in user who has an account the requested person does not belong to >>> # stub account doesn't own person >>> - should not find person >>> - should ... >>> >>> ------------------------------------------------------------------------------------------------------------------------ >>> >>> I prefer the second group, but unfortunately I am not able to write my specs in this organized fashion. >>> Just sayin. >> >> I appreciate the communication value you're looking for, and you can >> get it by stubbing everything you need to keep execution going >> before(:each) example and then set message expectations >> (should_receive) inside each example that help tell the story of that >> example. >> >> PeopleController >> # stub everything way up here at the top where these >> # definitions are out of context (by means of position) with following examples >> # >> # stub controller requirments >> # stub logged in requirement >> # stub account requirement >> # stub no account requirement >> # stub account owns person >> # stub account doesn't own person >> >> PeopleController with before filters >> - should require user >> >> PeopleController with a logged in user >> # expect logged in query >> - should find user >> >> PeopleController with a logged in user who has an account >> # expect logged in query >> # expect account query >> - should find account >> >> etc >> >> HTH, >> David > > Yep, thats exactly what I've been practicing, and while its not exactly what I want, it does work nicely. > Thank you David I'm gonna make another REALLY strong case for allowing the ability to stop example execution and test code incrementally. I currently have over 1700 examples for the current application I'm working on, and one little line of code that I added in my App controller ( before_filter :set_location ) brought on almost 1100 errors across my tests. Now I know people will say that the requirements weren't understood at the beginning of the application and that it could have been avoided with better planning... but this isn't the case. I now have to go into each of my controller tests and add the stub into every before declaration to clear up my errors. Not fun, and could've been avoided completely. Britt _________________________________________________________________ Enter the Zune-A-Day Giveaway for your chance to win ? day after day after day http://www.windowslive-hotmail.com/ZuneADay/?locale=en-US&ocid=TXT_TAGLM_Mobile_Zune_V1 From dchelimsky at gmail.com Wed Jul 2 23:19:07 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Jul 2008 22:19:07 -0500 Subject: [rspec-users] Stopping Example Execution? In-Reply-To: References: <57c63afe0807020415m9df6bdfmfed02ba908746e00@mail.gmail.com> Message-ID: <1D58DB37-395B-4D4B-9C0C-DA5D604957AA@gmail.com> On Jul 2, 2008, at 9:58 PM, Britt Mileshosky wrote: > ---------------------------------------- >> From: mileshosky at hotmail.com >> To: rspec-users at rubyforge.org >> Date: Wed, 2 Jul 2008 10:13:59 -0700 >> Subject: Re: [rspec-users] Stopping Example Execution? >> >> >> >> ---------------------------------------- >>> Date: Wed, 2 Jul 2008 06:15:10 -0500 >>> From: dchelimsky at gmail.com >>> To: rspec-users at rubyforge.org >>> Subject: Re: [rspec-users] Stopping Example Execution? >>> >>> On Mon, Jun 30, 2008 at 5:11 PM, Britt Mileshosky >>> wrote: >>>> >>>> n Sun, Jun 29, 2008 at 12:20 PM, David Chelimsky wrote: >>>> On Jun 29, 2008, at 11:18 AM, Britt Mileshosky wrote: >>>> >>>> However, do you see where something like a return statement or >>>> end example statement could be beneficial? >>>> If you are working from the top down with your controller action >>>> execution, then you only need to test your expectation >>>> and then bail out of your action. No need to further test or meet >>>> requirements on anything else in that action because your >>>> single test has been met. >>>> >>>> - in my example for making sure I find a user, I'd like to end >>>> execution once I DID find the user, i shouldn't have to satisfy >>>> requirements about finding an account and a person... I'll write >>>> those expectations later in another nested describe group, as you >>>> can see here, in a top down process >>>> >>>> PeopleController with a logged in user >>>> - should find user >>>> >>>> PeopleController with a logged in user who has an account >>>> - should find account >>>> >>>> PeopleController with a logged in user who doesnt have an account >>>> - shouldn't find account >>>> - should redirect ... >>>> >>>> PeopleController with a logged in user who has an account the >>>> person belongs to >>>> - should find person >>>> - should assign person for the view >>>> >>>> PeopleController with a logged in user who has an account the >>>> requested person does not belong to >>>> - should not find person >>>> - should ... >>>> >>>> My instinct about this is that it would encourage long methods >>>> because it would make it less painful to test them, so I would be >>>> adverse to anything that let's you short circuit the method. >>>> >>>> Anybody else have opinions on that? >>>> >>>> >>>> >>>> I'm just catching up on email now after being sick for the past >>>> six days, but health aside my opinion is that I agree with >>>> David's opinion. Rather than focusing on how-to write easier >>>> tests that complain less, start focusing on how-to write the >>>> right tests that complain when necessary. >>>> >>>> One of the benefits associated with feeling the pain of a test is >>>> that it may be a sign to re-assess and refactor your code. This >>>> usually happens early enough that it only takes a few minutes. >>>> Short circuiting essentially gives you the ability to not feel >>>> the pain. Its like CIPA [0], but for code. I would fear that the >>>> code would get so bad that by the time the test cried with pain >>>> your code was already beyond easy repair and instead required >>>> invasive surgery. >>>> >>>> Tests are part of the nervous system of your application. When >>>> they hurt, they're telling you something isn't right and that it >>>> should be addressed, >>>> >>>> >>>> >>>> I wouldn't really say that anything I have been presenting has >>>> been a result of 'pains', >>>> more so an observation on how an example group with other example >>>> groups can be much more readable >>>> for myself and for other developers when they need to read the >>>> specs. Stubbing everything at the top doesn't >>>> make complete sense. Why not stub inside the example group that >>>> has a NICE describe statement telling you >>>> what this stubbing is related to. We can't do this because the >>>> first examples will blow up due to having to execute >>>> all the code. >>>> >>>> Take the 2 examples: >>>> >>>> ------------------------------------------------------------------------------------------------------------------------ >>>> PeopleController >>>> # stub everything way up here at the top where these >>>> # definitions are out of context (by means of position) with >>>> following examples >>>> # >>>> # stub controller requirments >>>> # stub logged in requirement >>>> # stub account requirement >>>> # stub no account requirement >>>> # stub account owns person >>>> # stub account doesn't own person >>>> >>>> >>>> PeopleController with before filters >>>> - should require user >>>> >>>> PeopleController with a logged in user >>>> - should find user >>>> >>>> PeopleController with a logged in user who has an account >>>> - should find account >>>> >>>> PeopleController with a logged in user who doesnt have an account >>>> - shouldn't find account >>>> - should redirect ... >>>> >>>> PeopleController with a logged in user who has an account the >>>> person belongs to >>>> - should find person >>>> - should assign person for the view >>>> >>>> PeopleController with a logged in user who has an account the >>>> requested person does not belong to >>>> - should not find person >>>> - should ... >>>> >>>> ------------------------------------------------------------------------------------------------------------------------ >>>> PeopleController >>>> # stub the minimum needed to get to the first example group up >>>> and running >>>> >>>> PeopleController with before filters >>>> - should require user >>>> >>>> PeopleController with a logged in user >>>> # stub logged in requirement >>>> - should find user >>>> >>>> PeopleController with a logged in user who has an account >>>> # stub account requirement >>>> - should find account >>>> >>>> PeopleController with a logged in user who doesnt have an account >>>> # stub no account requirement >>>> - shouldn't find account >>>> - should redirect ... >>>> >>>> PeopleController with a logged in user who has an account the >>>> person belongs to >>>> # stub account owns person >>>> - should find person >>>> - should assign person for the view >>>> >>>> PeopleController with a logged in user who has an account the >>>> requested person does not belong to >>>> # stub account doesn't own person >>>> - should not find person >>>> - should ... >>>> >>>> ------------------------------------------------------------------------------------------------------------------------ >>>> >>>> I prefer the second group, but unfortunately I am not able to >>>> write my specs in this organized fashion. >>>> Just sayin. >>> >>> I appreciate the communication value you're looking for, and you can >>> get it by stubbing everything you need to keep execution going >>> before(:each) example and then set message expectations >>> (should_receive) inside each example that help tell the story of >>> that >>> example. >>> >>> PeopleController >>> # stub everything way up here at the top where these >>> # definitions are out of context (by means of position) with >>> following examples >>> # >>> # stub controller requirments >>> # stub logged in requirement >>> # stub account requirement >>> # stub no account requirement >>> # stub account owns person >>> # stub account doesn't own person >>> >>> PeopleController with before filters >>> - should require user >>> >>> PeopleController with a logged in user >>> # expect logged in query >>> - should find user >>> >>> PeopleController with a logged in user who has an account >>> # expect logged in query >>> # expect account query >>> - should find account >>> >>> etc >>> >>> HTH, >>> David >> >> Yep, thats exactly what I've been practicing, and while its not >> exactly what I want, it does work nicely. >> Thank you David > > > I'm gonna make another REALLY strong case for allowing the ability > to stop example execution and test code incrementally. I currently > have over 1700 examples for the current application I'm working on, > and one little line of code that I added in my App controller > ( before_filter :set_location ) brought on almost 1100 errors across > my tests. Now I know people will say that the requirements weren't > understood at the beginning of the application and that it could > have been avoided with better planning... RSpec < BDD < Agile < Embrace Change. I don't think you'd see that argument here. > but this isn't the case. > > I now have to go into each of my controller tests and add the stub > into every before declaration to clear up my errors. Not fun, and > could've been avoided completely. Yes, it could have, with the existing tools! Try this next time: Spec::Runner.configure do |config| config.before(:each, :type => :controller) do controller.stub!(:set_location) if controller.respond_to? (:set_location) end end Hey Britt - I appreciate your passion for this feature, but I have to say that I'm as passionately against it as you are for it, for reasons I've cited and others have echoed. That said, this is open source. If you want to make this happen then you have a few options. You can write your own gem that extends rspec to do it. You can even fork rspec and add it to your fork, though I think we'd all be better served if you did it in a separate gem. In either case, that would get you the feature you want and give other people a chance to try it out. And if it evolves into an essential feature that a lot of people find real value in, I'd be willing to look at it again. But until such time as its proven itself otherwise, this feature seems more potentially harmful than useful to me. FWIW, David From dchelimsky at gmail.com Wed Jul 2 23:54:40 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 2 Jul 2008 22:54:40 -0500 Subject: [rspec-users] unable to access flash from rails helper spec since upgrade to 1.1.4 In-Reply-To: <486C197B.2000307@e4net.com> References: <486C197B.2000307@e4net.com> Message-ID: <1C4A805E-789E-4778-AA8E-58FBB0F376DA@gmail.com> On Jul 2, 2008, at 7:12 PM, Jim Morris wrote: > Hi, > > Many moons ago I wrote this blog entry... > > http://blog.wolfman.com/articles/2007/07/14/using-rspec-to-test-haml-helpers > > I just upgraded that rails project to use rspec 1.1.4 and associated > rspec_rails. > > It seems that my helper when called from the helper specs no longer > are able to access flash, controller etc as they did before. > > I already prepended all helper calls with helper. so I fixed those > changes, but I have been unable to figure out how to access flash > etc... > > Here is a simplified example... > > in ApplicationHelper.rb > > def test_flash > for name in [:notice, :warning, :error] > if flash[name] > return "#{flash[name]}" > end > end > nil > end > > In my rails/spec/helpers/application_helper_spec.rb > > require File.dirname(__FILE__) + '/../spec_helper' > > describe ApplicationHelper do > > it "should test flash" do > for name in [:notice, :warning, :error] > flash[name]= "flash #{name.to_s} message" > helper.test_flash.should match(/.*#{name}.*/) > flash[name]= nil > end > end > > end > > I get this error trace... > 1) > NoMethodError in 'ApplicationHelper should test flash' > You have a nil object when you didn't expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.[] > /.../app/helpers/application_helper.rb:23:in `test_flash' > ... > > flash is nil, this used to work, so what is the new magic > incantation to get this to work again? Hey Jim - I fixed this in http://github.com/dchelimsky/rspec-rails/commit/40a0916325dbe9a1631849146d078e330fca71f2 , so you can either grab the very latest from github or wait for the 1.1.5 release (coming in the next few days). Cheers, David From zach.dennis at gmail.com Thu Jul 3 00:03:14 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 3 Jul 2008 00:03:14 -0400 Subject: [rspec-users] Stopping Example Execution? In-Reply-To: References: <57c63afe0807020415m9df6bdfmfed02ba908746e00@mail.gmail.com> Message-ID: <85d99afe0807022103t6783a64bw86d95c05cc5fea6e@mail.gmail.com> One good way (IMO) to approach before filters is to always stub them when it comes time to testing a controller action. And to test the filter separately in isolation. For example if you need to define an application level before filter in ApplicationController, then test the filter in isolation using an application_controller_spec. If you'd like to know that your controllers which subclass ApplicationController use them, you can easily add a declarative style "it" helper which verifies that the filter is being used, but doesn't test the filter (since you already did that in your application_controller_spec. I know this doesn't help you now, but it is a useful technique which you can use in the future to limit the maintenance nightmare that can come along with things like before filters, Zach On Wed, Jul 2, 2008 at 10:58 PM, Britt Mileshosky wrote: > > > ---------------------------------------- > > From: mileshosky at hotmail.com > > To: rspec-users at rubyforge.org > > Date: Wed, 2 Jul 2008 10:13:59 -0700 > > Subject: Re: [rspec-users] Stopping Example Execution? > > > > > > > > ---------------------------------------- > >> Date: Wed, 2 Jul 2008 06:15:10 -0500 > >> From: dchelimsky at gmail.com > >> To: rspec-users at rubyforge.org > >> Subject: Re: [rspec-users] Stopping Example Execution? > >> > >> On Mon, Jun 30, 2008 at 5:11 PM, Britt Mileshosky > >> wrote: > >>> > >>> n Sun, Jun 29, 2008 at 12:20 PM, David Chelimsky wrote: > >>> On Jun 29, 2008, at 11:18 AM, Britt Mileshosky wrote: > >>> > >>> However, do you see where something like a return statement or end > example statement could be beneficial? > >>> If you are working from the top down with your controller action > execution, then you only need to test your expectation > >>> and then bail out of your action. No need to further test or meet > requirements on anything else in that action because your > >>> single test has been met. > >>> > >>> - in my example for making sure I find a user, I'd like to end > execution once I DID find the user, i shouldn't have to satisfy > >>> requirements about finding an account and a person... I'll write those > expectations later in another nested describe group, as you > >>> can see here, in a top down process > >>> > >>> PeopleController with a logged in user > >>> - should find user > >>> > >>> PeopleController with a logged in user who has an account > >>> - should find account > >>> > >>> PeopleController with a logged in user who doesnt have an account > >>> - shouldn't find account > >>> - should redirect ... > >>> > >>> PeopleController with a logged in user who has an account the person > belongs to > >>> - should find person > >>> - should assign person for the view > >>> > >>> PeopleController with a logged in user who has an account the requested > person does not belong to > >>> - should not find person > >>> - should ... > >>> > >>> My instinct about this is that it would encourage long methods because > it would make it less painful to test them, so I would be adverse to > anything that let's you short circuit the method. > >>> > >>> Anybody else have opinions on that? > >>> > >>> > >>> > >>> I'm just catching up on email now after being sick for the past six > days, but health aside my opinion is that I agree with David's opinion. > Rather than focusing on how-to write easier tests that complain less, start > focusing on how-to write the right tests that complain when necessary. > >>> > >>> One of the benefits associated with feeling the pain of a test is that > it may be a sign to re-assess and refactor your code. This usually happens > early enough that it only takes a few minutes. Short circuiting essentially > gives you the ability to not feel the pain. Its like CIPA [0], but for code. > I would fear that the code would get so bad that by the time the test cried > with pain your code was already beyond easy repair and instead required > invasive surgery. > >>> > >>> Tests are part of the nervous system of your application. When they > hurt, they're telling you something isn't right and that it should be > addressed, > >>> > >>> > >>> > >>> I wouldn't really say that anything I have been presenting has been a > result of 'pains', > >>> more so an observation on how an example group with other example > groups can be much more readable > >>> for myself and for other developers when they need to read the specs. > Stubbing everything at the top doesn't > >>> make complete sense. Why not stub inside the example group that has a > NICE describe statement telling you > >>> what this stubbing is related to. We can't do this because the first > examples will blow up due to having to execute > >>> all the code. > >>> > >>> Take the 2 examples: > >>> > >>> > ------------------------------------------------------------------------------------------------------------------------ > >>> PeopleController > >>> # stub everything way up here at the top where these > >>> # definitions are out of context (by means of position) with following > examples > >>> # > >>> # stub controller requirments > >>> # stub logged in requirement > >>> # stub account requirement > >>> # stub no account requirement > >>> # stub account owns person > >>> # stub account doesn't own person > >>> > >>> > >>> PeopleController with before filters > >>> - should require user > >>> > >>> PeopleController with a logged in user > >>> - should find user > >>> > >>> PeopleController with a logged in user who has an account > >>> - should find account > >>> > >>> PeopleController with a logged in user who doesnt have an account > >>> - shouldn't find account > >>> - should redirect ... > >>> > >>> PeopleController with a logged in user who has an account the person > belongs to > >>> - should find person > >>> - should assign person for the view > >>> > >>> PeopleController with a logged in user who has an account the requested > person does not belong to > >>> - should not find person > >>> - should ... > >>> > >>> > ------------------------------------------------------------------------------------------------------------------------ > >>> PeopleController > >>> # stub the minimum needed to get to the first example group up and > running > >>> > >>> PeopleController with before filters > >>> - should require user > >>> > >>> PeopleController with a logged in user > >>> # stub logged in requirement > >>> - should find user > >>> > >>> PeopleController with a logged in user who has an account > >>> # stub account requirement > >>> - should find account > >>> > >>> PeopleController with a logged in user who doesnt have an account > >>> # stub no account requirement > >>> - shouldn't find account > >>> - should redirect ... > >>> > >>> PeopleController with a logged in user who has an account the person > belongs to > >>> # stub account owns person > >>> - should find person > >>> - should assign person for the view > >>> > >>> PeopleController with a logged in user who has an account the requested > person does not belong to > >>> # stub account doesn't own person > >>> - should not find person > >>> - should ... > >>> > >>> > ------------------------------------------------------------------------------------------------------------------------ > >>> > >>> I prefer the second group, but unfortunately I am not able to write my > specs in this organized fashion. > >>> Just sayin. > >> > >> I appreciate the communication value you're looking for, and you can > >> get it by stubbing everything you need to keep execution going > >> before(:each) example and then set message expectations > >> (should_receive) inside each example that help tell the story of that > >> example. > >> > >> PeopleController > >> # stub everything way up here at the top where these > >> # definitions are out of context (by means of position) with following > examples > >> # > >> # stub controller requirments > >> # stub logged in requirement > >> # stub account requirement > >> # stub no account requirement > >> # stub account owns person > >> # stub account doesn't own person > >> > >> PeopleController with before filters > >> - should require user > >> > >> PeopleController with a logged in user > >> # expect logged in query > >> - should find user > >> > >> PeopleController with a logged in user who has an account > >> # expect logged in query > >> # expect account query > >> - should find account > >> > >> etc > >> > >> HTH, > >> David > > > > Yep, thats exactly what I've been practicing, and while its not exactly > what I want, it does work nicely. > > Thank you David > > > I'm gonna make another REALLY strong case for allowing the ability to stop > example execution and test code incrementally. I currently have over 1700 > examples for the current application I'm working on, and one little line of > code that I added in my App controller ( before_filter :set_location ) > brought on almost 1100 errors across my tests. Now I know people will say > that the requirements weren't understood at the beginning of the application > and that it could have been avoided with better planning... but this isn't > the case. > > I now have to go into each of my controller tests and add the stub into > every before declaration to clear up my errors. Not fun, and could've been > avoided completely. > > Britt > > _________________________________________________________________ > Enter the Zune-A-Day Giveaway for your chance to win ? day after day after > day > > http://www.windowslive-hotmail.com/ZuneADay/?locale=en-US&ocid=TXT_TAGLM_Mobile_Zune_V1 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Thu Jul 3 01:57:30 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 2 Jul 2008 22:57:30 -0700 Subject: [rspec-users] Stopping example execution? In-Reply-To: References: <60f3810c0806281624y3130ba6eq7674b71f9b9c1e8f@mail.gmail.com> <62D4CE49-947E-4027-BF34-CD6326643F83@gmail.com> Message-ID: <810a540e0807022257n3711dc88rc7f7daf63f852ca1@mail.gmail.com> On Sun, Jun 29, 2008 at 9:18 AM, Britt Mileshosky wrote: > > However, do you see where something like a return statement or end example statement could be beneficial? > If you are working from the top down with your controller action execution, then you only need to test your expectation > and then bail out of your action. No need to further test or meet requirements on anything else in that action because your > single test has been met. > > - in my example for making sure I find a user, I'd like to end execution once I DID find the user, i shouldn't have to satisfy > requirements about finding an account and a person... I'll write those expectations later in another nested describe group, as you > can see here, in a top down process > > PeopleController with a logged in user > - should find user > > PeopleController with a logged in user who has an account > - should find account > > PeopleController with a logged in user who doesnt have an account > - shouldn't find account > - should redirect ... > > PeopleController with a logged in user who has an account the person belongs to > - should find person > - should assign person for the view > > PeopleController with a logged in user who has an account the requested person does not belong to > - should not find person > - should ... Hi Britt, Quick little thought experiment for you: Imagine you write the examples as you have described, stubbing only the minimum amount of things necessary and then ending the example once you've reached a certain point. So for the action def some_action @user = self.current_user @account = self.current_account if self.has_account? @person = @account.people.find(params[:person]) end your first example only runs until current_user, your second example runs only until has_account, and your third one runs only until account.people.find. So far so good. What happens when you change the implementation to: def some_action @user = self.current_user if self.has_account? @account = self.current_account @person = @account.people.find(params[:person]) end end which I could totally see doing, given that the original implementation will raise an error on the @account.people call on those occasions where has_account? returns false, making @account nil. Can you spot the problem? Your specs will now fail because you had only stubbed enough to get to a particular line. The specs are very tightly coupled to the implementation, which sucks. Also, if you were to do this incremental stubbing, you would have a hard time moving examples around, because the nested examples would rely on context set up by the parents. This technique, after looking a bit more deeply at it, would lead to specs that are tightly coupled to the implementation and to each other. Tight coupling is usually bad, and tight coupling from both angles is a recipe for total frustration. I hope that is helpful. Pat From ml at e4net.com Thu Jul 3 02:29:53 2008 From: ml at e4net.com (Jim Morris) Date: Wed, 02 Jul 2008 23:29:53 -0700 Subject: [rspec-users] unable to access flash from rails helper spec since upgrade to 1.1.4 In-Reply-To: <1C4A805E-789E-4778-AA8E-58FBB0F376DA@gmail.com> References: <486C197B.2000307@e4net.com> <1C4A805E-789E-4778-AA8E-58FBB0F376DA@gmail.com> Message-ID: <486C71E1.8010804@e4net.com> Hi David, Thanks that worked, and fixed that problem. Now I have run into another problem, from the same blog example (which I'll update once I get it all to work). Within the application helper I call haml_tag, which works fine when the app runs. (used to be called open). However when I try to test that helper in my helper spec I get... NoMethodError in 'ApplicationHelper should display flash' undefined method `haml_tag' for # For some reason it doesn't know anything about haml when run from the spec. I guess I need to inject a require haml or something into the HelperObject? I just don't know how to do that. I am using the latest version of HAML but I am still using rails 1.2.6 Any ideas? Thanks Jim David Chelimsky wrote: > On Jul 2, 2008, at 7:12 PM, Jim Morris wrote: > >> Hi, >> >> Many moons ago I wrote this blog entry... >> >> http://blog.wolfman.com/articles/2007/07/14/using-rspec-to-test-haml-helpers >> >> >> I just upgraded that rails project to use rspec 1.1.4 and associated >> rspec_rails. >> >> It seems that my helper when called from the helper specs no longer >> are able to access flash, controller etc as they did before. >> >> I already prepended all helper calls with helper. so I fixed those >> changes, but I have been unable to figure out how to access flash etc... >> >> Here is a simplified example... >> >> in ApplicationHelper.rb >> >> def test_flash >> for name in [:notice, :warning, :error] >> if flash[name] >> return "#{flash[name]}" >> end >> end >> nil >> end >> >> In my rails/spec/helpers/application_helper_spec.rb >> >> require File.dirname(__FILE__) + '/../spec_helper' >> >> describe ApplicationHelper do >> >> it "should test flash" do >> for name in [:notice, :warning, :error] >> flash[name]= "flash #{name.to_s} message" >> helper.test_flash.should match(/.*#{name}.*/) >> flash[name]= nil >> end >> end >> >> end >> >> I get this error trace... >> 1) >> NoMethodError in 'ApplicationHelper should test flash' >> You have a nil object when you didn't expect it! >> You might have expected an instance of Array. >> The error occurred while evaluating nil.[] >> /.../app/helpers/application_helper.rb:23:in `test_flash' >> ... >> >> flash is nil, this used to work, so what is the new magic incantation >> to get this to work again? > > Hey Jim - I fixed this in > http://github.com/dchelimsky/rspec-rails/commit/40a0916325dbe9a1631849146d078e330fca71f2, > so you can either grab the very latest from github or wait for the 1.1.5 > release (coming in the next few days). > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Jim Morris, http://blog.wolfman.com From lists at ruby-forum.com Thu Jul 3 03:24:15 2008 From: lists at ruby-forum.com (Damian Terentiev) Date: Thu, 3 Jul 2008 09:24:15 +0200 Subject: [rspec-users] Controller spec gives strange error Message-ID: Good day! I have a Rails app with a controller that sets an instance variable in a before_filter, like this: class PostsController < ApplicationController before_filter :set_site_language def set_site_language @site_language = cookie['lang'] ? Language.find_by_code(cookie['lang']) : Language.find(:first) end def index @posts = Post.find_by_language_id(@site_language.id) end end The controller has the following spec: describe PostsController do it "should show home page" do get :index response.should be_success end end And the equivalent test: class PostsControllerTest < ActionController::TestCase def test_should_show_home_page get :index assert_response :success end end The test runs fine, but the spec fails with the following error on line with `@posts = Post.find_by_language_id(@site_language.id)`: RuntimeError in 'PostsController should show home page' Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id Seems that @site_language does not get assigned when spec runs. Could you please help me solve this problem? Yours, Damian -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Jul 3 03:39:18 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 3 Jul 2008 02:39:18 -0500 Subject: [rspec-users] unable to access flash from rails helper spec since upgrade to 1.1.4 In-Reply-To: <486C71E1.8010804@e4net.com> References: <486C197B.2000307@e4net.com> <1C4A805E-789E-4778-AA8E-58FBB0F376DA@gmail.com> <486C71E1.8010804@e4net.com> Message-ID: <5F49DCC8-F8BE-4178-A11E-7D2F234D72EC@gmail.com> On Jul 3, 2008, at 1:29 AM, Jim Morris wrote: > Hi David, > > Thanks that worked, and fixed that problem. > > Now I have run into another problem, from the same blog example > (which I'll update once I get it all to work). > > Within the application helper I call haml_tag, which works fine when > the app runs. (used to be called open). > > However when I try to test that helper in my helper spec I get... > > NoMethodError in 'ApplicationHelper should display flash' > undefined method `haml_tag' for > # > > For some reason it doesn't know anything about haml when run from > the spec. > > I guess I need to inject a require haml or something into the > HelperObject? I just don't know how to do that. Try this: before(:each) do helper.extend Haml::Helpers end it "should ...." do ... end > > > I am using the latest version of HAML but I am still using rails 1.2.6 > > Any ideas? > > Thanks > Jim > > David Chelimsky wrote: >> On Jul 2, 2008, at 7:12 PM, Jim Morris wrote: >>> Hi, >>> >>> Many moons ago I wrote this blog entry... >>> >>> http://blog.wolfman.com/articles/2007/07/14/using-rspec-to-test-haml-helpers >>> >>> I just upgraded that rails project to use rspec 1.1.4 and >>> associated rspec_rails. >>> >>> It seems that my helper when called from the helper specs no >>> longer are able to access flash, controller etc as they did before. >>> >>> I already prepended all helper calls with helper. so I fixed those >>> changes, but I have been unable to figure out how to access flash >>> etc... >>> >>> Here is a simplified example... >>> >>> in ApplicationHelper.rb >>> >>> def test_flash >>> for name in [:notice, :warning, :error] >>> if flash[name] >>> return "#{flash[name]}" >>> end >>> end >>> nil >>> end >>> >>> In my rails/spec/helpers/application_helper_spec.rb >>> >>> require File.dirname(__FILE__) + '/../spec_helper' >>> >>> describe ApplicationHelper do >>> >>> it "should test flash" do >>> for name in [:notice, :warning, :error] >>> flash[name]= "flash #{name.to_s} message" >>> helper.test_flash.should match(/.*#{name}.*/) >>> flash[name]= nil >>> end >>> end >>> >>> end >>> >>> I get this error trace... >>> 1) >>> NoMethodError in 'ApplicationHelper should test flash' >>> You have a nil object when you didn't expect it! >>> You might have expected an instance of Array. >>> The error occurred while evaluating nil.[] >>> /.../app/helpers/application_helper.rb:23:in `test_flash' >>> ... >>> >>> flash is nil, this used to work, so what is the new magic >>> incantation to get this to work again? >> Hey Jim - I fixed this in http://github.com/dchelimsky/rspec-rails/commit/40a0916325dbe9a1631849146d078e330fca71f2 >> , so you can either grab the very latest from github or wait for >> the 1.1.5 release (coming in the next few days). >> Cheers, >> David >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > -- > Jim Morris, http://blog.wolfman.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Jul 3 03:44:19 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 3 Jul 2008 02:44:19 -0500 Subject: [rspec-users] Controller spec gives strange error In-Reply-To: References: Message-ID: <3E30998C-6A4E-43F7-AE33-A4A19D31D2EE@gmail.com> On Jul 3, 2008, at 2:24 AM, Damian Terentiev wrote: > Good day! > > I have a Rails app with a controller that sets an instance variable > in a > before_filter, like this: > > class PostsController < ApplicationController > > before_filter :set_site_language > > def set_site_language > @site_language = cookie['lang'] ? > Language.find_by_code(cookie['lang']) : > Language.find(:first) Shouldn't this be cookies, not cookie? Doesn't explain why the test passes when the example fails, but it seems that both should be raising errors on this. > > end > > def index > @posts = Post.find_by_language_id(@site_language.id) > end > > end > > The controller has the following spec: > > describe PostsController do > > it "should show home page" do > get :index > response.should be_success > end > > end > > And the equivalent test: > > class PostsControllerTest < ActionController::TestCase > > def test_should_show_home_page > get :index > assert_response :success > end > > end > > The test runs fine, but the spec fails with the following error on > line > with `@posts = Post.find_by_language_id(@site_language.id)`: > > RuntimeError in 'PostsController should show home page' > Called id for nil, which would mistakenly be 4 -- if you really wanted > the id of nil, use object_id > > Seems that @site_language does not get assigned when spec runs. Could > you please help me solve this problem? > > Yours, > Damian > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Thu Jul 3 03:51:32 2008 From: lists at ruby-forum.com (Damian Terentiev) Date: Thu, 3 Jul 2008 09:51:32 +0200 Subject: [rspec-users] Controller spec gives strange error In-Reply-To: <3E30998C-6A4E-43F7-AE33-A4A19D31D2EE@gmail.com> References: <3E30998C-6A4E-43F7-AE33-A4A19D31D2EE@gmail.com> Message-ID: <3da282f01a5ce18a1e0222a287906a6e@ruby-forum.com> David Chelimsky wrote: > On Jul 3, 2008, at 2:24 AM, Damian Terentiev wrote: > >> def set_site_language >> @site_language = cookie['lang'] ? >> Language.find_by_code(cookie['lang']) : >> Language.find(:first) > > Shouldn't this be cookies, not cookie? Doesn't explain why the test > passes when the example fails, but it seems that both should be > raising errors on this. Yes, there should be `cookies`, but the problem still exists. -- Posted via http://www.ruby-forum.com/. From dhf0820 at gmail.com Thu Jul 3 04:08:39 2008 From: dhf0820 at gmail.com (Don French) Date: Thu, 3 Jul 2008 01:08:39 -0700 (PDT) Subject: [rspec-users] autotest failing on startup Message-ID: <18246365.post@talk.nabble.com> I have been using autotest/zentest 3.5.0 with my rails 2.0.2 and rspec. I upgraded my gems and got 3.9.3 and had a problem. I went back to 3.5.0 and it worked. I stayed there until moving to rails 2.1. I again updated my gems and got 3.10. This one had the same problem. This time I need to figure out what is wrong. Here is what I get: /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:394:in `find_files_to_test': undefined method `values' for # (NoMethodError) from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:239:in `run_tests' from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:228:in `get_to_green' from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:208:in `run' from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:206:in `loop' from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:206:in `run' from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:136:in `run' from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/bin/autotest:55 from /usr/bin/autotest:19:in `load' from /usr/bin/autotest:19 Here is the failing code: def find_files result = {} targets = self.find_directories + self.extra_files self.find_order.clear targets.each do |target| order = [] Find.find(target) do |f| Find.prune if f =~ self.exceptions next if test ?d, f next if f =~ /(swp|~|rej|orig)$/ # temporary/patch files next if f =~ /\/\.?#/ # Emacs autosave/cvs merge files filename = f.sub(/^\.\//, '') result[filename] = File.stat(filename).mtime rescue next order << filename end self.find_order.push(*order.sort) end return result # this should return as a hash but is received as an array end ## # Find the files which have been modified, update the recorded # timestamps, and use this to update the files to test. Returns true # if any file is newer than the previously recorded most recent # file. def find_files_to_test(files=find_files) # for some reason files comes in as a array needs to be hash #myfiles = {} #files.each do |key, value| #myfiles[key] = value #end #files = myfiles updated = files.select { |filename, mtime| self.last_mtime < mtime } p updated if $v unless updated.empty? or self.last_mtime.to_i == 0 updated.map { |f,m| test_files_for(f) }.flatten.uniq.each do |filename| self.files_to_test[filename] # creates key with default value end if updated.empty? then nil else files.values.max <= line 394 end end For some reason the files is an array instead of a hash. I added the little change that is commented out and it works. But that should not have to be done. Any ideas? -- View this message in context: http://www.nabble.com/autotest-failing-on-startup-tp18246365p18246365.html Sent from the rspec-users mailing list archive at Nabble.com. From dhf0820 at gmail.com Thu Jul 3 04:15:40 2008 From: dhf0820 at gmail.com (Don French) Date: Thu, 3 Jul 2008 01:15:40 -0700 (PDT) Subject: [rspec-users] Error on Autotest start Message-ID: <18254059.post@talk.nabble.com> I have been using autotest/zentest 3.5.0 with my rails 2.0.2 and rspec. I upgraded my gems and got 3.9.3 and had a problem. I went back to 3.5.0 and it worked. I stayed there until moving to rails 2.1. I again updated my gems and got 3.10. This one had the same problem. This time I need to figure out what is wrong. Here is what I get: /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:394:in `find_files_to_test': undefined method `values' for # (NoMethodError) from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:239:in `run_tests' from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:228:in `get_to_green' from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:208:in `run' from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:206:in `loop' from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:206:in `run' from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:136:in `run' from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/bin/autotest:55 from /usr/bin/autotest:19:in `load' from /usr/bin/autotest:19 Here is the failing code: def find_files result = {} targets = self.find_directories + self.extra_files self.find_order.clear targets.each do |target| order = [] Find.find(target) do |f| Find.prune if f =~ self.exceptions next if test ?d, f next if f =~ /(swp|~|rej|orig)$/ # temporary/patch files next if f =~ /\/\.?#/ # Emacs autosave/cvs merge files filename = f.sub(/^\.\//, '') result[filename] = File.stat(filename).mtime rescue next order << filename end self.find_order.push(*order.sort) end return result # this should return as a hash but is received as an array end ## # Find the files which have been modified, update the recorded # timestamps, and use this to update the files to test. Returns true # if any file is newer than the previously recorded most recent # file. def find_files_to_test(files=find_files) # for some reason files comes in as a array needs to be hash #myfiles = {} #files.each do |key, value| #myfiles[key] = value #end #files = myfiles updated = files.select { |filename, mtime| self.last_mtime < mtime } p updated if $v unless updated.empty? or self.last_mtime.to_i == 0 updated.map { |f,m| test_files_for(f) }.flatten.uniq.each do |filename| self.files_to_test[filename] # creates key with default value end if updated.empty? then nil else files.values.max <= line 394 end end For some reason the files is an array instead of a hash. I added the little change that is commented out and it works. But that should not have to be done. Any ideas? -- View this message in context: http://www.nabble.com/Error-on-Autotest-start-tp18254059p18254059.html Sent from the rspec-users mailing list archive at Nabble.com. From jleddy at obtiva.com Thu Jul 3 08:22:08 2008 From: jleddy at obtiva.com (Joseph Leddy) Date: Thu, 3 Jul 2008 07:22:08 -0500 Subject: [rspec-users] (no subject) Message-ID: <8DFCA77A-FEF5-40CA-A634-A94D090BF632@obtiva.com> Sent from my mobile From matt at matt-darby.com Thu Jul 3 08:27:17 2008 From: matt at matt-darby.com (Matt Darby) Date: Thu, 3 Jul 2008 05:27:17 -0700 (PDT) Subject: [rspec-users] Odd Date-based spec failing In-Reply-To: <3B6415BF-3E17-4B5C-A74E-9DA66161D0EC@matt-darby.com> References: <5e2dde260806301940i7342b4ddw2a6c4c2158d51c8a@mail.gmail.com> <810a540e0806302310l50ce8434v1923aa413d38645@mail.gmail.com> <79205FC9-628C-4595-A65C-D5CFA9325A6C@matt-darby.com> <24E4D2F0-172E-48AD-B28D-E84FC9E7882E@experthuman.com> <3B6415BF-3E17-4B5C-A74E-9DA66161D0EC@matt-darby.com> Message-ID: <9fef42ec-cebf-476c-857f-03cec6d278d9@27g2000hsf.googlegroups.com> On Jul 1, 11:21?am, Matt Darby wrote: > On Jul 1, 2008, at 8:23 AM, Tom Stuart wrote: > > > $ ./script/console > > >> Date.today.minus_with_duration(5.days) > > => Thu, 26 Jun 2008 > > >> Date.today.minus_without_duration(5.days.to_i) > > => Sun, 17 Sep 0825 > > > Is this a load-order problem? Perhaps ? > > ActiveSupport::CoreExtensions::Date::Calculations isn't kicking in ? > > correctly. Anyone else have thoughts on this? From dchelimsky at gmail.com Thu Jul 3 09:27:58 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 3 Jul 2008 08:27:58 -0500 Subject: [rspec-users] autotest failing on startup In-Reply-To: <18246365.post@talk.nabble.com> References: <18246365.post@talk.nabble.com> Message-ID: On Jul 3, 2008, at 3:08 AM, Don French wrote: > I have been using autotest/zentest 3.5.0 with my rails 2.0.2 and > rspec. I > upgraded my gems and got 3.9.3 and had a problem. I went back to > 3.5.0 and > it worked. I stayed there until moving to rails 2.1. I again updated > my gems > and got 3.10. This one had the same problem. This time I need to > figure out > what is wrong. Here is what I get: > > /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:394:in > `find_files_to_test': undefined method `values' for # > (NoMethodError) > from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: > 239:in > `run_tests' > from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: > 228:in > `get_to_green' > from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: > 208:in > `run' > from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: > 206:in > `loop' > from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: > 206:in > `run' > from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: > 136:in > `run' > from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/bin/autotest:55 > from /usr/bin/autotest:19:in `load' > from /usr/bin/autotest:19 This is all autotest so I don't think it's related to rspec. That said, what version of rspec are you using? > Here is the failing code: > > def find_files > result = {} > targets = self.find_directories + self.extra_files > self.find_order.clear > > targets.each do |target| > order = [] > Find.find(target) do |f| > Find.prune if f =~ self.exceptions > > next if test ?d, f > next if f =~ /(swp|~|rej|orig)$/ # temporary/patch files > next if f =~ /\/\.?#/ # Emacs autosave/cvs merge > files > > filename = f.sub(/^\.\//, '') > > result[filename] = File.stat(filename).mtime rescue next > order << filename > end > self.find_order.push(*order.sort) > end > return result # this should return as a hash but is received as an > array > end > > ## > # Find the files which have been modified, update the recorded > # timestamps, and use this to update the files to test. Returns true > # if any file is newer than the previously recorded most recent > # file. > > def find_files_to_test(files=find_files) > # for some reason files comes in as a array needs to be hash > #myfiles = {} > #files.each do |key, value| > #myfiles[key] = value > #end > #files = myfiles > updated = files.select { |filename, mtime| self.last_mtime < > mtime } > > p updated if $v unless updated.empty? or self.last_mtime.to_i == 0 > > updated.map { |f,m| test_files_for(f) }.flatten.uniq.each do | > filename| > self.files_to_test[filename] # creates key with default value > end > > if updated.empty? then > nil > else > files.values.max <= line 394 > end > end > > For some reason the files is an array instead of a hash. I added > the little > change that is commented out and it works. But that should not have > to be > done. > > Any ideas? > > > -- > View this message in context: http://www.nabble.com/autotest-failing-on-startup-tp18246365p18246365.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Thu Jul 3 11:06:05 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 3 Jul 2008 11:06:05 -0400 Subject: [rspec-users] Odd Date-based spec failing In-Reply-To: <9fef42ec-cebf-476c-857f-03cec6d278d9@27g2000hsf.googlegroups.com> References: <5e2dde260806301940i7342b4ddw2a6c4c2158d51c8a@mail.gmail.com> <810a540e0806302310l50ce8434v1923aa413d38645@mail.gmail.com> <79205FC9-628C-4595-A65C-D5CFA9325A6C@matt-darby.com> <24E4D2F0-172E-48AD-B28D-E84FC9E7882E@experthuman.com> <3B6415BF-3E17-4B5C-A74E-9DA66161D0EC@matt-darby.com> <9fef42ec-cebf-476c-857f-03cec6d278d9@27g2000hsf.googlegroups.com> Message-ID: <16818EA1-7E39-49B5-A42D-A34529E24AC6@railsnewbie.com> On Jul 3, 2008, at 8:27 AM, Matt Darby wrote: > On Jul 1, 11:21 am, Matt Darby wrote: >> On Jul 1, 2008, at 8:23 AM, Tom Stuart wrote: >> >>> $ ./script/console >>>>> Date.today.minus_with_duration(5.days) >>> => Thu, 26 Jun 2008 >>>>> Date.today.minus_without_duration(5.days.to_i) >>> => Sun, 17 Sep 0825 >> >>> Is this a load-order problem? Perhaps >>> ActiveSupport::CoreExtensions::Date::Calculations isn't kicking in >>> correctly. > Anyone else have thoughts on this? Yeah - use the debugger (ruby-debug) and the failing test case: it "should have 5.days as the proper fixnum" do require 'rubygems'; require 'ruby-debug'; debugger 5.days.to_i.should == 5.days end Scott From matt at matt-darby.com Thu Jul 3 11:09:14 2008 From: matt at matt-darby.com (Matt Darby) Date: Thu, 3 Jul 2008 11:09:14 -0400 Subject: [rspec-users] Odd Date-based spec failing In-Reply-To: <16818EA1-7E39-49B5-A42D-A34529E24AC6@railsnewbie.com> References: <5e2dde260806301940i7342b4ddw2a6c4c2158d51c8a@mail.gmail.com> <810a540e0806302310l50ce8434v1923aa413d38645@mail.gmail.com> <79205FC9-628C-4595-A65C-D5CFA9325A6C@matt-darby.com> <24E4D2F0-172E-48AD-B28D-E84FC9E7882E@experthuman.com> <3B6415BF-3E17-4B5C-A74E-9DA66161D0EC@matt-darby.com> <9fef42ec-cebf-476c-857f-03cec6d278d9@27g2000hsf.googlegroups.com> <16818EA1-7E39-49B5-A42D-A34529E24AC6@railsnewbie.com> Message-ID: <4E621B70-9267-4B55-A6F3-183074552128@matt-darby.com> > Yeah - use the debugger (ruby-debug) and the failing test case: > > it "should have 5.days as the proper fixnum" do > require 'rubygems'; require 'ruby-debug'; debugger > 5.days.to_i.should == 5.days > end Thanks for the reply, but what does this resolve? It seems as this would be a bug upsteam, no? From dchelimsky at gmail.com Thu Jul 3 11:16:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 3 Jul 2008 10:16:21 -0500 Subject: [rspec-users] Odd Date-based spec failing In-Reply-To: References: <5e2dde260806301940i7342b4ddw2a6c4c2158d51c8a@mail.gmail.com> Message-ID: <2CF1C9BA-D91C-4922-92F5-40B11C3C4389@gmail.com> On Jun 30, 2008, at 9:43 PM, Matt Darby wrote: > On Jul 1, 2008, at 10:10 PM, Camilo Torres wrote: > >> It seems your Phase.percentage_complete is not working as you expect. >> It clearly returns 100 when you are specting 83. The test clearly >> said >> that. >> >> ?What is the implementation of your percentage_complete method? > > It only fails when run via 'rake spec:models'; otherwise, it passes. Just catching up with this. When you say 'otherwise', how else are you running this that it passes? Can you try these and tell us which ones pass and which ones fail? rake spec rake spec:models script/spec spec script/spec spec/models script/spec spec/models -r script/spec spec/models/phase_spec.rb script/spec spec/models/phase_spec.rb -r ruby spec/models/phase_spec.rb ruby spec/models/phase_spec.rb -r Thanks, David > > > def percentage_complete > # Returns an integer representation of a percentage (i.e. '78') > > return 100 if Date.today >= self.end_date > > length_in_days = (self.end_date - self.start_date).to_f > days_into_phase = (Date.today - self.start_date).to_f > > ((days_into_phase / length_in_days) * 100.0).round > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at matt-darby.com Thu Jul 3 11:31:29 2008 From: matt at matt-darby.com (Matt Darby) Date: Thu, 3 Jul 2008 11:31:29 -0400 Subject: [rspec-users] Odd Date-based spec failing In-Reply-To: <2CF1C9BA-D91C-4922-92F5-40B11C3C4389@gmail.com> References: <5e2dde260806301940i7342b4ddw2a6c4c2158d51c8a@mail.gmail.com> <2CF1C9BA-D91C-4922-92F5-40B11C3C4389@gmail.com> Message-ID: <8CA7FFAE-0021-4CAA-A18A-DB3B69F25D41@matt-darby.com> > Can you try these and tell us which ones pass and which ones fail? > > rake spec > rake spec:models > script/spec spec > script/spec spec/models > script/spec spec/models -r > script/spec spec/models/phase_spec.rb > script/spec spec/models/phase_spec.rb -r > ruby spec/models/phase_spec.rb > ruby spec/models/phase_spec.rb -r > > Thanks, > David Ahhh, Mr. Chelimsky himself ;) rake spec fails with: Date.today = 2008-07-03 self.start_date = 0825-09-19 self.end_date = 2008-07-04 rake spec:models fails with: Date.today = 2008-07-03 self.start_date = 0825-09-19 self.end_date = 2008-07-04 script/spec spec passes with: Date.today = 2008-07-03 self.start_date = 2008-06-28 self.end_date = 2008-07-04 script/spec spec/models passes with: Date.today = 2008-07-03 self.start_date = 2008-06-28 self.end_date = 2008-07-04 script/spec spec/models -r fails altogether with: optparse.rb:451:in `parse': missing argument: -r (OptionParser::MissingArgument) script/spec spec/models/phase_spec.rb passes with: Date.today = 2008-07-03 self.start_date = 2008-06-28 self.end_date = 2008-07-04 script/spec spec/models/phase_spec.rb -r fails with the MissingArgument exception ruby spec/models/phase_spec.rb passes with: Date.today = 2008-07-03 self.start_date = 2008-06-28 self.end_date = 2008-07-04 ruby spec/models/phase_spec.rb -r fails with the MissingArgument exception From ml at e4net.com Thu Jul 3 12:01:57 2008 From: ml at e4net.com (Jim Morris) Date: Thu, 03 Jul 2008 09:01:57 -0700 Subject: [rspec-users] unable to access flash from rails helper spec since upgrade to 1.1.4 In-Reply-To: <5F49DCC8-F8BE-4178-A11E-7D2F234D72EC@gmail.com> References: <486C197B.2000307@e4net.com> <1C4A805E-789E-4778-AA8E-58FBB0F376DA@gmail.com> <486C71E1.8010804@e4net.com> <5F49DCC8-F8BE-4178-A11E-7D2F234D72EC@gmail.com> Message-ID: <486CF7F5.3090602@e4net.com> Ok, its messy but this works... before :each do init_haml_helpers helper.extend Haml helper.extend Haml::Helpers helper.send :init_haml_helpers end it "should display flash" do for name in [:notice, :warning, :error] flash[name]= "flash #{name.to_s} message" helper.capture_haml{ helper.display_flash }.should match(/
\s*#{flash[name]}\s*<\/div>/) flash[name]= nil end end ... NOTE that the capture haml needs to be prepended by helper. otherwise nothing gets returned. David Chelimsky wrote: > On Jul 3, 2008, at 1:29 AM, Jim Morris wrote: > >> Hi David, >> >> Thanks that worked, and fixed that problem. >> >> Now I have run into another problem, from the same blog example (which >> I'll update once I get it all to work). >> >> Within the application helper I call haml_tag, which works fine when >> the app runs. (used to be called open). >> >> However when I try to test that helper in my helper spec I get... >> >> NoMethodError in 'ApplicationHelper should display flash' >> undefined method `haml_tag' for >> # >> >> For some reason it doesn't know anything about haml when run from the >> spec. >> >> I guess I need to inject a require haml or something into the >> HelperObject? I just don't know how to do that. > > Try this: > > before(:each) do > helper.extend Haml::Helpers > end > > it "should ...." do > ... > end > > >> >> >> I am using the latest version of HAML but I am still using rails 1.2.6 >> >> Any ideas? >> >> Thanks >> Jim >> >> David Chelimsky wrote: >>> On Jul 2, 2008, at 7:12 PM, Jim Morris wrote: >>>> Hi, >>>> >>>> Many moons ago I wrote this blog entry... >>>> >>>> http://blog.wolfman.com/articles/2007/07/14/using-rspec-to-test-haml-helpers >>>> >>>> >>>> I just upgraded that rails project to use rspec 1.1.4 and associated >>>> rspec_rails. >>>> >>>> It seems that my helper when called from the helper specs no longer >>>> are able to access flash, controller etc as they did before. >>>> >>>> I already prepended all helper calls with helper. so I fixed those >>>> changes, but I have been unable to figure out how to access flash >>>> etc... >>>> >>>> Here is a simplified example... >>>> >>>> in ApplicationHelper.rb >>>> >>>> def test_flash >>>> for name in [:notice, :warning, :error] >>>> if flash[name] >>>> return "#{flash[name]}" >>>> end >>>> end >>>> nil >>>> end >>>> >>>> In my rails/spec/helpers/application_helper_spec.rb >>>> >>>> require File.dirname(__FILE__) + '/../spec_helper' >>>> >>>> describe ApplicationHelper do >>>> >>>> it "should test flash" do >>>> for name in [:notice, :warning, :error] >>>> flash[name]= "flash #{name.to_s} message" >>>> helper.test_flash.should match(/.*#{name}.*/) >>>> flash[name]= nil >>>> end >>>> end >>>> >>>> end >>>> >>>> I get this error trace... >>>> 1) >>>> NoMethodError in 'ApplicationHelper should test flash' >>>> You have a nil object when you didn't expect it! >>>> You might have expected an instance of Array. >>>> The error occurred while evaluating nil.[] >>>> /.../app/helpers/application_helper.rb:23:in `test_flash' >>>> ... >>>> >>>> flash is nil, this used to work, so what is the new magic >>>> incantation to get this to work again? >>> Hey Jim - I fixed this in >>> http://github.com/dchelimsky/rspec-rails/commit/40a0916325dbe9a1631849146d078e330fca71f2, >>> so you can either grab the very latest from github or wait for the >>> 1.1.5 release (coming in the next few days). >>> Cheers, >>> David >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> -- >> Jim Morris, http://blog.wolfman.com >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > -- Jim Morris, http://blog.wolfman.com From bryansray at gmail.com Thu Jul 3 12:44:58 2008 From: bryansray at gmail.com (Bryan Ray) Date: Thu, 3 Jul 2008 11:44:58 -0500 Subject: [rspec-users] Controller spec gives strange error In-Reply-To: References: Message-ID: <817E4633-119C-455B-910D-3ADD690C8716@gmail.com> I believe the problem is that you're not telling the Language model what to stub/mock when it calls the find method inside of set_site_language. I'm not entirely sure, but I would imagine that the TestUnit test is passing, because it's using the full Rails stack to run the test. Try doing something like this (code below): On Jul 3, 2008, at 2:24 AM, Damian Terentiev wrote: > Good day! > > I have a Rails app with a controller that sets an instance variable > in a > before_filter, like this: > > class PostsController < ApplicationController > > before_filter :set_site_language > > def set_site_language > @site_language = cookie['lang'] ? > Language.find_by_code(cookie['lang']) : > Language.find(:first) > end > > def index > @posts = Post.find_by_language_id(@site_language.id) > end > > end > > The controller has the following spec: > > describe PostsController do before(:each) do @language_mock = mock_model(Language) controller.stub!(:set_site_language).and_return @language_mock end > > > it "should show home page" do > get :index > response.should be_success > end > > end > > And the equivalent test: > > class PostsControllerTest < ActionController::TestCase > > def test_should_show_home_page > get :index > assert_response :success > end > > end > > The test runs fine, but the spec fails with the following error on > line > with `@posts = Post.find_by_language_id(@site_language.id)`: > > RuntimeError in 'PostsController should show home page' > Called id for nil, which would mistakenly be 4 -- if you really wanted > the id of nil, use object_id > > Seems that @site_language does not get assigned when spec runs. Could > you please help me solve this problem? > > Yours, > Damian > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From david at digitalronin.com Thu Jul 3 12:57:02 2008 From: david at digitalronin.com (David Salgado) Date: Thu, 3 Jul 2008 17:57:02 +0100 Subject: [rspec-users] Re-use scenarios from another story file? Message-ID: <8c90cb7d0807030957s6d2071f8x5d30d9629dbc9820@mail.gmail.com> Hi All Is there a way to have "pre-requisite" story scenarios, and include them using GivenScenario in a different story file? i.e. I'd like to have a file "prereqs.story", with "Scenario: A common setup", and then in "somestuff.story" have "GivenScenario: A common setup...", and have the scenario go on from there. I know I can extract logic into steps, but I'd like the pre-requisite scenarios to have some assertions, and it doesn't feel right to put assertions in steps (if that's possible). I've had a dig through the rdoc and the source, and I couldn't figure out whether it could be done, or how to do it. Is this kind of thing possible and/or sensible? Many thanks David -------------- next part -------------- An HTML attachment was scrubbed... URL: From ml at e4net.com Thu Jul 3 12:57:58 2008 From: ml at e4net.com (Jim Morris) Date: Thu, 03 Jul 2008 09:57:58 -0700 Subject: [rspec-users] Testing HAML in helper rspec Message-ID: <486D0516.9080801@e4net.com> Thought I'd post this under its own heading so others can find it. Thanks to David for the pointers to solve this. Here is the incantation needed to use HAML 2.0 under RSpec 1.1.5 (Needs the .5 for a fix) # application_helper_spec.rb under spec/helpers ... before :each do helper.extend Haml helper.extend Haml::Helpers helper.send :init_haml_helpers end it "should display flash" do for name in [:notice, :warning, :error] flash[name]= "flash #{name.to_s} message" helper.capture_haml{ helper.display_flash }.should match(/
\s*#{flash[name]}\s*<\/div>/) flash[name]= nil end end ... Which tests this in application_helpers.rb def display_flash for name in [:notice, :warning, :error] if flash[name] haml_tag :div, flash[name], {:class => name.to_s} end end nil end I also updated my blog post on this topic to cover the new syntax... http://blog.wolfman.com/articles/2007/07/14/using-rspec-to-test-haml-helpers -- Jim Morris, http://blog.wolfman.com From dhf0820 at gmail.com Thu Jul 3 14:19:44 2008 From: dhf0820 at gmail.com (Don French) Date: Thu, 3 Jul 2008 11:19:44 -0700 (PDT) Subject: [rspec-users] autotest failing on startup In-Reply-To: References: <18246365.post@talk.nabble.com> Message-ID: <18265467.post@talk.nabble.com> Mahalo for the information. I am using version 1.1.4 of rspec. Is there a list somewhere for autotest? Don French David Chelimsky-2 wrote: > > On Jul 3, 2008, at 3:08 AM, Don French wrote: > >> I have been using autotest/zentest 3.5.0 with my rails 2.0.2 and >> rspec. I >> upgraded my gems and got 3.9.3 and had a problem. I went back to >> 3.5.0 and >> it worked. I stayed there until moving to rails 2.1. I again updated >> my gems >> and got 3.10. This one had the same problem. This time I need to >> figure out >> what is wrong. Here is what I get: >> >> /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:394:in >> `find_files_to_test': undefined method `values' for # >> (NoMethodError) >> from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: >> 239:in >> `run_tests' >> from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: >> 228:in >> `get_to_green' >> from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: >> 208:in >> `run' >> from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: >> 206:in >> `loop' >> from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: >> 206:in >> `run' >> from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: >> 136:in >> `run' >> from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/bin/autotest:55 >> from /usr/bin/autotest:19:in `load' >> from /usr/bin/autotest:19 > > This is all autotest so I don't think it's related to rspec. That > said, what version of rspec are you using? > >> Here is the failing code: >> >> def find_files >> result = {} >> targets = self.find_directories + self.extra_files >> self.find_order.clear >> >> targets.each do |target| >> order = [] >> Find.find(target) do |f| >> Find.prune if f =~ self.exceptions >> >> next if test ?d, f >> next if f =~ /(swp|~|rej|orig)$/ # temporary/patch files >> next if f =~ /\/\.?#/ # Emacs autosave/cvs merge >> files >> >> filename = f.sub(/^\.\//, '') >> >> result[filename] = File.stat(filename).mtime rescue next >> order << filename >> end >> self.find_order.push(*order.sort) >> end >> return result # this should return as a hash but is received as an >> array >> end >> >> ## >> # Find the files which have been modified, update the recorded >> # timestamps, and use this to update the files to test. Returns true >> # if any file is newer than the previously recorded most recent >> # file. >> >> def find_files_to_test(files=find_files) >> # for some reason files comes in as a array needs to be hash >> #myfiles = {} >> #files.each do |key, value| >> #myfiles[key] = value >> #end >> #files = myfiles >> updated = files.select { |filename, mtime| self.last_mtime < >> mtime } >> >> p updated if $v unless updated.empty? or self.last_mtime.to_i == 0 >> >> updated.map { |f,m| test_files_for(f) }.flatten.uniq.each do | >> filename| >> self.files_to_test[filename] # creates key with default value >> end >> >> if updated.empty? then >> nil >> else >> files.values.max <= line 394 >> end >> end >> >> For some reason the files is an array instead of a hash. I added >> the little >> change that is commented out and it works. But that should not have >> to be >> done. >> >> Any ideas? >> >> >> -- >> View this message in context: >> http://www.nabble.com/autotest-failing-on-startup-tp18246365p18246365.html >> Sent from the rspec-users mailing list archive at Nabble.com. >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -- View this message in context: http://www.nabble.com/autotest-failing-on-startup-tp18246365p18265467.html Sent from the rspec-users mailing list archive at Nabble.com. From dchelimsky at gmail.com Thu Jul 3 14:38:38 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 3 Jul 2008 13:38:38 -0500 Subject: [rspec-users] Re-use scenarios from another story file? In-Reply-To: <8c90cb7d0807030957s6d2071f8x5d30d9629dbc9820@mail.gmail.com> References: <8c90cb7d0807030957s6d2071f8x5d30d9629dbc9820@mail.gmail.com> Message-ID: On Jul 3, 2008, at 11:57 AM, David Salgado wrote: > Hi All > > Is there a way to have "pre-requisite" story scenarios, and include > them using GivenScenario in a different story file? > > i.e. I'd like to have a file "prereqs.story", with "Scenario: A > common setup", and then in "somestuff.story" have "GivenScenario: A > common setup...", and have the scenario go on from there. Unless you're looking for the steps to show up when you run things, why not just have a helper method that does the setup for you and then have a Given step that invokes that method? > I know I can extract logic into steps, but I'd like the pre- > requisite scenarios to have some assertions, and it doesn't feel > right to put assertions in steps (if that's possible). I'm not sure understand this. Don't you have expectations (assertions) in all your Then steps? David > I've had a dig through the rdoc and the source, and I couldn't > figure out whether it could be done, or how to do it. Is this kind > of thing possible and/or sensible? > > Many thanks > > David > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Thu Jul 3 14:39:45 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 3 Jul 2008 13:39:45 -0500 Subject: [rspec-users] autotest failing on startup In-Reply-To: <18265467.post@talk.nabble.com> References: <18246365.post@talk.nabble.com> <18265467.post@talk.nabble.com> Message-ID: <04D3E8BF-3EDC-4465-8124-3E6CF272BBC4@gmail.com> On Jul 3, 2008, at 1:19 PM, Don French wrote: > Mahalo for the information. I am using version 1.1.4 of rspec. > > Is there a list somewhere for autotest? No list that I know of, but there's a tracker: http://rubyforge.org/projects/zentest > > > Don French > > David Chelimsky-2 wrote: >> >> On Jul 3, 2008, at 3:08 AM, Don French wrote: >> >>> I have been using autotest/zentest 3.5.0 with my rails 2.0.2 and >>> rspec. I >>> upgraded my gems and got 3.9.3 and had a problem. I went back to >>> 3.5.0 and >>> it worked. I stayed there until moving to rails 2.1. I again updated >>> my gems >>> and got 3.10. This one had the same problem. This time I need to >>> figure out >>> what is wrong. Here is what I get: >>> >>> /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb:394:in >>> `find_files_to_test': undefined method `values' for #>> 0x18b2530> >>> (NoMethodError) >>> from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: >>> 239:in >>> `run_tests' >>> from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: >>> 228:in >>> `get_to_green' >>> from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: >>> 208:in >>> `run' >>> from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: >>> 206:in >>> `loop' >>> from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: >>> 206:in >>> `run' >>> from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/lib/autotest.rb: >>> 136:in >>> `run' >>> from /Library/Ruby/Gems/1.8/gems/ZenTest-3.10.0/bin/autotest:55 >>> from /usr/bin/autotest:19:in `load' >>> from /usr/bin/autotest:19 >> >> This is all autotest so I don't think it's related to rspec. That >> said, what version of rspec are you using? >> >>> Here is the failing code: >>> >>> def find_files >>> result = {} >>> targets = self.find_directories + self.extra_files >>> self.find_order.clear >>> >>> targets.each do |target| >>> order = [] >>> Find.find(target) do |f| >>> Find.prune if f =~ self.exceptions >>> >>> next if test ?d, f >>> next if f =~ /(swp|~|rej|orig)$/ # temporary/patch files >>> next if f =~ /\/\.?#/ # Emacs autosave/cvs merge >>> files >>> >>> filename = f.sub(/^\.\//, '') >>> >>> result[filename] = File.stat(filename).mtime rescue next >>> order << filename >>> end >>> self.find_order.push(*order.sort) >>> end >>> return result # this should return as a hash but is received as >>> an >>> array >>> end >>> >>> ## >>> # Find the files which have been modified, update the recorded >>> # timestamps, and use this to update the files to test. Returns true >>> # if any file is newer than the previously recorded most recent >>> # file. >>> >>> def find_files_to_test(files=find_files) >>> # for some reason files comes in as a array needs to be hash >>> #myfiles = {} >>> #files.each do |key, value| >>> #myfiles[key] = value >>> #end >>> #files = myfiles >>> updated = files.select { |filename, mtime| self.last_mtime < >>> mtime } >>> >>> p updated if $v unless updated.empty? or self.last_mtime.to_i == 0 >>> >>> updated.map { |f,m| test_files_for(f) }.flatten.uniq.each do | >>> filename| >>> self.files_to_test[filename] # creates key with default value >>> end >>> >>> if updated.empty? then >>> nil >>> else >>> files.values.max <= line 394 >>> end >>> end >>> >>> For some reason the files is an array instead of a hash. I added >>> the little >>> change that is commented out and it works. But that should not have >>> to be >>> done. >>> >>> Any ideas? >>> >>> >>> -- >>> View this message in context: >>> http://www.nabble.com/autotest-failing-on-startup-tp18246365p18246365.html >>> Sent from the rspec-users mailing list archive at Nabble.com. >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > > -- > View this message in context: http://www.nabble.com/autotest-failing-on-startup-tp18246365p18265467.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ivorpaul at gmail.com Thu Jul 3 16:47:47 2008 From: ivorpaul at gmail.com (Ivor Paul) Date: Thu, 3 Jul 2008 22:47:47 +0200 Subject: [rspec-users] matchers not working...? Solved (weird autotest error though) Message-ID: Hi David Thanks, the git repos work great. I am trying to get autotest to work but keep getting this error. loading autotest/rails_rspec Autotest style autotest/rails_rspec doesn't seem to exist. Aborting. Have you seen this before? Can you point me in the right direction? Thanks a lot for your help so far. Regards Ivor On Wed, Jul 2, 2008 at 2:02 PM, Ivor Paul wrote: > Hi David > > thanks for the response! > This is what the error looks like for be_valid > /activesupport/lib/active_support/dependencies.rb:478:in > `const_missing': uninitialized constant > Spec::Rails::Example::ModelExampleGroup::Be_valid > > and for be_nil > /activesupport/lib/active_support/dependencies.rb:478:in > `const_missing': uninitialized constant > Spec::Rails::Example::ModelExampleGroup::Be_nil > > I invoke the tests using rake spec. I also get this error when I use > ./script/spec path/to/file. > > We were using svn externals for the plugins. I will give github a try > and let you know what happens. > > Thanks for the help. > Ivor > > On Tue, Jul 1, 2008 at 10:57 PM, David Chelimsky wrote: >> On Jul 1, 2008, at 3:48 PM, Ivor Paul wrote: >> >>> I am getting errors that seem to be the matchers not working - example: >>> >>> >>> vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:478:in >>> `const_missing': uninitialized constant >>> Spec::Rails::Example::ModelExampleGroup::Be_nil >>> >>> I have seen the same error with other matchers like be_valid etc. >> >> Does the code say Be_nil instead of be_nil? >> >>> Does anyone have an idea what could be causing this? >> >> How are you invoking rspec? With rake? ruby? script/spec? or autotest? >> >>> I am using the rspec and rspec_on_rails plugins. Pretty much the >>> latest versions. Rails 2.0.2 >> >> With the 1.1.4 release we changed rspec_on_rails to rspec-rails, so I'm >> guessing you have the latest code that's still in subversion at rubyforge, >> but not the latest from github. >> >> Would you mind giving the code from github a shot? Install instructions can >> be found at http://github.com/dchelimsky/rspec-rails/wikis/home >> >> Cheers, >> David >> >>> Regards >>> Ivor >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > From tiffani2k3 at gmail.com Thu Jul 3 18:32:49 2008 From: tiffani2k3 at gmail.com (Tiffani Ashley Bell) Date: Thu, 3 Jul 2008 18:32:49 -0400 Subject: [rspec-users] Attempting to Make Sense of RSpec use Message-ID: Hi everybody, I'm pretty new to RSpec and have been reading over examples and tutorials of how to use the framework. I like everything so far since it goes right along with Rails' expressiveness and such. I was reading the Typo source code, however, and came across some code that I didn't know exactly how it worked. I've noticed that in testing one of their controllers, they use a variable (@comments) that they don't declare anywhere else, yet they use it as a stand in for collections on some of the mocks. How is that possible? I know in the mocking documentation it says that you can define collaborations with other objects before those objects exist, but how is that working in this code? I only ask that because later, you see code like this: @comments.stub!(:build).and_return(@comment). I'm looking at http://svn.typosphere.org/typo/trunk/spec/controllers/comments_controller_spec.rband http://svn.typosphere.org/typo/trunk/app/controllers/comments_controller.rb. Thanks in advance for any ideas! Tiffani AB -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben.teese at shinetech.com Thu Jul 3 20:23:57 2008 From: ben.teese at shinetech.com (Ben Teese) Date: Fri, 4 Jul 2008 10:23:57 +1000 Subject: [rspec-users] How to detect an attribute rename from a view spec? Message-ID: <200807040024.m640O6c2021773@newton.shinetech.com> I'm new to RSpec so excuse me if I'm missing something obvious here. I recently renamed an attribute on a model, and my generated view spec didn't detect it. This resulted in a defect going through undetected. Even worse, I'm not sure how I could reasonably get RSpec to detect such a change. I suspect the problem isn't specific to RSpec, but I encountered it whilst dealing with RSpec and thought this would be a good place to ask for advice. The details: I used RSpec to generate scaffolding for a model we'll call 'Resource'. Resource has an attribute called 'entity'. It generated for me a view for a Resource - including its 'entity' attribute. It also generated a corresponding spec that looked like this: describe "/resources/index.html.erb" do include ResourcesHelper before(:each) do resource_98 = mock_model(Resource) resource_98.should_receive(:entity).and_return("MyString") ... end it "should render list of resources" do render "/resources/index.html.erb" response.should have_tag("tr>td", "MyString", 2) .. end end It also generated a fixture and model spec, which I tweaked as follows: describe Resource do fixtures :resources it "should have an entity" do resources(:one).entity.should == 'MyString' end end Both specs pass. Excuse the lame model spec - I'm about to get to the point. Next I decided I wanted to rename the 'entity' attribute to 'entities'. My model spec failed, so I fixed it. However, the view spec didn't fail. It expected that the view would call 'entity' on the mock Resource - and this was indeed still the case. However, when I went and actually looked at the page, it died - the 'entity' attribute didn't exist anymore on the model. I'm not sure how I could have picked that up with an automated test. Any ideas? Thanks, Ben Ben Teese Senior Developer Mobile: +61 (0) 405 496 053 a passion for excellence www.shinetech.com This email is intended solely for the use of the addressee and may contain information that is confidential or privileged. If you receive this email in error please notify the sender and delete the email immediately. ............................................................................ ................................ -------------- next part -------------- An HTML attachment was scrubbed... URL: From raasdnil at gmail.com Thu Jul 3 21:09:58 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Fri, 4 Jul 2008 11:09:58 +1000 Subject: [rspec-users] Attempting to Make Sense of RSpec use In-Reply-To: References: Message-ID: <57a815bf0807031809o3ebc754bqcf3ed6445b9beeb9@mail.gmail.com> On Fri, Jul 4, 2008 at 8:32 AM, Tiffani Ashley Bell wrote: > Hi everybody, Hi Tiffany, welcome to Rspec > I was reading the Typo source code, however, and came across some code that > I didn't know exactly how it worked. I've noticed that in testing one of > their controllers, they use a variable (@comments) that they don't declare > anywhere else, yet they use it as a stand in for collections on some of the > mocks. How is that possible? I know in the mocking documentation it says > that you can define collaborations with other objects before those objects > exist, but how is that working in this code? I only ask that because later, > you see code like this: @comments.stub!(:build).and_return(@comment). If you have a look at the descriptions, they use :shared => true. This is a way of being DRY in RSpec (which I personally don't think is such a good idea). What the shared => true declaration allows you to do is to include that block of code elsewhere with 'it should behave like my shared code' So we have (describe "All Requests", :shared => true do) and then the next description block is: describe "General Comment Creation", :shared => true do it_should_behave_like "All Requests" Which then includes the All Requests block (which is just a before method). The @comments variable gets declared in: @comments.stub!(:build).and_return(@comment) and then this is tied in to the Article model in the _previous_ code block like so: @article = mock_model(Article, :comments => @comments, :published_comments => @comments, :add_comment => @comment) So when you call @article.comments you get @comments as a stub back which stubs :build and returns a @comment. Ugh. This is where, in RSpec, you can dig a very fast grave. Because you'll come back to this code in 6-12 months and be totally stuck trying to figure out what is where. I recently wrote a viewpoint on this that might help you: http://www.lindsaar.net/2008/6/24/tip-24-being-clever-in-specs-is-for-dummies Hope you do well with Rspec, feel free to ask more questions! -- http://lindsaar.net/ Rails, RSpec, Puppet and Life blog.... From raasdnil at gmail.com Thu Jul 3 21:11:38 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Fri, 4 Jul 2008 11:11:38 +1000 Subject: [rspec-users] (no subject) In-Reply-To: <8DFCA77A-FEF5-40CA-A634-A94D090BF632@obtiva.com> References: <8DFCA77A-FEF5-40CA-A634-A94D090BF632@obtiva.com> Message-ID: <57a815bf0807031811u1a3cb3fchbdabe991a0545f99@mail.gmail.com> On Thu, Jul 3, 2008 at 10:22 PM, Joseph Leddy wrote: > > > Sent from my mobile I assume this is a pending spec? :) -- http://lindsaar.net/ Rails, RSpec, Puppet and Life blog.... From raasdnil at gmail.com Thu Jul 3 21:15:17 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Fri, 4 Jul 2008 11:15:17 +1000 Subject: [rspec-users] How to detect an attribute rename from a view spec? In-Reply-To: <200807040024.m640O6c2021773@newton.shinetech.com> References: <200807040024.m640O6c2021773@newton.shinetech.com> Message-ID: <57a815bf0807031815t672d4c3aqfe52fc5d6d36583d@mail.gmail.com> On Fri, Jul 4, 2008 at 10:23 AM, Ben Teese wrote: > I'm new to RSpec so excuse me if I'm missing something obvious here. I > recently renamed an attribute on a model, and my generated view spec didn't > detect it. This resulted in a defect going through undetected. Even worse, > I'm not sure how I could reasonably get RSpec to detect such a change. You should have a look at stories. They provide the integration testing you are after. Basically, they run through your site page by page and look to see what is happening. Alternatively, you can look to using real objects in your specs instead of lots of stubs. There is a performance hit on your specs, though for me it has not been a problem.... yet :) Another option would be something like Selenium, which actually opens every page of your website one by one. -- http://lindsaar.net/ Rails, RSpec, Puppet and Life blog.... From mark.wilden at gmail.com Thu Jul 3 23:55:51 2008 From: mark.wilden at gmail.com (Mark Wilden) Date: Thu, 3 Jul 2008 20:55:51 -0700 Subject: [rspec-users] Attempting to Make Sense of RSpec use In-Reply-To: <3c30da400807031927p59aa7fa1mf6677022bec849c0@mail.gmail.com> References: <57a815bf0807031809o3ebc754bqcf3ed6445b9beeb9@mail.gmail.com> <3c30da400807031927p59aa7fa1mf6677022bec849c0@mail.gmail.com> Message-ID: <3c30da400807032055q5d13a17ejdd9ea561657493d8@mail.gmail.com> The problem I just found with shared specs is that if one fails, you don't see the sharer in the callstack, so you really don't know what went wrong. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Fri Jul 4 00:52:43 2008 From: lists at ruby-forum.com (Gregg Pollack) Date: Fri, 4 Jul 2008 06:52:43 +0200 Subject: [rspec-users] Global setup method goes where? Message-ID: <85c243837b67967d868385e141c7e863@ruby-forum.com> You know how sometimes you look in /log/test.log for debug information like which test caused a certain render or query? I found this post which shows how to get test information printed out in your test.log with test:unit and shoulda, but I'm not sure there's a way to do it with RSpec. http://bmorearty.wordpress.com/2008/06/18/find-tests-more-easily-in-your-testlog/ test:unit allows you to put "setup :blah" in your test_helper.rb, and then the blah method gets called before each test. This can be used to print out a log statement saying 'we're runnig test ___". How would we do the same in rspec with the spec_helper.rb so that we can print this data out in our logs too? Any takers? I'm sure I could probably figure this out if I dove deep into the code base, but I get the feeling someone must have done this before. I'm going to cover this on the next Rails Envy podcast, so you'll get some credit for a good answer, and a link if you post the answer to your blog (assuming you want the publicity). ;-) Gregg Pollack RailsEnvy.com -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Jul 4 02:08:32 2008 From: lists at ruby-forum.com (Damian Terentiev) Date: Fri, 4 Jul 2008 08:08:32 +0200 Subject: [rspec-users] Controller spec gives strange error In-Reply-To: <817E4633-119C-455B-910D-3ADD690C8716@gmail.com> References: <817E4633-119C-455B-910D-3ADD690C8716@gmail.com> Message-ID: <1eda452194fd415f28dcd3079c56d3fc@ruby-forum.com> Bryan Ray wrote: > I believe the problem is that you're not telling the Language model > what to stub/mock when it calls the find method inside of > set_site_language. > > I'm not entirely sure, but I would imagine that the TestUnit test is > passing, because it's using the full Rails stack to run the test. > > Try doing something like this (code below): Thanks for your help! Anyway, switching to Test::Spec has solved the problem. -- Posted via http://www.ruby-forum.com/. From ben at benmabey.com Fri Jul 4 02:19:34 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 04 Jul 2008 00:19:34 -0600 Subject: [rspec-users] Global setup method goes where? In-Reply-To: <85c243837b67967d868385e141c7e863@ruby-forum.com> References: <85c243837b67967d868385e141c7e863@ruby-forum.com> Message-ID: <486DC0F6.70102@benmabey.com> Gregg Pollack wrote: > You know how sometimes you look in /log/test.log for debug information > like which test caused a certain render or query? > > I found this post which shows how to get test information printed out in > your test.log with test:unit and shoulda, but I'm not sure there's a way > to do it with RSpec. > > http://bmorearty.wordpress.com/2008/06/18/find-tests-more-easily-in-your-testlog/ > > test:unit allows you to put "setup :blah" in your test_helper.rb, and > then the blah method gets called before each test. This can be used to > print out a log statement saying 'we're runnig test ___". How would we > do the same in rspec with the spec_helper.rb so that we can print this > data out in our logs too? > > Any takers? I'm sure I could probably figure this out if I dove deep > into the code base, but I get the feeling someone must have done this > before. > > I'm going to cover this on the next Rails Envy podcast, so you'll get > some credit for a good answer, and a link if you post the answer to your > blog (assuming you want the publicity). ;-) > > Gregg Pollack > RailsEnvy.com > In your spec_helper.rb just put: Spec::Runner.configure do |config| ... config.before(:each) do full_example_description = "#{self.class.description} #{@method_name}" RAILS_DEFAULT_LOGGER.info("\n\nStarting #{full_example_description}\n\n#{'-' * (9 + full_example_description.length)}") end end Note that the constant RAILS_DEFAULT_LOGGER is being used since Rails::logger is only available in 2.1. I'll write up a quick post on on this and show how to do something similar with the story runner. -Ben From raasdnil at gmail.com Fri Jul 4 02:30:18 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Fri, 4 Jul 2008 16:30:18 +1000 Subject: [rspec-users] Global setup method goes where? In-Reply-To: <486DC0F6.70102@benmabey.com> References: <85c243837b67967d868385e141c7e863@ruby-forum.com> <486DC0F6.70102@benmabey.com> Message-ID: <57a815bf0807032330lfe542f6jf36266317eadb678@mail.gmail.com> On Fri, Jul 4, 2008 at 4:19 PM, Ben Mabey wrote: > Gregg Pollack wrote: >> I found this post which shows how to get test information printed out in >> your test.log with test:unit and shoulda, but I'm not sure there's a way >> to do it with RSpec. Damn, that is a good idea. > In your spec_helper.rb just put: > Spec::Runner.configure do |config| > ... > config.before(:each) do > full_example_description = "#{self.class.description} #{@method_name}" > RAILS_DEFAULT_LOGGER.info("\n\nStarting > #{full_example_description}\n\n#{'-' * (9 + > full_example_description.length)}") > end > > end Beaten at the gate by about 30 seconds :) My implementation was basically the same! > Note that the constant RAILS_DEFAULT_LOGGER is being used since > Rails::logger is only available in 2.1. Didn't think of that bit though. Well done. -- http://lindsaar.net/ Rails, RSpec, Puppet and Life blog.... From ben at benmabey.com Fri Jul 4 04:15:10 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 04 Jul 2008 02:15:10 -0600 Subject: [rspec-users] Global setup method goes where? In-Reply-To: <486DC0F6.70102@benmabey.com> References: <85c243837b67967d868385e141c7e863@ruby-forum.com> <486DC0F6.70102@benmabey.com> Message-ID: <486DDC0E.1060408@benmabey.com> Ben Mabey wrote: > Gregg Pollack wrote: >> You know how sometimes you look in /log/test.log for debug information >> like which test caused a certain render or query? >> >> I found this post which shows how to get test information printed out in >> your test.log with test:unit and shoulda, but I'm not sure there's a way >> to do it with RSpec. >> >> http://bmorearty.wordpress.com/2008/06/18/find-tests-more-easily-in-your-testlog/ >> >> >> test:unit allows you to put "setup :blah" in your test_helper.rb, and >> then the blah method gets called before each test. This can be used to >> print out a log statement saying 'we're runnig test ___". How would we >> do the same in rspec with the spec_helper.rb so that we can print this >> data out in our logs too? >> >> Any takers? I'm sure I could probably figure this out if I dove deep >> into the code base, but I get the feeling someone must have done this >> before. >> >> I'm going to cover this on the next Rails Envy podcast, so you'll get >> some credit for a good answer, and a link if you post the answer to your >> blog (assuming you want the publicity). ;-) >> >> Gregg Pollack >> RailsEnvy.com >> > > In your spec_helper.rb just put: > > Spec::Runner.configure do |config| > ... > config.before(:each) do > full_example_description = "#{self.class.description} > #{@method_name}" > RAILS_DEFAULT_LOGGER.info("\n\nStarting > #{full_example_description}\n\n#{'-' * (9 + > full_example_description.length)}") > end > > end > > > Note that the constant RAILS_DEFAULT_LOGGER is being used since > Rails::logger is only available in 2.1. > > I'll write up a quick post on on this and show how to do something > similar with the story runner. > > -Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Here is the blog post: http://www.benmabey.com/2008/07/04/global-setup-in-rspec-or-how-to-add-logging-for-specs/ Thanks, Ben From david at digitalronin.com Fri Jul 4 04:17:45 2008 From: david at digitalronin.com (David Salgado) Date: Fri, 4 Jul 2008 09:17:45 +0100 Subject: [rspec-users] Re-use scenarios from another story file? In-Reply-To: References: <8c90cb7d0807030957s6d2071f8x5d30d9629dbc9820@mail.gmail.com> Message-ID: <8c90cb7d0807040117tbe69701ueba0a9a1cec483a6@mail.gmail.com> > Unless you're looking for the steps to show up when you run things, why not > just have a helper method that does the setup for you and then have a Given > step that invokes that method? > > I know I can extract logic into steps, but I'd like the pre-requisite >> scenarios to have some assertions, and it doesn't feel right to put >> assertions in steps (if that's possible). >> > > I'm not sure understand this. Don't you have expectations (assertions) in > all your Then steps? > Sure. I was just hoping I could keep my prereq stuff as a story in its own right - more for clarity when discussing requirements than for any other reason. If it's just a step or a helper method, then that particular story is reduced to a one-liner. I know I could always do both, and not be 100% DRY, so I guess that's what I'll do. Thanks for the advice David -------------- next part -------------- An HTML attachment was scrubbed... URL: From olivierdupuis at gmail.com Fri Jul 4 06:29:16 2008 From: olivierdupuis at gmail.com (Olivier Dupuis) Date: Fri, 4 Jul 2008 06:29:16 -0400 Subject: [rspec-users] Open source projects using RSpec Message-ID: <745312bd0807040329n461ea58j23be41615cbc66e0@mail.gmail.com> Hello, Anyone knows of open source projects that uses RSpec and RSpec Stories? I'd love to see how it is being used in different projects. Thank you Olivier Dupuis -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Jul 4 09:28:15 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 4 Jul 2008 08:28:15 -0500 Subject: [rspec-users] Attempting to Make Sense of RSpec use In-Reply-To: <3c30da400807032055q5d13a17ejdd9ea561657493d8@mail.gmail.com> References: <57a815bf0807031809o3ebc754bqcf3ed6445b9beeb9@mail.gmail.com> <3c30da400807031927p59aa7fa1mf6677022bec849c0@mail.gmail.com> <3c30da400807032055q5d13a17ejdd9ea561657493d8@mail.gmail.com> Message-ID: <3D6AB582-FD6C-4B07-A628-D9B89F029170@gmail.com> On Jul 3, 2008, at 10:55 PM, Mark Wilden wrote: > The problem I just found with shared specs is that if one fails, you > don't see the sharer in the callstack, so you really don't know what > went wrong. Even if you run it with --backtrace? > > > ///ark > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From loriolson at mac.com Fri Jul 4 10:52:34 2008 From: loriolson at mac.com (Lori M Olson) Date: Fri, 4 Jul 2008 08:52:34 -0600 Subject: [rspec-users] Open source projects using RSpec In-Reply-To: <745312bd0807040329n461ea58j23be41615cbc66e0@mail.gmail.com> References: <745312bd0807040329n461ea58j23be41615cbc66e0@mail.gmail.com> Message-ID: <3A184804-AAFA-44FF-9E92-2D2DE5509D25@mac.com> Someone on the list was just referencing Typo - http://svn.typosphere.org/typo/trunk/spec/controllers/comments_controller_spec.rb Doesn't look like they use stories, though. On 4-Jul-08, at 4:29 AM, Olivier Dupuis wrote: > Hello, > > Anyone knows of open source projects that uses RSpec and RSpec > Stories? I'd love to see how it is being used in different projects. > > Thank you > > Olivier Dupuis > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From erin at withassociates.com Fri Jul 4 11:24:27 2008 From: erin at withassociates.com (Erin Staniland) Date: Fri, 4 Jul 2008 16:24:27 +0100 Subject: [rspec-users] Open source projects using RSpec In-Reply-To: <745312bd0807040329n461ea58j23be41615cbc66e0@mail.gmail.com> References: <745312bd0807040329n461ea58j23be41615cbc66e0@mail.gmail.com> Message-ID: I know there are stories in the restful-authentication plugin http://github.com/technoweenie/restful-authentication/tree/master/generators/authenticated/templates/stories Erin On 4 Jul 2008, at 11:29, Olivier Dupuis wrote: > Hello, > > Anyone knows of open source projects that uses RSpec and RSpec > Stories? I'd love to see how it is being used in different projects. > > Thank you > > Olivier Dupuis > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users - - - - - - - - - - - - - - - - - - - With Associates Top Floor 100 De Beauvoir Road London N1 4EN +44 (0) 20 7923 4757 www.withassociates.com - - - - - - - - - - - - - - - - - - - - With Associates is the trading name of With Associates UK LLP Registered office: Top Floor 100 De Beauvoir Rd, N1 4EN Registered in England under registration No. OC313207 From dchelimsky at gmail.com Fri Jul 4 11:23:18 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 4 Jul 2008 10:23:18 -0500 Subject: [rspec-users] Open source projects using RSpec In-Reply-To: <745312bd0807040329n461ea58j23be41615cbc66e0@mail.gmail.com> References: <745312bd0807040329n461ea58j23be41615cbc66e0@mail.gmail.com> Message-ID: <7156D897-8E0B-49CB-9B3A-87BA04A197D2@gmail.com> On Jul 4, 2008, at 5:29 AM, Olivier Dupuis wrote: > Hello, > > Anyone knows of open source projects that uses RSpec and RSpec > Stories? I'd love to see how it is being used in different projects. Here are a few that I know of: rspec examples (no stories) * http://github.com/wycats/merb-core and friends * http://github.com/sam/dm-core and friends * http://github.com/technoweenie/mephisto rspec examples and stories * http://github.com/technoweenie/restful-authentication (generates example groups and stories) I think the most exciting development over the last year is the rubyspec project (http://github.com/rubyspec/rubyspec), which is an executable language specification for the Ruby language. This effort started as part of the (http://github.com/evanphx/rubinius) project. The rubinius team wanted to use rspec because they liked the feel, but they couldn't because rspec uses advanced language features that rubinius just didn't have early on (makes sense). So they developed their own implementation of a useful subset of the rspec-feature-set called mspec (http://github.com/rubyspec/mspec). As I understand it, rubinius is very close to being able to run against rspec-proper at this point. Meanwhile, rubyspec and mspec were split out into their own projects, and now rubinus, JRuby (http://jruby.codehaus.org/) and even MRI (http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8/Makefile.in - scroll down) are running against rubyspec as part of their build process. Very, very exciting stuff for the Ruby community as the end- result will be a single, definitive resource for anybody who wants to implement a standards-compliant Ruby interpreter. Cheers, David > Thank you > > Olivier Dupuis From mark.wilden at gmail.com Fri Jul 4 12:17:22 2008 From: mark.wilden at gmail.com (Mark Wilden) Date: Fri, 4 Jul 2008 09:17:22 -0700 Subject: [rspec-users] Fwd: Attempting to Make Sense of RSpec use In-Reply-To: <3c30da400807040740p4a2364abs692ec6db9daa54c2@mail.gmail.com> References: <57a815bf0807031809o3ebc754bqcf3ed6445b9beeb9@mail.gmail.com> <3c30da400807031927p59aa7fa1mf6677022bec849c0@mail.gmail.com> <3c30da400807032055q5d13a17ejdd9ea561657493d8@mail.gmail.com> <3D6AB582-FD6C-4B07-A628-D9B89F029170@gmail.com> <3c30da400807040740p4a2364abs692ec6db9daa54c2@mail.gmail.com> Message-ID: <3c30da400807040917o451e14wc6e64a9b81c2574c@mail.gmail.com> On Fri, Jul 4, 2008 at 6:28 AM, David Chelimsky wrote: > On Jul 3, 2008, at 10:55 PM, Mark Wilden wrote: > > The problem I just found with shared specs is that if one fails, you don't >> see the sharer in the callstack, so you really don't know what went wrong. >> > > Even if you run it with --backtrace? > I didn't think of that - I'll give it a shot next time I'm in those specs. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Fri Jul 4 16:23:12 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 4 Jul 2008 16:23:12 -0400 Subject: [rspec-users] Re-use scenarios from another story file? In-Reply-To: <8c90cb7d0807040117tbe69701ueba0a9a1cec483a6@mail.gmail.com> References: <8c90cb7d0807030957s6d2071f8x5d30d9629dbc9820@mail.gmail.com> <8c90cb7d0807040117tbe69701ueba0a9a1cec483a6@mail.gmail.com> Message-ID: <85d99afe0807041323p5c59664eg648b5bc581a72fcf@mail.gmail.com> A short experience report regarding this thread: Early on when stories were introduced to rspec's code base I started using them, and I tried some different techniques to see what the sweet spot was for using stories in actual development. To do some of this I made modifications to rspec (this was before stories were released officially) In my experience I found that trying to build up a highly re-usable set of steps caused a lot more overhead, both in the creation of new features and in the maintenance of ongoing development or changes to existing features. In practice has been much easier for me to build reusability in the form of helper methods which sit behind steps, and even to allow yourself to have very simple (even one line) step definitions. One problem I noticed I ran into was that I spent too much time trying to organize and group reusable sets of steps. This made it difficult when one story changed in how it did something, but another one did not, and it made my stories rely on several step files (ie: steps_for => [:site_navigation, :project_navigation, :project_creation, etc.]). Sometimes I would end up having to reorganize, or split one step into two, and then go find all places where things would be affected by this, etc. I also found that by focusing on this kind of step reusability I was writing much more granular stories (ie: implicit story style). When trying out what is now known as the declarative story style I have found that introducing new features and changing existing features takes much less time when all of my steps for a story are in as few as possible step files (typically just one step file). When I notice that two stories both have a scenario where the implementation of a step is the same, I pull that out into a helper much like David suggested. Now if one of those stories changes, you can change its step w/o affecting any others. In summary, don't focus on step reusability across stories, instead pull out helpers while allowing the steps to be defined separately for their respecive stories. This will make it easier to introduce new features and maintain/change existing features over the lifetime of the app. HTH, Zach On Fri, Jul 4, 2008 at 4:17 AM, David Salgado wrote: > > Unless you're looking for the steps to show up when you run things, why not >> just have a helper method that does the setup for you and then have a Given >> step that invokes that method? >> >> I know I can extract logic into steps, but I'd like the pre-requisite >>> scenarios to have some assertions, and it doesn't feel right to put >>> assertions in steps (if that's possible). >>> >> >> I'm not sure understand this. Don't you have expectations (assertions) in >> all your Then steps? >> > > Sure. I was just hoping I could keep my prereq stuff as a story in its own > right - more for clarity when discussing requirements than for any other > reason. If it's just a step or a helper method, then that particular story > is reduced to a one-liner. I know I could always do both, and not be 100% > DRY, so I guess that's what I'll do. > > Thanks for the advice > > David > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Fri Jul 4 16:35:14 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 4 Jul 2008 16:35:14 -0400 Subject: [rspec-users] Open source projects using RSpec In-Reply-To: <7156D897-8E0B-49CB-9B3A-87BA04A197D2@gmail.com> References: <745312bd0807040329n461ea58j23be41615cbc66e0@mail.gmail.com> <7156D897-8E0B-49CB-9B3A-87BA04A197D2@gmail.com> Message-ID: <85d99afe0807041335ld593b80g40e90d986915862c@mail.gmail.com> Strac uses rspec examples and stories. http://github.com/mvanholstyn/strac Zach On Fri, Jul 4, 2008 at 11:23 AM, David Chelimsky wrote: > On Jul 4, 2008, at 5:29 AM, Olivier Dupuis wrote: > > Hello, >> >> Anyone knows of open source projects that uses RSpec and RSpec Stories? >> I'd love to see how it is being used in different projects. >> > > Here are a few that I know of: > > rspec examples (no stories) > * http://github.com/wycats/merb-core and friends > * http://github.com/sam/dm-core and friends > * http://github.com/technoweenie/mephisto > > rspec examples and stories > * http://github.com/technoweenie/restful-authentication (generates example > groups and stories) > > I think the most exciting development over the last year is the rubyspec > project (http://github.com/rubyspec/rubyspec), which is an executable > language specification for the Ruby language. This effort started as part of > the (http://github.com/evanphx/rubinius) project. The rubinius team wanted > to use rspec because they liked the feel, but they couldn't because rspec > uses advanced language features that rubinius just didn't have early on > (makes sense). So they developed their own implementation of a useful subset > of the rspec-feature-set called mspec (http://github.com/rubyspec/mspec). > As I understand it, rubinius is very close to being able to run against > rspec-proper at this point. > > Meanwhile, rubyspec and mspec were split out into their own projects, and > now rubinus, JRuby (http://jruby.codehaus.org/) and even MRI ( > http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8/Makefile.in - scroll > down) are running against rubyspec as part of their build process. Very, > very exciting stuff for the Ruby community as the end-result will be a > single, definitive resource for anybody who wants to implement a > standards-compliant Ruby interpreter. > > Cheers, > David > > > Thank you >> >> Olivier Dupuis >> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Jul 4 16:45:48 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 4 Jul 2008 15:45:48 -0500 Subject: [rspec-users] auto-generated descriptions Message-ID: Hey all, I'm looking for ways to optimize rspec and came upon something interesting. If I remove handling for auto-generated descriptions (the thing that allows you to say "specify { 5.should == 5 }" with no description string) we get an average 35% performance increase per expectation. 35%. That's huge. So - how bad do you think this would suck to remove that feature? Are you using it yourself? All thoughts welcome. Thanks, David From mailing_lists at railsnewbie.com Fri Jul 4 17:03:51 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 4 Jul 2008 17:03:51 -0400 Subject: [rspec-users] Open source projects using RSpec In-Reply-To: <745312bd0807040329n461ea58j23be41615cbc66e0@mail.gmail.com> References: <745312bd0807040329n461ea58j23be41615cbc66e0@mail.gmail.com> Message-ID: <837D891C-F0F0-48B0-9107-BA28AECBCE06@railsnewbie.com> On Jul 4, 2008, at 6:29 AM, Olivier Dupuis wrote: > Hello, > > Anyone knows of open source projects that uses RSpec and RSpec > Stories? I'd love to see how it is being used in different projects. There are lots of projects: rspec itself, rubinius / rubyspec a series of rails plugins, like: webrat, fixture replacement deeptest You might also try searching the list - Obie Fernandez asked about this a while back. Scott From pergesu at gmail.com Fri Jul 4 18:20:21 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 4 Jul 2008 15:20:21 -0700 Subject: [rspec-users] [rspec-devel] auto-generated descriptions In-Reply-To: References: Message-ID: <810a540e0807041520x3691ce1ft3b114157bd47af40@mail.gmail.com> On Fri, Jul 4, 2008 at 1:45 PM, David Chelimsky wrote: > Hey all, > > I'm looking for ways to optimize rspec and came upon something interesting. > If I remove handling for auto-generated descriptions (the thing that allows > you to say "specify { 5.should == 5 }" with no description string) we get an > average 35% performance increase per expectation. 35%. That's huge. > > So - how bad do you think this would suck to remove that feature? Are you > using it yourself? > > All thoughts welcome. To be clear, this is for taking a spec like: it { 2.should == 2 } and then when running with the specdoc formatter, getting - should == 2 I personally don't use specdoc format very often anyway. My intuition is that writing specs without a description (which I frequently use) is optimized for programmer clarity, so auto-generating a description for it is less important. I understand that the description would be used in a number of other places, including error messages, but in the case of error messages I just use line numbers. Basically, auto-generating descriptions are valuable, but fall way short of withholding a 35% performance improvement. Pat From matt at matt-darby.com Fri Jul 4 19:19:22 2008 From: matt at matt-darby.com (Matt Darby) Date: Fri, 4 Jul 2008 19:19:22 -0400 Subject: [rspec-users] auto-generated descriptions In-Reply-To: References: Message-ID: <12565DB4-9DF2-43A8-B129-7B502C77F076@matt-darby.com> On Jul 4, 2008, at 4:45 PM, David Chelimsky wrote: > > So - how bad do you think this would suck to remove that feature? > Are you using it yourself? > > All thoughts welcome. Wasn't even aware that feature existed! From avdi at avdi.org Fri Jul 4 20:36:13 2008 From: avdi at avdi.org (Avdi Grimm) Date: Fri, 4 Jul 2008 20:36:13 -0400 Subject: [rspec-users] auto-generated descriptions In-Reply-To: References: Message-ID: On Fri, Jul 4, 2008 at 4:45 PM, David Chelimsky wrote: > So - how bad do you think this would suck to remove that feature? Are you > using it yourself? Personally, I *love* this feature, and would not like to see it go. One of my heuristics for a good spec is that it either a) has a clear spec doc string; or b) auto-formats to a clearly understandable doc string. I run spec -fs periodically to verify this. The fact that I can I can write a sizable subset of my specs in a very DRY way thanks to the auto-formatting feature is one of my favorite little perks of using RSpec. -- Avdi Home: http://avdi.org Developer Blog: http://avdi.org/devblog/ Twitter: http://twitter.com/avdi Journal: http://avdi.livejournal.com From steve at deepsalt.com Fri Jul 4 22:18:19 2008 From: steve at deepsalt.com (Steve Eley) Date: Fri, 4 Jul 2008 22:18:19 -0400 Subject: [rspec-users] auto-generated descriptions In-Reply-To: References: Message-ID: <74243c220807041918l47c5def9ia19e5860d2a704f4@mail.gmail.com> On Fri, Jul 4, 2008 at 4:45 PM, David Chelimsky wrote: > > So - how bad do you think this would suck to remove that feature? Are you > using it yourself? I'm not, but would it be impractical to extract it out into some sort of module or helper and tell people to include it in their config.* block if they want to use it? -- Have Fun, Steve Eley From ben at benmabey.com Fri Jul 4 22:20:06 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 04 Jul 2008 20:20:06 -0600 Subject: [rspec-users] Re-use scenarios from another story file? In-Reply-To: <85d99afe0807041323p5c59664eg648b5bc581a72fcf@mail.gmail.com> References: <8c90cb7d0807030957s6d2071f8x5d30d9629dbc9820@mail.gmail.com> <8c90cb7d0807040117tbe69701ueba0a9a1cec483a6@mail.gmail.com> <85d99afe0807041323p5c59664eg648b5bc581a72fcf@mail.gmail.com> Message-ID: <486EDA56.6050903@benmabey.com> Zach Dennis wrote: > A short experience report regarding this thread: > > Early on when stories were introduced to rspec's code base I started > using them, and I tried some different techniques to see what the > sweet spot was for using stories in actual development. To do some of > this I made modifications to rspec (this was before stories were > released officially) > > In my experience I found that trying to build up a highly re-usable > set of steps caused a lot more overhead, both in the creation of new > features and in the maintenance of ongoing development or changes to > existing features. In practice has been much easier for me to build > reusability in the form of helper methods which sit behind steps, and > even to allow yourself to have very simple (even one line) step > definitions. > > One problem I noticed I ran into was that I spent too much time trying > to organize and group reusable sets of steps. This made it difficult > when one story changed in how it did something, but another one did > not, and it made my stories rely on several step files (ie: steps_for > => [:site_navigation, :project_navigation, :project_creation, etc.]). > Sometimes I would end up having to reorganize, or split one step into > two, and then go find all places where things would be affected by > this, etc. > > I also found that by focusing on this kind of step reusability I was > writing much more granular stories (ie: implicit story style). When > trying out what is now known as the declarative story style I have > found that introducing new features and changing existing features > takes much less time when all of my steps for a story are in as few as > possible step files (typically just one step file). When I notice that > two stories both have a scenario where the implementation of a step is > the same, I pull that out into a helper much like David suggested. Now > if one of those stories changes, you can change its step w/o affecting > any others. > > In summary, don't focus on step reusability across stories, instead > pull out helpers while allowing the steps to be defined separately for > their respecive stories. This will make it easier to introduce new > features and maintain/change existing features over the lifetime of > the app. > > HTH, > > Zach > +1. I have had the exact same experience. Reusing story steps too aggressively tends to lead to awkward stories that have a higher maintenance cost for several reasons. -Ben From ben at benmabey.com Fri Jul 4 22:32:06 2008 From: ben at benmabey.com (Ben Mabey) Date: Fri, 04 Jul 2008 20:32:06 -0600 Subject: [rspec-users] auto-generated descriptions In-Reply-To: References: Message-ID: <486EDD26.6010901@benmabey.com> David Chelimsky wrote: > Hey all, > > I'm looking for ways to optimize rspec and came upon something > interesting. If I remove handling for auto-generated descriptions (the > thing that allows you to say "specify { 5.should == 5 }" with no > description string) we get an average 35% performance increase per > expectation. 35%. That's huge. > > So - how bad do you think this would suck to remove that feature? Are > you using it yourself? > > All thoughts welcome. > > Thanks, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users David, I personally like that feature, but I honestly don't find myself using it too much. 35% is a lot. One suggestion would be to keep the functionality but move it to a different keyword so that the common "it"/"specify" case is made faster. That way we could have our cake and eat it too. I'm not too sure on what keyword could be used though. "Expect" comes to mind but I think that is because of Jay Fields expectations framework. Which, BTW, if we added support for that to coexist within rspec example groups then the need for rspec to support the feature natively would diminish. So that is another option that may be worth investigating. Could you maybe post the diff of your changes to turn off that feature? I'd be interested in seeing how much speed improvements I get with my slower spec suites. Thanks, Ben From raasdnil at gmail.com Fri Jul 4 22:54:17 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Sat, 5 Jul 2008 12:54:17 +1000 Subject: [rspec-users] auto-generated descriptions In-Reply-To: <74243c220807041918l47c5def9ia19e5860d2a704f4@mail.gmail.com> References: <74243c220807041918l47c5def9ia19e5860d2a704f4@mail.gmail.com> Message-ID: <57a815bf0807041954r1b8b093ew36b93753a5d1cfc3@mail.gmail.com> On Sat, Jul 5, 2008 at 12:18 PM, Steve Eley wrote: > On Fri, Jul 4, 2008 at 4:45 PM, David Chelimsky wrote: >> So - how bad do you think this would suck to remove that feature? Are you >> using it yourself? > I'm not, but would it be impractical to extract it out into some sort > of module or helper and tell people to include it in their config.* > block if they want to use it? +1 config.enable_auto_generating_descriptions = true 35% is 35%... Mikel -- http://lindsaar.net/ Rails, RSpec, Puppet and Life blog.... From mailing_lists at railsnewbie.com Fri Jul 4 23:42:42 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 4 Jul 2008 23:42:42 -0400 Subject: [rspec-users] auto-generated descriptions In-Reply-To: <57a815bf0807041954r1b8b093ew36b93753a5d1cfc3@mail.gmail.com> References: <74243c220807041918l47c5def9ia19e5860d2a704f4@mail.gmail.com> <57a815bf0807041954r1b8b093ew36b93753a5d1cfc3@mail.gmail.com> Message-ID: <8C9BB4FC-0F1E-4DA2-8C97-F1F18247D3B7@railsnewbie.com> On Jul 4, 2008, at 10:54 PM, Mikel Lindsaar wrote: > On Sat, Jul 5, 2008 at 12:18 PM, Steve Eley > wrote: >> On Fri, Jul 4, 2008 at 4:45 PM, David Chelimsky >> wrote: >>> So - how bad do you think this would suck to remove that feature? >>> Are you >>> using it yourself? >> I'm not, but would it be impractical to extract it out into some sort >> of module or helper and tell people to include it in their config.* >> block if they want to use it? > > +1 > > config.enable_auto_generating_descriptions = true > > 35% is 35%... > > Mikel > I would think autoloading rspec (with Module#autoload) would be a big speed up for features that aren't used... Besides - where are the benchmarks? Scott From olivierdupuis at gmail.com Sat Jul 5 07:01:53 2008 From: olivierdupuis at gmail.com (Olivier Dupuis) Date: Sat, 5 Jul 2008 07:01:53 -0400 Subject: [rspec-users] Open source projects using RSpec In-Reply-To: <837D891C-F0F0-48B0-9107-BA28AECBCE06@railsnewbie.com> References: <745312bd0807040329n461ea58j23be41615cbc66e0@mail.gmail.com> <837D891C-F0F0-48B0-9107-BA28AECBCE06@railsnewbie.com> Message-ID: <745312bd0807050401v139f8ebdm349c430b3be99e7@mail.gmail.com> On Fri, Jul 4, 2008 at 5:03 PM, Scott Taylor wrote: > > On Jul 4, 2008, at 6:29 AM, Olivier Dupuis wrote: > > Hello, >> >> Anyone knows of open source projects that uses RSpec and RSpec Stories? >> I'd love to see how it is being used in different projects. >> > > There are lots of projects: > > rspec itself, > rubinius / rubyspec > a series of rails plugins, like: > webrat, > fixture replacement > deeptest > > You might also try searching the list - Obie Fernandez asked about this a > while back. > > Scott > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Thanks everyone for your suggestions. Those should certainly help. Olivier Dupuis -------------- next part -------------- An HTML attachment was scrubbed... URL: From david at digitalronin.com Sat Jul 5 08:42:39 2008 From: david at digitalronin.com (David Salgado) Date: Sat, 5 Jul 2008 13:42:39 +0100 Subject: [rspec-users] Re-use scenarios from another story file? In-Reply-To: <486EDA56.6050903@benmabey.com> References: <8c90cb7d0807030957s6d2071f8x5d30d9629dbc9820@mail.gmail.com> <8c90cb7d0807040117tbe69701ueba0a9a1cec483a6@mail.gmail.com> <85d99afe0807041323p5c59664eg648b5bc581a72fcf@mail.gmail.com> <486EDA56.6050903@benmabey.com> Message-ID: <8c90cb7d0807050542m63050421h2aeeb31c3486f656@mail.gmail.com> Many thanks for the advice, guys. David 2008/7/5 Ben Mabey : > Zach Dennis wrote: > >> A short experience report regarding this thread: >> >> Early on when stories were introduced to rspec's code base I started using >> them, and I tried some different techniques to see what the sweet spot was >> for using stories in actual development. To do some of this I made >> modifications to rspec (this was before stories were released officially) >> >> In my experience I found that trying to build up a highly re-usable set of >> steps caused a lot more overhead, both in the creation of new features and >> in the maintenance of ongoing development or changes to existing features. >> In practice has been much easier for me to build reusability in the form of >> helper methods which sit behind steps, and even to allow yourself to have >> very simple (even one line) step definitions. >> >> One problem I noticed I ran into was that I spent too much time trying to >> organize and group reusable sets of steps. This made it difficult when one >> story changed in how it did something, but another one did not, and it made >> my stories rely on several step files (ie: steps_for => [:site_navigation, >> :project_navigation, :project_creation, etc.]). Sometimes I would end up >> having to reorganize, or split one step into two, and then go find all >> places where things would be affected by this, etc. >> >> I also found that by focusing on this kind of step reusability I was >> writing much more granular stories (ie: implicit story style). When trying >> out what is now known as the declarative story style I have found that >> introducing new features and changing existing features takes much less time >> when all of my steps for a story are in as few as possible step files >> (typically just one step file). When I notice that two stories both have a >> scenario where the implementation of a step is the same, I pull that out >> into a helper much like David suggested. Now if one of those stories >> changes, you can change its step w/o affecting any others. >> >> In summary, don't focus on step reusability across stories, instead pull >> out helpers while allowing the steps to be defined separately for their >> respecive stories. This will make it easier to introduce new features and >> maintain/change existing features over the lifetime of the app. >> >> HTH, >> >> Zach >> >> > +1. I have had the exact same experience. Reusing story steps too > aggressively tends to lead to awkward stories that have a higher maintenance > cost for several reasons. > -Ben > > _______________________________________________ > 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 hayafirst at gmail.com Sat Jul 5 09:26:39 2008 From: hayafirst at gmail.com (Yi Wen) Date: Sat, 5 Jul 2008 08:26:39 -0500 Subject: [rspec-users] auto-generated descriptions In-Reply-To: <74243c220807041918l47c5def9ia19e5860d2a704f4@mail.gmail.com> References: <74243c220807041918l47c5def9ia19e5860d2a704f4@mail.gmail.com> Message-ID: +1. This is a smart. On Fri, Jul 4, 2008 at 9:18 PM, Steve Eley wrote: > On Fri, Jul 4, 2008 at 4:45 PM, David Chelimsky wrote: >> >> So - how bad do you think this would suck to remove that feature? Are you >> using it yourself? > > I'm not, but would it be impractical to extract it out into some sort > of module or helper and tell people to include it in their config.* > block if they want to use it? > > > -- > Have Fun, > Steve Eley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Sat Jul 5 10:03:58 2008 From: lists at ruby-forum.com (John Knox) Date: Sat, 5 Jul 2008 16:03:58 +0200 Subject: [rspec-users] Does RSpec work nicely with UUID primary keys? Message-ID: <4f53853a313b2a232707027e466b8341@ruby-forum.com> I have my application happily generating UUID primary keys using the uuidtools gem. But the auto-generated specifications created by "script/generate rspec_scaffold...", etc, assume that one is using a sequential integer primary key. For those who have hit this same issue, is it just a matter of rewriting the auto-generated specifications to take this into account, or does one have to dig into the code of rspec because this assumptions is hardwired in? Thanks in advance. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sat Jul 5 10:15:05 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 5 Jul 2008 09:15:05 -0500 Subject: [rspec-users] Does RSpec work nicely with UUID primary keys? In-Reply-To: <4f53853a313b2a232707027e466b8341@ruby-forum.com> References: <4f53853a313b2a232707027e466b8341@ruby-forum.com> Message-ID: <9DD69619-3ACF-4711-BBCD-40311366D5A9@gmail.com> On Jul 5, 2008, at 9:03 AM, John Knox wrote: > I have my application happily generating UUID primary keys using the > uuidtools gem. > > But the auto-generated specifications created by "script/generate > rspec_scaffold...", etc, assume that one is using a sequential integer > primary key. > > For those who have hit this same issue, is it just a matter of > rewriting > the auto-generated specifications to take this into account, or does > one > have to dig into the code of rspec because this assumptions is > hardwired > in? What happens when you run the generated examples? From steve at deepsalt.com Sat Jul 5 11:10:31 2008 From: steve at deepsalt.com (Steve Eley) Date: Sat, 5 Jul 2008 11:10:31 -0400 Subject: [rspec-users] Does RSpec work nicely with UUID primary keys? In-Reply-To: <4f53853a313b2a232707027e466b8341@ruby-forum.com> References: <4f53853a313b2a232707027e466b8341@ruby-forum.com> Message-ID: <74243c220807050810q64c7ff5ax7ff25ad566da7bba@mail.gmail.com> On Sat, Jul 5, 2008 at 10:03 AM, John Knox wrote: > > But the auto-generated specifications created by "script/generate > rspec_scaffold...", etc, assume that one is using a sequential integer > primary key. That's just the fixtures in spec/fixtures. They're using the old fixture style, where all the IDs are hardcoded. You can modify the fixtures easily enough simply by removing the ID field from each of them; if you're using Rails 2.0 or higher, read up on the "foxy fixtures" behavior where it handles ID generation and associations in a much smarter way. Better yet, for more flexibility, get rid of the fixtures entirely and create your test data using some sort of factory method. If you're doing something fundamentally different with your data like UUID primary keys, you might _have_ to do this. The Peepcode screencasts about RSpec show easy examples of how to define create_foo() methods in your specs. Or you could use one of the various fixture replacement plugins/gems: Fixture Replacement 2: http://replacefixtures.rubyforge.org/ (This is the one I use. I love it.) Factory Girl: http://giantrobots.thoughtbot.com/2008/6/6/waiting-for-a-factory-girl can_has_fixtures: http://github.com/benburkert/can_has_fixtures/tree/master If you use any of these, you will of course end up having to change the autogenerated specs in spec/models. But for models at least, the RSpec generator puts virtually nothing in, so that only means changing one or two lines of code each time. I don't consider that much of a burden. -- Have Fun, Steve Eley Deep Salt Team From lists at ruby-forum.com Sat Jul 5 11:37:50 2008 From: lists at ruby-forum.com (John Knox) Date: Sat, 5 Jul 2008 17:37:50 +0200 Subject: [rspec-users] Does RSpec work nicely with UUID primary keys? In-Reply-To: <9DD69619-3ACF-4711-BBCD-40311366D5A9@gmail.com> References: <4f53853a313b2a232707027e466b8341@ruby-forum.com> <9DD69619-3ACF-4711-BBCD-40311366D5A9@gmail.com> Message-ID: <0008c5cc9a3f2435784b610ddfe9bbfa@ruby-forum.com> David Chelimsky wrote: > What happens when you run the generated examples? My code uses single table inheritance (STI) and a MySQL database, so I thought it best to create some new simple projects with a single model. (1) I created a new project using SQLite with a single model. All 58 auto-generated specifications ran successfully. (2) I created a new single-model project using SQLite but added a UUID primary key. All 58 auto-generated specifications ran successfully. (3) I created a new project using MySQL with a single model. Again, all 58 auto-generated specifications ran successfully. (4) (2) I created a new single-model project using MySQL but added a UUID primary key. All 58 auto-generated specifications ran successfully. Hmm. So, it's not the UUIDs that are causing problems with my application... but perhaps single table inheritance. Will do more tests and post again when I've better defined the problem. Sorry for the confusion, Dave, but perhaps this will help somebody else searching the list. And Steve, will look into your suggestions for fixtures. Thanks very much. -- Posted via http://www.ruby-forum.com/. From tiffani2k3 at gmail.com Sat Jul 5 15:50:33 2008 From: tiffani2k3 at gmail.com (Tiffani Ashley Bell) Date: Sat, 5 Jul 2008 15:50:33 -0400 Subject: [rspec-users] Attempting to Make Sense of RSpec use In-Reply-To: <57a815bf0807031809o3ebc754bqcf3ed6445b9beeb9@mail.gmail.com> References: <57a815bf0807031809o3ebc754bqcf3ed6445b9beeb9@mail.gmail.com> Message-ID: Awesome. I totally get it, but is that how you're always supposed to spec out associations and all the methods that go with an association like "create" and such? I'm interested in that because I'm specing a lot of code that deals heavily with code that has associations going on, yet none of the examples of RSpec use I come across have anything about associations and RSpec. I don't imagine they'd be handled too differently, but it's just something wondered about. Right now, I'm testing and building up a controller and so far my tests have been passing as long as I don't run into any examples that involve associations. This code, for example, has been giving me a few issues: # my users_controller_spec.rb (or at least, the relevant part) describe UsersController do fixtures :users before(:each) do @tiffani = users(:tiffani) @users = [@tiffani] @users.stub!(:build).and_return(@tiffani) @mock_account = mock_model(Account, :users => @users, :save => true) end describe "when creating a User" do it "should return the registration form for adding a User on GET new" do User.should_receive(:new).once get :new end it "should render the new User registration form on GET new" do get :new response.should render_template("users/new") end it "should create a new User and then redirect to that User's profile on POST create" do @mock_account.should_receive(:new) post :create, :new_user => { :first_name => @tiffani.first_name, :last_name => @tiffani.last_name, :email_address => @tiffani.email_address } end it "should redirect to users/new when User is setup with invalid data" end # ... end And in users_controller.rb: def create @new_account = Account.new(params[:account]) @new_user = @new_account.users.build(params[:new_user]) respond_to do |wants| if @new_account.save flash[:notice] = "Welcome, #{ @new_user.first_name }!" wants.html { redirect_to(user_url(@new_user)) } else wants.html { render :action => "new" } end end end When I run the tests the third test fails and RSpec complains that "Mock 'Account_1003' expected :new with (any args) once, but received it 0 times" I'm confused about that since I am calling Account.new in the create method on the controller. What's really wrong here? Thanks in advance for answering my RSpec questions! :D --Tiffani AB On Thu, Jul 3, 2008 at 9:09 PM, Mikel Lindsaar wrote: > On Fri, Jul 4, 2008 at 8:32 AM, Tiffani Ashley Bell > wrote: > > Hi everybody, > > Hi Tiffany, welcome to Rspec > > > I was reading the Typo source code, however, and came across some code > that > > I didn't know exactly how it worked. I've noticed that in testing one of > > their controllers, they use a variable (@comments) that they don't > declare > > anywhere else, yet they use it as a stand in for collections on some of > the > > mocks. How is that possible? I know in the mocking documentation it > says > > that you can define collaborations with other objects before those > objects > > exist, but how is that working in this code? I only ask that because > later, > > you see code like this: @comments.stub!(:build).and_return(@comment). > > If you have a look at the descriptions, they use :shared => true. > This is a way of being DRY in RSpec (which I personally don't think is > such a good idea). > > What the shared => true declaration allows you to do is to include > that block of code elsewhere with 'it should behave like my shared > code' > > So we have (describe "All Requests", :shared => true do) > > and then the next description block is: > > describe "General Comment Creation", :shared => true do > it_should_behave_like "All Requests" > > Which then includes the All Requests block (which is just a before method). > > The @comments variable gets declared in: > > @comments.stub!(:build).and_return(@comment) > > and then this is tied in to the Article model in the _previous_ code > block like so: > > @article = mock_model(Article, > :comments => @comments, > :published_comments => @comments, > :add_comment => @comment) > > > So when you call @article.comments you get @comments as a stub back > which stubs :build and returns a @comment. > > Ugh. > > This is where, in RSpec, you can dig a very fast grave. Because > you'll come back to this code in 6-12 months and be totally stuck > trying to figure out what is where. > > I recently wrote a viewpoint on this that might help you: > > http://www.lindsaar.net/2008/6/24/tip-24-being-clever-in-specs-is-for-dummies > > Hope you do well with Rspec, feel free to ask more questions! > > -- > http://lindsaar.net/ > Rails, RSpec, Puppet and Life blog.... > _______________________________________________ > 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 jarkko at jlaine.net Sat Jul 5 16:11:29 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Sat, 5 Jul 2008 23:11:29 +0300 Subject: [rspec-users] Does RSpec work nicely with UUID primary keys? In-Reply-To: <0008c5cc9a3f2435784b610ddfe9bbfa@ruby-forum.com> References: <4f53853a313b2a232707027e466b8341@ruby-forum.com> <9DD69619-3ACF-4711-BBCD-40311366D5A9@gmail.com> <0008c5cc9a3f2435784b610ddfe9bbfa@ruby-forum.com> Message-ID: On 5.7.2008, at 18.37, John Knox wrote: > David Chelimsky wrote: >> What happens when you run the generated examples? > > My code uses single table inheritance (STI) and a MySQL database, so I > thought it best to create some new simple projects with a single > model. > > (1) I created a new project using SQLite with a single model. All 58 > auto-generated specifications ran successfully. > > (2) I created a new single-model project using SQLite but added a UUID > primary key. All 58 auto-generated specifications ran successfully. > > (3) I created a new project using MySQL with a single model. Again, > all > 58 auto-generated specifications ran successfully. > > (4) (2) I created a new single-model project using MySQL but added a > UUID primary key. All 58 auto-generated specifications ran > successfully. > > Hmm. So, it's not the UUIDs that are causing problems with my > application... but perhaps single table inheritance. Will do more > tests > and post again when I've better defined the problem. The thing is, the scaffolding specs are specs for the behaviour of the scaffolded controllers/models/views. If you want to change that behaviour, your specs should reflect that assumption. If you add some new code (without writing new specs for it), even in the form of using plugins, and your existing specs still run, it doesn't mean your code is working correctly because you didn't write specs for that part of the functionality yet. Using UUID probably changes things so little that (especially if/when they mock the models) it won't trip the scaffolding specs per se. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available URL: From steve at deepsalt.com Sat Jul 5 17:00:55 2008 From: steve at deepsalt.com (Steve Eley) Date: Sat, 5 Jul 2008 17:00:55 -0400 Subject: [rspec-users] Attempting to Make Sense of RSpec use In-Reply-To: References: <57a815bf0807031809o3ebc754bqcf3ed6445b9beeb9@mail.gmail.com> Message-ID: <74243c220807051400n592e0ba4v346a845fcbc8f507@mail.gmail.com> On Sat, Jul 5, 2008 at 3:50 PM, Tiffani Ashley Bell wrote: > > When I run the tests the third test fails and RSpec complains that "Mock > 'Account_1003' expected :new with (any args) once, but received it 0 times" > > I'm confused about that since I am calling Account.new in the create method > on the controller. What's really wrong here? The problem there is that Account.new is a _class_ method on the Account class. The @mock_account you made is an _instance_ of Account (actually, not even that, it's a mock object that will pretend it's an Account if you ask it). You're not sending @mock_account any messages, you're sending them to the Account class. To do what you want, you need to stub that class, for instance: Account.stub!(:new).and_return(@mock_account) And in the spec you can do Account.should_receive(:new). There's some other stuff in that spec that looks a bit messy... Generally speaking, you can do some pretty clean tests with fixtures *or* you can do tests by mocking everything, but it's not a great idea to do both at the same time. In controller specs, best practice is usually to mock your models and not touch the real models or the database (i.e. fixtures) at all, because A.) it's faster and B.) you're isolating your tests to *just* the controller code, and won't have to worry about tests failing because the models are broken. (That's what the model specs are for.) >8-> I'm also unclear on the relationship between User and Account in this code, and why you're creating a new account for every new user in the UsersController... But that's really about your application, not about RSpec. If that's how your application needs to behave, then your spec here seems to be on the right track. I hope this was helpful. I'm just figuring a lot of this out myself, and my main reason for answering you was to reinforce this stuff in my _own_ mind. >8-> > > Thanks in advance for answering my RSpec questions! :D > > --Tiffani AB > > > On Thu, Jul 3, 2008 at 9:09 PM, Mikel Lindsaar wrote: >> >> On Fri, Jul 4, 2008 at 8:32 AM, Tiffani Ashley Bell >> wrote: >> > Hi everybody, >> >> Hi Tiffany, welcome to Rspec >> >> > I was reading the Typo source code, however, and came across some code >> > that >> > I didn't know exactly how it worked. I've noticed that in testing one >> > of >> > their controllers, they use a variable (@comments) that they don't >> > declare >> > anywhere else, yet they use it as a stand in for collections on some of >> > the >> > mocks. How is that possible? I know in the mocking documentation it >> > says >> > that you can define collaborations with other objects before those >> > objects >> > exist, but how is that working in this code? I only ask that because >> > later, >> > you see code like this: @comments.stub!(:build).and_return(@comment). >> >> If you have a look at the descriptions, they use :shared => true. >> This is a way of being DRY in RSpec (which I personally don't think is >> such a good idea). >> >> What the shared => true declaration allows you to do is to include >> that block of code elsewhere with 'it should behave like my shared >> code' >> >> So we have (describe "All Requests", :shared => true do) >> >> and then the next description block is: >> >> describe "General Comment Creation", :shared => true do >> it_should_behave_like "All Requests" >> >> Which then includes the All Requests block (which is just a before >> method). >> >> The @comments variable gets declared in: >> >> @comments.stub!(:build).and_return(@comment) >> >> and then this is tied in to the Article model in the _previous_ code >> block like so: >> >> @article = mock_model(Article, >> :comments => @comments, >> :published_comments => @comments, >> :add_comment => @comment) >> >> >> So when you call @article.comments you get @comments as a stub back >> which stubs :build and returns a @comment. >> >> Ugh. >> >> This is where, in RSpec, you can dig a very fast grave. Because >> you'll come back to this code in 6-12 months and be totally stuck >> trying to figure out what is where. >> >> I recently wrote a viewpoint on this that might help you: >> >> http://www.lindsaar.net/2008/6/24/tip-24-being-clever-in-specs-is-for-dummies >> >> Hope you do well with Rspec, feel free to ask more questions! >> >> -- >> http://lindsaar.net/ >> Rails, RSpec, Puppet and Life blog.... >> _______________________________________________ >> 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 > -- Have Fun, Steve Eley Deep Salt Team From tiffani2k3 at gmail.com Sat Jul 5 17:56:05 2008 From: tiffani2k3 at gmail.com (Tiffani Ashley Bell) Date: Sat, 5 Jul 2008 17:56:05 -0400 Subject: [rspec-users] Attempting to Make Sense of RSpec use In-Reply-To: <74243c220807051400n592e0ba4v346a845fcbc8f507@mail.gmail.com> References: <57a815bf0807031809o3ebc754bqcf3ed6445b9beeb9@mail.gmail.com> <74243c220807051400n592e0ba4v346a845fcbc8f507@mail.gmail.com> Message-ID: Thanks on the reminder that "new" is a class method. Plus, I figured using mocks and fixtures together was probably a crappy idea. I'll be mocking from now on... --Tiffani AB On Sat, Jul 5, 2008 at 5:00 PM, Steve Eley wrote: > On Sat, Jul 5, 2008 at 3:50 PM, Tiffani Ashley Bell > wrote: > > > > When I run the tests the third test fails and RSpec complains that "Mock > > 'Account_1003' expected :new with (any args) once, but received it 0 > times" > > > > I'm confused about that since I am calling Account.new in the create > method > > on the controller. What's really wrong here? > > The problem there is that Account.new is a _class_ method on the > Account class. The @mock_account you made is an _instance_ of Account > (actually, not even that, it's a mock object that will pretend it's an > Account if you ask it). You're not sending @mock_account any > messages, you're sending them to the Account class. To do what you > want, you need to stub that class, for instance: > > Account.stub!(:new).and_return(@mock_account) > > And in the spec you can do Account.should_receive(:new). > > There's some other stuff in that spec that looks a bit messy... > Generally speaking, you can do some pretty clean tests with fixtures > *or* you can do tests by mocking everything, but it's not a great idea > to do both at the same time. In controller specs, best practice is > usually to mock your models and not touch the real models or the > database (i.e. fixtures) at all, because A.) it's faster and B.) > you're isolating your tests to *just* the controller code, and won't > have to worry about tests failing because the models are broken. > (That's what the model specs are for.) >8-> > > I'm also unclear on the relationship between User and Account in this > code, and why you're creating a new account for every new user in the > UsersController... But that's really about your application, not > about RSpec. If that's how your application needs to behave, then > your spec here seems to be on the right track. > > I hope this was helpful. I'm just figuring a lot of this out myself, > and my main reason for answering you was to reinforce this stuff in my > _own_ mind. >8-> > > > > > > > > Thanks in advance for answering my RSpec questions! :D > > > > --Tiffani AB > > > > > > On Thu, Jul 3, 2008 at 9:09 PM, Mikel Lindsaar > wrote: > >> > >> On Fri, Jul 4, 2008 at 8:32 AM, Tiffani Ashley Bell > >> wrote: > >> > Hi everybody, > >> > >> Hi Tiffany, welcome to Rspec > >> > >> > I was reading the Typo source code, however, and came across some code > >> > that > >> > I didn't know exactly how it worked. I've noticed that in testing one > >> > of > >> > their controllers, they use a variable (@comments) that they don't > >> > declare > >> > anywhere else, yet they use it as a stand in for collections on some > of > >> > the > >> > mocks. How is that possible? I know in the mocking documentation it > >> > says > >> > that you can define collaborations with other objects before those > >> > objects > >> > exist, but how is that working in this code? I only ask that because > >> > later, > >> > you see code like this: @comments.stub!(:build).and_return(@comment). > >> > >> If you have a look at the descriptions, they use :shared => true. > >> This is a way of being DRY in RSpec (which I personally don't think is > >> such a good idea). > >> > >> What the shared => true declaration allows you to do is to include > >> that block of code elsewhere with 'it should behave like my shared > >> code' > >> > >> So we have (describe "All Requests", :shared => true do) > >> > >> and then the next description block is: > >> > >> describe "General Comment Creation", :shared => true do > >> it_should_behave_like "All Requests" > >> > >> Which then includes the All Requests block (which is just a before > >> method). > >> > >> The @comments variable gets declared in: > >> > >> @comments.stub!(:build).and_return(@comment) > >> > >> and then this is tied in to the Article model in the _previous_ code > >> block like so: > >> > >> @article = mock_model(Article, > >> :comments => @comments, > >> :published_comments => @comments, > >> :add_comment => @comment) > >> > >> > >> So when you call @article.comments you get @comments as a stub back > >> which stubs :build and returns a @comment. > >> > >> Ugh. > >> > >> This is where, in RSpec, you can dig a very fast grave. Because > >> you'll come back to this code in 6-12 months and be totally stuck > >> trying to figure out what is where. > >> > >> I recently wrote a viewpoint on this that might help you: > >> > >> > http://www.lindsaar.net/2008/6/24/tip-24-being-clever-in-specs-is-for-dummies > >> > >> Hope you do well with Rspec, feel free to ask more questions! > >> > >> -- > >> http://lindsaar.net/ > >> Rails, RSpec, Puppet and Life blog.... > >> _______________________________________________ > >> 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 > > > > > > -- > Have Fun, > Steve Eley > Deep Salt Team > _______________________________________________ > 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 Sat Jul 5 23:30:17 2008 From: lists at ruby-forum.com (John Knox) Date: Sun, 6 Jul 2008 05:30:17 +0200 Subject: [rspec-users] Does RSpec work nicely with UUID primary keys? In-Reply-To: References: <4f53853a313b2a232707027e466b8341@ruby-forum.com> <9DD69619-3ACF-4711-BBCD-40311366D5A9@gmail.com> <0008c5cc9a3f2435784b610ddfe9bbfa@ruby-forum.com> Message-ID: <5aef31cceb65248c52399794f3248512@ruby-forum.com> Jarkko Laine wrote: > If you add some new code (without writing new specs for it), > even in the form of using plugins, and your existing specs still run, > it doesn't mean your code is working correctly because you didn't > write specs for that part of the functionality yet. That makes a lot of sense, and a useful gotcha to keep in mind. Since I'm just in the very early stages of my project, it makes sense for me start-over, get my specs working from the beginning, and ensure that they still pass after introducing inheritance through the addition of a parent class. Very impressed with the quality of replies on this list. : ) -- Posted via http://www.ruby-forum.com/. From cwdinfo at gmail.com Sun Jul 6 17:43:07 2008 From: cwdinfo at gmail.com (s.ross) Date: Sun, 6 Jul 2008 14:43:07 -0700 Subject: [rspec-users] How To Express Change of Associated Data Message-ID: <47DCCA18-DCFD-446C-8A43-05CEFAE1F5A5@gmail.com> Hello-- I'm not sure if I'm pushing too far out of specing a given model, but here's what I want to express: class A < AR::Base has_many :bs def okay(segment) end end class B < AR::Base belongs_to :a end it A, "should increase the vote count for a given segment if okayed" do @a = A.create(stuff) @a.okay(10) # okay segment 10 # here's where I'm having trouble... # a.bs should have one row, and it should have a segment number of 10 and various other stuff should happen # subsequent @a.okay with different values should transform numbers in a predictable way. This is handled in # the A model because the transforms occur only in Bs that belong to a given A. @a.bs.find_by_segment_number(10).thingie.should be(1) # not too expressive @a.okay(9) @a.bs.find_by_segment_number(9).thingie.should be(1) # still not too expressive @a.bs. find_by_segment_number(9).transformed_thingie.should be(something_else) end This kind of spec smells to me, yet I am having trouble figuring out how to explain, using rspec, exactly what the behavior is to be in a multi-step sequence. Anybody have thoughts regarding how this might be done better? Thanks From pergesu at gmail.com Sun Jul 6 18:00:57 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 6 Jul 2008 18:00:57 -0400 Subject: [rspec-users] How To Express Change of Associated Data In-Reply-To: <47DCCA18-DCFD-446C-8A43-05CEFAE1F5A5@gmail.com> References: <47DCCA18-DCFD-446C-8A43-05CEFAE1F5A5@gmail.com> Message-ID: <810a540e0807061500w756d473bp26883853a5906bf@mail.gmail.com> On Sun, Jul 6, 2008 at 5:43 PM, s.ross wrote: > Hello-- > > I'm not sure if I'm pushing too far out of specing a given model, but here's > what I want to express: > > class A < AR::Base > has_many :bs > > def okay(segment) > end > end > > class B < AR::Base > belongs_to :a > end > > it A, "should increase the vote count for a given segment if okayed" do > @a = A.create(stuff) > @a.okay(10) # okay segment 10 > # here's where I'm having trouble... > # a.bs should have one row, and it should have a segment number of 10 and > various other stuff should happen > # subsequent @a.okay with different values should transform numbers in a > predictable way. This is handled in > # the A model because the transforms occur only in Bs that belong to a > given A. > @a.bs.find_by_segment_number(10).thingie.should be(1) # not too expressive > @a.okay(9) > @a.bs.find_by_segment_number(9).thingie.should be(1) # still not too > expressive > @a.bs. find_by_segment_number(9).transformed_thingie.should > be(something_else) > end > > This kind of spec smells to me, yet I am having trouble figuring out how to > explain, using rspec, exactly what the behavior is to be in a multi-step > sequence. > > Anybody have thoughts regarding how this might be done better? Hi, You could do lambda { @a.okay(9) }.should change { @a.bs.find_by_segment_number(9) }. from(nil).to(1) I do wonder if you might be able to make it a bit more behavior-oriented, maybe something like lambda { @a.okay(9) }.should change { @a.count_votes_for(9) }.by(1) I don't know exactly what you're trying to get at though, so I can't be more specific. At any rate, does using "should change" make it more readable to you? Pat From cwdinfo at gmail.com Sun Jul 6 18:50:23 2008 From: cwdinfo at gmail.com (s.ross) Date: Sun, 6 Jul 2008 15:50:23 -0700 Subject: [rspec-users] How To Express Change of Associated Data In-Reply-To: <810a540e0807061500w756d473bp26883853a5906bf@mail.gmail.com> References: <47DCCA18-DCFD-446C-8A43-05CEFAE1F5A5@gmail.com> <810a540e0807061500w756d473bp26883853a5906bf@mail.gmail.com> Message-ID: <050C53E0-D052-4790-8958-33B98C11FF2A@gmail.com> On Jul 6, 2008, at 3:00 PM, Pat Maddox wrote: > On Sun, Jul 6, 2008 at 5:43 PM, s.ross wrote: >> Hello-- >> >> I'm not sure if I'm pushing too far out of specing a given model, >> but here's >> what I want to express: >> >> class A < AR::Base >> has_many :bs >> >> def okay(segment) >> end >> end >> >> class B < AR::Base >> belongs_to :a >> end >> >> it A, "should increase the vote count for a given segment if >> okayed" do >> @a = A.create(stuff) >> @a.okay(10) # okay segment 10 >> # here's where I'm having trouble... >> # a.bs should have one row, and it should have a segment number of >> 10 and >> various other stuff should happen >> # subsequent @a.okay with different values should transform numbers >> in a >> predictable way. This is handled in >> # the A model because the transforms occur only in Bs that belong >> to a >> given A. >> @a.bs.find_by_segment_number(10).thingie.should be(1) # not too >> expressive >> @a.okay(9) >> @a.bs.find_by_segment_number(9).thingie.should be(1) # still not too >> expressive >> @a.bs. find_by_segment_number(9).transformed_thingie.should >> be(something_else) >> end >> >> This kind of spec smells to me, yet I am having trouble figuring >> out how to >> explain, using rspec, exactly what the behavior is to be in a multi- >> step >> sequence. >> >> Anybody have thoughts regarding how this might be done better? > > Hi, > > You could do > > lambda { > @a.okay(9) > }.should change { @a.bs.find_by_segment_number(9) }. > from(nil).to(1) > > I do wonder if you might be able to make it a bit more > behavior-oriented, maybe something like > > lambda { > @a.okay(9) > }.should change { @a.count_votes_for(9) }.by(1) > > I don't know exactly what you're trying to get at though, so I can't > be more specific. At any rate, does using "should change" make it > more readable to you? Great suggestion using from and to. I am already using the behavior- oriented lambda{something_or_other}.should change(B, :count).by(1) for the straightforward case. The more difficult case is that when that okay() happens, it may or may not add a row, but it does some transformations that cause updates to fields in all of the rows belonging to the A. Sorry I can't be more specific than A's and B's :) And thanks again. Rspec rocks. From sam at samgranieri.com Mon Jul 7 02:28:21 2008 From: sam at samgranieri.com (Sam Granieri, Jr) Date: Mon, 7 Jul 2008 01:28:21 -0500 Subject: [rspec-users] Trouble with Association Proxies and new/create in rails Message-ID: <5EABE252-5DF3-48CF-9953-C973A107B6AB@samgranieri.com> I'm working on some code that uses association proxies. I'm trying to get away from using fixtures, and move more to mocking and stubbing. So far, so good, but the methods I cant figure out, even with extensive googling, are how to simulate the association_proxy.build method in rails. I'm on edge rails and edge rspec. Datawise, a bar has_many suggested_beers, and a suggested_beer belongs to a bar suggested_beers_controller > class SuggestedBeersController < ApplicationController > before_filter :find_bar > > #code omitted for brevity > # GET /bars/1/suggested_beers/new > def new > @suggested_beer = @bar.suggested_beers.build > > respond_to do |format| > format.html > end > end > > # POST /bars/1/suggested_beers > def create > @suggested_beer = > @bar.suggested_beers.build(params[:suggested_beer]) > #more redaction > end > > #code omitted for brevity > private > def find_bar > @bar = Bar.find(params[:bar_id]) > end suggested_beers_controller_spec.rb This is generated with rspec_scaffold, and i've added in the beer_id, bar_id, and ip_address attributes for stubbing. > def mock_suggested_beer(stubs={}) > stubs = { > :save => true, > :update_attributes => true, > :destroy => true, > :to_xml => '', > :beer_id => "1", > :bar_id => "1", > :ip_address => "127.0.0.1" > }.merge(stubs) > @mock_suggested_beer ||= mock_model(SuggestedBeer, stubs) > end > > describe "responding to GET /bars/1/suggested_beers/new" do > > it "should succeed" do > get :new, :bar_id => "1" > response.should be_success > end > > it "should render the 'new' template" do > get :new, :bar_id => "1" > response.should render_template('new') > end > > it "should create a new suggested_beer" do > > SuggestedBeer.should_receive(:new).and_return(mock_suggested_beer) > get :new, :bar_id => "1" > end "should create a new suggested_beer" fails with this message Spec::Mocks::MockExpectationError in 'SuggestedBeersController responding to GET /bars/1/suggested_beers/new should create a new suggested_beer' Mock 'SuggestedBeer_1016' received unexpected message :[]= with ("bar_id", 1) I don't know how to fix this. I've looked at several articles, specifically http://www.lukeredpath.co.uk/2007/10/18/demeters-revenge and http://www.ruby-forum.com/topic/158489 but I'm still confused. Any help is much appreciated! -------------------------------- Sam Granieri, Jr sam at samgranieri.com Chicago, IL irc (freenode): samgranieri http://www.samgranieri.com http://www.beerbin.com Recommend me at WWR! http://www.workingwithrails.com/person/7374-sam-granieri From zach.dennis at gmail.com Mon Jul 7 12:06:17 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 7 Jul 2008 12:06:17 -0400 Subject: [rspec-users] auto-generated descriptions In-Reply-To: <74243c220807041918l47c5def9ia19e5860d2a704f4@mail.gmail.com> References: <74243c220807041918l47c5def9ia19e5860d2a704f4@mail.gmail.com> Message-ID: <85d99afe0807070906k6af3998dk4a76a4aa2f09fa6@mail.gmail.com> On Fri, Jul 4, 2008 at 10:18 PM, Steve Eley wrote: > On Fri, Jul 4, 2008 at 4:45 PM, David Chelimsky > wrote: > > > > So - how bad do you think this would suck to remove that feature? Are you > > using it yourself? > > I'm not, but would it be impractical to extract it out into some sort > of module or helper and tell people to include it in their config.* > block if they want to use it? > +1 -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From yitzhakbg at gmail.com Mon Jul 7 14:25:19 2008 From: yitzhakbg at gmail.com (yitzhakbg) Date: Mon, 7 Jul 2008 11:25:19 -0700 (PDT) Subject: [rspec-users] Is BDD with RSpec cheaper? Message-ID: <18323328.post@talk.nabble.com> This might be a loaded question on this forum, but here goes: Just had a discussion with a prospective employer, a Ruby On Rails shop. His reaction to BDD development on every project was skeptical, saying something like: "It depends on the project". "Some jobs are so short that the extra time invested in developing tests doesn't justify the cost". He was insistent that writing tests costs more. After all, you write twice: first the tests, then the code (or the other way 'round). My question is: From hard, practical, cold real world experience, is that so? Is BDD development more expensive? Let me qualify that. One could answer, "no, since the tests save you pain and heartache down the line". The question is whether BDD coding with RSpec is more expensive in the implementation phase and how much truth there is in the statement that BDD isn't for every project, like quick knock ups for example? -- View this message in context: http://www.nabble.com/Is-BDD-with-RSpec-cheaper--tp18323328p18323328.html Sent from the rspec-users mailing list archive at Nabble.com. From ashley.moran at patchspace.co.uk Mon Jul 7 14:47:14 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 7 Jul 2008 19:47:14 +0100 Subject: [rspec-users] auto-generated descriptions In-Reply-To: References: Message-ID: <1A96B748-3CD5-43D9-BE31-0EA1287F02BF@patchspace.co.uk> On Jul 04, 2008, at 9:45 pm, David Chelimsky wrote: > I'm looking for ways to optimize rspec and came upon something > interesting. If I remove handling for auto-generated descriptions > (the thing that allows you to say "specify { 5.should == 5 }" with > no description string) we get an average 35% performance increase > per expectation. 35%. That's huge. > > So - how bad do you think this would suck to remove that feature? > Are you using it yourself? I was aware of it but never felt the need to use it Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From dchelimsky at gmail.com Mon Jul 7 15:03:41 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 7 Jul 2008 14:03:41 -0500 Subject: [rspec-users] auto-generated descriptions In-Reply-To: <1A96B748-3CD5-43D9-BE31-0EA1287F02BF@patchspace.co.uk> References: <1A96B748-3CD5-43D9-BE31-0EA1287F02BF@patchspace.co.uk> Message-ID: <38925F69-DE09-42B4-8D9F-6C3563C39628@gmail.com> On Jul 7, 2008, at 1:47 PM, Ashley Moran wrote: > > On Jul 04, 2008, at 9:45 pm, David Chelimsky wrote: > >> I'm looking for ways to optimize rspec and came upon something >> interesting. If I remove handling for auto-generated descriptions >> (the thing that allows you to say "specify { 5.should == 5 }" with >> no description string) we get an average 35% performance increase >> per expectation. 35%. That's huge. >> >> So - how bad do you think this would suck to remove that feature? >> Are you using it yourself? > > I was aware of it but never felt the need to use it Thanks to everyone for the feedback. I've come up w/ a good compromise solution which is to only generate the description when it's actually used. Just required moving the call to generate the description to a different place. Cheers, David From paolo.dona at gmail.com Mon Jul 7 15:31:19 2008 From: paolo.dona at gmail.com (=?UTF-8?Q?Paolo_Don=C3=A0?=) Date: Mon, 7 Jul 2008 20:31:19 +0100 Subject: [rspec-users] Colorize story output Message-ID: <9299dedc0807071231j64878253j32e167f981d3cfa1@mail.gmail.com> Hi guys, running large story files I started missing the red/green output of my specs. Thus I wrote a small scriptyou can pipe the story output to, in order to 'colorize' it.. so instead of: $ ./stories/all.rb you can say: $ ./stories/all.rb | ./colorize and get pending and failed steps correctly highlighted. There's a basic support for growl too if found in your path (I ripped off most of the code from .autotest). That works, but it's certainly not well integrated into RSpec stories. How would it be the right way to do this? (if you want to see how the result look like, take a look here: http://paolodona.com/2008/7/6/colorize-rspec-stories-output) -- Paolo Dona' http://paolodona.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From avdi at avdi.org Mon Jul 7 15:32:21 2008 From: avdi at avdi.org (Avdi Grimm) Date: Mon, 7 Jul 2008 15:32:21 -0400 Subject: [rspec-users] Is BDD with RSpec cheaper? In-Reply-To: <18323328.post@talk.nabble.com> References: <18323328.post@talk.nabble.com> Message-ID: On Mon, Jul 7, 2008 at 2:25 PM, yitzhakbg wrote: > > This might be a loaded question on this forum, but here goes: > Just had a discussion with a prospective employer, a Ruby On Rails shop. His > reaction to BDD development on every project was skeptical, saying something > like: "It depends on the project". "Some jobs are so short that the extra > time invested in developing tests doesn't justify the cost". > He was insistent that writing tests costs more. After all, you write twice: > first the tests, then the code (or the other way 'round). > My question is: From hard, practical, cold real world experience, is that > so? Is BDD development more expensive? Let me qualify that. One could > answer, "no, since the tests save you pain and heartache down the line". The > question is whether BDD coding with RSpec is more expensive in the > implementation phase and how much truth there is in the statement that BDD > isn't for every project, like quick knock ups for example? I'd say the cutoff-point for me is at around 100 lines of code. I've successfully developed little one-off scripts - either utilities or throw-away experimental spikes - of that length or less using only manual testing, which may have taken a little longer had I developed them test-first. I don't think something of this size really qualifies as a "project" though. With anything larger than 100 lines I know from experience that I'd just be slowing the project down if I failed to use TDD/BDD. -- Avdi Home: http://avdi.org Developer Blog: http://avdi.org/devblog/ Twitter: http://twitter.com/avdi Journal: http://avdi.livejournal.com From loriolson at mac.com Mon Jul 7 15:34:02 2008 From: loriolson at mac.com (Lori M Olson) Date: Mon, 7 Jul 2008 13:34:02 -0600 Subject: [rspec-users] Is BDD with RSpec cheaper? In-Reply-To: <18323328.post@talk.nabble.com> References: <18323328.post@talk.nabble.com> Message-ID: <5AC0A7E0-A1D3-49C5-9BDE-B9D12FBADCEE@mac.com> On 7-Jul-08, at 12:25 PM, yitzhakbg wrote: > > This might be a loaded question on this forum, but here goes: > Just had a discussion with a prospective employer, a Ruby On Rails > shop. His > reaction to BDD development on every project was skeptical, saying > something > like: "It depends on the project". "Some jobs are so short that the > extra > time invested in developing tests doesn't justify the cost". > He was insistent that writing tests costs more. After all, you write > twice: > first the tests, then the code (or the other way 'round). > My question is: From hard, practical, cold real world experience, is > that > so? Is BDD development more expensive? Let me qualify that. One could > answer, "no, since the tests save you pain and heartache down the > line". The > question is whether BDD coding with RSpec is more expensive in the > implementation phase and how much truth there is in the statement > that BDD > isn't for every project, like quick knock ups for example? > -- > View this message in context: http://www.nabble.com/Is-BDD-with-RSpec-cheaper--tp18323328p18323328.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users This is a TCO issue. IT WILL slow down initial development on a small, well defined app, and there is no way around that. But over the life of a medium-to-large application, BDD will greatly reduce maintenance and enhancement costs. So, if you are a contracting firm, paid to build sites, but not to maintain them, that might be a point you want to consider. But if I was your customer, I wouldn't likely be coming back to you. If you are hired to build and maintain an application, I really can't see a downside to writing the tests. Regards, Lori From ben at benmabey.com Mon Jul 7 15:34:58 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 07 Jul 2008 13:34:58 -0600 Subject: [rspec-users] Colorize story output In-Reply-To: <9299dedc0807071231j64878253j32e167f981d3cfa1@mail.gmail.com> References: <9299dedc0807071231j64878253j32e167f981d3cfa1@mail.gmail.com> Message-ID: <48726FE2.7010500@benmabey.com> Paolo Don? wrote: > Hi guys, > running large story files I started missing the red/green output of my > specs. > Thus I wrote a small script > you can > pipe the story output to, in order to 'colorize' it.. > > so instead of: $ ./stories/all.rb > you can say: $ ./stories/all.rb | ./colorize > and get pending and failed steps correctly highlighted. > > There's a basic support for growl too if found in your path (I ripped > off most of the code from .autotest). That works, but it's certainly > not well integrated into RSpec stories. How would it be the right way > to do this? > > (if you want to see how the result look like, take a look > here: http://paolodona.com/2008/7/6/colorize-rspec-stories-output) > > -- > Paolo Dona' > http://paolodona.com > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Hey Paolo, This looks look. However, the story runner currently supports colorization. You just need to pass in a --colour on the command line. -Ben From ben at benmabey.com Mon Jul 7 15:40:55 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 07 Jul 2008 13:40:55 -0600 Subject: [rspec-users] Is BDD with RSpec cheaper? In-Reply-To: <18323328.post@talk.nabble.com> References: <18323328.post@talk.nabble.com> Message-ID: <48727147.3080903@benmabey.com> yitzhakbg wrote: > This might be a loaded question on this forum, but here goes: > Just had a discussion with a prospective employer, a Ruby On Rails shop. His > reaction to BDD development on every project was skeptical, saying something > like: "It depends on the project". "Some jobs are so short that the extra > time invested in developing tests doesn't justify the cost". > He was insistent that writing tests costs more. After all, you write twice: > first the tests, then the code (or the other way 'round). > My question is: From hard, practical, cold real world experience, is that > so? Is BDD development more expensive? Let me qualify that. One could > answer, "no, since the tests save you pain and heartache down the line". The > question is whether BDD coding with RSpec is more expensive in the > implementation phase and how much truth there is in the statement that BDD > isn't for every project, like quick knock ups for example? > Does TDD/BDD take longer that hacking something out? I would say that it depends a lot on the project and the developer's experience in that domain, BDD, and doing BDD in that domain. That said, it probably isn't an unfair generalization to say that quick short jobs can be hacked together faster without tests. Prototyping, spikes, and exploring new technology are times when BDD would probably hinder you. As you point out though you will be building up a technical debt by not having tests that will come back and bite you at sometime. That is why I generally throw away any prototype code and start over with a blank slate that I can start doing BDD with along with my newly gained knowledge from the prototype. I have experiences where doing BDD has greatly sped up my development and has helped me in compartmentalizing a complex problem into smaller more manageable sub-problems. For a "quick knock up" then I think it it good to ask how long this software is suppose to live, and whether or not the developers have enough discipline to start adding tests once it does become more complex. If the answer to the latter question is no then forgoing tests in the beginning sounds like a recipe for disaster. I suppose another question is how important this piece of software is. If it is just for fun and you just want to see some results and could care less about maintenance down the line then manual testing is just fine. One more thing... you said "The question is whether BDD coding with RSpec is more expensive in the implementation phase...". BDD is not just the implementation phase but is also the design phase as well. I could certainly throw together some systems faster without doing BDD and then manually test the system afterwards. Would I have confidence in the system? Yes. In fact, I would have just as much confidence in the system as I would if I had a spec/test suite verifying the behavior. However, if I had created that system with TDD/BDD from the start I would end up with a greater sense of confidence of the *design*. Easily tested code tends to go hand in hand with good design, where hard to test code tends to carry some code smells resultant of a poor design. Which is another danger in delaying creating an automated suite because you may end up with hard to test objects which will be in dire need of some refactoring. I don't know if I really answered your question or if I just added to your confusion. In the end BDD, just like any other practice, has its trade offs and should only be applied in the right situations. I think the "right situations" will vary from developer to developer/team to team and there may not be one single rule for where the exact cutoff is. -Ben From rick.denatale at gmail.com Mon Jul 7 16:20:35 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Mon, 7 Jul 2008 16:20:35 -0400 Subject: [rspec-users] Trouble with Association Proxies and new/create in rails In-Reply-To: <5EABE252-5DF3-48CF-9953-C973A107B6AB@samgranieri.com> References: <5EABE252-5DF3-48CF-9953-C973A107B6AB@samgranieri.com> Message-ID: On Mon, Jul 7, 2008 at 2:28 AM, Sam Granieri, Jr wrote: > I'm working on some code that uses association proxies. I'm trying to get > away from using fixtures, and move more to mocking and stubbing. So far, so > good, but the methods I cant figure out, even with extensive googling, are > how to simulate the association_proxy.build method in rails. > > I'm on edge rails and edge rspec. > > Datawise, a bar has_many suggested_beers, and a suggested_beer belongs to a > bar > > suggested_beers_controller > > class SuggestedBeersController < ApplicationController >> before_filter :find_bar >> >> #code omitted for brevity >> # GET /bars/1/suggested_beers/new >> def new >> @suggested_beer = @bar.suggested_beers.build >> >> respond_to do |format| >> format.html >> end >> end >> >> # POST /bars/1/suggested_beers >> def create >> @suggested_beer = @bar.suggested_beers.build(params[:suggested_beer]) >> #more redaction >> end >> >> #code omitted for brevity >> private >> def find_bar >> @bar = Bar.find(params[:bar_id]) >> end >> > > > > suggested_beers_controller_spec.rb > > This is generated with rspec_scaffold, and i've added in the beer_id, > bar_id, and ip_address attributes for stubbing. > > def mock_suggested_beer(stubs={}) >> stubs = { >> :save => true, >> :update_attributes => true, >> :destroy => true, >> :to_xml => '', >> :beer_id => "1", >> :bar_id => "1", >> :ip_address => "127.0.0.1" >> }.merge(stubs) >> @mock_suggested_beer ||= mock_model(SuggestedBeer, stubs) >> end >> >> describe "responding to GET /bars/1/suggested_beers/new" do >> >> it "should succeed" do >> get :new, :bar_id => "1" >> response.should be_success >> end >> >> it "should render the 'new' template" do >> get :new, :bar_id => "1" >> response.should render_template('new') >> end >> >> it "should create a new suggested_beer" do >> >> SuggestedBeer.should_receive(:build).with().and_return(mock_suggested_beer) >> get :new, :bar_id => "1" >> end >> > "should create a new suggested_beer" fails with this message > > Spec::Mocks::MockExpectationError in 'SuggestedBeersController responding > to GET /bars/1/suggested_beers/new should create a new suggested_beer' > Mock 'SuggestedBeer_1016' received unexpected message :[]= with ("bar_id", > 1) > The way I approach this is to stub the object which has the association proxy to return a mock for the proxy. To do that you have to stub whatever method your controller uses to get that object. In this case, assuming that your controller is setting up @bar in the obvious way, it would be something like. it "should create a new suggested_beer" do suggested_beers = mock("suggested_beers") bar = mock_model(Bar, :suggested_beers => suggested_beers) Bar.stub!(:find).and_return(bar) suggested_beer = mock_model(SuggestedBeer, ....) SuggestedBeer.should_receive(:build).with(:blatz)..and_return(mock_suggested_beer) get :new, :bar_id => "1", :suggested_beer => :blatz end Some would break this down into at least two examples, one just checking that the build method is called and another checking that it is called with the expected paramenters. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From paolo.dona at gmail.com Mon Jul 7 16:34:28 2008 From: paolo.dona at gmail.com (=?UTF-8?Q?Paolo_Don=C3=A0?=) Date: Mon, 7 Jul 2008 21:34:28 +0100 Subject: [rspec-users] Colorize story output In-Reply-To: <48726FE2.7010500@benmabey.com> References: <9299dedc0807071231j64878253j32e167f981d3cfa1@mail.gmail.com> <48726FE2.7010500@benmabey.com> Message-ID: <9299dedc0807071334heee9394ubee39cb38da093e5@mail.gmail.com> Wow cool, I feel so stupid now :-) So, after one hour in the closet I would ask: how to plug the growl stuff in? Paolo On Mon, Jul 7, 2008 at 8:34 PM, Ben Mabey wrote: > Paolo Don? wrote: >> >> Hi guys, >> running large story files I started missing the red/green output of my >> specs. >> Thus I wrote a small script >> you can pipe the >> story output to, in order to 'colorize' it.. >> >> so instead of: $ ./stories/all.rb >> you can say: $ ./stories/all.rb | ./colorize >> and get pending and failed steps correctly highlighted. >> >> There's a basic support for growl too if found in your path (I ripped off >> most of the code from .autotest). That works, but it's certainly not well >> integrated into RSpec stories. How would it be the right way to do this? >> >> (if you want to see how the result look like, take a look here: >> http://paolodona.com/2008/7/6/colorize-rspec-stories-output) >> >> -- >> Paolo Dona' >> http://paolodona.com >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > Hey Paolo, > This looks look. However, the story runner currently supports colorization. > You just need to pass in a --colour on the command line. > > -Ben > -- Paolo Dona' http://paolodona.com From yitzhakbg at gmail.com Mon Jul 7 17:19:34 2008 From: yitzhakbg at gmail.com (yitzhakbg) Date: Mon, 7 Jul 2008 14:19:34 -0700 (PDT) Subject: [rspec-users] Is BDD with RSpec cheaper? In-Reply-To: <18323328.post@talk.nabble.com> References: <18323328.post@talk.nabble.com> Message-ID: <18326878.post@talk.nabble.com> Thanks very much. -- View this message in context: http://www.nabble.com/Is-BDD-with-RSpec-cheaper--tp18323328p18326878.html Sent from the rspec-users mailing list archive at Nabble.com. From tiffani2k3 at gmail.com Mon Jul 7 17:27:36 2008 From: tiffani2k3 at gmail.com (Tiffani Ashley Bell) Date: Mon, 7 Jul 2008 17:27:36 -0400 Subject: [rspec-users] Not sure why this controller spec isn't working Message-ID: Hey folks, I've been mocking and stubbing pretty nicely after the various bits of advice I received earlier about doing so. I've come to bits of code that work in one place and not in another, though. I'm hoping it's not something simple I've missed. The code below fails even though code that is practically the same elsewhere (except different models in use) passes. What gives? I have: in notes_controller_spec.rb: before(:each) do @mock_note = mock_model(Note, :body => "The hot dog shipment will be in later tonight.", :organization => @mock_org) @mock_org = mock_model(Organization, :name => "Slappy's Hot Dog Palace", :notes => [@mock_note]) @notes = [@mock_note] end it "should render 'notes/new' when the Note is setup with invalid data, i.e. without a body on POST create" do Note.stub!(:new).and_return(@mock_note) @notes.stub!(:<<).and_return(false) post :create, :organization_id => @mock_org.id, :new_note => { :body => @mock_note.body } response.should render_template("notes/new") end --- in notes_controller.rb: def create @new_note = Note.new(params[:new_note]) respond_to do |wants| if @organization.notes << @new_note wants.html { redirect_to organization_url(@organization) } else wants.html { render :action => "new" } end end end I figured that my stubbing the << method out in the test to return false would do the job of triggering the proper branch of the if statement in the controller action, but I'm not sure why it's not doing so. I get the error: expected "notes/new", got nil. I have code in my Users controller that does the exact same thing with the << method and the tests pass (they're virtually identical tests). Any thoughts? TIA. --Tiffani AB -------------- next part -------------- An HTML attachment was scrubbed... URL: From mileshosky at hotmail.com Mon Jul 7 17:55:50 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Mon, 7 Jul 2008 14:55:50 -0700 Subject: [rspec-users] Not sure why this controller spec isn't working In-Reply-To: References: Message-ID: ________________________________ > Date: Mon, 7 Jul 2008 17:27:36 -0400 > From: tiffani2k3 at gmail.com > To: rspec-users at rubyforge.org > Subject: [rspec-users] Not sure why this controller spec isn't working > > Hey folks, > > I've been mocking and stubbing pretty nicely after the various bits of advice I received earlier about doing so. I've come to bits of code that work in one place and not in another, though. I'm hoping it's not something simple I've missed. The code below fails even though code that is practically the same elsewhere (except different models in use) passes. What gives? > > I have: > > in notes_controller_spec.rb: > > > before(:each) do > @mock_note = mock_model(Note, :body => "The hot dog shipment will be in later tonight.", > :organization => @mock_org) > @mock_org = mock_model(Organization, :name => "Slappy's Hot Dog Palace", :notes => [@mock_note]) > > @notes = [@mock_note] > end > > > it "should render 'notes/new' when the Note is setup with invalid data, i.e. without a body on POST create" do > Note.stub!(:new).and_return(@mock_note) > @notes.stub!(:< post :create, :organization_id => @mock_org.id, :new_note => { :body => @mock_note.body } > response.should render_template("notes/new") > end > > --- > > in notes_controller.rb: > > def create > @new_note = Note.new(params[:new_note]) > > respond_to do |wants| > if @organization.notes << @new_note > wants.html { redirect_to organization_url(@organization) } > else > wants.html { render :action => "new" } > end > end > end > > I figured that my stubbing the << method out in the test to return false would do the job of triggering the proper branch of the if statement in the controller action, but I'm not sure why it's not doing so. I get the error: expected "notes/new", got nil. I have code in my Users controller that does the exact same thing with the << method and the tests pass (they're virtually identical tests). Any thoughts? TIA. > > > --Tiffani AB Where in your create action are you defining @organization? is this variable provided from a before filter? If not, that's the first thing you should look at. Another thing I noticed is that your @mock_note defines its organization @mock_org before @mock_org is defined... thus probably setting @mock_note.organization to nil. _________________________________________________________________ The i?m Talkaton. Can 30-days of conversation change the world? http://www.imtalkathon.com/?source=EML_WLH_Talkathon_ChangeWorld From zach.dennis at gmail.com Mon Jul 7 18:06:54 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 7 Jul 2008 18:06:54 -0400 Subject: [rspec-users] Not sure why this controller spec isn't working In-Reply-To: References: Message-ID: <85d99afe0807071506g1448f8e4nf9edd85d1fc7dff4@mail.gmail.com> On Mon, Jul 7, 2008 at 5:55 PM, Britt Mileshosky wrote: > > > ________________________________ > > Date: Mon, 7 Jul 2008 17:27:36 -0400 > > From: tiffani2k3 at gmail.com > > To: rspec-users at rubyforge.org > > Subject: [rspec-users] Not sure why this controller spec isn't working > > > > Hey folks, > > > > I've been mocking and stubbing pretty nicely after the various bits of > advice I received earlier about doing so. I've come to bits of code that > work in one place and not in another, though. I'm hoping it's not something > simple I've missed. The code below fails even though code that is > practically the same elsewhere (except different models in use) passes. > What gives? > > > > I have: > > > > in notes_controller_spec.rb: > > > > > > before(:each) do > > @mock_note = mock_model(Note, :body => "The hot dog shipment will be > in later tonight.", > > :organization => @mock_org) > > @mock_org = mock_model(Organization, :name => "Slappy's Hot Dog > Palace", :notes => [@mock_note]) > > > > @notes = [@mock_note] > > end > > > > > > it "should render 'notes/new' when the Note is setup with invalid data, > i.e. without a body on POST create" do > > Note.stub!(:new).and_return(@mock_note) > > @notes.stub!(:< post :create, :organization_id => @ > mock_org.id, :new_note => { :body => @mock_note.body } > > response.should render_template("notes/new") > > end > > > To add to what Britt already said, look at your example and then your before block again very carefully. Notice that you setup @notes in your before, and you use it to stub :<< in your example, but you never return @notes from anything. Instead you setup @mock_org to return an array with @mock_note. Although the contents of this and @notes are the same, you have created two different arrays. You are probably wanting to be dealing with the same @notes object in each of these cases. Zach -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From tiffani2k3 at gmail.com Mon Jul 7 20:44:16 2008 From: tiffani2k3 at gmail.com (Tiffani Ashley Bell) Date: Mon, 7 Jul 2008 20:44:16 -0400 Subject: [rspec-users] Not sure why this controller spec isn't working In-Reply-To: <85d99afe0807071506g1448f8e4nf9edd85d1fc7dff4@mail.gmail.com> References: <85d99afe0807071506g1448f8e4nf9edd85d1fc7dff4@mail.gmail.com> Message-ID: Hmmm...I made the changes that both you and Britt suggested and still no dice. I broke it down and put print statements (yeesh) in the controller around the @organization.notes << @new_note statement. This confirms that the statement returns false just like the stub told it to do (so I took out the puts statement and ran the test again), but for some reason I still don't get the rendered template as set up in the else clause. I'm not sure what's going on, but I suppose I'll just skip that test until later. Thanks for the help! Tiffani AB On Mon, Jul 7, 2008 at 6:06 PM, Zach Dennis wrote: > > On Mon, Jul 7, 2008 at 5:55 PM, Britt Mileshosky > wrote: > >> >> >> ________________________________ >> > Date: Mon, 7 Jul 2008 17:27:36 -0400 >> > From: tiffani2k3 at gmail.com >> > To: rspec-users at rubyforge.org >> > Subject: [rspec-users] Not sure why this controller spec isn't working >> > >> > Hey folks, >> > >> > I've been mocking and stubbing pretty nicely after the various bits of >> advice I received earlier about doing so. I've come to bits of code that >> work in one place and not in another, though. I'm hoping it's not something >> simple I've missed. The code below fails even though code that is >> practically the same elsewhere (except different models in use) passes. >> What gives? >> > >> > I have: >> > >> > in notes_controller_spec.rb: >> > >> > >> > before(:each) do >> > @mock_note = mock_model(Note, :body => "The hot dog shipment will be >> in later tonight.", >> > :organization => @mock_org) >> > @mock_org = mock_model(Organization, :name => "Slappy's Hot Dog >> Palace", :notes => [@mock_note]) >> > >> > @notes = [@mock_note] >> > end >> > >> > >> > it "should render 'notes/new' when the Note is setup with invalid data, >> i.e. without a body on POST create" do >> > Note.stub!(:new).and_return(@mock_note) >> > @notes.stub!(:< post :create, :organization_id => @ >> mock_org.id, :new_note => { :body => @mock_note.body } >> > response.should render_template("notes/new") >> > end >> > >> > > To add to what Britt already said, look at your example and then your > before block again very carefully. Notice that you setup @notes in your > before, and you use it to stub :<< in your example, but you never return > @notes from anything. Instead you setup @mock_org to return an array with > @mock_note. Although the contents of this and @notes are the same, you have > created two different arrays. You are probably wanting to be dealing with > the same @notes object in each of these cases. > > Zach > > > -- > Zach Dennis > http://www.continuousthinking.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mailing_lists at railsnewbie.com Mon Jul 7 22:29:46 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 7 Jul 2008 22:29:46 -0400 Subject: [rspec-users] Is BDD with RSpec cheaper? In-Reply-To: <18323328.post@talk.nabble.com> References: <18323328.post@talk.nabble.com> Message-ID: On Jul 7, 2008, at 2:25 PM, yitzhakbg wrote: > > This might be a loaded question on this forum, but here goes: > Just had a discussion with a prospective employer, a Ruby On Rails > shop. His > reaction to BDD development on every project was skeptical, saying > something > like: "It depends on the project". "Some jobs are so short that the > extra > time invested in developing tests doesn't justify the cost". > He was insistent that writing tests costs more. After all, you write > twice: > first the tests, then the code (or the other way 'round). > My question is: From hard, practical, cold real world experience, is > that > so? Is BDD development more expensive? Let me qualify that. One could > answer, "no, since the tests save you pain and heartache down the > line". The > question is whether BDD coding with RSpec is more expensive in the > implementation phase and how much truth there is in the statement > that BDD > isn't for every project, like quick knock ups for example? Yes - of course it will slow you down. There is nothing wrong with leaving code unspec'ed (just be aware of the consequences). Almost every app will grow to a size of immense complexity (i.e. every app in it's fullest wants to read email). If someone is paying you for it (and it's not a prototype), it almost always needs specs. The real question is: how much is my software worth? How much should it be worth? If it's worth nothing, it needs no specs. If it has any plans to grow (or is already big), or is ever going to be maintained by someone else besides the original maintainer, it needs specs. (There is one obvious exception to this rule: Prototyping needs no specs, and actually hampers growth). There have been many times when I've been in a "rush" to get a piece of code done, and so I don't spec it. I almost always find a bug in it later on, and always regret not spec'ing it. I'm not a testing fanatic - I'm human (and make so many tiny mistakes it's almost unbelievable). Dave Astels said something a while back to the effect of "Unspec'ed code sucks". I'm okay with short scripts and data migrations sucking. I don't plan to spend a lot of time on it, and in the end, I'm going to throw it away. No reason to keep a test suite around for it. This is why you'll hear many people say, "if it is under X number of lines it doesn't need specs." Scott From cdemyanovich at gmail.com Mon Jul 7 22:31:27 2008 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Mon, 7 Jul 2008 22:31:27 -0400 Subject: [rspec-users] Not sure why this controller spec isn't working In-Reply-To: References: <85d99afe0807071506g1448f8e4nf9edd85d1fc7dff4@mail.gmail.com> Message-ID: <61c885db0807071931t4b323d72wfa0d6e0b6ee3d828@mail.gmail.com> I'm assuming RSpec 1.1.3+, but here's how I might write this example: describe NotesController do it "renders 'notes/new' when an empty note is submitted" do Note.stub!(:new).and_return(stub("note")) organization = stub_model(Organization, :notes => stub("notes", :<< => false)) assigns[:organization] = organization post :create, "organization_id" => organization.to_param, "new_note" => { "body" => "" } response.should render_template("notes/new") end end I'm favoring the use of stub_model and stubs instead of mock_model (and mocks) because we're not setting any expectations on the note or the organization. Rather, we're just setting them up to deliver values that are either simply required (as in Note.new returning something non-nil) or what we want (the addition of the note to the organization to fail). I've also eliminated the idea of having existing notes on the organization. It's not central to what's being spec'd, so it's out. Furthermore, I made the submitted note's body empty because that's what was in the original description of the it block. That those two didn't match bothered me. Finally, I simplified the description of the it block to what I thought the essence of your example was; I hope that I'm at least close. :-) Please let the list know if this helped or if you already revisited the problem and solved it. I think we're interested in what ends up working for you. Regards, Craig From abroad-crawford at within3.com Mon Jul 7 22:36:33 2008 From: abroad-crawford at within3.com (Anthony Broad-Crawford) Date: Mon, 7 Jul 2008 22:36:33 -0400 Subject: [rspec-users] Is BDD with RSpec cheaper? In-Reply-To: <18323328.post@talk.nabble.com> References: <18323328.post@talk.nabble.com> Message-ID: Interesting statement that I have heard several times before, and it all boils down to how one measures cost. If you measure the cost of an application only in the time it takes to write the first line of code to the last line of code for the first and only release, then yes, you could argue that removing the tests would technically make it cheaper. However, I've never defined the cost of an application like that. The reason being, the application spends more of its life cycle in subsequent releases (release 2 through release N). That being said, the ROI on testing (behavioral or state based) becomes more apparent in future subsequent release as they take less time to move through the development life cycle. This is primarily due to the design being better, as it is more conducive to change (testing usually produces this side effect IMO), and releases test quicker, as you have that rich suite of tests to support development and testing efforts. Just my $0.02. Anthony Broad-Crawford On Jul 7, 2008, at 2:25 PM, yitzhakbg wrote: > > This might be a loaded question on this forum, but here goes: > Just had a discussion with a prospective employer, a Ruby On Rails > shop. His > reaction to BDD development on every project was skeptical, saying > something > like: "It depends on the project". "Some jobs are so short that the > extra > time invested in developing tests doesn't justify the cost". > He was insistent that writing tests costs more. After all, you write > twice: > first the tests, then the code (or the other way 'round). > My question is: From hard, practical, cold real world experience, is > that > so? Is BDD development more expensive? Let me qualify that. One could > answer, "no, since the tests save you pain and heartache down the > line". The > question is whether BDD coding with RSpec is more expensive in the > implementation phase and how much truth there is in the statement > that BDD > isn't for every project, like quick knock ups for example? > -- > View this message in context: http://www.nabble.com/Is-BDD-with-RSpec-cheaper--tp18323328p18323328.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From korny at sietsma.com Mon Jul 7 22:56:42 2008 From: korny at sietsma.com (Korny Sietsma) Date: Tue, 8 Jul 2008 12:56:42 +1000 Subject: [rspec-users] Is BDD with RSpec cheaper? In-Reply-To: <18323328.post@talk.nabble.com> References: <18323328.post@talk.nabble.com> Message-ID: <8e15872b0807071956m96160a4k2e723da2c52a12d7@mail.gmail.com> I met a great analogy the other day - applies to TDD as well as BDD really. Unit testing is like double-entry book-keeping. It takes longer to do the initial work, and yes you have some repetition - but the reduction in errors saves you time and money overall. I'm struggling to think of a project that is so short that it needs no testing. Anything that you have to run more than once, or that you might conceivably have to change one day (especially as that change will probably be done by a different set of developers to the original code!) is going to benefit from testing. Ask your employer, "so, would your accountants skip double-entry bookkeeping on really small expenses?" :) I could see the temptation on a pure prototype mock-up project - but you'd have to make damn sure that the technical debt of *not* having tests was clear and up-front, as far too many prototype mock-up systems get turned into real production systems, in which case you'd be spending more effort retro-fitting tests to the prototype to get it production-ready. And in my experience, it's much harder to add testing to existing code than to write the tests as you go. - Korny On Tue, Jul 8, 2008 at 4:25 AM, yitzhakbg wrote: > > This might be a loaded question on this forum, but here goes: > Just had a discussion with a prospective employer, a Ruby On Rails shop. His > reaction to BDD development on every project was skeptical, saying something > like: "It depends on the project". "Some jobs are so short that the extra > time invested in developing tests doesn't justify the cost". > He was insistent that writing tests costs more. After all, you write twice: > first the tests, then the code (or the other way 'round). > My question is: From hard, practical, cold real world experience, is that > so? Is BDD development more expensive? Let me qualify that. One could > answer, "no, since the tests save you pain and heartache down the line". The > question is whether BDD coding with RSpec is more expensive in the > implementation phase and how much truth there is in the statement that BDD > isn't for every project, like quick knock ups for example? > -- > View this message in context: http://www.nabble.com/Is-BDD-with-RSpec-cheaper--tp18323328p18323328.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Kornelis Sietsma korny at my surname dot com From grail at goldweb.com.au Mon Jul 7 23:23:44 2008 From: grail at goldweb.com.au (Alex Satrapa) Date: Tue, 8 Jul 2008 13:23:44 +1000 Subject: [rspec-users] Is BDD with RSpec cheaper? In-Reply-To: <18323328.post@talk.nabble.com> References: <18323328.post@talk.nabble.com> Message-ID: <1E5A0AB0-DCF0-4E9C-B5F0-91EE2685BE55@goldweb.com.au> On 08/07/2008, at 04:25 , yitzhakbg wrote: > Just had a discussion with a prospective employer, a Ruby On Rails > shop. His > reaction to BDD development on every project was skeptical, saying > something > like: "It depends on the project". "Some jobs are so short that the > extra > time invested in developing tests doesn't justify the cost". If I'm not expected to maintain the code, the project isn't going to grow particularly big, and the interface has fewer than 7 major functions, there's no real need to spec it out since you can hold the entire design in your head. > The question is whether BDD coding with RSpec is more expensive in the > implementation phase and how much truth there is in the statement > that BDD > isn't for every project, like quick knock ups for example? If you're trying to specify the design in the implementation phase, then yes you're wasting time. The time isn't being wasted in writing specs, it's already been wasted in committing design to paper without trying out any of the major features to see that they make sense in code. There's one department at the University where I work that insists on big design up front. They fully specify the software using UML or whatever the flavour of the month is, then implement from that. Just one more reason why I don't ever want to work within a bureaucracy. Alex From tiffani2k3 at gmail.com Tue Jul 8 00:14:06 2008 From: tiffani2k3 at gmail.com (Tiffani Ashley Bell) Date: Tue, 8 Jul 2008 00:14:06 -0400 Subject: [rspec-users] Not sure why this controller spec isn't working In-Reply-To: <61c885db0807071931t4b323d72wfa0d6e0b6ee3d828@mail.gmail.com> References: <85d99afe0807071506g1448f8e4nf9edd85d1fc7dff4@mail.gmail.com> <61c885db0807071931t4b323d72wfa0d6e0b6ee3d828@mail.gmail.com> Message-ID: Yeah, I was on 1.1.4 and this solution with a few tweaks definitely worked. The original set up of my code called for having the Organization returned by the notes controller in a before filter, so I stubbed out this stuff in the before(:each) block. It ended up looking like this: before(:each) do @organization = stub_model(Organization, :name => "Slappy's Hot Dog Palace") Organization.stub!(:find).and_return(@organization) end Then, I followed Craig's lead on what the example should do with a few things taken out: it "should render 'notes/new' when an empty note is submitted" do Note.stub!(:new).and_return(stub("note")) post :create, :appointment_id => @appointment.id, :organization_id => @ organization.id, :new_note => { :body => "" } response.should render_template("notes/new") end I kept the controller method just like it was in the original post. And whoooo! Everything passed. I'll be making sure I really differentiate the necessity of mock_model vs. stub_model from now on, too as a take-away from all this. Learning this stuff has really been interesting considering months ago the only testing I was doing was making changes in Textmate and then clicking "Refresh" in a browser. lol. Thanks again! Tiffani AB On Mon, Jul 7, 2008 at 10:31 PM, Craig Demyanovich wrote: > I'm assuming RSpec 1.1.3+, but here's how I might write this example: > > describe NotesController do > it "renders 'notes/new' when an empty note is submitted" do > Note.stub!(:new).and_return(stub("note")) > organization = stub_model(Organization, :notes => stub("notes", > :<< => false)) > assigns[:organization] = organization > > post :create, "organization_id" => organization.to_param, > "new_note" => { "body" => "" } > > response.should render_template("notes/new") > end > end > > I'm favoring the use of stub_model and stubs instead of mock_model > (and mocks) because we're not setting any expectations on the note or > the organization. Rather, we're just setting them up to deliver values > that are either simply required (as in Note.new returning something > non-nil) or what we want (the addition of the note to the organization > to fail). > > I've also eliminated the idea of having existing notes on the > organization. It's not central to what's being spec'd, so it's out. > > Furthermore, I made the submitted note's body empty because that's > what was in the original description of the it block. That those two > didn't match bothered me. > > Finally, I simplified the description of the it block to what I > thought the essence of your example was; I hope that I'm at least > close. :-) > > Please let the list know if this helped or if you already revisited > the problem and solved it. I think we're interested in what ends up > working for you. > > Regards, > Craig > _______________________________________________ > 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 tiffani at geek.commentari.at Tue Jul 8 00:15:25 2008 From: tiffani at geek.commentari.at (Tiffani Ashley Bell) Date: Tue, 8 Jul 2008 00:15:25 -0400 Subject: [rspec-users] Not sure why this controller spec isn't working In-Reply-To: References: <85d99afe0807071506g1448f8e4nf9edd85d1fc7dff4@mail.gmail.com> <61c885db0807071931t4b323d72wfa0d6e0b6ee3d828@mail.gmail.com> Message-ID: Whoops..wrong post. should be post :create, :organization_id => @organization.id, :new_note => { :body => "" } Copying from the wrong window... Tiffani AB On Tue, Jul 8, 2008 at 12:14 AM, Tiffani Ashley Bell wrote: > Yeah, I was on 1.1.4 and this solution with a few tweaks definitely > worked. The original set up of my code called for having the Organization > returned by the notes controller in a before filter, so I stubbed out this > stuff in the before(:each) block. It ended up looking like this: > > before(:each) do > @organization = stub_model(Organization, :name => "Slappy's Hot Dog > Palace") > Organization.stub!(:find).and_return(@organization) > end > > Then, I followed Craig's lead on what the example should do with a few > things taken out: > > it "should render 'notes/new' when an empty note is submitted" do > Note.stub!(:new).and_return(stub("note")) > > post :create, :appointment_id => @appointment.id, :organization_id => @ > organization.id, :new_note => { :body => "" } > response.should render_template("notes/new") > end > > I kept the controller method just like it was in the original post. And > whoooo! Everything passed. I'll be making sure I really differentiate the > necessity of mock_model vs. stub_model from now on, too as a take-away from > all this. Learning this stuff has really been interesting considering > months ago the only testing I was doing was making changes in Textmate and > then clicking "Refresh" in a browser. lol. > > Thanks again! > Tiffani AB > > > On Mon, Jul 7, 2008 at 10:31 PM, Craig Demyanovich > wrote: > >> I'm assuming RSpec 1.1.3+, but here's how I might write this example: >> >> describe NotesController do >> it "renders 'notes/new' when an empty note is submitted" do >> Note.stub!(:new).and_return(stub("note")) >> organization = stub_model(Organization, :notes => stub("notes", >> :<< => false)) >> assigns[:organization] = organization >> >> post :create, "organization_id" => organization.to_param, >> "new_note" => { "body" => "" } >> >> response.should render_template("notes/new") >> end >> end >> >> I'm favoring the use of stub_model and stubs instead of mock_model >> (and mocks) because we're not setting any expectations on the note or >> the organization. Rather, we're just setting them up to deliver values >> that are either simply required (as in Note.new returning something >> non-nil) or what we want (the addition of the note to the organization >> to fail). >> >> I've also eliminated the idea of having existing notes on the >> organization. It's not central to what's being spec'd, so it's out. >> >> Furthermore, I made the submitted note's body empty because that's >> what was in the original description of the it block. That those two >> didn't match bothered me. >> >> Finally, I simplified the description of the it block to what I >> thought the essence of your example was; I hope that I'm at least >> close. :-) >> >> Please let the list know if this helped or if you already revisited >> the problem and solved it. I think we're interested in what ends up >> working for you. >> >> Regards, >> Craig >> _______________________________________________ >> 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 ml at e4net.com Tue Jul 8 01:36:10 2008 From: ml at e4net.com (Jim Morris) Date: Mon, 07 Jul 2008 22:36:10 -0700 Subject: [rspec-users] is there a plain format output for stories? Message-ID: <4872FCCA.9000002@e4net.com> When running a lot of stories from a script it would be nice to have the plain format of dots rather than the verbose story descriptions. Is there a way to do this? I tried -f p but it ignored it. Thanks -- Jim Morris, http://blog.wolfman.com From treas at dynamicdudes.com Tue Jul 8 04:59:58 2008 From: treas at dynamicdudes.com (Andreas Wolff) Date: Tue, 8 Jul 2008 10:59:58 +0200 (CEST) Subject: [rspec-users] Strange behaviour with pending specs and implementation_backtrace Message-ID: <31691077.17691215507597991.JavaMail.root@mail.dynamicdudes.com> Hi all, I'm using my own OutputFormatter with /bin/spec to catch rspec results. I'm experiencing strange behaviour with pending specs and implementation_backtrace. This is my example_pending implementation in rspactor_formatter.rb: class RSpactorFormatter def example_pending(example, message) spec = SpecObject.new( :name => example.description, :example_group_name => @example_group.description, :state => :pending, :message => message, :backtrace => example.implementation_backtrace ) @remote_service.incoming(:spec_run_example_pending, spec) end end If my code contains a pending example in test_spec.rb like this: it 'should be pending' do pending end 'example.implementation_backtrace' contains the correct file path. If I change the implementation to: it 'should be pending' 'example.implementation_backtrace' doesn't contain the correct file path anymore. Instead the backtrace ends with my custom formatter file 'rspactor_formatter.rb'. Is this behaviour correct? Am I something missing? bye -- Andreas Wolff DynamicDudes Lightweight Ruby on Rails application development http://dynamicdudes.com hire: +49 151 58 54 78 50 home: http://rubyphunk.com From dchelimsky at gmail.com Tue Jul 8 08:29:31 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 8 Jul 2008 07:29:31 -0500 Subject: [rspec-users] Strange behaviour with pending specs and implementation_backtrace In-Reply-To: <31691077.17691215507597991.JavaMail.root@mail.dynamicdudes.com> References: <31691077.17691215507597991.JavaMail.root@mail.dynamicdudes.com> Message-ID: On Jul 8, 2008, at 3:59 AM, Andreas Wolff wrote: > Hi all, > > I'm using my own OutputFormatter with /bin/spec to catch rspec > results. I'm experiencing strange behaviour with pending specs and > implementation_backtrace. > This is my example_pending implementation in rspactor_formatter.rb: > > class RSpactorFormatter > def example_pending(example, message) > spec = SpecObject.new( > :name => example.description, > :example_group_name => @example_group.description, > :state => :pending, > :message => message, > :backtrace => example.implementation_backtrace > ) > @remote_service.incoming(:spec_run_example_pending, spec) > end > end > > > If my code contains a pending example in test_spec.rb like this: > > it 'should be pending' do > pending > end > > 'example.implementation_backtrace' contains the correct file path. > > > If I change the implementation to: > > it 'should be pending' > > 'example.implementation_backtrace' doesn't contain the correct file > path anymore. Instead the backtrace ends with my custom formatter > file 'rspactor_formatter.rb'. > > > Is this behaviour correct? Am I something missing? It's a bug. RSpec doesn't report backtraces of pending examples so this never came up. Please report this to http://rspec.lighthouseapp.com Cheers, David > bye > > -- > Andreas Wolff > DynamicDudes > > Lightweight Ruby on Rails application development > http://dynamicdudes.com > hire: +49 151 58 54 78 50 > > home: http://rubyphunk.com From aidy.lewis at googlemail.com Tue Jul 8 09:23:51 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Tue, 8 Jul 2008 14:23:51 +0100 Subject: [rspec-users] Colorize story output In-Reply-To: <48726FE2.7010500@benmabey.com> References: <9299dedc0807071231j64878253j32e167f981d3cfa1@mail.gmail.com> <48726FE2.7010500@benmabey.com> Message-ID: <7ac2300c0807080623u121e0ca2ifbf80a06a3fdb18e@mail.gmail.com> On 07/07/2008, Ben Mabey wrote: > > Hey Paolo, > This looks look. However, the story runner currently supports colorization. > You just need to pass in a --colour on the command line. > > -Ben Could you give me some sample syntax on how to achieve this please? Aidy From dchelimsky at gmail.com Tue Jul 8 09:24:22 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 8 Jul 2008 08:24:22 -0500 Subject: [rspec-users] Colorize story output In-Reply-To: <7ac2300c0807080623u121e0ca2ifbf80a06a3fdb18e@mail.gmail.com> References: <9299dedc0807071231j64878253j32e167f981d3cfa1@mail.gmail.com> <48726FE2.7010500@benmabey.com> <7ac2300c0807080623u121e0ca2ifbf80a06a3fdb18e@mail.gmail.com> Message-ID: <196B2756-04C7-4908-B125-96B7A721D324@gmail.com> On Jul 8, 2008, at 8:23 AM, aidy lewis wrote: > On 07/07/2008, Ben Mabey wrote: >> >> Hey Paolo, >> This looks look. However, the story runner currently supports >> colorization. >> You just need to pass in a --colour on the command line. >> >> -Ben > > Could you give me some sample syntax on how to achieve this please? ruby stories/all.rb -c Cheers, David From aidy.lewis at googlemail.com Tue Jul 8 09:41:41 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Tue, 8 Jul 2008 14:41:41 +0100 Subject: [rspec-users] Colorize story output In-Reply-To: <196B2756-04C7-4908-B125-96B7A721D324@gmail.com> References: <9299dedc0807071231j64878253j32e167f981d3cfa1@mail.gmail.com> <48726FE2.7010500@benmabey.com> <7ac2300c0807080623u121e0ca2ifbf80a06a3fdb18e@mail.gmail.com> <196B2756-04C7-4908-B125-96B7A721D324@gmail.com> Message-ID: <7ac2300c0807080641h2ac302fama24356590e8329c0@mail.gmail.com> Hi David, > > > > ruby stories/all.rb -c > Fantastic. Is it possible to create HTML from this? Aidy From hayafirst at gmail.com Tue Jul 8 09:59:20 2008 From: hayafirst at gmail.com (Yi Wen) Date: Tue, 8 Jul 2008 08:59:20 -0500 Subject: [rspec-users] Colorize story output In-Reply-To: <7ac2300c0807080641h2ac302fama24356590e8329c0@mail.gmail.com> References: <9299dedc0807071231j64878253j32e167f981d3cfa1@mail.gmail.com> <48726FE2.7010500@benmabey.com> <7ac2300c0807080623u121e0ca2ifbf80a06a3fdb18e@mail.gmail.com> <196B2756-04C7-4908-B125-96B7A721D324@gmail.com> <7ac2300c0807080641h2ac302fama24356590e8329c0@mail.gmail.com> Message-ID: yes. -f html On Tue, Jul 8, 2008 at 8:41 AM, aidy lewis wrote: > Hi David, > > > > > > > > ruby stories/all.rb -c > > > > Fantastic. Is it possible to create HTML from this? > > Aidy > _______________________________________________ > 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 hayafirst at gmail.com Tue Jul 8 10:00:06 2008 From: hayafirst at gmail.com (Yi Wen) Date: Tue, 8 Jul 2008 09:00:06 -0500 Subject: [rspec-users] Colorize story output In-Reply-To: References: <9299dedc0807071231j64878253j32e167f981d3cfa1@mail.gmail.com> <48726FE2.7010500@benmabey.com> <7ac2300c0807080623u121e0ca2ifbf80a06a3fdb18e@mail.gmail.com> <196B2756-04C7-4908-B125-96B7A721D324@gmail.com> <7ac2300c0807080641h2ac302fama24356590e8329c0@mail.gmail.com> Message-ID: Actually, for the completeness. please see this: http://yiwenandsoftware.wordpress.com/2008/06/25/intergrate-rspec-story-runner-in-cruisecontrolrb-build-with-html-report/ On Tue, Jul 8, 2008 at 8:59 AM, Yi Wen wrote: > yes. -f html > > > On Tue, Jul 8, 2008 at 8:41 AM, aidy lewis > wrote: > >> Hi David, >> >> > > >> > >> > ruby stories/all.rb -c >> > >> >> Fantastic. Is it possible to create HTML from this? >> >> Aidy >> _______________________________________________ >> 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 aidy.lewis at googlemail.com Tue Jul 8 11:10:00 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Tue, 8 Jul 2008 16:10:00 +0100 Subject: [rspec-users] If a step fails the scenario has a class name of "passed" Message-ID: <7ac2300c0807080810g79c3defer34fd25570751b5ab@mail.gmail.com> Hi, Post-story HTML creation if a step within a scenario fails (class="failed") that scenario still passes ( class="passed"). We have added some javascript to rspec.js var rspec = { load : function() { $$(".passed").each ( function (passedElement) { if (passedElement.select(".failed").length > 0) { Element.removeClassName(passedElement,"passed"); Element.addClassName(passedElement,"failed"); } } ) } } Event.observe(window,"load",rspec.load); Aidy From ben at benmabey.com Tue Jul 8 11:11:29 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 08 Jul 2008 09:11:29 -0600 Subject: [rspec-users] is there a plain format output for stories? In-Reply-To: <4872FCCA.9000002@e4net.com> References: <4872FCCA.9000002@e4net.com> Message-ID: <487383A1.6000804@benmabey.com> Jim Morris wrote: > When running a lot of stories from a script it would be nice to have > the plain format of dots rather than the verbose story descriptions. > > Is there a way to do this? I tried -f p but it ignored it. > > Thanks > AFAIK there is currently no such formatter. Such a formatter would be easy to make though and you can pass in the formatter you want to use on the command line (even custom classes that you create.) To get an idea of how to do it you can look at the rspec source code in lib/spec/runner/formatter. The formatter for the examples can be found there and the story formatter's are in the story subdir. -Ben From loop at superinfinite.com Tue Jul 8 15:09:05 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Tue, 8 Jul 2008 21:09:05 +0200 Subject: [rspec-users] Why has the --color gone from my life? In-Reply-To: <57a815bf0806092205v41f9a33el73e47af97a78c6e2@mail.gmail.com> References: <57a815bf0806040410l4cec192ex43bc301d695e27ad@mail.gmail.com> <03EEC8AB-625A-4C36-8585-4782DA9F4E41@gmail.com> <57a815bf0806092205v41f9a33el73e47af97a78c6e2@mail.gmail.com> Message-ID: On 10 jun 2008, at 07:05, Mikel Lindsaar wrote: > This was fixed up updating to trunk: > > 3b76fda..befd422 master -> origin/master Looks like I have the same problem now. Created a new rails app (2.1.0), and using the install instructions on the github wiki, leaves me with an autotest (ZenTest version 3.10.0) running autotest/rails instead of autotest/rails_rspec as some of my older projects do. When I copy vendor/plugins/rspec-rails/lib/autotest/rails_rspec.rb to ~/.autotest, autotest runs with: /opt/local/bin/ruby -I.:lib:test -rtest/unit -e "%w[spec/controllers/ foos_routing_spec.rb spec/views/foos/index.html.erb_spec.rb spec/ helpers/foos_helper_spec.rb spec/models/foo_spec.rb spec/views/foos/ new.html.erb_spec.rb spec/views/foos/show.html.erb_spec.rb spec/views/ foos/edit.html.erb_spec.rb spec/controllers/ foos_controller_spec.rb].each { |f| require f }" | unit_diff -u giving me grey specs. So, without an .autotest, nothing at all happens. Running autotest -v gives, among all the .git files even Dunno! app/controllers/ application.rb! With rspec-rails' autotest, it runs with -r test/unit. Weird stuff, hopefully someone makes sense of this al. bartz > On Sat, Jun 7, 2008 at 2:09 AM, David Chelimsky > wrote: > On Jun 6, 2008, at 10:57 AM, Juanma Cervera wrote: > > This was an error, but I thought it was corrected by D. Chelimsky. > > That is correct - at least temporarily - there is a conflict with > how rspec and autotest output to a terminal that makes it > challenging for rspec to color code terminal output while not > including the color code chars in html output. > > If anybody is interested in helping to solve that, check out http://rspec.lighthouseapp.com/projects/5645/tickets/413 > . > > Cheers, > David > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Jul 8 15:43:38 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 8 Jul 2008 14:43:38 -0500 Subject: [rspec-users] Why has the --color gone from my life? In-Reply-To: References: <57a815bf0806040410l4cec192ex43bc301d695e27ad@mail.gmail.com> <03EEC8AB-625A-4C36-8585-4782DA9F4E41@gmail.com> <57a815bf0806092205v41f9a33el73e47af97a78c6e2@mail.gmail.com> Message-ID: On Jul 8, 2008, at 2:09 PM, Bart Zonneveld wrote: > On 10 jun 2008, at 07:05, Mikel Lindsaar wrote: > >> This was fixed up updating to trunk: >> >> 3b76fda..befd422 master -> origin/master > > Looks like I have the same problem now. Created a new rails app > (2.1.0), and using the install instructions on the github wiki, > leaves me with an autotest (ZenTest version 3.10.0) running autotest/ > rails instead of autotest/rails_rspec as some of my older projects do. > When I copy vendor/plugins/rspec-rails/lib/autotest/rails_rspec.rb > to ~/.autotest, autotest runs with: Why are you copying that there? Try doing this: cd vendor/plugins/rspec rake gem rake install_gem rake clobber cd ../../../ autospec Since you're using edge, autospec is the new command to run autotest with rspec. > > > /opt/local/bin/ruby -I.:lib:test -rtest/unit -e "%w[spec/controllers/ > foos_routing_spec.rb spec/views/foos/index.html.erb_spec.rb spec/ > helpers/foos_helper_spec.rb spec/models/foo_spec.rb spec/views/foos/ > new.html.erb_spec.rb spec/views/foos/show.html.erb_spec.rb spec/ > views/foos/edit.html.erb_spec.rb spec/controllers/ > foos_controller_spec.rb].each { |f| require f }" | unit_diff -u > > giving me grey specs. > > So, without an .autotest, nothing at all happens. Running autotest - > v gives, among all the .git files even Dunno! app/controllers/ > application.rb! > With rspec-rails' autotest, it runs with -r test/unit. > > Weird stuff, hopefully someone makes sense of this al. > bartz > > >> On Sat, Jun 7, 2008 at 2:09 AM, David Chelimsky >> wrote: >> On Jun 6, 2008, at 10:57 AM, Juanma Cervera wrote: >> >> This was an error, but I thought it was corrected by D. Chelimsky. >> >> That is correct - at least temporarily - there is a conflict with >> how rspec and autotest output to a terminal that makes it >> challenging for rspec to color code terminal output while not >> including the color code chars in html output. >> >> If anybody is interested in helping to solve that, check out http://rspec.lighthouseapp.com/projects/5645/tickets/413 >> . >> >> Cheers, >> David >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From loop at superinfinite.com Tue Jul 8 15:52:43 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Tue, 8 Jul 2008 21:52:43 +0200 Subject: [rspec-users] Why has the --color gone from my life? In-Reply-To: References: <57a815bf0806040410l4cec192ex43bc301d695e27ad@mail.gmail.com> <03EEC8AB-625A-4C36-8585-4782DA9F4E41@gmail.com> <57a815bf0806092205v41f9a33el73e47af97a78c6e2@mail.gmail.com> Message-ID: <86CDDE0C-4BF1-43D7-97BD-F13B8E51A0E8@superinfinite.com> On 8 jul 2008, at 21:43, David Chelimsky wrote: > On Jul 8, 2008, at 2:09 PM, Bart Zonneveld wrote: > >> On 10 jun 2008, at 07:05, Mikel Lindsaar wrote: >> >>> This was fixed up updating to trunk: >>> >>> 3b76fda..befd422 master -> origin/master >> >> Looks like I have the same problem now. Created a new rails app >> (2.1.0), and using the install instructions on the github wiki, >> leaves me with an autotest (ZenTest version 3.10.0) running >> autotest/rails instead of autotest/rails_rspec as some of my older >> projects do. >> When I copy vendor/plugins/rspec-rails/lib/autotest/rails_rspec.rb >> to ~/.autotest, autotest runs with: > > Why are you copying that there? Just trying whatever I could think of :). > Try doing this: > > cd vendor/plugins/rspec > rake gem > rake install_gem > rake clobber > cd ../../../ > autospec > > Since you're using edge, autospec is the new command to run autotest > with rspec. Okay, thanks. Might be worth it to actually write this somewhere down, such as on the wiki? This is nowhere to be found. thanks, bartz >> /opt/local/bin/ruby -I.:lib:test -rtest/unit -e "%w[spec/ >> controllers/foos_routing_spec.rb spec/views/foos/ >> index.html.erb_spec.rb spec/helpers/foos_helper_spec.rb spec/models/ >> foo_spec.rb spec/views/foos/new.html.erb_spec.rb spec/views/foos/ >> show.html.erb_spec.rb spec/views/foos/edit.html.erb_spec.rb spec/ >> controllers/foos_controller_spec.rb].each { |f| require f }" | >> unit_diff -u >> >> giving me grey specs. >> >> So, without an .autotest, nothing at all happens. Running autotest - >> v gives, among all the .git files even Dunno! app/controllers/ >> application.rb! >> With rspec-rails' autotest, it runs with -r test/unit. >> >> Weird stuff, hopefully someone makes sense of this al. >> bartz >> >> >>> On Sat, Jun 7, 2008 at 2:09 AM, David Chelimsky >> > wrote: >>> On Jun 6, 2008, at 10:57 AM, Juanma Cervera wrote: >>> >>> This was an error, but I thought it was corrected by D. Chelimsky. >>> >>> That is correct - at least temporarily - there is a conflict with >>> how rspec and autotest output to a terminal that makes it >>> challenging for rspec to color code terminal output while not >>> including the color code chars in html output. >>> >>> If anybody is interested in helping to solve that, check out http://rspec.lighthouseapp.com/projects/5645/tickets/413 >>> . >>> >>> Cheers, >>> David >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Jul 8 15:55:05 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 8 Jul 2008 14:55:05 -0500 Subject: [rspec-users] Why has the --color gone from my life? In-Reply-To: <86CDDE0C-4BF1-43D7-97BD-F13B8E51A0E8@superinfinite.com> References: <57a815bf0806040410l4cec192ex43bc301d695e27ad@mail.gmail.com> <03EEC8AB-625A-4C36-8585-4782DA9F4E41@gmail.com> <57a815bf0806092205v41f9a33el73e47af97a78c6e2@mail.gmail.com> <86CDDE0C-4BF1-43D7-97BD-F13B8E51A0E8@superinfinite.com> Message-ID: On Jul 8, 2008, at 2:52 PM, Bart Zonneveld wrote: > > On 8 jul 2008, at 21:43, David Chelimsky wrote: > >> On Jul 8, 2008, at 2:09 PM, Bart Zonneveld wrote: >> >>> On 10 jun 2008, at 07:05, Mikel Lindsaar wrote: >>> >>>> This was fixed up updating to trunk: >>>> >>>> 3b76fda..befd422 master -> origin/master >>> >>> Looks like I have the same problem now. Created a new rails app >>> (2.1.0), and using the install instructions on the github wiki, >>> leaves me with an autotest (ZenTest version 3.10.0) running >>> autotest/rails instead of autotest/rails_rspec as some of my older >>> projects do. >>> When I copy vendor/plugins/rspec-rails/lib/autotest/rails_rspec.rb >>> to ~/.autotest, autotest runs with: >> >> Why are you copying that there? > > Just trying whatever I could think of :). > >> Try doing this: >> >> cd vendor/plugins/rspec >> rake gem >> rake install_gem >> rake clobber >> cd ../../../ >> autospec >> >> Since you're using edge, autospec is the new command to run >> autotest with rspec. > > Okay, thanks. Might be worth it to actually write this somewhere > down, such as on the wiki? > This is nowhere to be found. http://github.com/dchelimsky/rspec/tree/master/History.txt Cheers, David > thanks, > bartz > > >>> /opt/local/bin/ruby -I.:lib:test -rtest/unit -e "%w[spec/ >>> controllers/foos_routing_spec.rb spec/views/foos/ >>> index.html.erb_spec.rb spec/helpers/foos_helper_spec.rb spec/ >>> models/foo_spec.rb spec/views/foos/new.html.erb_spec.rb spec/views/ >>> foos/show.html.erb_spec.rb spec/views/foos/edit.html.erb_spec.rb >>> spec/controllers/foos_controller_spec.rb].each { |f| require f }" >>> | unit_diff -u >>> >>> giving me grey specs. >>> >>> So, without an .autotest, nothing at all happens. Running autotest >>> -v gives, among all the .git files even Dunno! app/controllers/ >>> application.rb! >>> With rspec-rails' autotest, it runs with -r test/unit. >>> >>> Weird stuff, hopefully someone makes sense of this al. >>> bartz >>> >>> >>>> On Sat, Jun 7, 2008 at 2:09 AM, David Chelimsky >>> > wrote: >>>> On Jun 6, 2008, at 10:57 AM, Juanma Cervera wrote: >>>> >>>> This was an error, but I thought it was corrected by D. Chelimsky. >>>> >>>> That is correct - at least temporarily - there is a conflict with >>>> how rspec and autotest output to a terminal that makes it >>>> challenging for rspec to color code terminal output while not >>>> including the color code chars in html output. >>>> >>>> If anybody is interested in helping to solve that, check out http://rspec.lighthouseapp.com/projects/5645/tickets/413 >>>> . >>>> >>>> Cheers, >>>> David >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Tue Jul 8 16:01:30 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 8 Jul 2008 15:01:30 -0500 Subject: [rspec-users] Why has the --color gone from my life? In-Reply-To: References: <57a815bf0806040410l4cec192ex43bc301d695e27ad@mail.gmail.com> <03EEC8AB-625A-4C36-8585-4782DA9F4E41@gmail.com> <57a815bf0806092205v41f9a33el73e47af97a78c6e2@mail.gmail.com> <86CDDE0C-4BF1-43D7-97BD-F13B8E51A0E8@superinfinite.com> Message-ID: <2AA59F21-B0CD-40FD-8A13-A59EA2846AFB@gmail.com> On Jul 8, 2008, at 2:55 PM, David Chelimsky wrote: > On Jul 8, 2008, at 2:52 PM, Bart Zonneveld wrote: > >> >> On 8 jul 2008, at 21:43, David Chelimsky wrote: >> >>> On Jul 8, 2008, at 2:09 PM, Bart Zonneveld wrote: >>> >>>> On 10 jun 2008, at 07:05, Mikel Lindsaar wrote: >>>> >>>>> This was fixed up updating to trunk: >>>>> >>>>> 3b76fda..befd422 master -> origin/master >>>> >>>> Looks like I have the same problem now. Created a new rails app >>>> (2.1.0), and using the install instructions on the github wiki, >>>> leaves me with an autotest (ZenTest version 3.10.0) running >>>> autotest/rails instead of autotest/rails_rspec as some of my >>>> older projects do. >>>> When I copy vendor/plugins/rspec-rails/lib/autotest/ >>>> rails_rspec.rb to ~/.autotest, autotest runs with: >>> >>> Why are you copying that there? >> >> Just trying whatever I could think of :). >> >>> Try doing this: >>> >>> cd vendor/plugins/rspec >>> rake gem >>> rake install_gem >>> rake clobber >>> cd ../../../ >>> autospec >>> >>> Since you're using edge, autospec is the new command to run >>> autotest with rspec. >> >> Okay, thanks. Might be worth it to actually write this somewhere >> down, such as on the wiki? >> This is nowhere to be found. > > http://github.com/dchelimsky/rspec/tree/master/History.txt Just added 'script/autospec' (in rspec-rails) too - http://github.com/dchelimsky/rspec-rails/tree/master/History.txt Cheers, David > > > Cheers, > David > >> thanks, >> bartz >> >> >>>> /opt/local/bin/ruby -I.:lib:test -rtest/unit -e "%w[spec/ >>>> controllers/foos_routing_spec.rb spec/views/foos/ >>>> index.html.erb_spec.rb spec/helpers/foos_helper_spec.rb spec/ >>>> models/foo_spec.rb spec/views/foos/new.html.erb_spec.rb spec/ >>>> views/foos/show.html.erb_spec.rb spec/views/foos/ >>>> edit.html.erb_spec.rb spec/controllers/ >>>> foos_controller_spec.rb].each { |f| require f }" | unit_diff -u >>>> >>>> giving me grey specs. >>>> >>>> So, without an .autotest, nothing at all happens. Running >>>> autotest -v gives, among all the .git files even Dunno! app/ >>>> controllers/application.rb! >>>> With rspec-rails' autotest, it runs with -r test/unit. >>>> >>>> Weird stuff, hopefully someone makes sense of this al. >>>> bartz >>>> >>>> >>>>> On Sat, Jun 7, 2008 at 2:09 AM, David Chelimsky >>>> > wrote: >>>>> On Jun 6, 2008, at 10:57 AM, Juanma Cervera wrote: >>>>> >>>>> This was an error, but I thought it was corrected by D. Chelimsky. >>>>> >>>>> That is correct - at least temporarily - there is a conflict >>>>> with how rspec and autotest output to a terminal that makes it >>>>> challenging for rspec to color code terminal output while not >>>>> including the color code chars in html output. >>>>> >>>>> If anybody is interested in helping to solve that, check out http://rspec.lighthouseapp.com/projects/5645/tickets/413 >>>>> . >>>>> >>>>> Cheers, >>>>> David >>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> 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 david at digitalronin.com Wed Jul 9 11:16:07 2008 From: david at digitalronin.com (David Salgado) Date: Wed, 9 Jul 2008 16:16:07 +0100 Subject: [rspec-users] is there a plain format output for stories? Message-ID: <8c90cb7d0807090816s2d7c32d4t55ab1db4ca604682@mail.gmail.com> I've created a very simple 'basic' formatter, than prints story scenarios as . / P / F for passing, pending and failing scenarios. You can get it here; http://github.com/digitalronin/rspec/tree/master Run it by appending " --format=basic " to the command-line when running your stories. Hope it's useful David On Jul 8, 4:11 pm, Ben Mabey wrote: > Jim Morris wrote: > > When running a lot of stories from a script it would be nice to have > > the plain format of dots rather than the verbose story descriptions. > > > Is there a way to do this? I tried -f p but it ignored it. > > > Thanks > > AFAIK there is currently no such formatter. Such a formatter would be > easy to make though and you can pass in the formatter you want to use on > the command line (even custom classes that you create.) To get an idea > of how to do it you can look at the rspec source code in > lib/spec/runner/formatter. The formatter for the examples can be found > there and the story formatter's are in the story subdir. > > -Ben > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed Jul 9 15:08:01 2008 From: lists at ruby-forum.com (Tim Stevens) Date: Wed, 9 Jul 2008 21:08:01 +0200 Subject: [rspec-users] controller vars for examples Message-ID: <8c986177803c48b94d5199c077a99574@ruby-forum.com> Hi, How do I override the value of a controller variable in a controller spec. For ex, if I have an action with an array, I want to have examples with different variables in the array def testing my_array = [1,2,4] end How do I test this with diff vals for my array? Thanks -- Posted via http://www.ruby-forum.com/. From matt at matt-darby.com Wed Jul 9 15:11:31 2008 From: matt at matt-darby.com (Matt Darby) Date: Wed, 9 Jul 2008 15:11:31 -0400 Subject: [rspec-users] controller vars for examples In-Reply-To: <8c986177803c48b94d5199c077a99574@ruby-forum.com> References: <8c986177803c48b94d5199c077a99574@ruby-forum.com> Message-ID: On Jul 9, 2008, at 3:08 PM, Tim Stevens wrote: > > How do I override the value of a controller variable in a controller > spec. For ex, if I have an action with an array, I want to have > examples > with different variables in the array > > def testing > my_array = [1,2,4] > end > > How do I test this with diff vals for my array? This should do the trick: stub!("my_array").and_return([2,3,4]) From zach.dennis at gmail.com Wed Jul 9 15:36:23 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 9 Jul 2008 15:36:23 -0400 Subject: [rspec-users] controller vars for examples In-Reply-To: <8c986177803c48b94d5199c077a99574@ruby-forum.com> References: <8c986177803c48b94d5199c077a99574@ruby-forum.com> Message-ID: <85d99afe0807091236w12805392ic2032f45b76b5706@mail.gmail.com> Can you provide more information about what you are spec'ing? Zach On Wed, Jul 9, 2008 at 3:08 PM, Tim Stevens wrote: > Hi, > > How do I override the value of a controller variable in a controller > spec. For ex, if I have an action with an array, I want to have examples > with different variables in the array > > def testing > my_array = [1,2,4] > end > > How do I test this with diff vals for my array? > > > > Thanks > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ml at e4net.com Wed Jul 9 15:55:14 2008 From: ml at e4net.com (Jim Morris) Date: Wed, 09 Jul 2008 12:55:14 -0700 Subject: [rspec-users] is there a plain format output for stories? In-Reply-To: <8c90cb7d0807090816s2d7c32d4t55ab1db4ca604682@mail.gmail.com> References: <8c90cb7d0807090816s2d7c32d4t55ab1db4ca604682@mail.gmail.com> Message-ID: <487517A2.9090000@e4net.com> David Salgado wrote: > I've created a very simple 'basic' formatter, than prints story > scenarios as . / P / F for passing, pending and failing scenarios. You > can get it here; > > http://github.com/digitalronin/rspec/tree/master > > Run it by appending " --format=basic " to the command-line when running > your stories. > Thanks, that is pretty simple. I knocked up this one, which shows progress like the progress for examples. I just put it in my spec_helper.rb and do --format ProgressFormatter require 'spec/runner/formatter/base_text_formatter' class ProgressFormatter < Spec::Runner::Formatter::BaseTextFormatter def initialize(options, where) super @successful_scenario_count = 0 @pending_scenario_count = 0 @failed_scenarios = [] @pending_steps = [] @previous_type = nil end def run_started(count) @count = count end def story_started(title, narrative) @current_story_title = title @output.print '[' @output.flush end def story_ended(title, narrative) @output.puts ']' end def scenario_started(story_title, scenario_name) @current_scenario_name = scenario_name @scenario_already_failed = false end def scenario_succeeded(story_title, scenario_name) @successful_scenario_count += 1 @output.print '*' @output.flush end def scenario_failed(story_title, scenario_name, err) @options.backtrace_tweaker.tweak_backtrace(err) @failed_scenarios << [story_title, scenario_name, err] unless @scenario_already_failed @scenario_already_failed = true @output.print 'F' @output.flush end def scenario_pending(story_title, scenario_name, msg) @pending_scenario_count += 1 unless @scenario_already_failed @scenario_pending = true @scenario_already_failed = true @output.print 'P' @output.flush end def run_ended @output.print "#@count scenarios: #@successful_scenario_count succeeded, #{@failed_scenarios.size} failed, #@pending_scenario_count pending" unless @pending_steps.empty? @output.print "\nPending Steps:" @pending_steps.each_with_index do |pending, i| story_name, scenario_name, msg = pending @output.print "#{i+1}) #{story_name} (#{scenario_name}): #{msg}" end end unless @failed_scenarios.empty? @output.print "\nFAILURES:" @failed_scenarios.each_with_index do |failure, i| title, scenario_name, err = failure @output.print %[ #{i+1}) #{title} (#{scenario_name}) FAILED #{err.class}: #{err.message} #{err.backtrace.join("\n")} ] end end @output.puts "" end def step_upcoming(type, description, *args) end def step_succeeded(type, description, *args) @output.print '.' @output.flush end def step_pending(type, description, *args) @pending_steps << [@current_story_title, @current_scenario_name, description] @output.print 'p' @output.flush @scenario_pending = true @scenario_ok = false end def step_failed(type, description, *args) @output.print 'f' @output.flush @scenario_ok = false end def collected_steps(steps) end def method_missing(sym, *args, &block) #:nodoc: # noop - ignore unknown messages end end -- Jim Morris, http://blog.wolfman.com From sera at fhwang.net Wed Jul 9 18:36:31 2008 From: sera at fhwang.net (Francis Hwang) Date: Wed, 9 Jul 2008 18:36:31 -0400 Subject: [rspec-users] setting request.raw_post with rspec-rails Message-ID: ... is there a way to do this? We have some REST-ish POSTs we'd like to spec out. In the controller this gets accessed with request.raw_post.to_s, is there a way to set this with rspec? Thanks as always, Francis From rick.denatale at gmail.com Wed Jul 9 18:52:01 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Wed, 9 Jul 2008 18:52:01 -0400 Subject: [rspec-users] Can I get RSpec NOT to abort rake on failing specs? Message-ID: At work we've got a rather complex app with both specs and tests. Our default rake task runs all our our tests and specs. We've also got separate rake tasks to run groups of tests and specs in the various subdirectories. The default task simply lists all the individual tasks as pre-reqs. We do a lot of branching and merging, so we really want to run all of the tests and specs to see all failures. We just realized that Rspec is aborting rake when a spec fails or errors in an individual rake task. I've been trying to fix this to no avail. I notice that SpecTask has an attribute accessor fail_on_error which looks like it SHOULD prevent terminating rake if it's set to false. So I tried that and it doesn't seem to work. Here's our projects lib/tasks/spec.rake, any ideas? def spec_tasks %w{spec:controllers spec:models spec:helpers spec:views spec:lib} + spec_subdirs.map {|t| "spec:#{t}"} end begin require RAILS_ROOT + '/vendor/plugins/rspec/lib/spec/rake/spectask' namespace :spec do spec_subdirs.each do |task| next if Rake::Task.task_defined?("spec:#{task}") desc "Run the specs under spec/#{task}" Spec::Rake::SpecTask.new(task) do |t| t.fail_on_error = false t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] t.spec_files = FileList["spec/#{task}/*_spec.rb"] end namespace(task) do Spec::Rake::SpecTask.new(:rcov) do |t| t.fail_on_error = false t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] t.rcov_opts = ['--include', "\"app/#{task}/.*.rb$\""] t.rcov = true t.spec_files = FileList["spec/#{task}/*_spec.rb"] end end end end rescue LoadError => e puts "Spec tasks are not available - #{e}" end namespace :spec do desc "Run each set of specs individually" task :each => spec_tasks end -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Jul 9 21:53:29 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 9 Jul 2008 20:53:29 -0500 Subject: [rspec-users] setting request.raw_post with rspec-rails In-Reply-To: References: Message-ID: <7D843464-B386-435A-ABBD-7FE63F23FA98@gmail.com> On Jul 9, 2008, at 5:36 PM, Francis Hwang wrote: > ... is there a way to do this? We have some REST-ish POSTs we'd like > to spec out. In the controller this gets accessed with > request.raw_post.to_s, is there a way to set this with rspec? If you mean you want to set it in an example before the post, you can do this: request.stub!(:raw_post).and_return('this string') post :whatever Or, if you want to be really detailed about it (I wouldn't, but it's up to you), you could say: raw_post = mock('raw_post') raw_post.should_receive(:to_s).and_return('this string') request.stub!(:raw_post).and_return(:raw_post) etc That what you're looking for? Cheers, David > > > Thanks as always, > Francis > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Jul 9 22:09:36 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 9 Jul 2008 21:09:36 -0500 Subject: [rspec-users] Can I get RSpec NOT to abort rake on failing specs? In-Reply-To: References: Message-ID: <8A207817-E226-4E2F-BA46-760C184B47F4@gmail.com> On Jul 9, 2008, at 5:52 PM, Rick DeNatale wrote: > At work we've got a rather complex app with both specs and tests. > Our default rake task runs all our our tests and specs. We've also > got separate rake tasks to run groups of tests and specs in the > various subdirectories. The default task simply lists all the > individual tasks as pre-reqs. > > We do a lot of branching and merging, so we really want to run all > of the tests and specs to see all failures. > > We just realized that Rspec is aborting rake when a spec fails or > errors in an individual rake task. I've been trying to fix this to > no avail. I notice that SpecTask has an attribute accessor > fail_on_error which looks like it SHOULD prevent terminating rake if > it's set to false. So I tried that and it doesn't seem to work. > Here's our projects lib/tasks/spec.rake, any ideas? > > > def spec_tasks > %w{spec:controllers spec:models spec:helpers spec:views spec:lib} > + spec_subdirs.map {|t| "spec:#{t}"} > end > > begin > require RAILS_ROOT + '/vendor/plugins/rspec/lib/spec/rake/spectask' > > namespace :spec do > spec_subdirs.each do |task| > next if Rake::Task.task_defined?("spec:#{task}") spec:models, views, controllers and helpers are all defined already in vendor/plugins/rspec-rails/tasks/rspec.rake, so the next keyword is being invoked for all of those. You'll need to undefined them before you redefine them here. spec_tasks.each {|t| Rake::Task::TASKS.delete t} Cheers, David > > > desc "Run the specs under spec/#{task}" > Spec::Rake::SpecTask.new(task) do |t| > t.fail_on_error = false > t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] > t.spec_files = FileList["spec/#{task}/*_spec.rb"] > end > > namespace(task) do > Spec::Rake::SpecTask.new(:rcov) do |t| > t.fail_on_error = false > t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts > \""] > t.rcov_opts = ['--include', "\"app/#{task}/.*.rb$\""] > t.rcov = true > t.spec_files = FileList["spec/#{task}/*_spec.rb"] > end > end > end > end > rescue LoadError => e > puts "Spec tasks are not available - #{e}" > end > > namespace :spec do > desc "Run each set of specs individually" > task :each => spec_tasks > end > > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From rick.denatale at gmail.com Thu Jul 10 08:45:54 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Thu, 10 Jul 2008 08:45:54 -0400 Subject: [rspec-users] Can I get RSpec NOT to abort rake on failing specs? In-Reply-To: <8A207817-E226-4E2F-BA46-760C184B47F4@gmail.com> References: <8A207817-E226-4E2F-BA46-760C184B47F4@gmail.com> Message-ID: On Wed, Jul 9, 2008 at 10:09 PM, David Chelimsky wrote: > On Jul 9, 2008, at 5:52 PM, Rick DeNatale wrote: > > spec:models, views, controllers and helpers are all defined already in > vendor/plugins/rspec-rails/tasks/rspec.rake, so the next keyword is being > invoked for all of those. You'll need to undefined them before you redefine > them here. > > spec_tasks.each {|t| Rake::Task::TASKS.delete t} > > Thanks David, I figured it was something like that. I had to modify it a bit since there is no TASKS constant. Rake::Task does have a tasks method, but it wasn't clear that deleting an element would work since it must be flattening the task namespace hierarchy. So I ended up with this: begin require RAILS_ROOT + '/vendor/plugins/rspec/lib/spec/rake/spectask' namespace :spec do spec_subdirs.each do |task| if Rake::Task.task_defined?("spec:#{task}") Rake::Task["spec:#{task}"].fail_on_error = false else desc "Run the specs under spec/#{task}" Spec::Rake::SpecTask.new(task) do |t| t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] t.spec_files = FileList["spec/#{task}/*_spec.rb"] t.fail_on_error = false end end if Rake::Task.task_defined?("spec:#{task}:rcov") Rake::Task["spec:#{task}:rcov"].fail_on_error = false else namespace(task) do Spec::Rake::SpecTask.new(:rcov) do |t| t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] t.rcov_opts = ['--include', "\"app/#{task}/.*.rb$\""] t.rcov = true t.fail_on_error = false t.spec_files = FileList["spec/#{task}/*_spec.rb"] end end end end end rescue LoadError => e puts "Spec tasks are not available - #{e}" end But this still DOESN'T WORK. It turns out that this code is running BEFORE the plugin creates its tasks so those are overwriting mine. I'm beginning to think that I need to patch RSpec to allow the default value of fail_on_error to be set with either an environment variable or in spec.opts. Thoughts? -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From mgomez at cit-jena.de Thu Jul 10 04:26:12 2008 From: mgomez at cit-jena.de (Miguel Gomez) Date: Thu, 10 Jul 2008 10:26:12 +0200 Subject: [rspec-users] Persistence across steps in stories Message-ID: <5c08fd737cdb555051a3c9b90419b51b@cit-jena.de> Hello. I have divided my story into several steps. I have a Given requirement in one file where I create (and save) an object. Afterwards, I have a When requirement in another "steps_for" file, which i suppossed to use this object. Now this is not working for me (neither calling the objects variable, nor with a Myclass.find(:first) ), whereas, if I create the object inside of the same "steps_for" file, everything works allright. I believe that it should be possible to call the objects along the whole scenario independently from in which file they where created, but I don't get how. Am I wrong? -- CIT Jena GmbH Computer- und Informationstechnik Jena GmbH Braunstra?e 16 04347 Leipzig Fon 0341 - 23 46 18 0 Fax 0341 - 23 15 92 72 eMail mgomez at cit-jena.de Web www.cit-jena.de Amtsgericht Leipzig HRB 21846 Umsatzsteuer ID DE 234250792 Gesch?ftsf?hrer Harry V?gele Haftungsausschluss Diese e-Mail ist vertraulich und nur f?r den Empf?nger bzw. den Adressaten bestimmt. Wenn Sie nicht der rechtm??ige Empf?nger dieser e-Mail sind, ist es Ihnen nicht erlaubt die Inhalte der Mail auszuwerten, zu verwenden oder weiterzuleiten. Wir bitten Sie in diesem Fall, die e-Mail zu l?schen. Disclaimer This e-mail is confidential and intended only for the recipient or organization to whom it is addressed. It may contain private or confidential information and if you are not the intended recipient, you must not copy, distribute or take any action in reliance on it. If you have received this e-mail in error, please delete it. Copyright ? Copyright 2008 CIT Jena GmbH. Alle Rechte vorbehalten. From loriolson at mac.com Thu Jul 10 13:32:11 2008 From: loriolson at mac.com (Lori M Olson) Date: Thu, 10 Jul 2008 11:32:11 -0600 Subject: [rspec-users] Baffled by error running rake rspec:models Message-ID: In my application, we connect to 2 databases, so we make a lot of specs to test this type of interaction. When I run individual model specs using spec, or using rake spec SPEC=xxx, they run *fine*. When I run rake spec:models, all the specs which connect to the 2nd database fail on errors like this: OCIError in 'WellLicense should identify EIS data is not available' ORA-01017: invalid username/password; logon denied env.c:257:in oci8lib.so ./spec/models/well_license2_spec.rb:6:in `new' ./spec/models/well_license2_spec.rb:6: This WAS working a couple of days ago. I did update from the beta version of the Oracle Intel InstantClient for Mac to the officially released version, but I can't see how that would make a difference, especially when running the specs individually works. This has to be some strange configuration error, but I'm baffled. I've spent hours trying to track it down. Help! database.yml entry: data_centre: adapter: oracle_enhanced database: xe username: XXXXXX password: YYYYYY And our database connection is established in data_center_spec_helper.rb like so: LabRecord .establish_connection(ActiveRecord::Base.configurations['data_centre']) Regards, Lori From ml at e4net.com Thu Jul 10 15:59:57 2008 From: ml at e4net.com (Jim Morris) Date: Thu, 10 Jul 2008 12:59:57 -0700 Subject: [rspec-users] rake task to run stories? Message-ID: <48766A3D.6090900@e4net.com> Hi, Shouldn't there be a rake task in rails to run the stories? and shouldn't rake spec run the stories as well? Right now it seems I run all my specs via rake spec, but then have to run the stories by ruby stories/all.rb Am I missing something? BTW using stories for rails integration testing seems to work very nicely, thank you! -- Jim Morris, http://blog.wolfman.com From dchelimsky at gmail.com Thu Jul 10 16:41:59 2008 From: dchelimsky at gmail.com (dchelimsky at gmail.com) Date: Thu, 10 Jul 2008 13:41:59 -0700 (PDT) Subject: [rspec-users] rake task to run stories? In-Reply-To: <48766A3D.6090900@e4net.com> References: <48766A3D.6090900@e4net.com> Message-ID: On Jul 10, 2:59?pm, Jim Morris wrote: > Hi, > > Shouldn't there be a rake task in rails to run the stories? There is one, but it needs a tweak. It uses the ruby method instead of sh, so you only get output if it fails. I'll get that fixed. > and shouldn't rake spec run the stories as well? No. Stories and specs are not the same thing. But, if you feel differently, then you can always do this in your rake file: task :spec => :stories Cheers, David > > Right now it seems I run all my specs via rake spec, but then have to run the stories by ruby > stories/all.rb > > Am I missing something? > > BTW using stories for rails integration testing seems to work very nicely, thank you! > > -- > Jim Morris,http://blog.wolfman.com > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Thu Jul 10 19:06:01 2008 From: lists at ruby-forum.com (Chris Sepic) Date: Fri, 11 Jul 2008 01:06:01 +0200 Subject: [rspec-users] Whence "post" in a description? In-Reply-To: <15988683.post@talk.nabble.com> References: <15988683.post@talk.nabble.com> Message-ID: <159454802276dc1ca470159653716e71@ruby-forum.com> I'm having the same problem. Did you ever solve this? I'm using Rails 1.2.6 - I recently ran a conversion plugin to convert my Test::Unit tests to Rspec. Everything is working fine except this - response.body just returns the template name. Test::Unit: xhr(:post, :add_to_cart_xhr, ...) assert_match(/Quantity is not a number/, @response.body) # <--passes Rspec xhr(:post, :add_to_cart_xhr, ...) response.body.should match(/Quantity is not a number/) #<--fails nzook wrote: > I'm having the exact problem described in this earlier post: > http://www.nabble.com/Odd-response.body-behavior-to12837556.html#a12837556 > > That is, after a post, response.body is just the controller/view string > ("user/login" in my case). > > Failing to find any answer on the web, I'm trying to trace execution, > but > hitting a bit of a snag. I'm tracing the ancestry of self inside a test > example to see where the "post" function is actually defined. I'm > getting a > hit on Spec::Rails::Example::FunctionalExampleGroup, but I cannot find > where > it is defined in this module! > ????? > > -- > View this message in context: > http://www.nabble.com/Whence-%22post%22-in-a-description--tp15988683p15988683.html > Sent from the rspec-users mailing list archive at Nabble.com. -- Posted via http://www.ruby-forum.com/. From restagner at gmail.com Thu Jul 10 19:19:07 2008 From: restagner at gmail.com (Robert Stagner) Date: Thu, 10 Jul 2008 16:19:07 -0700 Subject: [rspec-users] Executing multiple rspec scripts Message-ID: I'm new to RSpec. I've just installed the gem and begun experimenting with developing several scripts. From what I've seen thus far, it looks like it will aid our QA team in testing many web applications. Is there a way to execute multiple rspec test scripts from one central file? -- Regards, Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Thu Jul 10 19:30:17 2008 From: lists at ruby-forum.com (Chris Sepic) Date: Fri, 11 Jul 2008 01:30:17 +0200 Subject: [rspec-users] Whence "post" in a description? In-Reply-To: <159454802276dc1ca470159653716e71@ruby-forum.com> References: <15988683.post@talk.nabble.com> <159454802276dc1ca470159653716e71@ruby-forum.com> Message-ID: <389e35a81e8d277b8ba9723edf5ec255@ruby-forum.com> Found the problem. Was not calling integrate_views at the start of the describe block. Chris Sepic wrote: > I'm having the same problem. Did you ever solve this? I'm using Rails > 1.2.6 - I recently ran a conversion plugin to convert my Test::Unit > tests to Rspec. Everything is working fine except this - response.body > just returns the template name. > > Test::Unit: > xhr(:post, :add_to_cart_xhr, ...) > assert_match(/Quantity is not a number/, @response.body) # <--passes > > Rspec > xhr(:post, :add_to_cart_xhr, ...) > response.body.should match(/Quantity is not a number/) #<--fails -- Posted via http://www.ruby-forum.com/. From sera at fhwang.net Thu Jul 10 22:43:34 2008 From: sera at fhwang.net (Francis Hwang) Date: Thu, 10 Jul 2008 22:43:34 -0400 Subject: [rspec-users] setting request.raw_post with rspec-rails In-Reply-To: <7D843464-B386-435A-ABBD-7FE63F23FA98@gmail.com> References: <7D843464-B386-435A-ABBD-7FE63F23FA98@gmail.com> Message-ID: <7D33499C-3646-4196-A143-420EDBFE1A14@fhwang.net> Yup, that's exactly what I needed -- thanks, Francis Hwang http://fhwang.net/ On Jul 9, 2008, at 9:53 PM, David Chelimsky wrote: > On Jul 9, 2008, at 5:36 PM, Francis Hwang wrote: > >> ... is there a way to do this? We have some REST-ish POSTs we'd >> like to spec out. In the controller this gets accessed with >> request.raw_post.to_s, is there a way to set this with rspec? > > If you mean you want to set it in an example before the post, you > can do this: > > request.stub!(:raw_post).and_return('this string') > post :whatever > > Or, if you want to be really detailed about it (I wouldn't, but it's > up to you), you could say: > > raw_post = mock('raw_post') > raw_post.should_receive(:to_s).and_return('this string') > request.stub!(:raw_post).and_return(:raw_post) > > etc > > That what you're looking for? > > Cheers, > David > > >> >> >> Thanks as always, >> Francis >> >> _______________________________________________ >> 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 matt-darby.com Thu Jul 10 23:03:13 2008 From: matt at matt-darby.com (Matt Darby) Date: Thu, 10 Jul 2008 23:03:13 -0400 Subject: [rspec-users] Executing multiple rspec scripts In-Reply-To: References: Message-ID: On Jul 10, 2008, at 7:19 PM, Robert Stagner wrote: > I'm new to RSpec. I've just installed the gem and begun > experimenting with developing several scripts. From what I've seen > thus far, it looks like it will aid our QA team in testing many web > applications. Is there a way to execute multiple rspec test scripts > from one central file? I assume you're using Rails, from there you can see what RSpec tasks are available via "rake -T spec" Matt Darby, M.S. Rails | PHP | Linux | MySQL | IT Email: matt at matt-darby.com Skype: matt-darby Web: http://blog.matt-darby.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben at benmabey.com Thu Jul 10 23:17:19 2008 From: ben at benmabey.com (Ben Mabey) Date: Thu, 10 Jul 2008 21:17:19 -0600 Subject: [rspec-users] Executing multiple rspec scripts In-Reply-To: References: Message-ID: <4876D0BF.8080401@benmabey.com> Robert Stagner wrote: > I'm new to RSpec. I've just installed the gem and begun experimenting > with developing several scripts. From what I've seen thus far, it > looks like it will aid our QA team in testing many web applications. > Is there a way to execute multiple rspec test scripts from one central > file? > > -- > Regards, > Robert Robert, Welcome to rspec! There are a number of ways you can do this. You can do it with the command line: spec spec/*_spec.rb The way it is generally done is by using a rake task however... Are you using rails? If so.. have you run "./script/generate rspec"? That will install a spec task for you so you just have to type "rake spec" to run all of your specs. If you are in a normal ruby app then you can create your own spec task by putting this in your Rakefile or tasks dir: require 'rubygems' require 'spec' require 'spec/rake/spectask' desc "Run the specs under spec/models" Spec::Rake::SpecTask.new do |t| t.spec_files = FileList['spec/*_spec.rb'] end If you provide more information on what your setup is we could help more. -Ben http://benmabey.com From lists at ruby-forum.com Fri Jul 11 05:00:32 2008 From: lists at ruby-forum.com (Piotr Wlodarek) Date: Fri, 11 Jul 2008 11:00:32 +0200 Subject: [rspec-users] How to stub forever? Message-ID: <7696d5c671e45662fc57963ed34013ff@ruby-forum.com> How to stub a method for multiple calls? The calls are done in a loop. I expect: @agent.stub!( :submit ).multiple_times.and_return( @account_details_page ) ..to stub submit method "forever" (any number of calls). -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Jul 11 05:40:54 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 11 Jul 2008 04:40:54 -0500 Subject: [rspec-users] How to stub forever? In-Reply-To: <7696d5c671e45662fc57963ed34013ff@ruby-forum.com> References: <7696d5c671e45662fc57963ed34013ff@ruby-forum.com> Message-ID: <57c63afe0807110240jbdf6ef5u15564fdc27add626@mail.gmail.com> On 7/11/08, Piotr Wlodarek wrote: > > How to stub a method for multiple calls? > > The calls are done in a loop. > > I expect: > @agent.stub!( :submit ).multiple_times.and_return( @account_details_page > ) > ..to stub submit method "forever" (any number of calls). Stubs will do this automatically. Just do this: @agent.stub!( :submit ).and_return(@account_details_page) Cheers, David > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From restagner at gmail.com Fri Jul 11 12:55:22 2008 From: restagner at gmail.com (Robert Stagner) Date: Fri, 11 Jul 2008 09:55:22 -0700 Subject: [rspec-users] Executing multiple rspec scripts In-Reply-To: <4876D0BF.8080401@benmabey.com> References: <4876D0BF.8080401@benmabey.com> Message-ID: Actually, I'm a member of the QA team (limited development experience). So, we are attempting to use RSpec without rails. What is Rake? Near the end of your response, you list a way of running multiple spec files by creating a spec task. Since, I'm not a developer, could you please provide me with a clear example on how to do this? Or, if there is an alternative method on doing this, please let me know. Thanks again. My current setup is: 1 spec file that relies on accessing a module of classes to perform Watir web app testing. I've included a sample of the code below describe LoginWelcomeScreen do describe "using IE Explorer" do before(:each) do @login = LoginWelcomeScreen.new(IEWebBrowser.instance) end it "should support a username text field" do @login.test_username_field.should be_an_instance_of(Watir::TextField) end it "should support a password text field" do @login.test_password_field.should be_an_instance_of(Watir::TextField) end . . . . end On Thu, Jul 10, 2008 at 8:17 PM, Ben Mabey wrote: > Robert Stagner wrote: > >> I'm new to RSpec. I've just installed the gem and begun experimenting >> with developing several scripts. From what I've seen thus far, it looks like >> it will aid our QA team in testing many web applications. Is there a way to >> execute multiple rspec test scripts from one central file? >> >> -- >> Regards, >> Robert >> > > Robert, > Welcome to rspec! There are a number of ways you can do this. You can > do it with the command line: > spec spec/*_spec.rb > > The way it is generally done is by using a rake task however... > Are you using rails? If so.. have you run "./script/generate rspec"? > That will install a spec task for you so you just have to type "rake > spec" to run all of your specs. > > If you are in a normal ruby app then you can create your own spec task > by putting this in your Rakefile or tasks dir: > > require 'rubygems' > require 'spec' > require 'spec/rake/spectask' > > desc "Run the specs under spec/models" > Spec::Rake::SpecTask.new do |t| > t.spec_files = FileList['spec/*_spec.rb'] > end > > If you provide more information on what your setup is we could help more. > > -Ben > http://benmabey.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Regards, Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Fri Jul 11 13:04:00 2008 From: lists at ruby-forum.com (Reggie Mr.) Date: Fri, 11 Jul 2008 19:04:00 +0200 Subject: [rspec-users] rspec render :update Message-ID: <01601b55fe6dd1e35f3d2bf46354a6fe@ruby-forum.com> Hi all, I'm having trouble with rspec 1.1.4 and rjs In the controller: render :update do |page| page << 'added text' end render :update do |page| page.replace_html :divid :partial => 'apartial' end spec: response.should have_rjs #this should be successful for any rjs request; but fails response.should have_rjs(:replace_html) #no luck I have tried mocking the page object, but that also fails. e.g @page = mock('page) @page.should_receive(:replace_html) What's the best practice to validate rjs responses? Thanks in advance -- Posted via http://www.ruby-forum.com/. From cgrindel at yahoo.com Fri Jul 11 14:33:20 2008 From: cgrindel at yahoo.com (Charles Grindel) Date: Fri, 11 Jul 2008 11:33:20 -0700 (PDT) Subject: [rspec-users] Getting RSpec 1.1.4+ to Work with Autotest (ZenTest 3.10.0) on Windows (Win32) Message-ID: <841120.80434.qm@web54110.mail.re2.yahoo.com> Hi, After upgrading to Rails 2.1, RSpec 1.1.4+ and ZenTest 3.10.0, autotest would no longer find any of my specs on my Windows development machine. Some Googling directed me to a very recent update in the History.txt file for rspec-fails: IMPORTANT: use 'script/autospec' (or just 'autospec' if you have the rspec gem installed) instead of 'autotest'. We changed the way autotest discovers rspec so the autotest executable won't automatically load rspec anymore. This allows rspec to live side by side other spec frameworks without always co-opting autotest through autotest's discovery mechanism. My project is running RSpec and Rspec-rails as plugins, but I gave it a shot. Unfortunately, autotest would not even start. A quick inspection of autospec revealed that the call to autotest in this file will not work on Windows, as is. In the Windows environment, autotest is a batch file which must be executed with the "call" command when shelling out from a Ruby script. So, I updated my autospec file to the following: #!/usr/bin/env ruby ENV['RSPEC'] = 'true' autotest_cmd = 'autotest' autotest_cmd = "call #{autotest_cmd}" if RUBY_PLATFORM =~ /mswin/ system autotest_cmd I have submitted a ticket requesting that autospec be updated accordingly. http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/466-update-autospec-to-work-on-windows Thanks, Chuck -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Fri Jul 11 15:20:59 2008 From: lists at ruby-forum.com (Piotr Wlodarek) Date: Fri, 11 Jul 2008 21:20:59 +0200 Subject: [rspec-users] How to stub forever? In-Reply-To: <57c63afe0807110240jbdf6ef5u15564fdc27add626@mail.gmail.com> References: <7696d5c671e45662fc57963ed34013ff@ruby-forum.com> <57c63afe0807110240jbdf6ef5u15564fdc27add626@mail.gmail.com> Message-ID: David Chelimsky wrote: > On 7/11/08, Piotr Wlodarek wrote: >> >> How to stub a method for multiple calls? >> >> The calls are done in a loop. >> >> I expect: >> @agent.stub!( :submit ).multiple_times.and_return( @account_details_page >> ) >> ..to stub submit method "forever" (any number of calls). > > Stubs will do this automatically. Just do this: > > @agent.stub!( :submit ).and_return(@account_details_page) Thanks a lot. In fact, I had a bug in my code which lead me to think stubs don't do that automatically. -- Posted via http://www.ruby-forum.com/. From luislavena at gmail.com Fri Jul 11 15:29:04 2008 From: luislavena at gmail.com (Luis Lavena) Date: Fri, 11 Jul 2008 21:29:04 +0200 Subject: [rspec-users] Getting RSpec 1.1.4+ to Work with Autotest (ZenTest 3.10.0) on Windows (Win32) In-Reply-To: <841120.80434.qm@web54110.mail.re2.yahoo.com> References: <841120.80434.qm@web54110.mail.re2.yahoo.com> Message-ID: <71166b3b0807111229rcf2eb56wb59f648c25c178be@mail.gmail.com> On Fri, Jul 11, 2008 at 8:33 PM, Charles Grindel wrote: > Hi, > > After upgrading to Rails 2.1, RSpec 1.1.4+ and ZenTest 3.10.0, autotest > would no longer find any of my specs on my Windows development machine. > Some Googling directed me to a very recent update in the History.txt file > for rspec-fails: > > IMPORTANT: use 'script/autospec' (or just 'autospec' if you have the rspec > gem > installed) instead of 'autotest'. We changed the way autotest discovers > rspec > so the autotest executable won't automatically load rspec anymore. This > allows > rspec to live side by side other spec frameworks without always co-opting > autotest through autotest's discovery mechanism. > Dunno if this funny, but I'm running right now with the exact same combination of components and autotest picks my updated spec and files (even the ones in lib). > My project is running RSpec and Rspec-rails as plugins, but I gave it a > shot. Unfortunately, autotest would not even start. A quick inspection of > autospec revealed that the call to autotest in this file will not work on > Windows, as is. In the Windows environment, autotest is a batch file which > must be executed with the "call" command when shelling out from a Ruby > script. So, I updated my autospec file to the following: > > #!/usr/bin/env ruby > ENV['RSPEC'] = 'true' > autotest_cmd = 'autotest' > autotest_cmd = "call #{autotest_cmd}" if RUBY_PLATFORM =~ /mswin/ > system autotest_cmd > > I have submitted a ticket requesting that autospec be updated accordingly. > > http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/466-update-autospec-to-work-on-windows > The upcoming version of Ruby (1.8.6 after patchlevel 114) will include a fix for this issue, which I described in this post (less quirks for us section): http://blog.mmediasys.com/2008/04/24/contributions-speedup-and-less-quirks-for-us/ So there is no need to prepend 'call' or ".bat" on Windows anymore (also, you should consider mswin AND mingw as valid platforms ;-) Regards, -- Luis Lavena AREA 17 - Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. Douglas Adams From mark.wilden at gmail.com Fri Jul 11 17:25:16 2008 From: mark.wilden at gmail.com (Mark Wilden) Date: Fri, 11 Jul 2008 14:25:16 -0700 Subject: [rspec-users] Fwd: Getting RSpec 1.1.4+ to Work with Autotest (ZenTest 3.10.0) on Windows (Win32) In-Reply-To: <3c30da400807111315j77624901i422b1b8ed0fe7fd6@mail.gmail.com> References: <841120.80434.qm@web54110.mail.re2.yahoo.com> <71166b3b0807111229rcf2eb56wb59f648c25c178be@mail.gmail.com> <3c30da400807111315j77624901i422b1b8ed0fe7fd6@mail.gmail.com> Message-ID: <3c30da400807111425n3537b0e5gd348ab6a0dfa932@mail.gmail.com> Rspactor is a great alternative to autotest if you're on a Mac. It uses the OS to tell it when files have changed, instead of continually scanning the project tree. That makes it faster and less of a burden on the system. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From luislavena at gmail.com Fri Jul 11 18:03:45 2008 From: luislavena at gmail.com (Luis Lavena) Date: Sat, 12 Jul 2008 00:03:45 +0200 Subject: [rspec-users] Fwd: Getting RSpec 1.1.4+ to Work with Autotest (ZenTest 3.10.0) on Windows (Win32) In-Reply-To: <3c30da400807111425n3537b0e5gd348ab6a0dfa932@mail.gmail.com> References: <841120.80434.qm@web54110.mail.re2.yahoo.com> <71166b3b0807111229rcf2eb56wb59f648c25c178be@mail.gmail.com> <3c30da400807111315j77624901i422b1b8ed0fe7fd6@mail.gmail.com> <3c30da400807111425n3537b0e5gd348ab6a0dfa932@mail.gmail.com> Message-ID: <71166b3b0807111503l2be8ca00m8f09215f251c8bd4@mail.gmail.com> On Fri, Jul 11, 2008 at 11:25 PM, Mark Wilden wrote: > Rspactor is a great alternative to autotest if you're on a Mac. It uses the > OS to tell it when files have changed, instead of continually scanning the > project tree. That makes it faster and less of a burden on the system. > If I'm in a Mac... running Windows on parallels? ;-) I think the same can be achieved under Windows using the File monitoring api.. Anyhow, autotest tend to leak some memory due it's scanning (but you can restart it after 6 hours of continuous monitoring). -- Luis Lavena AREA 17 - Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. Douglas Adams From matt at matt-darby.com Sat Jul 12 10:05:12 2008 From: matt at matt-darby.com (Matt Darby) Date: Sat, 12 Jul 2008 10:05:12 -0400 Subject: [rspec-users] rspec render :update In-Reply-To: <01601b55fe6dd1e35f3d2bf46354a6fe@ruby-forum.com> References: <01601b55fe6dd1e35f3d2bf46354a6fe@ruby-forum.com> Message-ID: <11625ACC-3103-43BD-9B4D-A62A0D8DE494@matt-darby.com> On Jul 11, 2008, at 1:04 PM, Reggie Mr. wrote: > Hi all, > > I'm having trouble with rspec 1.1.4 and rjs > > response.should have_rjs #this should be successful for any rjs > request; but fails > > response.should have_rjs(:replace_html) #no luck > > I have tried mocking the page object, but that also fails. > > e.g > @page = mock('page) > @page.should_receive(:replace_html) > > What's the best practice to validate rjs responses? I use the ARTS plugin to validate RJS. (http://github.com/richpoirier/arts/tree/master ) After you install it, you can do things like: it "should render edit template" do do_get assert_rjs :page, 'error_div', :hide assert_rjs :replace_html, "edit_div" assert_rjs :visual_effect, :scroll_to, 'edit_div' assert_rjs :visual_effect, :highlight, "object_#{@object.id}" end Hope this helps! From ml at e4net.com Sat Jul 12 20:34:22 2008 From: ml at e4net.com (Jim Morris) Date: Sat, 12 Jul 2008 17:34:22 -0700 Subject: [rspec-users] Executing multiple rspec scripts In-Reply-To: References: <4876D0BF.8080401@benmabey.com> Message-ID: <48794D8E.8020202@e4net.com> Another way to do it instead of the Rake method is what I do... I create a suite.rb in the spec folder with this... # suite.rb - run all my tests in this folder and below if __FILE__ == $0 dir = File.dirname(__FILE__) tests= Dir["#{dir}/**/test_*.rb"] # anything named test_*.rb tests.concat Dir["#{dir}/**/*_spec.rb"] # anything named *_spec.rb # add additional tests that don;t follow conventional naming schemes %w(anotherfile, onemorefile).each do |f| tests << File.join(dir, f) + ".rb" end puts "Testing: #{tests.join(', ')}" tests.each do |file| load file, true end end then you can run all your tests via... > ruby suite.rb You could also use require instead of load, but I use nasty globals in my tests and I believe the load doesn't carry over globals. YMMV Robert Stagner wrote: > Actually, I'm a member of the QA team (limited development experience). > So, we are attempting to use RSpec without rails. What is Rake? Near > the end of your response, you list a way of running multiple spec files > by creating a spec task. Since, I'm not a developer, could you please > provide me with a clear example on how to do this? Or, if there is an > alternative method on doing this, please let me know. Thanks again. > > My current setup is: > > 1 spec file that relies on accessing a module of classes to perform > Watir web app testing. I've included a sample of the code below > > describe LoginWelcomeScreen do > describe "using IE Explorer" do > before(:each) do > @login = LoginWelcomeScreen.new(IEWebBrowser.instance) > end > > it "should support a username text field" do > @login.test_username_field.should be_an_instance_of(Watir::TextField) > end > > it "should support a password text field" do > @login.test_password_field.should > be_an_instance_of(Watir::TextField) > end > . > . > . > . > end > > > On Thu, Jul 10, 2008 at 8:17 PM, Ben Mabey > wrote: > > Robert Stagner wrote: > > I'm new to RSpec. I've just installed the gem and begun > experimenting with developing several scripts. From what I've > seen thus far, it looks like it will aid our QA team in testing > many web applications. Is there a way to execute multiple rspec > test scripts from one central file? > > -- > Regards, > Robert > > > Robert, > Welcome to rspec! There are a number of ways you can do this. You can > do it with the command line: > spec spec/*_spec.rb > > The way it is generally done is by using a rake task however... > Are you using rails? If so.. have you run "./script/generate rspec"? > That will install a spec task for you so you just have to type "rake > spec" to run all of your specs. > > If you are in a normal ruby app then you can create your own spec task > by putting this in your Rakefile or tasks dir: > > require 'rubygems' > require 'spec' > require 'spec/rake/spectask' > > desc "Run the specs under spec/models" > Spec::Rake::SpecTask.new do |t| > t.spec_files = FileList['spec/*_spec.rb'] > end > > If you provide more information on what your setup is we could help > more. > > -Ben > http://benmabey.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > -- > Regards, > Robert > > > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- Jim Morris, http://blog.wolfman.com From zach.dennis at gmail.com Sun Jul 13 00:56:03 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sun, 13 Jul 2008 00:56:03 -0400 Subject: [rspec-users] rspec render :update In-Reply-To: <01601b55fe6dd1e35f3d2bf46354a6fe@ruby-forum.com> References: <01601b55fe6dd1e35f3d2bf46354a6fe@ruby-forum.com> Message-ID: <85d99afe0807122156l4fcb502ci13fc97d48b559a50@mail.gmail.com> On Fri, Jul 11, 2008 at 1:04 PM, Reggie Mr. wrote: > Hi all, > > I'm having trouble with rspec 1.1.4 and rjs > > In the controller: > render :update do |page| > page << 'added text' > end > > render :update do |page| > page.replace_html :divid :partial => 'apartial' > end > > spec: > > response.should have_rjs #this should be successful for any rjs > request; but fails > > response.should have_rjs(:replace_html) #no luck > > I have tried mocking the page object, but that also fails. > > e.g > @page = mock('page) > @page.should_receive(:replace_html) > > What's the best practice to validate rjs responses? > I don't like validating generated JavaScript code from framework methods (or well tested third party libraries) against helper methods which just use regular expression matching underneath the covers (like ARTS or the built-in Rails helpers). I like to let the framework and the third party libraries test that their generated JavaScript is correct and I like to make sure my code is just doing the right thing using mocks. The below is a spec that will ensure a "render :update" call inside a controller action works... describe SomeController, '#foo' do it "renders the items entry form" do page = mock("page") controller.expect_render(:update).and_yield(page) page.should_receive(:replace_html).with(:some_id, partial => "items/form") get :show, :id => 1, :expense_reimbursement_id => 2 end end And here's the controller method: def show render :update do |page| page.replace_html :some_id, :partial => "Items/form" end end I like to keep my RJS separate from my controller as much as possible by pushing the code into external RJS files. This helps keep the controller simple and easily understandable. I know sometimes the controller action and the RJS are both so simple that it seems like overkill to separate them. This just becomes a judgment call by the developer. If the controller action or the inline RJS grows it's pretty simple to extract an RJS file after the fact. When an RJS file becomes messy or difficult to understand you can refactor that into using Renderer objects. For more information see "Extract Renderer from RJS" in the Rails Refactoring Catalog: http://assets.en.oreilly.com/1/event/6/Refactoring%20Your%20Rails%20Application%20Paper.pdf -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From restagner at gmail.com Sun Jul 13 01:12:58 2008 From: restagner at gmail.com (Robert Stagner) Date: Sat, 12 Jul 2008 22:12:58 -0700 Subject: [rspec-users] Executing multiple rspec scripts In-Reply-To: <48794D8E.8020202@e4net.com> References: <4876D0BF.8080401@benmabey.com> <48794D8E.8020202@e4net.com> Message-ID: Wow!! That is also very, very helpful. I was able to get rake to work as described in an earlier posting, but not without several hours of tinkering and reading the RSpec and Rake documentation. Your solution is certainly much more direct. Thanks. On Sat, Jul 12, 2008 at 5:34 PM, Jim Morris wrote: > Another way to do it instead of the Rake method is what I do... > > I create a suite.rb in the spec folder with this... > > # suite.rb - run all my tests in this folder and below > if __FILE__ == $0 > dir = File.dirname(__FILE__) > tests= Dir["#{dir}/**/test_*.rb"] # anything named test_*.rb > tests.concat Dir["#{dir}/**/*_spec.rb"] # anything named *_spec.rb > > # add additional tests that don;t follow conventional naming schemes > %w(anotherfile, onemorefile).each do |f| > tests << File.join(dir, f) + ".rb" > end > > puts "Testing: #{tests.join(', ')}" > > tests.each do |file| > load file, true > end > end > > > then you can run all your tests via... > > > ruby suite.rb > > You could also use require instead of load, but I use nasty globals in my > tests and I believe the load doesn't carry over globals. > > YMMV > > > Robert Stagner wrote: > >> Actually, I'm a member of the QA team (limited development experience). >> So, we are attempting to use RSpec without rails. What is Rake? Near the >> end of your response, you list a way of running multiple spec files by >> creating a spec task. Since, I'm not a developer, could you please provide >> me with a clear example on how to do this? Or, if there is an alternative >> method on doing this, please let me know. Thanks again. >> >> My current setup is: >> >> 1 spec file that relies on accessing a module of classes to perform Watir >> web app testing. I've included a sample of the code below >> >> describe LoginWelcomeScreen do >> describe "using IE Explorer" do >> before(:each) do >> @login = LoginWelcomeScreen.new(IEWebBrowser.instance) end >> it "should support a username text field" do >> @login.test_username_field.should be_an_instance_of(Watir::TextField) >> end >> it "should support a password text field" do >> @login.test_password_field.should be_an_instance_of(Watir::TextField) >> end >> . >> . >> . >> . >> end >> >> >> On Thu, Jul 10, 2008 at 8:17 PM, Ben Mabey > ben at benmabey.com>> wrote: >> >> Robert Stagner wrote: >> >> I'm new to RSpec. I've just installed the gem and begun >> experimenting with developing several scripts. From what I've >> seen thus far, it looks like it will aid our QA team in testing >> many web applications. Is there a way to execute multiple rspec >> test scripts from one central file? >> >> -- Regards, >> Robert >> >> >> Robert, >> Welcome to rspec! There are a number of ways you can do this. You can >> do it with the command line: >> spec spec/*_spec.rb >> >> The way it is generally done is by using a rake task however... >> Are you using rails? If so.. have you run "./script/generate rspec"? >> That will install a spec task for you so you just have to type "rake >> spec" to run all of your specs. >> >> If you are in a normal ruby app then you can create your own spec task >> by putting this in your Rakefile or tasks dir: >> >> require 'rubygems' >> require 'spec' >> require 'spec/rake/spectask' >> >> desc "Run the specs under spec/models" >> Spec::Rake::SpecTask.new do |t| >> t.spec_files = FileList['spec/*_spec.rb'] >> end >> >> If you provide more information on what your setup is we could help >> more. >> >> -Ben >> http://benmabey.com >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> >> >> -- >> Regards, >> Robert >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > -- > Jim Morris, http://blog.wolfman.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Regards, Robert -------------- next part -------------- An HTML attachment was scrubbed... URL: From svenfuchs at artweb-design.de Sun Jul 13 09:49:13 2008 From: svenfuchs at artweb-design.de (Sven Fuchs) Date: Sun, 13 Jul 2008 15:49:13 +0200 Subject: [rspec-users] Expecting arbitrary method calls in a particular order Message-ID: <1D1CB477-0BE9-47C7-A4AD-27F4256B60A2@artweb-design.de> I've been wondering how to expect arbitrary methods being called in a particular order. The RSpec documentation for expecting method calls on mock objects mentions that it is possible to pass a block to #should_receive, but does not mention that it can be used to track the method call order pretty easily: http://www.artweb-design.de/2008/7/13/expecting-arbitrary-method-calls-in-a-particular-order-in-rspec Is there a better way of doing this? If not, do you think it would make sense to add this to the RSpec docs? http://rspec.info/documentation/mocks/message_expectations.html -- sven fuchs svenfuchs at artweb-design.de artweb design http://www.artweb-design.de gr?nberger 65 + 49 (0) 30 - 47 98 69 96 (phone) d-10245 berlin + 49 (0) 171 - 35 20 38 4 (mobile) From pergesu at gmail.com Sun Jul 13 10:32:58 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 13 Jul 2008 10:32:58 -0400 Subject: [rspec-users] Expecting arbitrary method calls in a particular order In-Reply-To: <1D1CB477-0BE9-47C7-A4AD-27F4256B60A2@artweb-design.de> References: <1D1CB477-0BE9-47C7-A4AD-27F4256B60A2@artweb-design.de> Message-ID: <810a540e0807130732n608165f3mdc2a60bc1bd990c8@mail.gmail.com> On Sun, Jul 13, 2008 at 9:49 AM, Sven Fuchs wrote: > I've been wondering how to expect arbitrary methods being called in a > particular order. The RSpec documentation for expecting method calls on mock > objects mentions that it is possible to pass a block to #should_receive, but > does not mention that it can be used to track the method call order pretty > easily: > > http://www.artweb-design.de/2008/7/13/expecting-arbitrary-method-calls-in-a-particular-order-in-rspec > > Is there a better way of doing this? > > If not, do you think it would make sense to add this to the RSpec docs? > http://rspec.info/documentation/mocks/message_expectations.html Hey Sven, Mock objects have an optional notion of ordering. Check out the following spec: describe "a mock object" do it "should expect ordered messages" do foo = mock("ordered mock") foo.should_receive(:first).ordered foo.should_receive(:second).ordered foo.should_receive(:third).ordered foo.first foo.second foo.third end end Changing the order in which they're called will raise an ExpectationNotMetError. Pat From dchelimsky at gmail.com Sun Jul 13 10:41:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 13 Jul 2008 09:41:53 -0500 Subject: [rspec-users] Expecting arbitrary method calls in a particular order In-Reply-To: <810a540e0807130732n608165f3mdc2a60bc1bd990c8@mail.gmail.com> References: <1D1CB477-0BE9-47C7-A4AD-27F4256B60A2@artweb-design.de> <810a540e0807130732n608165f3mdc2a60bc1bd990c8@mail.gmail.com> Message-ID: <57c63afe0807130741q73cef843n99ef60eb97fd985c@mail.gmail.com> On Sun, Jul 13, 2008 at 9:32 AM, Pat Maddox wrote: > On Sun, Jul 13, 2008 at 9:49 AM, Sven Fuchs wrote: >> I've been wondering how to expect arbitrary methods being called in a >> particular order. The RSpec documentation for expecting method calls on mock >> objects mentions that it is possible to pass a block to #should_receive, but >> does not mention that it can be used to track the method call order pretty >> easily: >> >> http://www.artweb-design.de/2008/7/13/expecting-arbitrary-method-calls-in-a-particular-order-in-rspec >> >> Is there a better way of doing this? >> >> If not, do you think it would make sense to add this to the RSpec docs? >> http://rspec.info/documentation/mocks/message_expectations.html > > Hey Sven, > > Mock objects have an optional notion of ordering. Check out the following spec: > > describe "a mock object" do > it "should expect ordered messages" do > foo = mock("ordered mock") > foo.should_receive(:first).ordered > foo.should_receive(:second).ordered > foo.should_receive(:third).ordered > > foo.first > foo.second > foo.third > end > end > > Changing the order in which they're called will raise an ExpectationNotMetError. Sven, FYI - this is explained on the page you mentioned: http://rspec.info/documentation/mocks/message_expectations.html Cheers, David > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From svenfuchs at artweb-design.de Sun Jul 13 11:01:40 2008 From: svenfuchs at artweb-design.de (Sven Fuchs) Date: Sun, 13 Jul 2008 17:01:40 +0200 Subject: [rspec-users] Expecting arbitrary method calls in a particular order In-Reply-To: <57c63afe0807130741q73cef843n99ef60eb97fd985c@mail.gmail.com> References: <1D1CB477-0BE9-47C7-A4AD-27F4256B60A2@artweb-design.de> <810a540e0807130732n608165f3mdc2a60bc1bd990c8@mail.gmail.com> <57c63afe0807130741q73cef843n99ef60eb97fd985c@mail.gmail.com> Message-ID: On 13.07.2008, at 16:41, David Chelimsky wrote: > On Sun, Jul 13, 2008 at 9:32 AM, Pat Maddox wrote: >> On Sun, Jul 13, 2008 at 9:49 AM, Sven Fuchs > > wrote: >>> I've been wondering how to expect arbitrary methods being called >>> in a >>> particular order. The RSpec documentation for expecting method >>> calls on mock >>> objects mentions that it is possible to pass a block to >>> #should_receive, but >>> does not mention that it can be used to track the method call >>> order pretty >>> easily: >>> >>> http://www.artweb-design.de/2008/7/13/expecting-arbitrary-method-calls-in-a-particular-order-in-rspec >>> >>> Is there a better way of doing this? >>> >>> If not, do you think it would make sense to add this to the RSpec >>> docs? >>> http://rspec.info/documentation/mocks/message_expectations.html >> >> Hey Sven, >> >> Mock objects have an optional notion of ordering. Check out the >> following spec: >> >> describe "a mock object" do >> it "should expect ordered messages" do >> foo = mock("ordered mock") >> foo.should_receive(:first).ordered >> foo.should_receive(:second).ordered >> foo.should_receive(:third).ordered >> >> foo.first >> foo.second >> foo.third >> end >> end >> >> Changing the order in which they're called will raise an >> ExpectationNotMetError. > > Sven, FYI - this is explained on the page you mentioned: > http://rspec.info/documentation/mocks/message_expectations.html Hey guys, thanks for the quick answers :) Maybe I was not clear enough about what I wanted to spec. Or I actually do not understand what #ordered does. In Pat's spec above the methods #first, #second and #third are called on the same object foo and the spec defines the order. That's kind of the opposite of my usecase. I wanted to specify that the a method #run (or whatever) is called on *different* objects in a particular order. Like: filter_1 = mock('filter_1') filter_2 = mock('filter_2') filter_chain << filter_1 filter_chain << filter_2 Now, when the filter_chain is run I want to expect that the filters are run in the order they were added to the chain: filter_chain.run methods_called_on_individual_filters.should == ['filter_1#run', 'filter_2#run'] # pseudo-code If that's possible somehow with should_receive(:run).ordered than at least it's not very clear from that docs page which only talks about expecting the order of methods being called on the same mock, not on different mocks. ("There are times when you want to specify the order of messages sent to *a* mock") Am I missing something? -- sven fuchs svenfuchs at artweb-design.de artweb design http://www.artweb-design.de gr?nberger 65 + 49 (0) 30 - 47 98 69 96 (phone) d-10245 berlin + 49 (0) 171 - 35 20 38 4 (mobile) From svenfuchs at artweb-design.de Sun Jul 13 11:35:58 2008 From: svenfuchs at artweb-design.de (Sven Fuchs) Date: Sun, 13 Jul 2008 17:35:58 +0200 Subject: [rspec-users] Expecting arbitrary method calls in a particular order In-Reply-To: References: <1D1CB477-0BE9-47C7-A4AD-27F4256B60A2@artweb-design.de> <810a540e0807130732n608165f3mdc2a60bc1bd990c8@mail.gmail.com> <57c63afe0807130741q73cef843n99ef60eb97fd985c@mail.gmail.com> Message-ID: <0334BE49-8DBC-4CF2-B55A-63E8CB6EA55D@artweb-design.de> On 13.07.2008, at 17:01, Sven Fuchs wrote: > > On 13.07.2008, at 16:41, David Chelimsky wrote: > >> On Sun, Jul 13, 2008 at 9:32 AM, Pat Maddox >> wrote: >>> On Sun, Jul 13, 2008 at 9:49 AM, Sven Fuchs >> > wrote: >>>> I've been wondering how to expect arbitrary methods being called >>>> in a >>>> particular order. The RSpec documentation for expecting method >>>> calls on mock >>>> objects mentions that it is possible to pass a block to >>>> #should_receive, but >>>> does not mention that it can be used to track the method call >>>> order pretty >>>> easily: >>>> >>>> http://www.artweb-design.de/2008/7/13/expecting-arbitrary-method-calls-in-a-particular-order-in-rspec >>>> >>>> Is there a better way of doing this? >>>> >>>> If not, do you think it would make sense to add this to the RSpec >>>> docs? >>>> http://rspec.info/documentation/mocks/message_expectations.html >>> >>> Hey Sven, >>> >>> Mock objects have an optional notion of ordering. Check out the >>> following spec: >>> >>> describe "a mock object" do >>> it "should expect ordered messages" do >>> foo = mock("ordered mock") >>> foo.should_receive(:first).ordered >>> foo.should_receive(:second).ordered >>> foo.should_receive(:third).ordered >>> >>> foo.first >>> foo.second >>> foo.third >>> end >>> end >>> >>> Changing the order in which they're called will raise an >>> ExpectationNotMetError. >> >> Sven, FYI - this is explained on the page you mentioned: >> http://rspec.info/documentation/mocks/message_expectations.html > > Hey guys, thanks for the quick answers :) > > Maybe I was not clear enough about what I wanted to spec. Or I > actually do not understand what #ordered does. > > In Pat's spec above the methods #first, #second and #third are > called on the same object foo and the spec defines the order. That's > kind of the opposite of my usecase. I wanted to specify that the a > method #run (or whatever) is called on *different* objects in a > particular order. Like: > > filter_1 = mock('filter_1') > filter_2 = mock('filter_2') > filter_chain << filter_1 > filter_chain << filter_2 > > Now, when the filter_chain is run I want to expect that the filters > are run in the order they were added to the chain: > > filter_chain.run > methods_called_on_individual_filters.should == ['filter_1#run', > 'filter_2#run'] # pseudo-code > > If that's possible somehow with should_receive(:run).ordered than at > least it's not very clear from that docs page which only talks about > expecting the order of methods being called on the same mock, not on > different mocks. ("There are times when you want to specify the > order of messages sent to *a* mock") > > Am I missing something? Maybe it's bit more clear this way: class Chain < Array def run each{|object| object.run} end end describe "Expecting the order of methods being called on arbitrary objects" do it "works" do first = mock('first') second = mock('second') chain = Chain.new chain << first chain << second second.should_receive(:run).ordered first.should_receive(:run).ordered chain.run end end This passes, of course. I'd want to to specify that first#run is run first and second#run is run second though and I think I can't do that with should_receive.ordered -- sven fuchs svenfuchs at artweb-design.de artweb design http://www.artweb-design.de gr?nberger 65 + 49 (0) 30 - 47 98 69 96 (phone) d-10245 berlin + 49 (0) 171 - 35 20 38 4 (mobile) From ashley.moran at patchspace.co.uk Sun Jul 13 11:44:42 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 13 Jul 2008 16:44:42 +0100 Subject: [rspec-users] Expecting arbitrary method calls in a particular order In-Reply-To: <0334BE49-8DBC-4CF2-B55A-63E8CB6EA55D@artweb-design.de> References: <1D1CB477-0BE9-47C7-A4AD-27F4256B60A2@artweb-design.de> <810a540e0807130732n608165f3mdc2a60bc1bd990c8@mail.gmail.com> <57c63afe0807130741q73cef843n99ef60eb97fd985c@mail.gmail.com> <0334BE49-8DBC-4CF2-B55A-63E8CB6EA55D@artweb-design.de> Message-ID: On Jul 13, 2008, at 4:35 pm, Sven Fuchs wrote: > describe "Expecting the order of methods being called on arbitrary > objects" do > it "works" do > first = mock('first') > second = mock('second') > > chain = Chain.new > chain << first > chain << second > > second.should_receive(:run).ordered > first.should_receive(:run).ordered > chain.run > end > end Hi Sven I think you want second.should_receive(:run) do first.should_receive(:run) end which, if Mail.app is running my specs correctly, should only pass if second receives :run before first Is that what you were after? Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From zach.dennis at gmail.com Sun Jul 13 11:59:02 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sun, 13 Jul 2008 11:59:02 -0400 Subject: [rspec-users] Expecting arbitrary method calls in a particular order In-Reply-To: <0334BE49-8DBC-4CF2-B55A-63E8CB6EA55D@artweb-design.de> References: <1D1CB477-0BE9-47C7-A4AD-27F4256B60A2@artweb-design.de> <810a540e0807130732n608165f3mdc2a60bc1bd990c8@mail.gmail.com> <57c63afe0807130741q73cef843n99ef60eb97fd985c@mail.gmail.com> <0334BE49-8DBC-4CF2-B55A-63E8CB6EA55D@artweb-design.de> Message-ID: <85d99afe0807130859k610262a3v56f9c7e55427196c@mail.gmail.com> You want cross mock ordering! I've wanted this in RSpec in the past as well. The only ruby-based mocking library I know of that does this is Hardmock. It looks like its RDoc now has instructions for it to work with RSpec: http://hardmock.rubyforge.org/ Zach On Sun, Jul 13, 2008 at 11:35 AM, Sven Fuchs wrote: > On 13.07.2008, at 17:01, Sven Fuchs wrote: > >> >> On 13.07.2008, at 16:41, David Chelimsky wrote: >> >> On Sun, Jul 13, 2008 at 9:32 AM, Pat Maddox wrote: >>> >>>> On Sun, Jul 13, 2008 at 9:49 AM, Sven Fuchs >>>> wrote: >>>> >>>>> I've been wondering how to expect arbitrary methods being called in a >>>>> particular order. The RSpec documentation for expecting method calls on >>>>> mock >>>>> objects mentions that it is possible to pass a block to >>>>> #should_receive, but >>>>> does not mention that it can be used to track the method call order >>>>> pretty >>>>> easily: >>>>> >>>>> >>>>> http://www.artweb-design.de/2008/7/13/expecting-arbitrary-method-calls-in-a-particular-order-in-rspec >>>>> >>>>> Is there a better way of doing this? >>>>> >>>>> If not, do you think it would make sense to add this to the RSpec docs? >>>>> http://rspec.info/documentation/mocks/message_expectations.html >>>>> >>>> >>>> Hey Sven, >>>> >>>> Mock objects have an optional notion of ordering. Check out the >>>> following spec: >>>> >>>> describe "a mock object" do >>>> it "should expect ordered messages" do >>>> foo = mock("ordered mock") >>>> foo.should_receive(:first).ordered >>>> foo.should_receive(:second).ordered >>>> foo.should_receive(:third).ordered >>>> >>>> foo.first >>>> foo.second >>>> foo.third >>>> end >>>> end >>>> >>>> Changing the order in which they're called will raise an >>>> ExpectationNotMetError. >>>> >>> >>> Sven, FYI - this is explained on the page you mentioned: >>> http://rspec.info/documentation/mocks/message_expectations.html >>> >> >> Hey guys, thanks for the quick answers :) >> >> Maybe I was not clear enough about what I wanted to spec. Or I actually do >> not understand what #ordered does. >> >> In Pat's spec above the methods #first, #second and #third are called on >> the same object foo and the spec defines the order. That's kind of the >> opposite of my usecase. I wanted to specify that the a method #run (or >> whatever) is called on *different* objects in a particular order. Like: >> >> filter_1 = mock('filter_1') >> filter_2 = mock('filter_2') >> filter_chain << filter_1 >> filter_chain << filter_2 >> >> Now, when the filter_chain is run I want to expect that the filters are >> run in the order they were added to the chain: >> >> filter_chain.run >> methods_called_on_individual_filters.should == ['filter_1#run', >> 'filter_2#run'] # pseudo-code >> >> If that's possible somehow with should_receive(:run).ordered than at least >> it's not very clear from that docs page which only talks about expecting the >> order of methods being called on the same mock, not on different mocks. >> ("There are times when you want to specify the order of messages sent to *a* >> mock") >> >> Am I missing something? >> > > Maybe it's bit more clear this way: > > class Chain < Array > def run > each{|object| object.run} > end > end > > describe "Expecting the order of methods being called on arbitrary objects" > do > it "works" do > first = mock('first') > second = mock('second') > > chain = Chain.new > chain << first > chain << second > > second.should_receive(:run).ordered > first.should_receive(:run).ordered > chain.run > end > end > > This passes, of course. > > I'd want to to specify that first#run is run first and second#run is run > second though and I think I can't do that with should_receive.ordered > > > > -- > sven fuchs svenfuchs at artweb-design.de > artweb design http://www.artweb-design.de > gr?nberger 65 + 49 (0) 30 - 47 98 69 96 (phone) > d-10245 berlin + 49 (0) 171 - 35 20 38 4 (mobile) > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From svenfuchs at artweb-design.de Sun Jul 13 12:03:07 2008 From: svenfuchs at artweb-design.de (Sven Fuchs) Date: Sun, 13 Jul 2008 18:03:07 +0200 Subject: [rspec-users] Expecting arbitrary method calls in a particular order In-Reply-To: References: <1D1CB477-0BE9-47C7-A4AD-27F4256B60A2@artweb-design.de> <810a540e0807130732n608165f3mdc2a60bc1bd990c8@mail.gmail.com> <57c63afe0807130741q73cef843n99ef60eb97fd985c@mail.gmail.com> <0334BE49-8DBC-4CF2-B55A-63E8CB6EA55D@artweb-design.de> Message-ID: <872C355D-7E74-4C60-AFA1-142CB6D130D8@artweb-design.de> Hey Ashley! How's things? :) On 13.07.2008, at 17:44, Ashley Moran wrote: > I think you want > > second.should_receive(:run) do > first.should_receive(:run) > end > > which, if Mail.app is running my specs correctly, should only pass > if second receives :run before first > > Is that what you were after? Wow, yes. This also uses the block passed to should_receive, but in a nicer way than my inital attemp which is a bit chatty. It'd look a bit odd when I want to specify the order for a bunch of methods, but actually I don't need to do that here. Again, this really should be documented. I even started digging into the RSpec source, but obviously lacked the creativity for this :) -- sven fuchs svenfuchs at artweb-design.de artweb design http://www.artweb-design.de gr?nberger 65 + 49 (0) 30 - 47 98 69 96 (phone) d-10245 berlin + 49 (0) 171 - 35 20 38 4 (mobile) From svenfuchs at artweb-design.de Sun Jul 13 12:04:38 2008 From: svenfuchs at artweb-design.de (Sven Fuchs) Date: Sun, 13 Jul 2008 18:04:38 +0200 Subject: [rspec-users] Expecting arbitrary method calls in a particular order In-Reply-To: <85d99afe0807130859k610262a3v56f9c7e55427196c@mail.gmail.com> References: <1D1CB477-0BE9-47C7-A4AD-27F4256B60A2@artweb-design.de> <810a540e0807130732n608165f3mdc2a60bc1bd990c8@mail.gmail.com> <57c63afe0807130741q73cef843n99ef60eb97fd985c@mail.gmail.com> <0334BE49-8DBC-4CF2-B55A-63E8CB6EA55D@artweb-design.de> <85d99afe0807130859k610262a3v56f9c7e55427196c@mail.gmail.com> Message-ID: <988B9060-3042-49F9-8273-BF5DDAF64CFE@artweb-design.de> Hi Zach, On 13.07.2008, at 17:59, Zach Dennis wrote: > You want cross mock ordering! I've wanted this in RSpec in the past > as well. The only ruby-based mocking library I know of that does > this is Hardmock. It looks like its RDoc now has instructions for it > to work with RSpec: > > http://hardmock.rubyforge.org/ Thanks for the suggestion! To be honest, I'm not eager to add another library. Ashley's approach seems to work fine and I only need it in a couple of specs. > > > Zach > > On Sun, Jul 13, 2008 at 11:35 AM, Sven Fuchs > wrote: > On 13.07.2008, at 17:01, Sven Fuchs wrote: > > On 13.07.2008, at 16:41, David Chelimsky wrote: > > On Sun, Jul 13, 2008 at 9:32 AM, Pat Maddox wrote: > On Sun, Jul 13, 2008 at 9:49 AM, Sven Fuchs > wrote: > I've been wondering how to expect arbitrary methods being called in a > particular order. The RSpec documentation for expecting method calls > on mock > objects mentions that it is possible to pass a block to > #should_receive, but > does not mention that it can be used to track the method call order > pretty > easily: > > http://www.artweb-design.de/2008/7/13/expecting-arbitrary-method-calls-in-a-particular-order-in-rspec > > Is there a better way of doing this? > > If not, do you think it would make sense to add this to the RSpec > docs? > http://rspec.info/documentation/mocks/message_expectations.html > > Hey Sven, > > Mock objects have an optional notion of ordering. Check out the > following spec: > > describe "a mock object" do > it "should expect ordered messages" do > foo = mock("ordered mock") > foo.should_receive(:first).ordered > foo.should_receive(:second).ordered > foo.should_receive(:third).ordered > > foo.first > foo.second > foo.third > end > end > > Changing the order in which they're called will raise an > ExpectationNotMetError. > > Sven, FYI - this is explained on the page you mentioned: > http://rspec.info/documentation/mocks/message_expectations.html > > Hey guys, thanks for the quick answers :) > > Maybe I was not clear enough about what I wanted to spec. Or I > actually do not understand what #ordered does. > > In Pat's spec above the methods #first, #second and #third are > called on the same object foo and the spec defines the order. That's > kind of the opposite of my usecase. I wanted to specify that the a > method #run (or whatever) is called on *different* objects in a > particular order. Like: > > filter_1 = mock('filter_1') > filter_2 = mock('filter_2') > filter_chain << filter_1 > filter_chain << filter_2 > > Now, when the filter_chain is run I want to expect that the filters > are run in the order they were added to the chain: > > filter_chain.run > methods_called_on_individual_filters.should == ['filter_1#run', > 'filter_2#run'] # pseudo-code > > If that's possible somehow with should_receive(:run).ordered than at > least it's not very clear from that docs page which only talks about > expecting the order of methods being called on the same mock, not on > different mocks. ("There are times when you want to specify the > order of messages sent to *a* mock") > > Am I missing something? > > Maybe it's bit more clear this way: > > class Chain < Array > def run > each{|object| object.run} > end > end > > describe "Expecting the order of methods being called on arbitrary > objects" do > it "works" do > first = mock('first') > second = mock('second') > > chain = Chain.new > chain << first > chain << second > > second.should_receive(:run).ordered > first.should_receive(:run).ordered > chain.run > end > end > > This passes, of course. > > I'd want to to specify that first#run is run first and second#run is > run second though and I think I can't do that with > should_receive.ordered > > > > -- > sven fuchs svenfuchs at artweb-design.de > artweb design http://www.artweb-design.de > gr?nberger 65 + 49 (0) 30 - 47 98 69 96 (phone) > d-10245 berlin + 49 (0) 171 - 35 20 38 4 (mobile) > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > Zach Dennis > http://www.continuousthinking.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- sven fuchs svenfuchs at artweb-design.de artweb design http://www.artweb-design.de gr?nberger 65 + 49 (0) 30 - 47 98 69 96 (phone) d-10245 berlin + 49 (0) 171 - 35 20 38 4 (mobile) From ashley.moran at patchspace.co.uk Sun Jul 13 13:17:18 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 13 Jul 2008 18:17:18 +0100 Subject: [rspec-users] Expecting arbitrary method calls in a particular order In-Reply-To: <872C355D-7E74-4C60-AFA1-142CB6D130D8@artweb-design.de> References: <1D1CB477-0BE9-47C7-A4AD-27F4256B60A2@artweb-design.de> <810a540e0807130732n608165f3mdc2a60bc1bd990c8@mail.gmail.com> <57c63afe0807130741q73cef843n99ef60eb97fd985c@mail.gmail.com> <0334BE49-8DBC-4CF2-B55A-63E8CB6EA55D@artweb-design.de> <872C355D-7E74-4C60-AFA1-142CB6D130D8@artweb-design.de> Message-ID: On Jul 13, 2008, at 5:03 pm, Sven Fuchs wrote: > Hey Ashley! > > How's things? :) Good thanks, just sadly not spent much time using RSpec lately... Spam me off list if you want to catch up! > Wow, yes. > > This also uses the block passed to should_receive, but in a nicer > way than my inital attemp which is a bit chatty. > > It'd look a bit odd when I want to specify the order for a bunch of > methods, but actually I don't need to do that here. > > Again, this really should be documented. I even started digging into > the RSpec source, but obviously lacked the creativity for this :) I remember posting about this a long time ago. I think it was Aslak that replied. I'd prefer a neater syntax for ordered expectations across mocks. Not too long ago I was working on my database migration tool that has to turn a graph of migrations into a linear sequence before it can apply them, and obviously the order is essential. But the specs look something like... migration_1.should_receive(:apply) do migration_2.should_receive(:apply) do migration_3.should_receive(:apply) do migration_4.should_receive(:apply) do ... which is a bit hideous. I'd prefer something like migration_1.should_receive(:apply) migration_2.should_receive(:apply).after(migration_2.receives(:apply)) ... but I guess that would complicate the implementation. As it's a relatively uncommon thing I think probably just documenting it is ok for now. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From cgrindel at yahoo.com Sun Jul 13 17:50:55 2008 From: cgrindel at yahoo.com (Charles Grindel) Date: Sun, 13 Jul 2008 14:50:55 -0700 (PDT) Subject: [rspec-users] Getting RSpec 1.1.4+ to Work with Autotest (ZenTest 3.10.0) on Windows (Win32) Message-ID: <506754.80820.qm@web54101.mail.re2.yahoo.com> Hi, Thanks for the info, Luis. I am glad that they fixed the calling a batch file issue. I have had to handle this myself in several different situations. I do have one additional question. It sounds like your setup is very similar to ours. Is your project new or did you upgrade? Do you run autospec or autotest from the command line? It seems like running autotest directly should still work given the history comment, but I could not get things to fly until I started using autospec. Just curious. Thanks, Chuck ----- Original Message ---- From: Luis Lavena To: rspec-users Cc: RSpec Developers Mailing List Sent: Friday, July 11, 2008 3:29:04 PM Subject: Re: [rspec-users] Getting RSpec 1.1.4+ to Work with Autotest (ZenTest 3.10.0) on Windows (Win32) On Fri, Jul 11, 2008 at 8:33 PM, Charles Grindel wrote: > Hi, > > After upgrading to Rails 2.1, RSpec 1.1.4+ and ZenTest 3.10.0, autotest > would no longer find any of my specs on my Windows development machine. > Some Googling directed me to a very recent update in the History.txt file > for rspec-fails: > > IMPORTANT: use 'script/autospec' (or just 'autospec' if you have the rspec > gem > installed) instead of 'autotest'. We changed the way autotest discovers > rspec > so the autotest executable won't automatically load rspec anymore. This > allows > rspec to live side by side other spec frameworks without always co-opting > autotest through autotest's discovery mechanism. > Dunno if this funny, but I'm running right now with the exact same combination of components and autotest picks my updated spec and files (even the ones in lib). > My project is running RSpec and Rspec-rails as plugins, but I gave it a > shot. Unfortunately, autotest would not even start. A quick inspection of > autospec revealed that the call to autotest in this file will not work on > Windows, as is. In the Windows environment, autotest is a batch file which > must be executed with the "call" command when shelling out from a Ruby > script. So, I updated my autospec file to the following: > > #!/usr/bin/env ruby > ENV['RSPEC'] = 'true' > autotest_cmd = 'autotest' > autotest_cmd = "call #{autotest_cmd}" if RUBY_PLATFORM =~ /mswin/ > system autotest_cmd > > I have submitted a ticket requesting that autospec be updated accordingly. > > http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/466-update-autospec-to-work-on-windows > The upcoming version of Ruby (1.8.6 after patchlevel 114) will include a fix for this issue, which I described in this post (less quirks for us section): http://blog.mmediasys.com/2008/04/24/contributions-speedup-and-less-quirks-for-us/ So there is no need to prepend 'call' or ".bat" on Windows anymore (also, you should consider mswin AND mingw as valid platforms ;-) Regards, -- Luis Lavena AREA 17 - Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. Douglas Adams _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sun Jul 13 18:11:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 13 Jul 2008 17:11:53 -0500 Subject: [rspec-users] Getting RSpec 1.1.4+ to Work with Autotest (ZenTest 3.10.0) on Windows (Win32) In-Reply-To: <506754.80820.qm@web54101.mail.re2.yahoo.com> References: <506754.80820.qm@web54101.mail.re2.yahoo.com> Message-ID: <57c63afe0807131511w41e36b30oa396fb6626c71098@mail.gmail.com> On Sun, Jul 13, 2008 at 4:50 PM, Charles Grindel wrote: > Hi, > > Thanks for the info, Luis. I am glad that they fixed the calling a batch > file issue. I have had to handle this myself in several different > situations. > > I do have one additional question. It sounds like your setup is very > similar to ours. Is your project new or did you upgrade? Do you run > autospec or autotest from the command line? It seems like running autotest > directly should still work given the history comment, but I could not get > things to fly until I started using autospec. Just curious. When we introduced autospec, we also changed the way rspec identifies itself to autotest such that an ENV var must be present (which is set by autospec) - so no, the autotest command won't work. > > Thanks, > Chuck > > ----- Original Message ---- > From: Luis Lavena > To: rspec-users > Cc: RSpec Developers Mailing List > Sent: Friday, July 11, 2008 3:29:04 PM > Subject: Re: [rspec-users] Getting RSpec 1.1.4+ to Work with Autotest > (ZenTest 3.10.0) on Windows (Win32) > > On Fri, Jul 11, 2008 at 8:33 PM, Charles Grindel wrote: >> Hi, >> >> After upgrading to Rails 2.1, RSpec 1.1.4+ and ZenTest 3.10.0, autotest >> would no longer find any of my specs on my Windows development machine. >> Some Googling directed me to a very recent update in the History.txt file >> for rspec-fails: >> >> IMPORTANT: use 'script/autospec' (or just 'autospec' if you have the rspec >> gem >> installed) instead of 'autotest'. We changed the way autotest discovers >> rspec >> so the autotest executable won't automatically load rspec anymore. This >> allows >> rspec to live side by side other spec frameworks without always co-opting >> autotest through autotest's discovery mechanism. >> > > Dunno if this funny, but I'm running right now with the exact same > combination of components and autotest picks my updated spec and files > (even the ones in lib). > >> My project is running RSpec and Rspec-rails as plugins, but I gave it a >> shot. Unfortunately, autotest would not even start. A quick inspection >> of >> autospec revealed that the call to autotest in this file will not work on >> Windows, as is. In the Windows environment, autotest is a batch file >> which >> must be executed with the "call" command when shelling out from a Ruby >> script. So, I updated my autospec file to the following: >> >> #!/usr/bin/env ruby >> ENV['RSPEC'] = 'true' >> autotest_cmd = 'autotest' >> autotest_cmd = "call #{autotest_cmd}" if RUBY_PLATFORM =~ /mswin/ >> system autotest_cmd >> >> I have submitted a ticket requesting that autospec be updated accordingly. >> >> >> http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/466-update-autospec-to-work-on-windows >> > > The upcoming version of Ruby (1.8.6 after patchlevel 114) will include > a fix for this issue, which I described in this post (less quirks for > us section): > > http://blog.mmediasys.com/2008/04/24/contributions-speedup-and-less-quirks-for-us/ > > So there is no need to prepend 'call' or ".bat" on Windows anymore > (also, you should consider mswin AND mingw as valid platforms ;-) > > Regards, > -- > Luis Lavena > AREA 17 > - > Human beings, who are almost unique in having the ability to learn from > the experience of others, are also remarkable for their apparent > disinclination to do so. > Douglas Adams > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sean.schofield at gmail.com Mon Jul 14 09:13:57 2008 From: sean.schofield at gmail.com (Sean Schofield) Date: Mon, 14 Jul 2008 09:13:57 -0400 Subject: [rspec-users] Need help testing a module behavior with RSpec Message-ID: <2387fbc50807140613w2f105e4rc861ca484558583@mail.gmail.com> I have a resource_security.rb file that includes instance and class method definitions. At the end of the file I mix these into ActiveRecord::Base. ActiveRecord::Base.class_eval { include ResourceSecurity::InstanceMethods } ActiveRecord::Base.class_eval { extend ResourceSecurity::ClassMethods } I've had limited success testing using the following approach @resource = mock("ActiveRecord::Base") @resource.class.class_eval { extend ResourceSecurity::ClassMethods } @resource.class.class_eval { include ResourceSecurity::InstanceMethods } The problem is that I want to test the behavior of a security related instance method using different assumptions about the value of access_hash (a class method). Any suggestions on how to best test this? Its also possible that my actual code solution is less then ideal. The basic concept is that you can have statements like this in your model: allow :show, %w{admin team_lead} Each model is in charge of evaluating whether or not the current user has access (which is why I was thinking in terms of a class level access hash.) Anyways, any suggestions on how to test this would be greatly appreciated. TIA, Sean From address4spams at 21croissants.com Mon Jul 14 12:39:02 2008 From: address4spams at 21croissants.com (21croissants) Date: Mon, 14 Jul 2008 09:39:02 -0700 (PDT) Subject: [rspec-users] How to use more than ONE mock frmk (mocha, rr, rspec) Message-ID: <18447770.post@talk.nabble.com> I have started to play with http://pivots.pivotallabs.com/users/brian/blog/articles/352-introducing-rr and I really like its hyper-minimalist but readable syntax ... For the sake of flexibility, I'd like to use more than 1 mock framework. E.g.: The specs which come with the restful-authentication plugin are using 'RSpec' mock framework and my project is ussing 'rr' I thought I could put at the beginning of each file: Spec::Runner.configure do |config| config.mock_with :rr end or Spec::Runner.configure do |config| config.mock_with :rspec end Running each spec individually works but running them ALL within Autotest or "rake spec" will fail ... I am using Rails 2.1 + RSpec edge. I thought maybe someone has the same needs and found a solution. Otherwise, I'll patch Rspec -- View this message in context: http://www.nabble.com/How-to-use-more-than-ONE-mock-frmk-%28mocha%2C-rr%2C-rspec%29-tp18447770p18447770.html Sent from the rspec-users mailing list archive at Nabble.com. From tafkamk at gmail.com Mon Jul 14 17:44:07 2008 From: tafkamk at gmail.com (tafkamk) Date: Mon, 14 Jul 2008 14:44:07 -0700 (PDT) Subject: [rspec-users] Rspec - stubbing same class multiple times with different conditions Message-ID: <18446600.post@talk.nabble.com> Im having a hard time with a rspec controller test im writting, I need to stub! the User.find call twice once to return the owning user and once to return the viewing user. however when I attempt User.stub!(:find).with(1).and_return(@user) User.stub!(:find).with(2).and_return(@user2) the second call returns undefined local variable or method `find' for # I've managed to replicate the behavior outside of this specific test and I know the code works as I can test it manually. Any ideas as to why this is not working? or better still how to get it working. Thanks for the help in advance -- View this message in context: http://www.nabble.com/Rspec---stubbing-same-class-multiple-times-with-different-conditions-tp18446600p18446600.html Sent from the rspec-users mailing list archive at Nabble.com. From lists at ruby-forum.com Tue Jul 15 04:00:00 2008 From: lists at ruby-forum.com (Piotr Wlodarek) Date: Tue, 15 Jul 2008 10:00:00 +0200 Subject: [rspec-users] should_receive - how to allow multiple calls Message-ID: code: info( 'attempting to sign in' ) # I want to test it # ... info( 'signed in' ) # I don't care about it spec: @scraper.should_receive( :info ).with( 'attempting to sign in' ).at_least( 1 ).times result: expected :info with ("attempting to sign in") but received it with ("signed in") question: This is strange. How to test if method was called with specific argument AND don't care about other possible calls of that method? -- Posted via http://www.ruby-forum.com/. From luislavena at gmail.com Tue Jul 15 04:16:34 2008 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 15 Jul 2008 10:16:34 +0200 Subject: [rspec-users] Getting RSpec 1.1.4+ to Work with Autotest (ZenTest 3.10.0) on Windows (Win32) In-Reply-To: <57c63afe0807131511w41e36b30oa396fb6626c71098@mail.gmail.com> References: <506754.80820.qm@web54101.mail.re2.yahoo.com> <57c63afe0807131511w41e36b30oa396fb6626c71098@mail.gmail.com> Message-ID: <71166b3b0807150116j287458fydc221ba6850946c3@mail.gmail.com> On Mon, Jul 14, 2008 at 12:11 AM, David Chelimsky wrote: > On Sun, Jul 13, 2008 at 4:50 PM, Charles Grindel wrote: >> Hi, >> >> Thanks for the info, Luis. I am glad that they fixed the calling a batch >> file issue. I have had to handle this myself in several different >> situations. >> >> I do have one additional question. It sounds like your setup is very >> similar to ours. Is your project new or did you upgrade? Do you run >> autospec or autotest from the command line? It seems like running autotest >> directly should still work given the history comment, but I could not get >> things to fly until I started using autospec. Just curious. > > When we introduced autospec, we also changed the way rspec identifies > itself to autotest such that an ENV var must be present (which is set > by autospec) - so no, the autotest command won't work. > Hmn, really? rspec, commit 5bb989c6a54e325198e180ef3d4e59b5bf6eb21c rspec-rails: commit 9a1e10e7b71f7e8e4fb910a9695ee69abec63816 http://pastie.org/private/gwgvkbhpbvhvtquslwe6g But in any case, if you say that I should use script/autospec, then I should :-) -- Luis Lavena AREA 17 - Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. Douglas Adams From lists at ruby-forum.com Tue Jul 15 05:17:23 2008 From: lists at ruby-forum.com (Piotr Wlodarek) Date: Tue, 15 Jul 2008 11:17:23 +0200 Subject: [rspec-users] How to write specification for the *base* class API? Message-ID: <3f2c7903c5ecdfb1ec7b8f9a68183eb1@ruby-forum.com> For the base class, it seems reasonable to specify public API with RSpec. However, since we deal with a base class, methods are often empty (put there just to show the API). The spec cannot be run against the base class. In consequence, the spec must be duplicated in every derived class, which seems to be far from DRY. How to deal with it? What is THE RSpec way to specify APIs when we face inheritance? -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Jul 15 05:59:55 2008 From: lists at ruby-forum.com (Piotr Wlodarek) Date: Tue, 15 Jul 2008 11:59:55 +0200 Subject: [rspec-users] Specyfing behaviour VS specifying implementation Message-ID: <34a677f4388dd1cfb6e952edfe150ff3@ruby-forum.com> At first it seems obvious: one should specify behaviour, not implementation. However, there may be a tremendous overhead and duplication with such approach. Let's assume: def a # lot's of business logic end deb b # lot's of business logic end def main a b end Assuming we do have specs for methods a and b, how the main method should be specified? 1) Full behaviour specification Problem: it duplicates specification of a and b 2) Specify that main should call a, then b Problem: it specifies implementation, NOT behaviour So, what is the right way? -- Posted via http://www.ruby-forum.com/. From j at jonathanleighton.com Tue Jul 15 06:10:46 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Tue, 15 Jul 2008 11:10:46 +0100 Subject: [rspec-users] Profiling specs Message-ID: <1216116646.7161.12.camel@tybalt> Hi, Is there any simple, easy way to profile the running of my specs? It has recently starting being way slower and I want to know why :) Cheers, Jon From lists at ruby-forum.com Tue Jul 15 07:40:18 2008 From: lists at ruby-forum.com (Piotr Wlodarek) Date: Tue, 15 Jul 2008 13:40:18 +0200 Subject: [rspec-users] Profiling specs In-Reply-To: <1216116646.7161.12.camel@tybalt> References: <1216116646.7161.12.camel@tybalt> Message-ID: Jonathan Leighton wrote: > Is there any simple, easy way to profile the running of my specs? It has > recently starting being way slower and I want to know why :) spec --format profile -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Tue Jul 15 07:58:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 15 Jul 2008 06:58:21 -0500 Subject: [rspec-users] should_receive - how to allow multiple calls In-Reply-To: References: Message-ID: <57c63afe0807150458v17f43babg16b5434f7252d758@mail.gmail.com> On Tue, Jul 15, 2008 at 3:00 AM, Piotr Wlodarek wrote: > code: > > info( 'attempting to sign in' ) # I want to test it > # ... > info( 'signed in' ) # I don't care about it > > > spec: > > @scraper.should_receive( :info ).with( 'attempting to sign in' > ).at_least( 1 ).times > > > result: > expected :info with ("attempting to sign in") but received it with > ("signed in") > > > question: > This is strange. This is normal :) It's how most mock frameworks work because most of the time we want to know if unexpected calls start showing up. > How to test if method was called with specific argument > AND don't care about other possible calls of that method? @scraper.stub!(:info) @scraper.should_receive(:info).with("attempting to sign in") Cheers, David > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Jul 15 08:03:51 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 15 Jul 2008 07:03:51 -0500 Subject: [rspec-users] Getting RSpec 1.1.4+ to Work with Autotest (ZenTest 3.10.0) on Windows (Win32) In-Reply-To: <71166b3b0807150116j287458fydc221ba6850946c3@mail.gmail.com> References: <506754.80820.qm@web54101.mail.re2.yahoo.com> <57c63afe0807131511w41e36b30oa396fb6626c71098@mail.gmail.com> <71166b3b0807150116j287458fydc221ba6850946c3@mail.gmail.com> Message-ID: <57c63afe0807150503n3e4a5328kc2bb80e258d4bb77@mail.gmail.com> On Tue, Jul 15, 2008 at 3:16 AM, Luis Lavena wrote: > On Mon, Jul 14, 2008 at 12:11 AM, David Chelimsky wrote: >> On Sun, Jul 13, 2008 at 4:50 PM, Charles Grindel wrote: >>> Hi, >>> >>> Thanks for the info, Luis. I am glad that they fixed the calling a batch >>> file issue. I have had to handle this myself in several different >>> situations. >>> >>> I do have one additional question. It sounds like your setup is very >>> similar to ours. Is your project new or did you upgrade? Do you run >>> autospec or autotest from the command line? It seems like running autotest >>> directly should still work given the history comment, but I could not get >>> things to fly until I started using autospec. Just curious. >> >> When we introduced autospec, we also changed the way rspec identifies >> itself to autotest such that an ENV var must be present (which is set >> by autospec) - so no, the autotest command won't work. >> > > Hmn, really? > > rspec, commit 5bb989c6a54e325198e180ef3d4e59b5bf6eb21c > rspec-rails: commit 9a1e10e7b71f7e8e4fb910a9695ee69abec63816 > > http://pastie.org/private/gwgvkbhpbvhvtquslwe6g Hmm. Well, it's not supposed to work :) We added autospec specifically so that it wouldn't. Check out http://rspec.lighthouseapp.com/projects/5645/tickets/394 and http://github.com/dchelimsky/rspec/commit/c12b4e0cdcae1309725eeee75ce85110b905f432. Any reason that shouldn't work on windows? > But in any case, if you say that I should use script/autospec, then I should :-) > > -- > Luis Lavena > AREA 17 > - > Human beings, who are almost unique in having the ability to learn from > the experience of others, are also remarkable for their apparent > disinclination to do so. > Douglas Adams > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Jul 15 08:23:51 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 15 Jul 2008 07:23:51 -0500 Subject: [rspec-users] How to write specification for the *base* class API? In-Reply-To: <3f2c7903c5ecdfb1ec7b8f9a68183eb1@ruby-forum.com> References: <3f2c7903c5ecdfb1ec7b8f9a68183eb1@ruby-forum.com> Message-ID: <57c63afe0807150523n3a1dabd2qc3f0ae5cfd8b77aa@mail.gmail.com> On Tue, Jul 15, 2008 at 4:17 AM, Piotr Wlodarek wrote: > For the base class, it seems reasonable to specify public API with > RSpec. > > However, since we deal with a base class, methods are often empty (put > there just to show the API). > > The spec cannot be run against the base class. In consequence, the spec > must be duplicated in every derived class, which seems to be far from > DRY. > > How to deal with it? What is THE RSpec way to specify APIs when we face > inheritance? This is more a theoretical TDD/BDD question than an RSpec question. There are a few schools of thought about this, so I'd recommend checking out the testdrivendevelopment list at yahoo as well - but I'll give you my two cents :) Any subclass can override any method in the base class, so it is not sufficient to have examples of just the base class, nor is it very helpful to have examples for empty methods just for show if the intent is that the base class will never get initialized directly. If you're deriving objects from the base class, write examples for the derived classes. If all derived classes are intended to pass the same examples with the same input/output expectations, then you can write shared examples and run them against instances of all the derived classes, thus satisfying your quest for DRY. HTH, David From dchelimsky at gmail.com Tue Jul 15 08:36:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 15 Jul 2008 07:36:21 -0500 Subject: [rspec-users] Specyfing behaviour VS specifying implementation In-Reply-To: <34a677f4388dd1cfb6e952edfe150ff3@ruby-forum.com> References: <34a677f4388dd1cfb6e952edfe150ff3@ruby-forum.com> Message-ID: <57c63afe0807150536p15d88cecu2a3addc5a88e5819@mail.gmail.com> On Tue, Jul 15, 2008 at 4:59 AM, Piotr Wlodarek wrote: > At first it seems obvious: one should specify behaviour, not > implementation. > > However, there may be a tremendous overhead and duplication with such > approach. > > Let's assume: > > def a > # lot's of business logic > end > > deb b > # lot's of business logic > end > > def main > a > b > end > > Assuming we do have specs for methods a and b, how the main method > should be specified? > > 1) Full behaviour specification > Problem: it duplicates specification of a and b > > 2) Specify that main should call a, then b > Problem: it specifies implementation, NOT behaviour > > > So, what is the right way? The right way is to write examples of behaviour BEFORE you write the code so you don't end up with two methods with "lots of business logic" :) If you're writing examples first, then you'd have examples for :main and, as :main grew in complexity, :a and :b would be extracted from :main. If :a and :b are methods intended to be part of the public interface of the class, then perhaps they belong on another object, in which case setting message expectations on a mock is perfectly acceptable for examples of :main. HTH, David From luislavena at gmail.com Tue Jul 15 08:41:17 2008 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 15 Jul 2008 14:41:17 +0200 Subject: [rspec-users] Getting RSpec 1.1.4+ to Work with Autotest (ZenTest 3.10.0) on Windows (Win32) In-Reply-To: <57c63afe0807150503n3e4a5328kc2bb80e258d4bb77@mail.gmail.com> References: <506754.80820.qm@web54101.mail.re2.yahoo.com> <57c63afe0807131511w41e36b30oa396fb6626c71098@mail.gmail.com> <71166b3b0807150116j287458fydc221ba6850946c3@mail.gmail.com> <57c63afe0807150503n3e4a5328kc2bb80e258d4bb77@mail.gmail.com> Message-ID: <71166b3b0807150541s54be78e6te4319e90120b45e9@mail.gmail.com> On Tue, Jul 15, 2008 at 2:03 PM, David Chelimsky wrote: > On Tue, Jul 15, 2008 at 3:16 AM, Luis Lavena wrote: >> [...] >> >> Hmn, really? >> >> rspec, commit 5bb989c6a54e325198e180ef3d4e59b5bf6eb21c >> rspec-rails: commit 9a1e10e7b71f7e8e4fb910a9695ee69abec63816 >> >> http://pastie.org/private/gwgvkbhpbvhvtquslwe6g > > Hmm. Well, it's not supposed to work :) We added autospec specifically > so that it wouldn't. Check out > http://rspec.lighthouseapp.com/projects/5645/tickets/394 and > http://github.com/dchelimsky/rspec/commit/c12b4e0cdcae1309725eeee75ce85110b905f432. > Any reason that shouldn't work on windows? > Besides because is Windows? ;-) (just kidding) There is no specific code there, This are my .autotest and ~/.autotest contents: http://pastie.org/private/chano8j5px7izztck0t6tw One thing I noticed is that using script/autospec spec modifications get picked, but after successfully run they do not try to do a full run.. (try running the whole spec files). On the other hand, autotest try run the modified specs and *then* run a full check on all the specs (expected behavior). This is the output from script/autospec: http://pastie.org/private/bsbyyyppir7ica5moheqtg Just checked that ENV['RSPEC'] get set using script/autotest (inside .autotest) puts ENV['RSPEC'] Output: loading autotest/rails_rspec true When called from autotest directly, I get: loading autotest/rails_rspec nil Dunno if that helps. I'm using Rails 2.1.0 (from gems), RSpec and RSpec rails latest commits as plugins and ZenTest 3.10.0 -- Luis Lavena AREA 17 - Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. Douglas Adams From pergesu at gmail.com Tue Jul 15 08:47:56 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 15 Jul 2008 08:47:56 -0400 Subject: [rspec-users] How to write specification for the *base* class API? In-Reply-To: <3f2c7903c5ecdfb1ec7b8f9a68183eb1@ruby-forum.com> References: <3f2c7903c5ecdfb1ec7b8f9a68183eb1@ruby-forum.com> Message-ID: <810a540e0807150547w5520caadk18d5695c272e8946@mail.gmail.com> On Tue, Jul 15, 2008 at 5:17 AM, Piotr Wlodarek wrote: > For the base class, it seems reasonable to specify public API with > RSpec. > > However, since we deal with a base class, methods are often empty (put > there just to show the API). What's the point of that? This isn't Java. > The spec cannot be run against the base class. In consequence, the spec > must be duplicated in every derived class, which seems to be far from > DRY. Presumably the derived classes have different implementations, so you would need to spec them out differently. If the implementations are the same, shared behaviors are often useful. Pat From loop at superinfinite.com Tue Jul 15 08:58:46 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Tue, 15 Jul 2008 14:58:46 +0200 Subject: [rspec-users] How to write specification for the *base* class API? In-Reply-To: <810a540e0807150547w5520caadk18d5695c272e8946@mail.gmail.com> References: <3f2c7903c5ecdfb1ec7b8f9a68183eb1@ruby-forum.com> <810a540e0807150547w5520caadk18d5695c272e8946@mail.gmail.com> Message-ID: <22CADB27-82AF-4CC6-91F4-AFC7B483F53C@superinfinite.com> On 15-jul-2008, at 14:47, Pat Maddox wrote: > On Tue, Jul 15, 2008 at 5:17 AM, Piotr Wlodarek forum.com> wrote: >> For the base class, it seems reasonable to specify public API with >> RSpec. >> >> However, since we deal with a base class, methods are often empty >> (put >> there just to show the API). > > What's the point of that? This isn't Java. Exactly. In all of my projects, I only have an inheritance tree of at most 3 levels deep. AR::Base -> Generic -> Specific model. If there are more than three levels, something might not be okay with the design of your app. Of course your mileage may vary, but I think a lot of developers will agree on this subject. >> The spec cannot be run against the base class. In consequence, the >> spec >> must be duplicated in every derived class, which seems to be far from >> DRY. > > Presumably the derived classes have different implementations, so you > would need to spec them out differently. > > If the implementations are the same, shared behaviors are often > useful. From lists at ruby-forum.com Tue Jul 15 09:22:12 2008 From: lists at ruby-forum.com (Piotr Wlodarek) Date: Tue, 15 Jul 2008 15:22:12 +0200 Subject: [rspec-users] How to write specification for the *base* class API? In-Reply-To: <57c63afe0807150523n3a1dabd2qc3f0ae5cfd8b77aa@mail.gmail.com> References: <3f2c7903c5ecdfb1ec7b8f9a68183eb1@ruby-forum.com> <57c63afe0807150523n3a1dabd2qc3f0ae5cfd8b77aa@mail.gmail.com> Message-ID: <8dc35d346195b11775b946e48b452f0f@ruby-forum.com> >> However, since we deal with a base class, methods are often empty >> (put there just to show the API). > What's the point of that? This isn't Java. Documentation for developers of derived classes. > Exactly. In all of my projects, I only have an inheritance tree of > at most 3 levels deep. It's not AR. I have 2 levels: Site1Scraper < BaseScraper. There will be many SiteXScrapers implemented by several people. ++++ >From your answers I conclude it's not possible (or at least not recommended) to document abstract interface with RSpec. -- Posted via http://www.ruby-forum.com/. From zach.dennis at gmail.com Tue Jul 15 09:24:40 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 15 Jul 2008 09:24:40 -0400 Subject: [rspec-users] How to write specification for the *base* class API? In-Reply-To: <810a540e0807150547w5520caadk18d5695c272e8946@mail.gmail.com> References: <3f2c7903c5ecdfb1ec7b8f9a68183eb1@ruby-forum.com> <810a540e0807150547w5520caadk18d5695c272e8946@mail.gmail.com> Message-ID: <85d99afe0807150624n41e7d228hf10e205f5ece7163@mail.gmail.com> On Tue, Jul 15, 2008 at 8:47 AM, Pat Maddox wrote: > On Tue, Jul 15, 2008 at 5:17 AM, Piotr Wlodarek > wrote: > > For the base class, it seems reasonable to specify public API with > > RSpec. > > > > However, since we deal with a base class, methods are often empty (put > > there just to show the API). > > What's the point of that? This isn't Java. > > Readability I would assume. Rspec does this in the base_formatter.rb and Rails does this in some places as well I have noticed. -- Zach Dennis http://www.continuousthinking.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Tue Jul 15 09:51:42 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 15 Jul 2008 08:51:42 -0500 Subject: [rspec-users] How to write specification for the *base* class API? Message-ID: <76F8F301-C419-4589-A317-A297A81C4EF1@gmail.com> On Jul 15, 2008, at 8:22 AM, Piotr Wlodarek wrote: >>> However, since we deal with a base class, methods are often empty >>> (put there just to show the API). > >> What's the point of that? This isn't Java. > > Documentation for developers of derived classes. > > >> Exactly. In all of my projects, I only have an inheritance tree of >> at most 3 levels deep. > > It's not AR. I have 2 levels: Site1Scraper < BaseScraper. > > There will be many SiteXScrapers implemented by several people. > > ++++ > >> From your answers I conclude it's not possible (or at least not > recommended) to document abstract interface with RSpec. If everyone gave up that easily we'd never improve anything ;) Not sure how you get to "not possible." Pat suggested shared examples, which would be a perfectly good solution for part of the problem. I think the question is what are you trying to acheive here and whether Rspec (or any testing framework) is the right place for that goal. From lists at ruby-forum.com Tue Jul 15 10:10:30 2008 From: lists at ruby-forum.com (Piotr Wlodarek) Date: Tue, 15 Jul 2008 16:10:30 +0200 Subject: [rspec-users] How to write specification for the *base* class API? In-Reply-To: <76F8F301-C419-4589-A317-A297A81C4EF1@gmail.com> References: <76F8F301-C419-4589-A317-A297A81C4EF1@gmail.com> Message-ID: <64b532fc4ec69a7675b735ff90cfdb5f@ruby-forum.com> David Chelimsky wrote: > On Jul 15, 2008, at 8:22 AM, Piotr Wlodarek > wrote: > >> >> It's not AR. I have 2 levels: Site1Scraper < BaseScraper. >> >> There will be many SiteXScrapers implemented by several people. >> >> ++++ >> >>> From your answers I conclude it's not possible (or at least not >> recommended) to document abstract interface with RSpec. > > If everyone gave up that easily we'd never improve anything ;) > > Not sure how you get to "not possible." Pat suggested shared examples, > which would be a perfectly good solution for part of the problem. > > I think the question is what are you trying to acheive here and > whether Rspec (or any testing framework) is the right place for that > goal. I try to document public API of important base class. Shared examples, as you said, solve part of the problem. Since I try to develop this project in a BDD style, and specifications are said to be - among other things - a documentation tool, it seems reasonable to take advantage of it. Alternative is mixed documentation of rdoc + specs. In a perfect world I would expect to have only one documentation tool: specs. -- Posted via http://www.ruby-forum.com/. From j at jonathanleighton.com Tue Jul 15 09:50:12 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Tue, 15 Jul 2008 14:50:12 +0100 Subject: [rspec-users] Profiling specs In-Reply-To: References: <1216116646.7161.12.camel@tybalt> Message-ID: <1216129812.7161.14.camel@tybalt> On Tue, 2008-07-15 at 13:40 +0200, Piotr Wlodarek wrote: > Jonathan Leighton wrote: > > Is there any simple, easy way to profile the running of my specs? It has > > recently starting being way slower and I want to know why :) > > spec --format profile Thanks, but I was more thinking something that would allow me to run ruby-prof over the specs - it's not so much a problem that individual examples are too slow, but more that the specs have somehow become uniformly slower. I guess I could try and work out the revision at which it became a problem but if there was an easy way to profile it that would be better... Cheers From loop at superinfinite.com Tue Jul 15 10:16:20 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Tue, 15 Jul 2008 16:16:20 +0200 Subject: [rspec-users] How to write specification for the *base* class API? In-Reply-To: <8dc35d346195b11775b946e48b452f0f@ruby-forum.com> References: <3f2c7903c5ecdfb1ec7b8f9a68183eb1@ruby-forum.com> <57c63afe0807150523n3a1dabd2qc3f0ae5cfd8b77aa@mail.gmail.com> <8dc35d346195b11775b946e48b452f0f@ruby-forum.com> Message-ID: <8BECEF5F-AC73-4BAF-B48B-01777CE44175@superinfinite.com> On 15-jul-2008, at 15:22, Piotr Wlodarek wrote: >>> However, since we deal with a base class, methods are often empty >>> (put there just to show the API). > >> What's the point of that? This isn't Java. > > Documentation for developers of derived classes. > > >> Exactly. In all of my projects, I only have an inheritance tree of >> at most 3 levels deep. > > It's not AR. I have 2 levels: Site1Scraper < BaseScraper. Ok, but if a method is only in a BaseScraper for documentational purposes, eg, an empty body, should it be defined on that model at all? If it's only going to be used on a Site1Scraper, leave it to that class to define and have it tested there. As far as I know there's no useful implementation of an interface or an abstract class in ruby, but I could be wrong. > There will be many SiteXScrapers implemented by several people. > > ++++ > >> From your answers I conclude it's not possible (or at least not > recommended) to document abstract interface with RSpec. From pergesu at gmail.com Tue Jul 15 10:24:39 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 15 Jul 2008 10:24:39 -0400 Subject: [rspec-users] How to write specification for the *base* class API? In-Reply-To: <64b532fc4ec69a7675b735ff90cfdb5f@ruby-forum.com> References: <76F8F301-C419-4589-A317-A297A81C4EF1@gmail.com> <64b532fc4ec69a7675b735ff90cfdb5f@ruby-forum.com> Message-ID: <810a540e0807150724x5b654e01p43ce118534fdbe8@mail.gmail.com> On Tue, Jul 15, 2008 at 10:10 AM, Piotr Wlodarek wrote: > David Chelimsky wrote: >> On Jul 15, 2008, at 8:22 AM, Piotr Wlodarek >> wrote: >> >>> >>> It's not AR. I have 2 levels: Site1Scraper < BaseScraper. >>> >>> There will be many SiteXScrapers implemented by several people. >>> >>> ++++ >>> >>>> From your answers I conclude it's not possible (or at least not >>> recommended) to document abstract interface with RSpec. >> >> If everyone gave up that easily we'd never improve anything ;) >> >> Not sure how you get to "not possible." Pat suggested shared examples, >> which would be a perfectly good solution for part of the problem. >> >> I think the question is what are you trying to acheive here and >> whether Rspec (or any testing framework) is the right place for that >> goal. > > I try to document public API of important base class. > > Shared examples, as you said, solve part of the problem. > > Since I try to develop this project in a BDD style, and specifications > are said to be - among other things - a documentation tool, it seems > reasonable to take advantage of it. Alternative is mixed documentation > of rdoc + specs. > > In a perfect world I would expect to have only one documentation tool: > specs. I think in this case you could provide contract tests. These would be shared behaviors that developers can mix in to their own specs. Consider something basic for an account: describe "account", :shared => true do it "should increase in balance after a deposit" do start_balance = account.balance account.deposit 100 account.balance.should > start_balance end it "should decrease in balance after a withdrawal" do start_balance = account.balance account.withdraw 100 account.balance.should < start_balance end end This defines the contract of an Account abstraction... you can imagine different account types that might implement it in a way that the actual dollar values differ. For example, fees may be applied to one kind of account but not another. Anyone who implements your API can include that shared example group and verify their code against the contract you've defined. Pat From mailing_lists at railsnewbie.com Tue Jul 15 20:06:23 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 15 Jul 2008 20:06:23 -0400 Subject: [rspec-users] Profiling specs In-Reply-To: <1216129812.7161.14.camel@tybalt> References: <1216116646.7161.12.camel@tybalt> <1216129812.7161.14.camel@tybalt> Message-ID: <9C03305B-7EA0-42CE-84CF-E0252A773A71@railsnewbie.com> On Jul 15, 2008, at 9:50 AM, Jonathan Leighton wrote: > On Tue, 2008-07-15 at 13:40 +0200, Piotr Wlodarek wrote: >> Jonathan Leighton wrote: >>> Is there any simple, easy way to profile the running of my specs? >>> It has >>> recently starting being way slower and I want to know why :) >> >> spec --format profile > > Thanks, but I was more thinking something that would allow me to run > ruby-prof over the specs - it's not so much a problem that individual > examples are too slow, but more that the specs have somehow become > uniformly slower. > > I guess I could try and work out the revision at which it became a > problem but if there was an easy way to profile it that would be > better... It sounds like a build server would help you out. I'm sure you could also check out ever revision (or every 50 or 500 revisions) of your app, run the specs, and create some sort of graph to get some general ideas about when and where things have slowed down. Scott From lists at ruby-forum.com Wed Jul 16 01:14:28 2008 From: lists at ruby-forum.com (Piotr Wlodarek) Date: Wed, 16 Jul 2008 07:14:28 +0200 Subject: [rspec-users] How to write specification for the *base* class API? In-Reply-To: <810a540e0807150724x5b654e01p43ce118534fdbe8@mail.gmail.com> References: <76F8F301-C419-4589-A317-A297A81C4EF1@gmail.com> <64b532fc4ec69a7675b735ff90cfdb5f@ruby-forum.com> <810a540e0807150724x5b654e01p43ce118534fdbe8@mail.gmail.com> Message-ID: <119c8e42b193ca6b4b0e2563e398d0cc@ruby-forum.com> Pat Maddox wrote: > On Tue, Jul 15, 2008 at 10:10 AM, Piotr Wlodarek > wrote: >>>> >>> goal. >> In a perfect world I would expect to have only one documentation tool: >> specs. > > I think in this case you could provide contract tests. These would be > shared behaviors that developers can mix in to their own specs. > Consider something basic for an account: Thanks for the example. It carifies the issue. I will try it. ++++ BTW, do you think it's worthwile to replace most of rdoc and other documentation with specs? RSpec itself comes with nice RDoc, so perhaps I want too much? -- Posted via http://www.ruby-forum.com/. From nicholas.wieland at gmail.com Wed Jul 16 07:07:43 2008 From: nicholas.wieland at gmail.com (Nicholas Wieland) Date: Wed, 16 Jul 2008 13:07:43 +0200 Subject: [rspec-users] Testing upload via web services Message-ID: <2EA31DE6-7A08-42AC-A0FB-61E54FB80543@gmail.com> Hi *, I need to write a web service that accepts file uploads (even large ones). My WS is REST based, so I have a create method that accepts only POST. My problem is passing the file to the method, so if someone already solved this problem please let me know. My method is like this: def create radio = Radio.create!( params[ :radio ] ) ad = Ad.new( params[ :ad ].merge( :user => current_user, :resource => radio ) ) ad.save! respond_to do |format| format.html format.xml { render :xml => ad.to_xml, :status => :created } end rescue ActiveRecord::RecordInvalid respond_to do |format| format.html { render :action => :new } format.xml { render :xml => " #{e.message} ", :status => :unprocessable_entity } end end and this is the spec: it "should upload radios remotely" do @request.env[ "HTTP_AUTHORIZATION" ] = "Basic " + Base64::encode64( "quentin:test" ) puts @request.accepts file = MockUpload.new( 'example_radio.mp3' ) Radio.should_receive( :create! ).with( 'audio' => file ) post :create, :contest_slug => 'pago', :format => :xml, :radio => { :audio => file }, :ad => { :title => 'test 1', :description => 'test test test test test test test', :contest => contests( :pago ), :copyright_disclaimer => true } end It answers with a 406 code, so there's something wrong with my code (request.accepts returns */*). My concern is about what gets saved inside the Radio object, I don't think I can pass a raw binary object (AFAIK), and also the way I'm doing things, couldn't find any example on the net, I'm in the dark about how to pass stuff and how to get it, let's not even talk about how to spec it. About rspeccing the whole thing things get even more messy, I think I need to write controller tests that check that the file I begin with is exactly the same I have after using the WS, but isn't it something I shouldn't do in RSpec ? I mean, using real data. In this case I can have the controller behaving exactly as I think it should by calling the right methods in the right way, but having a corrupted file in the fs .... I can't test data in the model either, because corruption will happen exactly inside the controller. I'm new to this stuff, so I'm pretty clueless. Every help is very appreciated. TIA, ngw From dchelimsky at gmail.com Wed Jul 16 07:22:35 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 16 Jul 2008 06:22:35 -0500 Subject: [rspec-users] Testing upload via web services In-Reply-To: <2EA31DE6-7A08-42AC-A0FB-61E54FB80543@gmail.com> References: <2EA31DE6-7A08-42AC-A0FB-61E54FB80543@gmail.com> Message-ID: <57c63afe0807160422m584c9cc2ie4f59f317dae5d8e@mail.gmail.com> On Wed, Jul 16, 2008 at 6:07 AM, Nicholas Wieland wrote: > Hi *, > I need to write a web service that accepts file uploads (even large ones). > My WS is REST based, so I have a create method that accepts only POST. > My problem is passing the file to the method, so if someone already solved > this problem please let me know. http://talklikeaduck.denhaven2.com/articles/2008/04/18/rails-integration-test-file-upload-plugin Cheers, David From lists at ruby-forum.com Wed Jul 16 09:48:12 2008 From: lists at ruby-forum.com (Ming Li) Date: Wed, 16 Jul 2008 15:48:12 +0200 Subject: [rspec-users] hot sell shoes,jeans,shirt,clothes,cap,watch Message-ID: <77b07c027eb08ecaf6b935e1ef5b39b2@ruby-forum.com> hi freind welcome to www.007trader.com thanks Attachments: http://www.ruby-forum.com/attachment/2402/200852485255_____.jpg -- Posted via http://www.ruby-forum.com/. From paolo.dona at gmail.com Wed Jul 16 11:16:34 2008 From: paolo.dona at gmail.com (Paolo Dona) Date: Wed, 16 Jul 2008 08:16:34 -0700 (PDT) Subject: [rspec-users] '$' placeholder naming can confuse your runner Message-ID: Hi guys, I'm facing a strange behavior that smells like a bug. consider this scenario: Scenario: I'm cool Given that I am cool 4 times out of 7 and this step: Given("that I am cool $n times out of $n_total") do |n, n_total| ... end When running my story, this step is considered as PENDING. If I change the name of the second placeholder to $total, the step runs fine (as it should, given that it's implemented). My suspect is that when placeholders share a common prefix, the step cannot be recognized correctly. Anyone having the same issue? btw: quoting the placeholders doesn't change this behavior keep on with the great work, Paolo From pergesu at gmail.com Wed Jul 16 11:40:19 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 16 Jul 2008 11:40:19 -0400 Subject: [rspec-users] '$' placeholder naming can confuse your runner In-Reply-To: References: Message-ID: <810a540e0807160840u11322bbcsf5044edcd4392964@mail.gmail.com> What about when you make it $ntotal? Is it the common first letter or the underscore? Pat On 7/16/08, Paolo Dona wrote: > Hi guys, I'm facing a strange behavior that smells like a bug. > > consider this scenario: > > Scenario: I'm cool > Given that I am cool 4 times out of 7 > > and this step: > > Given("that I am cool $n times out of $n_total") do |n, n_total| > ... > end > > When running my story, this step is considered as PENDING. > If I change the name of the second placeholder to $total, the step > runs fine (as it should, given that it's implemented). > > My suspect is that when placeholders share a common prefix, the step > cannot be recognized correctly. > Anyone having the same issue? > > btw: quoting the placeholders doesn't change this behavior > > keep on with the great work, > Paolo > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From paolo.dona at gmail.com Wed Jul 16 12:07:19 2008 From: paolo.dona at gmail.com (Paolo Dona) Date: Wed, 16 Jul 2008 09:07:19 -0700 (PDT) Subject: [rspec-users] '$' placeholder naming can confuse your runner In-Reply-To: <810a540e0807160840u11322bbcsf5044edcd4392964@mail.gmail.com> References: <810a540e0807160840u11322bbcsf5044edcd4392964@mail.gmail.com> Message-ID: It is the common prefix, not the underscore. With $n and $nnn or $ntotal still fails. Paolo On Jul 16, 4:40?pm, "Pat Maddox" wrote: > What about when you make it $ntotal? Is it the common first letter or > the underscore? > > Pat > > On 7/16/08, Paolo Dona wrote: > > > Hi guys, I'm facing a strange behavior that smells like a bug. > > > consider this scenario: > > > Scenario: I'm cool > > ? Given that I am cool 4 times out of 7 > > > and this step: > > > Given("that I am cool $n times out of $n_total") do |n, n_total| > > ? ... > > end > > > When running my story, this step is considered as PENDING. > > If I change the name of the second placeholder to $total, the step > > runs fine (as it should, given that it's implemented). > > > My suspect is that when placeholders share a common prefix, the step > > cannot be recognized correctly. > > Anyone having the same issue? > > > btw: quoting the placeholders doesn't change this behavior > > > keep on with the great work, > > Paolo > > _______________________________________________ > > 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 aidy.lewis at googlemail.com Wed Jul 16 15:09:00 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Wed, 16 Jul 2008 12:09:00 -0700 Subject: [rspec-users] license to post rspec example Message-ID: <7ac2300c0807161209v1945eadr9db7969aa564749@mail.gmail.com> Hi, Would I need to use a license or give credit if I posted on OpenQA an example of Rspec and Watir (with my own AUT object model)? Aidy From ashley.moran at patchspace.co.uk Wed Jul 16 16:47:20 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 16 Jul 2008 21:47:20 +0100 Subject: [rspec-users] How to write specification for the *base* class API? In-Reply-To: <810a540e0807150724x5b654e01p43ce118534fdbe8@mail.gmail.com> References: <76F8F301-C419-4589-A317-A297A81C4EF1@gmail.com> <64b532fc4ec69a7675b735ff90cfdb5f@ruby-forum.com> <810a540e0807150724x5b654e01p43ce118534fdbe8@mail.gmail.com> Message-ID: <75FB3324-2582-4E29-BD3F-A299EF195BD8@patchspace.co.uk> On Jul 15, 2008, at 3:24 pm, Pat Maddox wrote: > This defines the contract of an Account abstraction... you can imagine > different account types that might implement it in a way that the > actual dollar values differ. For example, fees may be applied to one > kind of account but not another. > > Anyone who implements your API can include that shared example group > and verify their code against the contract you've defined. Hi Pat This sounds like a brilliant idea - I've wanted so often to be able to mix in specs for AR::Base for example. BUT - would it encourage programming by inheritance, rather than message passing? Often it feels unnatural to subclass *someone else's* library class and use it in *my* application. Subclassing a library class to pass back into the library doesn't bother me. For some reason it feels normal to subclass a controller class but not an ORM class. Perhaps because a controller is just a strategy for handling requests, and not something you instantiate and manipulate yourself, whereas an AR model class has business logic (handled by the app) and persistence (handled by the framework) rolled into one? WDYT? Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From chris at cobaltedge.com Wed Jul 16 19:59:24 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Wed, 16 Jul 2008 16:59:24 -0700 Subject: [rspec-users] How to do HTTP Basic Authentication in stories with WebRat? Message-ID: <443c240c0807161659k77974ca8yc0ad8b6baf8c94cf@mail.gmail.com> I have a controller that has simple HTTP basic authentication protecting a bunch of its actions. How can I authentication/get around this when creating stories for this controller that I'm driving via WebRat? From what I can tell, using "visits" won't work, although I could directly do "get" and "post" and such and pass a hash of headers, but of course I then lose all the handiness of using "visits". I'm looking at forking Webrat and adding the similar headers hash parameter feature to it (this would also help with providing the referer, so that you can use visits on actions that do "redirect_to :back"), but prior to me doing that, I wanted to see if there was a solution I wasn't aware of. -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From j at jonathanleighton.com Thu Jul 17 07:18:49 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Thu, 17 Jul 2008 12:18:49 +0100 Subject: [rspec-users] Specifying a few valid values Message-ID: <1216293529.8532.8.camel@tybalt> I have a Rails spec where I want to check that the action_name is either "create" or "update". I can think of a couple of ways to do it, but none of them reads fantastically well: 1. ["create", "update"].should include(controller.action_name) Problem: The error message, should it fail, is: expected ["create", "update"] to include "foo" 2. controller.action_name.should match(/^create|update$/) Problem: Not brilliantly readable, but the error message would be better. Is there a better way to do it? Something like this would be cool: controller.action_name.should == any_of("create", "update") Jon From dchelimsky at gmail.com Thu Jul 17 08:28:48 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 17 Jul 2008 07:28:48 -0500 Subject: [rspec-users] Specifying a few valid values In-Reply-To: <1216293529.8532.8.camel@tybalt> References: <1216293529.8532.8.camel@tybalt> Message-ID: <57c63afe0807170528n5d3f6249yf65eccd6c36cbc0a@mail.gmail.com> On Thu, Jul 17, 2008 at 6:18 AM, Jonathan Leighton wrote: > I have a Rails spec where I want to check that the action_name is either > "create" or "update". I can think of a couple of ways to do it, but none > of them reads fantastically well: > > 1. ["create", "update"].should include(controller.action_name) > > Problem: The error message, should it fail, is: expected ["create", > "update"] to include "foo" > > 2. controller.action_name.should match(/^create|update$/) > > Problem: Not brilliantly readable, but the error message would be > better. > > Is there a better way to do it? Something like this would be cool: > > controller.action_name.should == any_of("create", "update") Hi Jon - There's not really anything more clear supported, but you could always write a custom matcher for this. I'm wondering why the examples aren't more specific though. Why is it OK that the action could be one of two possibilities given a specific set of givens? David > Jon From j at jonathanleighton.com Thu Jul 17 08:40:21 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Thu, 17 Jul 2008 13:40:21 +0100 Subject: [rspec-users] Specifying a few valid values In-Reply-To: <57c63afe0807170528n5d3f6249yf65eccd6c36cbc0a@mail.gmail.com> References: <1216293529.8532.8.camel@tybalt> <57c63afe0807170528n5d3f6249yf65eccd6c36cbc0a@mail.gmail.com> Message-ID: <1216298421.8532.31.camel@tybalt> On Thu, 2008-07-17 at 07:28 -0500, David Chelimsky wrote: > I'm wondering why the examples aren't more specific though. Why is it > OK that the action could be one of two possibilities given a specific > set of givens? Ok well I lied a little bit :) I am using it in a story step, specifically the step is "Then the form should be shown". I guess I could split them into ?"Then the new/edit form should be shown" but it doesn't seem a huge issue... -- Jonathan Leighton http://jonathanleighton.com/ From lists at ruby-forum.com Thu Jul 17 09:45:30 2008 From: lists at ruby-forum.com (Gregg Pollack) Date: Thu, 17 Jul 2008 15:45:30 +0200 Subject: [rspec-users] We ain't got no RSpec Message-ID: <1ddf4fbe7cd6c6bd400ab540001b5cf9@ruby-forum.com> Hey Guys, This last week on the Rails Envy Podcast we received an "interesting" voicemail. Jason encouraged me to make a remix, and I think you guys will appreciate what resulted. If you have a few minutes and need a good laugh, see here for the voicemail and the remix: http://www.railsenvy.com/2008/7/17/we-aint-got-no-rspec -Gregg -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Jul 17 09:50:59 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 17 Jul 2008 08:50:59 -0500 Subject: [rspec-users] Specifying a few valid values In-Reply-To: <1216298421.8532.31.camel@tybalt> References: <1216293529.8532.8.camel@tybalt> <57c63afe0807170528n5d3f6249yf65eccd6c36cbc0a@mail.gmail.com> <1216298421.8532.31.camel@tybalt> Message-ID: On Jul 17, 2008, at 7:40 AM, Jonathan Leighton wrote: > On Thu, 2008-07-17 at 07:28 -0500, David Chelimsky wrote: >> I'm wondering why the examples aren't more specific though. Why is it >> OK that the action could be one of two possibilities given a specific >> set of givens? > > Ok well I lied a little bit :) > > I am using it in a story step, specifically the step is "Then the form > should be shown". I guess I could split them into "Then the new/edit > form should be shown" but it doesn't seem a huge issue... Aha. Now that's a horse of a different color. I tend to avoid details like that in story steps. I prefer to expect what's visible, submit forms (whatever the action is) and expect to end up in the right place. Are you familiar with Webrat? It's a tool that allows you to describe things at a much higher level and takes care of the low level detail for you. So rather than expecting specific form elements in the story steps, you just do things like this: Given I am registered as David with password Secret And am and Administrator When I log in with David/Secret Then I should see Manage Schedules in a list of Things To Do The interesting step here is "When I sign in with David/Secret": When /I log in with (.*)\/(.*)/ do |login, password| visits "/login" fills_in "Login", :with => login fills_in "Password", :with => password clicks_button "Log In" end The fills_in method does two things at once: expects to find an item with either an id of "Login" or with a related form label that has the text "Login". Then it manipulates the DOM, setting the value of that element to "David" (in this example). Then #clicks_button finds a button with the text "Log In", builds a POST from the related DOM elements and submits the POST. I use this 100% of the time for Rails stories these days and am overall very happy with the resulting code. FWIW, Cheers, David > -- > Jonathan Leighton > http://jonathanleighton.com/ From j at jonathanleighton.com Thu Jul 17 10:19:08 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Thu, 17 Jul 2008 15:19:08 +0100 Subject: [rspec-users] Specifying a few valid values In-Reply-To: References: <1216293529.8532.8.camel@tybalt> <57c63afe0807170528n5d3f6249yf65eccd6c36cbc0a@mail.gmail.com> <1216298421.8532.31.camel@tybalt> Message-ID: <1216304348.8532.46.camel@tybalt> On Thu, 2008-07-17 at 08:50 -0500, David Chelimsky wrote: > Are you familiar with Webrat? Yep, we are using it. However, I want to test what happens when invalid data is entered - that's the reason to specify that the form gets shown. What would you consider a better approach to verify the user sees the form again, instead of moving on through the application? I guess I could test that they *don't* get redirected? Cheers, Jon -- Jonathan Leighton http://jonathanleighton.com/ From zach.dennis at gmail.com Thu Jul 17 10:37:56 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 17 Jul 2008 10:37:56 -0400 Subject: [rspec-users] Specifying a few valid values In-Reply-To: <1216304348.8532.46.camel@tybalt> References: <1216293529.8532.8.camel@tybalt> <57c63afe0807170528n5d3f6249yf65eccd6c36cbc0a@mail.gmail.com> <1216298421.8532.31.camel@tybalt> <1216304348.8532.46.camel@tybalt> Message-ID: <85d99afe0807170737s33159edbiad24f0d9bc35e805@mail.gmail.com> Perhaps... When "I login with invalid credentials" Then "I see that I have not been logged in" And in your implementation of the Then you could make sure they are at the login form still. Zach On Thu, Jul 17, 2008 at 10:19 AM, Jonathan Leighton wrote: > On Thu, 2008-07-17 at 08:50 -0500, David Chelimsky wrote: >> Are you familiar with Webrat? > > Yep, we are using it. However, I want to test what happens when invalid > data is entered - that's the reason to specify that the form gets shown. > What would you consider a better approach to verify the user sees the > form again, instead of moving on through the application? I guess I > could test that they *don't* get redirected? > > Cheers, > Jon > > -- > Jonathan Leighton > http://jonathanleighton.com/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From dchelimsky at gmail.com Thu Jul 17 10:40:01 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 17 Jul 2008 09:40:01 -0500 Subject: [rspec-users] Specifying a few valid values In-Reply-To: <85d99afe0807170737s33159edbiad24f0d9bc35e805@mail.gmail.com> References: <1216293529.8532.8.camel@tybalt> <57c63afe0807170528n5d3f6249yf65eccd6c36cbc0a@mail.gmail.com> <1216298421.8532.31.camel@tybalt> <1216304348.8532.46.camel@tybalt> <85d99afe0807170737s33159edbiad24f0d9bc35e805@mail.gmail.com> Message-ID: <57c63afe0807170740t534f8248jfbe6b4a570ad7562@mail.gmail.com> On Thu, Jul 17, 2008 at 9:37 AM, Zach Dennis wrote: > Perhaps... > > When "I login with invalid credentials" > Then "I see that I have not been logged in" Or .... When I login with invalid credentials Then I should see the login form And I should see a message saying "Something went wrong." > > And in your implementation of the Then you could make sure they are at > the login form still. > > Zach > > > > > On Thu, Jul 17, 2008 at 10:19 AM, Jonathan Leighton > wrote: >> On Thu, 2008-07-17 at 08:50 -0500, David Chelimsky wrote: >>> Are you familiar with Webrat? >> >> Yep, we are using it. However, I want to test what happens when invalid >> data is entered - that's the reason to specify that the form gets shown. >> What would you consider a better approach to verify the user sees the >> form again, instead of moving on through the application? I guess I >> could test that they *don't* get redirected? >> >> Cheers, >> Jon >> >> -- >> Jonathan Leighton >> http://jonathanleighton.com/ >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Zach Dennis > http://www.continuousthinking.com > http://www.mutuallyhuman.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Thu Jul 17 11:03:08 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 17 Jul 2008 11:03:08 -0400 Subject: [rspec-users] Seed Data With Stories Message-ID: <85d99afe0807170803r218b98bbheec9ca700828fcf4@mail.gmail.com> More of an FYI should someone find this useful, http://www.continuousthinking.com/2008/7/17/using-seed-data-with-rspec-stories -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From j at jonathanleighton.com Thu Jul 17 12:04:49 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Thu, 17 Jul 2008 17:04:49 +0100 Subject: [rspec-users] Specifying a few valid values In-Reply-To: <57c63afe0807170740t534f8248jfbe6b4a570ad7562@mail.gmail.com> References: <1216293529.8532.8.camel@tybalt> <57c63afe0807170528n5d3f6249yf65eccd6c36cbc0a@mail.gmail.com> <1216298421.8532.31.camel@tybalt> <1216304348.8532.46.camel@tybalt> <85d99afe0807170737s33159edbiad24f0d9bc35e805@mail.gmail.com> <57c63afe0807170740t534f8248jfbe6b4a570ad7562@mail.gmail.com> Message-ID: <1216310689.8532.49.camel@tybalt> On Thu, 2008-07-17 at 09:40 -0500, David Chelimsky wrote: > On Thu, Jul 17, 2008 at 9:37 AM, Zach Dennis wrote: > > Perhaps... > > > > When "I login with invalid credentials" > > Then "I see that I have not been logged in" > > Or .... > > When I login with invalid credentials > Then I should see the login form > And I should see a message saying "Something went wrong." What would be the implementation of "?Then I should see the login form"? We are already testing for an error message :) Jon From pergesu at gmail.com Thu Jul 17 14:27:44 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 17 Jul 2008 14:27:44 -0400 Subject: [rspec-users] How to write specification for the *base* class API? In-Reply-To: <75FB3324-2582-4E29-BD3F-A299EF195BD8@patchspace.co.uk> References: <76F8F301-C419-4589-A317-A297A81C4EF1@gmail.com> <64b532fc4ec69a7675b735ff90cfdb5f@ruby-forum.com> <810a540e0807150724x5b654e01p43ce118534fdbe8@mail.gmail.com> <75FB3324-2582-4E29-BD3F-A299EF195BD8@patchspace.co.uk> Message-ID: <810a540e0807171127w54c5b161gd3a60fbb49f78a5c@mail.gmail.com> On Wed, Jul 16, 2008 at 4:47 PM, Ashley Moran wrote: > > On Jul 15, 2008, at 3:24 pm, Pat Maddox wrote: > >> This defines the contract of an Account abstraction... you can imagine >> different account types that might implement it in a way that the >> actual dollar values differ. For example, fees may be applied to one >> kind of account but not another. >> >> Anyone who implements your API can include that shared example group >> and verify their code against the contract you've defined. > > > Hi Pat > > This sounds like a brilliant idea - I've wanted so often to be able to mix > in specs for AR::Base for example. BUT - would it encourage programming by > inheritance, rather than message passing? Often it feels unnatural to > subclass *someone else's* library class and use it in *my* application. > Subclassing a library class to pass back into the library doesn't bother > me. For some reason it feels normal to subclass a controller class but not > an ORM class. Perhaps because a controller is just a strategy for handling > requests, and not something you instantiate and manipulate yourself, whereas > an AR model class has business logic (handled by the app) and persistence > (handled by the framework) rolled into one? > > WDYT? > > Ashley Well, I don't think people would fall into the trap of misusing inheritance if you don't give them classes to inherit from :) The original post was about writing specs for base classes that have empty methods. The reason that he wanted to write these empty methods was to provide documentation for later programmers. If, however, you provided a set of specs that defined the expected contract, people could write whatever code they want and know that it should work within the framework - no inheritance required. And if the framework developer did want to provide existing behavior, he can do so by writing modules that people can mix into their own stuff. Now, this is speculation on my part, as I've never actually done this. But I like the idea of taking DBC ideas and flipping them on their head, defining contracts from the client-side in the form of specs. Pat From pergesu at gmail.com Thu Jul 17 17:53:38 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 17 Jul 2008 17:53:38 -0400 Subject: [rspec-users] We ain't got no RSpec In-Reply-To: <1ddf4fbe7cd6c6bd400ab540001b5cf9@ruby-forum.com> References: <1ddf4fbe7cd6c6bd400ab540001b5cf9@ruby-forum.com> Message-ID: <810a540e0807171453h12cbfedp5e7281b137f94155@mail.gmail.com> Awesome. Well done On Thu, Jul 17, 2008 at 9:45 AM, Gregg Pollack wrote: > Hey Guys, > > This last week on the Rails Envy Podcast we received an "interesting" > voicemail. Jason encouraged me to make a remix, and I think you guys > will appreciate what resulted. > > If you have a few minutes and need a good laugh, see here for the > voicemail and the remix: > > http://www.railsenvy.com/2008/7/17/we-aint-got-no-rspec > > -Gregg > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Jul 17 19:22:27 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 17 Jul 2008 18:22:27 -0500 Subject: [rspec-users] Specifying a few valid values In-Reply-To: <1216310689.8532.49.camel@tybalt> References: <1216293529.8532.8.camel@tybalt> <57c63afe0807170528n5d3f6249yf65eccd6c36cbc0a@mail.gmail.com> <1216298421.8532.31.camel@tybalt> <1216304348.8532.46.camel@tybalt> <85d99afe0807170737s33159edbiad24f0d9bc35e805@mail.gmail.com> <57c63afe0807170740t534f8248jfbe6b4a570ad7562@mail.gmail.com> <1216310689.8532.49.camel@tybalt> Message-ID: <57c63afe0807171622n7c1b44fte96d41fa469a8f5@mail.gmail.com> On Thu, Jul 17, 2008 at 11:04 AM, Jonathan Leighton wrote: > On Thu, 2008-07-17 at 09:40 -0500, David Chelimsky wrote: >> On Thu, Jul 17, 2008 at 9:37 AM, Zach Dennis wrote: >> > Perhaps... >> > >> > When "I login with invalid credentials" >> > Then "I see that I have not been logged in" >> >> Or .... >> >> When I login with invalid credentials >> Then I should see the login form >> And I should see a message saying "Something went wrong." > > What would be the implementation of "?Then I should see the login form"? > We are already testing for an error message :) As with all things, context is everything. *If* I were going to have such a step, I'd do it based on things in the form: Then "should see the login form" do response.should have_tag('input#login') response.should have_tag('input#password') end That's more granular than I generally like, but that's what probably what I'd do in this scenario. HTH, David > > Jon > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mileshosky at hotmail.com Thu Jul 17 21:13:46 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Thu, 17 Jul 2008 18:13:46 -0700 Subject: [rspec-users] Specing Law of Demeter methods... Message-ID: It's been suggested that instead of doing -- organization.events.find(params[:id]) that you should be writing -- organization.get_event( params[:id] ) and the orgs 'get_event' method should look like -- def get_event( event_id ) -- self.events.find( event_id ) -- end So are the following valid / efficient specs or am I testing what isn't my own code? it "should return a particular event" do event = stub("an event") events = stub("event association") events.stub!(:find).with("1").and_return(event) @organization.stub!(:events).and_return(events) @organization.get_event("1").should == event end it "should raise error if it can't find event" do lambda{ @organization.get_event("1") }.should raise_error(ActiveRecord::RecordNotFound) end Any other suggestions? _________________________________________________________________ Stay in touch when you're away with Windows Live Messenger. http://www.windowslive.com/messenger/overview.html?ocid=TXT_TAGLM_WL_messenger2_072008 From dchelimsky at gmail.com Thu Jul 17 21:59:10 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 17 Jul 2008 20:59:10 -0500 Subject: [rspec-users] Specing Law of Demeter methods... In-Reply-To: References: Message-ID: <57c63afe0807171859o25962363p60977b89955d8f80@mail.gmail.com> On Thu, Jul 17, 2008 at 8:13 PM, Britt Mileshosky wrote: > > It's been suggested that instead of doing > > -- organization.events.find(params[:id]) > > that you should be writing > > -- organization.get_event( params[:id] ) > > and the orgs 'get_event' method should look like > > -- def get_event( event_id ) > -- self.events.find( event_id ) > -- end > > So are the following valid / efficient specs or am I testing what isn't my own code? > > it "should return a particular event" do > event = stub("an event") > events = stub("event association") > events.stub!(:find).with("1").and_return(event) > @organization.stub!(:events).and_return(events) > @organization.get_event("1").should == event > end > > it "should raise error if it can't find event" do > lambda{ @organization.get_event("1") }.should raise_error(ActiveRecord::RecordNotFound) > end > > Any other suggestions? http://plugins.code.lukeredpath.co.uk/browser/demeters_revenge/trunk Cheers, David From siemenbaader at gmail.com Fri Jul 18 04:00:08 2008 From: siemenbaader at gmail.com (Siemen Baader) Date: Fri, 18 Jul 2008 10:00:08 +0200 Subject: [rspec-users] Spec::Rails::Example::ModelExampleGroup Message-ID: Hi list! I get some not-so-nice output from rspec-rails when using the -f specdoc option. It happens both with the spec command and the rake task and on a prestine, newly generated rails app. I'm using rspec & rspec-rails 1.1.4 and rails 2.0.1. Is this a bug? Do you get the same output? -- Siemen Output: siemen at lazarus 0 /tmp/rs-app/spec % rake spec SPEC_OPTS='-f s -c' Spec::Rails::Example::RailsExampleGroup Spec::Rails::Example::ModelExampleGroup Spec::Rails::Example::FunctionalExampleGroup Spec::Rails::Example::ControllerExampleGroup Spec::Rails::Example::HelperExampleGroup Spec::Rails::Example::ViewExampleGroup Object - has legs Finished in 0.159382 seconds 1 example, 0 failures -------------- next part -------------- An HTML attachment was scrubbed... URL: From keith at dancingtext.com Fri Jul 18 06:11:10 2008 From: keith at dancingtext.com (Keith McDonnell) Date: Fri, 18 Jul 2008 12:11:10 +0200 Subject: [rspec-users] Specing a rails monkey patch Message-ID: <48806C3E.6010800@dancingtext.com> Hi all, I wrote an ActiveRecord extension to emulate a db cursor: http://pastie.org/236367 As you can see, the spec doesn't really ensure that the records are fetched in chunks. I'd like to mock the call to AR find and ensure that it's called with an incrementing offset. Any advice? Keith PS If you're interested, Jamis Buck wrote a (mySQL specific) DB cursor: http://weblog.jamisbuck.org/2007/4/6/faking-cursors-in-activerecord From david at digitalronin.com Fri Jul 18 06:56:29 2008 From: david at digitalronin.com (David Salgado) Date: Fri, 18 Jul 2008 11:56:29 +0100 Subject: [rspec-users] How to run specs AND tests with autotest Message-ID: <8c90cb7d0807180356m33768d5etfdd377a054007400@mail.gmail.com> Hi All I'm using test/unit on a project, at the client's insistence, but I'm also using rspec stories for integration testing. I notice that as soon as I install rspec and rspec-rails plugins, autotest no longer finds my test/unit tests - it just runs specs. Is there a way to make autotest run *both* specs and test/unit tests? I've had a look at the autotest code, and it looks as if it should be possible to do this with clever use of discover.rb files. But, unfortunately, I'm not clever enough to figure out how! FYI, ZenTest is version 3.10.0, Rails is 2.1.0, rspec and rspec-rails are git clones from the github repo as at 2008-07-03. Thanks in advance David From dchelimsky at gmail.com Fri Jul 18 08:42:01 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 18 Jul 2008 07:42:01 -0500 Subject: [rspec-users] Spec::Rails::Example::ModelExampleGroup In-Reply-To: References: Message-ID: <57c63afe0807180542j692cc510v22fc3f9b0a66f7f5@mail.gmail.com> On Fri, Jul 18, 2008 at 3:00 AM, Siemen Baader wrote: > Hi list! > > I get some not-so-nice output from rspec-rails when using the -f specdoc > option. It happens both with the spec command and the rake task and on a > prestine, newly generated rails app. > > I'm using rspec & rspec-rails 1.1.4 and rails 2.0.1. > > Is this a bug? Do you get the same output? It's a bug in 1.1.4 but it's already been fixed in git. Cheers, David From dchelimsky at gmail.com Fri Jul 18 08:49:26 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 18 Jul 2008 07:49:26 -0500 Subject: [rspec-users] How to run specs AND tests with autotest In-Reply-To: <8c90cb7d0807180356m33768d5etfdd377a054007400@mail.gmail.com> References: <8c90cb7d0807180356m33768d5etfdd377a054007400@mail.gmail.com> Message-ID: <57c63afe0807180549s47f3382k4a51a15914457a69@mail.gmail.com> On Fri, Jul 18, 2008 at 5:56 AM, David Salgado wrote: > Hi All > > I'm using test/unit on a project, at the client's insistence, but I'm > also using rspec stories for integration testing. I notice that as > soon as I install rspec and rspec-rails plugins, autotest no longer > finds my test/unit tests - it just runs specs. Is there a way to make > autotest run *both* specs and test/unit tests? > > I've had a look at the autotest code, and it looks as if it should be > possible to do this with clever use of discover.rb files. But, > unfortunately, I'm not clever enough to figure out how! > > FYI, ZenTest is version 3.10.0, Rails is 2.1.0, rspec and rspec-rails > are git clones from the github repo as at 2008-07-03. Any chance you have an rspec gem installed too? If so and you don't need it, get rid of it. If so and you do need it, grab the latest rspec/rspec-rails plugins and cd into the rspec directory and do this: rake gem rake install_gem That'll get you a gem based on the latest code which does not interfere w/ the autotest command at all (we added an autospec command for running specs). Cheers, David > > Thanks in advance > > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From david at digitalronin.com Fri Jul 18 09:00:05 2008 From: david at digitalronin.com (David Salgado) Date: Fri, 18 Jul 2008 14:00:05 +0100 Subject: [rspec-users] How to run specs AND tests with autotest In-Reply-To: <57c63afe0807180549s47f3382k4a51a15914457a69@mail.gmail.com> References: <8c90cb7d0807180356m33768d5etfdd377a054007400@mail.gmail.com> <57c63afe0807180549s47f3382k4a51a15914457a69@mail.gmail.com> Message-ID: <8c90cb7d0807180600k139b1585ue7e7d8a333fc2c83@mail.gmail.com> > Any chance you have an rspec gem installed too? If so and you don't > need it, get rid of it. If so and you do need it, grab the latest > rspec/rspec-rails plugins and cd into the rspec directory and do this: Yes, that was it. Getting rid of my rspec gem did the trick. Many thanks David From siemenbaader at gmail.com Fri Jul 18 10:56:28 2008 From: siemenbaader at gmail.com (Siemen Baader) Date: Fri, 18 Jul 2008 16:56:28 +0200 Subject: [rspec-users] Spec::Rails::Example::ModelExampleGroup In-Reply-To: <57c63afe0807180542j692cc510v22fc3f9b0a66f7f5@mail.gmail.com> References: <57c63afe0807180542j692cc510v22fc3f9b0a66f7f5@mail.gmail.com> Message-ID: Thanks for you reply! I had tried the newest checkouts of rsepc and rspec-rails from git as well, but my locally installed rspec gem was 1.1.4 and apparently rake did use that instead! -- Siemen -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Fri Jul 18 11:20:35 2008 From: lists at ruby-forum.com (Gene Smith) Date: Fri, 18 Jul 2008 17:20:35 +0200 Subject: [rspec-users] We ain't got no RSpec In-Reply-To: <810a540e0807171453h12cbfedp5e7281b137f94155@mail.gmail.com> References: <1ddf4fbe7cd6c6bd400ab540001b5cf9@ruby-forum.com> <810a540e0807171453h12cbfedp5e7281b137f94155@mail.gmail.com> Message-ID: <07fc68e48178a4e5341c080998dd0542@ruby-forum.com> haha -- love it! -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Sat Jul 19 03:40:05 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 19 Jul 2008 03:40:05 -0400 Subject: [rspec-users] '$' placeholder naming can confuse your runner In-Reply-To: References: <810a540e0807160840u11322bbcsf5044edcd4392964@mail.gmail.com> Message-ID: <810a540e0807190040k7b9ac14fl32ca70c26fc6b98e@mail.gmail.com> Hey Paolo, I've fixed this. Update your rspec plugin and it should work fine now. Pat On Wed, Jul 16, 2008 at 12:07 PM, Paolo Dona wrote: > It is the common prefix, not the underscore. > With $n and $nnn or $ntotal still fails. > > Paolo > > On Jul 16, 4:40 pm, "Pat Maddox" wrote: >> What about when you make it $ntotal? Is it the common first letter or >> the underscore? >> >> Pat >> >> On 7/16/08, Paolo Dona wrote: >> >> > Hi guys, I'm facing a strange behavior that smells like a bug. >> >> > consider this scenario: >> >> > Scenario: I'm cool >> > Given that I am cool 4 times out of 7 >> >> > and this step: >> >> > Given("that I am cool $n times out of $n_total") do |n, n_total| >> > ... >> > end >> >> > When running my story, this step is considered as PENDING. >> > If I change the name of the second placeholder to $total, the step >> > runs fine (as it should, given that it's implemented). >> >> > My suspect is that when placeholders share a common prefix, the step >> > cannot be recognized correctly. >> > Anyone having the same issue? >> >> > btw: quoting the placeholders doesn't change this behavior >> >> > keep on with the great work, >> > Paolo >> > _______________________________________________ >> > 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 raasdnil at gmail.com Sat Jul 19 09:44:26 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Sat, 19 Jul 2008 23:44:26 +1000 Subject: [rspec-users] Specing a rails monkey patch In-Reply-To: <48806C3E.6010800@dancingtext.com> References: <48806C3E.6010800@dancingtext.com> Message-ID: <57a815bf0807190644x20049c7csf0870b01844d3fee@mail.gmail.com> On Fri, Jul 18, 2008 at 8:11 PM, Keith McDonnell wrote: > I wrote an ActiveRecord extension to emulate a db cursor: > http://pastie.org/236367 > As you can see, the spec doesn't really ensure that the records are fetched > in chunks. I'd like to mock the call to AR find and ensure that it's called > with an incrementing offset. I'm using cursors to walk a table with close to a million rows at times. I am just wrapping the action in a transaction and then declaring the cursor within the transaction and then walking the table with a find_by_sql with an SQL fetch command. It works well. Any reason you aren't doing it this way? Could just call it with a block... Mikel -- http://lindsaar.net/ Rails, RSpec and Life blog.... From paolo.dona at gmail.com Sun Jul 20 05:46:09 2008 From: paolo.dona at gmail.com (Paolo Dona) Date: Sun, 20 Jul 2008 02:46:09 -0700 (PDT) Subject: [rspec-users] '$' placeholder naming can confuse your runner In-Reply-To: <810a540e0807190040k7b9ac14fl32ca70c26fc6b98e@mail.gmail.com> References: <810a540e0807160840u11322bbcsf5044edcd4392964@mail.gmail.com> <810a540e0807190040k7b9ac14fl32ca70c26fc6b98e@mail.gmail.com> Message-ID: Thank you for your quick fix man! What if I'm testing a standalone app instead of a rails one? (I bet I need to wait for the next rspec release right?) Paolo On Jul 19, 8:40?am, "Pat Maddox" wrote: > Hey Paolo, > > I've fixed this. ?Update your rspec plugin and it should work fine now. > > Pat > > > > On Wed, Jul 16, 2008 at 12:07 PM, Paolo Dona wrote: > > It is the common prefix, not the underscore. > > With $n and $nnn or $ntotal still fails. > > > Paolo > > > On Jul 16, 4:40 pm, "Pat Maddox" wrote: > >> What about when you make it $ntotal? Is it the common first letter or > >> the underscore? > > >> Pat > > >> On 7/16/08, Paolo Dona wrote: > > >> > Hi guys, I'm facing a strange behavior that smells like a bug. > > >> > consider this scenario: > > >> > Scenario: I'm cool > >> > ? Given that I am cool 4 times out of 7 > > >> > and this step: > > >> > Given("that I am cool $n times out of $n_total") do |n, n_total| > >> > ? ... > >> > end > > >> > When running my story, this step is considered as PENDING. > >> > If I change the name of the second placeholder to $total, the step > >> > runs fine (as it should, given that it's implemented). > > >> > My suspect is that when placeholders share a common prefix, the step > >> > cannot be recognized correctly. > >> > Anyone having the same issue? > > >> > btw: quoting the placeholders doesn't change this behavior > > >> > keep on with the great work, > >> > Paolo > >> > _______________________________________________ > >> > rspec-users mailing list > >> > rspec-us... at rubyforge.org > >> >http://rubyforge.org/mailman/listinfo/rspec-users > > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.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 Sun Jul 20 08:46:51 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 20 Jul 2008 07:46:51 -0500 Subject: [rspec-users] '$' placeholder naming can confuse your runner In-Reply-To: References: <810a540e0807160840u11322bbcsf5044edcd4392964@mail.gmail.com> <810a540e0807190040k7b9ac14fl32ca70c26fc6b98e@mail.gmail.com> Message-ID: <57c63afe0807200546l58db68a6k9f09ece9bb084c32@mail.gmail.com> On Sun, Jul 20, 2008 at 4:46 AM, Paolo Dona wrote: > Thank you for your quick fix man! > What if I'm testing a standalone app instead of a rails one? (I bet I > need to wait for the next rspec release right?) git clone git://github.com/dchelimsky/rspec.git cd rspec rake gem rake install_gem TaDa! Cheers, David > > Paolo > > On Jul 19, 8:40 am, "Pat Maddox" wrote: >> Hey Paolo, >> >> I've fixed this. Update your rspec plugin and it should work fine now. >> >> Pat >> >> >> >> On Wed, Jul 16, 2008 at 12:07 PM, Paolo Dona wrote: >> > It is the common prefix, not the underscore. >> > With $n and $nnn or $ntotal still fails. >> >> > Paolo >> >> > On Jul 16, 4:40 pm, "Pat Maddox" wrote: >> >> What about when you make it $ntotal? Is it the common first letter or >> >> the underscore? >> >> >> Pat >> >> >> On 7/16/08, Paolo Dona wrote: >> >> >> > Hi guys, I'm facing a strange behavior that smells like a bug. >> >> >> > consider this scenario: >> >> >> > Scenario: I'm cool >> >> > Given that I am cool 4 times out of 7 >> >> >> > and this step: >> >> >> > Given("that I am cool $n times out of $n_total") do |n, n_total| >> >> > ... >> >> > end >> >> >> > When running my story, this step is considered as PENDING. >> >> > If I change the name of the second placeholder to $total, the step >> >> > runs fine (as it should, given that it's implemented). >> >> >> > My suspect is that when placeholders share a common prefix, the step >> >> > cannot be recognized correctly. >> >> > Anyone having the same issue? >> >> >> > btw: quoting the placeholders doesn't change this behavior >> >> >> > keep on with the great work, >> >> > Paolo >> >> > _______________________________________________ >> >> > rspec-users mailing list >> >> > rspec-us... at rubyforge.org >> >> >http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> _______________________________________________ >> >> rspec-users mailing list >> >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ >> > rspec-users mailing list >> > rspec-us... at rubyforge.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 cheef at list.ru Sun Jul 20 08:50:46 2008 From: cheef at list.ru (cheef) Date: Sun, 20 Jul 2008 05:50:46 -0700 (PDT) Subject: [rspec-users] Errors in controller test Message-ID: <18358354.post@talk.nabble.com> I catch very strange error while testing: NoMethodError in 'VotingsController handling POST /votings should redirect to index if success' You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.save Strange, because I'm stub my @voting. This is my test: describe "handling POST /votings" do before(:each) do login_user #login helper, stub login_requered and return @user @voting = mock_model(Voting) controller.stub!(:create_voting).and_return @voting end def do_post post :create end it "should redirect to index if success" do @voting.stub!(:save).and_return true do_post response.should redirect_to(votings_path) end #something else end And there is my controller: class VotingsController < ApplicationController before_filter :create_voting, :only => [:create] #some stuff there def create respond_to do |format| if @voting.save ... end end end private def create_voting @voting = Voting.new(params[:voting]) @voting.author = current_user end end P.S. but this tested fine def create @voting = Voting.new(params[:voting]) @voting.author = current_user respond_to do |format| if @voting.save ... end end end -- View this message in context: http://www.nabble.com/Errors-in-controller-test-tp18358354p18358354.html Sent from the rspec-users mailing list archive at Nabble.com. From mauricio.linhares at gmail.com Sun Jul 20 09:52:42 2008 From: mauricio.linhares at gmail.com (=?ISO-8859-1?Q?Maur=EDcio_Linhares?=) Date: Sun, 20 Jul 2008 10:52:42 -0300 Subject: [rspec-users] Errors in controller test In-Reply-To: <18358354.post@talk.nabble.com> References: <18358354.post@talk.nabble.com> Message-ID: You are stubbing the wrong method, try this: before(:each) do login_user #login helper, stub login_requered and return @user @voting = mock_model(Voting) Voting.stub!(:new).and_return( @voting ) end On Sun, Jul 20, 2008 at 9:50 AM, cheef wrote: > > I catch very strange error while testing: > > NoMethodError in 'VotingsController handling POST /votings should redirect > to index if success' > You have a nil object when you didn't expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.save > > Strange, because I'm stub my @voting. > > This is my test: > > describe "handling POST /votings" do > > before(:each) do > login_user #login helper, stub login_requered and return @user > @voting = mock_model(Voting) > controller.stub!(:create_voting).and_return @voting > end > > def do_post > post :create > end > > it "should redirect to index if success" do > @voting.stub!(:save).and_return true > do_post > response.should redirect_to(votings_path) > end > > #something else > > end > > And there is my controller: > > class VotingsController < ApplicationController > before_filter :create_voting, :only => [:create] > > #some stuff there > > def create > respond_to do |format| > if @voting.save > ... > end > end > end > > private > > def create_voting > @voting = Voting.new(params[:voting]) > @voting.author = current_user > end > > end > > P.S. but this tested fine > > def create > @voting = Voting.new(params[:voting]) > @voting.author = current_user > respond_to do |format| > if @voting.save > ... > end > end > end > -- > View this message in context: http://www.nabble.com/Errors-in-controller-test-tp18358354p18358354.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Maur?cio Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) Jo?o Pessoa, PB, +55 83 8867-7208 From twscannell at gmail.com Mon Jul 21 01:21:07 2008 From: twscannell at gmail.com (Teedub) Date: Sun, 20 Jul 2008 22:21:07 -0700 (PDT) Subject: [rspec-users] Newbie question, populate or ignore test db Message-ID: <34c82da2-a22c-46f7-b6a3-6e55b8d38cf2@z16g2000prn.googlegroups.com> Hi, I have been attempting to get rspec running on Ubuntu without much luck. I finally got it to go, but I can't figure out how to turn off the database access. I created a new test project named myspec Ran script/generate rspec and then so I would have restful routes, ran script/generate rspec_scaffold page title:string body:text Out of the box, 5 of the tests are failing because the test database is not being populated. This is probably a config issue, but after many hours, I can't figure what to do. Thanks in advance ActiveRecord::StatementInvalid in 'Page should create a new instance given valid attributes' Mysql::Error: Table 'myspec_test.pages' doesn't exist: SHOW FIELDS FROM `pages` ./spec/models/page_spec.rb:12: spec/views/pages/show.html.erb_spec.rb:3: ./spec/models/page_spec.rb:12: require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe Page do before(:each) do @valid_attributes = { :title => "value for title", :body => "value for body" } end it "should create a new instance given valid attributes" do Page.create!(@valid_attributes) #this is line 12 end end spec/views/pages/show.html.erb_spec.rb:3: require File.expand_path(File.dirname(__FILE__) + '/../../ spec_helper') describe "/pages/show.html.erb" do include PagesHelper #line 3 before(:each) do assigns[:page] = @page = stub_model(Page, :title => "value for title", :body => "value for body" ) end it "should render attributes in

" do render "/pages/show.html.erb" response.should have_text(/value\ for\ title/) response.should have_text(/value\ for\ body/) end end From david at digitalronin.com Mon Jul 21 03:27:34 2008 From: david at digitalronin.com (David Salgado) Date: Mon, 21 Jul 2008 08:27:34 +0100 Subject: [rspec-users] Newbie question, populate or ignore test db In-Reply-To: <34c82da2-a22c-46f7-b6a3-6e55b8d38cf2@z16g2000prn.googlegroups.com> References: <34c82da2-a22c-46f7-b6a3-6e55b8d38cf2@z16g2000prn.googlegroups.com> Message-ID: <8c90cb7d0807210027p3c12cdeft339b31099d5048a@mail.gmail.com> Have you created the database "myspec_test"? If not, try running "rake db:create:all". If you have created it, then perhaps the test db doesn't have the right tables. So, try "rake db:test:prepare". You'll need to do that after every migration as well. HTH David 2008/7/21 Teedub : > Hi, > > I have been attempting to get rspec running on Ubuntu without much > luck. > I finally got it to go, but I can't figure out how to turn off the > database access. > > I created a new test project named myspec > Ran > script/generate rspec > > and then so I would have restful routes, ran > script/generate rspec_scaffold page title:string body:text > > Out of the box, 5 of the tests are failing because the test database > is not being populated. This is probably a config issue, but after > many hours, I can't figure what to do. > > Thanks in advance > > ActiveRecord::StatementInvalid in 'Page should create a new instance > given valid attributes' > Mysql::Error: Table 'myspec_test.pages' doesn't exist: SHOW FIELDS > FROM `pages` > ./spec/models/page_spec.rb:12: > spec/views/pages/show.html.erb_spec.rb:3: > > > ./spec/models/page_spec.rb:12: > require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') > > describe Page do > before(:each) do > @valid_attributes = { > :title => "value for title", > :body => "value for body" > } > end > > it "should create a new instance given valid attributes" do > Page.create!(@valid_attributes) #this is line 12 > end > end > > > spec/views/pages/show.html.erb_spec.rb:3: > require File.expand_path(File.dirname(__FILE__) + '/../../ > spec_helper') > > describe "/pages/show.html.erb" do > include PagesHelper #line 3 > > before(:each) do > assigns[:page] = @page = stub_model(Page, > :title => "value for title", > :body => "value for body" > ) > end > > it "should render attributes in

" do > render "/pages/show.html.erb" > response.should have_text(/value\ for\ title/) > response.should have_text(/value\ for\ body/) > end > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From baz at madeofstone.net Mon Jul 21 04:01:50 2008 From: baz at madeofstone.net (Rahoul Baruah) Date: Mon, 21 Jul 2008 09:01:50 +0100 Subject: [rspec-users] Newbie question, populate or ignore test db In-Reply-To: <8c90cb7d0807210027p3c12cdeft339b31099d5048a@mail.gmail.com> References: <34c82da2-a22c-46f7-b6a3-6e55b8d38cf2@z16g2000prn.googlegroups.com> <8c90cb7d0807210027p3c12cdeft339b31099d5048a@mail.gmail.com> Message-ID: On 21 Jul 2008, at 08:27, David Salgado wrote: > If you have created it, then perhaps the test db doesn't have the > right tables. So, try "rake db:test:prepare". You'll need to do that > after every migration as well. Once your test database is built, using "rake spec" should ensure that your test database matches the structure of your dev database, before running your specifications. Baz. Rahoul Baruah Web design and development: http://www.3hv.co.uk/ Serious Rails Hosting: http://www.brightbox.co.uk/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From keith at dancingtext.com Mon Jul 21 04:38:36 2008 From: keith at dancingtext.com (Keith McDonnell) Date: Mon, 21 Jul 2008 10:38:36 +0200 Subject: [rspec-users] Specing a rails monkey patch In-Reply-To: References: Message-ID: <48844B0C.1050804@dancingtext.com> Hi Mikel, Thanks for the feedback. Much appreciated. >I'm using cursors to walk a table with close to a million rows at times. > >I am just wrapping the action in a transaction and then declaring the >cursor within the transaction and then walking the table with a >find_by_sql with an SQL fetch command. > >It works well. > >Any reason you aren't doing it this way? Could just call it with a block... I /could/ use an SQL cursor but: - I wanted to write a method that could be re-used by the other developers on the team. - our code base is polluted with SQL, ostensibly for "performance" reasons. I'm trying to refactor out unnecessary SQL. - raw speed is less important that ensuring that the production db doesn't crash, ie it doesn't matter if the updates take an hour or two once the live site doesn't slow down considerably. Our max # rows is 3.3 million. I don't know if these are valid reasons however :) Thanks for your suggested solution (transaction, cursor, find_by_sql & fetch). I'll play around with it & see what I can do. Can't immediately envision how to spec it though. Keith From loop at superinfinite.com Mon Jul 21 11:36:23 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Mon, 21 Jul 2008 17:36:23 +0200 Subject: [rspec-users] Specifying a few valid values In-Reply-To: <57c63afe0807171622n7c1b44fte96d41fa469a8f5@mail.gmail.com> References: <1216293529.8532.8.camel@tybalt> <57c63afe0807170528n5d3f6249yf65eccd6c36cbc0a@mail.gmail.com> <1216298421.8532.31.camel@tybalt> <1216304348.8532.46.camel@tybalt> <85d99afe0807170737s33159edbiad24f0d9bc35e805@mail.gmail.com> <57c63afe0807170740t534f8248jfbe6b4a570ad7562@mail.gmail.com> <1216310689.8532.49.camel@tybalt> <57c63afe0807171622n7c1b44fte96d41fa469a8f5@mail.gmail.com> Message-ID: On 18-jul-2008, at 1:22, David Chelimsky wrote: > On Thu, Jul 17, 2008 at 11:04 AM, Jonathan Leighton > wrote: >> On Thu, 2008-07-17 at 09:40 -0500, David Chelimsky wrote: >>> On Thu, Jul 17, 2008 at 9:37 AM, Zach Dennis >>> wrote: >>>> Perhaps... >>>> >>>> When "I login with invalid credentials" >>>> Then "I see that I have not been logged in" >>> >>> Or .... >>> >>> When I login with invalid credentials >>> Then I should see the login form >>> And I should see a message saying "Something went wrong." >> >> What would be the implementation of "Then I should see the login >> form"? >> We are already testing for an error message :) > > As with all things, context is everything. Definately. For what it's worth, my approach: I use the "should see the form | page" construct a lot when implementing new functionality. I expect a form with just response.should have_tag('form[action=?]', blogposts_path), and spec the form fields in my view specs. This ensures that my integration tests won't necessarily break when I change a form field, but it does get picked up by the view specs. After I'm done prototyping, I write higher level stories dealing with the flow of the functionality. gr, bartz > > *If* I were going to have such a step, I'd do it based on things in > the form: > > Then "should see the login form" do > response.should have_tag('input#login') > response.should have_tag('input#password') > end > > That's more granular than I generally like, but that's what probably > what I'd do in this scenario. From lists at ruby-forum.com Mon Jul 21 19:33:08 2008 From: lists at ruby-forum.com (Macario Ortega) Date: Tue, 22 Jul 2008 01:33:08 +0200 Subject: [rspec-users] Failing on rake but not on textmate (rails) Message-ID: <9d557867dbb34a255e62911d9bcd0777@ruby-forum.com> I have a spec for a model that passes all tests if I run it using textmate but I run rake some of the otherwise passed tests fail. I would like to use autotest but I can't trust the results. Any ideas? -- Posted via http://www.ruby-forum.com/. From mark.wilden at gmail.com Mon Jul 21 20:34:43 2008 From: mark.wilden at gmail.com (Mark Wilden) Date: Mon, 21 Jul 2008 17:34:43 -0700 Subject: [rspec-users] Failing on rake but not on textmate (rails) In-Reply-To: <3c30da400807211732s6b33cb98h1fcbb1d376e78d8f@mail.gmail.com> References: <9d557867dbb34a255e62911d9bcd0777@ruby-forum.com> <3c30da400807211732s6b33cb98h1fcbb1d376e78d8f@mail.gmail.com> Message-ID: <3c30da400807211734v17b78678n277905695bddf331@mail.gmail.com> On Mon, Jul 21, 2008 at 4:33 PM, Macario Ortega wrote: > > I have a spec for a model that passes all tests if I run it using > textmate but I run rake some of the otherwise passed tests fail. > AFAIK, the main difference is that rake copies the development db structure to the test db, whereas TextMate does not (and runs faster as a result). I don't know if that explains the behavior you're seeing. > I would like to use autotest but I can't trust the results. > autotest also does not copy the database structure. I've been using it for six months and I've never noticed a problem with it. Why don't you trust it? ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From twscannell at gmail.com Tue Jul 22 00:43:53 2008 From: twscannell at gmail.com (Teedub) Date: Mon, 21 Jul 2008 21:43:53 -0700 (PDT) Subject: [rspec-users] Newbie question, populate or ignore test db In-Reply-To: References: <34c82da2-a22c-46f7-b6a3-6e55b8d38cf2@z16g2000prn.googlegroups.com> <8c90cb7d0807210027p3c12cdeft339b31099d5048a@mail.gmail.com> Message-ID: Thanks rake db:test:prepare did the trick. I am still a bit confused as to why rake cares about a database that it isn't using. But I guess that will all fall into place in my brain one day. Teedub On Jul 21, 1:01?am, Rahoul Baruah wrote: > On 21 Jul 2008, at 08:27, David Salgado wrote: > > > If you have created it, then perhaps the test db doesn't have the > > right tables. So, try "rake db:test:prepare". You'll need to do that > > after every migration as well. > > Once your test database is built, using "rake spec" should ensure ? > that your test database matches the structure of your dev database, ? > before running your specifications. > > Baz. > > Rahoul Baruah > Web design and development:http://www.3hv.co.uk/ > Serious Rails Hosting:http://www.brightbox.co.uk/ > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From loop at superinfinite.com Tue Jul 22 03:09:05 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Tue, 22 Jul 2008 09:09:05 +0200 Subject: [rspec-users] Newbie question, populate or ignore test db In-Reply-To: References: <34c82da2-a22c-46f7-b6a3-6e55b8d38cf2@z16g2000prn.googlegroups.com> <8c90cb7d0807210027p3c12cdeft339b31099d5048a@mail.gmail.com> Message-ID: <9116C0F4-7636-46CD-9D74-82618572FC9F@superinfinite.com> On 22-jul-2008, at 6:43, Teedub wrote: > Thanks > rake db:test:prepare did the trick. I am still a bit confused as to > why rake cares about a database that it isn't using. > But I guess that will all fall into place in my brain one day. Well, the test database is for ehrm, testing :). So rake is actually using it. gr, bartz > On Jul 21, 1:01 am, Rahoul Baruah wrote: >> On 21 Jul 2008, at 08:27, David Salgado wrote: >> >>> If you have created it, then perhaps the test db doesn't have the >>> right tables. So, try "rake db:test:prepare". You'll need to do that >>> after every migration as well. >> >> Once your test database is built, using "rake spec" should ensure >> that your test database matches the structure of your dev database, >> before running your specifications. >> >> Baz. >> >> Rahoul Baruah >> Web design and development:http://www.3hv.co.uk/ >> Serious Rails Hosting:http://www.brightbox.co.uk/ >> >> _______________________________________________ >> 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 rick.denatale at gmail.com Tue Jul 22 08:06:28 2008 From: rick.denatale at gmail.com (Rick DeNatale) Date: Tue, 22 Jul 2008 08:06:28 -0400 Subject: [rspec-users] Failing on rake but not on textmate (rails) In-Reply-To: <3c30da400807211734v17b78678n277905695bddf331@mail.gmail.com> References: <9d557867dbb34a255e62911d9bcd0777@ruby-forum.com> <3c30da400807211732s6b33cb98h1fcbb1d376e78d8f@mail.gmail.com> <3c30da400807211734v17b78678n277905695bddf331@mail.gmail.com> Message-ID: On Mon, Jul 21, 2008 at 8:34 PM, Mark Wilden wrote: > On Mon, Jul 21, 2008 at 4:33 PM, Macario Ortega > wrote: > >> >> I have a spec for a model that passes all tests if I run it using >> textmate but I run rake some of the otherwise passed tests fail. >> > > AFAIK, the main difference is that rake copies the development db structure > to the test db, whereas TextMate does not (and runs faster as a result). I > don't know if that explains the behavior you're seeing. > > >> I would like to use autotest but I can't trust the results. >> > > autotest also does not copy the database structure. I've been using it for > six months and I've never noticed a problem with it. Why don't you trust it? > > I doubt that it's a problem with not copy the database structure from dev to test. That sync's the db schema and would only be needed after a schema change (i.e. one or more migrations have been run), and it would be much more likely to cause a failure in Textmate when the code under test doesn't see the expected db schema. It's more likely that there are undeclared fixtures affecting the spec, a spec which needs particular state in the database might succeed or not depending on whether or not previous specs either left data behind, or deleted data needed by the spec in question. When I've seen cases where test/specs behaved differently when run separately vs. being run in batch (e.g. by Rake) it's almost always because I left out a fixture declaration. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From mileshosky at hotmail.com Tue Jul 22 12:26:15 2008 From: mileshosky at hotmail.com (Britt Mileshosky) Date: Tue, 22 Jul 2008 09:26:15 -0700 Subject: [rspec-users] Funny single line of rspec_code Message-ID: So lastnight I was writing a fake controller to test some before filter action. I found myself writing this line of code that I thought was funny ... maybe its a subtle indication i've been programming to much lately. get :some_action HA! _________________________________________________________________ Use video conversation to talk face-to-face with Windows Live Messenger. http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_video_072008 From dchelimsky at gmail.com Tue Jul 22 12:41:17 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 22 Jul 2008 11:41:17 -0500 Subject: [rspec-users] Funny single line of rspec_code In-Reply-To: References: Message-ID: <57c63afe0807220941v1c7e8fa7s31e314fa9bc1059b@mail.gmail.com> On Tue, Jul 22, 2008 at 11:26 AM, Britt Mileshosky wrote: > > So lastnight I was writing a fake controller to test some before filter action. > I found myself writing this line of code that I thought was funny ... maybe its > a subtle indication i've been programming to much lately. > > get :some_action Search for that string in the rspec-rails specs. Double HA! > > HA! > _________________________________________________________________ > Use video conversation to talk face-to-face with Windows Live Messenger. > http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_video_072008 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Tue Jul 22 13:56:02 2008 From: lists at ruby-forum.com (Macario Ortega) Date: Tue, 22 Jul 2008 19:56:02 +0200 Subject: [rspec-users] Failing on rake but not on textmate (rails) In-Reply-To: <3c30da400807211734v17b78678n277905695bddf331@mail.gmail.com> References: <9d557867dbb34a255e62911d9bcd0777@ruby-forum.com> <3c30da400807211734v17b78678n277905695bddf331@mail.gmail.com> Message-ID: <7dd9f1c116577cb3139a0af88660f1ab@ruby-forum.com> Mark Wilden wrote: > On Mon, Jul 21, 2008 at 4:33 PM, Macario Ortega > wrote: > >> >> I have a spec for a model that passes all tests if I run it using >> textmate but I run rake some of the otherwise passed tests fail. >> > > AFAIK, the main difference is that rake copies the development db > structure > to the test db, whereas TextMate does not (and runs faster as a result). > I > don't know if that explains the behavior you're seeing. > > >> I would like to use autotest but I can't trust the results. >> > > autotest also does not copy the database structure. I've been using it > for > six months and I've never noticed a problem with it. Why don't you trust > it? > > ///ark Well I don't trust autotest because the same tests pass when i run them from textmate and they fail when I run autotest. The dubbious specs are all for a specific model but some of them are very basic such as testing validates_presence_of in which the model code is obviously good and yet the spec fails on rake or autotest. So I've been running my specs just on textmate but I would like to use autotest too. -- Posted via http://www.ruby-forum.com/. From steve at deepsalt.com Tue Jul 22 16:24:36 2008 From: steve at deepsalt.com (Steve Eley) Date: Tue, 22 Jul 2008 16:24:36 -0400 Subject: [rspec-users] Failing on rake but not on textmate (rails) In-Reply-To: <7dd9f1c116577cb3139a0af88660f1ab@ruby-forum.com> References: <9d557867dbb34a255e62911d9bcd0777@ruby-forum.com> <3c30da400807211734v17b78678n277905695bddf331@mail.gmail.com> <7dd9f1c116577cb3139a0af88660f1ab@ruby-forum.com> Message-ID: <74243c220807221324i2e0866e5se4f996ce0ae7b931@mail.gmail.com> On Tue, Jul 22, 2008 at 1:56 PM, Macario Ortega wrote: > > Well I don't trust autotest because the same tests pass when i run them > from textmate and they fail when I run autotest. > > The dubbious specs are all for a specific model but some of them are > very basic such as testing validates_presence_of in which the model code > is obviously good and yet the spec fails on rake or autotest. I've had this happen before, and it turned out to be a state problem. Things I did in one spec file were altering the state of the application, so that spec files run after it would fail in certain ways. Thus, passing or failing was entirely dependent on the *order* the files were run in. Rake runs things in a different order than autotest, so different tests were failing; and running a single file by itself always passed. In my case the state change was stupid and totally unnecessary. At the time I didn't really understand mocking and stubbing, so I was trying to bypass my authentication code in my specs by reopening the authentication modules in lib/ and overriding the live logged_in? method to return 'true'. This worked, but I didn't realize the overrides would continue to be in place for all future specs. And quite naturally, some of the specs for restful_authentication were failing. I wasted hours figuring that one out. The moral I learned was, don't EVER try to screw with your actual application code in a spec, and make sure that nothing you do in a spec leaves a permanent change in memory. I can't know if that's your problem, of course, but it's something to think about. -- Have Fun, Steve Eley Deep Salt Team From xtrmclmb at gmail.com Tue Jul 22 21:36:12 2008 From: xtrmclmb at gmail.com (Camilo Torres) Date: Wed, 23 Jul 2008 21:06:12 +1930 Subject: [rspec-users] [HELP] should receive :new but does not Message-ID: <5e2dde260807221836l1792b133ke42fec8cd5b63a24@mail.gmail.com> Hello, I am learning rspec/rspec-rails and ruby on rails. Controller: class IssuesController < ApplicationController def index end def new @issue = Issue.new end def create @issue = Issue.new(params[:issue]) @issue.save end end Spec: require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper.rb')) describe IssuesController do it 'should sucess on index' do get :index response.should be_success end describe 'create new issue' do it 'should success on new' do get :new response.should be_success end it 'should pass a new Issue to the view' do issue = mock_model(Issue) Issue.stub!(:new).and_return(issue) get :new assigns[:issue].should == issue end end describe 'saving with right data' do it 'should save the issue' do issue = mock_model(Issue) Issue.stub!(:new).and_return(issue) issue.stub!(:save).and_return(:true) post :create, { :issue => {:title => 'some title', :description => 'some more data to describe'}} assigns[:issue].should == issue end end describe 'when saving wrong data' do # before(:each) do # @issue = mock_model(Issue) # @issue.stub!(:save).and_return(:false) # Issue.stub!(:new).and_return(@issue) # end # def post_create # post :create, { :issue => {:title => 'some title', :description => 'some more data to describe'}} # end it 'should not save the issue' do @issue = mock_model(Issue) @issue.stub!(:save).and_return(:false) Issue.stub!(:new).and_return(@issue) post :create, { :issue => {:title => 'some title', :description => ''}} @issue.should_receive(:save).and_return(:false) end # it 'should flash the failure to save' do # end end end Error: F.... 1) Spec::Mocks::MockExpectationError in 'IssuesController when saving wrong data should not save the issue' Mock 'Issue_1001' expected :save with (any args) once, but received it 0 times spec/controllers/issues_controler_spec.rb:51: spec/controllers/issues_controler_spec.rb:3: Finished in 0.282526 seconds 5 examples, 1 failure I am running script/autospec. ?What is wrong? I don't understand why this spec is not passing. I have tried before(:each) and a helper method, but got the same. Please, help. From mauricio.linhares at gmail.com Tue Jul 22 21:43:35 2008 From: mauricio.linhares at gmail.com (=?ISO-8859-1?Q?Maur=EDcio_Linhares?=) Date: Tue, 22 Jul 2008 22:43:35 -0300 Subject: [rspec-users] [HELP] should receive :new but does not In-Reply-To: <5e2dde260807221836l1792b133ke42fec8cd5b63a24@mail.gmail.com> References: <5e2dde260807221836l1792b133ke42fec8cd5b63a24@mail.gmail.com> Message-ID: The "should_receive" should appear before the "post :create" (look at this for a better explanation -> http://rubyforge.org/pipermail/rspec-users/2008-June/007342.html ) it 'should not save the issue' do @issue = mock_model(Issue) @issue.stub!(:save).and_return(:false) Issue.stub!(:new).and_return(@issue) @issue.should_receive(:save).and_return(:false) # you should define the "should receive" before calling "post :create" post :create, { :issue => {:title => 'some title', :description => ''}} end On Tue, Jul 22, 2008 at 10:36 PM, Camilo Torres wrote: > > Hello, I am learning rspec/rspec-rails and ruby on rails. > > Controller: > class IssuesController < ApplicationController > def index > > end > > def new > @issue = Issue.new > end > > def create > @issue = Issue.new(params[:issue]) > @issue.save > end > end > > Spec: > require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper.rb')) > > describe IssuesController do > it 'should sucess on index' do > get :index > response.should be_success > end > > describe 'create new issue' do > it 'should success on new' do > get :new > response.should be_success > end > > it 'should pass a new Issue to the view' do > issue = mock_model(Issue) > Issue.stub!(:new).and_return(issue) > get :new > assigns[:issue].should == issue > end > end > > describe 'saving with right data' do > it 'should save the issue' do > issue = mock_model(Issue) > Issue.stub!(:new).and_return(issue) > issue.stub!(:save).and_return(:true) > post :create, { :issue => {:title => 'some title', :description => > 'some more data to describe'}} > assigns[:issue].should == issue > end > end > > describe 'when saving wrong data' do > # before(:each) do > # @issue = mock_model(Issue) > # @issue.stub!(:save).and_return(:false) > # Issue.stub!(:new).and_return(@issue) > # end > > # def post_create > # post :create, { :issue => {:title => 'some title', :description => > 'some more data to describe'}} > # end > > it 'should not save the issue' do > @issue = mock_model(Issue) > @issue.stub!(:save).and_return(:false) > Issue.stub!(:new).and_return(@issue) > > post :create, { :issue => {:title => 'some title', :description => ''}} > > @issue.should_receive(:save).and_return(:false) > end > > # it 'should flash the failure to save' do > > # end > end > end > > Error: > F.... > > 1) > Spec::Mocks::MockExpectationError in 'IssuesController when saving > wrong data should not save the issue' > Mock 'Issue_1001' expected :save with (any args) once, but received it 0 times > spec/controllers/issues_controler_spec.rb:51: > spec/controllers/issues_controler_spec.rb:3: > > Finished in 0.282526 seconds > > 5 examples, 1 failure > > > > I am running script/autospec. > > ?What is wrong? I don't understand why this spec is not passing. I > have tried before(:each) and a helper method, but got the same. > > Please, help. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -- Maur?cio Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) Jo?o Pessoa, PB, +55 83 8867-7208 From xtrmclmb at gmail.com Tue Jul 22 22:03:05 2008 From: xtrmclmb at gmail.com (Camilo Torres) Date: Wed, 23 Jul 2008 21:33:05 +1930 Subject: [rspec-users] [HELP] should receive :new but does not In-Reply-To: References: <5e2dde260807221836l1792b133ke42fec8cd5b63a24@mail.gmail.com> Message-ID: <5e2dde260807221903x4bb961dve0d4b7479c14b25a@mail.gmail.com> thanks Maur?cio, I read your link. It worked. 2008/7/23 Maur?cio Linhares : > The "should_receive" should appear before the "post :create" (look at > this for a better explanation -> > http://rubyforge.org/pipermail/rspec-users/2008-June/007342.html ) > > it 'should not save the issue' do > @issue = mock_model(Issue) > @issue.stub!(:save).and_return(:false) > > Issue.stub!(:new).and_return(@issue) > @issue.should_receive(:save).and_return(:false) > # you should define the "should receive" before calling "post :create" > > post :create, { :issue => {:title => 'some > title', :description => ''}} > end > > On Tue, Jul 22, 2008 at 10:36 PM, Camilo Torres wrote: >> >> Hello, I am learning rspec/rspec-rails and ruby on rails. >> >> Controller: >> class IssuesController < ApplicationController >> def index >> >> end >> >> def new >> @issue = Issue.new >> end >> >> def create >> @issue = Issue.new(params[:issue]) >> @issue.save >> end >> end >> >> Spec: >> require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper.rb')) >> >> describe IssuesController do >> it 'should sucess on index' do >> get :index >> response.should be_success >> end >> >> describe 'create new issue' do >> it 'should success on new' do >> get :new >> response.should be_success >> end >> >> it 'should pass a new Issue to the view' do >> issue = mock_model(Issue) >> Issue.stub!(:new).and_return(issue) >> get :new >> assigns[:issue].should == issue >> end >> end >> >> describe 'saving with right data' do >> it 'should save the issue' do >> issue = mock_model(Issue) >> Issue.stub!(:new).and_return(issue) >> issue.stub!(:save).and_return(:true) >> post :create, { :issue => {:title => 'some title', :description => >> 'some more data to describe'}} >> assigns[:issue].should == issue >> end >> end >> >> describe 'when saving wrong data' do >> # before(:each) do >> # @issue = mock_model(Issue) >> # @issue.stub!(:save).and_return(:false) >> # Issue.stub!(:new).and_return(@issue) >> # end >> >> # def post_create >> # post :create, { :issue => {:title => 'some title', :description => >> 'some more data to describe'}} >> # end >> >> it 'should not save the issue' do >> @issue = mock_model(Issue) >> @issue.stub!(:save).and_return(:false) >> Issue.stub!(:new).and_return(@issue) >> >> post :create, { :issue => {:title => 'some title', :description => ''}} >> >> @issue.should_receive(:save).and_return(:false) >> end >> >> # it 'should flash the failure to save' do >> >> # end >> end >> end >> >> Error: >> F.... >> >> 1) >> Spec::Mocks::MockExpectationError in 'IssuesController when saving >> wrong data should not save the issue' >> Mock 'Issue_1001' expected :save with (any args) once, but received it 0 times >> spec/controllers/issues_controler_spec.rb:51: >> spec/controllers/issues_controler_spec.rb:3: >> >> Finished in 0.282526 seconds >> >> 5 examples, 1 failure >> >> >> >> I am running script/autospec. >> >> ?What is wrong? I don't understand why this spec is not passing. I >> have tried before(:each) and a helper method, but got the same. >> >> Please, help. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > > -- > Maur?cio Linhares > http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) > Jo?o Pessoa, PB, +55 83 8867-7208 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Tue Jul 22 22:37:28 2008 From: lists at ruby-forum.com (Ry An) Date: Wed, 23 Jul 2008 04:37:28 +0200 Subject: [rspec-users] Rspec - stubbing same class multiple times with different co Message-ID: <5560226ae7f676cc8cda7bb3f933534a@ruby-forum.com> Im having a hard time with a rspec controller test im writting, I need to stub! the User.find call twice once to return the owning user and once to return the viewing user. however when I attempt User.stub!(:find).with(1).and_return(@user) User.stub!(:find).with(2).and_return(@user2) the second call returns undefined local variable or method `find' for # I've managed to replicate the behavior outside of this specific test and I know the code works as I can test it manually. Any ideas as to why this is not working? or better still how to get it working. Thanks for the help in advance -- Posted via http://www.ruby-forum.com/. From loriolson at me.com Wed Jul 23 00:06:58 2008 From: loriolson at me.com (Lori M Olson) Date: Tue, 22 Jul 2008 22:06:58 -0600 Subject: [rspec-users] Rspec - stubbing same class multiple times with different co In-Reply-To: <5560226ae7f676cc8cda7bb3f933534a@ruby-forum.com> References: <5560226ae7f676cc8cda7bb3f933534a@ruby-forum.com> Message-ID: <43176AC4-473A-4E02-9591-B77594881BCC@me.com> Have you tried using should_receive instead of stub! ? Sent from my iPhone On 22-Jul-08, at 8:37 PM, Ry An wrote: > Im having a hard time with a rspec controller test im writting, I need > to stub! the User.find call twice once to return the owning user and > once to return the viewing user. however when I attempt > > User.stub!(:find).with(1).and_return(@user) > User.stub!(:find).with(2).and_return(@user2) > > the second call returns > undefined local variable or method `find' for # > > I've managed to replicate the behavior outside of this specific test > and > I know the code works as I can test it manually. > > Any ideas as to why this is not working? or better still how to get it > working. > > Thanks for the help in advance > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Wed Jul 23 01:18:06 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Jul 2008 00:18:06 -0500 Subject: [rspec-users] Rspec - stubbing same class multiple times with different co In-Reply-To: <5560226ae7f676cc8cda7bb3f933534a@ruby-forum.com> References: <5560226ae7f676cc8cda7bb3f933534a@ruby-forum.com> Message-ID: <57c63afe0807222218w58931083q70e3d3b733fb0f59@mail.gmail.com> On Tue, Jul 22, 2008 at 9:37 PM, Ry An wrote: > Im having a hard time with a rspec controller test im writting, I need > to stub! the User.find call twice once to return the owning user and > once to return the viewing user. however when I attempt > > User.stub!(:find).with(1).and_return(@user) > User.stub!(:find).with(2).and_return(@user2) > > the second call returns > undefined local variable or method `find' for # > > I've managed to replicate the behavior outside of this specific test and > I know the code works as I can test it manually. > > Any ideas as to why this is not working? Not without more context. What you seem to be trying to do should work. Would please post the code of the spec (including any before blocks) and the code for the action in question? Thanks, David > or better still how to get it > working. > > Thanks for the help in advance > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From tero at tilus.net Wed Jul 23 00:56:16 2008 From: tero at tilus.net (Tero Tilus) Date: Wed, 23 Jul 2008 07:56:16 +0300 Subject: [rspec-users] Rspec - stubbing same class multiple times with different co In-Reply-To: <5560226ae7f676cc8cda7bb3f933534a@ruby-forum.com> References: <5560226ae7f676cc8cda7bb3f933534a@ruby-forum.com> Message-ID: <20080723045615.GN24488@uivelo.tilus.net> 2008-07-23 04:37, Ry An: > User.stub!(:find).with(1).and_return(@user) > User.stub!(:find).with(2).and_return(@user2) > > the second call returns > undefined local variable or method `find' for > # This is a kludge, but you might be able to work around your situation using User.stub!(:find).and_return { ... calculate retval ... } or User.stub!(:find).and_return(@user, @user2) see http://rspec.info/documentation/mocks/stubs.html > Any ideas as to why this is not working? or better still how to get > it working. Uhh, no idea, sorry. -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ From raasdnil at gmail.com Wed Jul 23 03:17:27 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Wed, 23 Jul 2008 17:17:27 +1000 Subject: [rspec-users] Specing a rails monkey patch In-Reply-To: <48844B0C.1050804@dancingtext.com> References: <48844B0C.1050804@dancingtext.com> Message-ID: <57a815bf0807230017h2445e7dcq4a6e602b2128aea@mail.gmail.com> On Mon, Jul 21, 2008 at 6:38 PM, Keith McDonnell wrote: > I /could/ use an SQL cursor but: > I don't know if these are valid reasons however :) The only thing you gain with a direct SQL cursor is the guarantee of hitting each row exactly once without having to pull down all the IDs into an array first. > Thanks for your suggested solution (transaction, cursor, find_by_sql & > fetch). I'll play around with it & see what I can do. Can't immediately > envision how to spec it though. You'd stub out the model. class Record end -- http://lindsaar.net/ Rails, RSpec and Life blog.... From raasdnil at gmail.com Wed Jul 23 03:22:36 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Wed, 23 Jul 2008 17:22:36 +1000 Subject: [rspec-users] Specing a rails monkey patch In-Reply-To: <57a815bf0807230017h2445e7dcq4a6e602b2128aea@mail.gmail.com> References: <48844B0C.1050804@dancingtext.com> <57a815bf0807230017h2445e7dcq4a6e602b2128aea@mail.gmail.com> Message-ID: <57a815bf0807230022y440f9b55h75b6fe8972d412fe@mail.gmail.com> Sorry, hit the tab and enter key too soon :) You'd stub out the model. class DummyModel acts_as_curseable end it "should ask the database to set up a transaction" do DummyModel.connection.should_receive("BEGIN;").once ... then the execution code to make that happen end it "should ask the database to set up a cursor" do DummyModel.connection.should_receive("DECLARE dummy_model_cursor CURSOR FOR...;").once ... then the execution code to make that happen end it "should tell the database to give it another X rows" do DummyModel.should_receive(:find_by_sql).with("FETCH 500 FROM dummy_model_cursor;") ... then the execution code to make that happen end Hope that sort of starts you off :) And if you like 'acts_as_curseable' for the plugin name, I want acknowledgement :D -- http://lindsaar.net/ Rails, RSpec and Life blog.... From lists at ruby-forum.com Wed Jul 23 09:52:23 2008 From: lists at ruby-forum.com (Ann Hu) Date: Wed, 23 Jul 2008 15:52:23 +0200 Subject: [rspec-users] wholesale and retail Message-ID: <4da906efe002ea39aec7bc069a873036@ruby-forum.com> fashion in china Attachments: http://www.ruby-forum.com/attachment/2442/599260225417414177.jpg -- Posted via http://www.ruby-forum.com/. From j at jonathanleighton.com Wed Jul 23 12:16:23 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Wed, 23 Jul 2008 17:16:23 +0100 Subject: [rspec-users] Routes not working properly inside "helper" Message-ID: <1216829783.18020.30.camel@tybalt> I have been upgrading my helper specs due to the recent change regarding mixing in modules: http://blog.davidchelimsky.net/2008/5/29/rspec-waving-bye-bye-to-implicit-module-inclusion Unfortunately I have hit a snag. It seems that when the helper uses routes I get an error about a nil object. For instance, if one of my helper methods calls the route "new_company_path", I get the following error: You have a nil object when you didn't expect it! The error occurred while evaluating nil.url_for (eval):45:in `new_company_path' RAILS_ROOT/app/helpers/application_helper.rb:64:in `format_address' ./spec/helpers/application_helper_spec.rb:151: If I include the module directly into the spec it works fine. Any ideas? Cheers, Jon From dchelimsky at gmail.com Wed Jul 23 12:28:38 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 23 Jul 2008 11:28:38 -0500 Subject: [rspec-users] Routes not working properly inside "helper" In-Reply-To: <1216829783.18020.30.camel@tybalt> References: <1216829783.18020.30.camel@tybalt> Message-ID: <57c63afe0807230928y6e8a350fi25efb5be1731403@mail.gmail.com> That's a bug in 1.1.4 which is fixed in git. If you grab the latest you should be OK. On Wed, Jul 23, 2008 at 11:16 AM, Jonathan Leighton wrote: > I have been upgrading my helper specs due to the recent change regarding > mixing in modules: > http://blog.davidchelimsky.net/2008/5/29/rspec-waving-bye-bye-to-implicit-module-inclusion > > Unfortunately I have hit a snag. It seems that when the helper uses > routes I get an error about a nil object. For instance, if one of my > helper methods calls the route "new_company_path", I get the following > error: > > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.url_for > (eval):45:in `new_company_path' > RAILS_ROOT/app/helpers/application_helper.rb:64:in `format_address' > ./spec/helpers/application_helper_spec.rb:151: > > If I include the module directly into the spec it works fine. > > Any ideas? > > Cheers, > Jon > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ml at e4net.com Thu Jul 24 07:13:46 2008 From: ml at e4net.com (Jim Morris) Date: Thu, 24 Jul 2008 04:13:46 -0700 Subject: [rspec-users] Running all stories in a directory Message-ID: <488863EA.3040008@e4net.com> I have a bunch on non-rails stories, and I want to run them all with either a rake task or a script. I tried the all.rb approach from rails, but is doesn't seem to work. I do this basically... dir = File.dirname(__FILE__) tests= [] %w(story1 story2 story3).each do |f| tests << File.join(dir, f) + ".rb" end puts "Testing: #{tests.join(',')}" tests.each do |file| require file end Should this work? Some of the stories run OK, but some seem to not be setup properly, they run fine if run individually from the command line as... > ruby story2.rb -- Jim Morris, http://blog.wolfman.com From ml at e4net.com Thu Jul 24 07:22:46 2008 From: ml at e4net.com (Jim Morris) Date: Thu, 24 Jul 2008 04:22:46 -0700 Subject: [rspec-users] Running all stories in a directory In-Reply-To: <488863EA.3040008@e4net.com> References: <488863EA.3040008@e4net.com> Message-ID: <48886606.10800@e4net.com> Jim Morris wrote: > I have a bunch on non-rails stories, and I want to run them all with > either a rake task or a script. > > I tried the all.rb approach from rails, but is doesn't seem to work. > > I do this basically... > > dir = File.dirname(__FILE__) > tests= [] > %w(story1 story2 story3).each do |f| > tests << File.join(dir, f) + ".rb" > end > > puts "Testing: #{tests.join(',')}" > > tests.each do |file| > require file > end > > Should this work? > > Some of the stories run OK, but some seem to not be setup properly, they > run fine if run individually from the command line as... > > > ruby story2.rb > > This does work BTW... replace require file with system('ruby', 'file') -- Jim Morris, http://blog.wolfman.com From j at jonathanleighton.com Thu Jul 24 08:32:14 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Thu, 24 Jul 2008 13:32:14 +0100 Subject: [rspec-users] HTML Story Formatter Message-ID: <1216902734.7340.14.camel@tybalt> Hiya, I am trying to use the HTML Story Formatter in conjunction with CruiseControl.rb. I have got it outputting the stories to a file, but I notice there are CSS and JS files linked in the head, which don't appear to be anywhere in the rspec repository. Are these files available and if so where? Cheers, Jon From dchelimsky at gmail.com Thu Jul 24 08:44:35 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 24 Jul 2008 07:44:35 -0500 Subject: [rspec-users] HTML Story Formatter In-Reply-To: <1216902734.7340.14.camel@tybalt> References: <1216902734.7340.14.camel@tybalt> Message-ID: <57c63afe0807240544p5a8adc2keaa21aac0ca1fe0e@mail.gmail.com> On Thu, Jul 24, 2008 at 7:32 AM, Jonathan Leighton wrote: > Hiya, > > I am trying to use the HTML Story Formatter in conjunction with > CruiseControl.rb. I have got it outputting the stories to a file, but I > notice there are CSS and JS files linked in the head, which don't appear > to be anywhere in the rspec repository. Are these files available and if > so where? They're in the story_server directory. We haven't automated this yet, so what I do is just copy them to a logical place and set up a rake task to put the stories in the same place. On Rails projects, I've gotten into the habit of putting them in public/doc/[javascripts|stylesheets] (or similar) and then use this rake task. namespace :stories do desc "Run all the stories (HTML)" task :html do sh "ruby stories/all.rb -fh:public/doc/index.html" end end Now the customers can see the story output at /docs. Of course, so can anybody else, so that might come down before releasing or move to a controller that can manage who gets to see it. But this should give you an idea. Also note that the javascript is 1/2 baked at this point and includes an "add step" (non) feature (which you'll see in the browser) that doesn't really do anything. Maybe it's time to get rid of that for now and standardize on where this stuff goes :) HTH, David > > Cheers, > Jon > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Thu Jul 24 09:35:15 2008 From: lists at ruby-forum.com (Doug Livesey) Date: Thu, 24 Jul 2008 15:35:15 +0200 Subject: [rspec-users] Speccing a respond_to block outside of a request Message-ID: <48115f6b90667d785a5959ae06df7155@ruby-forum.com> Hi -- I have a bunch of controllers whose index actions are so similar, I can safely stick most of the code in a superclass. I am having trouble, however, in speccing the index method in the superclass. It could look like this: http://pastie.org/240207 This is the class that the controllers that would actually get called would inherit from. I want to describe SuperController#index in a spec, so will need to be able to manipulate the respond_to method -- any ideas on how i can do this? Also, it would be nice to spec that the before filter has been applied, if there was a way, but the main thing is the index method. Cheers for any & all assistance, Doug. -- Posted via http://www.ruby-forum.com/. From chris at cobaltedge.com Thu Jul 24 12:29:41 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Thu, 24 Jul 2008 09:29:41 -0700 Subject: [rspec-users] HTML Story Formatter In-Reply-To: <57c63afe0807240544p5a8adc2keaa21aac0ca1fe0e@mail.gmail.com> References: <1216902734.7340.14.camel@tybalt> <57c63afe0807240544p5a8adc2keaa21aac0ca1fe0e@mail.gmail.com> Message-ID: <443c240c0807240929g7b76d63fv6e8d3fc76635030@mail.gmail.com> For another variant, with my CC.rb setup, I have a rake task as follows: desc "Copy RSpec Story HTML includes" task :copy_story_html_includes do if ENV['CC_BUILD_ARTIFACTS'] stories_output_dir = File.join(ENV['CC_BUILD_ARTIFACTS'], 'Stories') system "mkdir #{stories_output_dir}" system("/bin/cp -r #{RAILS_ROOT}/vendor/plugins/rspec/story_server/prototype/stylesheets/ #{stories_output_dir}") system("/bin/cp -r #{RAILS_ROOT}/vendor/plugins/rspec/story_server/prototype/javascripts/ #{stories_output_dir}") end end And then I just have that as a pre-requisite to my regular spec:stories rake task (since it'll only do something if we're in the CC.rb environment): desc "Run all spec stories" task :stories => [ :copy_story_html_includes ] do if ENV['CC_BUILD_ARTIFACTS'] ruby "stories/all.rb --format html > #{File.join(ENV['CC_BUILD_ARTIFACTS'], 'Stories', 'index.html')}" else ruby "stories/all.rb --format plain --colour" end end On Thu, Jul 24, 2008 at 5:44 AM, David Chelimsky wrote: > On Thu, Jul 24, 2008 at 7:32 AM, Jonathan Leighton > wrote: >> Hiya, >> >> I am trying to use the HTML Story Formatter in conjunction with >> CruiseControl.rb. I have got it outputting the stories to a file, but I >> notice there are CSS and JS files linked in the head, which don't appear >> to be anywhere in the rspec repository. Are these files available and if >> so where? > > They're in the story_server directory. We haven't automated this yet, > so what I do is just copy them to a logical place and set up a rake > task to put the stories in the same place. On Rails projects, I've > gotten into the habit of putting them in > public/doc/[javascripts|stylesheets] (or similar) and then use this > rake task. > > namespace :stories do > > desc "Run all the stories (HTML)" > task :html do > sh "ruby stories/all.rb -fh:public/doc/index.html" > end > > end > > Now the customers can see the story output at /docs. Of course, so can > anybody else, so that might come down before releasing or move to a > controller that can manage who gets to see it. But this should give > you an idea. > > Also note that the javascript is 1/2 baked at this point and includes > an "add step" (non) feature (which you'll see in the browser) that > doesn't really do anything. > > Maybe it's time to get rid of that for now and standardize on where > this stuff goes :) > > HTH, > David > > >> >> Cheers, >> Jon >> >> _______________________________________________ >> 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 > -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From j at jonathanleighton.com Thu Jul 24 12:45:11 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Thu, 24 Jul 2008 17:45:11 +0100 Subject: [rspec-users] HTML Story Formatter In-Reply-To: <443c240c0807240929g7b76d63fv6e8d3fc76635030@mail.gmail.com> References: <1216902734.7340.14.camel@tybalt> <57c63afe0807240544p5a8adc2keaa21aac0ca1fe0e@mail.gmail.com> <443c240c0807240929g7b76d63fv6e8d3fc76635030@mail.gmail.com> Message-ID: <1216917911.7340.40.camel@tybalt> Thanks for both your answers. The copying rake task was pretty useful as I was basically intending to write the same thing after I read David's message :) Jon On Thu, 2008-07-24 at 09:29 -0700, Christopher Bailey wrote: > For another variant, with my CC.rb setup, I have a rake task as follows: > > desc "Copy RSpec Story HTML includes" > task :copy_story_html_includes do > if ENV['CC_BUILD_ARTIFACTS'] > stories_output_dir = File.join(ENV['CC_BUILD_ARTIFACTS'], 'Stories') > system "mkdir #{stories_output_dir}" > system("/bin/cp -r > #{RAILS_ROOT}/vendor/plugins/rspec/story_server/prototype/stylesheets/ > #{stories_output_dir}") > system("/bin/cp -r > #{RAILS_ROOT}/vendor/plugins/rspec/story_server/prototype/javascripts/ > #{stories_output_dir}") > end > end > > And then I just have that as a pre-requisite to my regular > spec:stories rake task (since it'll only do something if we're in the > CC.rb environment): > > desc "Run all spec stories" > task :stories => [ :copy_story_html_includes ] do > if ENV['CC_BUILD_ARTIFACTS'] > ruby "stories/all.rb --format html > > #{File.join(ENV['CC_BUILD_ARTIFACTS'], 'Stories', 'index.html')}" > else > ruby "stories/all.rb --format plain --colour" > end > end > > > On Thu, Jul 24, 2008 at 5:44 AM, David Chelimsky wrote: > > On Thu, Jul 24, 2008 at 7:32 AM, Jonathan Leighton > > wrote: > >> Hiya, > >> > >> I am trying to use the HTML Story Formatter in conjunction with > >> CruiseControl.rb. I have got it outputting the stories to a file, but I > >> notice there are CSS and JS files linked in the head, which don't appear > >> to be anywhere in the rspec repository. Are these files available and if > >> so where? > > > > They're in the story_server directory. We haven't automated this yet, > > so what I do is just copy them to a logical place and set up a rake > > task to put the stories in the same place. On Rails projects, I've > > gotten into the habit of putting them in > > public/doc/[javascripts|stylesheets] (or similar) and then use this > > rake task. > > > > namespace :stories do > > > > desc "Run all the stories (HTML)" > > task :html do > > sh "ruby stories/all.rb -fh:public/doc/index.html" > > end > > > > end > > > > Now the customers can see the story output at /docs. Of course, so can > > anybody else, so that might come down before releasing or move to a > > controller that can manage who gets to see it. But this should give > > you an idea. > > > > Also note that the javascript is 1/2 baked at this point and includes > > an "add step" (non) feature (which you'll see in the browser) that > > doesn't really do anything. > > > > Maybe it's time to get rid of that for now and standardize on where > > this stuff goes :) > > > > HTH, > > David > > > > > >> > >> Cheers, > >> Jon > >> > >> _______________________________________________ > >> 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 > > > > > -- Jonathan Leighton http://jonathanleighton.com/ From lists at ruby-forum.com Thu Jul 24 15:27:02 2008 From: lists at ruby-forum.com (Macario Ortega) Date: Thu, 24 Jul 2008 21:27:02 +0200 Subject: [rspec-users] Failing on rake but not on textmate (rails) In-Reply-To: References: <9d557867dbb34a255e62911d9bcd0777@ruby-forum.com> <3c30da400807211734v17b78678n277905695bddf331@mail.gmail.com> Message-ID: Rick Denatale wrote: > On Mon, Jul 21, 2008 at 8:34 PM, Mark Wilden > wrote: > >> don't know if that explains the behavior you're seeing. >> >> >>> I would like to use autotest but I can't trust the results. >>> >> >> autotest also does not copy the database structure. I've been using it for >> six months and I've never noticed a problem with it. Why don't you trust it? >> >> I doubt that it's a problem with not copy the database structure from dev > to test. That sync's the db schema and would only be needed after a > schema > change (i.e. one or more migrations have been run), and it would be much > more likely to cause a failure in Textmate when the code under test > doesn't > see the expected db schema. > > It's more likely that there are undeclared fixtures affecting the spec, > a > spec which needs particular state in the database might succeed or not > depending on whether or not previous specs either left data behind, or > deleted data needed by the spec in question. > > When I've seen cases where test/specs behaved differently when run > separately vs. being run in batch (e.g. by Rake) it's almost always > because > I left out a fixture declaration. > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ Hi, thanks for the answer today I ran rake several times and all my test passed (and that made me very happy) but suddenly the tests for this model started failing again. Prior to each test I delete all records for the model and I have no fixture for that particular model. I am just starting with sdd and I find fixtures to give me more trouble than they solve so when I need to populate the database I create and save the models I need thus I have all the dependencies. What do you mean by undeclared fixture? a fixture with no data? What is strange is that some validation specs ('it should require name') that don't depend on database also fail. -- Posted via http://www.ruby-forum.com/. From dan at revelationglobal.com Thu Jul 24 16:17:10 2008 From: dan at revelationglobal.com (Dan Herrera) Date: Thu, 24 Jul 2008 13:17:10 -0700 Subject: [rspec-users] Failing on rake but not on textmate (rails) In-Reply-To: References: <9d557867dbb34a255e62911d9bcd0777@ruby-forum.com> <3c30da400807211734v17b78678n277905695bddf331@mail.gmail.com> Message-ID: On Thu, Jul 24, 2008 at 12:27 PM, Macario Ortega wrote: > Rick Denatale wrote: >> On Mon, Jul 21, 2008 at 8:34 PM, Mark Wilden >> wrote: >> >>> don't know if that explains the behavior you're seeing. >>> >>> >>>> I would like to use autotest but I can't trust the results. >>>> >>> >>> autotest also does not copy the database structure. I've been using it for >>> six months and I've never noticed a problem with it. Why don't you trust it? >>> >>> I doubt that it's a problem with not copy the database structure from dev >> to test. That sync's the db schema and would only be needed after a >> schema >> change (i.e. one or more migrations have been run), and it would be much >> more likely to cause a failure in Textmate when the code under test >> doesn't >> see the expected db schema. >> >> It's more likely that there are undeclared fixtures affecting the spec, >> a >> spec which needs particular state in the database might succeed or not >> depending on whether or not previous specs either left data behind, or >> deleted data needed by the spec in question. >> >> When I've seen cases where test/specs behaved differently when run >> separately vs. being run in batch (e.g. by Rake) it's almost always >> because >> I left out a fixture declaration. >> >> -- >> Rick DeNatale >> >> My blog on Ruby >> http://talklikeaduck.denhaven2.com/ > > > Hi, thanks for the answer today I ran rake several times and all my test > passed (and that made me very happy) but suddenly the tests for this > model started failing again. We get failures at times when running specs with rake spec that we can't reproduce when running in Textmate. We came to the conclusion that it may have something to do with transactions not rolling back before the start of the next test. So even though the models we create should be unique (we create them with some randomness built in), we will get validation failures when saving a new record to the DB. You may want to try turning off transactions with: config.use_transactional_fixtures = false and see if that makes a difference. We are using Rspec 1.1.4 and PostgreSQL as our db. Let me know if that helps. dan > Prior to each test I delete all records for the model and I have no > fixture for that particular model. > > I am just starting with sdd and I find fixtures to give me more trouble > than they solve so when I need to populate the database I create and > save the models I need thus I have all the dependencies. > > What do you mean by undeclared fixture? a fixture with no data? > > What is strange is that some validation specs ('it should require name') > that don't depend on database also fail. From lists at ruby-forum.com Thu Jul 24 16:34:35 2008 From: lists at ruby-forum.com (Macario Ortega) Date: Thu, 24 Jul 2008 22:34:35 +0200 Subject: [rspec-users] Failing on rake but not on textmate (rails) In-Reply-To: References: <9d557867dbb34a255e62911d9bcd0777@ruby-forum.com> <3c30da400807211734v17b78678n277905695bddf331@mail.gmail.com> Message-ID: <6c169a778fd2c90e5b1c6dad14cc8790@ruby-forum.com> Dan Herrera wrote: > We get failures at times when running specs with rake spec that we > can't reproduce when running in Textmate. We came to the conclusion > that it may have something to do with transactions not rolling back > before the start of the next test. So even though the models we > create should be unique (we create them with some randomness built > in), we will get validation failures when saving a new record to the > DB. > > You may want to try turning off transactions with: > config.use_transactional_fixtures = false > and see if that makes a difference. > > We are using Rspec 1.1.4 and PostgreSQL as our db. Let me know if that > helps. > > dan Thanks, I've tried that and I got four additional failures concerning Attachment Fu not using the expected path to save the images. I guess the whole rspec system is very complex. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Jul 24 16:35:10 2008 From: lists at ruby-forum.com (Macario Ortega) Date: Thu, 24 Jul 2008 22:35:10 +0200 Subject: [rspec-users] Failing on rake but not on textmate (rails) In-Reply-To: <6c169a778fd2c90e5b1c6dad14cc8790@ruby-forum.com> References: <9d557867dbb34a255e62911d9bcd0777@ruby-forum.com> <3c30da400807211734v17b78678n277905695bddf331@mail.gmail.com> <6c169a778fd2c90e5b1c6dad14cc8790@ruby-forum.com> Message-ID: Btw, I am with sqlite3. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Jul 24 16:58:45 2008 From: lists at ruby-forum.com (Macario Ortega) Date: Thu, 24 Jul 2008 22:58:45 +0200 Subject: [rspec-users] Failing on rake but not on textmate (rails) In-Reply-To: References: <9d557867dbb34a255e62911d9bcd0777@ruby-forum.com> <3c30da400807211734v17b78678n277905695bddf331@mail.gmail.com> <6c169a778fd2c90e5b1c6dad14cc8790@ruby-forum.com> Message-ID: <5f4cbef0a2ac92f5514a67ea03c26bfa@ruby-forum.com> Macario Ortega wrote: > > Btw, I am with sqlite3. Hi, I think I solved the issue, I had mocha in my plugins but I was using it in just a couple of tests and this line was commented in the spec_helper.rb # config.mock_with :mocha I removed mocha from my plugins folder ran rake and this two tests failed, I fixed them and now I can see about 600 green dots and no F's when I run rake :) -- Posted via http://www.ruby-forum.com/. From mattlins at gmail.com Thu Jul 24 23:49:45 2008 From: mattlins at gmail.com (Matt Lins) Date: Thu, 24 Jul 2008 22:49:45 -0500 Subject: [rspec-users] Problems with mock assigned to a constant Message-ID: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> Hi all, Initially I thought this was a bug in the built-in mocking framework(and it still may be), but I better hash it out on the mailing list before I file/reopen the ticket: http://rspec.lighthouseapp.com/projects/5645/tickets/478-mocks-on-constants#ticket-478-6 I thought my example illustrated my problem, but obviously I was passing the wrong arguments to the mock. I revised my example to more clearly state my problem: http://gist.github.com/2372 This is a snip of a some code from a library I'm writing. When I run this spec I get the following: # spec migration_spec.rb .F 1) Spec::Mocks::MockExpectationError in 'Migration should find the records' Mock 'MyModel Class' received unexpected message :count with (no args) ./migration.rb:14:in `run' ./migration_spec.rb:19: Finished in 0.009164 seconds 2 examples, 1 failure ------------------------------------------ I want to mock out MyModel completely because it's an ActiveRecord object. As suggested, if I define the MyModel class, this whole spec will pass. But, I don't think I should need to do that, should I? So it seems to only occur when I assign the mock to a constant. So, even though MyModel.count is stubbed in the before block, the mock reports an unexpected message. Note however the first example passes. I had difficulty figuring out the cause of this, so I just gave FlexMock a shot (since it's so easy to swap out). FlexMock passed both examples(not that, that alone signifies a bug in rSpec). So, my question: Is this a bug in the built in mocking framework, or am I doing it wrong? :) -Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: From mailing_lists at railsnewbie.com Fri Jul 25 00:00:04 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 25 Jul 2008 00:00:04 -0400 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> Message-ID: <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> On Jul 24, 2008, at 11:49 PM, Matt Lins wrote: > Hi all, > > Initially I thought this was a bug in the built-in mocking > framework(and it still may be), but I better hash it out on the > mailing list before I file/reopen the ticket: > > http://rspec.lighthouseapp.com/projects/5645/tickets/478-mocks-on-constants#ticket-478-6 > > I thought my example illustrated my problem, but obviously I was > passing the wrong arguments to the mock. I revised my example to > more clearly state my problem: > > http://gist.github.com/2372 > > This is a snip of a some code from a library I'm writing. When I > run this spec I get the following: > > # spec migration_spec.rb > .F > > 1) > Spec::Mocks::MockExpectationError in 'Migration should find the > records' > Mock 'MyModel Class' received unexpected message :count with (no args) > ./migration.rb:14:in `run' > ./migration_spec.rb:19: > > Finished in 0.009164 seconds > > 2 examples, 1 failure > > ------------------------------------------ > > I want to mock out MyModel completely because it's an ActiveRecord > object. As suggested, if I define the MyModel class, this whole > spec will pass. But, I don't think I should need to do that, should > I? So it seems to only occur when I assign the mock to a constant. > > So, even though MyModel.count is stubbed in the before block, the > mock reports an unexpected message. Note however the first example > passes. The first example passes because "should_receive" acts as a stub, too. The second example fails, because in the second example there is no stub for the count method. I'd suggest adding this line to before(:each) (or to the start of each test case): MyModel.stub!(:count).and_return 0 Scott -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattlins at gmail.com Fri Jul 25 00:21:38 2008 From: mattlins at gmail.com (Matt Lins) Date: Thu, 24 Jul 2008 23:21:38 -0500 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> Message-ID: <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> Scott, Thanks, your solution does work, although I'm not sure I like it. I like to stub out behavior in my before block but also use mock expectations to verify behavior in my specs. Similar to what Dave explains here: http://blog.davidchelimsky.net/2006/11/9/tutorial-rspec-stubs-and-mocks I defined the stubs in the before block: MyModel = mock('MyModel Class', :count => 1, :find => [@record]) So, I'm assuming by adding the expectation in the first spec, I'm wiping out the stubs defined in the before block? If that is the case why does the first spec not fail because of MyModel.find ? Also, FlexMock does not seem to behave this way(not that they need to behave the same), but I would question whether this behavior is intentional? -Matt On Thu, Jul 24, 2008 at 11:00 PM, Scott Taylor wrote: > > On Jul 24, 2008, at 11:49 PM, Matt Lins wrote: > > Hi all, > > Initially I thought this was a bug in the built-in mocking framework(and it still may be), but I better hash it out on the mailing list before I file/reopen the ticket: > > http://rspec.lighthouseapp.com/projects/5645/tickets/478-mocks-on-constants#ticket-478-6 > > I thought my example illustrated my problem, but obviously I was passing the wrong arguments to the mock. I revised my example to more clearly state my problem: > > http://gist.github.com/2372 > > This is a snip of a some code from a library I'm writing. When I run this spec I get the following: > > # spec migration_spec.rb > .F > > 1) > Spec::Mocks::MockExpectationError in 'Migration should find the records' > Mock 'MyModel Class' received unexpected message :count with (no args) > ./migration.rb:14:in `run' > ./migration_spec.rb:19: > > Finished in 0.009164 seconds > > 2 examples, 1 failure > > ------------------------------------------ > > I want to mock out MyModel completely because it's an ActiveRecord object. As suggested, if I define the MyModel class, this whole spec will pass. But, I don't think I should need to do that, should I? So it seems to only occur when I assign the mock to a constant. > > So, even though MyModel.count is stubbed in the before block, the mock reports an unexpected message. Note however the first example passes. > > The first example passes because "should_receive" acts as a stub, too. > The second example fails, because in the second example there is no stub for the count method. I'd suggest adding this line to before(:each) (or to the start of each test case): > MyModel.stub!(:count).and_return 0 > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mattlins at gmail.com Fri Jul 25 00:32:27 2008 From: mattlins at gmail.com (Matt Lins) Date: Thu, 24 Jul 2008 23:32:27 -0500 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> Message-ID: <3795d7870807242132v6162aa36pdc2936e5fcb99d9d@mail.gmail.com> I suppose the way I'm defining the stubs, differs from what Dave is doing in his example. I assumed that: MyModel = mock('MyModel Class', :count => 1) was the same as: MyModel.stub!(:count).and_return(1) But, I'm starting to think they are not. I haven't looked at the rSpec internals to verify, other than the parameter name: stubs_and_options+ lets you assign options and stub values at the same time. The only option available is :null_object. Anything else is treated as a stub value. So, is this problem? -Matt On Thu, Jul 24, 2008 at 11:21 PM, Matt Lins wrote: > Scott, > > Thanks, your solution does work, although I'm not sure I like it. I > like to stub out behavior in my before block but also use mock > expectations to verify behavior in my specs. Similar to what Dave > explains here: > > http://blog.davidchelimsky.net/2006/11/9/tutorial-rspec-stubs-and-mocks > > I defined the stubs in the before block: > > MyModel = mock('MyModel Class', :count => 1, :find => [@record]) > > So, I'm assuming by adding the expectation in the first spec, I'm > wiping out the stubs defined in the before block? If that is the case > why does the first spec not fail because of MyModel.find ? > > Also, FlexMock does not seem to behave this way(not that they need to > behave the same), but I would question whether this behavior is > intentional? > > -Matt > > On Thu, Jul 24, 2008 at 11:00 PM, Scott Taylor > wrote: >> >> On Jul 24, 2008, at 11:49 PM, Matt Lins wrote: >> >> Hi all, >> >> Initially I thought this was a bug in the built-in mocking framework(and it still may be), but I better hash it out on the mailing list before I file/reopen the ticket: >> >> http://rspec.lighthouseapp.com/projects/5645/tickets/478-mocks-on-constants#ticket-478-6 >> >> I thought my example illustrated my problem, but obviously I was passing the wrong arguments to the mock. I revised my example to more clearly state my problem: >> >> http://gist.github.com/2372 >> >> This is a snip of a some code from a library I'm writing. When I run this spec I get the following: >> >> # spec migration_spec.rb >> .F >> >> 1) >> Spec::Mocks::MockExpectationError in 'Migration should find the records' >> Mock 'MyModel Class' received unexpected message :count with (no args) >> ./migration.rb:14:in `run' >> ./migration_spec.rb:19: >> >> Finished in 0.009164 seconds >> >> 2 examples, 1 failure >> >> ------------------------------------------ >> >> I want to mock out MyModel completely because it's an ActiveRecord object. As suggested, if I define the MyModel class, this whole spec will pass. But, I don't think I should need to do that, should I? So it seems to only occur when I assign the mock to a constant. >> >> So, even though MyModel.count is stubbed in the before block, the mock reports an unexpected message. Note however the first example passes. >> >> The first example passes because "should_receive" acts as a stub, too. >> The second example fails, because in the second example there is no stub for the count method. I'd suggest adding this line to before(:each) (or to the start of each test case): >> MyModel.stub!(:count).and_return 0 >> Scott >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Fri Jul 25 00:38:36 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 25 Jul 2008 00:38:36 -0400 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> Message-ID: <10A74184-E898-4620-AEFC-AE80352F10CA@railsnewbie.com> On Jul 25, 2008, at 12:21 AM, Matt Lins wrote: > Scott, > > Thanks, your solution does work, although I'm not sure I like it. I > like to stub out behavior in my before block but also use mock > expectations to verify behavior in my specs. Similar to what Dave > explains here: > > http://blog.davidchelimsky.net/2006/11/9/tutorial-rspec-stubs-and- > mocks > > I defined the stubs in the before block: > > MyModel = mock('MyModel Class', :count => 1, :find => [@record]) > Ah - well, I missed this part. This make much more sense. Btw, aren't you seeing warnings every time you run your specs? Redefining the constant for your test, is, IMHO, the most ugly solution you can take (and plus, it'll break in many circumstances - for instance, it probably wont' play well with rails loading schemes). One way around this is by using dependency injection - I would highly recommend you use this technique. *DON'T* use the constant technique, unless you really know what your doing. Unfortunately there are times when DI doesn't work (especially in the rails world) - in those cases, you really have no other option besides stubbing the class methods directly. > wiping out the stubs defined in the before block? If that is the case > why does the first spec not fail because of MyModel.find ? Well - what is happening between each test case? Are the classes (defined elsewhere) being reloaded each time? Are you getting a warning when you redefine MyModel? Do you understand how rails is (re)loading this stuff? Scott From mailing_lists at railsnewbie.com Fri Jul 25 00:47:13 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 25 Jul 2008 00:47:13 -0400 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <3795d7870807242132v6162aa36pdc2936e5fcb99d9d@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> <3795d7870807242132v6162aa36pdc2936e5fcb99d9d@mail.gmail.com> Message-ID: <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> On Jul 25, 2008, at 12:32 AM, Matt Lins wrote: > I suppose the way I'm defining the stubs, differs from what Dave is > doing in his example. > > I assumed that: > > MyModel = mock('MyModel Class', :count => 1) > > was the same as: > > MyModel.stub!(:count).and_return(1) Nope. Not even close. Here's an equivalent of the first form: Object.send :remove_const, :MyModel MyModel = and here's the second form: MyModel.instance_eval do def count 1 end end (or:) MyModel.class_eval do class << self def count; 1; end end end Scott > > > But, I'm starting to think they are not. I haven't looked at the > rSpec internals to verify, other than the parameter name: > > stubs_and_options+ lets you assign options and stub values > at the same time. The only option available is :null_object. > Anything else is treated as a stub value. > > So, is this problem? Yeah - so here are two related, but not equivalent ideas: mock objects, and stubs. A stub is just a faked out method - it can exist on a mock object (a completely fake object), or on a partial mock (i.e. a real object, with a method faked out). mock('My mock") is a mock object, MyRealObject.stub!(:foo) is a real object with the method foo faked out. What is the difference between a mock object and a fake object? A mock object will complain (read: raise an error) any time it receives a message which it doesn't understand (i.e. one which hasn't been explicitly stubbed). A real object will work as usual. (A null object mock is a special type of mock - one which never complains. For now, you shouldn't worry about it). Hope this helps, Scott From mailing_lists at railsnewbie.com Fri Jul 25 00:51:30 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 25 Jul 2008 00:51:30 -0400 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> <3795d7870807242132v6162aa36pdc2936e5fcb99d9d@mail.gmail.com> <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> Message-ID: <311EF816-E4BE-4473-B7CB-57C7CD636564@railsnewbie.com> On Jul 25, 2008, at 12:47 AM, Scott Taylor wrote: > > On Jul 25, 2008, at 12:32 AM, Matt Lins wrote: > >> I suppose the way I'm defining the stubs, differs from what Dave is >> doing in his example. >> >> I assumed that: >> >> MyModel = mock('MyModel Class', :count => 1) >> >> was the same as: >> >> MyModel.stub!(:count).and_return(1) > > Nope. Not even close. Here's an equivalent of the first form: > > Object.send :remove_const, :MyModel > MyModel = > > and here's the second form: > > MyModel.instance_eval do > def count > 1 > end > end > > (or:) > > MyModel.class_eval do > class << self > def count; 1; end > end > end > > Scott > > >> >> >> But, I'm starting to think they are not. I haven't looked at the >> rSpec internals to verify, other than the parameter name: >> >> stubs_and_options+ lets you assign options and stub values >> at the same time. The only option available is :null_object. >> Anything else is treated as a stub value. >> >> So, is this problem? > > Yeah - so here are two related, but not equivalent ideas: mock > objects, and stubs. A stub is just a faked out method - it can > exist on a mock object (a completely fake object), or on a partial > mock (i.e. a real object, with a method faked out). mock('My mock") > is a mock object, MyRealObject.stub!(:foo) is a real object with the > method foo faked out. > > What is the difference between a mock object and a fake object? A > mock object will complain (read: raise an error) any time it > receives a message which it doesn't understand (i.e. one which > hasn't been explicitly stubbed). A real object will work as usual. > (A null object mock is a special type of mock - one which never > complains. For now, you shouldn't worry about it). > > Hope this helps, > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Oops. Guess I signed that one twice. I'll make up for it by not signing this one at all. From mattlins at gmail.com Fri Jul 25 01:05:30 2008 From: mattlins at gmail.com (Matt Lins) Date: Fri, 25 Jul 2008 00:05:30 -0500 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <10A74184-E898-4620-AEFC-AE80352F10CA@railsnewbie.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> <10A74184-E898-4620-AEFC-AE80352F10CA@railsnewbie.com> Message-ID: <3795d7870807242205j291285e9lf874435d15f7037f@mail.gmail.com> On Thu, Jul 24, 2008 at 11:38 PM, Scott Taylor wrote: > > On Jul 25, 2008, at 12:21 AM, Matt Lins wrote: > >> Scott, >> >> Thanks, your solution does work, although I'm not sure I like it. I >> like to stub out behavior in my before block but also use mock >> expectations to verify behavior in my specs. Similar to what Dave >> explains here: >> >> http://blog.davidchelimsky.net/2006/11/9/tutorial-rspec-stubs-and-mocks >> >> I defined the stubs in the before block: >> >> MyModel = mock('MyModel Class', :count => 1, :find => [@record]) >> > > Ah - well, I missed this part. This make much more sense. > > Btw, aren't you seeing warnings every time you run your specs? I'm not sure what code you're looking at, but in the gist paste I posted for this thread, I'm only defining the constant once( before(:all) ). If you're looking at the lighthouse code, I was undefining the constants in the after block. So, no, I'm not seeing warnings. > > Redefining the constant for your test, is, IMHO, the most ugly solution you > can take (and plus, it'll break in many circumstances - for instance, it > probably wont' play well with rails loading schemes). One way around this > is by using dependency injection - I would highly recommend you use this > technique. *DON'T* use the constant technique, unless you really know what > your doing. > Like I said I'm not redefining the constants. Thanks for the insight, I'll research DI. > Unfortunately there are times when DI doesn't work (especially in the rails > world) - in those cases, you really have no other option besides stubbing > the class methods directly. > >> wiping out the stubs defined in the before block? If that is the case >> why does the first spec not fail because of MyModel.find ? > > Well - what is happening between each test case? Are the classes (defined > elsewhere) being reloaded each time? Are you getting a warning when you > redefine MyModel? Do you understand how rails is (re)loading this stuff? > All my code for the example was posted in gist ( you can download it if you'd like ). I'm not using Rails, I'm writing a library that uses ActiveRecord. But, all that is mocked out. The example in gist fully illustrates the problem in my actual library. The output that I posted in the first post is exactly what you get if you run the code pasted in gist: http://gist.github.com/2372 Sorry, if that was confusing, I shouldn't have even mentioned the lighthouse ticket. > Scott > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mattlins at gmail.com Fri Jul 25 01:15:37 2008 From: mattlins at gmail.com (Matt Lins) Date: Fri, 25 Jul 2008 00:15:37 -0500 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> <3795d7870807242132v6162aa36pdc2936e5fcb99d9d@mail.gmail.com> <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> Message-ID: <3795d7870807242215ldd9cd55oa41d156f17c94d96@mail.gmail.com> On Thu, Jul 24, 2008 at 11:47 PM, Scott Taylor wrote: > > On Jul 25, 2008, at 12:32 AM, Matt Lins wrote: > >> I suppose the way I'm defining the stubs, differs from what Dave is >> doing in his example. >> >> I assumed that: >> >> MyModel = mock('MyModel Class', :count => 1) >> >> was the same as: >> >> MyModel.stub!(:count).and_return(1) > > Nope. Not even close. Here's an equivalent of the first form: > > Object.send :remove_const, :MyModel > MyModel = > > and here's the second form: > > MyModel.instance_eval do > def count > 1 > end > end > > (or:) > > MyModel.class_eval do > class << self > def count; 1; end > end > end > > Scott > > But the stubs are defined the same way in both occurrences, no? MyModel = mock('MyModel Class', :count => 1) By passing {:count => 1} to +stubs_and_options+ I should have defined stubs on the mock object. I'm using it as a shortcut for this: MyModel = mock('MyModel Class') MyModel.stub!(:count).and_return(1) If those example aren't doing the exact same thing I guess I'm a little baffled (or maybe just need to go to sleep). >> >> >> But, I'm starting to think they are not. I haven't looked at the >> rSpec internals to verify, other than the parameter name: >> >> stubs_and_options+ lets you assign options and stub values >> at the same time. The only option available is :null_object. >> Anything else is treated as a stub value. >> >> So, is this problem? > > Yeah - so here are two related, but not equivalent ideas: mock objects, and > stubs. A stub is just a faked out method - it can exist on a mock object (a > completely fake object), or on a partial mock (i.e. a real object, with a > method faked out). mock('My mock") is a mock object, > MyRealObject.stub!(:foo) is a real object with the method foo faked out. > > What is the difference between a mock object and a fake object? A mock > object will complain (read: raise an error) any time it receives a message > which it doesn't understand (i.e. one which hasn't been explicitly stubbed). > A real object will work as usual. (A null object mock is a special type of > mock - one which never complains. For now, you shouldn't worry about it). > Ok, I get what you saying, but as I understand it I am explicitly stubbing out the methods on the _mock_ object and it's still complaining. If +stubs_and_options+ isn't stubbing, then what is it doing? > Hope this helps, > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Fri Jul 25 01:16:28 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 25 Jul 2008 01:16:28 -0400 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <3795d7870807242205j291285e9lf874435d15f7037f@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> <10A74184-E898-4620-AEFC-AE80352F10CA@railsnewbie.com> <3795d7870807242205j291285e9lf874435d15f7037f@mail.gmail.com> Message-ID: On Jul 25, 2008, at 1:05 AM, Matt Lins wrote: > On Thu, Jul 24, 2008 at 11:38 PM, Scott Taylor > wrote: >> >> On Jul 25, 2008, at 12:21 AM, Matt Lins wrote: >> >>> Scott, >>> >>> Thanks, your solution does work, although I'm not sure I like it. I >>> like to stub out behavior in my before block but also use mock >>> expectations to verify behavior in my specs. Similar to what Dave >>> explains here: >>> >>> http://blog.davidchelimsky.net/2006/11/9/tutorial-rspec-stubs-and-mocks >>> >>> I defined the stubs in the before block: >>> >>> MyModel = mock('MyModel Class', :count => 1, :find => [@record]) >>> >> >> Ah - well, I missed this part. This make much more sense. >> >> Btw, aren't you seeing warnings every time you run your specs? > > I'm not sure what code you're looking at, but in the gist paste I > posted for this thread, I'm only defining the constant once( > before(:all) ). If you're looking at the lighthouse code, I was > undefining the constants in the after block. So, no, I'm not seeing > warnings. > >> >> Redefining the constant for your test, is, IMHO, the most ugly >> solution you >> can take (and plus, it'll break in many circumstances - for >> instance, it >> probably wont' play well with rails loading schemes). One way >> around this >> is by using dependency injection - I would highly recommend you use >> this >> technique. *DON'T* use the constant technique, unless you really >> know what >> your doing. >> > > Like I said I'm not redefining the constants. Thanks for the insight, > I'll research DI. > >> Unfortunately there are times when DI doesn't work (especially in >> the rails >> world) - in those cases, you really have no other option besides >> stubbing >> the class methods directly. >> >>> wiping out the stubs defined in the before block? If that is the >>> case >>> why does the first spec not fail because of MyModel.find ? >> >> Well - what is happening between each test case? Are the classes >> (defined >> elsewhere) being reloaded each time? Are you getting a warning >> when you >> redefine MyModel? Do you understand how rails is (re)loading this >> stuff? >> > > All my code for the example was posted in gist ( you can download it > if you'd like ). I'm not using Rails, I'm writing a library that uses > ActiveRecord. But, all that is mocked out. The example in gist fully > illustrates the problem in my actual library. The output that I > posted in the first post is exactly what you get if you run the code > pasted in gist: > > http://gist.github.com/2372 > > Sorry, if that was confusing, I shouldn't have even mentioned the > lighthouse ticket. > No - it was my own fault. I didn't take the time to read your post fully. Anyway - DI is surely the way to go. And generally you'll want to stay away from before(:all) when you can. Best, Scott From mailing_lists at railsnewbie.com Fri Jul 25 01:25:20 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 25 Jul 2008 01:25:20 -0400 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <3795d7870807242215ldd9cd55oa41d156f17c94d96@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> <3795d7870807242132v6162aa36pdc2936e5fcb99d9d@mail.gmail.com> <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> <3795d7870807242215ldd9cd55oa41d156f17c94d96@mail.gmail.com> Message-ID: <7B825364-11F8-4235-9C90-69D0756E47E5@railsnewbie.com> On Jul 25, 2008, at 1:15 AM, Matt Lins wrote: > On Thu, Jul 24, 2008 at 11:47 PM, Scott Taylor > wrote: >> >> On Jul 25, 2008, at 12:32 AM, Matt Lins wrote: >> >>> I suppose the way I'm defining the stubs, differs from what Dave is >>> doing in his example. >>> >>> I assumed that: >>> >>> MyModel = mock('MyModel Class', :count => 1) >>> >>> was the same as: >>> >>> MyModel.stub!(:count).and_return(1) >> >> Nope. Not even close. Here's an equivalent of the first form: >> >> Object.send :remove_const, :MyModel >> MyModel = >> >> and here's the second form: >> >> MyModel.instance_eval do >> def count >> 1 >> end >> end >> >> (or:) >> >> MyModel.class_eval do >> class << self >> def count; 1; end >> end >> end >> >> Scott >> >> > > But the stubs are defined the same way in both occurrences, no? > > MyModel = mock('MyModel Class', :count => 1) > > By passing {:count => 1} to +stubs_and_options+ I should have defined > stubs on the mock object. I'm using it as a shortcut for this: > > MyModel = mock('MyModel Class') > MyModel.stub!(:count).and_return(1) > > If those example aren't doing the exact same thing I guess I'm a > little baffled (or maybe just need to go to sleep). The first one is redefining the constant 'MyModel'. The second one is just redefining a class method (the constant isn't changing - it's remaining whatever it was before - say, a class) > > >>> >>> >>> But, I'm starting to think they are not. I haven't looked at the >>> rSpec internals to verify, other than the parameter name: >>> >>> stubs_and_options+ lets you assign options and stub values >>> at the same time. The only option available is :null_object. >>> Anything else is treated as a stub value. >>> >>> So, is this problem? >> >> Yeah - so here are two related, but not equivalent ideas: mock >> objects, and >> stubs. A stub is just a faked out method - it can exist on a mock >> object (a >> completely fake object), or on a partial mock (i.e. a real object, >> with a >> method faked out). mock('My mock") is a mock object, >> MyRealObject.stub!(:foo) is a real object with the method foo faked >> out. >> >> What is the difference between a mock object and a fake object? A >> mock >> object will complain (read: raise an error) any time it receives a >> message >> which it doesn't understand (i.e. one which hasn't been explicitly >> stubbed). >> A real object will work as usual. (A null object mock is a special >> type of >> mock - one which never complains. For now, you shouldn't worry >> about it). >> > > Ok, I get what you saying, but as I understand it I am explicitly > stubbing out the methods on the _mock_ object and it's still > complaining. If +stubs_and_options+ isn't stubbing, then what is it > doing? That's right - the hash to the mock method is a shorthand. So these two are equivalent: my_mock = mock('a mock') my_mock.stub!(:foo).and_return(:bar) AND: my_mock = mock("a mock", {:foo => :bar}) Scott From mattlins at gmail.com Fri Jul 25 01:34:05 2008 From: mattlins at gmail.com (Matt Lins) Date: Fri, 25 Jul 2008 00:34:05 -0500 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <7B825364-11F8-4235-9C90-69D0756E47E5@railsnewbie.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> <3795d7870807242132v6162aa36pdc2936e5fcb99d9d@mail.gmail.com> <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> <3795d7870807242215ldd9cd55oa41d156f17c94d96@mail.gmail.com> <7B825364-11F8-4235-9C90-69D0756E47E5@railsnewbie.com> Message-ID: <3795d7870807242234j2e7aeeb2q979f227c3bd5791b@mail.gmail.com> On Fri, Jul 25, 2008 at 12:25 AM, Scott Taylor wrote: > > On Jul 25, 2008, at 1:15 AM, Matt Lins wrote: > >> On Thu, Jul 24, 2008 at 11:47 PM, Scott Taylor >> wrote: >>> >>> On Jul 25, 2008, at 12:32 AM, Matt Lins wrote: >>> >>>> I suppose the way I'm defining the stubs, differs from what Dave is >>>> doing in his example. >>>> >>>> I assumed that: >>>> >>>> MyModel = mock('MyModel Class', :count => 1) >>>> >>>> was the same as: >>>> >>>> MyModel.stub!(:count).and_return(1) >>> >>> Nope. Not even close. Here's an equivalent of the first form: >>> >>> Object.send :remove_const, :MyModel >>> MyModel = >>> >>> and here's the second form: >>> >>> MyModel.instance_eval do >>> def count >>> 1 >>> end >>> end >>> >>> (or:) >>> >>> MyModel.class_eval do >>> class << self >>> def count; 1; end >>> end >>> end >>> >>> Scott >>> >>> >> >> But the stubs are defined the same way in both occurrences, no? >> >> MyModel = mock('MyModel Class', :count => 1) >> >> By passing {:count => 1} to +stubs_and_options+ I should have defined >> stubs on the mock object. I'm using it as a shortcut for this: >> >> MyModel = mock('MyModel Class') >> MyModel.stub!(:count).and_return(1) >> >> If those example aren't doing the exact same thing I guess I'm a >> little baffled (or maybe just need to go to sleep). > > The first one is redefining the constant 'MyModel'. The second one is just > redefining a class method (the constant isn't changing - it's remaining > whatever it was before - say, a class) > >> >> >>>> >>>> >>>> But, I'm starting to think they are not. I haven't looked at the >>>> rSpec internals to verify, other than the parameter name: >>>> >>>> stubs_and_options+ lets you assign options and stub values >>>> at the same time. The only option available is :null_object. >>>> Anything else is treated as a stub value. >>>> >>>> So, is this problem? >>> >>> Yeah - so here are two related, but not equivalent ideas: mock objects, >>> and >>> stubs. A stub is just a faked out method - it can exist on a mock object >>> (a >>> completely fake object), or on a partial mock (i.e. a real object, with a >>> method faked out). mock('My mock") is a mock object, >>> MyRealObject.stub!(:foo) is a real object with the method foo faked out. >>> >>> What is the difference between a mock object and a fake object? A mock >>> object will complain (read: raise an error) any time it receives a >>> message >>> which it doesn't understand (i.e. one which hasn't been explicitly >>> stubbed). >>> A real object will work as usual. (A null object mock is a special type >>> of >>> mock - one which never complains. For now, you shouldn't worry about >>> it). >>> >> >> Ok, I get what you saying, but as I understand it I am explicitly >> stubbing out the methods on the _mock_ object and it's still >> complaining. If +stubs_and_options+ isn't stubbing, then what is it >> doing? > > That's right - the hash to the mock method is a shorthand. So these two are > equivalent: > > my_mock = mock('a mock') > my_mock.stub!(:foo).and_return(:bar) > > AND: > > my_mock = mock("a mock", {:foo => :bar}) > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Ok, then would you still insist that: This: http://gist.github.com/2372 Should produce this: # spec migration_spec.rb .F 1) Spec::Mocks::MockExpectationError in 'Migration should find the records' Mock 'MyModel Class' received unexpected message :count with (no args) ./migration.rb:14:in `run' ./migration_spec.rb:19: Finished in 0.009435 seconds -------------------- And like I said earlier, this code passes both examples with FlexMock( if you simply replace mock with flexmock and uncomment the code in spec_helper, of course you need the flexmock gem) From chris at cobaltedge.com Fri Jul 25 04:11:52 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Fri, 25 Jul 2008 01:11:52 -0700 Subject: [rspec-users] Webrat visits fails, but works in browser Message-ID: <443c240c0807250111r3939b194tda226e1d0e2f9e26@mail.gmail.com> I'm wondering if folks have suggestions for how I can debug the following problem. I have some RSpec Stories that use WebRat, and do a "visits hotels_path" type of thing. It is failing, yet the page works fine in the browser. I'm trying to figure out how to go about looking into why Webrat fails. The error it puts out looks like: FAILURES: 1) Add and edit hotels (View all hotels) FAILED RuntimeError: Page load was not successful (Code: 0) /Users/chris/Code/project/vendor/plugins/webrat/lib/webrat/core/page.rb:298:in `flunk' /Users/chris/Code/project/vendor/plugins/webrat/lib/webrat/core/page.rb:268:in `request_page' /Users/chris/Code/project/vendor/plugins/webrat/lib/webrat/core/page.rb:223:in `load_page' /Users/chris/Code/project/vendor/plugins/webrat/lib/webrat/core/page.rb:19:in `initialize' /Users/chris/Code/project/vendor/plugins/webrat/lib/webrat/rails/session.rb:15:in `new' /Users/chris/Code/project/vendor/plugins/webrat/lib/webrat/rails/session.rb:15:in `visits' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/integration.rb:501:in `send!' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/integration.rb:501:in `method_missing' /Users/chris/Code/project/stories/steps/hotel_steps.rb:37:in `view all hotels' stories/all.rb:2 I'm using the very latest webrat (was also using a version from several weeks ago and this happened too, so I updated to see if that made a difference). Any suggestions welcome, thanks. -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From loop at superinfinite.com Fri Jul 25 08:56:15 2008 From: loop at superinfinite.com (Bart Zonneveld) Date: Fri, 25 Jul 2008 14:56:15 +0200 Subject: [rspec-users] Webrat visits fails, but works in browser In-Reply-To: <443c240c0807250111r3939b194tda226e1d0e2f9e26@mail.gmail.com> References: <443c240c0807250111r3939b194tda226e1d0e2f9e26@mail.gmail.com> Message-ID: <1BD124B8-D9BD-4CE1-B335-B3E1152F262A@superinfinite.com> On 25 jul 2008, at 10:11, Christopher Bailey wrote: > I'm wondering if folks have suggestions for how I can debug the > following problem. I have some RSpec Stories that use WebRat, and do > a "visits hotels_path" type of thing. It is failing, yet the page > works fine in the browser. I'm trying to figure out how to go about > looking into why Webrat fails. The error it puts out looks like: Just look in yout log/test.log. That usually has a lot more info than the output from webrat. good luck, bartz From dchelimsky at gmail.com Fri Jul 25 08:57:39 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 25 Jul 2008 07:57:39 -0500 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <3795d7870807242234j2e7aeeb2q979f227c3bd5791b@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> <3795d7870807242132v6162aa36pdc2936e5fcb99d9d@mail.gmail.com> <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> <3795d7870807242215ldd9cd55oa41d156f17c94d96@mail.gmail.com> <7B825364-11F8-4235-9C90-69D0756E47E5@railsnewbie.com> <3795d7870807242234j2e7aeeb2q979f227c3bd5791b@mail.gmail.com> Message-ID: <57c63afe0807250557lab67c5bj9641dc4b24a1ee6@mail.gmail.com> On Fri, Jul 25, 2008 at 12:34 AM, Matt Lins wrote: > On Fri, Jul 25, 2008 at 12:25 AM, Scott Taylor > wrote: >> >> On Jul 25, 2008, at 1:15 AM, Matt Lins wrote: >> >>> On Thu, Jul 24, 2008 at 11:47 PM, Scott Taylor >>> wrote: >>>> >>>> On Jul 25, 2008, at 12:32 AM, Matt Lins wrote: >>>> >>>>> I suppose the way I'm defining the stubs, differs from what Dave is >>>>> doing in his example. >>>>> >>>>> I assumed that: >>>>> >>>>> MyModel = mock('MyModel Class', :count => 1) >>>>> >>>>> was the same as: >>>>> >>>>> MyModel.stub!(:count).and_return(1) >>>> >>>> Nope. Not even close. Here's an equivalent of the first form: >>>> >>>> Object.send :remove_const, :MyModel >>>> MyModel = >>>> >>>> and here's the second form: >>>> >>>> MyModel.instance_eval do >>>> def count >>>> 1 >>>> end >>>> end >>>> >>>> (or:) >>>> >>>> MyModel.class_eval do >>>> class << self >>>> def count; 1; end >>>> end >>>> end >>>> >>>> Scott >>>> >>>> >>> >>> But the stubs are defined the same way in both occurrences, no? >>> >>> MyModel = mock('MyModel Class', :count => 1) >>> >>> By passing {:count => 1} to +stubs_and_options+ I should have defined >>> stubs on the mock object. I'm using it as a shortcut for this: >>> >>> MyModel = mock('MyModel Class') >>> MyModel.stub!(:count).and_return(1) >>> >>> If those example aren't doing the exact same thing I guess I'm a >>> little baffled (or maybe just need to go to sleep). >> >> The first one is redefining the constant 'MyModel'. The second one is just >> redefining a class method (the constant isn't changing - it's remaining >> whatever it was before - say, a class) >> >>> >>> >>>>> >>>>> >>>>> But, I'm starting to think they are not. I haven't looked at the >>>>> rSpec internals to verify, other than the parameter name: >>>>> >>>>> stubs_and_options+ lets you assign options and stub values >>>>> at the same time. The only option available is :null_object. >>>>> Anything else is treated as a stub value. >>>>> >>>>> So, is this problem? >>>> >>>> Yeah - so here are two related, but not equivalent ideas: mock objects, >>>> and >>>> stubs. A stub is just a faked out method - it can exist on a mock object >>>> (a >>>> completely fake object), or on a partial mock (i.e. a real object, with a >>>> method faked out). mock('My mock") is a mock object, >>>> MyRealObject.stub!(:foo) is a real object with the method foo faked out. >>>> >>>> What is the difference between a mock object and a fake object? A mock >>>> object will complain (read: raise an error) any time it receives a >>>> message >>>> which it doesn't understand (i.e. one which hasn't been explicitly >>>> stubbed). >>>> A real object will work as usual. (A null object mock is a special type >>>> of >>>> mock - one which never complains. For now, you shouldn't worry about >>>> it). >>>> >>> >>> Ok, I get what you saying, but as I understand it I am explicitly >>> stubbing out the methods on the _mock_ object and it's still >>> complaining. If +stubs_and_options+ isn't stubbing, then what is it >>> doing? >> >> That's right - the hash to the mock method is a shorthand. So these two are >> equivalent: >> >> my_mock = mock('a mock') >> my_mock.stub!(:foo).and_return(:bar) >> >> AND: >> >> my_mock = mock("a mock", {:foo => :bar}) >> >> Scott >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > Ok, then would you still insist that: > > This: > > http://gist.github.com/2372 > > Should produce this: > > # spec migration_spec.rb > .F > > 1) > Spec::Mocks::MockExpectationError in 'Migration should find the records' > Mock 'MyModel Class' received unexpected message :count with (no args) > ./migration.rb:14:in `run' > ./migration_spec.rb:19: > > Finished in 0.009435 seconds > > -------------------- > > And like I said earlier, this code passes both examples with FlexMock( > if you simply replace mock with flexmock and uncomment the code in > spec_helper, of course you need the flexmock gem) I can't speak for why it's passing in Flexmock, but I can explain why it's failing in rspec. RSpec clears out all stub methods and message expectations at the end of each example. In this case, the stub on count is defined in a before(:all) block, which is only executed once, before all the examples are run (perhaps before(:any) would be a more clear expression of this?). After the first example is executed, that stub goes away. So when the mock receives the :count message in the second example, it's not expecting it (which is exactly what it's telling you). If you run the second example by itself (spec migration_spec.rb -e "should find the records") it will pass. You can solve the immediate problem by removing the stubs from the initial declaration of the MyModel constant and moving them to a before(:each) block so they get set before each example. Another option is to set :null_object => true. That will tell the mock to ignore unexpected messages, however the stub on find might still need to move to before(:each) because it returns something. Also - this code creates instance variables that get used across examples. If something happens in the first example to change the state of @record, you're going to get the same object in the second example and it becomes a challenge to understand what's happening when there are failures in the second example. I don't use before(:all) blocks this way for exactly this reason. They are run only once, and can cause a lot of confusion because they leak state across examples. The way I usually go about something like this is to create a simple empty class: class MyModel; end And then set expectations on it before(:each) example. You can get the gist of what I'm talking about here: http://gist.github.com/2438 - I've got two different approaches in two separate commits, so grab the repo to see both (this is my first time checking out gist - wow!). HTH, David From lists at ruby-forum.com Fri Jul 25 09:08:25 2008 From: lists at ruby-forum.com (Joseph Wilk) Date: Fri, 25 Jul 2008 15:08:25 +0200 Subject: [rspec-users] HTML Story Formatter In-Reply-To: <57c63afe0807240544p5a8adc2keaa21aac0ca1fe0e@mail.gmail.com> References: <1216902734.7340.14.camel@tybalt> <57c63afe0807240544p5a8adc2keaa21aac0ca1fe0e@mail.gmail.com> Message-ID: To handle this I wrote a patch which delivered the styles in the html formatters output. In much the same way as the html spec formatter does. I know Aslak Helles?y has been looking at the editable html stories. Is it acceptable to have stories have styles embedded in the html formatter until Aslak's editable stories project evolves? I could imagine there are some arguments that the HTML output of stories is something people might want to control the look and feel of, more so than specs as they are seen more frequently by customers. Perhapes by default the styles are embedded in the html formatter but if a CSS stylesheet is passed to the formatter than it will suppress this output and use your custom css. something like: ruby stories/all.rb --format html --css my_own.css -- Joseph Wilk, http://www.joesniff.co.uk David Chelimsky wrote: > On Thu, Jul 24, 2008 at 7:32 AM, Jonathan Leighton > wrote: >> Hiya, >> >> I am trying to use the HTML Story Formatter in conjunction with >> CruiseControl.rb. I have got it outputting the stories to a file, but I >> notice there are CSS and JS files linked in the head, which don't appear >> to be anywhere in the rspec repository. Are these files available and if >> so where? > > They're in the story_server directory. We haven't automated this yet, > so what I do is just copy them to a logical place and set up a rake > task to put the stories in the same place. On Rails projects, I've > gotten into the habit of putting them in > public/doc/[javascripts|stylesheets] (or similar) and then use this > rake task. > > namespace :stories do > > desc "Run all the stories (HTML)" > task :html do > sh "ruby stories/all.rb -fh:public/doc/index.html" > end > > end > > Now the customers can see the story output at /docs. Of course, so can > anybody else, so that might come down before releasing or move to a > controller that can manage who gets to see it. But this should give > you an idea. > > Also note that the javascript is 1/2 baked at this point and includes > an "add step" (non) feature (which you'll see in the browser) that > doesn't really do anything. > > Maybe it's time to get rid of that for now and standardize on where > this stuff goes :) > > HTH, > David -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Fri Jul 25 09:11:38 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 25 Jul 2008 08:11:38 -0500 Subject: [rspec-users] HTML Story Formatter In-Reply-To: References: <1216902734.7340.14.camel@tybalt> <57c63afe0807240544p5a8adc2keaa21aac0ca1fe0e@mail.gmail.com> Message-ID: <57c63afe0807250611p5a950d51icefc3c36829650f2@mail.gmail.com> On Fri, Jul 25, 2008 at 8:08 AM, Joseph Wilk wrote: > To handle this I wrote a patch which delivered the styles in the html > formatters output. In much the same way as the html spec formatter does. > > I know Aslak Helles?y has been looking at the editable html stories. > > Is it acceptable to have stories have styles embedded in the html > formatter until Aslak's editable stories project evolves? > > I could imagine there are some arguments that the HTML output of stories > is something people might want to control the look and feel of, more so > than specs as they are seen more frequently by customers. > > Perhapes by default the styles are embedded in the html formatter but if > a CSS stylesheet is passed to the formatter than it will suppress this > output and use your custom css. > > something like: > ruby stories/all.rb --format html --css my_own.css That all sounds reasonable to me. Sensible defaults, yet configurable. Other opinions? > > -- > Joseph Wilk, > http://www.joesniff.co.uk > > > > David Chelimsky wrote: >> On Thu, Jul 24, 2008 at 7:32 AM, Jonathan Leighton >> wrote: >>> Hiya, >>> >>> I am trying to use the HTML Story Formatter in conjunction with >>> CruiseControl.rb. I have got it outputting the stories to a file, but I >>> notice there are CSS and JS files linked in the head, which don't appear >>> to be anywhere in the rspec repository. Are these files available and if >>> so where? >> >> They're in the story_server directory. We haven't automated this yet, >> so what I do is just copy them to a logical place and set up a rake >> task to put the stories in the same place. On Rails projects, I've >> gotten into the habit of putting them in >> public/doc/[javascripts|stylesheets] (or similar) and then use this >> rake task. >> >> namespace :stories do >> >> desc "Run all the stories (HTML)" >> task :html do >> sh "ruby stories/all.rb -fh:public/doc/index.html" >> end >> >> end >> >> Now the customers can see the story output at /docs. Of course, so can >> anybody else, so that might come down before releasing or move to a >> controller that can manage who gets to see it. But this should give >> you an idea. >> >> Also note that the javascript is 1/2 baked at this point and includes >> an "add step" (non) feature (which you'll see in the browser) that >> doesn't really do anything. >> >> Maybe it's time to get rid of that for now and standardize on where >> this stuff goes :) >> >> HTH, >> David > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Fri Jul 25 09:15:14 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 25 Jul 2008 08:15:14 -0500 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <57c63afe0807250557lab67c5bj9641dc4b24a1ee6@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> <3795d7870807242132v6162aa36pdc2936e5fcb99d9d@mail.gmail.com> <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> <3795d7870807242215ldd9cd55oa41d156f17c94d96@mail.gmail.com> <7B825364-11F8-4235-9C90-69D0756E47E5@railsnewbie.com> <3795d7870807242234j2e7aeeb2q979f227c3bd5791b@mail.gmail.com> <57c63afe0807250557lab67c5bj9641dc4b24a1ee6@mail.gmail.com> Message-ID: <57c63afe0807250615t4c9a4a51pc5a66d59081bef6f@mail.gmail.com> On Fri, Jul 25, 2008 at 7:57 AM, David Chelimsky wrote: > On Fri, Jul 25, 2008 at 12:34 AM, Matt Lins wrote: >> On Fri, Jul 25, 2008 at 12:25 AM, Scott Taylor >> wrote: >>> >>> On Jul 25, 2008, at 1:15 AM, Matt Lins wrote: >>> >>>> On Thu, Jul 24, 2008 at 11:47 PM, Scott Taylor >>>> wrote: >>>>> >>>>> On Jul 25, 2008, at 12:32 AM, Matt Lins wrote: >>>>> >>>>>> I suppose the way I'm defining the stubs, differs from what Dave is >>>>>> doing in his example. >>>>>> >>>>>> I assumed that: >>>>>> >>>>>> MyModel = mock('MyModel Class', :count => 1) >>>>>> >>>>>> was the same as: >>>>>> >>>>>> MyModel.stub!(:count).and_return(1) >>>>> >>>>> Nope. Not even close. Here's an equivalent of the first form: >>>>> >>>>> Object.send :remove_const, :MyModel >>>>> MyModel = >>>>> >>>>> and here's the second form: >>>>> >>>>> MyModel.instance_eval do >>>>> def count >>>>> 1 >>>>> end >>>>> end >>>>> >>>>> (or:) >>>>> >>>>> MyModel.class_eval do >>>>> class << self >>>>> def count; 1; end >>>>> end >>>>> end >>>>> >>>>> Scott >>>>> >>>>> >>>> >>>> But the stubs are defined the same way in both occurrences, no? >>>> >>>> MyModel = mock('MyModel Class', :count => 1) >>>> >>>> By passing {:count => 1} to +stubs_and_options+ I should have defined >>>> stubs on the mock object. I'm using it as a shortcut for this: >>>> >>>> MyModel = mock('MyModel Class') >>>> MyModel.stub!(:count).and_return(1) >>>> >>>> If those example aren't doing the exact same thing I guess I'm a >>>> little baffled (or maybe just need to go to sleep). >>> >>> The first one is redefining the constant 'MyModel'. The second one is just >>> redefining a class method (the constant isn't changing - it's remaining >>> whatever it was before - say, a class) >>> >>>> >>>> >>>>>> >>>>>> >>>>>> But, I'm starting to think they are not. I haven't looked at the >>>>>> rSpec internals to verify, other than the parameter name: >>>>>> >>>>>> stubs_and_options+ lets you assign options and stub values >>>>>> at the same time. The only option available is :null_object. >>>>>> Anything else is treated as a stub value. >>>>>> >>>>>> So, is this problem? >>>>> >>>>> Yeah - so here are two related, but not equivalent ideas: mock objects, >>>>> and >>>>> stubs. A stub is just a faked out method - it can exist on a mock object >>>>> (a >>>>> completely fake object), or on a partial mock (i.e. a real object, with a >>>>> method faked out). mock('My mock") is a mock object, >>>>> MyRealObject.stub!(:foo) is a real object with the method foo faked out. >>>>> >>>>> What is the difference between a mock object and a fake object? A mock >>>>> object will complain (read: raise an error) any time it receives a >>>>> message >>>>> which it doesn't understand (i.e. one which hasn't been explicitly >>>>> stubbed). >>>>> A real object will work as usual. (A null object mock is a special type >>>>> of >>>>> mock - one which never complains. For now, you shouldn't worry about >>>>> it). >>>>> >>>> >>>> Ok, I get what you saying, but as I understand it I am explicitly >>>> stubbing out the methods on the _mock_ object and it's still >>>> complaining. If +stubs_and_options+ isn't stubbing, then what is it >>>> doing? >>> >>> That's right - the hash to the mock method is a shorthand. So these two are >>> equivalent: >>> >>> my_mock = mock('a mock') >>> my_mock.stub!(:foo).and_return(:bar) >>> >>> AND: >>> >>> my_mock = mock("a mock", {:foo => :bar}) >>> >>> Scott >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> Ok, then would you still insist that: >> >> This: >> >> http://gist.github.com/2372 >> >> Should produce this: >> >> # spec migration_spec.rb >> .F >> >> 1) >> Spec::Mocks::MockExpectationError in 'Migration should find the records' >> Mock 'MyModel Class' received unexpected message :count with (no args) >> ./migration.rb:14:in `run' >> ./migration_spec.rb:19: >> >> Finished in 0.009435 seconds >> >> -------------------- >> >> And like I said earlier, this code passes both examples with FlexMock( >> if you simply replace mock with flexmock and uncomment the code in >> spec_helper, of course you need the flexmock gem) > > I can't speak for why it's passing in Flexmock, but I can explain why > it's failing in rspec. > > RSpec clears out all stub methods and message expectations at the end > of each example. In this case, the stub on count is defined in a > before(:all) block, which is only executed once, before all the > examples are run (perhaps before(:any) would be a more clear > expression of this?). After the first example is executed, that stub > goes away. So when the mock receives the :count message in the second > example, it's not expecting it (which is exactly what it's telling > you). If you run the second example by itself (spec migration_spec.rb > -e "should find the records") it will pass. > > You can solve the immediate problem by removing the stubs from the > initial declaration of the MyModel constant and moving them to a > before(:each) block so they get set before each example. > > Another option is to set :null_object => true. That will tell the mock > to ignore unexpected messages, however the stub on find might still > need to move to before(:each) because it returns something. > > Also - this code creates instance variables that get used across > examples. If something happens in the first example to change the > state of @record, you're going to get the same object in the second > example and it becomes a challenge to understand what's happening when > there are failures in the second example. > > I don't use before(:all) blocks this way for exactly this reason. They > are run only once, and can cause a lot of confusion because they leak > state across examples. The way I usually go about something like this > is to create a simple empty class: > > class MyModel; end > > And then set expectations on it before(:each) example. > > You can get the gist of what I'm talking about here: > http://gist.github.com/2438 - I've got two different approaches in two > separate commits, so grab the repo to see both Or you *could* just look at them on line! https://gist.github.com/2438/040f26916032ad864ba51d0d733e16056c77be42 https://gist.github.com/2438/0ee4fcaebbafdbdab77dffd5228a9aae92f17191 > (this is my first time > checking out gist - wow!). > > HTH, > David > From mattlins at gmail.com Fri Jul 25 09:30:20 2008 From: mattlins at gmail.com (Matt Lins) Date: Fri, 25 Jul 2008 08:30:20 -0500 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <57c63afe0807250615t4c9a4a51pc5a66d59081bef6f@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <9E406612-743D-4DFB-BAFB-6975826A289F@railsnewbie.com> <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> <3795d7870807242132v6162aa36pdc2936e5fcb99d9d@mail.gmail.com> <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> <3795d7870807242215ldd9cd55oa41d156f17c94d96@mail.gmail.com> <7B825364-11F8-4235-9C90-69D0756E47E5@railsnewbie.com> <3795d7870807242234j2e7aeeb2q979f227c3bd5791b@mail.gmail.com> <57c63afe0807250557lab67c5bj9641dc4b24a1ee6@mail.gmail.com> <57c63afe0807250615t4c9a4a51pc5a66d59081bef6f@mail.gmail.com> Message-ID: <3795d7870807250630q65241e46y3e81d8e1de4f4758@mail.gmail.com> Yes, gist is great! Thank you very much for taking the time to look at this. I like your suggestions very much and will use them. At this point I'm just messing around, but I don't understand why this doesn't work. One more bad implementation if you have time: http://gist.github.com/2372 I'm removing the constant after each spec runs and redefining it before each runs. The second spec still doesn't pass though, even though the constant is defined before each spec. Again, I realize this is horrible, but it should still work, no? On Fri, Jul 25, 2008 at 8:15 AM, David Chelimsky wrote: > On Fri, Jul 25, 2008 at 7:57 AM, David Chelimsky wrote: >> On Fri, Jul 25, 2008 at 12:34 AM, Matt Lins wrote: >>> On Fri, Jul 25, 2008 at 12:25 AM, Scott Taylor >>> wrote: >>>> >>>> On Jul 25, 2008, at 1:15 AM, Matt Lins wrote: >>>> >>>>> On Thu, Jul 24, 2008 at 11:47 PM, Scott Taylor >>>>> wrote: >>>>>> >>>>>> On Jul 25, 2008, at 12:32 AM, Matt Lins wrote: >>>>>> >>>>>>> I suppose the way I'm defining the stubs, differs from what Dave is >>>>>>> doing in his example. >>>>>>> >>>>>>> I assumed that: >>>>>>> >>>>>>> MyModel = mock('MyModel Class', :count => 1) >>>>>>> >>>>>>> was the same as: >>>>>>> >>>>>>> MyModel.stub!(:count).and_return(1) >>>>>> >>>>>> Nope. Not even close. Here's an equivalent of the first form: >>>>>> >>>>>> Object.send :remove_const, :MyModel >>>>>> MyModel = >>>>>> >>>>>> and here's the second form: >>>>>> >>>>>> MyModel.instance_eval do >>>>>> def count >>>>>> 1 >>>>>> end >>>>>> end >>>>>> >>>>>> (or:) >>>>>> >>>>>> MyModel.class_eval do >>>>>> class << self >>>>>> def count; 1; end >>>>>> end >>>>>> end >>>>>> >>>>>> Scott >>>>>> >>>>>> >>>>> >>>>> But the stubs are defined the same way in both occurrences, no? >>>>> >>>>> MyModel = mock('MyModel Class', :count => 1) >>>>> >>>>> By passing {:count => 1} to +stubs_and_options+ I should have defined >>>>> stubs on the mock object. I'm using it as a shortcut for this: >>>>> >>>>> MyModel = mock('MyModel Class') >>>>> MyModel.stub!(:count).and_return(1) >>>>> >>>>> If those example aren't doing the exact same thing I guess I'm a >>>>> little baffled (or maybe just need to go to sleep). >>>> >>>> The first one is redefining the constant 'MyModel'. The second one is just >>>> redefining a class method (the constant isn't changing - it's remaining >>>> whatever it was before - say, a class) >>>> >>>>> >>>>> >>>>>>> >>>>>>> >>>>>>> But, I'm starting to think they are not. I haven't looked at the >>>>>>> rSpec internals to verify, other than the parameter name: >>>>>>> >>>>>>> stubs_and_options+ lets you assign options and stub values >>>>>>> at the same time. The only option available is :null_object. >>>>>>> Anything else is treated as a stub value. >>>>>>> >>>>>>> So, is this problem? >>>>>> >>>>>> Yeah - so here are two related, but not equivalent ideas: mock objects, >>>>>> and >>>>>> stubs. A stub is just a faked out method - it can exist on a mock object >>>>>> (a >>>>>> completely fake object), or on a partial mock (i.e. a real object, with a >>>>>> method faked out). mock('My mock") is a mock object, >>>>>> MyRealObject.stub!(:foo) is a real object with the method foo faked out. >>>>>> >>>>>> What is the difference between a mock object and a fake object? A mock >>>>>> object will complain (read: raise an error) any time it receives a >>>>>> message >>>>>> which it doesn't understand (i.e. one which hasn't been explicitly >>>>>> stubbed). >>>>>> A real object will work as usual. (A null object mock is a special type >>>>>> of >>>>>> mock - one which never complains. For now, you shouldn't worry about >>>>>> it). >>>>>> >>>>> >>>>> Ok, I get what you saying, but as I understand it I am explicitly >>>>> stubbing out the methods on the _mock_ object and it's still >>>>> complaining. If +stubs_and_options+ isn't stubbing, then what is it >>>>> doing? >>>> >>>> That's right - the hash to the mock method is a shorthand. So these two are >>>> equivalent: >>>> >>>> my_mock = mock('a mock') >>>> my_mock.stub!(:foo).and_return(:bar) >>>> >>>> AND: >>>> >>>> my_mock = mock("a mock", {:foo => :bar}) >>>> >>>> Scott >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> >>> Ok, then would you still insist that: >>> >>> This: >>> >>> http://gist.github.com/2372 >>> >>> Should produce this: >>> >>> # spec migration_spec.rb >>> .F >>> >>> 1) >>> Spec::Mocks::MockExpectationError in 'Migration should find the records' >>> Mock 'MyModel Class' received unexpected message :count with (no args) >>> ./migration.rb:14:in `run' >>> ./migration_spec.rb:19: >>> >>> Finished in 0.009435 seconds >>> >>> -------------------- >>> >>> And like I said earlier, this code passes both examples with FlexMock( >>> if you simply replace mock with flexmock and uncomment the code in >>> spec_helper, of course you need the flexmock gem) >> >> I can't speak for why it's passing in Flexmock, but I can explain why >> it's failing in rspec. >> >> RSpec clears out all stub methods and message expectations at the end >> of each example. In this case, the stub on count is defined in a >> before(:all) block, which is only executed once, before all the >> examples are run (perhaps before(:any) would be a more clear >> expression of this?). After the first example is executed, that stub >> goes away. So when the mock receives the :count message in the second >> example, it's not expecting it (which is exactly what it's telling >> you). If you run the second example by itself (spec migration_spec.rb >> -e "should find the records") it will pass. >> >> You can solve the immediate problem by removing the stubs from the >> initial declaration of the MyModel constant and moving them to a >> before(:each) block so they get set before each example. >> >> Another option is to set :null_object => true. That will tell the mock >> to ignore unexpected messages, however the stub on find might still >> need to move to before(:each) because it returns something. >> >> Also - this code creates instance variables that get used across >> examples. If something happens in the first example to change the >> state of @record, you're going to get the same object in the second >> example and it becomes a challenge to understand what's happening when >> there are failures in the second example. >> >> I don't use before(:all) blocks this way for exactly this reason. They >> are run only once, and can cause a lot of confusion because they leak >> state across examples. The way I usually go about something like this >> is to create a simple empty class: >> >> class MyModel; end >> >> And then set expectations on it before(:each) example. >> >> You can get the gist of what I'm talking about here: >> http://gist.github.com/2438 - I've got two different approaches in two >> separate commits, so grab the repo to see both > > Or you *could* just look at them on line! > > https://gist.github.com/2438/040f26916032ad864ba51d0d733e16056c77be42 > https://gist.github.com/2438/0ee4fcaebbafdbdab77dffd5228a9aae92f17191 > > > >> (this is my first time >> checking out gist - wow!). >> >> HTH, >> David >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jul 25 09:40:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 25 Jul 2008 08:40:53 -0500 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <3795d7870807250630q65241e46y3e81d8e1de4f4758@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> <3795d7870807242132v6162aa36pdc2936e5fcb99d9d@mail.gmail.com> <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> <3795d7870807242215ldd9cd55oa41d156f17c94d96@mail.gmail.com> <7B825364-11F8-4235-9C90-69D0756E47E5@railsnewbie.com> <3795d7870807242234j2e7aeeb2q979f227c3bd5791b@mail.gmail.com> <57c63afe0807250557lab67c5bj9641dc4b24a1ee6@mail.gmail.com> <57c63afe0807250615t4c9a4a51pc5a66d59081bef6f@mail.gmail.com> <3795d7870807250630q65241e46y3e81d8e1de4f4758@mail.gmail.com> Message-ID: <57c63afe0807250640q22ab0a0aq861aeb45772807b1@mail.gmail.com> > On Fri, Jul 25, 2008 at 8:15 AM, David Chelimsky wrote: >> On Fri, Jul 25, 2008 at 7:57 AM, David Chelimsky wrote: >>> On Fri, Jul 25, 2008 at 12:34 AM, Matt Lins wrote: >>>> On Fri, Jul 25, 2008 at 12:25 AM, Scott Taylor >>>> wrote: >>>>> >>>>> On Jul 25, 2008, at 1:15 AM, Matt Lins wrote: >>>>> >>>>>> On Thu, Jul 24, 2008 at 11:47 PM, Scott Taylor >>>>>> wrote: >>>>>>> >>>>>>> On Jul 25, 2008, at 12:32 AM, Matt Lins wrote: >>>>>>> >>>>>>>> I suppose the way I'm defining the stubs, differs from what Dave is >>>>>>>> doing in his example. >>>>>>>> >>>>>>>> I assumed that: >>>>>>>> >>>>>>>> MyModel = mock('MyModel Class', :count => 1) >>>>>>>> >>>>>>>> was the same as: >>>>>>>> >>>>>>>> MyModel.stub!(:count).and_return(1) >>>>>>> >>>>>>> Nope. Not even close. Here's an equivalent of the first form: >>>>>>> >>>>>>> Object.send :remove_const, :MyModel >>>>>>> MyModel = >>>>>>> >>>>>>> and here's the second form: >>>>>>> >>>>>>> MyModel.instance_eval do >>>>>>> def count >>>>>>> 1 >>>>>>> end >>>>>>> end >>>>>>> >>>>>>> (or:) >>>>>>> >>>>>>> MyModel.class_eval do >>>>>>> class << self >>>>>>> def count; 1; end >>>>>>> end >>>>>>> end >>>>>>> >>>>>>> Scott >>>>>>> >>>>>>> >>>>>> >>>>>> But the stubs are defined the same way in both occurrences, no? >>>>>> >>>>>> MyModel = mock('MyModel Class', :count => 1) >>>>>> >>>>>> By passing {:count => 1} to +stubs_and_options+ I should have defined >>>>>> stubs on the mock object. I'm using it as a shortcut for this: >>>>>> >>>>>> MyModel = mock('MyModel Class') >>>>>> MyModel.stub!(:count).and_return(1) >>>>>> >>>>>> If those example aren't doing the exact same thing I guess I'm a >>>>>> little baffled (or maybe just need to go to sleep). >>>>> >>>>> The first one is redefining the constant 'MyModel'. The second one is just >>>>> redefining a class method (the constant isn't changing - it's remaining >>>>> whatever it was before - say, a class) >>>>> >>>>>> >>>>>> >>>>>>>> >>>>>>>> >>>>>>>> But, I'm starting to think they are not. I haven't looked at the >>>>>>>> rSpec internals to verify, other than the parameter name: >>>>>>>> >>>>>>>> stubs_and_options+ lets you assign options and stub values >>>>>>>> at the same time. The only option available is :null_object. >>>>>>>> Anything else is treated as a stub value. >>>>>>>> >>>>>>>> So, is this problem? >>>>>>> >>>>>>> Yeah - so here are two related, but not equivalent ideas: mock objects, >>>>>>> and >>>>>>> stubs. A stub is just a faked out method - it can exist on a mock object >>>>>>> (a >>>>>>> completely fake object), or on a partial mock (i.e. a real object, with a >>>>>>> method faked out). mock('My mock") is a mock object, >>>>>>> MyRealObject.stub!(:foo) is a real object with the method foo faked out. >>>>>>> >>>>>>> What is the difference between a mock object and a fake object? A mock >>>>>>> object will complain (read: raise an error) any time it receives a >>>>>>> message >>>>>>> which it doesn't understand (i.e. one which hasn't been explicitly >>>>>>> stubbed). >>>>>>> A real object will work as usual. (A null object mock is a special type >>>>>>> of >>>>>>> mock - one which never complains. For now, you shouldn't worry about >>>>>>> it). >>>>>>> >>>>>> >>>>>> Ok, I get what you saying, but as I understand it I am explicitly >>>>>> stubbing out the methods on the _mock_ object and it's still >>>>>> complaining. If +stubs_and_options+ isn't stubbing, then what is it >>>>>> doing? >>>>> >>>>> That's right - the hash to the mock method is a shorthand. So these two are >>>>> equivalent: >>>>> >>>>> my_mock = mock('a mock') >>>>> my_mock.stub!(:foo).and_return(:bar) >>>>> >>>>> AND: >>>>> >>>>> my_mock = mock("a mock", {:foo => :bar}) >>>>> >>>>> Scott >>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>> >>>> Ok, then would you still insist that: >>>> >>>> This: >>>> >>>> http://gist.github.com/2372 >>>> >>>> Should produce this: >>>> >>>> # spec migration_spec.rb >>>> .F >>>> >>>> 1) >>>> Spec::Mocks::MockExpectationError in 'Migration should find the records' >>>> Mock 'MyModel Class' received unexpected message :count with (no args) >>>> ./migration.rb:14:in `run' >>>> ./migration_spec.rb:19: >>>> >>>> Finished in 0.009435 seconds >>>> >>>> -------------------- >>>> >>>> And like I said earlier, this code passes both examples with FlexMock( >>>> if you simply replace mock with flexmock and uncomment the code in >>>> spec_helper, of course you need the flexmock gem) >>> >>> I can't speak for why it's passing in Flexmock, but I can explain why >>> it's failing in rspec. >>> >>> RSpec clears out all stub methods and message expectations at the end >>> of each example. In this case, the stub on count is defined in a >>> before(:all) block, which is only executed once, before all the >>> examples are run (perhaps before(:any) would be a more clear >>> expression of this?). After the first example is executed, that stub >>> goes away. So when the mock receives the :count message in the second >>> example, it's not expecting it (which is exactly what it's telling >>> you). If you run the second example by itself (spec migration_spec.rb >>> -e "should find the records") it will pass. >>> >>> You can solve the immediate problem by removing the stubs from the >>> initial declaration of the MyModel constant and moving them to a >>> before(:each) block so they get set before each example. >>> >>> Another option is to set :null_object => true. That will tell the mock >>> to ignore unexpected messages, however the stub on find might still >>> need to move to before(:each) because it returns something. >>> >>> Also - this code creates instance variables that get used across >>> examples. If something happens in the first example to change the >>> state of @record, you're going to get the same object in the second >>> example and it becomes a challenge to understand what's happening when >>> there are failures in the second example. >>> >>> I don't use before(:all) blocks this way for exactly this reason. They >>> are run only once, and can cause a lot of confusion because they leak >>> state across examples. The way I usually go about something like this >>> is to create a simple empty class: >>> >>> class MyModel; end >>> >>> And then set expectations on it before(:each) example. >>> >>> You can get the gist of what I'm talking about here: >>> http://gist.github.com/2438 - I've got two different approaches in two >>> separate commits, so grab the repo to see both >> >> Or you *could* just look at them on line! >> >> https://gist.github.com/2438/040f26916032ad864ba51d0d733e16056c77be42 >> https://gist.github.com/2438/0ee4fcaebbafdbdab77dffd5228a9aae92f17191 >> >> >> >>> (this is my first time >>> checking out gist - wow!). >>> >>> HTH, >>> David On Fri, Jul 25, 2008 at 8:30 AM, Matt Lins wrote: > Yes, gist is great! > > Thank you very much for taking the time to look at this. I like your > suggestions very much and will use them. At this point I'm just > messing around, but I don't understand why this doesn't work. > > One more bad implementation if you have time: I don't really have much - packing for a week's holiday. > http://gist.github.com/2372 > > I'm removing the constant after each spec runs and redefining it > before each runs. The second spec still doesn't pass though, even > though the constant is defined before each spec. Is is the same failure? > Again, I realize this is horrible, but it should still work, no? From mattlins at gmail.com Fri Jul 25 09:44:39 2008 From: mattlins at gmail.com (Matt Lins) Date: Fri, 25 Jul 2008 08:44:39 -0500 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <57c63afe0807250640q22ab0a0aq861aeb45772807b1@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <3795d7870807242132v6162aa36pdc2936e5fcb99d9d@mail.gmail.com> <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> <3795d7870807242215ldd9cd55oa41d156f17c94d96@mail.gmail.com> <7B825364-11F8-4235-9C90-69D0756E47E5@railsnewbie.com> <3795d7870807242234j2e7aeeb2q979f227c3bd5791b@mail.gmail.com> <57c63afe0807250557lab67c5bj9641dc4b24a1ee6@mail.gmail.com> <57c63afe0807250615t4c9a4a51pc5a66d59081bef6f@mail.gmail.com> <3795d7870807250630q65241e46y3e81d8e1de4f4758@mail.gmail.com> <57c63afe0807250640q22ab0a0aq861aeb45772807b1@mail.gmail.com> Message-ID: <3795d7870807250644n5b785fd6if59c57b807a2917b@mail.gmail.com> On Fri, Jul 25, 2008 at 8:40 AM, David Chelimsky wrote: >> On Fri, Jul 25, 2008 at 8:15 AM, David Chelimsky wrote: >>> On Fri, Jul 25, 2008 at 7:57 AM, David Chelimsky wrote: >>>> On Fri, Jul 25, 2008 at 12:34 AM, Matt Lins wrote: >>>>> On Fri, Jul 25, 2008 at 12:25 AM, Scott Taylor >>>>> wrote: >>>>>> >>>>>> On Jul 25, 2008, at 1:15 AM, Matt Lins wrote: >>>>>> >>>>>>> On Thu, Jul 24, 2008 at 11:47 PM, Scott Taylor >>>>>>> wrote: >>>>>>>> >>>>>>>> On Jul 25, 2008, at 12:32 AM, Matt Lins wrote: >>>>>>>> >>>>>>>>> I suppose the way I'm defining the stubs, differs from what Dave is >>>>>>>>> doing in his example. >>>>>>>>> >>>>>>>>> I assumed that: >>>>>>>>> >>>>>>>>> MyModel = mock('MyModel Class', :count => 1) >>>>>>>>> >>>>>>>>> was the same as: >>>>>>>>> >>>>>>>>> MyModel.stub!(:count).and_return(1) >>>>>>>> >>>>>>>> Nope. Not even close. Here's an equivalent of the first form: >>>>>>>> >>>>>>>> Object.send :remove_const, :MyModel >>>>>>>> MyModel = >>>>>>>> >>>>>>>> and here's the second form: >>>>>>>> >>>>>>>> MyModel.instance_eval do >>>>>>>> def count >>>>>>>> 1 >>>>>>>> end >>>>>>>> end >>>>>>>> >>>>>>>> (or:) >>>>>>>> >>>>>>>> MyModel.class_eval do >>>>>>>> class << self >>>>>>>> def count; 1; end >>>>>>>> end >>>>>>>> end >>>>>>>> >>>>>>>> Scott >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> But the stubs are defined the same way in both occurrences, no? >>>>>>> >>>>>>> MyModel = mock('MyModel Class', :count => 1) >>>>>>> >>>>>>> By passing {:count => 1} to +stubs_and_options+ I should have defined >>>>>>> stubs on the mock object. I'm using it as a shortcut for this: >>>>>>> >>>>>>> MyModel = mock('MyModel Class') >>>>>>> MyModel.stub!(:count).and_return(1) >>>>>>> >>>>>>> If those example aren't doing the exact same thing I guess I'm a >>>>>>> little baffled (or maybe just need to go to sleep). >>>>>> >>>>>> The first one is redefining the constant 'MyModel'. The second one is just >>>>>> redefining a class method (the constant isn't changing - it's remaining >>>>>> whatever it was before - say, a class) >>>>>> >>>>>>> >>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> But, I'm starting to think they are not. I haven't looked at the >>>>>>>>> rSpec internals to verify, other than the parameter name: >>>>>>>>> >>>>>>>>> stubs_and_options+ lets you assign options and stub values >>>>>>>>> at the same time. The only option available is :null_object. >>>>>>>>> Anything else is treated as a stub value. >>>>>>>>> >>>>>>>>> So, is this problem? >>>>>>>> >>>>>>>> Yeah - so here are two related, but not equivalent ideas: mock objects, >>>>>>>> and >>>>>>>> stubs. A stub is just a faked out method - it can exist on a mock object >>>>>>>> (a >>>>>>>> completely fake object), or on a partial mock (i.e. a real object, with a >>>>>>>> method faked out). mock('My mock") is a mock object, >>>>>>>> MyRealObject.stub!(:foo) is a real object with the method foo faked out. >>>>>>>> >>>>>>>> What is the difference between a mock object and a fake object? A mock >>>>>>>> object will complain (read: raise an error) any time it receives a >>>>>>>> message >>>>>>>> which it doesn't understand (i.e. one which hasn't been explicitly >>>>>>>> stubbed). >>>>>>>> A real object will work as usual. (A null object mock is a special type >>>>>>>> of >>>>>>>> mock - one which never complains. For now, you shouldn't worry about >>>>>>>> it). >>>>>>>> >>>>>>> >>>>>>> Ok, I get what you saying, but as I understand it I am explicitly >>>>>>> stubbing out the methods on the _mock_ object and it's still >>>>>>> complaining. If +stubs_and_options+ isn't stubbing, then what is it >>>>>>> doing? >>>>>> >>>>>> That's right - the hash to the mock method is a shorthand. So these two are >>>>>> equivalent: >>>>>> >>>>>> my_mock = mock('a mock') >>>>>> my_mock.stub!(:foo).and_return(:bar) >>>>>> >>>>>> AND: >>>>>> >>>>>> my_mock = mock("a mock", {:foo => :bar}) >>>>>> >>>>>> Scott >>>>>> >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>> >>>>> >>>>> Ok, then would you still insist that: >>>>> >>>>> This: >>>>> >>>>> http://gist.github.com/2372 >>>>> >>>>> Should produce this: >>>>> >>>>> # spec migration_spec.rb >>>>> .F >>>>> >>>>> 1) >>>>> Spec::Mocks::MockExpectationError in 'Migration should find the records' >>>>> Mock 'MyModel Class' received unexpected message :count with (no args) >>>>> ./migration.rb:14:in `run' >>>>> ./migration_spec.rb:19: >>>>> >>>>> Finished in 0.009435 seconds >>>>> >>>>> -------------------- >>>>> >>>>> And like I said earlier, this code passes both examples with FlexMock( >>>>> if you simply replace mock with flexmock and uncomment the code in >>>>> spec_helper, of course you need the flexmock gem) >>>> >>>> I can't speak for why it's passing in Flexmock, but I can explain why >>>> it's failing in rspec. >>>> >>>> RSpec clears out all stub methods and message expectations at the end >>>> of each example. In this case, the stub on count is defined in a >>>> before(:all) block, which is only executed once, before all the >>>> examples are run (perhaps before(:any) would be a more clear >>>> expression of this?). After the first example is executed, that stub >>>> goes away. So when the mock receives the :count message in the second >>>> example, it's not expecting it (which is exactly what it's telling >>>> you). If you run the second example by itself (spec migration_spec.rb >>>> -e "should find the records") it will pass. >>>> >>>> You can solve the immediate problem by removing the stubs from the >>>> initial declaration of the MyModel constant and moving them to a >>>> before(:each) block so they get set before each example. >>>> >>>> Another option is to set :null_object => true. That will tell the mock >>>> to ignore unexpected messages, however the stub on find might still >>>> need to move to before(:each) because it returns something. >>>> >>>> Also - this code creates instance variables that get used across >>>> examples. If something happens in the first example to change the >>>> state of @record, you're going to get the same object in the second >>>> example and it becomes a challenge to understand what's happening when >>>> there are failures in the second example. >>>> >>>> I don't use before(:all) blocks this way for exactly this reason. They >>>> are run only once, and can cause a lot of confusion because they leak >>>> state across examples. The way I usually go about something like this >>>> is to create a simple empty class: >>>> >>>> class MyModel; end >>>> >>>> And then set expectations on it before(:each) example. >>>> >>>> You can get the gist of what I'm talking about here: >>>> http://gist.github.com/2438 - I've got two different approaches in two >>>> separate commits, so grab the repo to see both >>> >>> Or you *could* just look at them on line! >>> >>> https://gist.github.com/2438/040f26916032ad864ba51d0d733e16056c77be42 >>> https://gist.github.com/2438/0ee4fcaebbafdbdab77dffd5228a9aae92f17191 >>> >>> >>> >>>> (this is my first time >>>> checking out gist - wow!). >>>> >>>> HTH, >>>> David > > On Fri, Jul 25, 2008 at 8:30 AM, Matt Lins wrote: >> Yes, gist is great! >> >> Thank you very much for taking the time to look at this. I like your >> suggestions very much and will use them. At this point I'm just >> messing around, but I don't understand why this doesn't work. >> >> One more bad implementation if you have time: > > I don't really have much - packing for a week's holiday. Ok, thanks anyway. Enjoy your holiday. :) > >> http://gist.github.com/2372 >> >> I'm removing the constant after each spec runs and redefining it >> before each runs. The second spec still doesn't pass though, even >> though the constant is defined before each spec. > > Is is the same failure? Yes. > >> Again, I realize this is horrible, but it should still work, no? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jul 25 09:49:41 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 25 Jul 2008 08:49:41 -0500 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <3795d7870807250644n5b785fd6if59c57b807a2917b@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> <3795d7870807242215ldd9cd55oa41d156f17c94d96@mail.gmail.com> <7B825364-11F8-4235-9C90-69D0756E47E5@railsnewbie.com> <3795d7870807242234j2e7aeeb2q979f227c3bd5791b@mail.gmail.com> <57c63afe0807250557lab67c5bj9641dc4b24a1ee6@mail.gmail.com> <57c63afe0807250615t4c9a4a51pc5a66d59081bef6f@mail.gmail.com> <3795d7870807250630q65241e46y3e81d8e1de4f4758@mail.gmail.com> <57c63afe0807250640q22ab0a0aq861aeb45772807b1@mail.gmail.com> <3795d7870807250644n5b785fd6if59c57b807a2917b@mail.gmail.com> Message-ID: <57c63afe0807250649h2ecc2411s47979910850946d7@mail.gmail.com> On Fri, Jul 25, 2008 at 8:44 AM, Matt Lins wrote: > On Fri, Jul 25, 2008 at 8:40 AM, David Chelimsky wrote: >>> On Fri, Jul 25, 2008 at 8:15 AM, David Chelimsky wrote: >>>> On Fri, Jul 25, 2008 at 7:57 AM, David Chelimsky wrote: >>>>> On Fri, Jul 25, 2008 at 12:34 AM, Matt Lins wrote: >>>>>> On Fri, Jul 25, 2008 at 12:25 AM, Scott Taylor >>>>>> wrote: >>>>>>> >>>>>>> On Jul 25, 2008, at 1:15 AM, Matt Lins wrote: >>>>>>> >>>>>>>> On Thu, Jul 24, 2008 at 11:47 PM, Scott Taylor >>>>>>>> wrote: >>>>>>>>> >>>>>>>>> On Jul 25, 2008, at 12:32 AM, Matt Lins wrote: >>>>>>>>> >>>>>>>>>> I suppose the way I'm defining the stubs, differs from what Dave is >>>>>>>>>> doing in his example. >>>>>>>>>> >>>>>>>>>> I assumed that: >>>>>>>>>> >>>>>>>>>> MyModel = mock('MyModel Class', :count => 1) >>>>>>>>>> >>>>>>>>>> was the same as: >>>>>>>>>> >>>>>>>>>> MyModel.stub!(:count).and_return(1) >>>>>>>>> >>>>>>>>> Nope. Not even close. Here's an equivalent of the first form: >>>>>>>>> >>>>>>>>> Object.send :remove_const, :MyModel >>>>>>>>> MyModel = >>>>>>>>> >>>>>>>>> and here's the second form: >>>>>>>>> >>>>>>>>> MyModel.instance_eval do >>>>>>>>> def count >>>>>>>>> 1 >>>>>>>>> end >>>>>>>>> end >>>>>>>>> >>>>>>>>> (or:) >>>>>>>>> >>>>>>>>> MyModel.class_eval do >>>>>>>>> class << self >>>>>>>>> def count; 1; end >>>>>>>>> end >>>>>>>>> end >>>>>>>>> >>>>>>>>> Scott >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> But the stubs are defined the same way in both occurrences, no? >>>>>>>> >>>>>>>> MyModel = mock('MyModel Class', :count => 1) >>>>>>>> >>>>>>>> By passing {:count => 1} to +stubs_and_options+ I should have defined >>>>>>>> stubs on the mock object. I'm using it as a shortcut for this: >>>>>>>> >>>>>>>> MyModel = mock('MyModel Class') >>>>>>>> MyModel.stub!(:count).and_return(1) >>>>>>>> >>>>>>>> If those example aren't doing the exact same thing I guess I'm a >>>>>>>> little baffled (or maybe just need to go to sleep). >>>>>>> >>>>>>> The first one is redefining the constant 'MyModel'. The second one is just >>>>>>> redefining a class method (the constant isn't changing - it's remaining >>>>>>> whatever it was before - say, a class) >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> But, I'm starting to think they are not. I haven't looked at the >>>>>>>>>> rSpec internals to verify, other than the parameter name: >>>>>>>>>> >>>>>>>>>> stubs_and_options+ lets you assign options and stub values >>>>>>>>>> at the same time. The only option available is :null_object. >>>>>>>>>> Anything else is treated as a stub value. >>>>>>>>>> >>>>>>>>>> So, is this problem? >>>>>>>>> >>>>>>>>> Yeah - so here are two related, but not equivalent ideas: mock objects, >>>>>>>>> and >>>>>>>>> stubs. A stub is just a faked out method - it can exist on a mock object >>>>>>>>> (a >>>>>>>>> completely fake object), or on a partial mock (i.e. a real object, with a >>>>>>>>> method faked out). mock('My mock") is a mock object, >>>>>>>>> MyRealObject.stub!(:foo) is a real object with the method foo faked out. >>>>>>>>> >>>>>>>>> What is the difference between a mock object and a fake object? A mock >>>>>>>>> object will complain (read: raise an error) any time it receives a >>>>>>>>> message >>>>>>>>> which it doesn't understand (i.e. one which hasn't been explicitly >>>>>>>>> stubbed). >>>>>>>>> A real object will work as usual. (A null object mock is a special type >>>>>>>>> of >>>>>>>>> mock - one which never complains. For now, you shouldn't worry about >>>>>>>>> it). >>>>>>>>> >>>>>>>> >>>>>>>> Ok, I get what you saying, but as I understand it I am explicitly >>>>>>>> stubbing out the methods on the _mock_ object and it's still >>>>>>>> complaining. If +stubs_and_options+ isn't stubbing, then what is it >>>>>>>> doing? >>>>>>> >>>>>>> That's right - the hash to the mock method is a shorthand. So these two are >>>>>>> equivalent: >>>>>>> >>>>>>> my_mock = mock('a mock') >>>>>>> my_mock.stub!(:foo).and_return(:bar) >>>>>>> >>>>>>> AND: >>>>>>> >>>>>>> my_mock = mock("a mock", {:foo => :bar}) >>>>>>> >>>>>>> Scott >>>>>>> >>>>>>> _______________________________________________ >>>>>>> rspec-users mailing list >>>>>>> rspec-users at rubyforge.org >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>> >>>>>> >>>>>> Ok, then would you still insist that: >>>>>> >>>>>> This: >>>>>> >>>>>> http://gist.github.com/2372 >>>>>> >>>>>> Should produce this: >>>>>> >>>>>> # spec migration_spec.rb >>>>>> .F >>>>>> >>>>>> 1) >>>>>> Spec::Mocks::MockExpectationError in 'Migration should find the records' >>>>>> Mock 'MyModel Class' received unexpected message :count with (no args) >>>>>> ./migration.rb:14:in `run' >>>>>> ./migration_spec.rb:19: >>>>>> >>>>>> Finished in 0.009435 seconds >>>>>> >>>>>> -------------------- >>>>>> >>>>>> And like I said earlier, this code passes both examples with FlexMock( >>>>>> if you simply replace mock with flexmock and uncomment the code in >>>>>> spec_helper, of course you need the flexmock gem) >>>>> >>>>> I can't speak for why it's passing in Flexmock, but I can explain why >>>>> it's failing in rspec. >>>>> >>>>> RSpec clears out all stub methods and message expectations at the end >>>>> of each example. In this case, the stub on count is defined in a >>>>> before(:all) block, which is only executed once, before all the >>>>> examples are run (perhaps before(:any) would be a more clear >>>>> expression of this?). After the first example is executed, that stub >>>>> goes away. So when the mock receives the :count message in the second >>>>> example, it's not expecting it (which is exactly what it's telling >>>>> you). If you run the second example by itself (spec migration_spec.rb >>>>> -e "should find the records") it will pass. >>>>> >>>>> You can solve the immediate problem by removing the stubs from the >>>>> initial declaration of the MyModel constant and moving them to a >>>>> before(:each) block so they get set before each example. >>>>> >>>>> Another option is to set :null_object => true. That will tell the mock >>>>> to ignore unexpected messages, however the stub on find might still >>>>> need to move to before(:each) because it returns something. >>>>> >>>>> Also - this code creates instance variables that get used across >>>>> examples. If something happens in the first example to change the >>>>> state of @record, you're going to get the same object in the second >>>>> example and it becomes a challenge to understand what's happening when >>>>> there are failures in the second example. >>>>> >>>>> I don't use before(:all) blocks this way for exactly this reason. They >>>>> are run only once, and can cause a lot of confusion because they leak >>>>> state across examples. The way I usually go about something like this >>>>> is to create a simple empty class: >>>>> >>>>> class MyModel; end >>>>> >>>>> And then set expectations on it before(:each) example. >>>>> >>>>> You can get the gist of what I'm talking about here: >>>>> http://gist.github.com/2438 - I've got two different approaches in two >>>>> separate commits, so grab the repo to see both >>>> >>>> Or you *could* just look at them on line! >>>> >>>> https://gist.github.com/2438/040f26916032ad864ba51d0d733e16056c77be42 >>>> https://gist.github.com/2438/0ee4fcaebbafdbdab77dffd5228a9aae92f17191 >>>> >>>> >>>> >>>>> (this is my first time >>>>> checking out gist - wow!). >>>>> >>>>> HTH, >>>>> David >> >> On Fri, Jul 25, 2008 at 8:30 AM, Matt Lins wrote: >>> Yes, gist is great! >>> >>> Thank you very much for taking the time to look at this. I like your >>> suggestions very much and will use them. At this point I'm just >>> messing around, but I don't understand why this doesn't work. >>> >>> One more bad implementation if you have time: >> >> I don't really have much - packing for a week's holiday. > > Ok, thanks anyway. Enjoy your holiday. :) > >> >>> http://gist.github.com/2372 >>> >>> I'm removing the constant after each spec runs and redefining it >>> before each runs. The second spec still doesn't pass though, even >>> though the constant is defined before each spec. >> >> Is is the same failure? > > Yes. What about when you run them each individually? spec migration_spec.rb - e 'should get a count of the records' spec migration_spec.rb - e 'should find the records' > >> >>> Again, I realize this is horrible, but it should still work, no? >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Jul 25 09:53:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 25 Jul 2008 08:53:21 -0500 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <57c63afe0807250649h2ecc2411s47979910850946d7@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <3795d7870807242215ldd9cd55oa41d156f17c94d96@mail.gmail.com> <7B825364-11F8-4235-9C90-69D0756E47E5@railsnewbie.com> <3795d7870807242234j2e7aeeb2q979f227c3bd5791b@mail.gmail.com> <57c63afe0807250557lab67c5bj9641dc4b24a1ee6@mail.gmail.com> <57c63afe0807250615t4c9a4a51pc5a66d59081bef6f@mail.gmail.com> <3795d7870807250630q65241e46y3e81d8e1de4f4758@mail.gmail.com> <57c63afe0807250640q22ab0a0aq861aeb45772807b1@mail.gmail.com> <3795d7870807250644n5b785fd6if59c57b807a2917b@mail.gmail.com> <57c63afe0807250649h2ecc2411s47979910850946d7@mail.gmail.com> Message-ID: <57c63afe0807250653u5e837846pde0ce7d4c46e7858@mail.gmail.com> On Fri, Jul 25, 2008 at 8:49 AM, David Chelimsky wrote: > On Fri, Jul 25, 2008 at 8:44 AM, Matt Lins wrote: >> On Fri, Jul 25, 2008 at 8:40 AM, David Chelimsky wrote: >>>> On Fri, Jul 25, 2008 at 8:15 AM, David Chelimsky wrote: >>>>> On Fri, Jul 25, 2008 at 7:57 AM, David Chelimsky wrote: >>>>>> On Fri, Jul 25, 2008 at 12:34 AM, Matt Lins wrote: >>>>>>> On Fri, Jul 25, 2008 at 12:25 AM, Scott Taylor >>>>>>> wrote: >>>>>>>> >>>>>>>> On Jul 25, 2008, at 1:15 AM, Matt Lins wrote: >>>>>>>> >>>>>>>>> On Thu, Jul 24, 2008 at 11:47 PM, Scott Taylor >>>>>>>>> wrote: >>>>>>>>>> >>>>>>>>>> On Jul 25, 2008, at 12:32 AM, Matt Lins wrote: >>>>>>>>>> >>>>>>>>>>> I suppose the way I'm defining the stubs, differs from what Dave is >>>>>>>>>>> doing in his example. >>>>>>>>>>> >>>>>>>>>>> I assumed that: >>>>>>>>>>> >>>>>>>>>>> MyModel = mock('MyModel Class', :count => 1) >>>>>>>>>>> >>>>>>>>>>> was the same as: >>>>>>>>>>> >>>>>>>>>>> MyModel.stub!(:count).and_return(1) >>>>>>>>>> >>>>>>>>>> Nope. Not even close. Here's an equivalent of the first form: >>>>>>>>>> >>>>>>>>>> Object.send :remove_const, :MyModel >>>>>>>>>> MyModel = >>>>>>>>>> >>>>>>>>>> and here's the second form: >>>>>>>>>> >>>>>>>>>> MyModel.instance_eval do >>>>>>>>>> def count >>>>>>>>>> 1 >>>>>>>>>> end >>>>>>>>>> end >>>>>>>>>> >>>>>>>>>> (or:) >>>>>>>>>> >>>>>>>>>> MyModel.class_eval do >>>>>>>>>> class << self >>>>>>>>>> def count; 1; end >>>>>>>>>> end >>>>>>>>>> end >>>>>>>>>> >>>>>>>>>> Scott >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>> But the stubs are defined the same way in both occurrences, no? >>>>>>>>> >>>>>>>>> MyModel = mock('MyModel Class', :count => 1) >>>>>>>>> >>>>>>>>> By passing {:count => 1} to +stubs_and_options+ I should have defined >>>>>>>>> stubs on the mock object. I'm using it as a shortcut for this: >>>>>>>>> >>>>>>>>> MyModel = mock('MyModel Class') >>>>>>>>> MyModel.stub!(:count).and_return(1) >>>>>>>>> >>>>>>>>> If those example aren't doing the exact same thing I guess I'm a >>>>>>>>> little baffled (or maybe just need to go to sleep). >>>>>>>> >>>>>>>> The first one is redefining the constant 'MyModel'. The second one is just >>>>>>>> redefining a class method (the constant isn't changing - it's remaining >>>>>>>> whatever it was before - say, a class) >>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> But, I'm starting to think they are not. I haven't looked at the >>>>>>>>>>> rSpec internals to verify, other than the parameter name: >>>>>>>>>>> >>>>>>>>>>> stubs_and_options+ lets you assign options and stub values >>>>>>>>>>> at the same time. The only option available is :null_object. >>>>>>>>>>> Anything else is treated as a stub value. >>>>>>>>>>> >>>>>>>>>>> So, is this problem? >>>>>>>>>> >>>>>>>>>> Yeah - so here are two related, but not equivalent ideas: mock objects, >>>>>>>>>> and >>>>>>>>>> stubs. A stub is just a faked out method - it can exist on a mock object >>>>>>>>>> (a >>>>>>>>>> completely fake object), or on a partial mock (i.e. a real object, with a >>>>>>>>>> method faked out). mock('My mock") is a mock object, >>>>>>>>>> MyRealObject.stub!(:foo) is a real object with the method foo faked out. >>>>>>>>>> >>>>>>>>>> What is the difference between a mock object and a fake object? A mock >>>>>>>>>> object will complain (read: raise an error) any time it receives a >>>>>>>>>> message >>>>>>>>>> which it doesn't understand (i.e. one which hasn't been explicitly >>>>>>>>>> stubbed). >>>>>>>>>> A real object will work as usual. (A null object mock is a special type >>>>>>>>>> of >>>>>>>>>> mock - one which never complains. For now, you shouldn't worry about >>>>>>>>>> it). >>>>>>>>>> >>>>>>>>> >>>>>>>>> Ok, I get what you saying, but as I understand it I am explicitly >>>>>>>>> stubbing out the methods on the _mock_ object and it's still >>>>>>>>> complaining. If +stubs_and_options+ isn't stubbing, then what is it >>>>>>>>> doing? >>>>>>>> >>>>>>>> That's right - the hash to the mock method is a shorthand. So these two are >>>>>>>> equivalent: >>>>>>>> >>>>>>>> my_mock = mock('a mock') >>>>>>>> my_mock.stub!(:foo).and_return(:bar) >>>>>>>> >>>>>>>> AND: >>>>>>>> >>>>>>>> my_mock = mock("a mock", {:foo => :bar}) >>>>>>>> >>>>>>>> Scott >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> rspec-users mailing list >>>>>>>> rspec-users at rubyforge.org >>>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>>> >>>>>>> >>>>>>> Ok, then would you still insist that: >>>>>>> >>>>>>> This: >>>>>>> >>>>>>> http://gist.github.com/2372 >>>>>>> >>>>>>> Should produce this: >>>>>>> >>>>>>> # spec migration_spec.rb >>>>>>> .F >>>>>>> >>>>>>> 1) >>>>>>> Spec::Mocks::MockExpectationError in 'Migration should find the records' >>>>>>> Mock 'MyModel Class' received unexpected message :count with (no args) >>>>>>> ./migration.rb:14:in `run' >>>>>>> ./migration_spec.rb:19: >>>>>>> >>>>>>> Finished in 0.009435 seconds >>>>>>> >>>>>>> -------------------- >>>>>>> >>>>>>> And like I said earlier, this code passes both examples with FlexMock( >>>>>>> if you simply replace mock with flexmock and uncomment the code in >>>>>>> spec_helper, of course you need the flexmock gem) >>>>>> >>>>>> I can't speak for why it's passing in Flexmock, but I can explain why >>>>>> it's failing in rspec. >>>>>> >>>>>> RSpec clears out all stub methods and message expectations at the end >>>>>> of each example. In this case, the stub on count is defined in a >>>>>> before(:all) block, which is only executed once, before all the >>>>>> examples are run (perhaps before(:any) would be a more clear >>>>>> expression of this?). After the first example is executed, that stub >>>>>> goes away. So when the mock receives the :count message in the second >>>>>> example, it's not expecting it (which is exactly what it's telling >>>>>> you). If you run the second example by itself (spec migration_spec.rb >>>>>> -e "should find the records") it will pass. >>>>>> >>>>>> You can solve the immediate problem by removing the stubs from the >>>>>> initial declaration of the MyModel constant and moving them to a >>>>>> before(:each) block so they get set before each example. >>>>>> >>>>>> Another option is to set :null_object => true. That will tell the mock >>>>>> to ignore unexpected messages, however the stub on find might still >>>>>> need to move to before(:each) because it returns something. >>>>>> >>>>>> Also - this code creates instance variables that get used across >>>>>> examples. If something happens in the first example to change the >>>>>> state of @record, you're going to get the same object in the second >>>>>> example and it becomes a challenge to understand what's happening when >>>>>> there are failures in the second example. >>>>>> >>>>>> I don't use before(:all) blocks this way for exactly this reason. They >>>>>> are run only once, and can cause a lot of confusion because they leak >>>>>> state across examples. The way I usually go about something like this >>>>>> is to create a simple empty class: >>>>>> >>>>>> class MyModel; end >>>>>> >>>>>> And then set expectations on it before(:each) example. >>>>>> >>>>>> You can get the gist of what I'm talking about here: >>>>>> http://gist.github.com/2438 - I've got two different approaches in two >>>>>> separate commits, so grab the repo to see both >>>>> >>>>> Or you *could* just look at them on line! >>>>> >>>>> https://gist.github.com/2438/040f26916032ad864ba51d0d733e16056c77be42 >>>>> https://gist.github.com/2438/0ee4fcaebbafdbdab77dffd5228a9aae92f17191 >>>>> >>>>> >>>>> >>>>>> (this is my first time >>>>>> checking out gist - wow!). >>>>>> >>>>>> HTH, >>>>>> David >>> >>> On Fri, Jul 25, 2008 at 8:30 AM, Matt Lins wrote: >>>> Yes, gist is great! >>>> >>>> Thank you very much for taking the time to look at this. I like your >>>> suggestions very much and will use them. At this point I'm just >>>> messing around, but I don't understand why this doesn't work. >>>> >>>> One more bad implementation if you have time: >>> >>> I don't really have much - packing for a week's holiday. >> >> Ok, thanks anyway. Enjoy your holiday. :) >> >>> >>>> http://gist.github.com/2372 >>>> >>>> I'm removing the constant after each spec runs and redefining it >>>> before each runs. The second spec still doesn't pass though, even >>>> though the constant is defined before each spec. >>> >>> Is is the same failure? >> >> Yes. > > What about when you run them each individually? > > spec migration_spec.rb - e 'should get a count of the records' > spec migration_spec.rb - e 'should find the records' I actually just did that myself and they both pass separately - so there is some state-leaking problem. I don't really have the time to investigate this now, but this is beginning to feel a lot like "doctor, it hurts when I bang my head against the wall like this ...." > > >> >>> >>>> Again, I realize this is horrible, but it should still work, no? >>> _______________________________________________ >>> 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 mattlins at gmail.com Fri Jul 25 10:02:42 2008 From: mattlins at gmail.com (Matt Lins) Date: Fri, 25 Jul 2008 09:02:42 -0500 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <57c63afe0807250653u5e837846pde0ce7d4c46e7858@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <7B825364-11F8-4235-9C90-69D0756E47E5@railsnewbie.com> <3795d7870807242234j2e7aeeb2q979f227c3bd5791b@mail.gmail.com> <57c63afe0807250557lab67c5bj9641dc4b24a1ee6@mail.gmail.com> <57c63afe0807250615t4c9a4a51pc5a66d59081bef6f@mail.gmail.com> <3795d7870807250630q65241e46y3e81d8e1de4f4758@mail.gmail.com> <57c63afe0807250640q22ab0a0aq861aeb45772807b1@mail.gmail.com> <3795d7870807250644n5b785fd6if59c57b807a2917b@mail.gmail.com> <57c63afe0807250649h2ecc2411s47979910850946d7@mail.gmail.com> <57c63afe0807250653u5e837846pde0ce7d4c46e7858@mail.gmail.com> Message-ID: <3795d7870807250702r4711da3av2ed1e0d6e56f5c1b@mail.gmail.com> Fair enough. Thanks. On Fri, Jul 25, 2008 at 8:53 AM, David Chelimsky wrote: > On Fri, Jul 25, 2008 at 8:49 AM, David Chelimsky wrote: >> On Fri, Jul 25, 2008 at 8:44 AM, Matt Lins wrote: >>> On Fri, Jul 25, 2008 at 8:40 AM, David Chelimsky wrote: >>>>> On Fri, Jul 25, 2008 at 8:15 AM, David Chelimsky wrote: >>>>>> On Fri, Jul 25, 2008 at 7:57 AM, David Chelimsky wrote: >>>>>>> On Fri, Jul 25, 2008 at 12:34 AM, Matt Lins wrote: >>>>>>>> On Fri, Jul 25, 2008 at 12:25 AM, Scott Taylor >>>>>>>> wrote: >>>>>>>>> >>>>>>>>> On Jul 25, 2008, at 1:15 AM, Matt Lins wrote: >>>>>>>>> >>>>>>>>>> On Thu, Jul 24, 2008 at 11:47 PM, Scott Taylor >>>>>>>>>> wrote: >>>>>>>>>>> >>>>>>>>>>> On Jul 25, 2008, at 12:32 AM, Matt Lins wrote: >>>>>>>>>>> >>>>>>>>>>>> I suppose the way I'm defining the stubs, differs from what Dave is >>>>>>>>>>>> doing in his example. >>>>>>>>>>>> >>>>>>>>>>>> I assumed that: >>>>>>>>>>>> >>>>>>>>>>>> MyModel = mock('MyModel Class', :count => 1) >>>>>>>>>>>> >>>>>>>>>>>> was the same as: >>>>>>>>>>>> >>>>>>>>>>>> MyModel.stub!(:count).and_return(1) >>>>>>>>>>> >>>>>>>>>>> Nope. Not even close. Here's an equivalent of the first form: >>>>>>>>>>> >>>>>>>>>>> Object.send :remove_const, :MyModel >>>>>>>>>>> MyModel = >>>>>>>>>>> >>>>>>>>>>> and here's the second form: >>>>>>>>>>> >>>>>>>>>>> MyModel.instance_eval do >>>>>>>>>>> def count >>>>>>>>>>> 1 >>>>>>>>>>> end >>>>>>>>>>> end >>>>>>>>>>> >>>>>>>>>>> (or:) >>>>>>>>>>> >>>>>>>>>>> MyModel.class_eval do >>>>>>>>>>> class << self >>>>>>>>>>> def count; 1; end >>>>>>>>>>> end >>>>>>>>>>> end >>>>>>>>>>> >>>>>>>>>>> Scott >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> But the stubs are defined the same way in both occurrences, no? >>>>>>>>>> >>>>>>>>>> MyModel = mock('MyModel Class', :count => 1) >>>>>>>>>> >>>>>>>>>> By passing {:count => 1} to +stubs_and_options+ I should have defined >>>>>>>>>> stubs on the mock object. I'm using it as a shortcut for this: >>>>>>>>>> >>>>>>>>>> MyModel = mock('MyModel Class') >>>>>>>>>> MyModel.stub!(:count).and_return(1) >>>>>>>>>> >>>>>>>>>> If those example aren't doing the exact same thing I guess I'm a >>>>>>>>>> little baffled (or maybe just need to go to sleep). >>>>>>>>> >>>>>>>>> The first one is redefining the constant 'MyModel'. The second one is just >>>>>>>>> redefining a class method (the constant isn't changing - it's remaining >>>>>>>>> whatever it was before - say, a class) >>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> But, I'm starting to think they are not. I haven't looked at the >>>>>>>>>>>> rSpec internals to verify, other than the parameter name: >>>>>>>>>>>> >>>>>>>>>>>> stubs_and_options+ lets you assign options and stub values >>>>>>>>>>>> at the same time. The only option available is :null_object. >>>>>>>>>>>> Anything else is treated as a stub value. >>>>>>>>>>>> >>>>>>>>>>>> So, is this problem? >>>>>>>>>>> >>>>>>>>>>> Yeah - so here are two related, but not equivalent ideas: mock objects, >>>>>>>>>>> and >>>>>>>>>>> stubs. A stub is just a faked out method - it can exist on a mock object >>>>>>>>>>> (a >>>>>>>>>>> completely fake object), or on a partial mock (i.e. a real object, with a >>>>>>>>>>> method faked out). mock('My mock") is a mock object, >>>>>>>>>>> MyRealObject.stub!(:foo) is a real object with the method foo faked out. >>>>>>>>>>> >>>>>>>>>>> What is the difference between a mock object and a fake object? A mock >>>>>>>>>>> object will complain (read: raise an error) any time it receives a >>>>>>>>>>> message >>>>>>>>>>> which it doesn't understand (i.e. one which hasn't been explicitly >>>>>>>>>>> stubbed). >>>>>>>>>>> A real object will work as usual. (A null object mock is a special type >>>>>>>>>>> of >>>>>>>>>>> mock - one which never complains. For now, you shouldn't worry about >>>>>>>>>>> it). >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Ok, I get what you saying, but as I understand it I am explicitly >>>>>>>>>> stubbing out the methods on the _mock_ object and it's still >>>>>>>>>> complaining. If +stubs_and_options+ isn't stubbing, then what is it >>>>>>>>>> doing? >>>>>>>>> >>>>>>>>> That's right - the hash to the mock method is a shorthand. So these two are >>>>>>>>> equivalent: >>>>>>>>> >>>>>>>>> my_mock = mock('a mock') >>>>>>>>> my_mock.stub!(:foo).and_return(:bar) >>>>>>>>> >>>>>>>>> AND: >>>>>>>>> >>>>>>>>> my_mock = mock("a mock", {:foo => :bar}) >>>>>>>>> >>>>>>>>> Scott >>>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> rspec-users mailing list >>>>>>>>> rspec-users at rubyforge.org >>>>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>>>> >>>>>>>> >>>>>>>> Ok, then would you still insist that: >>>>>>>> >>>>>>>> This: >>>>>>>> >>>>>>>> http://gist.github.com/2372 >>>>>>>> >>>>>>>> Should produce this: >>>>>>>> >>>>>>>> # spec migration_spec.rb >>>>>>>> .F >>>>>>>> >>>>>>>> 1) >>>>>>>> Spec::Mocks::MockExpectationError in 'Migration should find the records' >>>>>>>> Mock 'MyModel Class' received unexpected message :count with (no args) >>>>>>>> ./migration.rb:14:in `run' >>>>>>>> ./migration_spec.rb:19: >>>>>>>> >>>>>>>> Finished in 0.009435 seconds >>>>>>>> >>>>>>>> -------------------- >>>>>>>> >>>>>>>> And like I said earlier, this code passes both examples with FlexMock( >>>>>>>> if you simply replace mock with flexmock and uncomment the code in >>>>>>>> spec_helper, of course you need the flexmock gem) >>>>>>> >>>>>>> I can't speak for why it's passing in Flexmock, but I can explain why >>>>>>> it's failing in rspec. >>>>>>> >>>>>>> RSpec clears out all stub methods and message expectations at the end >>>>>>> of each example. In this case, the stub on count is defined in a >>>>>>> before(:all) block, which is only executed once, before all the >>>>>>> examples are run (perhaps before(:any) would be a more clear >>>>>>> expression of this?). After the first example is executed, that stub >>>>>>> goes away. So when the mock receives the :count message in the second >>>>>>> example, it's not expecting it (which is exactly what it's telling >>>>>>> you). If you run the second example by itself (spec migration_spec.rb >>>>>>> -e "should find the records") it will pass. >>>>>>> >>>>>>> You can solve the immediate problem by removing the stubs from the >>>>>>> initial declaration of the MyModel constant and moving them to a >>>>>>> before(:each) block so they get set before each example. >>>>>>> >>>>>>> Another option is to set :null_object => true. That will tell the mock >>>>>>> to ignore unexpected messages, however the stub on find might still >>>>>>> need to move to before(:each) because it returns something. >>>>>>> >>>>>>> Also - this code creates instance variables that get used across >>>>>>> examples. If something happens in the first example to change the >>>>>>> state of @record, you're going to get the same object in the second >>>>>>> example and it becomes a challenge to understand what's happening when >>>>>>> there are failures in the second example. >>>>>>> >>>>>>> I don't use before(:all) blocks this way for exactly this reason. They >>>>>>> are run only once, and can cause a lot of confusion because they leak >>>>>>> state across examples. The way I usually go about something like this >>>>>>> is to create a simple empty class: >>>>>>> >>>>>>> class MyModel; end >>>>>>> >>>>>>> And then set expectations on it before(:each) example. >>>>>>> >>>>>>> You can get the gist of what I'm talking about here: >>>>>>> http://gist.github.com/2438 - I've got two different approaches in two >>>>>>> separate commits, so grab the repo to see both >>>>>> >>>>>> Or you *could* just look at them on line! >>>>>> >>>>>> https://gist.github.com/2438/040f26916032ad864ba51d0d733e16056c77be42 >>>>>> https://gist.github.com/2438/0ee4fcaebbafdbdab77dffd5228a9aae92f17191 >>>>>> >>>>>> >>>>>> >>>>>>> (this is my first time >>>>>>> checking out gist - wow!). >>>>>>> >>>>>>> HTH, >>>>>>> David >>>> >>>> On Fri, Jul 25, 2008 at 8:30 AM, Matt Lins wrote: >>>>> Yes, gist is great! >>>>> >>>>> Thank you very much for taking the time to look at this. I like your >>>>> suggestions very much and will use them. At this point I'm just >>>>> messing around, but I don't understand why this doesn't work. >>>>> >>>>> One more bad implementation if you have time: >>>> >>>> I don't really have much - packing for a week's holiday. >>> >>> Ok, thanks anyway. Enjoy your holiday. :) >>> >>>> >>>>> http://gist.github.com/2372 >>>>> >>>>> I'm removing the constant after each spec runs and redefining it >>>>> before each runs. The second spec still doesn't pass though, even >>>>> though the constant is defined before each spec. >>>> >>>> Is is the same failure? >>> >>> Yes. >> >> What about when you run them each individually? >> >> spec migration_spec.rb - e 'should get a count of the records' >> spec migration_spec.rb - e 'should find the records' > > I actually just did that myself and they both pass separately - so > there is some state-leaking problem. I don't really have the time to > investigate this now, but this is beginning to feel a lot like > "doctor, it hurts when I bang my head against the wall like this ...." > >> >> >>> >>>> >>>>> Again, I realize this is horrible, but it should still work, no? >>>> _______________________________________________ >>>> 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 chris at cobaltedge.com Fri Jul 25 10:48:13 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Fri, 25 Jul 2008 07:48:13 -0700 Subject: [rspec-users] Webrat visits fails, but works in browser In-Reply-To: <1BD124B8-D9BD-4CE1-B335-B3E1152F262A@superinfinite.com> References: <443c240c0807250111r3939b194tda226e1d0e2f9e26@mail.gmail.com> <1BD124B8-D9BD-4CE1-B335-B3E1152F262A@superinfinite.com> Message-ID: <443c240c0807250748j1d069fb7qa22ee134839b8779@mail.gmail.com> Ok, thanks. I have figured it out of course by now :) It was an issue with RedCloth. On Fri, Jul 25, 2008 at 5:56 AM, Bart Zonneveld wrote: > > On 25 jul 2008, at 10:11, Christopher Bailey wrote: > >> I'm wondering if folks have suggestions for how I can debug the >> following problem. I have some RSpec Stories that use WebRat, and do >> a "visits hotels_path" type of thing. It is failing, yet the page >> works fine in the browser. I'm trying to figure out how to go about >> looking into why Webrat fails. The error it puts out looks like: > > > > Just look in yout log/test.log. That usually has a lot more info than the > output from webrat. > > good luck, > bartz > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com From pergesu at gmail.com Fri Jul 25 12:28:20 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 25 Jul 2008 12:28:20 -0400 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <3795d7870807250630q65241e46y3e81d8e1de4f4758@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <3795d7870807242121r2a19d698y5180225e1f376f42@mail.gmail.com> <3795d7870807242132v6162aa36pdc2936e5fcb99d9d@mail.gmail.com> <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> <3795d7870807242215ldd9cd55oa41d156f17c94d96@mail.gmail.com> <7B825364-11F8-4235-9C90-69D0756E47E5@railsnewbie.com> <3795d7870807242234j2e7aeeb2q979f227c3bd5791b@mail.gmail.com> <57c63afe0807250557lab67c5bj9641dc4b24a1ee6@mail.gmail.com> <57c63afe0807250615t4c9a4a51pc5a66d59081bef6f@mail.gmail.com> <3795d7870807250630q65241e46y3e81d8e1de4f4758@mail.gmail.com> Message-ID: <810a540e0807250928v50ef4753oda7421e14f3379b@mail.gmail.com> On Fri, Jul 25, 2008 at 9:30 AM, Matt Lins wrote: > Yes, gist is great! > > Thank you very much for taking the time to look at this. I like your > suggestions very much and will use them. At this point I'm just > messing around, but I don't understand why this doesn't work. > > One more bad implementation if you have time: > > http://gist.github.com/2372 > > I'm removing the constant after each spec runs and redefining it > before each runs. The second spec still doesn't pass though, even > though the constant is defined before each spec. > > Again, I realize this is horrible, but it should still work, no? I think you're right, there is something funky going on, and I *think* it's something internal to RSpec. Your code looks like it ought to work, and it works in Mocha. I've poked around a little bit, but nothing jumped out at me. That said, this is a pretty weird edge case and afaik has not affected anything I've ever done. I can tell you that this is an uber-low priority, for me at least, so you'll either have to hope it piques someone's curiosity enough to fix, or go ahead and work on a fix yourself. As you've pointed out, you can do class MyModel; end MyModel.stub!(:count).and_return 1 MyModel.stub!(:find).and_return [@record] I've just committed a small enhancement that lets you do MyModel.stub!(:count => 1, :find => [@record]) in order to cut down on the noise. Download the latest source and build your gem and you're good to go. Also, you can do as Scott suggested and use DI. Then you'd be doing something like Migration.set_model MyModel I agree though that this may not be desirable in some cases. For instance, if the constant name is represented as a string (such as in a DB column) then you've now put the burden on client code to do the string->constant conversion. Pat From mattlins at gmail.com Fri Jul 25 14:42:14 2008 From: mattlins at gmail.com (Matt Lins) Date: Fri, 25 Jul 2008 13:42:14 -0500 Subject: [rspec-users] Problems with mock assigned to a constant In-Reply-To: <810a540e0807250928v50ef4753oda7421e14f3379b@mail.gmail.com> References: <3795d7870807242049t407e5fa7x7b1727c65012cc2c@mail.gmail.com> <3795d7870807242132v6162aa36pdc2936e5fcb99d9d@mail.gmail.com> <5343FE1C-8A45-42DF-9805-7D865C934D6B@railsnewbie.com> <3795d7870807242215ldd9cd55oa41d156f17c94d96@mail.gmail.com> <7B825364-11F8-4235-9C90-69D0756E47E5@railsnewbie.com> <3795d7870807242234j2e7aeeb2q979f227c3bd5791b@mail.gmail.com> <57c63afe0807250557lab67c5bj9641dc4b24a1ee6@mail.gmail.com> <57c63afe0807250615t4c9a4a51pc5a66d59081bef6f@mail.gmail.com> <3795d7870807250630q65241e46y3e81d8e1de4f4758@mail.gmail.com> <810a540e0807250928v50ef4753oda7421e14f3379b@mail.gmail.com> Message-ID: <3795d7870807251142w18c3a56cj984873ca11cfaf01@mail.gmail.com> Yah, I looked around. I came out with a better understanding of rSpec's mocking internals, but no answer to the problem. I don't need it. I'll probably end up using FlexMock or Mocha for future projects anyway. I'd be happy to file a ticket if you think it's worthy of one. It was my first implementation of the spec and I thought it should work. I've since refactored with Dave's suggestions. I'm not so sure about DI in this scenario. I couldn't find any decent examples of it's use in rSpec and I'm happy with what I have now. Thanks again everyone. On Fri, Jul 25, 2008 at 11:28 AM, Pat Maddox wrote: > On Fri, Jul 25, 2008 at 9:30 AM, Matt Lins wrote: >> Yes, gist is great! >> >> Thank you very much for taking the time to look at this. I like your >> suggestions very much and will use them. At this point I'm just >> messing around, but I don't understand why this doesn't work. >> >> One more bad implementation if you have time: >> >> http://gist.github.com/2372 >> >> I'm removing the constant after each spec runs and redefining it >> before each runs. The second spec still doesn't pass though, even >> though the constant is defined before each spec. >> >> Again, I realize this is horrible, but it should still work, no? > > I think you're right, there is something funky going on, and I *think* > it's something internal to RSpec. Your code looks like it ought to > work, and it works in Mocha. I've poked around a little bit, but > nothing jumped out at me. > > That said, this is a pretty weird edge case and afaik has not affected > anything I've ever done. I can tell you that this is an uber-low > priority, for me at least, so you'll either have to hope it piques > someone's curiosity enough to fix, or go ahead and work on a fix > yourself. > > As you've pointed out, you can do > class MyModel; end > MyModel.stub!(:count).and_return 1 > MyModel.stub!(:find).and_return [@record] > > I've just committed a small enhancement that lets you do > MyModel.stub!(:count => 1, :find => [@record]) > > in order to cut down on the noise. > > Download the latest source and build your gem and you're good to go. > > Also, you can do as Scott suggested and use DI. Then you'd be doing > something like > Migration.set_model MyModel > > I agree though that this may not be desirable in some cases. For > instance, if the constant name is represented as a string (such as in > a DB column) then you've now put the burden on client code to do the > string->constant conversion. > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben at benmabey.com Sat Jul 26 18:38:35 2008 From: ben at benmabey.com (Ben Mabey) Date: Sat, 26 Jul 2008 16:38:35 -0600 (MDT) Subject: [rspec-users] HTML Story Formatter In-Reply-To: <57c63afe0807250611p5a950d51icefc3c36829650f2@mail.gmail.com> References: <1216902734.7340.14.camel@tybalt> <57c63afe0807240544p5a8adc2keaa21aac0ca1fe0e@mail.gmail.com> <57c63afe0807250611p5a950d51icefc3c36829650f2@mail.gmail.com> Message-ID: <49733.98.202.34.115.1217111915.squirrel@mail.onticweb.com> David Chelimsky wrote: > On Fri, Jul 25, 2008 at 8:08 AM, Joseph Wilk wrote: > >> To handle this I wrote a patch which delivered the styles in the html formatters output. In much the same way as the html spec formatter does. >> I know Aslak Helles?y has been looking at the editable html stories. Is it acceptable to have stories have styles embedded in the html formatter until Aslak's editable stories project evolves? >> I could imagine there are some arguments that the HTML output of stories >> is something people might want to control the look and feel of, more so than specs as they are seen more frequently by customers. >> Perhapes by default the styles are embedded in the html formatter but if >> a CSS stylesheet is passed to the formatter than it will suppress this output and use your custom css. >> something like: >> ruby stories/all.rb --format html --css my_own.css >> > That all sounds reasonable to me. Sensible defaults, yet configurable. Other opinions? > I like that idea. I haven't wanted to push back any of my changes to the HTML formatter because I knew that Aslak's goal was to create a customer facing editable HTML page. However, for CI builds it is more useful as a programmer to not have that functionality and inline the backtrace as well (which is something most customer's wouldn't want to see.) I vote for inlining the basic styles and providing the way to configure it as suggested above. I think the HTML formatter should include the backtrace and then JS can be used to hide it for a customer-facing version. Which brings up the other question.. how do we want to handle the JS? Due to how the HTML is written out JS is required to change the Story's and Scenario's styles when a step fails or is pending. I did this with lowpro for the rspec-story-tmbundle: http://github.com/bmabey/rspec-story-tmbundle/tree/master/Support/resource/rspec.js (The JS commented out in the file was the original JS that Aslak did for the editable version.) My JS is untested though (and only works for rspec 1.1.4), so I don't know if you want to incorporate it into rspec, plus it would require the additional lowpro.js lib. The bigger question, I think, is how to handle the required JS files. I don't think inlining the whole prototype lib is a good solution. So, maybe we could default to generating full paths to the JS files which reside in the rspec lib folder? Then we could allow options to be passed in to modify the JS path, just like the CSS option above? Any other suggestions/ideas of how to handle the external JS files? -Ben From twscannell at gmail.com Sun Jul 27 00:43:45 2008 From: twscannell at gmail.com (Teedub) Date: Sat, 26 Jul 2008 21:43:45 -0700 (PDT) Subject: [rspec-users] Newbie question, populate or ignore test db In-Reply-To: <9116C0F4-7636-46CD-9D74-82618572FC9F@superinfinite.com> References: <34c82da2-a22c-46f7-b6a3-6e55b8d38cf2@z16g2000prn.googlegroups.com> <8c90cb7d0807210027p3c12cdeft339b31099d5048a@mail.gmail.com> <9116C0F4-7636-46CD-9D74-82618572FC9F@superinfinite.com> Message-ID: <3d202f98-9670-462a-943d-ec29c1c03da5@q28g2000prh.googlegroups.com> For some reason I thought I was using the fixture that thescript/ generate rspec_scaffold method created for me. And further that the fixture didn't use a database, but pretended that it did. Thanks On Jul 22, 12:09?am, Bart Zonneveld wrote: > On 22-jul-2008, at 6:43, Teedub wrote: > > > Thanks > > rake db:test:prepare did the trick. I am still a bit confused as to > > why rake cares about a database that it isn't using. > > But I guess that will all fall into place in my brain one day. > > Well, the test database is for ehrm, testing :). So rake is actually ? > using it. > > gr, > bartz > > > > > On Jul 21, 1:01 am, Rahoul Baruah wrote: > >> On 21 Jul 2008, at 08:27, David Salgado wrote: > > >>> If you have created it, then perhaps the test db doesn't have the > >>> right tables. So, try "rake db:test:prepare". You'll need to do that > >>> after every migration as well. > > >> Once your test database is built, using "rake spec" should ensure > >> that your test database matches the structure of your dev database, > >> before running your specifications. > > >> Baz. > > >> Rahoul Baruah > >> Web design and development:http://www.3hv.co.uk/ > >> Serious Rails Hosting:http://www.brightbox.co.uk/ > > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/ > >> rspec-users > > _______________________________________________ > > 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 j at jonathanleighton.com Sun Jul 27 06:32:40 2008 From: j at jonathanleighton.com (Jonathan Leighton) Date: Sun, 27 Jul 2008 11:32:40 +0100 Subject: [rspec-users] HTML Story Formatter In-Reply-To: <49733.98.202.34.115.1217111915.squirrel@mail.onticweb.com> References: <1216902734.7340.14.camel@tybalt> <57c63afe0807240544p5a8adc2keaa21aac0ca1fe0e@mail.gmail.com> <57c63afe0807250611p5a950d51icefc3c36829650f2@mail.gmail.com> <49733.98.202.34.115.1217111915.squirrel@mail.onticweb.com> Message-ID: <1217154760.7207.1.camel@tybalt> On Sat, 2008-07-26 at 16:38 -0600, Ben Mabey wrote: > Any other suggestions/ideas of how to handle the external JS files? Wasn't there some Google-hosted JS lib repository launched a little while ago? That could be used for Prototype? Jon -- Jonathan Leighton http://jonathanleighton.com/ From vertebrate at gmail.com Sun Jul 27 11:56:58 2008 From: vertebrate at gmail.com (Steve) Date: Sun, 27 Jul 2008 10:56:58 -0500 Subject: [rspec-users] Clear a stub Message-ID: I can't find it on the RSpec site, and my googling is turning up nothing. Is there a way to clear a stub once set? I'm experiencing some behavior where I have some nested describes, with "before :each" and I need to change the stub from the parent. I thought it would just overwrite the previous stub value, but instead it seems to turn the stub into an array making the previous value the first element, and then the new value the second. Thanks, Steve From pergesu at gmail.com Sun Jul 27 13:33:42 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 27 Jul 2008 13:33:42 -0400 Subject: [rspec-users] Clear a stub In-Reply-To: References: Message-ID: <810a540e0807271033m197b4c28o80fec10976bcf148@mail.gmail.com> On Sun, Jul 27, 2008 at 11:56 AM, Steve wrote: > I can't find it on the RSpec site, and my googling is turning up nothing. Is > there a way to clear a stub once set? I'm experiencing some behavior where I > have some nested describes, with "before :each" and I need to change the > stub from the parent. I thought it would just overwrite the previous stub > value, but instead it seems to turn the stub into an array making the > previous value the first element, and then the new value the second. > > Thanks, > Steve Can you paste your code please? Here's an example I just whipped up that seems to work fine...I'm using a stub defined inline, a stub defined in two steps, and a partially stubbed object. They all shadow the outer stub. What does your code look like? Pat describe "outer" do before(:each) do @inlined_stub = stub("object", :inlined_stub => :outer) @verbose = stub("verbose") @verbose.stub!(:verbose).and_return :outer @partial = Object.new @partial.stub!(:partial).and_return :outer end it "should work" do @inlined_stub.inlined_stub.should == :outer @verbose.verbose.should == :outer @partial.partial.should == :outer end describe "inner" do before(:each) do @inlined_stub.stub!(:inlined_stub).and_return :inner @verbose.stub!(:verbose).and_return :inner @partial.stub!(:partial).and_return :inner end it "should work" do @inlined_stub.inlined_stub.should == :inner @verbose.verbose.should == :inner @partial.partial.should == :inner end end end From vertebrate at gmail.com Sun Jul 27 15:13:48 2008 From: vertebrate at gmail.com (Steve) Date: Sun, 27 Jul 2008 14:13:48 -0500 Subject: [rspec-users] Clear a stub In-Reply-To: <810a540e0807271033m197b4c28o80fec10976bcf148@mail.gmail.com> References: <810a540e0807271033m197b4c28o80fec10976bcf148@mail.gmail.com> Message-ID: Pat Maddox wrote: > > Can you paste your code please? Here's an example I just whipped up > that seems to work fine...I'm using a stub defined inline, a stub > defined in two steps, and a partially stubbed object. They all shadow > the outer stub. What does your code look like? > > Pat It looks like I was lead somewhat astray. It wasn't the stubbing, it's actually something wrong with the fixture loading. The other fixtures that load with it seem to be okay, but the ones I need are just returning empty arrays. describe ReservationsController, "reservations/GET" do describe "all reservations/ GET", :shared => true do ...snip... describe "with reservations" do fixtures :customers, :users, :products, :reservation_statuses, :reservations, :reservation_items before(:each) do res = [reservations(:single), reservations(:cancelled), reservations(:surprise)] Reservation.stub!(:find).and_return(res) end it "should group the reservations by date for the view assign" do do_request rd = assigns[:reservation_dates] rd.should have(2).items end end end end Instead of 'res' containing an array of three reservations, it's just an array of three empty arrays. I know the fixtures are good because I have used them in other specs. The 'reservations' collection is present, and it is aware of appropriate keys, but it just gives back empty arrays. Any thoughts on my new and improved problem? I should also note that I'm running off of svn r3312 from around mid February. At this time I cannot update to trunk, so if it's a problem, and it has been fixed since that time, just let me know. From eagerwombat at gmail.com Sun Jul 27 15:52:59 2008 From: eagerwombat at gmail.com (john) Date: Sun, 27 Jul 2008 12:52:59 -0700 Subject: [rspec-users] Capistrano: after_deploy system specs? Message-ID: <5b1b5e890807271252g28a6b10emc2fe12d6ff866430@mail.gmail.com> Hi everyone, I was curious if anyone out there had any examples or advice for running specs on system status. I would like to analyze unix utilities such as ps -aux|grep dispatch, uptime, top (ruby processes), proper log activity, etc. Write now I frantically scramble through these on the command to make sure everything's okay and a rollback isn't in order. So far I've only found one writing about the subject: http://www.vaporbase.com/postings/Running_rspec_after_you_deploy This artcle (very cool) has his post deploy rspec results outputted to the server in question as HTML, so a few minutes after the deploy he just visits the web page. Thanks in advance John -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Sun Jul 27 18:56:38 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 27 Jul 2008 18:56:38 -0400 Subject: [rspec-users] Clear a stub In-Reply-To: References: <810a540e0807271033m197b4c28o80fec10976bcf148@mail.gmail.com> Message-ID: <810a540e0807271556g615bf002n2c142eb44176173a@mail.gmail.com> On Sun, Jul 27, 2008 at 3:13 PM, Steve wrote: > Pat Maddox wrote: >> >> Can you paste your code please? Here's an example I just whipped up >> that seems to work fine...I'm using a stub defined inline, a stub >> defined in two steps, and a partially stubbed object. They all shadow >> the outer stub. What does your code look like? >> >> Pat > > It looks like I was lead somewhat astray. It wasn't the stubbing, it's > actually something wrong with the fixture loading. The other fixtures that > load with it seem to be okay, but the ones I need are just returning empty > arrays. > > describe ReservationsController, "reservations/GET" do > describe "all reservations/ GET", :shared => true do > ...snip... > > describe "with reservations" do > fixtures :customers, :users, :products, :reservation_statuses, > :reservations, :reservation_items > > before(:each) do > res = [reservations(:single), reservations(:cancelled), > reservations(:surprise)] > Reservation.stub!(:find).and_return(res) > end > > it "should group the reservations by date for the view assign" do > do_request > rd = assigns[:reservation_dates] > > rd.should have(2).items > end > end > end > end > > Instead of 'res' containing an array of three reservations, it's just an > array of three empty arrays. I know the fixtures are good because I have > used them in other specs. The 'reservations' collection is present, and it > is aware of appropriate keys, but it just gives back empty arrays. Any > thoughts on my new and improved problem? So are you saying that reservations(:single) == reservations(:cancelled) == reservations(:surprised) == [] When you print each of them out, that's what you see? > I should also note that I'm running off of svn r3312 from around mid > February. At this time I cannot update to trunk, so if it's a problem, and > it has been fixed since that time, just let me know. Well, a lot of stuff has happened since then :) However, I'm not sure what your problem is still so I can't tell you that it's been fixed since then. It sounds to me like you're saying reservations(:single) returns a Reservation object in one test, but [] in this one. Is that accurate? Pat From vertebrate at gmail.com Mon Jul 28 00:08:48 2008 From: vertebrate at gmail.com (Steve) Date: Sun, 27 Jul 2008 23:08:48 -0500 Subject: [rspec-users] Clear a stub In-Reply-To: <810a540e0807271556g615bf002n2c142eb44176173a@mail.gmail.com> References: <810a540e0807271033m197b4c28o80fec10976bcf148@mail.gmail.com> <810a540e0807271556g615bf002n2c142eb44176173a@mail.gmail.com> Message-ID: Pat Maddox wrote: ...big snip... > > Well, a lot of stuff has happened since then :) However, I'm not sure > what your problem is still so I can't tell you that it's been fixed > since then. It sounds to me like you're saying reservations(:single) > returns a Reservation object in one test, but [] in this one. Is that > accurate? > > Pat Yes, that's exactly the case. Just empty arrays in this instance, but appropriate Reservation objects in other places. The other thing that gets me is that even the other fixtures at this time are correct. Like the customers, and users are both fine. It's just the reservations. I've also tried moving the fixtures loading up higher in the describe nesting, thinking that maybe it had something to do with being used in a 'shared' describe. That had no effect though. Am I tripping over some keyword magic maybe? I have no idea what magic that might be, I'm just thinking out loud. From lists at ruby-forum.com Mon Jul 28 05:54:05 2008 From: lists at ruby-forum.com (Joseph Wilk) Date: Mon, 28 Jul 2008 11:54:05 +0200 Subject: [rspec-users] HTML Story Formatter In-Reply-To: <49733.98.202.34.115.1217111915.squirrel@mail.onticweb.com> References: <1216902734.7340.14.camel@tybalt> <57c63afe0807240544p5a8adc2keaa21aac0ca1fe0e@mail.gmail.com> <57c63afe0807250611p5a950d51icefc3c36829650f2@mail.gmail.com> <49733.98.202.34.115.1217111915.squirrel@mail.onticweb.com> Message-ID: > Which brings up the other question.. how do we want to handle the JS? > Due to how the HTML is written out JS is required to change the Story's > and Scenario's styles when a step fails or is pending. I did this with > lowpro for the rspec-story-tmbundle: The current html formatter in trunk no longer requires js to apply styles for failure or pending. So that moves us along to looking at js to hide/show the backtrace. The idea of showing the backtrace in the html has been something I've been debating for a while. I did come to conclusion that as a developer I have the build log (or terminal stories are run from) as a source for story errors. Hence I felt I was best left leaving my stories clean for the non-developer users of the stories. I can see from your post that there is a usecase for a more developer centric output. My goal with the default story output was to get a standalone .html file which can then be moved around and played with without having to worry about managing css & js files. Pretty much just as the spec reporter does. Thinking about a developer centric report and maintaining a standalone html report starts to make me think about different formatters/reports. * Default standalone * Custom css -- * Developer centric story report - js & customizable css So this move us to something like: *ruby stories/all.rb --format html *ruby stories/all.rb --format html --css my_own.css AND *ruby stories/all.rb --format developer-html I think the first two are important and represent the majority of use cases. If we can separate the idea of js and backtrace output to a separate formatter then we can start work on the first two outputs now (and make story reports usable out of the box). Then we can use a developer formatter as a sounding board for advanced/verbose output (profiling each story aswell perhaps?). Potentially Aslak's new interface could move to this dev-formatter(or some other formatter) so that we continue development without disturbing those using the simple default output. What do people think? -- Joseph Wilk http://www.joesniff.co.uk Ben Mabey wrote: > David Chelimsky wrote: >> On Fri, Jul 25, 2008 at 8:08 AM, Joseph Wilk > wrote: >> >>> To handle this I wrote a patch which delivered the styles in the html > formatters output. In much the same way as the html spec formatter > does. >>> I know Aslak Helles?y has been looking at the editable html stories. Is > it acceptable to have stories have styles embedded in the html > formatter until Aslak's editable stories project evolves? >>> I could imagine there are some arguments that the HTML output of > stories >>> is something people might want to control the look and feel of, more so > than specs as they are seen more frequently by customers. >>> Perhapes by default the styles are embedded in the html formatter but > if >>> a CSS stylesheet is passed to the formatter than it will suppress this > output and use your custom css. >>> something like: >>> ruby stories/all.rb --format html --css my_own.css >>> >> That all sounds reasonable to me. Sensible defaults, yet configurable. > Other opinions? >> > > I like that idea. I haven't wanted to push back any of my changes to > the > HTML formatter because I knew that Aslak's goal was to create a > customer > facing editable HTML page. > > However, for CI builds it is more useful as a programmer to not have > that > functionality and inline the backtrace as well (which is something most > customer's wouldn't want to see.) I vote for inlining the basic styles > and providing the way to configure it as suggested above. I think the > HTML formatter should include the backtrace and then JS can be used to > hide it for a customer-facing version. > > Which brings up the other question.. how do we want to handle the JS? > Due to how the HTML is written out JS is required to change the Story's > and Scenario's styles when a step fails or is pending. I did this with > lowpro for the rspec-story-tmbundle: > http://github.com/bmabey/rspec-story-tmbundle/tree/master/Support/resource/rspec.js > (The JS commented out in the file was the original JS that Aslak did for > the editable version.) > My JS is untested though (and only works for rspec 1.1.4), so I don't > know if you want to incorporate it into rspec, plus it would require the > additional lowpro.js lib. > > The bigger question, I think, is how to handle the required JS files. I > don't think inlining the whole prototype lib is a good solution. So, > maybe we could default to generating full paths to the JS files which > reside in the rspec lib folder? Then we could allow options to be > passed > in to modify the JS path, just like the CSS option above? > > Any other suggestions/ideas of how to handle the external JS files? > > -Ben -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Mon Jul 28 08:39:23 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 28 Jul 2008 08:39:23 -0400 Subject: [rspec-users] Clear a stub In-Reply-To: References: <810a540e0807271033m197b4c28o80fec10976bcf148@mail.gmail.com> <810a540e0807271556g615bf002n2c142eb44176173a@mail.gmail.com> Message-ID: <810a540e0807280539w1a66e0dclc35b5b08cc196bb7@mail.gmail.com> On Mon, Jul 28, 2008 at 12:08 AM, Steve wrote: > Pat Maddox wrote: > ...big snip... >> >> Well, a lot of stuff has happened since then :) However, I'm not sure >> what your problem is still so I can't tell you that it's been fixed >> since then. It sounds to me like you're saying reservations(:single) >> returns a Reservation object in one test, but [] in this one. Is that >> accurate? >> >> Pat > > Yes, that's exactly the case. Just empty arrays in this instance, but > appropriate Reservation objects in other places. The other thing that gets > me is that even the other fixtures at this time are correct. Like the > customers, and users are both fine. It's just the reservations. I've also > tried moving the fixtures loading up higher in the describe nesting, > thinking that maybe it had something to do with being used in a 'shared' > describe. That had no effect though. Am I tripping over some keyword magic > maybe? I have no idea what magic that might be, I'm just thinking out loud. Not sure. Your best bet is probably to build it up piece by piece again. describe "with reservations" do fixtures .... before(:each) do puts reservations(:single) end end etc. It's super weird that it works in every other place but not here. So I'd start from the tiniest thing possible and add lines until you find one that breaks it. Pat From ben at benmabey.com Mon Jul 28 12:40:08 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 28 Jul 2008 10:40:08 -0600 Subject: [rspec-users] HTML Story Formatter In-Reply-To: References: <1216902734.7340.14.camel@tybalt> <57c63afe0807240544p5a8adc2keaa21aac0ca1fe0e@mail.gmail.com> <57c63afe0807250611p5a950d51icefc3c36829650f2@mail.gmail.com> <49733.98.202.34.115.1217111915.squirrel@mail.onticweb.com> Message-ID: <488DF668.8070301@benmabey.com> Joseph Wilk wrote: >> Which brings up the other question.. how do we want to handle the JS? >> Due to how the HTML is written out JS is required to change the Story's >> and Scenario's styles when a step fails or is pending. I did this with >> lowpro for the rspec-story-tmbundle: >> > > The current html formatter in trunk no longer requires js to apply > styles for failure or pending. > Ahh, good to know. Does that mean that the HTML isn't outputted until all of the scenario's are ran for a particular story? > So that moves us along to looking at js to hide/show the backtrace. > > The idea of showing the backtrace in the html has been something I've > been debating for a while. I did come to conclusion that as a developer > I have the build log (or terminal stories are run from) as a source for > story errors. Hence I felt I was best left leaving my stories clean for > the non-developer users of the stories. > This is true for regular development, although having the backtrace can also be helpful in the HTML version if you use that as your main formatter (i.e. in textmate.) The real use for the backtrace, IMO, is for providing a decent build artifact for CI. Otherwise you could have to look through your test.log file and try to match it up.. which would be no fun. > I can see from your post that there is a usecase for a more developer > centric output. > > My goal with the default story output was to get a standalone .html file > which can then be moved around and played with without having to worry > about managing css & js files. Pretty much just as the spec reporter > does. > > Thinking about a developer centric report and maintaining a standalone > html report starts to make me think about different formatters/reports. > > * Default standalone > * Custom css > -- > * Developer centric story report - js & customizable css > > So this move us to something like: > > *ruby stories/all.rb --format html > *ruby stories/all.rb --format html --css my_own.css > > AND > > *ruby stories/all.rb --format developer-html > > I think the first two are important and represent the majority of use > cases. > If we can separate the idea of js and backtrace output to a separate > formatter then we can start work on the first two outputs now (and make > story reports usable out of the box). > > Then we can use a developer formatter as a sounding board for > advanced/verbose output (profiling each story aswell perhaps?). > Potentially Aslak's new interface could move to this dev-formatter(or > some other formatter) so that we continue development without disturbing > those using the simple default output. > > What do people think? > I really like that idea, and I agree with you that these two would cover most use cases. -Ben From lists at ruby-forum.com Mon Jul 28 18:10:48 2008 From: lists at ruby-forum.com (Evan Dorn) Date: Tue, 29 Jul 2008 00:10:48 +0200 Subject: [rspec-users] Autotest quits when code has errors Message-ID: Sorry, I'd put this in a ZenTest forum (as opposed to RSpec), except that I can't find one. I find it frustrating that autotest keeps running when it finds failing tests - but it quits back to the command line whenever a test or code contains *errors*. This means I have to constantly (like every 5 minutes) restart autotest by hand, which kind of defeats the purpose of autotest, and I find it hard to believe this is the default behavior. If I want to do TDD/BDD and call methods before they exist, this causes autotest to quit, which REALLY defeats the purpose. Am I doing something wrong, or is there a fix? I'm using ZenTest 3.10 with RSpec 1.1.5. Thanks! -- Posted via http://www.ruby-forum.com/. From mark.wilden at gmail.com Mon Jul 28 19:19:48 2008 From: mark.wilden at gmail.com (Mark Wilden) Date: Mon, 28 Jul 2008 16:19:48 -0700 Subject: [rspec-users] Autotest quits when code has errors In-Reply-To: <3c30da400807281528p2d2f49bfi95f515cd490dc1a6@mail.gmail.com> References: <3c30da400807281528p2d2f49bfi95f515cd490dc1a6@mail.gmail.com> Message-ID: <3c30da400807281619k5046e5b3w7a48b4381b6bd947@mail.gmail.com> On Mon, Jul 28, 2008 at 3:10 PM, Evan Dorn wrote: > Sorry, I'd put this in a ZenTest forum (as opposed to RSpec), except > that I can't find one. > > I find it frustrating that autotest keeps running when it finds failing > tests - but it quits back to the command line whenever a test or code > contains *errors*. > > This means I have to constantly (like every 5 minutes) restart autotest > by hand, which kind of defeats the purpose of autotest, and I find it > hard to believe this is the default behavior. > > If I want to do TDD/BDD and call methods before they exist, this causes > autotest to quit, which REALLY defeats the purpose. > > Am I doing something wrong, or is there a fix? I'm using ZenTest 3.10 > with RSpec 1.1.5. > It sounds like it might be an RSpec 1.1.5 thing. I've used 1.1.4 with autotest without seeing the problem you describe. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From abroad-crawford at within3.com Mon Jul 28 19:58:42 2008 From: abroad-crawford at within3.com (Anthony Broad-Crawford) Date: Mon, 28 Jul 2008 19:58:42 -0400 Subject: [rspec-users] Autotest quits when code has errors In-Reply-To: <3c30da400807281619k5046e5b3w7a48b4381b6bd947@mail.gmail.com> References: <3c30da400807281528p2d2f49bfi95f515cd490dc1a6@mail.gmail.com> <3c30da400807281619k5046e5b3w7a48b4381b6bd947@mail.gmail.com> Message-ID: <159A7283-25A3-4764-BAC4-5D6E73CDF416@within3.com> Try rspactor. I have been using since the author pinged this list several months ago. No complaints thus far. To your point, it doesn't bomb when there is an error. Anthony Broad-Crawford On Jul 28, 2008, at 7:19 PM, Mark Wilden wrote: > On Mon, Jul 28, 2008 at 3:10 PM, Evan Dorn > wrote: > Sorry, I'd put this in a ZenTest forum (as opposed to RSpec), except > that I can't find one. > > I find it frustrating that autotest keeps running when it finds > failing > tests - but it quits back to the command line whenever a test or code > contains *errors*. > > This means I have to constantly (like every 5 minutes) restart > autotest > by hand, which kind of defeats the purpose of autotest, and I find it > hard to believe this is the default behavior. > > If I want to do TDD/BDD and call methods before they exist, this > causes > autotest to quit, which REALLY defeats the purpose. > > Am I doing something wrong, or is there a fix? I'm using ZenTest > 3.10 > with RSpec 1.1.5. > > It sounds like it might be an RSpec 1.1.5 thing. I've used 1.1.4 > with autotest without seeing the problem you describe. > > ///ark > > _______________________________________________ > 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 mark.wilden at gmail.com Mon Jul 28 20:28:43 2008 From: mark.wilden at gmail.com (Mark Wilden) Date: Mon, 28 Jul 2008 17:28:43 -0700 Subject: [rspec-users] Autotest quits when code has errors In-Reply-To: <159A7283-25A3-4764-BAC4-5D6E73CDF416@within3.com> References: <3c30da400807281528p2d2f49bfi95f515cd490dc1a6@mail.gmail.com> <3c30da400807281619k5046e5b3w7a48b4381b6bd947@mail.gmail.com> <159A7283-25A3-4764-BAC4-5D6E73CDF416@within3.com> Message-ID: <3c30da400807281728n20d1e272td3efabcd11343bdb@mail.gmail.com> On Mon, Jul 28, 2008 at 4:58 PM, Anthony Broad-Crawford < abroad-crawford at within3.com> wrote: > Try rspactor. I have been using since the author pinged this list several > months ago. No complaints thus far. To your point, it doesn't bomb when > there is an error. > I use rspactor these days, too. A couple of things should be noted, however: 1) It's Mac-only. 2) It makes debugging rather painful if you run the debugger during rspactor's execution. I think this might be because it's polling for the Enter key instead of being signalled by ^C (autotest works the other way around!). This has the effect of swallowing some keystrokes while you're in the debugger, which can be very irritating. The solution of course is either to 1) debug directly from script/spec, or 2) don't use the debugger. :) ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From vertebrate at gmail.com Tue Jul 29 00:31:01 2008 From: vertebrate at gmail.com (Steve) Date: Mon, 28 Jul 2008 23:31:01 -0500 Subject: [rspec-users] Clear a stub In-Reply-To: <810a540e0807280539w1a66e0dclc35b5b08cc196bb7@mail.gmail.com> References: <810a540e0807271033m197b4c28o80fec10976bcf148@mail.gmail.com> <810a540e0807271556g615bf002n2c142eb44176173a@mail.gmail.com> <810a540e0807280539w1a66e0dclc35b5b08cc196bb7@mail.gmail.com> Message-ID: Pat Maddox wrote: > > etc. It's super weird that it works in every other place but not > here. So I'd start from the tiniest thing possible and add lines > until you find one that breaks it. > > Pat So I went through and took the whole thing apart. It turns out that it is/was a stub issue(just not quite what expected). Prior to calling the shared describe Reservation.find was stubbed to return []. I didn't realize that internally the fixtures collections used find. Now that I do, it all makes sense; since it's just doing what I told it to. So in a way my original question still stands. Is there a way to "unstub" something? Because I don't see a way around this unless I can do that. Thanks for your help. From tero at tilus.net Tue Jul 29 05:45:29 2008 From: tero at tilus.net (Tero Tilus) Date: Tue, 29 Jul 2008 12:45:29 +0300 Subject: [rspec-users] $LOAD_PATH problem when creating rake task Message-ID: <20080729094528.GD1672@uivelo.tilus.net> I'm trying to put together some rake tasks to run my specs, but require 'spec/rake/spectask' complains "no such file". I've gem installed rspec on my Ubuntu box and looks like it's locate in /var/lib/gems/1.8/gems/rspec-1.1.4/, which is not in load path irb> $LOAD_PATH => ["/usr/local/lib/site_ruby/1.8", "/usr/local/lib/site_ruby/1.8/i486-linux", "/usr/local/lib/site_ruby/1.8/i386-linux", "/usr/local/lib/site_ruby", "/usr/lib/ruby/1.8", "/usr/lib/ruby/1.8/i486-linux", "/usr/lib/ruby/1.8/i386-linux", "."] Now what? What would be a kosher way around this, maybe ln -s something somewhere? I can see the issue being discussed though, https://bugs.launchpad.net/ubuntu/+source/libgems-ruby/+bug/145267 -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ From luislavena at gmail.com Tue Jul 29 05:59:07 2008 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 29 Jul 2008 11:59:07 +0200 Subject: [rspec-users] $LOAD_PATH problem when creating rake task In-Reply-To: <20080729094528.GD1672@uivelo.tilus.net> References: <20080729094528.GD1672@uivelo.tilus.net> Message-ID: <71166b3b0807290259k5e327078xb54f79795485948@mail.gmail.com> On Tue, Jul 29, 2008 at 11:45 AM, Tero Tilus wrote: > I'm trying to put together some rake tasks to run my specs, but > require 'spec/rake/spectask' complains "no such file". I've gem > installed rspec on my Ubuntu box and looks like it's locate in > /var/lib/gems/1.8/gems/rspec-1.1.4/, which is not in load path > > irb> $LOAD_PATH > => ["/usr/local/lib/site_ruby/1.8", > "/usr/local/lib/site_ruby/1.8/i486-linux", > "/usr/local/lib/site_ruby/1.8/i386-linux", "/usr/local/lib/site_ruby", > "/usr/lib/ruby/1.8", "/usr/lib/ruby/1.8/i486-linux", > "/usr/lib/ruby/1.8/i386-linux", "."] > > Now what? What would be a kosher way around this, maybe ln -s > something somewhere? I can see the issue being discussed though, > https://bugs.launchpad.net/ubuntu/+source/libgems-ruby/+bug/145267 > Did you require rubygems first? D:\Users\Luis>irb irb(main):001:0> puts $LOAD_PATH D:/Users/Luis/ruby/ruby-186-p114-MINGW-rubygems-120/lib/ruby/site_ruby/1.8 D:/Users/Luis/ruby/ruby-186-p114-MINGW-rubygems-120/lib/ruby/site_ruby/1.8/i386-msvcrt D:/Users/Luis/ruby/ruby-186-p114-MINGW-rubygems-120/lib/ruby/site_ruby D:/Users/Luis/ruby/ruby-186-p114-MINGW-rubygems-120/lib/ruby/1.8 D:/Users/Luis/ruby/ruby-186-p114-MINGW-rubygems-120/lib/ruby/1.8/i386-mingw32 . => nil irb(main):002:0> require 'spec/rake/spectask' LoadError: no such file to load -- spec/rake/spectask from (irb):2:in `require' from (irb):2 irb(main):003:0> require 'rubygems' => true irb(main):004:0> require 'spec/rake/spectask' => true Maybe just a stupid comment, if so, please disregard it. -- Luis Lavena AREA 17 - Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. Douglas Adams From tero at tilus.net Tue Jul 29 06:09:13 2008 From: tero at tilus.net (Tero Tilus) Date: Tue, 29 Jul 2008 13:09:13 +0300 Subject: [rspec-users] $LOAD_PATH problem when creating rake task In-Reply-To: <71166b3b0807290259k5e327078xb54f79795485948@mail.gmail.com> References: <20080729094528.GD1672@uivelo.tilus.net> <71166b3b0807290259k5e327078xb54f79795485948@mail.gmail.com> Message-ID: <20080729100913.GE1672@uivelo.tilus.net> 2008-07-29 11:59, Luis Lavena: > Did you require rubygems first? Oh dear! You made my day. \o/ -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ From luislavena at gmail.com Tue Jul 29 06:14:15 2008 From: luislavena at gmail.com (Luis Lavena) Date: Tue, 29 Jul 2008 12:14:15 +0200 Subject: [rspec-users] $LOAD_PATH problem when creating rake task In-Reply-To: <20080729100913.GE1672@uivelo.tilus.net> References: <20080729094528.GD1672@uivelo.tilus.net> <71166b3b0807290259k5e327078xb54f79795485948@mail.gmail.com> <20080729100913.GE1672@uivelo.tilus.net> Message-ID: <71166b3b0807290314j47843d0fk99a0bcf637a7d996@mail.gmail.com> On Tue, Jul 29, 2008 at 12:09 PM, Tero Tilus wrote: > 2008-07-29 11:59, Luis Lavena: >> Did you require rubygems first? > > Oh dear! You made my day. \o/ > Sorry, I'm not a native english speaker, that means it worked? :-) -- Luis Lavena AREA 17 - Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. Douglas Adams From tero at tilus.net Tue Jul 29 06:56:30 2008 From: tero at tilus.net (Tero Tilus) Date: Tue, 29 Jul 2008 13:56:30 +0300 Subject: [rspec-users] $LOAD_PATH problem when creating rake task In-Reply-To: <71166b3b0807290314j47843d0fk99a0bcf637a7d996@mail.gmail.com> References: <20080729094528.GD1672@uivelo.tilus.net> <71166b3b0807290259k5e327078xb54f79795485948@mail.gmail.com> <20080729100913.GE1672@uivelo.tilus.net> <71166b3b0807290314j47843d0fk99a0bcf637a7d996@mail.gmail.com> Message-ID: <20080729105630.GF1672@uivelo.tilus.net> 2008-07-29 12:14, Luis Lavena: > > Oh dear! You made my day. \o/ > that means it worked? :-) Yes. :) -- Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/ From lists at ruby-forum.com Tue Jul 29 15:28:32 2008 From: lists at ruby-forum.com (Joseph Wilk) Date: Tue, 29 Jul 2008 21:28:32 +0200 Subject: [rspec-users] HTML Story Formatter In-Reply-To: <488DF668.8070301@benmabey.com> References: <1216902734.7340.14.camel@tybalt> <57c63afe0807240544p5a8adc2keaa21aac0ca1fe0e@mail.gmail.com> <57c63afe0807250611p5a950d51icefc3c36829650f2@mail.gmail.com> <49733.98.202.34.115.1217111915.squirrel@mail.onticweb.com> <488DF668.8070301@benmabey.com> Message-ID: <747a4561e23c795b961245c283ea648f@ruby-forum.com> > Ahh, good to know. Does that mean that the HTML isn't outputted until > all of the scenario's are ran for a particular story? Exactly. It made the html much nicer but did loose that per scenario output. I added a progress bar formatter so I could still get that direct scenario feedback, be it just a green dot or red F :) David are you happy with this html and dev-html formatter direction? If so I'll move this issue to lighthouse and start adding my patch. Ben Mabey wrote: > Joseph Wilk wrote: >>> Which brings up the other question.. how do we want to handle the JS? >>> Due to how the HTML is written out JS is required to change the Story's >>> and Scenario's styles when a step fails or is pending. I did this with >>> lowpro for the rspec-story-tmbundle: >>> >> >> The current html formatter in trunk no longer requires js to apply >> styles for failure or pending. >> > > Ahh, good to know. Does that mean that the HTML isn't outputted until > all of the scenario's are ran for a particular story? >> So that moves us along to looking at js to hide/show the backtrace. >> >> The idea of showing the backtrace in the html has been something I've >> been debating for a while. I did come to conclusion that as a developer >> I have the build log (or terminal stories are run from) as a source for >> story errors. Hence I felt I was best left leaving my stories clean for >> the non-developer users of the stories. >> > > This is true for regular development, although having the backtrace can > also be helpful in the HTML version if you use that as your main > formatter (i.e. in textmate.) > The real use for the backtrace, IMO, is for providing a decent build > artifact for CI. Otherwise you could have to look through your test.log > file and try to match it up.. which would be no fun. >> >> AND >> advanced/verbose output (profiling each story aswell perhaps?). >> Potentially Aslak's new interface could move to this dev-formatter(or >> some other formatter) so that we continue development without disturbing >> those using the simple default output. >> >> What do people think? >> > > I really like that idea, and I agree with you that these two would cover > most use cases. > > -Ben -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Tue Jul 29 16:54:03 2008 From: lists at ruby-forum.com (Evan Dorn) Date: Tue, 29 Jul 2008 22:54:03 +0200 Subject: [rspec-users] Autotest quits when code has errors In-Reply-To: <3c30da400807281619k5046e5b3w7a48b4381b6bd947@mail.gmail.com> References: <3c30da400807281619k5046e5b3w7a48b4381b6bd947@mail.gmail.com> Message-ID: <76047348249c46ce279b5b04262e05e6@ruby-forum.com> Mark Wilden wrote: > On Mon, Jul 28, 2008 at 3:10 PM, Evan Dorn wrote: > > > It sounds like it might be an RSpec 1.1.5 thing. I've used 1.1.4 with > autotest without seeing the problem you describe. > I have the same problem on projects that use Test::Unit, too, at least for some kinds of errors, particularly syntax errors. I'll check out this rspactor thing, I haven't heard of it before. But I'd still like to fix the original problem. -- Posted via http://www.ruby-forum.com/. From mailing_lists at railsnewbie.com Tue Jul 29 20:45:40 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 29 Jul 2008 20:45:40 -0400 Subject: [rspec-users] Clear a stub In-Reply-To: References: <810a540e0807271033m197b4c28o80fec10976bcf148@mail.gmail.com> <810a540e0807271556g615bf002n2c142eb44176173a@mail.gmail.com> <810a540e0807280539w1a66e0dclc35b5b08cc196bb7@mail.gmail.com> Message-ID: <5A1075BA-6E52-49FC-BE78-CF1E000D08CF@railsnewbie.com> On Jul 29, 2008, at 12:31 AM, Steve wrote: > Pat Maddox wrote: >> etc. It's super weird that it works in every other place but not >> here. So I'd start from the tiniest thing possible and add lines >> until you find one that breaks it. >> Pat > > So I went through and took the whole thing apart. It turns out that > it is/was a stub issue(just not quite what expected). Prior to > calling the shared describe Reservation.find was stubbed to return > []. I didn't realize that internally the fixtures collections used > find. Now that I do, it all makes sense; since it's just doing what > I told it to. > > So in a way my original question still stands. Is there a way to > "unstub" something? Because I don't see a way around this unless I > can do that. Thanks for your help. Of course there is a way - the question is, do you really want to use it? Here's how the test suite sets up stubs: 1. you say, stub object foo with method bar, returning baz 2. rspec aliases the original method, and then redefines it bar on foo to return baz 3. your test case ends, and then rspec goes back, and re-aliases the method to it's original definition. So yes, you could call the un-stub'ed method (which I believe rspec calls #proxied_by_rspec_#{method_name}), although I think it'll be ugly and confusing. But, if you really want to override the behaviour, I'd suggest defining something like this: class Object def original_stub(method_name, *args, &blk) self.send("proxied_by_rspec_#{method_name}", *args, &blk) end end But, I think the best result is just to duplicate the stub. Scott > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From vertebrate at gmail.com Thu Jul 31 09:43:03 2008 From: vertebrate at gmail.com (Steve) Date: Thu, 31 Jul 2008 08:43:03 -0500 Subject: [rspec-users] Clear a stub In-Reply-To: <5A1075BA-6E52-49FC-BE78-CF1E000D08CF@railsnewbie.com> References: <810a540e0807271033m197b4c28o80fec10976bcf148@mail.gmail.com> <810a540e0807271556g615bf002n2c142eb44176173a@mail.gmail.com> <810a540e0807280539w1a66e0dclc35b5b08cc196bb7@mail.gmail.com> <5A1075BA-6E52-49FC-BE78-CF1E000D08CF@railsnewbie.com> Message-ID: Scott Taylor wrote: > > Of course there is a way - the question is, do you really want to use it? After seeing that, no, not really. I agree with you on it likely messing with clarity. I opted to rework my specs. It wasn't my preferred option, but there really wasn't a better way. Thanks to both of you for the help. From bastien.vaucher at gmail.com Thu Jul 31 10:06:41 2008 From: bastien.vaucher at gmail.com (Bastien) Date: Thu, 31 Jul 2008 07:06:41 -0700 (PDT) Subject: [rspec-users] Can't access actions of a singular nested resource Message-ID: <8e78802d-707e-4782-a69c-e5cbf4a92692@m36g2000hse.googlegroups.com> I can't figure out what I do wrong there, I have a nested controller which is defined as a singular resource, the routing works properly, but inside my specs the request never goes through the show action. I keep on getting this error : Spec::Mocks::MockExpectationError in 'Surveys::ReportController should return the survey corresponding to the report' Mock 'Class' expected :find with (any args) once, but received it 0 times In my specs : require File.expand_path(File.dirname(__FILE__) + '/../../ spec_helper') describe Surveys::ReportController do it "should return the survey corresponding to the report" do Survey.should_receive(:find) get :show, :survey_id=>"34" end end In route.rb : map.resources :surveys do |survey| survey.resource :report, :controller =>'surveys/report' end In controller/surveys/report_controller.rb : class Surveys::ReportController < ApplicationController def show @survey = Survey.find(params[:survey_id]) respond_to do |format| format.html format.xml end end end From aslak.hellesoy at gmail.com Thu Jul 31 11:21:24 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 31 Jul 2008 17:21:24 +0200 Subject: [rspec-users] Can't access actions of a singular nested resource In-Reply-To: <8e78802d-707e-4782-a69c-e5cbf4a92692@m36g2000hse.googlegroups.com> References: <8e78802d-707e-4782-a69c-e5cbf4a92692@m36g2000hse.googlegroups.com> Message-ID: <8d961d900807310821h1a1a7d6at281434f486e34432@mail.gmail.com> On Thu, Jul 31, 2008 at 4:06 PM, Bastien wrote: > I can't figure out what I do wrong there, I have a nested controller > which is defined as a singular resource, the routing works properly, > but inside my specs the request never goes through the show action. > > I keep on getting this error : > > Spec::Mocks::MockExpectationError in 'Surveys::ReportController should > return the survey corresponding to the report' > Mock 'Class' expected :find with (any args) once, but received it 0 > times > > In my specs : > require File.expand_path(File.dirname(__FILE__) + '/../../ > spec_helper') > describe Surveys::ReportController do > > it "should return the survey corresponding to the report" do > Survey.should_receive(:find) > get :show, :survey_id=>"34" Try: get :show, :id=>"34" Aslak > end > > end > > In route.rb : > map.resources :surveys do |survey| > survey.resource :report, :controller =>'surveys/report' > end > > In controller/surveys/report_controller.rb : > class Surveys::ReportController < ApplicationController > > def show > @survey = Survey.find(params[:survey_id]) > > respond_to do |format| > format.html > format.xml > end > end > > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Thu Jul 31 11:23:42 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 31 Jul 2008 17:23:42 +0200 Subject: [rspec-users] Can't access actions of a singular nested resource In-Reply-To: <8d961d900807310821h1a1a7d6at281434f486e34432@mail.gmail.com> References: <8e78802d-707e-4782-a69c-e5cbf4a92692@m36g2000hse.googlegroups.com> <8d961d900807310821h1a1a7d6at281434f486e34432@mail.gmail.com> Message-ID: <8d961d900807310823q7c80b7e1u1876f636146ef8e2@mail.gmail.com> On Thu, Jul 31, 2008 at 5:21 PM, aslak hellesoy wrote: > On Thu, Jul 31, 2008 at 4:06 PM, Bastien wrote: >> I can't figure out what I do wrong there, I have a nested controller >> which is defined as a singular resource, the routing works properly, >> but inside my specs the request never goes through the show action. >> >> I keep on getting this error : >> >> Spec::Mocks::MockExpectationError in 'Surveys::ReportController should >> return the survey corresponding to the report' >> Mock 'Class' expected :find with (any args) once, but received it 0 >> times >> >> In my specs : >> require File.expand_path(File.dirname(__FILE__) + '/../../ >> spec_helper') >> describe Surveys::ReportController do >> >> it "should return the survey corresponding to the report" do >> Survey.should_receive(:find) >> get :show, :survey_id=>"34" > > Try: > > get :show, :id=>"34" > Sorry, I was too quick. It sounds like your params don't match the routes you want. Try rake routes, and also try to spec the routing in the associated routing_spec.rb. Aslak > Aslak > >> end >> >> end >> >> In route.rb : >> map.resources :surveys do |survey| >> survey.resource :report, :controller =>'surveys/report' >> end >> >> In controller/surveys/report_controller.rb : >> class Surveys::ReportController < ApplicationController >> >> def show >> @survey = Survey.find(params[:survey_id]) >> >> respond_to do |format| >> format.html >> format.xml >> end >> end >> >> end >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > From lesliefreeman3 at gmail.com Thu Jul 31 15:02:36 2008 From: lesliefreeman3 at gmail.com (Leslie Freeman) Date: Thu, 31 Jul 2008 12:02:36 -0700 Subject: [rspec-users] Writing specs for a plugin module for ActionController Message-ID: Hello, I'm trying to spec a plugin that includes a module that adds functionality to ActionController below is what I've come up with: # vendor/plugins/custom_attribute_fu/spec/active_record_spec.rb require File.dirname(__FILE__) + '/spec_helper' class TestPerson < ActiveRecord::Base end class TestPeopleController < ActionController::Base #calling defines_custom_attributes should add the custom_attribute_definitions method, I've defined it explicitly for now to just get the tests running #defines_custom_attributes def custom_attribute_definitions end end describe TestPeopleController do describe "handling GET /custom_attribute_definitions" do before(:each) do @controller = TestPeopleController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new end def do_get get :custom_attribute_definitions end it "should be successful" do do_get response.should be_success end end end When I run the spec I get: 1) ActionView::TemplateError in 'TestPeopleController handling GET / custom_attribute_definitions should be successful' undefined method `custom_attribute_definitions' for TestPerson(id: integer, name: string):Class What I don't understand is that why get :custom_attribute_definitions is trying to call that method on TestPerson rather than TestPersonController. I'm sure there's a better way to set this up - any advice would be greatly appreciated! Les