From timcharper at gmail.com Wed Oct 1 00:28:01 2008 From: timcharper at gmail.com (Tim Harper) Date: Tue, 30 Sep 2008 22:28:01 -0600 Subject: [rspec-users] Why no rspec-rails gem? In-Reply-To: <57c63afe0809290531q51a29f59o403f01c959af9ba0@mail.gmail.com> References: <57c63afe0809290531q51a29f59o403f01c959af9ba0@mail.gmail.com> Message-ID: <408AE25D-138F-4F17-B888-0738A8BE206C@gmail.com> > > I released 1.1.5 yesterday, including rspec-1.1.5 and rspec- > rails-1.1.5 gems. > It works fantastic. Thanks for a quality release. I've freed up about 100 of megs on my hard drive already. > Cheers, > David From dchelimsky at gmail.com Wed Oct 1 00:45:34 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 30 Sep 2008 23:45:34 -0500 Subject: [rspec-users] Shoulda In-Reply-To: <48E239F1.3050208@benmabey.com> References: <79482482-39F5-40B8-AF01-9577CD0F7D9F@mattwynne.net> <223a182c8e8a471651f6b13e20a7eaf1@ruby-forum.com> <85d99afe0809300557x4d572a59qd829d294d62e3252@mail.gmail.com> <85d99afe0809300559k5c396563k5793576763930e4f@mail.gmail.com> <57c63afe0809300705u161e57a3qdc2c6d4551ae351b@mail.gmail.com> <48E239F1.3050208@benmabey.com> Message-ID: <57c63afe0809302145wf2e2791j9c1457f11c31668@mail.gmail.com> On Tue, Sep 30, 2008 at 9:38 AM, Ben Mabey wrote: > David Chelimsky wrote: >> >> On Tue, Sep 30, 2008 at 7:59 AM, Zach Dennis >> wrote: >> >>> >>> Also, a nice thing about RSpec is that when you do describe an actual >>> object, ie: "describe Foo", you can determine this by asking the >>> example group what it's described type is. >>> >>> This makes things a lot simpler and cleaner than having to hack away >>> strings, or guess based on the name of your test. >>> >>> Zach >>> >>> On Tue, Sep 30, 2008 at 8:57 AM, Zach Dennis >>> wrote: >>> >>>> >>>> On Tue, Sep 30, 2008 at 8:41 AM, Andy Freeman >>>> wrote: >>>> >>>>> >>>>> Are you willing to provide a simple example? >>>>> >>>> >>>> I'm using the same example as the articled you linked to originally as >>>> the base. This way you should be able to clearly see the differences. >>>> >>>> http://gist.github.com/13804 >>>> >> >> Here's a variation on that with a helper for defining macros that I'm >> thinking of adding to rspec. Lemme know what you think: >> >> http://gist.github.com/13821 >> >> Cheers, >> David >> >> > > +1 > I like it. For rspec-rails it would also be nice to be able to say: > > define_macros(:for => :controller) do > ... > end > > define_macros(:for => :models) do > ... > end > etc... > > Also, instead of yielding within another block you can simply pass in the > given block as an arg: > > def define_macros(¯o_block) > Spec::Example::ExampleGroupMethods.extend Module.new(¯o_block) > end Close but not quite. Here are two similar examples that work: def define_macros(&block) Spec::Example::ExampleGroupMethods.module_eval(&block) end def define_macros(&block) Spec::Example::ExampleGroupMethods.extend Module.new(&block.call) end I think the first is nicer if we're not too concerned with control or traceability, but the second, w/ the Module.new on a separate line, would support maintaining references to the module (if that would be useful). Cheers, David > You probably knew this but I thought I would point it out because it seems > that it would give you better performance. (I have not tested that > assumption at all.) > > -Ben From dchelimsky at gmail.com Wed Oct 1 00:46:27 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 30 Sep 2008 23:46:27 -0500 Subject: [rspec-users] Shoulda In-Reply-To: <845b68658ddffc6cbf2ea0e7097f6043@ruby-forum.com> References: <79482482-39F5-40B8-AF01-9577CD0F7D9F@mattwynne.net> <223a182c8e8a471651f6b13e20a7eaf1@ruby-forum.com> <85d99afe0809300557x4d572a59qd829d294d62e3252@mail.gmail.com> <85d99afe0809300559k5c396563k5793576763930e4f@mail.gmail.com> <57c63afe0809300705u161e57a3qdc2c6d4551ae351b@mail.gmail.com> <845b68658ddffc6cbf2ea0e7097f6043@ruby-forum.com> Message-ID: <57c63afe0809302146g51fa76bfn206acd163e4916cf@mail.gmail.com> On Tue, Sep 30, 2008 at 10:18 PM, Andy Freeman wrote: > David Chelimsky wrote: >> On Tue, Sep 30, 2008 at 7:59 AM, Zach Dennis >> wrote: >>>> On Tue, Sep 30, 2008 at 8:41 AM, Andy Freeman wrote: >>>>> Are you willing to provide a simple example? >>>> >>>> I'm using the same example as the articled you linked to originally as >>>> the base. This way you should be able to clearly see the differences. >>>> >>>> http://gist.github.com/13804 >> >> Here's a variation on that with a helper for defining macros that I'm >> thinking of adding to rspec. Lemme know what you think: >> >> http://gist.github.com/13821 > What's not to like?! Despite the fact that a new RSpec version was just > released, it would be nice to see a new version released right away with > this concept built in so that a RSpec version of Shoulda could start > rolling. :) Not quite sure how we got from discussing an idea to release planning, but the idea of a shoulda-like library built on this is a good one. If you're planning on writing one, no need to wait for this to appear in rspec. It's 3 lines of code that you could include in such a library until such time as it is released w/ RSpec. Cheers, David >> >> Cheers, >> David From lists at ruby-forum.com Wed Oct 1 00:49:57 2008 From: lists at ruby-forum.com (Andy Freeman) Date: Wed, 1 Oct 2008 06:49:57 +0200 Subject: [rspec-users] Shoulda In-Reply-To: <57c63afe0809302146g51fa76bfn206acd163e4916cf@mail.gmail.com> References: <79482482-39F5-40B8-AF01-9577CD0F7D9F@mattwynne.net> <223a182c8e8a471651f6b13e20a7eaf1@ruby-forum.com> <85d99afe0809300557x4d572a59qd829d294d62e3252@mail.gmail.com> <85d99afe0809300559k5c396563k5793576763930e4f@mail.gmail.com> <57c63afe0809300705u161e57a3qdc2c6d4551ae351b@mail.gmail.com> <845b68658ddffc6cbf2ea0e7097f6043@ruby-forum.com> <57c63afe0809302146g51fa76bfn206acd163e4916cf@mail.gmail.com> Message-ID: I was actually teasing... :) As far as writing one... already on it! David Chelimsky wrote: > On Tue, Sep 30, 2008 at 10:18 PM, Andy Freeman > wrote: >>> >>> Here's a variation on that with a helper for defining macros that I'm >>> thinking of adding to rspec. Lemme know what you think: >>> >>> http://gist.github.com/13821 > >> What's not to like?! Despite the fact that a new RSpec version was just >> released, it would be nice to see a new version released right away with >> this concept built in so that a RSpec version of Shoulda could start >> rolling. :) > > Not quite sure how we got from discussing an idea to release planning, > but the idea of a shoulda-like library built on this is a good one. If > you're planning on writing one, no need to wait for this to appear in > rspec. It's 3 lines of code that you could include in such a library > until such time as it is released w/ RSpec. > > Cheers, > David -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Wed Oct 1 02:46:48 2008 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 1 Oct 2008 07:46:48 +0100 Subject: [rspec-users] [ANN] Cucumber Textmate Bundle In-Reply-To: <48D2AF3C.6080600@shopwatch.org> References: <48D14F7A.4@benmabey.com> <8d961d900809171321vb0a2a3bjdafdb98dadc896da@mail.gmail.com> <48D16F15.50503@benmabey.com> <8d961d900809171413v7692a915p111fbee2a6619858@mail.gmail.com> <48D17818.3010503@benmabey.com> <8d961d900809171542x422f6838s36219a7c981a216b@mail.gmail.com> <48D18F55.7080904@benmabey.com> <48D2AF3C.6080600@shopwatch.org> Message-ID: Is it possible to rename the project maybe? I know you can have dots in the name - e.g. http://github.com/thoughtworks/cruisecontrol.rb though I think I may have heard this was a restriction that was lifted relatively recently. On 18 Sep 2008, at 20:42, Jay Levitt wrote: > Ben Mabey wrote: > >> You can get it here: >> http://github.com/bmabey/cucumber-tmbundle/ > > This is probably blindingly obvious to anyone who's ever installed a > Textmate bundle from github before (i.e. not me), but you have to > rename cucumber-tmbundle to cucumber.tmbundle before TextMate will > recognize it. Dunno if that should go in the README or not. > > Jay Levitt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Wed Oct 1 02:50:46 2008 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 1 Oct 2008 07:50:46 +0100 Subject: [rspec-users] [ANN] Cucumber Textmate Bundle In-Reply-To: <48D14F7A.4@benmabey.com> References: <48D14F7A.4@benmabey.com> Message-ID: <9A958EDC-4CD5-4FE6-96EE-DE6EE6CEFCEE@mattwynne.net> Just installed this - superb! Thanks Ben. On 17 Sep 2008, at 19:42, Ben Mabey wrote: > Hey all, > I am in the process of porting my RSpec Story Textmate bundle over to > Cucumber. > So far I have the syntax highlighting, file switching, and running of > the features and single scenarios done. So not all the functionally > is > ported yet and it has some rough edges but I think it is ready to be > used/tested by more than just me. :) > > You can get it here: > http://github.com/bmabey/cucumber-tmbundle/ > > Please read the README as it talks about avoiding RSpec Story bundle > collisions and how to run features. > > Thanks, > Ben > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Wed Oct 1 03:33:21 2008 From: lists at ruby-forum.com (Neil Cauldwell) Date: Wed, 1 Oct 2008 09:33:21 +0200 Subject: [rspec-users] Spec for 'an array should not include an item' In-Reply-To: <48E2767F.5090406@benmabey.com> References: <23fca9046d582f17fa4e61119eb45334@ruby-forum.com> <48E2767F.5090406@benmabey.com> Message-ID: Ben Mabey wrote: > Pat Maddox wrote: >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > Also, what is your data? The matcher may not work as expected due to > nuances in your data. For example, STI tends to mess things up in cases > like this. > > -Ben Thanks guys. The problem is that it simply doesn't fail when I expect it to. If I remove the call to the :inactive_user fixture (i.e. I'm checking that the results should not include any of the 'users' at all), it still passes. This is the spec in full; describe "handling GET /searches/people" do def do_get ThinkingSphinx::Search.stub!(:search).and_return(users) get :people, :search => "bob" end it "should be successful" do do_get response.should be_success end it "should render people template" do do_get response.should render_template('people') end it "should assign an array of user results" do do_get assigns[:results].should_not be_nil end it "should not include any inactive users in an assigned array of user results " do do_get assigns[:results].should_not include(users(:inactive_user)) end it "should not include any banned users in an assigned array of user results " do do_get assigns[:results].should_not include(users(:banned)) end end Is my stubbing breaking this? I hope not because Thinking SPhinx isn't determining the scope of the search in relation to the 'active' state of the users; the search is built on top of a named scope on the User model; # GET /searches/people # GET /searches/people.xml def people @results = User.active.search params[:search], :page => params[:page], :per_page => 15 respond_to do |format| format.html format.xml { render :xml => @results } end end Cheers -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Oct 1 04:05:05 2008 From: lists at ruby-forum.com (Andy Freeman) Date: Wed, 1 Oct 2008 10:05:05 +0200 Subject: [rspec-users] Shoulda In-Reply-To: <57c63afe0809302145wf2e2791j9c1457f11c31668@mail.gmail.com> References: <79482482-39F5-40B8-AF01-9577CD0F7D9F@mattwynne.net> <223a182c8e8a471651f6b13e20a7eaf1@ruby-forum.com> <85d99afe0809300557x4d572a59qd829d294d62e3252@mail.gmail.com> <85d99afe0809300559k5c396563k5793576763930e4f@mail.gmail.com> <57c63afe0809300705u161e57a3qdc2c6d4551ae351b@mail.gmail.com> <48E239F1.3050208@benmabey.com> <57c63afe0809302145wf2e2791j9c1457f11c31668@mail.gmail.com> Message-ID: <5e08813e3a1c4ef81e781a2096dc9058@ruby-forum.com> It is a bit ugly but here is an initial port of the Shoulda ActiveRecord macros: http://gist.github.com/14050 I did not try running ALL of the macros, but most of them. Before going too far with it, I would appreciate some recommendations as to how to improve the flow. The Shoulda version has a different feel to it since the assertions cause the code to die early. Whereas the RSpec conversion I did mostly wrap each should call in its own it block. Thanks for the help! I learned a lot from this exercise! Andy David Chelimsky wrote: > On Tue, Sep 30, 2008 at 9:38 AM, Ben Mabey wrote: >>>> This makes things a lot simpler and cleaner than having to hack away >>>>> >>> Here's a variation on that with a helper for defining macros that I'm >> I like it. For rspec-rails it would also be nice to be able to say: >> Also, instead of yielding within another block you can simply pass in the >> given block as an arg: >> >> def define_macros(¯o_block) >> Spec::Example::ExampleGroupMethods.extend Module.new(¯o_block) >> end > > Close but not quite. Here are two similar examples that work: > > def define_macros(&block) > Spec::Example::ExampleGroupMethods.module_eval(&block) > end > > def define_macros(&block) > Spec::Example::ExampleGroupMethods.extend Module.new(&block.call) > end > > I think the first is nicer if we're not too concerned with control or > traceability, but the second, w/ the Module.new on a separate line, > would support maintaining references to the module (if that would be > useful). > > Cheers, > David -- Posted via http://www.ruby-forum.com/. From ashley.moran at patchspace.co.uk Wed Oct 1 08:54:24 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 1 Oct 2008 13:54:24 +0100 Subject: [rspec-users] Associations should be private Message-ID: <10BF8774-5F69-444E-B442-B40F472EFFBB@patchspace.co.uk> Hi The discussion among me, David, Michael, and Pat got me thinking. Specifically this by Michael: > Just my $0.02, but I really like specs to be treated as > specifications for what SHOULD be happening, not pretending other > code is different than it is. This made me think the real solution is for ActiveRecord/A N Other ORM to declare that its associations are proxies and not arrays. But that's *terrible*, because it's encouraging users to manipulate the ORM objects' structures. So what if you flatly make all associations private? Is this a good idea? Has anyone tried it? Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From dchelimsky at gmail.com Wed Oct 1 09:00:23 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 1 Oct 2008 08:00:23 -0500 Subject: [rspec-users] Spec for 'an array should not include an item' In-Reply-To: References: <23fca9046d582f17fa4e61119eb45334@ruby-forum.com> <48E2767F.5090406@benmabey.com> Message-ID: <57c63afe0810010600v5c3ca519u7d7bd07f2369da0b@mail.gmail.com> On Wed, Oct 1, 2008 at 2:33 AM, Neil Cauldwell wrote: > Ben Mabey wrote: >> Pat Maddox wrote: >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> >> Also, what is your data? The matcher may not work as expected due to >> nuances in your data. For example, STI tends to mess things up in cases >> like this. >> >> -Ben > > Thanks guys. The problem is that it simply doesn't fail when I expect it > to. If I remove the call to the :inactive_user fixture (i.e. I'm > checking that the results should not include any of the 'users' at all), > it still passes. This is the spec in full; > > describe "handling GET /searches/people" do > > def do_get > ThinkingSphinx::Search.stub!(:search).and_return(users) > get :people, :search => "bob" > end > > it "should be successful" do > do_get > response.should be_success > end > > it "should render people template" do > do_get > response.should render_template('people') > end > > it "should assign an array of user results" do > do_get > assigns[:results].should_not be_nil > end > > it "should not include any inactive users in an assigned array of user > results " do > do_get > assigns[:results].should_not include(users(:inactive_user)) > end > > it "should not include any banned users in an assigned array of user > results " do > do_get > assigns[:results].should_not include(users(:banned)) > end > > end > > Is my stubbing breaking this? I hope not because Thinking SPhinx isn't > determining the scope of the search in relation to the 'active' state of > the users; the search is built on top of a named scope on the User > model; > > # GET /searches/people > # GET /searches/people.xml > def people > @results = User.active.search params[:search], :page => > params[:page], :per_page => 15 > > respond_to do |format| > format.html > format.xml { render :xml => @results } > end > end Looks to me like this is testing the User here in addition to the controller. I'd recommend this: @mock_user = mock_model(User) User.stub!(:search_active).and_return([@mock_user]) This would suggest a new method on User that wraps User.active.search, which you can drive out with code examples directly on the model, where the work is being done. Then you could have only one example that deals w/ the collection of users assigned for the view: it "should expose @results for the view" do do_get assigns[:results].should = [@mock_user] end Then, in the model examples, you could either stub the Sphinx search or just not use stubs/mocks at all. HTH, David > > Cheers > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From raasdnil at gmail.com Wed Oct 1 09:11:39 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Wed, 1 Oct 2008 23:11:39 +1000 Subject: [rspec-users] How do BOTH these examples pass? In-Reply-To: <7D40733D-FB29-4C94-9C13-4598FD93FD26@patchspace.co.uk> References: <7D40733D-FB29-4C94-9C13-4598FD93FD26@patchspace.co.uk> Message-ID: <57a815bf0810010611s643765a8u8394a5d46021afd6@mail.gmail.com> On Wed, Oct 1, 2008 at 1:02 AM, Ashley Moran wrote: > RssReader when there is an HTTP error > - should attempt to parse the RSS > - should not attempt to parse the RSS > - should fail gracefully >From what I can see, your code error is not doing anything with the caught exception: def rss rss_body = begin @uri.read rescue OpenURI::HTTPError => e nil end ::RSS::Parser.parse(rss_body, false) end This starts reading the body, catches an error, evaluates nil, exits the rescue block and then continues to do the Parser.parse. Changing it to: def rss rss_body = begin @uri.read ::RSS::Parser.parse(rss_body, false) rescue OpenURI::HTTPError => e nil end end Should pass your specs. Mikel -- http://lindsaar.net/ Rails, RSpec and Life blog.... From dchelimsky at gmail.com Wed Oct 1 09:11:55 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 1 Oct 2008 08:11:55 -0500 Subject: [rspec-users] Associations should be private In-Reply-To: <10BF8774-5F69-444E-B442-B40F472EFFBB@patchspace.co.uk> References: <10BF8774-5F69-444E-B442-B40F472EFFBB@patchspace.co.uk> Message-ID: <57c63afe0810010611o626510b2tee027aa8b2301d67@mail.gmail.com> On Wed, Oct 1, 2008 at 7:54 AM, Ashley Moran wrote: > Hi > > The discussion among me, David, Michael, and Pat got me thinking. > Specifically this by Michael: > >> Just my $0.02, but I really like specs to be treated as specifications for >> what SHOULD be happening, not pretending other code is different than it is. > > This made me think the real solution is for ActiveRecord/A N Other ORM to > declare that its associations are proxies and not arrays. But that's > *terrible*, because it's encouraging users to manipulate the ORM objects' > structures. > > So what if you flatly make all associations private? Is this a good idea? > Has anyone tried it? It's been a while since I've taken a look at it, but Luke Redpath has a plugin called Demeter's Revenge (http://plugins.code.lukeredpath.co.uk/browser/demeters_revenge/trunk) that actually manages this all for you by adding methods like team.add_player that wrap chains like team.players.add. It's a year old and I don't know if it works w/ the latest rails updates or not. I think that if you're actually writing a bunch of boilerplate code the same way over and over without a plugin like that, then it's probably painful. With something like that it's painless and expressive and seriously cleans up your controller code examples. Glancing at github, I see one other library up there that tries to solve the same problem. Will have to look closer later at http://github.com/trotter/belongs_to_demeter. Cheers, David > > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Wed Oct 1 09:19:54 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 1 Oct 2008 14:19:54 +0100 Subject: [rspec-users] Associations should be private In-Reply-To: <57c63afe0810010611o626510b2tee027aa8b2301d67@mail.gmail.com> References: <10BF8774-5F69-444E-B442-B40F472EFFBB@patchspace.co.uk> <57c63afe0810010611o626510b2tee027aa8b2301d67@mail.gmail.com> Message-ID: <45CA449D-9071-49ED-877A-96657E08B854@patchspace.co.uk> On 1 Oct 2008, at 14:11, David Chelimsky wrote: > It's been a while since I've taken a look at it, but Luke Redpath has > a plugin called Demeter's Revenge > (http://plugins.code.lukeredpath.co.uk/browser/demeters_revenge/trunk) > that actually manages this all for you by adding methods like > team.add_player that wrap chains like team.players.add. It's a year > old and I don't know if it works w/ the latest rails updates or not. > > I think that if you're actually writing a bunch of boilerplate code > the same way over and over without a plugin like that, then it's > probably painful. With something like that it's painless and > expressive and seriously cleans up your controller code examples. > > Glancing at github, I see one other library up there that tries to > solve the same problem. Will have to look closer later at > http://github.com/trotter/belongs_to_demeter. Cool, thanks for the pointers there! Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Wed Oct 1 09:26:06 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 1 Oct 2008 14:26:06 +0100 Subject: [rspec-users] How do BOTH these examples pass? In-Reply-To: <57a815bf0810010611s643765a8u8394a5d46021afd6@mail.gmail.com> References: <7D40733D-FB29-4C94-9C13-4598FD93FD26@patchspace.co.uk> <57a815bf0810010611s643765a8u8394a5d46021afd6@mail.gmail.com> Message-ID: <9B111CEF-8628-41B6-AF85-CA1B686F7F9D@patchspace.co.uk> On 1 Oct 2008, at 14:11, Mikel Lindsaar wrote: > Changing it to: > > def rss > rss_body = > begin > @uri.read > ::RSS::Parser.parse(rss_body, false) > rescue OpenURI::HTTPError => e > nil > end > end Ah don't worry, that's what my real code does. The code I posted was mid-refactoring. > Should pass your specs. It's academic really, but this code: > def rss > rss_body = > begin > @uri.read > rescue OpenURI::HTTPError => e > nil > end > > ::RSS::Parser.parse(rss_body, false) > end *does* pass the specs, both the one that says parse should be called, and the one that say it shouldn't! But why? I'm prepared to admit I'm just missing something really really really obvious (it happens often), but how can: it "should attempt to parse the RSS" do ::RSS::Parser.should_receive(:parse) @rss_reader.rss end it "should not attempt to parse the RSS" do ::RSS::Parser.should_not_receive(:parse) @rss_reader.rss end both pass, under any circumstances? Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From lists at ruby-forum.com Wed Oct 1 09:35:17 2008 From: lists at ruby-forum.com (Neil Cauldwell) Date: Wed, 1 Oct 2008 15:35:17 +0200 Subject: [rspec-users] Spec for 'an array should not include an item' In-Reply-To: <57c63afe0810010600v5c3ca519u7d7bd07f2369da0b@mail.gmail.com> References: <23fca9046d582f17fa4e61119eb45334@ruby-forum.com> <48E2767F.5090406@benmabey.com> <57c63afe0810010600v5c3ca519u7d7bd07f2369da0b@mail.gmail.com> Message-ID: <3592c0403423339ea394f776e2adb731@ruby-forum.com> David Chelimsky wrote: > On Wed, Oct 1, 2008 at 2:33 AM, Neil Cauldwell > wrote: >>> Also, what is your data? The matcher may not work as expected due to >> describe "handling GET /searches/people" do >> >> it "should not include any inactive users in an assigned array of user >> >> @results = User.active.search params[:search], :page => >> params[:page], :per_page => 15 >> >> respond_to do |format| >> format.html >> format.xml { render :xml => @results } >> end >> end > > Looks to me like this is testing the User here in addition to the > controller. > > I'd recommend this: > > @mock_user = mock_model(User) > User.stub!(:search_active).and_return([@mock_user]) > > This would suggest a new method on User that wraps User.active.search, > which you can drive out with code examples directly on the model, > where the work is being done. > > Then you could have only one example that deals w/ the collection of > users assigned for the view: > > it "should expose @results for the view" do > do_get > assigns[:results].should = [@mock_user] > end > > Then, in the model examples, you could either stub the Sphinx search > or just not use stubs/mocks at all. > > HTH, > David Thanks David. After a couple of reads through I don't really grasp that. Where would this go in relation to the controller description I posted (?); @mock_user = mock_model(User) User.stub!(:search_active).and_return([@mock_user]) Would it work in the do_get? Further to this, am I right in thinking that I would write a spec along these lines; > it "should not expose @results for the view" do > do_get > assigns[:results].should_not == [@mock_user] > end Also (I'm assuming that the 'model examples' are the User model spec), the user_spec.rb doesn't have any specs that relate to search. Are you suggesting that there should be some in there, or, are all your suggestions all related to the controller example I posted? Please bear with me, I'm not much of a developer. -- Posted via http://www.ruby-forum.com/. From raasdnil at gmail.com Wed Oct 1 09:36:02 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Wed, 1 Oct 2008 23:36:02 +1000 Subject: [rspec-users] How do BOTH these examples pass? In-Reply-To: <9B111CEF-8628-41B6-AF85-CA1B686F7F9D@patchspace.co.uk> References: <7D40733D-FB29-4C94-9C13-4598FD93FD26@patchspace.co.uk> <57a815bf0810010611s643765a8u8394a5d46021afd6@mail.gmail.com> <9B111CEF-8628-41B6-AF85-CA1B686F7F9D@patchspace.co.uk> Message-ID: <57a815bf0810010636sfcee200v8999296eb8bb9b56@mail.gmail.com> On Wed, Oct 1, 2008 at 11:26 PM, Ashley Moran wrote: > *does* pass the specs, both the one that says parse should be called, and > the one that say it shouldn't! But why? I'm prepared to admit I'm just > missing something really really really obvious (it happens often), but how > can: > > both pass, under any circumstances? Oh... I see what you are saying now.... Weird. When I have had something like this in the past, I refactor my spec code to not use any nesting at all and put all the pre conditions inside of the it should block, that way you are sure you are not getting some weird edge case on something. Try it out. it "should not pass" do every setup thing from every before block in here do the action end See what comes of that. -- http://lindsaar.net/ Rails, RSpec and Life blog.... From lists at ruby-forum.com Wed Oct 1 10:01:59 2008 From: lists at ruby-forum.com (Andy Freeman) Date: Wed, 1 Oct 2008 16:01:59 +0200 Subject: [rspec-users] Shoulda In-Reply-To: <5e08813e3a1c4ef81e781a2096dc9058@ruby-forum.com> References: <79482482-39F5-40B8-AF01-9577CD0F7D9F@mattwynne.net> <223a182c8e8a471651f6b13e20a7eaf1@ruby-forum.com> <85d99afe0809300557x4d572a59qd829d294d62e3252@mail.gmail.com> <85d99afe0809300559k5c396563k5793576763930e4f@mail.gmail.com> <57c63afe0809300705u161e57a3qdc2c6d4551ae351b@mail.gmail.com> <48E239F1.3050208@benmabey.com> <57c63afe0809302145wf2e2791j9c1457f11c31668@mail.gmail.com> <5e08813e3a1c4ef81e781a2096dc9058@ruby-forum.com> Message-ID: I updated the gist posting. All of the macros should be functional now and have cleaned up describe blocks. http://gist.github.com/14050 Andy Freeman wrote: > It is a bit ugly but here is an initial port of the Shoulda ActiveRecord > macros: > > http://gist.github.com/14050 > > I did not try running ALL of the macros, but most of them. Before going > too far with it, I would appreciate some recommendations as to how to > improve the flow. The Shoulda version has a different feel to it since > the assertions cause the code to die early. Whereas the RSpec > conversion I did mostly wrap each should call in its own it block. > > Thanks for the help! I learned a lot from this exercise! > > Andy -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Wed Oct 1 10:23:02 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 01 Oct 2008 07:23:02 -0700 Subject: [rspec-users] How do BOTH these examples pass? In-Reply-To: <9B111CEF-8628-41B6-AF85-CA1B686F7F9D@patchspace.co.uk> (Ashley Moran's message of "Wed\, 1 Oct 2008 14\:26\:06 +0100") References: <7D40733D-FB29-4C94-9C13-4598FD93FD26@patchspace.co.uk> <57a815bf0810010611s643765a8u8394a5d46021afd6@mail.gmail.com> <9B111CEF-8628-41B6-AF85-CA1B686F7F9D@patchspace.co.uk> Message-ID: Ashley Moran writes: > *does* pass the specs, both the one that says parse should be called, > and the one that say it shouldn't! But why? I'm prepared to admit > I'm just missing something really really really obvious (it happens > often), but how can: > > it "should attempt to parse the RSS" do > ::RSS::Parser.should_receive(:parse) > @rss_reader.rss > end > > it "should not attempt to parse the RSS" do > ::RSS::Parser.should_not_receive(:parse) > @rss_reader.rss > end > > both pass, under any circumstances? I think this may be a bug that I introduced recently. Fortunately I also think someone already wrote a patch :) Check out http://rspec.lighthouseapp.com/projects/5645/tickets/548 and see if it solves your problem. Pat From pergesu at gmail.com Wed Oct 1 10:29:51 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 01 Oct 2008 07:29:51 -0700 Subject: [rspec-users] Spec for 'an array should not include an item' In-Reply-To: (Neil Cauldwell's message of "Wed\, 1 Oct 2008 09\:33\:21 +0200") References: <23fca9046d582f17fa4e61119eb45334@ruby-forum.com> <48E2767F.5090406@benmabey.com> Message-ID: Neil Cauldwell writes: > Is my stubbing breaking this? I hope not because Thinking SPhinx isn't > determining the scope of the search in relation to the 'active' state of > the users; the search is built on top of a named scope on the User > model; > > # GET /searches/people > # GET /searches/people.xml > def people > @results = User.active.search params[:search], :page => > params[:page], :per_page => 15 > > respond_to do |format| > format.html > format.xml { render :xml => @results } > end > end > > Cheers You're stubbing User.search, but you don't actually call it. search ends up being called on a named_scope collection proxy. So I think that this is using the real implementation of both active and search. I never saw you post a failure message, so I'm not actually sure what problem you're having. A failure message would be helpful. Pat From ashley.moran at patchspace.co.uk Wed Oct 1 10:40:06 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 1 Oct 2008 15:40:06 +0100 Subject: [rspec-users] How do BOTH these examples pass? In-Reply-To: References: <7D40733D-FB29-4C94-9C13-4598FD93FD26@patchspace.co.uk> <57a815bf0810010611s643765a8u8394a5d46021afd6@mail.gmail.com> <9B111CEF-8628-41B6-AF85-CA1B686F7F9D@patchspace.co.uk> Message-ID: On 1 Oct 2008, at 15:23, Pat Maddox wrote: > I think this may be a bug that I introduced recently. Fortunately I > also think someone already wrote a patch :) Check out > http://rspec.lighthouseapp.com/projects/5645/tickets/548 and see if it > solves your problem. Aha! That's it. That's a pretty bad bug though! Will there be an RSpec 1.1.6 soon to patch it? Thanks Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From mark at mwilden.com Wed Oct 1 10:54:08 2008 From: mark at mwilden.com (Mark Wilden) Date: Wed, 1 Oct 2008 07:54:08 -0700 Subject: [rspec-users] Associations should be private In-Reply-To: <57c63afe0810010611o626510b2tee027aa8b2301d67@mail.gmail.com> References: <10BF8774-5F69-444E-B442-B40F472EFFBB@patchspace.co.uk> <57c63afe0810010611o626510b2tee027aa8b2301d67@mail.gmail.com> Message-ID: <3c30da400810010754n287c4dbap5ab777120ae6e7@mail.gmail.com> On Wed, Oct 1, 2008 at 6:11 AM, David Chelimsky wrote: > It's been a while since I've taken a look at it, but Luke Redpath has > a plugin called Demeter's Revenge > (http://plugins.code.lukeredpath.co.uk/browser/demeters_revenge/trunk) > that actually manages this all for you by adding methods like > team.add_player that wrap chains like team.players.add. It's a year > old and I don't know if it works w/ the latest rails updates or not. > See, this is what I don't get about Demeter. By adding delegators, you might trick someone into thinking that you're not playing with other objects' parts, but really you still are. Does Demeter just mean mechanically adding a level of indirection? For example, in the case under discussion, even with Demetering, you're _still_ going to get back a proxy object, and end up with the same problem, aren't you? ///ark P.S. Of course, controlling access to data (especially changing it) can often be a Good Thing. But that's just a general principle and applies to your own data as well as to your data's data's data. Nothing Demetery there. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed Oct 1 11:08:59 2008 From: lists at ruby-forum.com (Neil Cauldwell) Date: Wed, 1 Oct 2008 17:08:59 +0200 Subject: [rspec-users] Spec for 'an array should not include an item' In-Reply-To: References: <23fca9046d582f17fa4e61119eb45334@ruby-forum.com> <48E2767F.5090406@benmabey.com> Message-ID: <86c46d539fd3c5b1dffa266491e43015@ruby-forum.com> Pat Maddox wrote: > Neil Cauldwell writes: >> >> respond_to do |format| >> format.html >> format.xml { render :xml => @results } >> end >> end >> >> Cheers > > You're stubbing User.search, but you don't actually call it. search > ends up being called on a named_scope collection proxy. So I think that > this is using the real implementation of both active and search. > > I never saw you post a failure message, so I'm not actually sure what > problem you're having. A failure message would be helpful. > > Pat Pat, I don't see an error message but, I was expecting this to fail (which it doesn't, therefore suggesting the spec is broken); it "should not include any inactive users in an assigned array of user results " do do_get assigns[:results].should_not include(users) end I was under the assumption that the above spec checks that we don't have any of the users fixtures in the :results. The spec uses this; def do_get ThinkingSphinx::Search.stub!(:search).and_return(users) get :people, :search => "bob" end ...so shouldn't the spec fail if we're returning all the users fixtures when assigns[:results].should_not include(users)? Thanks -- Posted via http://www.ruby-forum.com/. From cflipse at gmail.com Wed Oct 1 11:11:28 2008 From: cflipse at gmail.com (Chris Flipse) Date: Wed, 1 Oct 2008 11:11:28 -0400 Subject: [rspec-users] Cucumber: please make "gem install aslakhellesoy-cucumber" or "gem install cucumber" work again In-Reply-To: <8d961d900809301420u181fc7c4scda243099b88f0ae@mail.gmail.com> References: <810a540e0809151335o79378b71le965d2024c07a731@mail.gmail.com> <71A9DF99-4B20-4493-97C2-686E11F2119D@lukemelia.com> <0758DC51-1E6D-45F3-B9B8-CD301F1738F7@tiggerpalace.com> <8d961d900809301420u181fc7c4scda243099b88f0ae@mail.gmail.com> Message-ID: On Tue, Sep 30, 2008 at 5:20 PM, aslak hellesoy wrote: > On Tue, Sep 30, 2008 at 9:02 PM, Evan David Light > wrote: > > Subject says most of it. I'd love to use Cucumber in my project but I > need > > to be able to install it in a Rails app and by a particular version > number. > > > > You can do that with git pull and git checkout. Would it help if > detailed instructions were posted to the wiki? > That gets you whatever the latest is, which is good if you want to live on edge. I'm behind a firewall, and living on edge isn't necessarily a good option. Would it be too much to ask if you could tag the repo when you jump to a new release, like David is doing with rspec? Github lets you download a snapshot of the repo by tags, and I just build the gems from that, and toss them up into a behind-the-firewall gem server, and let everyone gem install from there. It's a bit harder with cucumber, because I'm not sure where the "released, stable" point is ... > > > I forked it and struggled with getting GitHub gems deployer to behave > > itself. > > > > Maybe a "canonical" version can be kept and updated in RubyForge > > occasionally because of occasional gem problems with GitHub? > > > > Yes, I'll probably do that soon. GitHub fails to build the gem every > time for me (not occasionally). > http://logicalawesome.lighthouseapp.com/projects/8570-github/tickets/945 > > Aslak > > > Evan > > _______________________________________________ > > 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 > -- // anything worth taking seriously is worth making fun of // http://blog.devcaffeine.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From aslak.hellesoy at gmail.com Wed Oct 1 11:20:32 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 1 Oct 2008 17:20:32 +0200 Subject: [rspec-users] Cucumber: please make "gem install aslakhellesoy-cucumber" or "gem install cucumber" work again In-Reply-To: References: <810a540e0809151335o79378b71le965d2024c07a731@mail.gmail.com> <71A9DF99-4B20-4493-97C2-686E11F2119D@lukemelia.com> <0758DC51-1E6D-45F3-B9B8-CD301F1738F7@tiggerpalace.com> <8d961d900809301420u181fc7c4scda243099b88f0ae@mail.gmail.com> Message-ID: <8d961d900810010820q5d5e085end082911ddd21dba5@mail.gmail.com> On Wed, Oct 1, 2008 at 5:11 PM, Chris Flipse wrote: > On Tue, Sep 30, 2008 at 5:20 PM, aslak hellesoy > wrote: >> >> On Tue, Sep 30, 2008 at 9:02 PM, Evan David Light >> wrote: >> > Subject says most of it. I'd love to use Cucumber in my project but I >> > need >> > to be able to install it in a Rails app and by a particular version >> > number. >> > >> >> You can do that with git pull and git checkout. Would it help if >> detailed instructions were posted to the wiki? > > That gets you whatever the latest is, which is good if you want to live on > edge. I'm behind a firewall, and living on edge isn't necessarily a good > option. Have you tried this? export http_proxy=http://yourproxy:yourport git clone http://github.com/aslakhellesoy/cucumber git checkout SHA-of-the-rev-you-want > Would it be too much to ask if you could tag the repo when you jump > to a new release, like David is doing with rspec? > Absolutely - I'll tag it when there is a release. And push a gem to RubyForge. But there hasn't been one yet. > Github lets you download a snapshot of the repo by tags, and I just build > the gems from that, and toss them up into a behind-the-firewall gem server, > and let everyone gem install from there. It's a bit harder with cucumber, > because I'm not sure where the "released, stable" point is ... > It's whenever I feel like it and have some spare time :-) Probably within the next week or so. Aslak >> >> > I forked it and struggled with getting GitHub gems deployer to behave >> > itself. >> > >> > Maybe a "canonical" version can be kept and updated in RubyForge >> > occasionally because of occasional gem problems with GitHub? >> > >> >> Yes, I'll probably do that soon. GitHub fails to build the gem every >> time for me (not occasionally). >> http://logicalawesome.lighthouseapp.com/projects/8570-github/tickets/945 >> >> Aslak >> >> > Evan >> > _______________________________________________ >> > 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 > > > > -- > // anything worth taking seriously is worth making fun of > // http://blog.devcaffeine.com/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From cflipse at gmail.com Wed Oct 1 11:30:41 2008 From: cflipse at gmail.com (Chris Flipse) Date: Wed, 1 Oct 2008 11:30:41 -0400 Subject: [rspec-users] Cucumber: please make "gem install aslakhellesoy-cucumber" or "gem install cucumber" work again In-Reply-To: <8d961d900810010820q5d5e085end082911ddd21dba5@mail.gmail.com> References: <810a540e0809151335o79378b71le965d2024c07a731@mail.gmail.com> <71A9DF99-4B20-4493-97C2-686E11F2119D@lukemelia.com> <0758DC51-1E6D-45F3-B9B8-CD301F1738F7@tiggerpalace.com> <8d961d900809301420u181fc7c4scda243099b88f0ae@mail.gmail.com> <8d961d900810010820q5d5e085end082911ddd21dba5@mail.gmail.com> Message-ID: On Wed, Oct 1, 2008 at 11:20 AM, aslak hellesoy wrote: > On Wed, Oct 1, 2008 at 5:11 PM, Chris Flipse wrote: > > On Tue, Sep 30, 2008 at 5:20 PM, aslak hellesoy < > aslak.hellesoy at gmail.com> > > wrote: > >> > >> On Tue, Sep 30, 2008 at 9:02 PM, Evan David Light > >> wrote: > >> > Subject says most of it. I'd love to use Cucumber in my project but I > >> > need > >> > to be able to install it in a Rails app and by a particular version > >> > number. > >> > > >> > >> You can do that with git pull and git checkout. Would it help if > >> detailed instructions were posted to the wiki? > > > > That gets you whatever the latest is, which is good if you want to live > on > > edge. I'm behind a firewall, and living on edge isn't necessarily a good > > option. > > Have you tried this? > > export http_proxy=http://yourproxy:yourport > git clone http://github.com/aslakhellesoy/cucumber > > git checkout SHA-of-the-rev-you-want > That'd work if I had git on the windows machine that can actually access the internet. Unfortunately, I don't, and I won't. It's pretty tightly locked down. "firewall" is a bad term, because it implies there's an actual path to the internet. There isn't, at least not from the place I do actual work. Have to burn files and copy them. Virus paranoia and such. ... yes, it's a pain in the ass. > > Would it be too much to ask if you could tag the repo when you jump > > to a new release, like David is doing with rspec? > > > > Absolutely - I'll tag it when there is a release. And push a gem to > RubyForge. But there hasn't been one yet. Ah. I'd been going on the assumption that the occasional gem version bumps were signifying real checkpoints. If not, then, I havn't yet been burned by pulling down head once a week or so -- // anything worth taking seriously is worth making fun of // http://blog.devcaffeine.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Wed Oct 1 11:32:53 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 01 Oct 2008 08:32:53 -0700 Subject: [rspec-users] How do BOTH these examples pass? In-Reply-To: (Ashley Moran's message of "Wed\, 1 Oct 2008 15\:40\:06 +0100") References: <7D40733D-FB29-4C94-9C13-4598FD93FD26@patchspace.co.uk> <57a815bf0810010611s643765a8u8394a5d46021afd6@mail.gmail.com> <9B111CEF-8628-41B6-AF85-CA1B686F7F9D@patchspace.co.uk> Message-ID: Ashley Moran writes: > On 1 Oct 2008, at 15:23, Pat Maddox wrote: > >> I think this may be a bug that I introduced recently. Fortunately I >> also think someone already wrote a patch :) Check out >> http://rspec.lighthouseapp.com/projects/5645/tickets/548 and see if it >> solves your problem. > > Aha! That's it. > > That's a pretty bad bug though! Will there be an RSpec 1.1.6 soon to > patch it? I don't know, we'll late David determine how critical it is and whether it warrants a new release. fwiw, I've run that code against several rails apps and open source projects with no problems. So while I agree that it's a nasty little bug, I'm not sure how often it comes up in practice? Maybe we can knock out a bunch of outstanding bug reports in the next couple days and push out 1.1.6. Pat From aslak.hellesoy at gmail.com Wed Oct 1 11:53:53 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 1 Oct 2008 17:53:53 +0200 Subject: [rspec-users] Cucumber: please make "gem install aslakhellesoy-cucumber" or "gem install cucumber" work again In-Reply-To: References: <810a540e0809151335o79378b71le965d2024c07a731@mail.gmail.com> <71A9DF99-4B20-4493-97C2-686E11F2119D@lukemelia.com> <0758DC51-1E6D-45F3-B9B8-CD301F1738F7@tiggerpalace.com> <8d961d900809301420u181fc7c4scda243099b88f0ae@mail.gmail.com> <8d961d900810010820q5d5e085end082911ddd21dba5@mail.gmail.com> Message-ID: <8d961d900810010853h4b9cf8c5w7ec902cfa2a4511e@mail.gmail.com> On Wed, Oct 1, 2008 at 5:30 PM, Chris Flipse wrote: > > > On Wed, Oct 1, 2008 at 11:20 AM, aslak hellesoy > wrote: >> >> On Wed, Oct 1, 2008 at 5:11 PM, Chris Flipse wrote: >> > On Tue, Sep 30, 2008 at 5:20 PM, aslak hellesoy >> > >> > wrote: >> >> >> >> On Tue, Sep 30, 2008 at 9:02 PM, Evan David Light >> >> wrote: >> >> > Subject says most of it. I'd love to use Cucumber in my project but >> >> > I >> >> > need >> >> > to be able to install it in a Rails app and by a particular version >> >> > number. >> >> > >> >> >> >> You can do that with git pull and git checkout. Would it help if >> >> detailed instructions were posted to the wiki? >> > >> > That gets you whatever the latest is, which is good if you want to live >> > on >> > edge. I'm behind a firewall, and living on edge isn't necessarily a >> > good >> > option. >> >> Have you tried this? >> >> export http_proxy=http://yourproxy:yourport >> git clone http://github.com/aslakhellesoy/cucumber >> >> git checkout SHA-of-the-rev-you-want > > That'd work if I had git on the windows machine that can actually access the > internet. Unfortunately, I don't, and I won't. It's pretty tightly locked > down. "firewall" is a bad term, because it implies there's an actual path > to the internet. There isn't, at least not from the place I do actual > work. Have to burn files and copy them. Virus paranoia and such. > > ... yes, it's a pain in the ass. > I can feel your pain. I have worked for this kind of clients. Insurance and government. They don't seem to understand how big an impediment this is. And that people who need to work around this (us) will do it anyway to get work done. It's just stupid. >> >> > Would it be too much to ask if you could tag the repo when you jump >> > to a new release, like David is doing with rspec? >> > >> >> Absolutely - I'll tag it when there is a release. And push a gem to >> RubyForge. But there hasn't been one yet. > > Ah. I'd been going on the assumption that the occasional gem version bumps > were signifying real checkpoints. If not, then, I havn't yet been burned by > pulling down head once a week or so No, actually - it's been me trying to convince the GitHub pixies to build the gem. To no avail. Aslak > -- > // anything worth taking seriously is worth making fun of > // http://blog.devcaffeine.com/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben at benmabey.com Wed Oct 1 11:54:25 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 01 Oct 2008 09:54:25 -0600 Subject: [rspec-users] [ANN] Cucumber Textmate Bundle In-Reply-To: References: <48D14F7A.4@benmabey.com> <8d961d900809171321vb0a2a3bjdafdb98dadc896da@mail.gmail.com> <48D16F15.50503@benmabey.com> <8d961d900809171413v7692a915p111fbee2a6619858@mail.gmail.com> <48D17818.3010503@benmabey.com> <8d961d900809171542x422f6838s36219a7c981a216b@mail.gmail.com> <48D18F55.7080904@benmabey.com> <48D2AF3C.6080600@shopwatch.org> Message-ID: <48E39D31.60501@benmabey.com> Matt Wynne wrote: > Is it possible to rename the project maybe? I know you can have dots > in the name - e.g. http://github.com/thoughtworks/cruisecontrol.rb > though I think I may have heard this was a restriction that was lifted > relatively recently. I'll look into it. I named it that because all of the other textmate bundles on github that I'ved used have followed the same convention. That makes sense if, like you said, they just relaxed the naming rules. Thanks, Ben From aslak.hellesoy at gmail.com Wed Oct 1 11:57:38 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 1 Oct 2008 17:57:38 +0200 Subject: [rspec-users] [ANN] Cucumber Textmate Bundle In-Reply-To: <48E39D31.60501@benmabey.com> References: <48D14F7A.4@benmabey.com> <8d961d900809171321vb0a2a3bjdafdb98dadc896da@mail.gmail.com> <48D16F15.50503@benmabey.com> <8d961d900809171413v7692a915p111fbee2a6619858@mail.gmail.com> <48D17818.3010503@benmabey.com> <8d961d900809171542x422f6838s36219a7c981a216b@mail.gmail.com> <48D18F55.7080904@benmabey.com> <48D2AF3C.6080600@shopwatch.org> <48E39D31.60501@benmabey.com> Message-ID: <8d961d900810010857h9375da2gba39a229076f169c@mail.gmail.com> On Wed, Oct 1, 2008 at 5:54 PM, Ben Mabey wrote: > Matt Wynne wrote: >> >> Is it possible to rename the project maybe? I know you can have dots in >> the name - e.g. http://github.com/thoughtworks/cruisecontrol.rb though I >> think I may have heard this was a restriction that was lifted relatively >> recently. > > I'll look into it. I named it that because all of the other textmate > bundles on github that I'ved used have followed the same convention. That > makes sense if, like you said, they just relaxed the naming rules. > I would guess the source of the problem is that Rails doesn't like dots in resource names. Because in Rails a dot is an alias mechanism for the HTTP Accepts header. (/blah and /blah.xml for instance) Aslak > Thanks, > Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at tiggerpalace.com Wed Oct 1 12:05:31 2008 From: lists at tiggerpalace.com (Evan Light) Date: Wed, 1 Oct 2008 12:05:31 -0400 Subject: [rspec-users] Cucumber: please make "gem install aslakhellesoy-cucumber" or "gem install cucumber" work again In-Reply-To: <8d961d900810010853h4b9cf8c5w7ec902cfa2a4511e@mail.gmail.com> References: <810a540e0809151335o79378b71le965d2024c07a731@mail.gmail.com> <71A9DF99-4B20-4493-97C2-686E11F2119D@lukemelia.com> <0758DC51-1E6D-45F3-B9B8-CD301F1738F7@tiggerpalace.com> <8d961d900809301420u181fc7c4scda243099b88f0ae@mail.gmail.com> <8d961d900810010820q5d5e085end082911ddd21dba5@mail.gmail.com> <8d961d900810010853h4b9cf8c5w7ec902cfa2a4511e@mail.gmail.com> Message-ID: On Oct 1, 2008, at 11:53 AM, aslak hellesoy wrote: > No, actually - it's been me trying to convince the GitHub pixies to > build the gem. To no avail. Not to belabor a point overly but hence my suggestion to put a gem on RubyForge. I'm dying for a stable version of Cucumber -- even if it's only "stable" ;-) Evan From ashley.moran at patchspace.co.uk Wed Oct 1 12:09:06 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 1 Oct 2008 17:09:06 +0100 Subject: [rspec-users] Cucumber: please make "gem install aslakhellesoy-cucumber" or "gem install cucumber" work again In-Reply-To: <8d961d900810010853h4b9cf8c5w7ec902cfa2a4511e@mail.gmail.com> References: <810a540e0809151335o79378b71le965d2024c07a731@mail.gmail.com> <71A9DF99-4B20-4493-97C2-686E11F2119D@lukemelia.com> <0758DC51-1E6D-45F3-B9B8-CD301F1738F7@tiggerpalace.com> <8d961d900809301420u181fc7c4scda243099b88f0ae@mail.gmail.com> <8d961d900810010820q5d5e085end082911ddd21dba5@mail.gmail.com> <8d961d900810010853h4b9cf8c5w7ec902cfa2a4511e@mail.gmail.com> Message-ID: On 1 Oct 2008, at 16:53, aslak hellesoy wrote: > No, actually - it's been me trying to convince the GitHub pixies to > build the gem. To no avail. Have we witnessed the birth of Pixie Driven Development this week? I feel like we need PixieSpec and Pixie Stories next :) Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From pergesu at gmail.com Wed Oct 1 12:10:03 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 01 Oct 2008 09:10:03 -0700 Subject: [rspec-users] Spec for 'an array should not include an item' In-Reply-To: <86c46d539fd3c5b1dffa266491e43015@ruby-forum.com> (Neil Cauldwell's message of "Wed\, 1 Oct 2008 17\:08\:59 +0200") References: <23fca9046d582f17fa4e61119eb45334@ruby-forum.com> <48E2767F.5090406@benmabey.com> <86c46d539fd3c5b1dffa266491e43015@ruby-forum.com> Message-ID: Neil Cauldwell writes: > Pat Maddox wrote: >> Neil Cauldwell writes: >>> >>> respond_to do |format| >>> format.html >>> format.xml { render :xml => @results } >>> end >>> end >>> >>> Cheers >> >> You're stubbing User.search, but you don't actually call it. search >> ends up being called on a named_scope collection proxy. So I think that >> this is using the real implementation of both active and search. >> >> I never saw you post a failure message, so I'm not actually sure what >> problem you're having. A failure message would be helpful. >> >> Pat > > Pat, I don't see an error message but, I was expecting this to fail > (which it doesn't, therefore suggesting the spec is broken); > > it "should not include any inactive users in an assigned array of user > results " do > do_get > assigns[:results].should_not include(users) > end > > I was under the assumption that the above spec checks that we don't have > any of the users fixtures in the :results. The spec uses this; > > def do_get > ThinkingSphinx::Search.stub!(:search).and_return(users) > get :people, :search => "bob" > end > > ...so shouldn't the spec fail if we're returning all the users fixtures > when assigns[:results].should_not include(users)? > > Thanks Well, flip the should_not to should and it ought to fail, and give you a bit more info. Or print the stuff out. I imagine what's ultimately happening is something along the lines of [1,2,3].should_not include([1,2,3]) which is true. [1,2,3] is not an element of the array [1,2,3]. I used a simplified example here but it applies equally to an array of User objects. Anyway, what kind of debugging have you done to see what objects you're actually dealing with? I think doing "p assigns[:results]" and "p users" will help point you in the right direction... Pat From lists at tiggerpalace.com Wed Oct 1 12:32:52 2008 From: lists at tiggerpalace.com (Evan Light) Date: Wed, 1 Oct 2008 12:32:52 -0400 Subject: [rspec-users] Cucumber: please make "gem install aslakhellesoy-cucumber" or "gem install cucumber" work again In-Reply-To: References: <810a540e0809151335o79378b71le965d2024c07a731@mail.gmail.com> <71A9DF99-4B20-4493-97C2-686E11F2119D@lukemelia.com> <0758DC51-1E6D-45F3-B9B8-CD301F1738F7@tiggerpalace.com> <8d961d900809301420u181fc7c4scda243099b88f0ae@mail.gmail.com> <8d961d900810010820q5d5e085end082911ddd21dba5@mail.gmail.com> <8d961d900810010853h4b9cf8c5w7ec902cfa2a4511e@mail.gmail.com> Message-ID: On Oct 1, 2008, at 12:09 PM, Ashley Moran wrote: > > On 1 Oct 2008, at 16:53, aslak hellesoy wrote: > >> No, actually - it's been me trying to convince the GitHub pixies to >> build the gem. To no avail. > > Have we witnessed the birth of Pixie Driven Development this week? > I feel like we need PixieSpec and Pixie Stories next :) > No, I think it's a matter of "GitHub Driven Deployment" -- or non- Deployment as the case would be. :-/ Evan From luislavena at gmail.com Wed Oct 1 13:03:04 2008 From: luislavena at gmail.com (Luis Lavena) Date: Wed, 1 Oct 2008 14:03:04 -0300 Subject: [rspec-users] Cucumber: please make "gem install aslakhellesoy-cucumber" or "gem install cucumber" work again In-Reply-To: References: <810a540e0809151335o79378b71le965d2024c07a731@mail.gmail.com> <71A9DF99-4B20-4493-97C2-686E11F2119D@lukemelia.com> <0758DC51-1E6D-45F3-B9B8-CD301F1738F7@tiggerpalace.com> <8d961d900809301420u181fc7c4scda243099b88f0ae@mail.gmail.com> <8d961d900810010820q5d5e085end082911ddd21dba5@mail.gmail.com> Message-ID: <71166b3b0810011003x39203caer58a7abe323290633@mail.gmail.com> On Wed, Oct 1, 2008 at 12:30 PM, Chris Flipse wrote: > > > On Wed, Oct 1, 2008 at 11:20 AM, aslak hellesoy > wrote: >> >> On Wed, Oct 1, 2008 at 5:11 PM, Chris Flipse wrote: >> > On Tue, Sep 30, 2008 at 5:20 PM, aslak hellesoy >> > >> > wrote: >> >> >> >> On Tue, Sep 30, 2008 at 9:02 PM, Evan David Light >> >> wrote: >> >> > Subject says most of it. I'd love to use Cucumber in my project but >> >> > I >> >> > need >> >> > to be able to install it in a Rails app and by a particular version >> >> > number. >> >> > >> >> >> >> You can do that with git pull and git checkout. Would it help if >> >> detailed instructions were posted to the wiki? >> > >> > That gets you whatever the latest is, which is good if you want to live >> > on >> > edge. I'm behind a firewall, and living on edge isn't necessarily a >> > good >> > option. >> >> Have you tried this? >> >> export http_proxy=http://yourproxy:yourport >> git clone http://github.com/aslakhellesoy/cucumber >> >> git checkout SHA-of-the-rev-you-want > > That'd work if I had git on the windows machine that can actually access the > internet. Unfortunately, I don't, and I won't. It's pretty tightly locked > down. "firewall" is a bad term, because it implies there's an actual path > to the internet. There isn't, at least not from the place I do actual > work. Have to burn files and copy them. Virus paranoia and such. > > ... yes, it's a pain in the ass. > I hear ya brother, same here, luckily not anymore. you can do the following (at home): gem search cucumber --remote --source http://gems.github.com gem fetch cucumber --source http://gems.github.com This will put the .gem file in the folder you performed the task for you to easily copy to your locked down environment :-D >> >> > Would it be too much to ask if you could tag the repo when you jump >> > to a new release, like David is doing with rspec? >> > >> >> Absolutely - I'll tag it when there is a release. And push a gem to >> RubyForge. But there hasn't been one yet. > > Ah. I'd been going on the assumption that the occasional gem version bumps > were signifying real checkpoints. If not, then, I havn't yet been burned by > pulling down head once a week or so Github gems are only updated when the cucumber.gemspec file is updated. -- 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 dchelimsky at gmail.com Wed Oct 1 13:39:32 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 1 Oct 2008 12:39:32 -0500 Subject: [rspec-users] How do BOTH these examples pass? In-Reply-To: References: <7D40733D-FB29-4C94-9C13-4598FD93FD26@patchspace.co.uk> <57a815bf0810010611s643765a8u8394a5d46021afd6@mail.gmail.com> <9B111CEF-8628-41B6-AF85-CA1B686F7F9D@patchspace.co.uk> Message-ID: <57c63afe0810011039o4f1b2d9eic7ff741e7299eb57@mail.gmail.com> On Wed, Oct 1, 2008 at 10:32 AM, Pat Maddox wrote: > Ashley Moran writes: > >> On 1 Oct 2008, at 15:23, Pat Maddox wrote: >> >>> I think this may be a bug that I introduced recently. Fortunately I >>> also think someone already wrote a patch :) Check out >>> http://rspec.lighthouseapp.com/projects/5645/tickets/548 and see if it >>> solves your problem. >> >> Aha! That's it. >> >> That's a pretty bad bug though! Will there be an RSpec 1.1.6 soon to >> patch it? > > I don't know, we'll late David determine how critical it is and whether > it warrants a new release. > > fwiw, I've run that code against several rails apps and open source > projects with no problems. So while I agree that it's a nasty little > bug, I'm not sure how often it comes up in practice? Maybe we can knock > out a bunch of outstanding bug reports in the next couple days and push > out 1.1.6. There were a couple of other bugs introduced in 1.1.5 so I would like to get out a 1.1.6 very soon. Probably over the weekend if we can get them all fixed. Cheers, David > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben at benmabey.com Wed Oct 1 14:12:04 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 01 Oct 2008 12:12:04 -0600 Subject: [rspec-users] [ANN] Cucumber Textmate Bundle In-Reply-To: <48E39D31.60501@benmabey.com> References: <48D14F7A.4@benmabey.com> <8d961d900809171321vb0a2a3bjdafdb98dadc896da@mail.gmail.com> <48D16F15.50503@benmabey.com> <8d961d900809171413v7692a915p111fbee2a6619858@mail.gmail.com> <48D17818.3010503@benmabey.com> <8d961d900809171542x422f6838s36219a7c981a216b@mail.gmail.com> <48D18F55.7080904@benmabey.com> <48D2AF3C.6080600@shopwatch.org> <48E39D31.60501@benmabey.com> Message-ID: <48E3BD74.6020804@benmabey.com> Ben Mabey wrote: > Matt Wynne wrote: >> Is it possible to rename the project maybe? I know you can have dots >> in the name - e.g. http://github.com/thoughtworks/cruisecontrol.rb >> though I think I may have heard this was a restriction that was >> lifted relatively recently. > > I'll look into it. I named it that because all of the other textmate > bundles on github that I'ved used have followed the same convention. > That makes sense if, like you said, they just relaxed the naming rules. > > Thanks, > Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users I can rename it but by doing so I may mess up all of the forks and everyone would need to update their clone url in .git/config. What do you think, is it worth changing the name? -Ben From lattam at mac.com Wed Oct 1 14:29:54 2008 From: lattam at mac.com (Michael Latta) Date: Wed, 01 Oct 2008 11:29:54 -0700 Subject: [rspec-users] Associations should be private In-Reply-To: <3c30da400810010754n287c4dbap5ab777120ae6e7@mail.gmail.com> References: <10BF8774-5F69-444E-B442-B40F472EFFBB@patchspace.co.uk> <57c63afe0810010611o626510b2tee027aa8b2301d67@mail.gmail.com> <3c30da400810010754n287c4dbap5ab777120ae6e7@mail.gmail.com> Message-ID: <1A9B3F7B-9160-445D-8136-AA6343BD0FDF@mac.com> The point is to never assume the structure of another object, but to let it decide that. So you never get A.B.C you always use a method on A to do the work. You get a lot more methods on A but the structure underneath can change without a ripple effect. For example if you had 2 associations that got merged into one you can still support the same method interface and then filter the one association to appear to be 2. Or you can merge 2 into what appears to be one, etc. Using plugins that do this too simply removes some of the value. If they always map the underlying structure you have not gained much. But, if you can specify the intended interface and then map that to the underlying structure you have gained much more. That of course requires a more sophisticated (complex) plug-in and some added work to explicitly define the interface. The whole convention over configuration means that the underlying structure tends to be exposed more than good software engineering practice would advise, but it works because most of the time the cost to fix a change is actually lower in Ruby than the cost of preventing the change. Michael On Oct 1, 2008, at 7:54 AM, Mark Wilden wrote: > On Wed, Oct 1, 2008 at 6:11 AM, David Chelimsky > wrote: > > It's been a while since I've taken a look at it, but Luke Redpath has > a plugin called Demeter's Revenge > (http://plugins.code.lukeredpath.co.uk/browser/demeters_revenge/trunk) > that actually manages this all for you by adding methods like > team.add_player that wrap chains like team.players.add. It's a year > old and I don't know if it works w/ the latest rails updates or not. > > See, this is what I don't get about Demeter. By adding delegators, > you might trick someone into thinking that you're not playing with > other objects' parts, but really you still are. Does Demeter just > mean mechanically adding a level of indirection? > > For example, in the case under discussion, even with Demetering, > you're _still_ going to get back a proxy object, and end up with the > same problem, aren't you? > > ///ark > > P.S. Of course, controlling access to data (especially changing it) > can often be a Good Thing. But that's just a general principle and > applies to your own data as well as to your data's data's data. > Nothing Demetery there. > _______________________________________________ > 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 aslak.hellesoy at gmail.com Wed Oct 1 14:50:49 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 1 Oct 2008 20:50:49 +0200 Subject: [rspec-users] Cucumber: please make "gem install aslakhellesoy-cucumber" or "gem install cucumber" work again In-Reply-To: <71166b3b0810011003x39203caer58a7abe323290633@mail.gmail.com> References: <810a540e0809151335o79378b71le965d2024c07a731@mail.gmail.com> <71A9DF99-4B20-4493-97C2-686E11F2119D@lukemelia.com> <0758DC51-1E6D-45F3-B9B8-CD301F1738F7@tiggerpalace.com> <8d961d900809301420u181fc7c4scda243099b88f0ae@mail.gmail.com> <8d961d900810010820q5d5e085end082911ddd21dba5@mail.gmail.com> <71166b3b0810011003x39203caer58a7abe323290633@mail.gmail.com> Message-ID: <8d961d900810011150n7be11bfcj715026b57838e066@mail.gmail.com> On Wed, Oct 1, 2008 at 7:03 PM, Luis Lavena wrote: > On Wed, Oct 1, 2008 at 12:30 PM, Chris Flipse wrote: >> >> >> On Wed, Oct 1, 2008 at 11:20 AM, aslak hellesoy >> wrote: >>> >>> On Wed, Oct 1, 2008 at 5:11 PM, Chris Flipse wrote: >>> > On Tue, Sep 30, 2008 at 5:20 PM, aslak hellesoy >>> > >>> > wrote: >>> >> >>> >> On Tue, Sep 30, 2008 at 9:02 PM, Evan David Light >>> >> wrote: >>> >> > Subject says most of it. I'd love to use Cucumber in my project but >>> >> > I >>> >> > need >>> >> > to be able to install it in a Rails app and by a particular version >>> >> > number. >>> >> > >>> >> >>> >> You can do that with git pull and git checkout. Would it help if >>> >> detailed instructions were posted to the wiki? >>> > >>> > That gets you whatever the latest is, which is good if you want to live >>> > on >>> > edge. I'm behind a firewall, and living on edge isn't necessarily a >>> > good >>> > option. >>> >>> Have you tried this? >>> >>> export http_proxy=http://yourproxy:yourport >>> git clone http://github.com/aslakhellesoy/cucumber >>> >>> git checkout SHA-of-the-rev-you-want >> >> That'd work if I had git on the windows machine that can actually access the >> internet. Unfortunately, I don't, and I won't. It's pretty tightly locked >> down. "firewall" is a bad term, because it implies there's an actual path >> to the internet. There isn't, at least not from the place I do actual >> work. Have to burn files and copy them. Virus paranoia and such. >> >> ... yes, it's a pain in the ass. >> > > I hear ya brother, same here, luckily not anymore. > > you can do the following (at home): > > gem search cucumber --remote --source http://gems.github.com > > gem fetch cucumber --source http://gems.github.com > > This will put the .gem file in the folder you performed the task for > you to easily copy to your locked down environment :-D > >>> >>> > Would it be too much to ask if you could tag the repo when you jump >>> > to a new release, like David is doing with rspec? >>> > >>> >>> Absolutely - I'll tag it when there is a release. And push a gem to >>> RubyForge. But there hasn't been one yet. >> >> Ah. I'd been going on the assumption that the occasional gem version bumps >> were signifying real checkpoints. If not, then, I havn't yet been burned by >> pulling down head once a week or so > > Github gems are only updated when the cucumber.gemspec file is updated. > Yes, but only in theory: http://logicalawesome.lighthouseapp.com/projects/8570-github/tickets/945 Does anyone want Cucumber gems? No? Yes? Anyone? OK I HEARD YOU! :-) http://rubyforge.org/frs/?group_id=797 Just chill till it rsyncs around. Install docs are updated: http://github.com/aslakhellesoy/cucumber/wikis/home Aslak > -- > 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 matt at mattwynne.net Wed Oct 1 14:52:20 2008 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 1 Oct 2008 19:52:20 +0100 Subject: [rspec-users] [ANN] Cucumber Textmate Bundle In-Reply-To: <48E3BD74.6020804@benmabey.com> References: <48D14F7A.4@benmabey.com> <8d961d900809171321vb0a2a3bjdafdb98dadc896da@mail.gmail.com> <48D16F15.50503@benmabey.com> <8d961d900809171413v7692a915p111fbee2a6619858@mail.gmail.com> <48D17818.3010503@benmabey.com> <8d961d900809171542x422f6838s36219a7c981a216b@mail.gmail.com> <48D18F55.7080904@benmabey.com> <48D2AF3C.6080600@shopwatch.org> <48E39D31.60501@benmabey.com> <48E3BD74.6020804@benmabey.com> Message-ID: How about - can you somehow fork it to the new name, thereby keeping the old things up and running but blazing a new and shiny train from henceforth? Otherwise, it's gotta be a no, hasn't it? On 1 Oct 2008, at 19:12, Ben Mabey wrote: > Ben Mabey wrote: >> Matt Wynne wrote: >>> Is it possible to rename the project maybe? I know you can have >>> dots in the name - e.g. http://github.com/thoughtworks/cruisecontrol.rb >>> though I think I may have heard this was a restriction that was >>> lifted relatively recently. >> >> I'll look into it. I named it that because all of the other >> textmate bundles on github that I'ved used have followed the same >> convention. That makes sense if, like you said, they just relaxed >> the naming rules. >> >> Thanks, >> Ben >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > I can rename it but by doing so I may mess up all of the forks and > everyone would need to update their clone url in .git/config. What > do you think, is it worth changing the name? > > -Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Wed Oct 1 15:17:30 2008 From: lists at ruby-forum.com (Neil Cauldwell) Date: Wed, 1 Oct 2008 21:17:30 +0200 Subject: [rspec-users] Spec for 'an array should not include an item' In-Reply-To: References: <23fca9046d582f17fa4e61119eb45334@ruby-forum.com> <48E2767F.5090406@benmabey.com> <86c46d539fd3c5b1dffa266491e43015@ruby-forum.com> Message-ID: <80e33c00244430283649bc4970e66220@ruby-forum.com> Pat Maddox wrote: > Neil Cauldwell writes: > >>> >> (which it doesn't, therefore suggesting the spec is broken); >> def do_get >> ThinkingSphinx::Search.stub!(:search).and_return(users) >> get :people, :search => "bob" >> end >> >> ...so shouldn't the spec fail if we're returning all the users fixtures >> when assigns[:results].should_not include(users)? >> >> Thanks > > Well, flip the should_not to should and it ought to fail, and give you a > bit more info. Or print the stuff out. I imagine what's ultimately > happening is something along the lines of > > [1,2,3].should_not include([1,2,3]) > > which is true. [1,2,3] is not an element of the array [1,2,3]. I used > a simplified example here but it applies equally to an array of User > objects. > > Anyway, what kind of debugging have you done to see what objects you're > actually dealing with? I think doing "p assigns[:results]" and "p > users" will help point you in the right direction... > > Pat Thanks Pat. That really helps. If I do the flip (please ignore the spec description); it "should not include any inactive users in an assigned array of user results " do do_get assigns[:results].should include(users) end Rspec tells me; should not include any inactive users in an assigned array of user results expected [] to include [] I was expecting :results to contain something, otherwise, wouldn't this spec fail (?), or is nil different to empty?; it "should assign an array of user results" do do_get assigns[:results].should_not be_nil end ...so I'm one step closer but I'm now a little confused by the other specs. I haven't done any debugging, I haven't come across any debugging techniques within Rspec before - please treat me as an absolute newbie to this. -- Posted via http://www.ruby-forum.com/. From mark at mwilden.com Wed Oct 1 15:17:41 2008 From: mark at mwilden.com (Mark Wilden) Date: Wed, 1 Oct 2008 12:17:41 -0700 Subject: [rspec-users] Associations should be private In-Reply-To: <1A9B3F7B-9160-445D-8136-AA6343BD0FDF@mac.com> References: <10BF8774-5F69-444E-B442-B40F472EFFBB@patchspace.co.uk> <57c63afe0810010611o626510b2tee027aa8b2301d67@mail.gmail.com> <3c30da400810010754n287c4dbap5ab777120ae6e7@mail.gmail.com> <1A9B3F7B-9160-445D-8136-AA6343BD0FDF@mac.com> Message-ID: <3c30da400810011217h7cc367d5y5fcec1d13150ac62@mail.gmail.com> On Wed, Oct 1, 2008 at 11:29 AM, Michael Latta wrote: > The point is to never assume the structure of another object, but to let it > decide that. So you never get A.B.C you always use a method on A to do the > work. You get a lot more methods on A but the structure underneath can > change without a ripple effect. > Sounds like future-proofing to me. In the case of libraries, that can be a good thing. For application code, it flies in the face of YAGNI. Using plugins that do this too simply removes some of the value. If they > always map the underlying structure you have not gained much. > Yes, it was the "auto-demetering" that I was mainly responding to. The whole convention over configuration means that the underlying structure > tends to be exposed more than good software engineering practice would > advise, but it works because most of the time the cost to fix a change is > actually lower in Ruby than the cost of preventing the change. > "Embrace change" - Kent Beck. The whole white book is predicated on what you just pointed out about Rails. But here I go again, off the RSpec track... ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at tiggerpalace.com Wed Oct 1 16:27:31 2008 From: lists at tiggerpalace.com (Evan Light) Date: Wed, 1 Oct 2008 16:27:31 -0400 Subject: [rspec-users] Cucumber: please make "gem install aslakhellesoy-cucumber" or "gem install cucumber" work again In-Reply-To: <8d961d900810011150n7be11bfcj715026b57838e066@mail.gmail.com> References: <810a540e0809151335o79378b71le965d2024c07a731@mail.gmail.com> <71A9DF99-4B20-4493-97C2-686E11F2119D@lukemelia.com> <0758DC51-1E6D-45F3-B9B8-CD301F1738F7@tiggerpalace.com> <8d961d900809301420u181fc7c4scda243099b88f0ae@mail.gmail.com> <8d961d900810010820q5d5e085end082911ddd21dba5@mail.gmail.com> <71166b3b0810011003x39203caer58a7abe323290633@mail.gmail.com> <8d961d900810011150n7be11bfcj715026b57838e066@mail.gmail.com> Message-ID: <5C8218AF-4BE3-4DC1-B693-5FC784A7ACB4@tiggerpalace.com> On Oct 1, 2008, at 2:50 PM, aslak hellesoy wrote: > Does anyone want Cucumber gems? No? Yes? Anyone? OK I HEARD YOU! :-) > > http://rubyforge.org/frs/?group_id=797 > > Just chill till it rsyncs around. Install docs are updated: > http://github.com/aslakhellesoy/cucumber/wikis/home Thank you! -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Wed Oct 1 16:35:15 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 01 Oct 2008 13:35:15 -0700 Subject: [rspec-users] Spec for 'an array should not include an item' In-Reply-To: <80e33c00244430283649bc4970e66220@ruby-forum.com> (Neil Cauldwell's message of "Wed\, 1 Oct 2008 21\:17\:30 +0200") References: <23fca9046d582f17fa4e61119eb45334@ruby-forum.com> <48E2767F.5090406@benmabey.com> <86c46d539fd3c5b1dffa266491e43015@ruby-forum.com> <80e33c00244430283649bc4970e66220@ruby-forum.com> Message-ID: Neil Cauldwell writes: > Pat Maddox wrote: >> Neil Cauldwell writes: >> >>>> >>> (which it doesn't, therefore suggesting the spec is broken); >>> def do_get >>> ThinkingSphinx::Search.stub!(:search).and_return(users) >>> get :people, :search => "bob" >>> end >>> >>> ...so shouldn't the spec fail if we're returning all the users fixtures >>> when assigns[:results].should_not include(users)? >>> >>> Thanks >> >> Well, flip the should_not to should and it ought to fail, and give you a >> bit more info. Or print the stuff out. I imagine what's ultimately >> happening is something along the lines of >> >> [1,2,3].should_not include([1,2,3]) >> >> which is true. [1,2,3] is not an element of the array [1,2,3]. I used >> a simplified example here but it applies equally to an array of User >> objects. >> >> Anyway, what kind of debugging have you done to see what objects you're >> actually dealing with? I think doing "p assigns[:results]" and "p >> users" will help point you in the right direction... >> >> Pat > > Thanks Pat. That really helps. If I do the flip (please ignore the spec > description); > > it "should not include any inactive users in an assigned array of user > results " do > do_get > assigns[:results].should include(users) > end > > Rspec tells me; > > should not include any inactive users in an assigned array of user > results > expected [] to include [] > > I was expecting :results to contain something, otherwise, wouldn't this > spec fail (?), or is nil different to empty?; > > it "should assign an array of user results" do > do_get > assigns[:results].should_not be_nil > end > > ...so I'm one step closer but I'm now a little confused by the other > specs. They are different. This is similar to the example I posted before: [].should include([]) that will fail... [[]].should include([]) will pass. Do you see the difference? One of them is an empty array, and one of them is an array containing a single element (which is itself an empty array). nil and [] are not equivalent in Ruby. Anyway, I'm pretty convinced that your stubbing isn't working at all. You can verify this by changing ThinkingSphinx::Search.stub!(:search).and_return(users) to ThinkingSphinx::Search.stub!(:search).and_raise("boom!") If your stubbed method is being called then it'll raise an error, but I suspect it's not. As far as the fixtures stuff, I'm afraid I can't help much there. I think rails db fixtures are the devil and so have managed to put them completely out of my consciousness. Pat From lists at ruby-forum.com Wed Oct 1 17:08:45 2008 From: lists at ruby-forum.com (Neil Cauldwell) Date: Wed, 1 Oct 2008 23:08:45 +0200 Subject: [rspec-users] Spec for 'an array should not include an item' In-Reply-To: References: <23fca9046d582f17fa4e61119eb45334@ruby-forum.com> <48E2767F.5090406@benmabey.com> <86c46d539fd3c5b1dffa266491e43015@ruby-forum.com> <80e33c00244430283649bc4970e66220@ruby-forum.com> Message-ID: <0be6b260e2742b33bc3aee3bc008b8bd@ruby-forum.com> Pat Maddox wrote: > Neil Cauldwell writes: > >>>> ...so shouldn't the spec fail if we're returning all the users fixtures >>> which is true. [1,2,3] is not an element of the array [1,2,3]. I used >> description); >> results >> ...so I'm one step closer but I'm now a little confused by the other >> specs. > > They are different. This is similar to the example I posted before: > [].should include([]) > > that will fail... > [[]].should include([]) > > will pass. Do you see the difference? One of them is an empty array, > and one of them is an array containing a single element (which is itself > an empty array). > > nil and [] are not equivalent in Ruby. > > Anyway, I'm pretty convinced that your stubbing isn't working at all. > You can verify this by changing > ThinkingSphinx::Search.stub!(:search).and_return(users) > to > ThinkingSphinx::Search.stub!(:search).and_raise("boom!") > > If your stubbed method is being called then it'll raise an error, but I > suspect it's not. > > As far as the fixtures stuff, I'm afraid I can't help much there. I > think rails db fixtures are the devil and so have managed to put them > completely out of my consciousness. > > Pat I just tried the raise; ThinkingSphinx::Search.stub!(:search).and_raise("BOOM") and; RSpec Results 36 examples, 5 failures Finished in 1.338815 seconds SearchesController handling GET /searches/people should be successful BOOM should render people template BOOM I should have left my mac by now as my brain is pretty much fried by this of night, but, unless I'm mistaken, that means the stub is working, right? I would like to move away from fixtures but it'll have to wait for now. I just want to collect the users fixtures through the :people action in the searches controller and to make sure that a certain user fixture isn't among the return users...I didn't think it would so tricky! Thanks, though. -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Wed Oct 1 17:13:50 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 01 Oct 2008 14:13:50 -0700 Subject: [rspec-users] Spec for 'an array should not include an item' In-Reply-To: <0be6b260e2742b33bc3aee3bc008b8bd@ruby-forum.com> (Neil Cauldwell's message of "Wed\, 1 Oct 2008 23\:08\:45 +0200") References: <23fca9046d582f17fa4e61119eb45334@ruby-forum.com> <48E2767F.5090406@benmabey.com> <86c46d539fd3c5b1dffa266491e43015@ruby-forum.com> <80e33c00244430283649bc4970e66220@ruby-forum.com> <0be6b260e2742b33bc3aee3bc008b8bd@ruby-forum.com> Message-ID: Neil Cauldwell writes: > Pat Maddox wrote: >> Neil Cauldwell writes: >> >>>>> ...so shouldn't the spec fail if we're returning all the users fixtures >>>> which is true. [1,2,3] is not an element of the array [1,2,3]. I used >>> description); >>> results >>> ...so I'm one step closer but I'm now a little confused by the other >>> specs. >> >> They are different. This is similar to the example I posted before: >> [].should include([]) >> >> that will fail... >> [[]].should include([]) >> >> will pass. Do you see the difference? One of them is an empty array, >> and one of them is an array containing a single element (which is itself >> an empty array). >> >> nil and [] are not equivalent in Ruby. >> >> Anyway, I'm pretty convinced that your stubbing isn't working at all. >> You can verify this by changing >> ThinkingSphinx::Search.stub!(:search).and_return(users) >> to >> ThinkingSphinx::Search.stub!(:search).and_raise("boom!") >> >> If your stubbed method is being called then it'll raise an error, but I >> suspect it's not. >> >> As far as the fixtures stuff, I'm afraid I can't help much there. I >> think rails db fixtures are the devil and so have managed to put them >> completely out of my consciousness. >> >> Pat > > > I just tried the raise; > > ThinkingSphinx::Search.stub!(:search).and_raise("BOOM") > > and; > > RSpec Results > 36 examples, 5 failures > Finished in 1.338815 seconds > > SearchesController handling GET /searches/people > should be successful > BOOM > > should render people template > BOOM > > I should have left my mac by now as my brain is pretty much fried by > this of night, but, unless I'm mistaken, that means the stub is working, > right? Yes, so, that's progress :) Pat From yar.dmitriev at gmail.com Wed Oct 1 17:59:11 2008 From: yar.dmitriev at gmail.com (Yar Dmitriev) Date: Wed, 1 Oct 2008 14:59:11 -0700 (PDT) Subject: [rspec-users] Story runner has session limit of 4000 bytes, like CookieStore Message-ID: <7003c5a7-5f8d-4739-8897-fe561c018901@q9g2000hsb.googlegroups.com> This could be intentional, but still surprising. Say, we are using ActiveRecord session store, according to the setting in environment.rb: config.action_controller.session_store = :active_record_store When controller writes 5000 bytes to the session: session[:foo] = "a" * 5000 The application works correctly (because there is no 4K limit for the ActiveRecord store), but story runner raises the error: CGI::Session::CookieStore::CookieOverflow I spent an hour trying to understand how it worked there, without success. Ended up writing custom, more efficient marshalling code for one of my classes. Being able to fit sessions into CookieStore is useful by itself, of course. From ashley.moran at patchspace.co.uk Wed Oct 1 21:07:12 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 2 Oct 2008 02:07:12 +0100 Subject: [rspec-users] How do BOTH these examples pass? In-Reply-To: <57c63afe0810011039o4f1b2d9eic7ff741e7299eb57@mail.gmail.com> References: <7D40733D-FB29-4C94-9C13-4598FD93FD26@patchspace.co.uk> <57a815bf0810010611s643765a8u8394a5d46021afd6@mail.gmail.com> <9B111CEF-8628-41B6-AF85-CA1B686F7F9D@patchspace.co.uk> <57c63afe0810011039o4f1b2d9eic7ff741e7299eb57@mail.gmail.com> Message-ID: <3544E766-CD0D-46E4-AA35-A5B574528856@patchspace.co.uk> On Oct 01, 2008, at 6:39 pm, David Chelimsky wrote: > There were a couple of other bugs introduced in 1.1.5 so I would like > to get out a 1.1.6 very soon. Probably over the weekend if we can get > them all fixed. Cool thanks David. It's not such an issue now I know how to work round it but it was a nasty gotcha. Cheers Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Wed Oct 1 21:22:49 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 2 Oct 2008 02:22:49 +0100 Subject: [rspec-users] Associations should be private In-Reply-To: <3c30da400810011217h7cc367d5y5fcec1d13150ac62@mail.gmail.com> References: <10BF8774-5F69-444E-B442-B40F472EFFBB@patchspace.co.uk> <57c63afe0810010611o626510b2tee027aa8b2301d67@mail.gmail.com> <3c30da400810010754n287c4dbap5ab777120ae6e7@mail.gmail.com> <1A9B3F7B-9160-445D-8136-AA6343BD0FDF@mac.com> <3c30da400810011217h7cc367d5y5fcec1d13150ac62@mail.gmail.com> Message-ID: <83ECBE02-B044-418C-996F-81D3FDDC9E40@patchspace.co.uk> On Oct 01, 2008, at 8:17 pm, Mark Wilden wrote: > Sounds like future-proofing to me. In the case of libraries, that > can be a good thing. For application code, it flies in the face of > YAGNI. Actually I don't think that's a YAGNI. You need *an* interface to your models, the question is whether to build one that litters trainwrecks through your code, or one that is internally refactorable. Or, you could "take the first Demeter bullet" and use associations until they cause a breakage... > The whole convention over configuration means that the underlying > structure tends to be exposed more than good software engineering > practice would advise, but it works because most of the time the > cost to fix a change is actually lower in Ruby than the cost of > preventing the change. ... which takes advantage of this property of Ruby. > "Embrace change" - Kent Beck. The whole white book is predicated on > what you just pointed out about Rails. You meant to say Ruby there, right? ;o) Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From mark at mwilden.com Wed Oct 1 21:38:47 2008 From: mark at mwilden.com (Mark Wilden) Date: Wed, 1 Oct 2008 18:38:47 -0700 Subject: [rspec-users] Associations should be private In-Reply-To: <83ECBE02-B044-418C-996F-81D3FDDC9E40@patchspace.co.uk> References: <10BF8774-5F69-444E-B442-B40F472EFFBB@patchspace.co.uk> <57c63afe0810010611o626510b2tee027aa8b2301d67@mail.gmail.com> <3c30da400810010754n287c4dbap5ab777120ae6e7@mail.gmail.com> <1A9B3F7B-9160-445D-8136-AA6343BD0FDF@mac.com> <3c30da400810011217h7cc367d5y5fcec1d13150ac62@mail.gmail.com> <83ECBE02-B044-418C-996F-81D3FDDC9E40@patchspace.co.uk> Message-ID: <3c30da400810011838o20f9b6ffy18137459c2cf1bb0@mail.gmail.com> On Wed, Oct 1, 2008 at 6:22 PM, Ashley Moran wrote: > > On Oct 01, 2008, at 8:17 pm, Mark Wilden wrote: > > Sounds like future-proofing to me. In the case of libraries, that can be a >> good thing. For application code, it flies in the face of YAGNI. >> > > Actually I don't think that's a YAGNI. You need *an* interface to your > models, the question is whether to build one that litters trainwrecks > through your code, or one that is internally refactorable. > ActiveRecord already provides an interface to your models. If you add on to that because it might things easier in the future, that's where I call "YAGNI." It reminds me of a book on Java by a well-known author which said that you should declare an interface for every class, because it will make things easier if you need to change the implementation. He's absolutely right, of course. However, I say that there are too many things that need doing right now - right this second - to waste time on what may or may not happen in the future. Put another way, what are you willing to give up in order to add this layer? "Litters trainwrecks," BTW, I believe begs the question. > Embrace change" - Kent Beck. The whole white book is predicated on what you >> just pointed out about Rails. >> > > You meant to say Ruby there, right? ;o) I was responding to the "convention over configuration" remark. But yeah, Ruby certainly does make changing stuff easier than many other languages. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Wed Oct 1 21:53:36 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 01 Oct 2008 18:53:36 -0700 Subject: [rspec-users] How do BOTH these examples pass? In-Reply-To: <3544E766-CD0D-46E4-AA35-A5B574528856@patchspace.co.uk> (Ashley Moran's message of "Thu\, 2 Oct 2008 02\:07\:12 +0100") References: <7D40733D-FB29-4C94-9C13-4598FD93FD26@patchspace.co.uk> <57a815bf0810010611s643765a8u8394a5d46021afd6@mail.gmail.com> <9B111CEF-8628-41B6-AF85-CA1B686F7F9D@patchspace.co.uk> <57c63afe0810011039o4f1b2d9eic7ff741e7299eb57@mail.gmail.com> <3544E766-CD0D-46E4-AA35-A5B574528856@patchspace.co.uk> Message-ID: Ashley Moran writes: > On Oct 01, 2008, at 6:39 pm, David Chelimsky wrote: > >> There were a couple of other bugs introduced in 1.1.5 so I would like >> to get out a 1.1.6 very soon. Probably over the weekend if we can get >> them all fixed. > > > Cool thanks David. > > It's not such an issue now I know how to work round it but it was a > nasty gotcha. btw this is applied in trunk, so if you haven't applied the patch yourself yet then you can just update to the latest code and you're set. Pat From dchelimsky at gmail.com Wed Oct 1 22:06:56 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 1 Oct 2008 21:06:56 -0500 Subject: [rspec-users] Associations should be private In-Reply-To: <3c30da400810011838o20f9b6ffy18137459c2cf1bb0@mail.gmail.com> References: <10BF8774-5F69-444E-B442-B40F472EFFBB@patchspace.co.uk> <57c63afe0810010611o626510b2tee027aa8b2301d67@mail.gmail.com> <3c30da400810010754n287c4dbap5ab777120ae6e7@mail.gmail.com> <1A9B3F7B-9160-445D-8136-AA6343BD0FDF@mac.com> <3c30da400810011217h7cc367d5y5fcec1d13150ac62@mail.gmail.com> <83ECBE02-B044-418C-996F-81D3FDDC9E40@patchspace.co.uk> <3c30da400810011838o20f9b6ffy18137459c2cf1bb0@mail.gmail.com> Message-ID: <57c63afe0810011906m2047b00u44e505fbad8b5507@mail.gmail.com> On Wed, Oct 1, 2008 at 8:38 PM, Mark Wilden wrote: > On Wed, Oct 1, 2008 at 6:22 PM, Ashley Moran > wrote: >> >> On Oct 01, 2008, at 8:17 pm, Mark Wilden wrote: >> >>> Sounds like future-proofing to me. In the case of libraries, that can be >>> a good thing. For application code, it flies in the face of YAGNI. >> >> Actually I don't think that's a YAGNI. You need *an* interface to your >> models, the question is whether to build one that litters trainwrecks >> through your code, or one that is internally refactorable. > > ActiveRecord already provides an interface to your models. If you add on to > that because it might things easier in the future, that's where I call > "YAGNI." It reminds me of a book on Java by a well-known author which said > that you should declare an interface for every class, because it will make > things easier if you need to change the implementation. He's absolutely > right, of course. Au contraire! You're comparing apples and cadillacs here. Demeter is about encapsulation. Interfaces are about abstraction and structure. Completely different animals. Unless you're developing an library that will be directly consumed outside your team, the cost of not adding the Java Interface until the need for an abstraction arises is very low. Finding all of the instantiations of the class is easy, and converting them to us a factory call is easy too. Tracking down all of the trainwrecks in a system is not quite so simple. First of all, they are not guaranteed to look the same: trainer.animals.dogs.first vs t = trainer a = trainer.animals d = trainer.dogs dog = dogs[0] So when the design seems to want to categorize animals into domestic and wild, the first call has to be changed to trainer.animals.domestic.dogs.first. Good luck tracking down the second example. Principles/guidelines like YAGNI and DRY and even the ever-threatening-sounding Law of Demeter are NOT LAWS. They are indicators. Red flag triggers. Red flags are *warnings*, not *errors*. In this case, we've got two of these in direct conflict with each other, so which one wins? Gotta look at the costs and benefits of each and proceed wisely and *in context*, not with a face stained with kool-aide. FWIW, David > However, I say that there are too many things that need doing right now - > right this second - to waste time on what may or may not happen in the > future. Put another way, what are you willing to give up in order to add > this layer? > > "Litters trainwrecks," BTW, I believe begs the question. >>> >>> Embrace change" - Kent Beck. The whole white book is predicated on what >>> you just pointed out about Rails. >> >> You meant to say Ruby there, right? ;o) > > I was responding to the "convention over configuration" remark. But yeah, > Ruby certainly does make changing stuff easier than many other languages. > > ///ark > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Wed Oct 1 22:10:01 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 2 Oct 2008 03:10:01 +0100 Subject: [rspec-users] Associations should be private In-Reply-To: <3c30da400810011838o20f9b6ffy18137459c2cf1bb0@mail.gmail.com> References: <10BF8774-5F69-444E-B442-B40F472EFFBB@patchspace.co.uk> <57c63afe0810010611o626510b2tee027aa8b2301d67@mail.gmail.com> <3c30da400810010754n287c4dbap5ab777120ae6e7@mail.gmail.com> <1A9B3F7B-9160-445D-8136-AA6343BD0FDF@mac.com> <3c30da400810011217h7cc367d5y5fcec1d13150ac62@mail.gmail.com> <83ECBE02-B044-418C-996F-81D3FDDC9E40@patchspace.co.uk> <3c30da400810011838o20f9b6ffy18137459c2cf1bb0@mail.gmail.com> Message-ID: <87C533CD-F0AB-40C8-BE04-1EBB5DAF2F10@patchspace.co.uk> On Oct 02, 2008, at 2:38 am, Mark Wilden wrote: > However, I say that there are too many things that need doing right > now - right this second - to waste time on what may or may not > happen in the future. Put another way, what are you willing to give > up in order to add this layer? Perhaps I was a bit terse (and opaque) with the comment "take the first. What I meant was that, yes, I see your point, and it's fine to do it this way if it's a risk you're willing to take. But if it causes you problems, you should always fix the software, not constantly refactor associations. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Wed Oct 1 23:30:53 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 2 Oct 2008 04:30:53 +0100 Subject: [rspec-users] Slides from my talk on Cucumber + Celerity + RSpec tonight Message-ID: Hi all Just ran a session known as a "huddle" in GeekUp terms. GeekUp[1] is a group of monthly events in North West England. The Sheffield one starts with a huddle every month, which is intended to have more audience participation than a pure talk. For this one, I got an unsuspecting audience (of developers, designers, business analysts, project managers, and itinerant alcoholics stumbling past our end of the bar) writing user stories and fighting^H^H^H^H^H discussing in a civilised manner which was most important. Second half was a tech demo, and they all loved Cucumber. So hats off to everyone involved in RSpec Stories and to Aslak for its recent re- incarnation, it had a room full of geeks going "I want that for my PHP code!". Slides are on my blog[2] for anyone that wants a flick through, or to find out more about what went on. Ashley [1] http://geekup.org/ [2] http://aviewfromafar.net/2008/10/2/geekup-sheffield-vi-from-specification-to-success -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Wed Oct 1 23:31:22 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 2 Oct 2008 04:31:22 +0100 Subject: [rspec-users] How do BOTH these examples pass? In-Reply-To: References: <7D40733D-FB29-4C94-9C13-4598FD93FD26@patchspace.co.uk> <57a815bf0810010611s643765a8u8394a5d46021afd6@mail.gmail.com> <9B111CEF-8628-41B6-AF85-CA1B686F7F9D@patchspace.co.uk> <57c63afe0810011039o4f1b2d9eic7ff741e7299eb57@mail.gmail.com> <3544E766-CD0D-46E4-AA35-A5B574528856@patchspace.co.uk> Message-ID: <3D82FC41-893F-49D5-BF79-07153C5BAC80@patchspace.co.uk> On Oct 02, 2008, at 2:53 am, Pat Maddox wrote: > btw this is applied in trunk, so if you haven't applied the patch > yourself yet then you can just update to the latest code and you're > set. Cool thanks for the info Pat Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From aslak.hellesoy at gmail.com Thu Oct 2 01:07:15 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 2 Oct 2008 07:07:15 +0200 Subject: [rspec-users] Slides from my talk on Cucumber + Celerity + RSpec tonight In-Reply-To: References: Message-ID: <8d961d900810012207j3cb5e2e1vcb1054fe9c17173d@mail.gmail.com> On Thu, Oct 2, 2008 at 5:30 AM, Ashley Moran wrote: > Hi all > > Just ran a session known as a "huddle" in GeekUp terms. GeekUp[1] is a > group of monthly events in North West England. The Sheffield one starts > with a huddle every month, which is intended to have more audience > participation than a pure talk. For this one, I got an unsuspecting > audience (of developers, designers, business analysts, project managers, and > itinerant alcoholics stumbling past our end of the bar) writing user stories > and fighting^H^H^H^H^H discussing in a civilised manner which was most > important. > > Second half was a tech demo, and they all loved Cucumber. So hats off to > everyone involved in RSpec Stories and to Aslak for its recent > re-incarnation, it had a room full of geeks going "I want that for my PHP > code!". > > Slides are on my blog[2] for anyone that wants a flick through, or to find > out more about what went on. > Thanks a lot for sharing Ashley. This is a really good introduction to BDD. Short enough to be graspable for people who are new to it - long enough to be really valuable. I can imagine you had a good time! I really like that you started off by talking about business value (So that). The two sentences about acceptance criteria (verifiable by humans and discrete for machines) really nail down what BDD acceptance criteria are about. I'm ccing the Celerity crew - they also live here in Oslo. BTW - if you are developing an open source conference organising tool, please let me know. I've written two that suck (one in Rails, one as a Radiant extension) and I want something good for the next conference I organise. Cheers, Aslak > Ashley > > [1] http://geekup.org/ > [2] > http://aviewfromafar.net/2008/10/2/geekup-sheffield-vi-from-specification-to-success > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Thu Oct 2 06:30:54 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 2 Oct 2008 11:30:54 +0100 Subject: [rspec-users] Slides from my talk on Cucumber + Celerity + RSpec tonight In-Reply-To: <8d961d900810012207j3cb5e2e1vcb1054fe9c17173d@mail.gmail.com> References: <8d961d900810012207j3cb5e2e1vcb1054fe9c17173d@mail.gmail.com> Message-ID: <35F23CFF-E533-4E49-B4B3-32DA71CF7096@patchspace.co.uk> On Oct 02, 2008, at 6:07 am, aslak hellesoy wrote: > Thanks a lot for sharing Ashley. > > This is a really good introduction to BDD. Short enough to be > graspable for people who are new to it - long enough to be really > valuable. I can imagine you had a good time! I really like that you > started off by talking about business value (So that). The two > sentences about acceptance criteria (verifiable by humans and discrete > for machines) really nail down what BDD acceptance criteria are about. Hi Aslak Yeah! It was fun. The interactivity worked better than I expected. I think it made it sink in too. One thing I've learnt about stories is they are very academic until users see real software that implements them. > I'm ccing the Celerity crew - they also live here in Oslo. I haven't used it extensively but I'm already a big fan of it. One guy last night said that Cucumber + Celerity has completely renewed his interest in automated acceptance testing, after giving up on FIT and Selenium. He says it's also the excuse he needs to learn Ruby (he does all C-pound right now), or at least enough to write Cucumber files. And another guy grabbed the slides off me so he could get JRuby set up for a new team to use today! The new killer app (combo) for Ruby? :o) > BTW - if you are developing an open source conference organising tool, > please let me know. I've written two that suck (one in Rails, one as a > Radiant extension) and I want something good for the next conference I > organise. We're doing it specifically for BarCamp Sheffield 2008 (end of November) at first, but I'd love to expand it. When's your next conference likely to be? Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From lists at ruby-forum.com Thu Oct 2 07:27:30 2008 From: lists at ruby-forum.com (Juanma Cervera) Date: Thu, 2 Oct 2008 13:27:30 +0200 Subject: [rspec-users] Setting Request headers with webrat In-Reply-To: References: <3BBB5CAC-AB61-4DCE-93E9-B6036B2C09C2@mattwynne.net> <1cb6196ba4b95463395bab2b4b24797f@ruby-forum.com> Message-ID: <91dbbef758c3fc92dbaae64bbba66aac@ruby-forum.com> Well, Matt was right. I have not got the solution for my problems. The problem is that I can't set the headers with click_button or visits. If anyone knows how to set the request headers with these methods of webrat, this would be very helpful. Thank yus Matt Wynne wrote: > Cool. > > Be aware that you're by-passing webrat by using the post method - > that's one of the 'raw' rails calls that webrat wraps up in its > elegant set of methods. > > It may be that you can pass this same hash to clicks_button but I > don't know - you'd have to check the webrat source. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Oct 2 10:00:36 2008 From: lists at ruby-forum.com (=?utf-8?Q?R=c3=a9mi_Gagnon?=) Date: Thu, 2 Oct 2008 16:00:36 +0200 Subject: [rspec-users] autospec is not picking latest changes In-Reply-To: <944EFAEC-DB2D-48B8-9DD2-BED943E64176@mattwynne.net> References: <71166b3b0809161218s49ebc480k8aab512529251091@mail.gmail.com> <71166b3b0809161220o4686e6f9oe61ed2954b1eb954@mail.gmail.com> <944EFAEC-DB2D-48B8-9DD2-BED943E64176@mattwynne.net> Message-ID: <305b6429cc978d2a31093968e7917b28@ruby-forum.com> On my side I updated the rspec gem and rspec_rails plugins and now autotest and autospec are not working anymore. autospec does nothing at all and autotest starts but does not execute the specs I'm on windows vista. R?mi Matt Wynne wrote: > try script/autospec instead - I always use that these days. not sure > what the difference is. > On 16 Sep 2008, at 20:20, Luis Lavena wrote: > >>> >> >> - >> 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 > > cheers, > Matt > ---- > http://blog.mattwynne.net > http://songkick.com > > In case you wondered: The opinions expressed in this email are my own > and do not necessarily reflect the views of any former, current or > future employers of mine. -- Posted via http://www.ruby-forum.com/. From mark at mwilden.com Thu Oct 2 13:01:47 2008 From: mark at mwilden.com (Mark Wilden) Date: Thu, 2 Oct 2008 10:01:47 -0700 Subject: [rspec-users] Associations should be private In-Reply-To: <57c63afe0810011906m2047b00u44e505fbad8b5507@mail.gmail.com> References: <10BF8774-5F69-444E-B442-B40F472EFFBB@patchspace.co.uk> <57c63afe0810010611o626510b2tee027aa8b2301d67@mail.gmail.com> <3c30da400810010754n287c4dbap5ab777120ae6e7@mail.gmail.com> <1A9B3F7B-9160-445D-8136-AA6343BD0FDF@mac.com> <3c30da400810011217h7cc367d5y5fcec1d13150ac62@mail.gmail.com> <83ECBE02-B044-418C-996F-81D3FDDC9E40@patchspace.co.uk> <3c30da400810011838o20f9b6ffy18137459c2cf1bb0@mail.gmail.com> <57c63afe0810011906m2047b00u44e505fbad8b5507@mail.gmail.com> Message-ID: <3c30da400810021001l3859606aw39cd74dd704634bb@mail.gmail.com> On Wed, Oct 1, 2008 at 7:06 PM, David Chelimsky wrote: > > Au contraire! You're comparing apples and cadillacs here. Demeter is > about encapsulation. Interfaces are about abstraction and structure. > Completely different animals. Interfaces in that Java book and LOD in this topic were being supported by arguments of the form "if you need to change things in the future..." There are some practitioners for whom that's a valid argument, and there are others for whom it's an anti-argument. YAGNI is the latter. Doesn't make it right, but it does provide a way to evaluate each of these animals. > Tracking down all of the trainwrecks in a system is not quite so > simple. First of all, they are not guaranteed to look the same: > > trainer.animals.dogs.first > > vs > > t = trainer > a = trainer.animals > d = trainer.dogs > dog = dogs[0] > > So when the design seems to want to categorize animals into domestic > and wild, the first call has to be changed to > trainer.animals.domestic.dogs.first. Good luck tracking down the > second example In a statically-typed language, this would be trivial. In a dynamically-typed language using BDD, this would be caught by tests. > Principles/guidelines like YAGNI and DRY and even the > ever-threatening-sounding Law of Demeter are NOT LAWS. They are > indicators. Red flag triggers. Red flags are *warnings*, not *errors*. > We agree on that. See my recent post: http://www.nabble.com/Prepare-for-newbie-ness-to19516110.html#a19542377 In this case, we've got two of these in direct conflict with each > other, so which one wins? Gotta look at the costs and benefits of each > and proceed wisely and *in context* I feel that YAGNI and LOD are at different levels of granularity. I use YAGNI and TSTTCPW in my daily life (which isn't to say that I always think they're the best approach). So I approach problems using those principles as my base. I don't ask myself a hundred times a day whether I should use a goto statement - I use structured programming as my base. Same with OOP, readable code, lack of commenting, etc. You can't approach everything de novo. So I apply YAGNI unless I see a compelling reason not to. The reason is that the "costs and benefits" of any approach are usually not obvious - especially when talking about the future. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Thu Oct 2 18:20:57 2008 From: lists at ruby-forum.com (Peter Degen-Portnoy) Date: Fri, 3 Oct 2008 00:20:57 +0200 Subject: [rspec-users] Need to clear Mocha expectation? Message-ID: <16f3627bd0241e78308013039ad35366@ruby-forum.com> Hi Folks, I have a problem that I have been able to isolate into a small test application. The problem seems to be that when I set an expectation on the number of times a method will be called in one describe block, the expectation is still set in a different describe block. My understanding was that RSpec restored the state of objects and the end of a test, which I interpreted as the end of a describe block (seeing that the scope of the expectation ended). Here is my test application: : rails rspecproblem : cd rspecproblem : script/generate rspec_model Contest contest_name:string status:integer contest_series_id:integer : script/generate rspec_model ContestSeries series_name:string : rake db:migrate : autotest I edited contest.rb and set the following: class Contest < ActiveRecord::Base belongs_to :contest_series def getSeries ContestSeries.find(contest_series_id) end end I edited contest_series.rb and added the has_many statement: class ContestSeries < ActiveRecord::Base has_many :contests end I then created the following spec file in spec/models/contest_spec.rb that can be found at http://pastie.org/283936 The summary of the test spec is that there are two describe blocks. The first block creates a Contest and assigns it to a ContestSeries. For the sake of the example, I then call ContestSeries.find(). The second block sets an expectation on ContestSeries that the find method will be called only once. This causes the following error: Mocha::ExpectationError in 'Contest should demonstrate that the stub is not cleared' unexpected invocation: ContestSeries(id: integer, series_name: string, created_at: datetime, updated_at: datetime).find(1) satisfied expectations: - expected exactly once, already invoked once: ContestSeries(id: integer, series_name: string, created_at: datetime, updated_at: datetime).find(1000) Playing around with some variations, I have found that if I change the code in line 24 to: ContestSeries.expects(:find).at_least(1) then no error is generated, but this isn't really what I want. I want to be confident that the "getSeries" call (which is really only a simplification of the actual code) gets the correct ContestSeries. Have I misunderstood how to use this stubbing behavior? Is there a way to correctly clear such expectations in an after block? Many thanks, Peter -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Oct 2 18:53:47 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 2 Oct 2008 17:53:47 -0500 Subject: [rspec-users] Need to clear Mocha expectation? In-Reply-To: <16f3627bd0241e78308013039ad35366@ruby-forum.com> References: <16f3627bd0241e78308013039ad35366@ruby-forum.com> Message-ID: <57c63afe0810021553t3d127451oe3d31cbad8482316@mail.gmail.com> On Thu, Oct 2, 2008 at 5:20 PM, Peter Degen-Portnoy wrote: > Hi Folks, > > I have a problem that I have been able to isolate into a small test > application. > > The problem seems to be that when I set an expectation on the number of > times a method will be called in one describe block, the expectation is > still set in a different describe block. My understanding was that > RSpec restored the state of objects and the end of a test, which I > interpreted as the end of a describe block (seeing that the scope of the > expectation ended). > > Here is my test application: > : rails rspecproblem > : cd rspecproblem > > : script/generate rspec_model Contest contest_name:string status:integer > contest_series_id:integer > : script/generate rspec_model ContestSeries series_name:string > : rake db:migrate > : autotest > > I edited contest.rb and set the following: > class Contest < ActiveRecord::Base > belongs_to :contest_series > > def getSeries > ContestSeries.find(contest_series_id) > end > end > > I edited contest_series.rb and added the has_many statement: > class ContestSeries < ActiveRecord::Base > has_many :contests > end > > > I then created the following spec file in spec/models/contest_spec.rb > that can be found at http://pastie.org/283936 > > The summary of the test spec is that there are two describe blocks. The > first block creates a Contest and assigns it to a ContestSeries. For > the sake of the example, I then call ContestSeries.find(). > > The second block sets an expectation on ContestSeries that the find > method will be called only once. > > This causes the following error: > > Mocha::ExpectationError in 'Contest should demonstrate that the stub is > not cleared' > unexpected invocation: ContestSeries(id: integer, series_name: string, > created_at: datetime, updated_at: datetime).find(1) > satisfied expectations: > - expected exactly once, already invoked once: ContestSeries(id: > integer, series_name: string, created_at: datetime, updated_at: > datetime).find(1000) > > Playing around with some variations, I have found that if I change the > code in line 24 to: > > ContestSeries.expects(:find).at_least(1) You learn something new every day! First, the fix: in spec_helper.rb Spec::Runner.configure do |config| ... config.mock_with :mocha ... end The problem is that rspec needs to know that you're using mocha in order for it to call the mocha methods needed to verify and reset at the end of each example. The reason that the examples that use mocha methods seem to recognize those mocha methods is that, as I only just learned, rails *might* automatically load mocha in the test environment (depending on a few other factors in your system) implicitly without any direction to do so. If you're a mocha user, this is a good thing. Not so great if you're using other frameworks :) C'est la vie. Cheers, David > > then no error is generated, but this isn't really what I want. I want > to be confident that the "getSeries" call (which is really only a > simplification of the actual code) gets the correct ContestSeries. > > Have I misunderstood how to use this stubbing behavior? Is there a way > to correctly clear such expectations in an after block? > > Many thanks, > > Peter > -- > 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 Oct 2 23:43:49 2008 From: lists at ruby-forum.com (Evan Dorn) Date: Fri, 3 Oct 2008 05:43:49 +0200 Subject: [rspec-users] how to catch a missing image (rspec-rails) Message-ID: <18c7e87b177b2209d9ab23beae0b73d5@ruby-forum.com> I want to make sure all external resources called for by my views (like images) actually exist. How do I write an rspec that will fail when an image included on the page isn't present? For example, let's say in application.html.erb, I include , but that file doesn't exist (say it's actually /images/mylogo.jpg). When this is run on the server, the image won't appear, and the server log will show an error like this: >> ActionController::RoutingError (No route matches "/images/mylogo.png" with >> {:method=>:get}): However, views tests like response.should have_tag(img[src=/mylogo.png/) won't catch it, because the tag will be there. controllers tests (with integrate_views on) for response.should be_success, render_template won't catch it because the page itself was a success and rendered the template. But an error was thrown during a second connection to the server, because the image file didn't exist ... there must be a way for any such failures. How? Thanks! Ev -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Oct 2 23:52:51 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 2 Oct 2008 22:52:51 -0500 Subject: [rspec-users] [ANN] RSpec-1.1.7 is released Message-ID: <57c63afe0810022052k529b84bid56bc50c6417097d@mail.gmail.com> The RSpec Development is happy to announce the release of rspec-1.1.7 and rspec-rails-1.1.7 This is recommended for anyone who upgraded to 1.1.5 earlier this week as it addresses bugs that were introduced by that release: == rspec and rspec-rails 1.1.7 * fixed dependency problem introduced in rspec-rails-1.1.6 earlier this evening :( == rspec-1.1.6 * 2 bug fixes * fixed bug where negative message expectations following stubs resulted in false (negative) positives. Fixes #548. * fixed bug where Not Yet Implemented examples report incorrect caller. Fixes #547. * 1 minor enhancement * removed deprecated mock argument constraint symbols == rspec-rails-1.1.6 * 1 bug fix * fixed regression where values assigned to the assigns hash were not accessible from the example. Fixes #549. == More Information http://rspec.info/ http://github.com/dchelimsky/rspec/wikis http://rspec.lighthouseapp.com/ From pergesu at gmail.com Fri Oct 3 01:20:10 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 02 Oct 2008 22:20:10 -0700 Subject: [rspec-users] how to catch a missing image (rspec-rails) In-Reply-To: <18c7e87b177b2209d9ab23beae0b73d5@ruby-forum.com> (Evan Dorn's message of "Fri\, 3 Oct 2008 05\:43\:49 +0200") References: <18c7e87b177b2209d9ab23beae0b73d5@ruby-forum.com> Message-ID: Evan Dorn writes: > I want to make sure all external resources called for by my views (like > images) actually exist. How do I write an rspec that will fail when an > image included on the page isn't present? > > > For example, let's say in application.html.erb, I include src="/images/mylogo.png">, but that file doesn't exist (say it's > actually /images/mylogo.jpg). > > When this is run on the server, the image won't appear, and the server > log will show an error like this: > > >> ActionController::RoutingError (No route matches > "/images/mylogo.png" with > >> {:method=>:get}): > > However, views tests like response.should have_tag(img[src=/mylogo.png/) > won't catch it, because the tag will be there. controllers tests > (with integrate_views on) for response.should be_success, > render_template won't catch it because the page itself was a success and > rendered the template. > > But an error was thrown during a second connection to the server, > because the image file didn't exist ... there must be a way for any such > failures. How? Hi Evan, Can you rely on the convention that images are under RAILS_ROOT/public? If so, you could do a little translucent-box testing. Maybe you could use hpricot to get all the image elements and check their referenced file's existence. # I'm just BSing the hpricot hpricot("doc/img") do |element| element.attr('src').should be_existing_resource end Where be_existing_resource is a custom matcher with a simple implementation of def matches?(actual) File.exists?(File.expand_path(RAILS_ROOT + actual)) end (simple enough for a simple matcher, even) This should give you a good deal of confidence without any hassle. Pat From dchelimsky at gmail.com Fri Oct 3 09:14:22 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Oct 2008 08:14:22 -0500 Subject: [rspec-users] [ANN] RSpec-1.1.8 Message-ID: <57c63afe0810030614u6e245034u51e86ba644630112@mail.gmail.com> Thanks to some very quick feedback on the 1.1.7 release, the RSpec Development Team is proud to announce yet another bug fix release: RSpec-1.1.8. RSpec-1.1.8 includes the following changes: == rspec-1.1.8 * 2 bug fixes * restore colorized output in linux and windows w/ autotest (Tim Pope). Fixes #413. * autospec no longer hangs on windows. Fixes #554. == rspec-rails-1.1.8 * 2 bug fixes * correctly handle assigns that are false. Fixes #552. * ensure that NotYetImplemented examples report as pending (fixed in rspec, not rspec-rails). Fixes #553. == Install [sudo] gem install rspec [sudo] gem install rspec-rails == More information http://rspec.info http://rubyforge.org/projects/rspec/ http://github.com/dchelimsky/rspec/wikis http://rspec.lighthouseapp.com/ From lists at ruby-forum.com Fri Oct 3 10:09:19 2008 From: lists at ruby-forum.com (Peter Degen-Portnoy) Date: Fri, 3 Oct 2008 16:09:19 +0200 Subject: [rspec-users] Need to clear Mocha expectation? In-Reply-To: <57c63afe0810021553t3d127451oe3d31cbad8482316@mail.gmail.com> References: <16f3627bd0241e78308013039ad35366@ruby-forum.com> <57c63afe0810021553t3d127451oe3d31cbad8482316@mail.gmail.com> Message-ID: David Chelimsky wrote: > First, the fix: in spec_helper.rb > > Spec::Runner.configure do |config| > ... > config.mock_with :mocha > ... > end > Indeed! There was even such a line ready to be uncommented in spec_helper.rb Thank you so very much! That did indeed fix the problem nicely. - Peter -- Posted via http://www.ruby-forum.com/. From zach.dennis at gmail.com Fri Oct 3 13:28:37 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 3 Oct 2008 13:28:37 -0400 Subject: [rspec-users] [ANN] RSpec-1.1.8 In-Reply-To: <57c63afe0810030614u6e245034u51e86ba644630112@mail.gmail.com> References: <57c63afe0810030614u6e245034u51e86ba644630112@mail.gmail.com> Message-ID: <85d99afe0810031028n7f88b482l150f941a351791c3@mail.gmail.com> David, Can you tag this in git or push your git tags if you have done so locally ? Thanks, Zach On Fri, Oct 3, 2008 at 9:14 AM, David Chelimsky wrote: > Thanks to some very quick feedback on the 1.1.7 release, the RSpec > Development Team is proud to announce yet another bug fix release: > RSpec-1.1.8. > > RSpec-1.1.8 includes the following changes: > > == rspec-1.1.8 > > * 2 bug fixes > > * restore colorized output in linux and windows w/ autotest (Tim > Pope). Fixes #413. > * autospec no longer hangs on windows. Fixes #554. > > == rspec-rails-1.1.8 > > * 2 bug fixes > > * correctly handle assigns that are false. Fixes #552. > * ensure that NotYetImplemented examples report as pending (fixed in > rspec, not rspec-rails). Fixes #553. > > == Install > > [sudo] gem install rspec > [sudo] gem install rspec-rails > > == More information > > http://rspec.info > http://rubyforge.org/projects/rspec/ > http://github.com/dchelimsky/rspec/wikis > http://rspec.lighthouseapp.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 Fri Oct 3 14:02:42 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Oct 2008 13:02:42 -0500 Subject: [rspec-users] [ANN] RSpec-1.1.8 In-Reply-To: <85d99afe0810031028n7f88b482l150f941a351791c3@mail.gmail.com> References: <57c63afe0810030614u6e245034u51e86ba644630112@mail.gmail.com> <85d99afe0810031028n7f88b482l150f941a351791c3@mail.gmail.com> Message-ID: <57c63afe0810031102s212406e9re91c603c1a6281b0@mail.gmail.com> On Fri, Oct 3, 2008 at 12:28 PM, Zach Dennis wrote: > David, > > Can you tag this in git or push your git tags if you have done so > locally ? Thanks, The tags have already been pushed - I can see them on github, can you not? > > Zach > > On Fri, Oct 3, 2008 at 9:14 AM, David Chelimsky wrote: >> Thanks to some very quick feedback on the 1.1.7 release, the RSpec >> Development Team is proud to announce yet another bug fix release: >> RSpec-1.1.8. >> >> RSpec-1.1.8 includes the following changes: >> >> == rspec-1.1.8 >> >> * 2 bug fixes >> >> * restore colorized output in linux and windows w/ autotest (Tim >> Pope). Fixes #413. >> * autospec no longer hangs on windows. Fixes #554. >> >> == rspec-rails-1.1.8 >> >> * 2 bug fixes >> >> * correctly handle assigns that are false. Fixes #552. >> * ensure that NotYetImplemented examples report as pending (fixed in >> rspec, not rspec-rails). Fixes #553. >> >> == Install >> >> [sudo] gem install rspec >> [sudo] gem install rspec-rails >> >> == More information >> >> http://rspec.info >> http://rubyforge.org/projects/rspec/ >> http://github.com/dchelimsky/rspec/wikis >> http://rspec.lighthouseapp.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 Fri Oct 3 14:09:51 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 3 Oct 2008 14:09:51 -0400 Subject: [rspec-users] [ANN] RSpec-1.1.8 In-Reply-To: <57c63afe0810031102s212406e9re91c603c1a6281b0@mail.gmail.com> References: <57c63afe0810030614u6e245034u51e86ba644630112@mail.gmail.com> <85d99afe0810031028n7f88b482l150f941a351791c3@mail.gmail.com> <57c63afe0810031102s212406e9re91c603c1a6281b0@mail.gmail.com> Message-ID: <85d99afe0810031109r638bf669o3ca85723e07fc959@mail.gmail.com> On Fri, Oct 3, 2008 at 2:02 PM, David Chelimsky wrote: > On Fri, Oct 3, 2008 at 12:28 PM, Zach Dennis wrote: >> David, >> >> Can you tag this in git or push your git tags if you have done so >> locally ? Thanks, > > The tags have already been pushed - I can see them on github, can you not? > I was doing git tag -l from the rspec-dev repository, which shows 1.1.4 and 1.1.5. From within the rspec and rspec-rails repositories I am seeing 1.1.4, 1.1.5, 1.1.6, 1.1.7 and 1.1.8 tags. Does the rspec-dev repository need to be tagged in general? -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From dchelimsky at gmail.com Fri Oct 3 15:04:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 3 Oct 2008 14:04:21 -0500 Subject: [rspec-users] [ANN] RSpec-1.1.8 In-Reply-To: <85d99afe0810031109r638bf669o3ca85723e07fc959@mail.gmail.com> References: <57c63afe0810030614u6e245034u51e86ba644630112@mail.gmail.com> <85d99afe0810031028n7f88b482l150f941a351791c3@mail.gmail.com> <57c63afe0810031102s212406e9re91c603c1a6281b0@mail.gmail.com> <85d99afe0810031109r638bf669o3ca85723e07fc959@mail.gmail.com> Message-ID: <57c63afe0810031204g272de754ndbfc96464581da21@mail.gmail.com> On Fri, Oct 3, 2008 at 1:09 PM, Zach Dennis wrote: > On Fri, Oct 3, 2008 at 2:02 PM, David Chelimsky wrote: >> On Fri, Oct 3, 2008 at 12:28 PM, Zach Dennis wrote: >>> David, >>> >>> Can you tag this in git or push your git tags if you have done so >>> locally ? Thanks, >> >> The tags have already been pushed - I can see them on github, can you not? >> > > I was doing git tag -l from the rspec-dev repository, which shows > 1.1.4 and 1.1.5. From within the rspec and rspec-rails repositories I > am seeing 1.1.4, 1.1.5, 1.1.6, 1.1.7 and 1.1.8 tags. Does the > rspec-dev repository need to be tagged in general? That's a good question. Right now some of the code examples for rspec-rails still live in the rspec-dev repo (in the example rails app). I'd like to change that anyhow. I'll it going forward, and if we find a need for it we can figure out dates and do a best guess retroactively. Cheers, David > > -- > 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 dhf0820 at gmail.com Fri Oct 3 16:46:44 2008 From: dhf0820 at gmail.com (Donald French) Date: Fri, 3 Oct 2008 10:46:44 -1000 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: References: Message-ID: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> Can someone tell me the difference ins the gem versions and the plugin versions? do they work together? need both? Don French On Oct 3, 2008, at 3:14 AM, rspec-users-request at rubyforge.org wrote: > Send rspec-users mailing list submissions to > rspec-users at rubyforge.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://rubyforge.org/mailman/listinfo/rspec-users > or, via email, send a message with subject or body 'help' to > rspec-users-request at rubyforge.org > > You can reach the person managing the list at > rspec-users-owner at rubyforge.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of rspec-users digest..." > > > Today's Topics: > > 1. Re: Associations should be private (Mark Wilden) > 2. Need to clear Mocha expectation? (Peter Degen-Portnoy) > 3. Re: Need to clear Mocha expectation? (David Chelimsky) > 4. how to catch a missing image (rspec-rails) (Evan Dorn) > 5. [ANN] RSpec-1.1.7 is released (David Chelimsky) > 6. Re: how to catch a missing image (rspec-rails) (Pat Maddox) > 7. [ANN] RSpec-1.1.8 (David Chelimsky) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 2 Oct 2008 10:01:47 -0700 > From: "Mark Wilden" > Subject: Re: [rspec-users] Associations should be private > To: rspec-users > Message-ID: > <3c30da400810021001l3859606aw39cd74dd704634bb at mail.gmail.com> > Content-Type: text/plain; charset="iso-8859-1" > > On Wed, Oct 1, 2008 at 7:06 PM, David Chelimsky > wrote: > >> >> Au contraire! You're comparing apples and cadillacs here. Demeter is >> about encapsulation. Interfaces are about abstraction and structure. >> Completely different animals. > > > Interfaces in that Java book and LOD in this topic were being > supported by > arguments of the form "if you need to change things in the > future..." There > are some practitioners for whom that's a valid argument, and there are > others for whom it's an anti-argument. YAGNI is the latter. Doesn't > make it > right, but it does provide a way to evaluate each of these animals. > > >> Tracking down all of the trainwrecks in a system is not quite so >> simple. First of all, they are not guaranteed to look the same: >> >> trainer.animals.dogs.first >> >> vs >> >> t = trainer >> a = trainer.animals >> d = trainer.dogs >> dog = dogs[0] >> >> So when the design seems to want to categorize animals into domestic >> and wild, the first call has to be changed to >> trainer.animals.domestic.dogs.first. Good luck tracking down the >> second example > > > In a statically-typed language, this would be trivial. In a > dynamically-typed language using BDD, this would be caught by tests. > > >> Principles/guidelines like YAGNI and DRY and even the >> ever-threatening-sounding Law of Demeter are NOT LAWS. They are >> indicators. Red flag triggers. Red flags are *warnings*, not >> *errors*. >> > > We agree on that. See my recent post: > http://www.nabble.com/Prepare-for-newbie-ness- > to19516110.html#a19542377 > > In this case, we've got two of these in direct conflict with each > >> other, so which one wins? Gotta look at the costs and benefits of >> each >> and proceed wisely and *in context* > > > I feel that YAGNI and LOD are at different levels of granularity. I > use > YAGNI and TSTTCPW in my daily life (which isn't to say that I always > think > they're the best approach). So I approach problems using those > principles as > my base. I don't ask myself a hundred times a day whether I should > use a > goto statement - I use structured programming as my base. Same with > OOP, > readable code, lack of commenting, etc. You can't approach > everything de > novo. So I apply YAGNI unless I see a compelling reason not to. The > reason > is that the "costs and benefits" of any approach are usually not > obvious - > especially when talking about the future. > > ///ark > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > > > ------------------------------ > > Message: 2 > Date: Fri, 3 Oct 2008 00:20:57 +0200 > From: Peter Degen-Portnoy > Subject: [rspec-users] Need to clear Mocha expectation? > To: rspec-users at rubyforge.org > Message-ID: <16f3627bd0241e78308013039ad35366 at ruby-forum.com> > Content-Type: text/plain; charset=utf-8 > > Hi Folks, > > I have a problem that I have been able to isolate into a small test > application. > > The problem seems to be that when I set an expectation on the number > of > times a method will be called in one describe block, the expectation > is > still set in a different describe block. My understanding was that > RSpec restored the state of objects and the end of a test, which I > interpreted as the end of a describe block (seeing that the scope of > the > expectation ended). > > Here is my test application: > : rails rspecproblem > : cd rspecproblem > > : script/generate rspec_model Contest contest_name:string > status:integer > contest_series_id:integer > : script/generate rspec_model ContestSeries series_name:string > : rake db:migrate > : autotest > > I edited contest.rb and set the following: > class Contest < ActiveRecord::Base > belongs_to :contest_series > > def getSeries > ContestSeries.find(contest_series_id) > end > end > > I edited contest_series.rb and added the has_many statement: > class ContestSeries < ActiveRecord::Base > has_many :contests > end > > > I then created the following spec file in spec/models/contest_spec.rb > that can be found at http://pastie.org/283936 > > The summary of the test spec is that there are two describe blocks. > The > first block creates a Contest and assigns it to a ContestSeries. For > the sake of the example, I then call ContestSeries.find(). > > The second block sets an expectation on ContestSeries that the find > method will be called only once. > > This causes the following error: > > Mocha::ExpectationError in 'Contest should demonstrate that the stub > is > not cleared' > unexpected invocation: ContestSeries(id: integer, series_name: string, > created_at: datetime, updated_at: datetime).find(1) > satisfied expectations: > - expected exactly once, already invoked once: ContestSeries(id: > integer, series_name: string, created_at: datetime, updated_at: > datetime).find(1000) > > Playing around with some variations, I have found that if I change the > code in line 24 to: > > ContestSeries.expects(:find).at_least(1) > > then no error is generated, but this isn't really what I want. I want > to be confident that the "getSeries" call (which is really only a > simplification of the actual code) gets the correct ContestSeries. > > Have I misunderstood how to use this stubbing behavior? Is there a > way > to correctly clear such expectations in an after block? > > Many thanks, > > Peter > -- > Posted via http://www.ruby-forum.com/. > > > ------------------------------ > > Message: 3 > Date: Thu, 2 Oct 2008 17:53:47 -0500 > From: "David Chelimsky" > Subject: Re: [rspec-users] Need to clear Mocha expectation? > To: rspec-users at rubyforge.org > Message-ID: > <57c63afe0810021553t3d127451oe3d31cbad8482316 at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > > On Thu, Oct 2, 2008 at 5:20 PM, Peter Degen-Portnoy > wrote: >> Hi Folks, >> >> I have a problem that I have been able to isolate into a small test >> application. >> >> The problem seems to be that when I set an expectation on the >> number of >> times a method will be called in one describe block, the >> expectation is >> still set in a different describe block. My understanding was that >> RSpec restored the state of objects and the end of a test, which I >> interpreted as the end of a describe block (seeing that the scope >> of the >> expectation ended). >> >> Here is my test application: >> : rails rspecproblem >> : cd rspecproblem >> >> : script/generate rspec_model Contest contest_name:string >> status:integer >> contest_series_id:integer >> : script/generate rspec_model ContestSeries series_name:string >> : rake db:migrate >> : autotest >> >> I edited contest.rb and set the following: >> class Contest < ActiveRecord::Base >> belongs_to :contest_series >> >> def getSeries >> ContestSeries.find(contest_series_id) >> end >> end >> >> I edited contest_series.rb and added the has_many statement: >> class ContestSeries < ActiveRecord::Base >> has_many :contests >> end >> >> >> I then created the following spec file in spec/models/contest_spec.rb >> that can be found at http://pastie.org/283936 >> >> The summary of the test spec is that there are two describe >> blocks. The >> first block creates a Contest and assigns it to a ContestSeries. For >> the sake of the example, I then call ContestSeries.find(). >> >> The second block sets an expectation on ContestSeries that the find >> method will be called only once. >> >> This causes the following error: >> >> Mocha::ExpectationError in 'Contest should demonstrate that the >> stub is >> not cleared' >> unexpected invocation: ContestSeries(id: integer, series_name: >> string, >> created_at: datetime, updated_at: datetime).find(1) >> satisfied expectations: >> - expected exactly once, already invoked once: ContestSeries(id: >> integer, series_name: string, created_at: datetime, updated_at: >> datetime).find(1000) >> >> Playing around with some variations, I have found that if I change >> the >> code in line 24 to: >> >> ContestSeries.expects(:find).at_least(1) > > You learn something new every day! > > First, the fix: in spec_helper.rb > > Spec::Runner.configure do |config| > ... > config.mock_with :mocha > ... > end > > The problem is that rspec needs to know that you're using mocha in > order for it to call the mocha methods needed to verify and reset at > the end of each example. > > The reason that the examples that use mocha methods seem to recognize > those mocha methods is that, as I only just learned, rails *might* > automatically load mocha in the test environment (depending on a few > other factors in your system) implicitly without any direction to do > so. If you're a mocha user, this is a good thing. Not so great if > you're using other frameworks :) C'est la vie. > > Cheers, > David > > > >> >> then no error is generated, but this isn't really what I want. I >> want >> to be confident that the "getSeries" call (which is really only a >> simplification of the actual code) gets the correct ContestSeries. >> >> Have I misunderstood how to use this stubbing behavior? Is there a >> way >> to correctly clear such expectations in an after block? >> >> Many thanks, >> >> Peter >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > ------------------------------ > > Message: 4 > Date: Fri, 3 Oct 2008 05:43:49 +0200 > From: Evan Dorn > Subject: [rspec-users] how to catch a missing image (rspec-rails) > To: rspec-users at rubyforge.org > Message-ID: <18c7e87b177b2209d9ab23beae0b73d5 at ruby-forum.com> > Content-Type: text/plain; charset=utf-8 > > I want to make sure all external resources called for by my views > (like > images) actually exist. How do I write an rspec that will fail when > an > image included on the page isn't present? > > > For example, let's say in application.html.erb, I include src="/images/mylogo.png">, but that file doesn't exist (say it's > actually /images/mylogo.jpg). > > When this is run on the server, the image won't appear, and the server > log will show an error like this: > >>> ActionController::RoutingError (No route matches > "/images/mylogo.png" with >>> {:method=>:get}): > > However, views tests like response.should have_tag(img[src=/ > mylogo.png/) > won't catch it, because the tag will be there. controllers tests > (with integrate_views on) for response.should be_success, > render_template won't catch it because the page itself was a success > and > rendered the template. > > But an error was thrown during a second connection to the server, > because the image file didn't exist ... there must be a way for any > such > failures. How? > > Thanks! > Ev > -- > Posted via http://www.ruby-forum.com/. > > > ------------------------------ > > Message: 5 > Date: Thu, 2 Oct 2008 22:52:51 -0500 > From: "David Chelimsky" > Subject: [rspec-users] [ANN] RSpec-1.1.7 is released > To: rspec-users , rspec-devel > , "ruby-talk ML" lang.org> > Message-ID: > <57c63afe0810022052k529b84bid56bc50c6417097d at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > > The RSpec Development is happy to announce the release of rspec-1.1.7 > and rspec-rails-1.1.7 > > This is recommended for anyone who upgraded to 1.1.5 earlier this week > as it addresses bugs that were introduced by that release: > > == rspec and rspec-rails 1.1.7 > > * fixed dependency problem introduced in rspec-rails-1.1.6 earlier > this evening :( > > == rspec-1.1.6 > > * 2 bug fixes > > * fixed bug where negative message expectations following stubs > resulted in false (negative) positives. Fixes #548. > * fixed bug where Not Yet Implemented examples report incorrect > caller. Fixes #547. > > * 1 minor enhancement > > * removed deprecated mock argument constraint symbols > > == rspec-rails-1.1.6 > > * 1 bug fix > > * fixed regression where values assigned to the assigns hash were not > accessible from the example. Fixes #549. > > == More Information > > http://rspec.info/ > http://github.com/dchelimsky/rspec/wikis > http://rspec.lighthouseapp.com/ > > > ------------------------------ > > Message: 6 > Date: Thu, 02 Oct 2008 22:20:10 -0700 > From: Pat Maddox > Subject: Re: [rspec-users] how to catch a missing image (rspec-rails) > To: rspec-users at rubyforge.org > Message-ID: > Content-Type: text/plain; charset=us-ascii > > Evan Dorn writes: > >> I want to make sure all external resources called for by my views >> (like >> images) actually exist. How do I write an rspec that will fail >> when an >> image included on the page isn't present? >> >> >> For example, let's say in application.html.erb, I include > src="/images/mylogo.png">, but that file doesn't exist (say it's >> actually /images/mylogo.jpg). >> >> When this is run on the server, the image won't appear, and the >> server >> log will show an error like this: >> >>>> ActionController::RoutingError (No route matches >> "/images/mylogo.png" with >>>> {:method=>:get}): >> >> However, views tests like response.should have_tag(img[src=/ >> mylogo.png/) >> won't catch it, because the tag will be there. controllers tests >> (with integrate_views on) for response.should be_success, >> render_template won't catch it because the page itself was a >> success and >> rendered the template. >> >> But an error was thrown during a second connection to the server, >> because the image file didn't exist ... there must be a way for any >> such >> failures. How? > > Hi Evan, > > Can you rely on the convention that images are under RAILS_ROOT/ > public? > If so, you could do a little translucent-box testing. Maybe you could > use hpricot to get all the image elements and check their referenced > file's existence. > > # I'm just BSing the hpricot > hpricot("doc/img") do |element| > element.attr('src').should be_existing_resource > end > > Where be_existing_resource is a custom matcher with a simple > implementation of > > def matches?(actual) > File.exists?(File.expand_path(RAILS_ROOT + actual)) > end > > (simple enough for a simple matcher, even) > > This should give you a good deal of confidence without any hassle. > > Pat > > > ------------------------------ > > Message: 7 > Date: Fri, 3 Oct 2008 08:14:22 -0500 > From: "David Chelimsky" > Subject: [rspec-users] [ANN] RSpec-1.1.8 > To: rspec-users , rspec-devel > , "ruby-talk ML" lang.org> > Message-ID: > <57c63afe0810030614u6e245034u51e86ba644630112 at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > > Thanks to some very quick feedback on the 1.1.7 release, the RSpec > Development Team is proud to announce yet another bug fix release: > RSpec-1.1.8. > > RSpec-1.1.8 includes the following changes: > > == rspec-1.1.8 > > * 2 bug fixes > > * restore colorized output in linux and windows w/ autotest (Tim > Pope). Fixes #413. > * autospec no longer hangs on windows. Fixes #554. > > == rspec-rails-1.1.8 > > * 2 bug fixes > > * correctly handle assigns that are false. Fixes #552. > * ensure that NotYetImplemented examples report as pending (fixed in > rspec, not rspec-rails). Fixes #553. > > == Install > > [sudo] gem install rspec > [sudo] gem install rspec-rails > > == More information > > http://rspec.info > http://rubyforge.org/projects/rspec/ > http://github.com/dchelimsky/rspec/wikis > http://rspec.lighthouseapp.com/ > > > ------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > End of rspec-users Digest, Vol 28, Issue 9 > ****************************************** From zach.dennis at gmail.com Fri Oct 3 16:57:23 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 3 Oct 2008 16:57:23 -0400 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> Message-ID: <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> On Fri, Oct 3, 2008 at 4:46 PM, Donald French wrote: > Can someone tell me the difference ins the gem versions and the plugin > versions? do they work together? need both? > You do not need both. The plugin versions are for Ruby on Rails projects. Rails had a way of loading plugins from the vendor/plugins/ directory. This will most likely deprecate (or become less and less used) as Rails has added support for bundling gems with the project in the vendor/gems/ directory. The gem versions of rspec are the ones that are intended for everyday use. I would go with those unless you are supporting a Rails application in the 1.2.x family or earlier. Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From pergesu at gmail.com Fri Oct 3 17:03:22 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 03 Oct 2008 14:03:22 -0700 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> (Zach Dennis's message of "Fri\, 3 Oct 2008 16\:57\:23 -0400") References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> Message-ID: "Zach Dennis" writes: > On Fri, Oct 3, 2008 at 4:46 PM, Donald French wrote: >> Can someone tell me the difference ins the gem versions and the plugin >> versions? do they work together? need both? >> > > You do not need both. The plugin versions are for Ruby on Rails > projects. Rails had a way of loading plugins from the vendor/plugins/ > directory. This will most likely deprecate (or become less and less > used) as Rails has added support for bundling gems with the project > in the vendor/gems/ directory. rspec-rails is now published as a gem as well. I am 100% plugin free when it comes to RSpec. Pat From lists at ruby-forum.com Sat Oct 4 12:09:17 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Sat, 4 Oct 2008 18:09:17 +0200 Subject: [rspec-users] Webrat and submitting a form using an image Message-ID: <8aad12d9790121baec3cb3b3cafd3045@ruby-forum.com> Webrat doesn't seem to be able to handle the submit of a form through an image input. How do you handle that? -- Posted via http://www.ruby-forum.com/. From lianliming at gmail.com Sat Oct 4 12:22:58 2008 From: lianliming at gmail.com (Lian Liming) Date: Sun, 5 Oct 2008 00:22:58 +0800 Subject: [rspec-users] Newbie's question about generated features by cucumber in Rails In-Reply-To: <2ab0f52d0810040319x15e74103h7c6df8d47e2d47ea@mail.gmail.com> References: <2ab0f52d0810040319x15e74103h7c6df8d47e2d47ea@mail.gmail.com> Message-ID: <2ab0f52d0810040922g6d65be03md9845e79d811598b@mail.gmail.com> Hi all, I am new to rspec and trying to use cucumber to learn writingfeatures. I follow the wiki page http://github.com/aslakhellesoy/cucumber/wikis/ruby-on-rails to start my first feature. The command "ruby script/generate feature Frooble name color description" generates a file "manage_froobles.feature" with itscontent as following: ------ manage_froobles.feature --- Feature: Manage froobles In order to keep track of froobles A frooble mechanic Should be able to manage several froobles Scenario: Register new frooble <....omit some lines here...> Scenario: Delete frooble Given there are 4 froobles When I delete the first frooble Then there should be 3 froobles left | initial | after | | 100 | 99 | | 1 | 0 | ------end of manage_froobles.feature --- I quite understand most of lines in this file except the last few lines, which composes a two-column table with heads "initial" and "after". I am really confusing on what is the meaning of those data. I have studied some background knowledge about stories in BDD, while those don't help me understand this. So any hints? Thanks in dvance! Liming From aslak.hellesoy at gmail.com Sat Oct 4 12:45:55 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 4 Oct 2008 18:45:55 +0200 Subject: [rspec-users] Newbie's question about generated features by cucumber in Rails In-Reply-To: <2ab0f52d0810040922g6d65be03md9845e79d811598b@mail.gmail.com> References: <2ab0f52d0810040319x15e74103h7c6df8d47e2d47ea@mail.gmail.com> <2ab0f52d0810040922g6d65be03md9845e79d811598b@mail.gmail.com> Message-ID: <8d961d900810040945v89cf5b6k74f84a60095249ef@mail.gmail.com> On Sat, Oct 4, 2008 at 6:22 PM, Lian Liming wrote: > Hi all, > > I am new to rspec and trying to use cucumber to learn writingfeatures. > I follow the wiki page > http://github.com/aslakhellesoy/cucumber/wikis/ruby-on-rails to start > my first feature. > > The command "ruby script/generate feature Frooble name color > description" generates a file "manage_froobles.feature" with > itscontent as following: > > ------ manage_froobles.feature --- > Feature: Manage froobles > In order to keep track of froobles > A frooble mechanic > Should be able to manage several froobles > > Scenario: Register new frooble > <....omit some lines here...> > > Scenario: Delete frooble > Given there are 4 froobles > When I delete the first frooble > Then there should be 3 froobles left > > | initial | after | > | 100 | 99 | > | 1 | 0 | > ------end of manage_froobles.feature --- > > I quite understand most of lines in this file except the last few > lines, which composes a two-column table with heads "initial" and > "after". I am really confusing on what is the meaning of those data. I > have studied some background knowledge about stories in BDD, while > those don't help me understand this. So any hints? Thanks in dvance! > This table will run the previous scenario once for each row in the table, substituting the parameters in the scenario. The first line in the table is just for documentation. It's inspired from column fixtures in the FIT tool: http://fit.c2.com/wiki.cgi?ColumnFixture Aslak > Liming > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Sat Oct 4 12:54:19 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Sat, 4 Oct 2008 18:54:19 +0200 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> Message-ID: How do you go plugin-less for RSpec? The plugins require you to generate some files, so how do you do that without a plugin? Is there still a rake task in the gem to generate the required files? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sat Oct 4 12:58:20 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Oct 2008 11:58:20 -0500 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> Message-ID: <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> On Sat, Oct 4, 2008 at 11:54 AM, Fernando Perez wrote: > How do you go plugin-less for RSpec? The plugins require you to generate > some files, so how do you do that without a plugin? Is there still a > rake task in the gem to generate the required files? I'll post this up on the wiki, but the steps are: [sudo] gem install rspec-rails script/generate rspec That's it. rspec is a dependency of rspec-rails, so installing the rspec-rails gem will also install the rspec gem. Once installed, if you type 'script/generate' with no arguments, you'll see all the rspec generators listed. 'script/generate rspec' generates the files necessary to work with rspec without having to install the plugins in your app. Cheers, David From lists at ruby-forum.com Sat Oct 4 13:01:18 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Sat, 4 Oct 2008 19:01:18 +0200 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> Message-ID: <7ec8b0e0b72b72a894428b314842772e@ruby-forum.com> Cool. However what happens when my app is currently using the plugin version, is it easy to migrate to the gem? Should I regenerate the files? I guess there is somewhere a line that says to rspec "look into vendor/plugins"? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sat Oct 4 13:07:39 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Oct 2008 12:07:39 -0500 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: <7ec8b0e0b72b72a894428b314842772e@ruby-forum.com> References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> <7ec8b0e0b72b72a894428b314842772e@ruby-forum.com> Message-ID: <57c63afe0810041007w4a70ed17s87208b6531d6e245@mail.gmail.com> On Sat, Oct 4, 2008 at 12:01 PM, Fernando Perez wrote: > Cool. > > However what happens when my app is currently using the plugin version, > is it easy to migrate to the gem? Should I regenerate the files? I guess > there is somewhere a line that says to rspec "look into vendor/plugins"? Just delete the plugin directories. http://github.com/dchelimsky/rspec-rails/wikis/home Cheers, David From luislavena at gmail.com Sat Oct 4 14:06:44 2008 From: luislavena at gmail.com (Luis Lavena) Date: Sat, 4 Oct 2008 16:06:44 -0200 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> Message-ID: <71166b3b0810041106n7e739424x95915be4365f0f08@mail.gmail.com> On Sat, Oct 4, 2008 at 2:58 PM, David Chelimsky wrote: > On Sat, Oct 4, 2008 at 11:54 AM, Fernando Perez wrote: >> How do you go plugin-less for RSpec? The plugins require you to generate >> some files, so how do you do that without a plugin? Is there still a >> rake task in the gem to generate the required files? > > I'll post this up on the wiki, but the steps are: > > [sudo] gem install rspec-rails > script/generate rspec > > That's it. > > rspec is a dependency of rspec-rails, so installing the rspec-rails > gem will also install the rspec gem. > > Once installed, if you type 'script/generate' with no arguments, > you'll see all the rspec generators listed. 'script/generate rspec' > generates the files necessary to work with rspec without having to > install the plugins in your app. > It doesn't :-P Just tried that on a fresh application, and when call script/generate rspec it just not find it and don't execute it :-P Also, going to the gem version instead of the plugin requires a new set of script files, since they try to look for vendor/plugins/ instead of doing: require 'rubygems' require 'spec' Last, but not least, you need to do config.gem 'rspec-rails', :lib => 'spec/rails' since Rails will try by default to load 'rspec-rails' module instead. Wow, lot of details :-P Cheers, -- 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 dchelimsky at gmail.com Sat Oct 4 14:38:43 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Oct 2008 13:38:43 -0500 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: <71166b3b0810041106n7e739424x95915be4365f0f08@mail.gmail.com> References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> <71166b3b0810041106n7e739424x95915be4365f0f08@mail.gmail.com> Message-ID: <57c63afe0810041138x67a6b634k57d99df61c32487d@mail.gmail.com> On Sat, Oct 4, 2008 at 1:06 PM, Luis Lavena wrote: > On Sat, Oct 4, 2008 at 2:58 PM, David Chelimsky wrote: >> On Sat, Oct 4, 2008 at 11:54 AM, Fernando Perez wrote: >>> How do you go plugin-less for RSpec? The plugins require you to generate >>> some files, so how do you do that without a plugin? Is there still a >>> rake task in the gem to generate the required files? >> >> I'll post this up on the wiki, but the steps are: >> >> [sudo] gem install rspec-rails >> script/generate rspec >> >> That's it. >> >> rspec is a dependency of rspec-rails, so installing the rspec-rails >> gem will also install the rspec gem. >> >> Once installed, if you type 'script/generate' with no arguments, >> you'll see all the rspec generators listed. 'script/generate rspec' >> generates the files necessary to work with rspec without having to >> install the plugins in your app. >> > > It doesn't :-P > > Just tried that on a fresh application, and when call script/generate > rspec it just not find it and don't execute it :-P > > Also, going to the gem version instead of the plugin requires a new > set of script files, since they try to look for vendor/plugins/ > instead of doing: > > require 'rubygems' > require 'spec' > > Last, but not least, you need to do > > config.gem 'rspec-rails', :lib => 'spec/rails' since Rails will try by > default to load 'rspec-rails' module instead. > > Wow, lot of details :-P Hmmm. Wonder if this is a windows thing. Or maybe you have an older version of rubygems? It works as I prescribed for me with the following: $ ruby -v ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0] $ gem -v 1.3.0 $ rails -v Rails 2.1.1 $ spec --version rspec 1.1.8 Besides the OS, what's different in your system? > > Cheers, > -- > 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 dchelimsky at gmail.com Sat Oct 4 14:41:08 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Oct 2008 13:41:08 -0500 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: <57c63afe0810041138x67a6b634k57d99df61c32487d@mail.gmail.com> References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> <71166b3b0810041106n7e739424x95915be4365f0f08@mail.gmail.com> <57c63afe0810041138x67a6b634k57d99df61c32487d@mail.gmail.com> Message-ID: <57c63afe0810041141o62051affof3c78192af0990f4@mail.gmail.com> On Sat, Oct 4, 2008 at 1:38 PM, David Chelimsky wrote: > On Sat, Oct 4, 2008 at 1:06 PM, Luis Lavena wrote: >> On Sat, Oct 4, 2008 at 2:58 PM, David Chelimsky wrote: >>> On Sat, Oct 4, 2008 at 11:54 AM, Fernando Perez wrote: >>>> How do you go plugin-less for RSpec? The plugins require you to generate >>>> some files, so how do you do that without a plugin? Is there still a >>>> rake task in the gem to generate the required files? >>> >>> I'll post this up on the wiki, but the steps are: >>> >>> [sudo] gem install rspec-rails >>> script/generate rspec >>> >>> That's it. >>> >>> rspec is a dependency of rspec-rails, so installing the rspec-rails >>> gem will also install the rspec gem. >>> >>> Once installed, if you type 'script/generate' with no arguments, >>> you'll see all the rspec generators listed. 'script/generate rspec' >>> generates the files necessary to work with rspec without having to >>> install the plugins in your app. >>> >> >> It doesn't :-P >> >> Just tried that on a fresh application, and when call script/generate >> rspec it just not find it and don't execute it :-P >> >> Also, going to the gem version instead of the plugin requires a new >> set of script files, since they try to look for vendor/plugins/ >> instead of doing: >> >> require 'rubygems' >> require 'spec' >> >> Last, but not least, you need to do >> >> config.gem 'rspec-rails', :lib => 'spec/rails' since Rails will try by >> default to load 'rspec-rails' module instead. >> >> Wow, lot of details :-P > > Hmmm. Wonder if this is a windows thing. Or maybe you have an older > version of rubygems? It works as I prescribed for me with the > following: > > $ ruby -v > ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0] > $ gem -v > 1.3.0 > $ rails -v > Rails 2.1.1 > $ spec --version > rspec 1.1.8 > > Besides the OS, what's different in your system? Also - the script files prepend vendor/plugins/rspec/lib to the path, but if they are not there, there shouldn't be a problem. That just ensures that if you DO have the plugin installed it takes precedence over the gem. > > >> >> Cheers, >> -- >> 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 luislavena at gmail.com Sat Oct 4 14:43:27 2008 From: luislavena at gmail.com (Luis Lavena) Date: Sat, 4 Oct 2008 16:43:27 -0200 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: <57c63afe0810041141o62051affof3c78192af0990f4@mail.gmail.com> References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> <71166b3b0810041106n7e739424x95915be4365f0f08@mail.gmail.com> <57c63afe0810041138x67a6b634k57d99df61c32487d@mail.gmail.com> <57c63afe0810041141o62051affof3c78192af0990f4@mail.gmail.com> Message-ID: <71166b3b0810041143j3072773aoa560f0040ba4bdbc@mail.gmail.com> On Sat, Oct 4, 2008 at 4:41 PM, David Chelimsky wrote: > ... > > Also - the script files prepend vendor/plugins/rspec/lib to the path, > but if they are not there, there shouldn't be a problem. That just > ensures that if you DO have the plugin installed it takes precedence > over the gem. > But require 'rubygems' on top is missing, ending with LoadError due missing 'spec' :-P Will get back to you with facts and all the details, 1.3.0 was released with a bug on Windows so I need to cook a sandboxed ruby with trunk version instead. -- 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 dchelimsky at gmail.com Sat Oct 4 14:47:31 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Oct 2008 13:47:31 -0500 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: <71166b3b0810041143j3072773aoa560f0040ba4bdbc@mail.gmail.com> References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> <71166b3b0810041106n7e739424x95915be4365f0f08@mail.gmail.com> <57c63afe0810041138x67a6b634k57d99df61c32487d@mail.gmail.com> <57c63afe0810041141o62051affof3c78192af0990f4@mail.gmail.com> <71166b3b0810041143j3072773aoa560f0040ba4bdbc@mail.gmail.com> Message-ID: <57c63afe0810041147x552e0e06n3e9e2e1b0fb0ae6b@mail.gmail.com> On Sat, Oct 4, 2008 at 1:43 PM, Luis Lavena wrote: > On Sat, Oct 4, 2008 at 4:41 PM, David Chelimsky wrote: >> ... >> >> Also - the script files prepend vendor/plugins/rspec/lib to the path, >> but if they are not there, there shouldn't be a problem. That just >> ensures that if you DO have the plugin installed it takes precedence >> over the gem. >> > > But require 'rubygems' on top is missing, ending with LoadError due > missing 'spec' :-P I've added that to script/spec: http://github.com/dchelimsky/rspec-rails/commit/931f3700cf90f44f10ad599b360b20ebbbe95eab > Will get back to you with facts and all the details, 1.3.0 was > released with a bug on Windows so I need to cook a sandboxed ruby with > trunk version instead. Thanks for your help! Cheers, David > > -- > 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 joe at pinkpucker.net Sat Oct 4 19:05:53 2008 From: joe at pinkpucker.net (Joe Van Dyk) Date: Sat, 4 Oct 2008 16:05:53 -0700 Subject: [rspec-users] problem running cucumber Message-ID: When I run 'rake features', this is the output I get: /usr/local/bin/ruby -I "/home/joe/projects/voxy/vendor/plugins/cucumber/lib" "/home/joe/projects/voxy/vendor/plugins/cucumber/bin/cucumber" --format pretty --require features/steps/env.rb --require features/steps/request_steps.rb --require features/steps/common_webrat.rb features/manage_requests.feature Usage: spec (FILE|DIRECTORY|GLOB)+ [options] -p, --pattern [PATTERN] Limit files loaded to those matching this pattern. Defaults to '**/*_spec.rb' (and so on) Any ideas? Joe From dchelimsky at gmail.com Sat Oct 4 21:41:36 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Oct 2008 20:41:36 -0500 Subject: [rspec-users] problem running cucumber In-Reply-To: References: Message-ID: <57c63afe0810041841o30e24fedka1ae4d42d7438cb5@mail.gmail.com> On Sat, Oct 4, 2008 at 6:05 PM, Joe Van Dyk wrote: > When I run 'rake features', this is the output I get: > > /usr/local/bin/ruby -I > "/home/joe/projects/voxy/vendor/plugins/cucumber/lib" > "/home/joe/projects/voxy/vendor/plugins/cucumber/bin/cucumber" > --format pretty --require features/steps/env.rb --require > features/steps/request_steps.rb --require > features/steps/common_webrat.rb features/manage_requests.feature > Usage: spec (FILE|DIRECTORY|GLOB)+ [options] > -p, --pattern [PATTERN] Limit files loaded to those > matching this pattern. Defaults to '**/*_spec.rb' > (and so on) > > Any ideas? This is a bug I introduced to rspec AFTER the last release (1.1.8) so it's only affecting you if you've grabbed source since then. Fix in the works. > > Joe > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Oct 4 21:59:38 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 4 Oct 2008 20:59:38 -0500 Subject: [rspec-users] problem running cucumber In-Reply-To: <57c63afe0810041841o30e24fedka1ae4d42d7438cb5@mail.gmail.com> References: <57c63afe0810041841o30e24fedka1ae4d42d7438cb5@mail.gmail.com> Message-ID: <57c63afe0810041859q6ecf8e1cg6955b5960ce62528@mail.gmail.com> On Sat, Oct 4, 2008 at 8:41 PM, David Chelimsky wrote: > On Sat, Oct 4, 2008 at 6:05 PM, Joe Van Dyk wrote: >> When I run 'rake features', this is the output I get: >> >> /usr/local/bin/ruby -I >> "/home/joe/projects/voxy/vendor/plugins/cucumber/lib" >> "/home/joe/projects/voxy/vendor/plugins/cucumber/bin/cucumber" >> --format pretty --require features/steps/env.rb --require >> features/steps/request_steps.rb --require >> features/steps/common_webrat.rb features/manage_requests.feature >> Usage: spec (FILE|DIRECTORY|GLOB)+ [options] >> -p, --pattern [PATTERN] Limit files loaded to those >> matching this pattern. Defaults to '**/*_spec.rb' >> (and so on) >> >> Any ideas? > > This is a bug I introduced to rspec AFTER the last release (1.1.8) so > it's only affecting you if you've grabbed source since then. > > Fix in the works. Fixed. git pull Cheers, David > >> >> Joe >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > From luke at lukemelia.com Sat Oct 4 23:05:47 2008 From: luke at lukemelia.com (Luke Melia) Date: Sat, 4 Oct 2008 23:05:47 -0400 Subject: [rspec-users] Webrat and submitting a form using an image In-Reply-To: <8aad12d9790121baec3cb3b3cafd3045@ruby-forum.com> References: <8aad12d9790121baec3cb3b3cafd3045@ruby-forum.com> Message-ID: On Oct 4, 2008, at 12:09 PM, Fernando Perez wrote: > Webrat doesn't seem to be able to handle the submit of a form > through an > image input. Fernando, this should work, at least in trunk webrat. For example, see the specs near: http://github.com/brynary/webrat/tree/master/spec/api/clicks_button_spec.rb#L337 Are you seeing another behavior? Cheers from NYC, Luke -- Luke Melia luke at lukemelia.com http://www.lukemelia.com/ From raasdnil at gmail.com Sun Oct 5 06:41:08 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Sun, 5 Oct 2008 21:41:08 +1100 Subject: [rspec-users] Best place to set load path for new spec folders Message-ID: <57a815bf0810050341w7f5078bejc19f9748c17bbcfd@mail.gmail.com> I have a bunch of observers in RAILS_ROOT/spec/observers/ as well as in some sub directories for some name spaced observers. For example: \spec \observers person_observer_spec.rb \admin user_observer_spec.rb autospec doesn't seem to want to pick them up. The box I am talking about is on RSpec 1.1.5. How to tell autospec to go hunt down the observers tree ? Mikel From greg.hauptmann.ruby at gmail.com Sun Oct 5 07:26:15 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Sun, 5 Oct 2008 21:26:15 +1000 Subject: [rspec-users] would I stub an existing class method out or use fixtures in this scenario? Message-ID: Hi, Would the BDD experts recommend I either (a) use fixtures for data or (b) stub out existing class methods for such a scenario? Scenario = Working on a "populate for future transactions" method & testing this. It generates "transactions" table rows as part of the test. To do this it (a) requires BankAccount table row entries to be in place to ensure foreign key constraints allow new "transaction" to be added, i.e. with a bank_account_id which exists, and (b) ability to call the BankAccount class method "balance?(date)". Discussion = I've set things up with dynamic fixture type data using Ruby code (in the before(:each) do), however I was wondering whether in fact I should not be having to create such data (i.e. bank_account rows, when the real code under test is generating new "transaction" rows) but rather be "stubbing" out the existing methods on the BankAccount model (e.g. BankAccount.any_instance.stubs(:balance?).returns()). Do people normal use the "any_instance.stubs" approach to stub out existing classes already developed, as a means to minimize associated test data that may have to be put in place to allow the test to work? Any other comments/suggestions re best practice here? Tks From lists at ruby-forum.com Sun Oct 5 10:55:07 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Sun, 5 Oct 2008 16:55:07 +0200 Subject: [rspec-users] Webrat and submitting a form using an image In-Reply-To: References: <8aad12d9790121baec3cb3b3cafd3045@ruby-forum.com> Message-ID: Thank you very much for the link! Actually my problem was that I have 2 buttons on the page, and the only way to distinguish them is to use the alt tag which I wasn't currently using. Now everything works perfectly. -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Sun Oct 5 11:11:38 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 5 Oct 2008 08:11:38 -0700 Subject: [rspec-users] What questions do you have about testing? Message-ID: <810a540e0810050811v6c288c29vb1d0ad16d245ec1f@mail.gmail.com> Hey everyone, We're doing a panel on testing at the Voices That Matter conference (http://www.voicesthatmatter.com/ruby2008/ - you should go :). Obie set up a google moderator thing [1] to collect questions for the panel. I invite you all to put some questions up on there. They can be questions that you want to learn the answer to, or you just think that the answer would be beneficial to the community as a whole (that is, you already know it but you wish others did too :). And please add questions even if you're not going...there may be a video of these things (I dunno yet, but I'm guessing so), and I'll definitely answer them on my blog. If you're interested in attending the conference, check out my blog post [2]. I'll be doing a half-day workshop on BDD, then sitting on this testing panel, and finally on the last day I'm doing a breakfast with the speakers where we sit down and talk about whatever. Would love to see you all there. Pat [1] http://moderator.appspot.com/#e%253Dagltb2RlcmF0b3JyDQsSBlNlcmllcxjPBQw%252Bt%253Dagltb2RlcmF0b3JyDAsSBVRvcGljGI0EDA%252Bv%253D0%252Bs%253D1 [2] http://evang.eli.st/blog/2008/10/5/the-next-conference-you-should-go-to From lists at ruby-forum.com Sun Oct 5 11:45:47 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Sun, 5 Oct 2008 17:45:47 +0200 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: <57c63afe0810041147x552e0e06n3e9e2e1b0fb0ae6b@mail.gmail.com> References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> <71166b3b0810041106n7e739424x95915be4365f0f08@mail.gmail.com> <57c63afe0810041138x67a6b634k57d99df61c32487d@mail.gmail.com> <57c63afe0810041141o62051affof3c78192af0990f4@mail.gmail.com> <71166b3b0810041143j3072773aoa560f0040ba4bdbc@mail.gmail.com> <57c63afe0810041147x552e0e06n3e9e2e1b0fb0ae6b@mail.gmail.com> Message-ID: Hi, Going plugin-less for RSpec went 99% smoothly, here is the only error message I got: $ ./script/generate rspec Gem::SourceIndex#search support for Regexp patterns is deprecated /usr/local/ruby/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/rails_generator/lookup.rb:211:in `each' is outdated -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sun Oct 5 11:48:55 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 5 Oct 2008 10:48:55 -0500 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> <71166b3b0810041106n7e739424x95915be4365f0f08@mail.gmail.com> <57c63afe0810041138x67a6b634k57d99df61c32487d@mail.gmail.com> <57c63afe0810041141o62051affof3c78192af0990f4@mail.gmail.com> <71166b3b0810041143j3072773aoa560f0040ba4bdbc@mail.gmail.com> <57c63afe0810041147x552e0e06n3e9e2e1b0fb0ae6b@mail.gmail.com> Message-ID: <57c63afe0810050848k2e250cb6kaca60c99d068b96f@mail.gmail.com> On Sun, Oct 5, 2008 at 10:45 AM, Fernando Perez wrote: > Hi, > > Going plugin-less for RSpec went 99% smoothly, here is the only error > message I got: > > $ ./script/generate rspec > Gem::SourceIndex#search support for Regexp patterns is deprecated > /usr/local/ruby/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/rails_generator/lookup.rb:211:in > `each' is outdated That's actually not related to rspec. The deprecation notice is coming from Rubygems-1.3, and is referencing rails code, not rspec code. > -- > 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 Sun Oct 5 11:51:07 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Sun, 5 Oct 2008 17:51:07 +0200 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> <71166b3b0810041106n7e739424x95915be4365f0f08@mail.gmail.com> <57c63afe0810041138x67a6b634k57d99df61c32487d@mail.gmail.com> <57c63afe0810041141o62051affof3c78192af0990f4@mail.gmail.com> <71166b3b0810041143j3072773aoa560f0040ba4bdbc@mail.gmail.com> <57c63afe0810041147x552e0e06n3e9e2e1b0fb0ae6b@mail.gmail.com> Message-ID: <2fdafcacb7847c06bed7008e97b4300a@ruby-forum.com> By the way for a RoR application, can I also go plugin-less for Webrat and Cucumber? From what I understand I still need to install these two as plugins. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sun Oct 5 11:58:03 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 5 Oct 2008 10:58:03 -0500 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: <2fdafcacb7847c06bed7008e97b4300a@ruby-forum.com> References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> <71166b3b0810041106n7e739424x95915be4365f0f08@mail.gmail.com> <57c63afe0810041138x67a6b634k57d99df61c32487d@mail.gmail.com> <57c63afe0810041141o62051affof3c78192af0990f4@mail.gmail.com> <71166b3b0810041143j3072773aoa560f0040ba4bdbc@mail.gmail.com> <57c63afe0810041147x552e0e06n3e9e2e1b0fb0ae6b@mail.gmail.com> <2fdafcacb7847c06bed7008e97b4300a@ruby-forum.com> Message-ID: <57c63afe0810050858h75ee11baj6066e64880c482a8@mail.gmail.com> On Sun, Oct 5, 2008 at 10:51 AM, Fernando Perez wrote: > By the way for a RoR application, can I also go plugin-less for Webrat > and Cucumber? From what I understand I still need to install these two > as plugins. Why ask us when you can ask rubygems? $ gem q -drn cucumber $ gem q -drn webrat 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 lists at ruby-forum.com Sun Oct 5 12:20:12 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Sun, 5 Oct 2008 18:20:12 +0200 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: <57c63afe0810050858h75ee11baj6066e64880c482a8@mail.gmail.com> References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> <71166b3b0810041106n7e739424x95915be4365f0f08@mail.gmail.com> <57c63afe0810041138x67a6b634k57d99df61c32487d@mail.gmail.com> <57c63afe0810041141o62051affof3c78192af0990f4@mail.gmail.com> <71166b3b0810041143j3072773aoa560f0040ba4bdbc@mail.gmail.com> <57c63afe0810041147x552e0e06n3e9e2e1b0fb0ae6b@mail.gmail.com> <2fdafcacb7847c06bed7008e97b4300a@ruby-forum.com> <57c63afe0810050858h75ee11baj6066e64880c482a8@mail.gmail.com> Message-ID: <1ddb091cab037672a49b6f781888abbf@ruby-forum.com> > Why ask us when you can ask rubygems? > Well I prefer to ask (and sound stupid 5 minutes) than not ask (and be stupid all my life), that's the way I work. From the cucumber github wiki located at: http://github.com/aslakhellesoy/cucumber/wikis -- Installation (Rails people ? see Ruby on Rails). After you have installed Ruby or JRuby ? install Cucumber with the following command: Ruby: gem install cucumber -- When I go to the Ruby on Rails wiki page, Aslak says to install Cucumber as a plugin. Therefore I was wondering if for a Rails app, installing Cucumber as a gem was okay. In the past, even though the RSpec gem existed, it was recommended to install the plugin version of rspec if it was going to be used with a Rails app. -- Posted via http://www.ruby-forum.com/. From aslak.hellesoy at gmail.com Sun Oct 5 12:55:40 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sun, 5 Oct 2008 18:55:40 +0200 Subject: [rspec-users] Cucumber 0.1.7 released Message-ID: <8d961d900810050955x1f302c8aj307a5032bb259e98@mail.gmail.com> I just released 0.1.7 as a gem. (As usual, it will take a few hours before it rsyncs around the world). Changes are here: http://github.com/aslakhellesoy/cucumber/tree/v0.1.7/History.txt Thanks to everyone who's contributed with feedback and patches! Cheers, Aslak From lists at ruby-forum.com Sun Oct 5 13:29:00 2008 From: lists at ruby-forum.com (Fernando Perez) Date: Sun, 5 Oct 2008 19:29:00 +0200 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: <1ddb091cab037672a49b6f781888abbf@ruby-forum.com> References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <85d99afe0810031357g13eee9acid02d332db0844146@mail.gmail.com> <57c63afe0810040958od3e7d5fif362a104c5309d34@mail.gmail.com> <71166b3b0810041106n7e739424x95915be4365f0f08@mail.gmail.com> <57c63afe0810041138x67a6b634k57d99df61c32487d@mail.gmail.com> <57c63afe0810041141o62051affof3c78192af0990f4@mail.gmail.com> <71166b3b0810041143j3072773aoa560f0040ba4bdbc@mail.gmail.com> <57c63afe0810041147x552e0e06n3e9e2e1b0fb0ae6b@mail.gmail.com> <2fdafcacb7847c06bed7008e97b4300a@ruby-forum.com> <57c63afe0810050858h75ee11baj6066e64880c482a8@mail.gmail.com> <1ddb091cab037672a49b6f781888abbf@ruby-forum.com> Message-ID: I have removed the plugins for both cucumber and webrat. Now I am having the following error message when running rake features or ./script/generate cucumber: -- /usr/local/ruby/lib/ruby/gems/1.8/gems/cucumber-0.1.6/lib/cucumber/cli.rb:83:in `read': No such file or directory - cucumber.yml (Errno::ENOENT) from /usr/local/ruby/lib/ruby/gems/1.8/gems/cucumber-0.1.6/lib/cucumber/cli.rb:83:in `parse_args_from_profile' -- -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Sun Oct 5 13:48:29 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 5 Oct 2008 12:48:29 -0500 Subject: [rspec-users] Difference between gem and plugin In-Reply-To: <1ddb091cab037672a49b6f781888abbf@ruby-forum.com> References: <37073F11-8C89-4D65-BC64-781380ECC36C@gmail.com> <71166b3b0810041106n7e739424x95915be4365f0f08@mail.gmail.com> <57c63afe0810041138x67a6b634k57d99df61c32487d@mail.gmail.com> <57c63afe0810041141o62051affof3c78192af0990f4@mail.gmail.com> <71166b3b0810041143j3072773aoa560f0040ba4bdbc@mail.gmail.com> <57c63afe0810041147x552e0e06n3e9e2e1b0fb0ae6b@mail.gmail.com> <2fdafcacb7847c06bed7008e97b4300a@ruby-forum.com> <57c63afe0810050858h75ee11baj6066e64880c482a8@mail.gmail.com> <1ddb091cab037672a49b6f781888abbf@ruby-forum.com> Message-ID: <57c63afe0810051048o61ffb447qf5b12eac7750a677@mail.gmail.com> On Sun, Oct 5, 2008 at 11:20 AM, Fernando Perez wrote: >> Why ask us when you can ask rubygems? >> > Well I prefer to ask (and sound stupid 5 minutes) than not ask (and be > stupid all my life), that's the way I work. From the cucumber github > wiki located at: http://github.com/aslakhellesoy/cucumber/wikis > > -- > Installation > > (Rails people ? see Ruby on Rails). > > After you have installed Ruby or JRuby ? install Cucumber with the > following command: > Ruby: > > gem install cucumber > -- > > When I go to the Ruby on Rails wiki page, Aslak says to install Cucumber > as a plugin. Therefore I was wondering if for a Rails app, installing > Cucumber as a gem was okay. > > In the past, even though the RSpec gem existed, it was recommended to > install the plugin version of rspec if it was going to be used with a > Rails app. Didn't mean to make you feel bad or stupid. Was just offering you a way to answer at least part of your question. Teach a man to fish, and all. That said, here's some fish: As of 1.1.5, rspec-rails is now released as a gem. If you're using rails >= 2.0, you can use rspec/rspec-rails gems because the rspec generator (script/generate rspec) is visible, and the generated files are all you need in the rails app. Cucumber and webrat are both released as gems. My recommendation is to use gems for all these tools, except in cases where you need functionality that is in git, but not in the latest gem. Even then, I'd recommend downloading source from git and building the gem locally rather than adding the code to your repo. Of course, this all assumes just a local build on your development machine. If you've got a build machine running scenarios and code examples, you might find it easier to keep unreleased code in your app. Another option would be to use gems by default, and then store them in vendor/gems instead of vendor/plugins when you need functionality between releases. HTH, David From matt at mattwynne.net Sun Oct 5 16:37:55 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 5 Oct 2008 21:37:55 +0100 Subject: [rspec-users] Cucumber 0.1.7 released In-Reply-To: <8d961d900810050955x1f302c8aj307a5032bb259e98@mail.gmail.com> References: <8d961d900810050955x1f302c8aj307a5032bb259e98@mail.gmail.com> Message-ID: Shame we didn't see you at Citcon, Aslak, but I'm glad to hear you were doing something useful instead! Looking forward to playing with the new toys. cheers, Matt On 5 Oct 2008, at 17:55, aslak hellesoy wrote: > I just released 0.1.7 as a gem. (As usual, it will take a few hours > before it rsyncs around the world). > > Changes are here: > http://github.com/aslakhellesoy/cucumber/tree/v0.1.7/History.txt > > Thanks to everyone who's contributed with feedback and patches! > > Cheers, > Aslak > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Sun Oct 5 16:47:52 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 5 Oct 2008 21:47:52 +0100 Subject: [rspec-users] would I stub an existing class method out or use fixtures in this scenario? In-Reply-To: References: Message-ID: <8C0E2F74-13A1-4CD7-8C8B-ADCA9A5B7E4A@mattwynne.net> On 5 Oct 2008, at 12:26, Greg Hauptmann wrote: > BankAccount.any_instance.stubs(:balance?).returns()). > > Do people normal use the "any_instance.stubs" approach to stub out > existing classes already developed, as a means to minimize associated Is this any_instance thing in the rspec mocking framework now? I vaguely remember wanting this a few weeks ago and it was only in mocha or another of the competing mocking frameworks. From mailing_lists at railsnewbie.com Sun Oct 5 16:51:48 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 5 Oct 2008 16:51:48 -0400 Subject: [rspec-users] What questions do you have about testing? In-Reply-To: <810a540e0810050811v6c288c29vb1d0ad16d245ec1f@mail.gmail.com> References: <810a540e0810050811v6c288c29vb1d0ad16d245ec1f@mail.gmail.com> Message-ID: <1388396A-3957-491D-9561-46AD7D8ADFB8@railsnewbie.com> On Oct 5, 2008, at 11:11 AM, Pat Maddox wrote: > Hey everyone, > > We're doing a panel on testing at the Voices That Matter conference > (http://www.voicesthatmatter.com/ruby2008/ - you should go :). Obie > set > up a google moderator thing [1] to collect questions for the panel. I > invite you all to put some questions up on there. They can be > questions > that you want to learn the answer to, or you just think that the > answer > would be beneficial to the community as a whole (that is, you already > know it but you wish others did too :). And please add questions even > if you're not going...there may be a video of these things (I dunno > yet, > but I'm guessing so), and I'll definitely answer them on my blog. Didn't see any where to submit those questions, so here it goes: I'm curious as to what people are doing to speed up their tests. Often mocks are used, but I've always found black-box testing to be both more intuitive and to serve as better regression tests going forward. Scott From matt at mattwynne.net Sun Oct 5 16:52:05 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 5 Oct 2008 21:52:05 +0100 Subject: [rspec-users] would I stub an existing class method out or use fixtures in this scenario? In-Reply-To: References: Message-ID: <1B6EFF06-00D8-48DA-A707-03CDDA79A5D6@mattwynne.net> On 5 Oct 2008, at 12:26, Greg Hauptmann wrote: > Hi, > > Would the BDD experts recommend I either (a) use fixtures for data or > (b) stub out existing class methods for such a scenario? > > Scenario = Working on a "populate for future transactions" method & > testing this. It generates "transactions" table rows as part of the > test. To do this it (a) requires BankAccount table row entries to be > in place to ensure foreign key constraints allow new "transaction" to > be added, i.e. with a bank_account_id which exists, and (b) ability to > call the BankAccount class method "balance?(date)". > > Discussion = I've set things up with dynamic fixture type data using > Ruby code (in the before(:each) do), however I was wondering whether > in fact I should not be having to create such data (i.e. bank_account > rows, when the real code under test is generating new "transaction" > rows) but rather be "stubbing" out the existing methods on the > BankAccount model (e.g. > BankAccount.any_instance.stubs(:balance?).returns()). > > Do people normal use the "any_instance.stubs" approach to stub out > existing classes already developed, as a means to minimize associated > test data that may have to be put in place to allow the test to work? > Any other comments/suggestions re best practice here? I think you should be able to do this with mocks, but it's not going to be easy. Are you using ActiveRecord? I might be being thick, but I'm not really clear what the desired behaviour is from the question. Can you maybe post a spec --format specdoc of the relevant specs? From mailing_lists at railsnewbie.com Sun Oct 5 16:56:53 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 5 Oct 2008 16:56:53 -0400 Subject: [rspec-users] would I stub an existing class method out or use fixtures in this scenario? In-Reply-To: <8C0E2F74-13A1-4CD7-8C8B-ADCA9A5B7E4A@mattwynne.net> References: <8C0E2F74-13A1-4CD7-8C8B-ADCA9A5B7E4A@mattwynne.net> Message-ID: <95D1E4A1-52A3-459A-86F5-68C483B36B4A@railsnewbie.com> On Oct 5, 2008, at 4:47 PM, Matt Wynne wrote: > On 5 Oct 2008, at 12:26, Greg Hauptmann wrote: >> BankAccount.any_instance.stubs(:balance?).returns()). >> >> Do people normal use the "any_instance.stubs" approach to stub out >> existing classes already developed, as a means to minimize associated > > Is this any_instance thing in the rspec mocking framework now? I > vaguely remember wanting this a few weeks ago and it was only in > mocha or another of the competing mocking frameworks. No, it isn't. Most consider it a code smell, which is why it hasn't been high on the priority list. I submitted a patch a while back for this (see: http://rspec.lighthouseapp.com/projects/5645/tickets/28-6791-stub-return-values-for-all-instances-of-a-class#ticket-28-5) , which wasn't accepted into core for asthetic reasons. Feel free to revise it ;) Scott From matt at mattwynne.net Sun Oct 5 17:04:11 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 5 Oct 2008 22:04:11 +0100 Subject: [rspec-users] would I stub an existing class method out or use fixtures in this scenario? In-Reply-To: <95D1E4A1-52A3-459A-86F5-68C483B36B4A@railsnewbie.com> References: <8C0E2F74-13A1-4CD7-8C8B-ADCA9A5B7E4A@mattwynne.net> <95D1E4A1-52A3-459A-86F5-68C483B36B4A@railsnewbie.com> Message-ID: <3607ECD2-AAAF-4428-83CE-E52CE4DD1473@mattwynne.net> On 5 Oct 2008, at 21:56, Scott Taylor wrote: > > On Oct 5, 2008, at 4:47 PM, Matt Wynne wrote: > >> On 5 Oct 2008, at 12:26, Greg Hauptmann wrote: >>> BankAccount.any_instance.stubs(:balance?).returns()). >>> >>> Do people normal use the "any_instance.stubs" approach to stub out >>> existing classes already developed, as a means to minimize >>> associated >> >> Is this any_instance thing in the rspec mocking framework now? I >> vaguely remember wanting this a few weeks ago and it was only in >> mocha or another of the competing mocking frameworks. > > No, it isn't. Most consider it a code smell, which is why it hasn't > been high on the priority list. So does this suggest there's something wrong with Greg's design? Does he maybe need to sprout a new class to handle the generation of the transactions, and pass that a specific BankAccount instance? From mailing_lists at railsnewbie.com Sun Oct 5 17:29:46 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 5 Oct 2008 17:29:46 -0400 Subject: [rspec-users] would I stub an existing class method out or use fixtures in this scenario? In-Reply-To: <3607ECD2-AAAF-4428-83CE-E52CE4DD1473@mattwynne.net> References: <8C0E2F74-13A1-4CD7-8C8B-ADCA9A5B7E4A@mattwynne.net> <95D1E4A1-52A3-459A-86F5-68C483B36B4A@railsnewbie.com> <3607ECD2-AAAF-4428-83CE-E52CE4DD1473@mattwynne.net> Message-ID: <5D92AB44-7067-4F21-ACA0-53B900AC2F9E@railsnewbie.com> On Oct 5, 2008, at 5:04 PM, Matt Wynne wrote: > On 5 Oct 2008, at 21:56, Scott Taylor wrote: > >> >> On Oct 5, 2008, at 4:47 PM, Matt Wynne wrote: >> >>> On 5 Oct 2008, at 12:26, Greg Hauptmann wrote: >>>> BankAccount.any_instance.stubs(:balance?).returns()). >>>> >>>> Do people normal use the "any_instance.stubs" approach to stub out >>>> existing classes already developed, as a means to minimize >>>> associated >>> >>> Is this any_instance thing in the rspec mocking framework now? I >>> vaguely remember wanting this a few weeks ago and it was only in >>> mocha or another of the competing mocking frameworks. >> >> No, it isn't. Most consider it a code smell, which is why it >> hasn't been high on the priority list. > > So does this suggest there's something wrong with Greg's design? > Does he maybe need to sprout a new class to handle the generation of > the transactions, and pass that a specific BankAccount instance? Well, Look at this comment previously written in the thread: >>>> Do people normal use the "any_instance.stubs" approach to stub out >>>> existing classes already developed, as a means to minimize >>>> associated Notice "existing classes" - this usually means classes that haven't been developed test first. if they had been developed test first, they'd probably be trivial to test with. Scott From pergesu at gmail.com Sun Oct 5 19:22:21 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 05 Oct 2008 16:22:21 -0700 Subject: [rspec-users] What questions do you have about testing? In-Reply-To: <1388396A-3957-491D-9561-46AD7D8ADFB8@railsnewbie.com> (Scott Taylor's message of "Sun\, 5 Oct 2008 16\:51\:48 -0400") References: <810a540e0810050811v6c288c29vb1d0ad16d245ec1f@mail.gmail.com> <1388396A-3957-491D-9561-46AD7D8ADFB8@railsnewbie.com> Message-ID: Scott Taylor writes: > On Oct 5, 2008, at 11:11 AM, Pat Maddox wrote: > >> Hey everyone, >> >> We're doing a panel on testing at the Voices That Matter conference >> (http://www.voicesthatmatter.com/ruby2008/ - you should go :). Obie >> set >> up a google moderator thing [1] to collect questions for the panel. I >> invite you all to put some questions up on there. They can be >> questions >> that you want to learn the answer to, or you just think that the >> answer >> would be beneficial to the community as a whole (that is, you already >> know it but you wish others did too :). And please add questions even >> if you're not going...there may be a video of these things (I dunno >> yet, >> but I'm guessing so), and I'll definitely answer them on my blog. > > Didn't see any where to submit those questions, so here it goes: > > I'm curious as to what people are doing to speed up their tests. > Often mocks are used, but I've always found black-box testing to be > both more intuitive and to serve as better regression tests going > forward. > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Scott, The link is http://moderator.appspot.com/#e%253Dagltb2RlcmF0b3JyDQsSBlNlcmllcxjPBQw%252Bt%253Dagltb2RlcmF0b3JyDAsSBVRvcGljGI0EDA%252Bv%253D0%252Bs%253D1 You have to be signed into a gmail account I guess, and at the bottom there's a button that says "suggest a question." Would you mind putting your question on there? Pat From greg.hauptmann.ruby at gmail.com Mon Oct 6 00:26:06 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Mon, 6 Oct 2008 14:26:06 +1000 Subject: [rspec-users] would I stub an existing class method out or use fixtures in this scenario? In-Reply-To: <5D92AB44-7067-4F21-ACA0-53B900AC2F9E@railsnewbie.com> References: <8C0E2F74-13A1-4CD7-8C8B-ADCA9A5B7E4A@mattwynne.net> <95D1E4A1-52A3-459A-86F5-68C483B36B4A@railsnewbie.com> <3607ECD2-AAAF-4428-83CE-E52CE4DD1473@mattwynne.net> <5D92AB44-7067-4F21-ACA0-53B900AC2F9E@railsnewbie.com> Message-ID: Hi guys, I'll try to put some clarifying comments here re my question: (a) "any_instance.stubs" - this already exists in Mocha (http://mocha.rubyforge.org/classes/Class.html#M000001) (b) where I had "do people normal use the "any_instance.stubs" approach to stub out existing classes already developed" - this should have read for "an existing method in an existing class". In my case I had a method in the BankAccount model which requires "bankaccounts" table rows to be populated, so I was asking re stubbing this out. (c) as a quick overview of the key elements of my question, I have: * "recurrings" table - has details of recurring items (e.g. food, $200, every week). Has foreign key to BankAccount re where the expense is likely to turn up against. * "transactions" table - has actual plus future projected transactions. Has BankAccount foreign key. * "bank_accounts" table - ID and name for each bank account * BankAccount model - Has method "balance?(date=Today.now.to_date) which gets balance for that bank account for that date (by looking at the transactions table) * "populate_projections" method - this is what I want to test. It basically: - reads input from "recurrings" table - creates "transactions" table rows - during the process calls BankAccount.balance? method So overall I'm pondering how to test my "populate_projections" method in a manner that minimises the amount of dynamically generated fixtures I have to create (currently I create recurring items & bank_accounts), and also the reliance on the BankAccount.balance? method (and it's correct operation). My specific question was about how to stub out the already existing BankAccount.balance? method using "any_instance.stubs". Any feedback welcome on what the best practice would be here. Cheers Greg From lists at ruby-forum.com Mon Oct 6 10:27:11 2008 From: lists at ruby-forum.com (=?utf-8?Q?R=c3=a9mi_Gagnon?=) Date: Mon, 6 Oct 2008 16:27:11 +0200 Subject: [rspec-users] Newbie question about mock_model and should_receive.... Message-ID: <8c906b7cd7183e132a9db7a30ceeef4c@ruby-forum.com> Hello, I mocked a model and I need to test when I set for instance '000' to an attribute 'A' that B attibute is set to '1111'. I don't want to stub or mock the B(accessors) to that value cause I want to make sure my controller will do that. I know its dummy question. suggestions? R?mi -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Mon Oct 6 11:03:46 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 06 Oct 2008 08:03:46 -0700 Subject: [rspec-users] Newbie question about mock_model and should_receive.... In-Reply-To: <8c906b7cd7183e132a9db7a30ceeef4c@ruby-forum.com> (=?utf-8?Q?=22R=C3=A9mi?= Gagnon"'s message of "Mon\, 6 Oct 2008 16\:27\:11 +0200") References: <8c906b7cd7183e132a9db7a30ceeef4c@ruby-forum.com> Message-ID: R?mi Gagnon writes: > Hello, > > I mocked a model and I need to test when I set for instance '000' to an > attribute 'A' that B attibute is set to '1111'. I don't want to stub or > mock the B(accessors) to that value cause I want to make sure my > controller will do that. > > I know its dummy question. > > suggestions? > > > R?mi In that case, you want to use the real object. The spec would be pretty simple: it "should set B when A is set" do MyModel.new(:a => '000').b.should == '1111' end Pat From mark.thomson at ieee.org Mon Oct 6 12:29:38 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Mon, 06 Oct 2008 11:29:38 -0500 Subject: [rspec-users] Uninitialized constant Spec:Story Message-ID: <48EA3CF2.6070303@ieee.org> Hi, I'm fairly new to Rails and v. new to RSpec. Think it looks pretty useful and so I'm trying it out for the first time. I have installed the rspec-rails gem and created a simple plain text my_story file and my_story.rb file along the lines described here - http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app. When I run stories/my_story.rb it blows up and the thing that seems most significant in the error messages is "uninitialized constant Spec::Story (NameError)" which seems to originate from story_adapter.rb:66, where the class Spec::Story::Runner::ScenarioRunner is defined. Would appreciate any guidance towards a resolution of this issue. Thanks, Mark From dchelimsky at gmail.com Mon Oct 6 13:20:08 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 6 Oct 2008 12:20:08 -0500 Subject: [rspec-users] Uninitialized constant Spec:Story In-Reply-To: <48EA3CF2.6070303@ieee.org> References: <48EA3CF2.6070303@ieee.org> Message-ID: <57c63afe0810061020w586cc559od20285ed85a13d39@mail.gmail.com> On Mon, Oct 6, 2008 at 11:29 AM, Mark Thomson wrote: > Hi, I'm fairly new to Rails and v. new to RSpec. Think it looks pretty > useful and so I'm trying it out for the first time. I have installed the > rspec-rails gem and created a simple plain text my_story file and > my_story.rb file along the lines described here - > http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app. > > When I run stories/my_story.rb it blows up and the thing that seems most > significant in the error messages is "uninitialized constant Spec::Story > (NameError)" which seems to originate from story_adapter.rb:66, where the > class Spec::Story::Runner::ScenarioRunner is defined. > > Would appreciate any guidance towards a resolution of this issue. Have you done this: script/generate rspec > > Thanks, > > Mark > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mark.thomson at ieee.org Mon Oct 6 13:41:10 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Mon, 06 Oct 2008 12:41:10 -0500 Subject: [rspec-users] Uninitialized constant Spec:Story In-Reply-To: <57c63afe0810061020w586cc559od20285ed85a13d39@mail.gmail.com> References: <48EA3CF2.6070303@ieee.org> <57c63afe0810061020w586cc559od20285ed85a13d39@mail.gmail.com> Message-ID: <48EA4DB6.9030305@ieee.org> Indeed I have. Just re-ran it to make sure. No change in behavior. Mark. David Chelimsky wrote: > On Mon, Oct 6, 2008 at 11:29 AM, Mark Thomson wrote: > >> Hi, I'm fairly new to Rails and v. new to RSpec. Think it looks pretty >> useful and so I'm trying it out for the first time. I have installed the >> rspec-rails gem and created a simple plain text my_story file and >> my_story.rb file along the lines described here - >> http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app. >> >> When I run stories/my_story.rb it blows up and the thing that seems most >> significant in the error messages is "uninitialized constant Spec::Story >> (NameError)" which seems to originate from story_adapter.rb:66, where the >> class Spec::Story::Runner::ScenarioRunner is defined. >> >> Would appreciate any guidance towards a resolution of this issue. >> > > Have you done this: > > script/generate rspec > > >> Thanks, >> >> Mark >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark at mwilden.com Mon Oct 6 13:50:46 2008 From: mark at mwilden.com (Mark Wilden) Date: Mon, 6 Oct 2008 10:50:46 -0700 Subject: [rspec-users] would I stub an existing class method out or use fixtures in this scenario? In-Reply-To: References: <8C0E2F74-13A1-4CD7-8C8B-ADCA9A5B7E4A@mattwynne.net> <95D1E4A1-52A3-459A-86F5-68C483B36B4A@railsnewbie.com> <3607ECD2-AAAF-4428-83CE-E52CE4DD1473@mattwynne.net> <5D92AB44-7067-4F21-ACA0-53B900AC2F9E@railsnewbie.com> Message-ID: <3c30da400810061050t656a9660q441732248165c00d@mail.gmail.com> On Sun, Oct 5, 2008 at 9:26 PM, Greg Hauptmann < greg.hauptmann.ruby at gmail.com> wrote: > So overall I'm pondering how to test my "populate_projections" method > in a manner that minimises the amount of dynamically generated > fixtures I have to create (currently I create recurring items & > bank_accounts), and also the reliance on the BankAccount.balance? > method (and it's correct operation). My specific question was about > how to stub out the already existing BankAccount.balance? method using > "any_instance.stubs". > In general, I do something like bank_account = mock_model(BankAccount, :balance => 12) BankAccount.stub!(:find).with(bank_account.id).and_return bank_account Is that what you're talking about? As opposed to bank_account = BankAcount.create! Transaction.create!(:back_account_id => bank_account.id, :amount => 12) Are you asking which one is better, or am I totally off on the wrong track? :) Otherwise, I'd pick the first approach, because it's faster. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.thomson at ieee.org Mon Oct 6 14:19:15 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Mon, 06 Oct 2008 13:19:15 -0500 Subject: [rspec-users] Uninitialized constant Spec:Story In-Reply-To: <48EA4DB6.9030305@ieee.org> References: <48EA3CF2.6070303@ieee.org> <57c63afe0810061020w586cc559od20285ed85a13d39@mail.gmail.com> <48EA4DB6.9030305@ieee.org> Message-ID: <48EA56A3.2060503@ieee.org> FWIW, I'm running Rails 2.1 on Windows. I have tried running RSpec on two completely separate Rails installations on different machines and get the same result. Mark. Mark Thomson wrote: > Indeed I have. Just re-ran it to make sure. No change in behavior. > > Mark. > > > > David Chelimsky wrote: >> On Mon, Oct 6, 2008 at 11:29 AM, Mark Thomson wrote: >> >>> Hi, I'm fairly new to Rails and v. new to RSpec. Think it looks pretty >>> useful and so I'm trying it out for the first time. I have installed the >>> rspec-rails gem and created a simple plain text my_story file and >>> my_story.rb file along the lines described here - >>> http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app. >>> >>> When I run stories/my_story.rb it blows up and the thing that seems most >>> significant in the error messages is "uninitialized constant Spec::Story >>> (NameError)" which seems to originate from story_adapter.rb:66, where the >>> class Spec::Story::Runner::ScenarioRunner is defined. >>> >>> Would appreciate any guidance towards a resolution of this issue. >>> >> >> Have you done this: >> >> script/generate rspec >> >> >>> Thanks, >>> >>> Mark >>> >>> >>> _______________________________________________ >>> 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben at benmabey.com Mon Oct 6 14:38:31 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 06 Oct 2008 12:38:31 -0600 Subject: [rspec-users] Uninitialized constant Spec:Story In-Reply-To: <48EA56A3.2060503@ieee.org> References: <48EA3CF2.6070303@ieee.org> <57c63afe0810061020w586cc559od20285ed85a13d39@mail.gmail.com> <48EA4DB6.9030305@ieee.org> <48EA56A3.2060503@ieee.org> Message-ID: <48EA5B27.70808@benmabey.com> Mark Thomson wrote: > FWIW, I'm running Rails 2.1 on Windows. I have tried running RSpec on > two completely separate Rails installations on different machines and > get the same result. > > Mark. Please post your stories/helper.rb. -Ben > > Mark Thomson wrote: >> Indeed I have. Just re-ran it to make sure. No change in behavior. >> >> Mark. >> >> >> >> David Chelimsky wrote: >>> On Mon, Oct 6, 2008 at 11:29 AM, Mark Thomson wrote: >>> >>>> Hi, I'm fairly new to Rails and v. new to RSpec. Think it looks pretty >>>> useful and so I'm trying it out for the first time. I have installed the >>>> rspec-rails gem and created a simple plain text my_story file and >>>> my_story.rb file along the lines described here - >>>> http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app. >>>> >>>> When I run stories/my_story.rb it blows up and the thing that seems most >>>> significant in the error messages is "uninitialized constant Spec::Story >>>> (NameError)" which seems to originate from story_adapter.rb:66, where the >>>> class Spec::Story::Runner::ScenarioRunner is defined. >>>> >>>> Would appreciate any guidance towards a resolution of this issue. >>>> >>> >>> Have you done this: >>> >>> script/generate rspec >>> >>> >>>> Thanks, >>>> >>>> Mark >>>> >>>> >>>> _______________________________________________ >>>> 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 mark.thomson at ieee.org Mon Oct 6 14:52:45 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Mon, 06 Oct 2008 13:52:45 -0500 Subject: [rspec-users] Uninitialized constant Spec:Story In-Reply-To: <48EA5B27.70808@benmabey.com> References: <48EA3CF2.6070303@ieee.org> <57c63afe0810061020w586cc559od20285ed85a13d39@mail.gmail.com> <48EA4DB6.9030305@ieee.org> <48EA56A3.2060503@ieee.org> <48EA5B27.70808@benmabey.com> Message-ID: <48EA5E7D.3010603@ieee.org> stories/helper.rb is as follows - ---- ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'spec/rails/story_adapter' dir = File.dirname(__FILE__) Dir[File.expand_path("#{dir}/steps/*.rb")].uniq.each do |file| require file end ## # Run a story file relative to the stories directory. def run_local_story(filename, options={}) run File.join(File.dirname(__FILE__), filename), options end ---- Mark. Ben Mabey wrote: > Mark Thomson wrote: >> FWIW, I'm running Rails 2.1 on Windows. I have tried running RSpec on >> two completely separate Rails installations on different machines and >> get the same result. >> >> Mark. > > Please post your stories/helper.rb. > > -Ben > >> >> Mark Thomson wrote: >>> Indeed I have. Just re-ran it to make sure. No change in behavior. >>> >>> Mark. >>> >>> >>> >>> David Chelimsky wrote: >>>> On Mon, Oct 6, 2008 at 11:29 AM, Mark Thomson >>>> wrote: >>>> >>>>> Hi, I'm fairly new to Rails and v. new to RSpec. Think it looks >>>>> pretty >>>>> useful and so I'm trying it out for the first time. I have >>>>> installed the >>>>> rspec-rails gem and created a simple plain text my_story file and >>>>> my_story.rb file along the lines described here - >>>>> http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app. >>>>> >>>>> >>>>> When I run stories/my_story.rb it blows up and the thing that >>>>> seems most >>>>> significant in the error messages is "uninitialized constant >>>>> Spec::Story >>>>> (NameError)" which seems to originate from story_adapter.rb:66, >>>>> where the >>>>> class Spec::Story::Runner::ScenarioRunner is defined. >>>>> >>>>> Would appreciate any guidance towards a resolution of this issue. >>>>> >>>> >>>> Have you done this: >>>> >>>> script/generate rspec >>>> >>>> >>>>> Thanks, >>>>> >>>>> Mark >>>>> >>>>> >>>>> _______________________________________________ >>>>> 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 ben at benmabey.com Mon Oct 6 14:58:30 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 06 Oct 2008 12:58:30 -0600 Subject: [rspec-users] Uninitialized constant Spec:Story In-Reply-To: <48EA5E7D.3010603@ieee.org> References: <48EA3CF2.6070303@ieee.org> <57c63afe0810061020w586cc559od20285ed85a13d39@mail.gmail.com> <48EA4DB6.9030305@ieee.org> <48EA56A3.2060503@ieee.org> <48EA5B27.70808@benmabey.com> <48EA5E7D.3010603@ieee.org> Message-ID: <48EA5FD6.3000602@benmabey.com> Mark Thomson wrote: > stories/helper.rb is as follows - > > > ---- > ENV["RAILS_ENV"] = "test" > require File.expand_path(File.dirname(__FILE__) + > "/../config/environment") > require 'spec/rails/story_adapter' Hmm.. Shot in the dark, but try adding require 'spec/story' before the "require 'spec/rails/story_adapter'" line. -Ben > > dir = File.dirname(__FILE__) > Dir[File.expand_path("#{dir}/steps/*.rb")].uniq.each do |file| > require file > end > > ## > # Run a story file relative to the stories directory. > > def run_local_story(filename, options={}) > run File.join(File.dirname(__FILE__), filename), options > end > ---- > > > Mark. > > > Ben Mabey wrote: >> Mark Thomson wrote: >>> FWIW, I'm running Rails 2.1 on Windows. I have tried running RSpec >>> on two completely separate Rails installations on different machines >>> and get the same result. >>> >>> Mark. >> >> Please post your stories/helper.rb. >> >> -Ben >> >>> >>> Mark Thomson wrote: >>>> Indeed I have. Just re-ran it to make sure. No change in behavior. >>>> >>>> Mark. >>>> >>>> >>>> >>>> David Chelimsky wrote: >>>>> On Mon, Oct 6, 2008 at 11:29 AM, Mark Thomson >>>>> wrote: >>>>> >>>>>> Hi, I'm fairly new to Rails and v. new to RSpec. Think it looks >>>>>> pretty >>>>>> useful and so I'm trying it out for the first time. I have >>>>>> installed the >>>>>> rspec-rails gem and created a simple plain text my_story file and >>>>>> my_story.rb file along the lines described here - >>>>>> http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app. >>>>>> >>>>>> >>>>>> When I run stories/my_story.rb it blows up and the thing that >>>>>> seems most >>>>>> significant in the error messages is "uninitialized constant >>>>>> Spec::Story >>>>>> (NameError)" which seems to originate from story_adapter.rb:66, >>>>>> where the >>>>>> class Spec::Story::Runner::ScenarioRunner is defined. >>>>>> >>>>>> Would appreciate any guidance towards a resolution of this issue. >>>>>> >>>>> >>>>> Have you done this: >>>>> >>>>> script/generate rspec >>>>> >>>>> >>>>>> Thanks, >>>>>> >>>>>> Mark >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>> >>>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>>> >>>>> >>>> ------------------------------------------------------------------------ >>>> >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> ------------------------------------------------------------------------ >>> >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mark.thomson at ieee.org Mon Oct 6 15:12:41 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Mon, 06 Oct 2008 14:12:41 -0500 Subject: [rspec-users] Uninitialized constant Spec:Story In-Reply-To: <48EA5FD6.3000602@benmabey.com> References: <48EA3CF2.6070303@ieee.org> <57c63afe0810061020w586cc559od20285ed85a13d39@mail.gmail.com> <48EA4DB6.9030305@ieee.org> <48EA56A3.2060503@ieee.org> <48EA5B27.70808@benmabey.com> <48EA5E7D.3010603@ieee.org> <48EA5FD6.3000602@benmabey.com> Message-ID: <48EA6329.7000805@ieee.org> Good shot - that worked! :-) Still, I'm curious as to why. Poking around with my very rudimentary knowledge of how ruby gems work, it looks as if the files that define Spec::Stories are in the rspec gem, not the rspec-rails gem, and as far as I can see there is nothing in the skeleton files that get installed in /stories to require those files. Does this suggest that the line you recommended should be added to the release? But am I the only person to have this problem? Mark. Ben Mabey wrote: > Mark Thomson wrote: >> stories/helper.rb is as follows - >> >> >> ---- >> ENV["RAILS_ENV"] = "test" >> require File.expand_path(File.dirname(__FILE__) + >> "/../config/environment") >> require 'spec/rails/story_adapter' > > Hmm.. Shot in the dark, but try adding > require 'spec/story' > > before the "require 'spec/rails/story_adapter'" line. > > -Ben >> >> dir = File.dirname(__FILE__) >> Dir[File.expand_path("#{dir}/steps/*.rb")].uniq.each do |file| >> require file >> end >> >> ## >> # Run a story file relative to the stories directory. >> >> def run_local_story(filename, options={}) >> run File.join(File.dirname(__FILE__), filename), options >> end >> ---- >> >> >> Mark. >> >> >> Ben Mabey wrote: >>> Mark Thomson wrote: >>>> FWIW, I'm running Rails 2.1 on Windows. I have tried running RSpec >>>> on two completely separate Rails installations on different >>>> machines and get the same result. >>>> >>>> Mark. >>> >>> Please post your stories/helper.rb. >>> >>> -Ben >>> >>>> >>>> Mark Thomson wrote: >>>>> Indeed I have. Just re-ran it to make sure. No change in behavior. >>>>> >>>>> Mark. >>>>> >>>>> >>>>> >>>>> David Chelimsky wrote: >>>>>> On Mon, Oct 6, 2008 at 11:29 AM, Mark Thomson >>>>>> wrote: >>>>>> >>>>>>> Hi, I'm fairly new to Rails and v. new to RSpec. Think it looks >>>>>>> pretty >>>>>>> useful and so I'm trying it out for the first time. I have >>>>>>> installed the >>>>>>> rspec-rails gem and created a simple plain text my_story file and >>>>>>> my_story.rb file along the lines described here - >>>>>>> http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app. >>>>>>> >>>>>>> >>>>>>> When I run stories/my_story.rb it blows up and the thing that >>>>>>> seems most >>>>>>> significant in the error messages is "uninitialized constant >>>>>>> Spec::Story >>>>>>> (NameError)" which seems to originate from story_adapter.rb:66, >>>>>>> where the >>>>>>> class Spec::Story::Runner::ScenarioRunner is defined. >>>>>>> >>>>>>> Would appreciate any guidance towards a resolution of this issue. >>>>>>> >>>>>> >>>>>> Have you done this: >>>>>> >>>>>> script/generate rspec >>>>>> >>>>>> >>>>>>> Thanks, >>>>>>> >>>>>>> Mark >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> rspec-users mailing list >>>>>>> rspec-users at rubyforge.org >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>> >>>>>>> >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>> >>>>>> >>>>>> >>>>> ------------------------------------------------------------------------ >>>>> >>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> ------------------------------------------------------------------------ >>>> >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben at benmabey.com Mon Oct 6 15:28:43 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 06 Oct 2008 13:28:43 -0600 Subject: [rspec-users] Uninitialized constant Spec:Story In-Reply-To: <48EA6329.7000805@ieee.org> References: <48EA3CF2.6070303@ieee.org> <57c63afe0810061020w586cc559od20285ed85a13d39@mail.gmail.com> <48EA4DB6.9030305@ieee.org> <48EA56A3.2060503@ieee.org> <48EA5B27.70808@benmabey.com> <48EA5E7D.3010603@ieee.org> <48EA5FD6.3000602@benmabey.com> <48EA6329.7000805@ieee.org> Message-ID: <48EA66EB.4050702@benmabey.com> Mark Thomson wrote: > Good shot - that worked! :-) > > Still, I'm curious as to why. Poking around with my very rudimentary > knowledge of how ruby gems work, it looks as if the files that define > Spec::Stories are in the rspec gem, not the rspec-rails gem, and as > far as I can see there is nothing in the skeleton files that get > installed in /stories to require those files. Does this suggest > that the line you recommended should be added to the release? But am I > the only person to have this problem? > > Mark. Well, I lied- I have had that exact same problem before. So it wasn't really in the dark, but I wasn't 100% sure it was the same problem. :) I think either the helper.rb generator changed and removed the 'spec/story' line or the rails adapter changed and removed the needed require it may of once had. So the problem should be fixed in one of those places IMO. We just had a series of rspec releases and I don't know if this would qualify for another emergency fix. WDYT David or Pat? -Ben > > > > Ben Mabey wrote: >> Mark Thomson wrote: >>> stories/helper.rb is as follows - >>> >>> >>> ---- >>> ENV["RAILS_ENV"] = "test" >>> require File.expand_path(File.dirname(__FILE__) + >>> "/../config/environment") >>> require 'spec/rails/story_adapter' >> >> Hmm.. Shot in the dark, but try adding >> require 'spec/story' >> >> before the "require 'spec/rails/story_adapter'" line. >> >> -Ben >>> >>> dir = File.dirname(__FILE__) >>> Dir[File.expand_path("#{dir}/steps/*.rb")].uniq.each do |file| >>> require file >>> end >>> >>> ## >>> # Run a story file relative to the stories directory. >>> >>> def run_local_story(filename, options={}) >>> run File.join(File.dirname(__FILE__), filename), options >>> end >>> ---- >>> >>> >>> Mark. >>> >>> >>> Ben Mabey wrote: >>>> Mark Thomson wrote: >>>>> FWIW, I'm running Rails 2.1 on Windows. I have tried running RSpec >>>>> on two completely separate Rails installations on different >>>>> machines and get the same result. >>>>> >>>>> Mark. >>>> >>>> Please post your stories/helper.rb. >>>> >>>> -Ben >>>> >>>>> >>>>> Mark Thomson wrote: >>>>>> Indeed I have. Just re-ran it to make sure. No change in behavior. >>>>>> >>>>>> Mark. >>>>>> >>>>>> >>>>>> >>>>>> David Chelimsky wrote: >>>>>>> On Mon, Oct 6, 2008 at 11:29 AM, Mark Thomson >>>>>>> wrote: >>>>>>> >>>>>>>> Hi, I'm fairly new to Rails and v. new to RSpec. Think it looks >>>>>>>> pretty >>>>>>>> useful and so I'm trying it out for the first time. I have >>>>>>>> installed the >>>>>>>> rspec-rails gem and created a simple plain text my_story file and >>>>>>>> my_story.rb file along the lines described here - >>>>>>>> http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app. >>>>>>>> >>>>>>>> >>>>>>>> When I run stories/my_story.rb it blows up and the thing that >>>>>>>> seems most >>>>>>>> significant in the error messages is "uninitialized constant >>>>>>>> Spec::Story >>>>>>>> (NameError)" which seems to originate from story_adapter.rb:66, >>>>>>>> where the >>>>>>>> class Spec::Story::Runner::ScenarioRunner is defined. >>>>>>>> >>>>>>>> Would appreciate any guidance towards a resolution of this issue. >>>>>>>> >>>>>>> >>>>>>> Have you done this: >>>>>>> >>>>>>> script/generate rspec >>>>>>> >>>>>>> >>>>>>>> Thanks, >>>>>>>> >>>>>>>> Mark >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> rspec-users mailing list >>>>>>>> rspec-users at rubyforge.org >>>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>>> >>>>>>>> >>>>>>> _______________________________________________ >>>>>>> rspec-users mailing list >>>>>>> rspec-users at rubyforge.org >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>> >>>>>>> >>>>>>> >>>>>> ------------------------------------------------------------------------ >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> ------------------------------------------------------------------------ >>>>> >>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Mon Oct 6 16:07:37 2008 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 6 Oct 2008 21:07:37 +0100 Subject: [rspec-users] Uninitialized constant Spec:Story In-Reply-To: <48EA6329.7000805@ieee.org> References: <48EA3CF2.6070303@ieee.org> <57c63afe0810061020w586cc559od20285ed85a13d39@mail.gmail.com> <48EA4DB6.9030305@ieee.org> <48EA56A3.2060503@ieee.org> <48EA5B27.70808@benmabey.com> <48EA5E7D.3010603@ieee.org> <48EA5FD6.3000602@benmabey.com> <48EA6329.7000805@ieee.org> Message-ID: <8AC56AC6-F4A9-4DB6-ADBA-7AE51C0631E1@mattwynne.net> Mark, what nobody seems to a have mentioned on this thread is that you're using a branch of the story runner that's probably going to be retired. There's no reason why you should know - the rspec.info site is a bit out of date in this regard. I'd encourage you to read this: http://blog.davidchelimsky.net/2008/9/22/cucumber On 6 Oct 2008, at 20:12, Mark Thomson wrote: > Good shot - that worked! :-) > > Still, I'm curious as to why. Poking around with my very rudimentary > knowledge of how ruby gems work, it looks as if the files that > define Spec::Stories are in the rspec gem, not the rspec-rails gem, > and as far as I can see there is nothing in the skeleton files that > get installed in /stories to require those files. Does this > suggest that the line you recommended should be added to the > release? But am I the only person to have this problem? > > Mark. > > > > Ben Mabey wrote: >> >> Mark Thomson wrote: >>> stories/helper.rb is as follows - >>> >>> >>> ---- >>> ENV["RAILS_ENV"] = "test" >>> require File.expand_path(File.dirname(__FILE__) + "/../config/ >>> environment") >>> require 'spec/rails/story_adapter' >> >> Hmm.. Shot in the dark, but try adding >> require 'spec/story' >> >> before the "require 'spec/rails/story_adapter'" line. >> >> -Ben >>> >>> dir = File.dirname(__FILE__) >>> Dir[File.expand_path("#{dir}/steps/*.rb")].uniq.each do |file| >>> require file >>> end >>> >>> ## >>> # Run a story file relative to the stories directory. >>> >>> def run_local_story(filename, options={}) >>> run File.join(File.dirname(__FILE__), filename), options >>> end >>> ---- >>> >>> >>> Mark. >>> >>> >>> Ben Mabey wrote: >>>> Mark Thomson wrote: >>>>> FWIW, I'm running Rails 2.1 on Windows. I have tried running >>>>> RSpec on two completely separate Rails installations on >>>>> different machines and get the same result. >>>>> >>>>> Mark. >>>> >>>> Please post your stories/helper.rb. >>>> >>>> -Ben >>>> >>>>> >>>>> Mark Thomson wrote: >>>>>> Indeed I have. Just re-ran it to make sure. No change in >>>>>> behavior. >>>>>> >>>>>> Mark. >>>>>> >>>>>> >>>>>> >>>>>> David Chelimsky wrote: >>>>>>> On Mon, Oct 6, 2008 at 11:29 AM, Mark Thomson >>>>>> > wrote: >>>>>>> >>>>>>>> Hi, I'm fairly new to Rails and v. new to RSpec. Think it >>>>>>>> looks pretty >>>>>>>> useful and so I'm trying it out for the first time. I have >>>>>>>> installed the >>>>>>>> rspec-rails gem and created a simple plain text my_story file >>>>>>>> and >>>>>>>> my_story.rb file along the lines described here - >>>>>>>> http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app >>>>>>>> . >>>>>>>> >>>>>>>> When I run stories/my_story.rb it blows up and the thing that >>>>>>>> seems most >>>>>>>> significant in the error messages is "uninitialized constant >>>>>>>> Spec::Story >>>>>>>> (NameError)" which seems to originate from story_adapter.rb: >>>>>>>> 66, where the >>>>>>>> class Spec::Story::Runner::ScenarioRunner is defined. >>>>>>>> >>>>>>>> Would appreciate any guidance towards a resolution of this >>>>>>>> issue. >>>>>>>> >>>>>>> >>>>>>> Have you done this: >>>>>>> >>>>>>> script/generate rspec >>>>>>> >>>>>>> >>>>>>>> Thanks, >>>>>>>> >>>>>>>> Mark >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> rspec-users mailing list >>>>>>>> rspec-users at rubyforge.org >>>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>>> >>>>>>>> >>>>>>> _______________________________________________ >>>>>>> rspec-users mailing list >>>>>>> rspec-users at rubyforge.org >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>> >>>>>>> >>>>>>> >>>>>> ------------------------------------------------------------------------ >>>>>> >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> ------------------------------------------------------------------------ >>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mark.thomson at ieee.org Mon Oct 6 16:28:30 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Mon, 06 Oct 2008 15:28:30 -0500 Subject: [rspec-users] Uninitialized constant Spec:Story In-Reply-To: <8AC56AC6-F4A9-4DB6-ADBA-7AE51C0631E1@mattwynne.net> References: <48EA3CF2.6070303@ieee.org> <57c63afe0810061020w586cc559od20285ed85a13d39@mail.gmail.com> <48EA4DB6.9030305@ieee.org> <48EA56A3.2060503@ieee.org> <48EA5B27.70808@benmabey.com> <48EA5E7D.3010603@ieee.org> <48EA5FD6.3000602@benmabey.com> <48EA6329.7000805@ieee.org> <8AC56AC6-F4A9-4DB6-ADBA-7AE51C0631E1@mattwynne.net> Message-ID: <48EA74EE.3030309@ieee.org> Wow, more stuff to learn! Thanks for the heads up. Mark. Matt Wynne wrote: > Mark, what nobody seems to a have mentioned on this thread is that > you're using a branch of the story runner that's probably going to be > retired. > > There's no reason why you should know - the rspec.info site is a bit > out of date in this regard. > > I'd encourage you to read this: > http://blog.davidchelimsky.net/2008/9/22/cucumber > > On 6 Oct 2008, at 20:12, Mark Thomson wrote: > >> Good shot - that worked! :-) >> >> Still, I'm curious as to why. Poking around with my very rudimentary >> knowledge of how ruby gems work, it looks as if the files that define >> Spec::Stories are in the rspec gem, not the rspec-rails gem, and as >> far as I can see there is nothing in the skeleton files that get >> installed in /stories to require those files. Does this suggest >> that the line you recommended should be added to the release? But am >> I the only person to have this problem? >> >> Mark. >> >> >> >> Ben Mabey wrote: >>> >>> Mark Thomson wrote: >>>> stories/helper.rb is as follows - >>>> >>>> >>>> ---- >>>> ENV["RAILS_ENV"] = "test" >>>> require File.expand_path(File.dirname(__FILE__) + >>>> "/../config/environment") >>>> require 'spec/rails/story_adapter' >>> >>> Hmm.. Shot in the dark, but try adding >>> require 'spec/story' >>> >>> before the "require 'spec/rails/story_adapter'" line. >>> >>> -Ben >>>> >>>> dir = File.dirname(__FILE__) >>>> Dir[File.expand_path("#{dir}/steps/*.rb")].uniq.each do |file| >>>> require file >>>> end >>>> >>>> ## >>>> # Run a story file relative to the stories directory. >>>> >>>> def run_local_story(filename, options={}) >>>> run File.join(File.dirname(__FILE__), filename), options >>>> end >>>> ---- >>>> >>>> >>>> Mark. >>>> >>>> >>>> Ben Mabey wrote: >>>>> Mark Thomson wrote: >>>>>> FWIW, I'm running Rails 2.1 on Windows. I have tried running >>>>>> RSpec on two completely separate Rails installations on different >>>>>> machines and get the same result. >>>>>> >>>>>> Mark. >>>>> >>>>> Please post your stories/helper.rb. >>>>> >>>>> -Ben >>>>> >>>>>> >>>>>> Mark Thomson wrote: >>>>>>> Indeed I have. Just re-ran it to make sure. No change in behavior. >>>>>>> >>>>>>> Mark. >>>>>>> >>>>>>> >>>>>>> >>>>>>> David Chelimsky wrote: >>>>>>>> On Mon, Oct 6, 2008 at 11:29 AM, Mark Thomson >>>>>>>> wrote: >>>>>>>> >>>>>>>>> Hi, I'm fairly new to Rails and v. new to RSpec. Think it >>>>>>>>> looks pretty >>>>>>>>> useful and so I'm trying it out for the first time. I have >>>>>>>>> installed the >>>>>>>>> rspec-rails gem and created a simple plain text my_story file and >>>>>>>>> my_story.rb file along the lines described here - >>>>>>>>> http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app. >>>>>>>>> >>>>>>>>> >>>>>>>>> When I run stories/my_story.rb it blows up and the thing that >>>>>>>>> seems most >>>>>>>>> significant in the error messages is "uninitialized constant >>>>>>>>> Spec::Story >>>>>>>>> (NameError)" which seems to originate from >>>>>>>>> story_adapter.rb:66, where the >>>>>>>>> class Spec::Story::Runner::ScenarioRunner is defined. >>>>>>>>> >>>>>>>>> Would appreciate any guidance towards a resolution of this issue. >>>>>>>>> >>>>>>>> >>>>>>>> Have you done this: >>>>>>>> >>>>>>>> script/generate rspec >>>>>>>> >>>>>>>> >>>>>>>>> Thanks, >>>>>>>>> >>>>>>>>> Mark >>>>>>>>> >>>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> rspec-users mailing list >>>>>>>>> rspec-users at rubyforge.org >>>>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>>>> >>>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> rspec-users mailing list >>>>>>>> rspec-users at rubyforge.org >>>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> ------------------------------------------------------------------------ >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> rspec-users mailing list >>>>>>> rspec-users at rubyforge.org >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>> ------------------------------------------------------------------------ >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > 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.thomson at ieee.org Mon Oct 6 21:52:12 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Mon, 06 Oct 2008 20:52:12 -0500 Subject: [rspec-users] post authentication token Message-ID: <48EAC0CC.7030205@ieee.org> Hi, I have a simple story that involves the user clicking a button and a new page being rendered. Seems like a simple situation, but it's testing my limited knowledge. The problem I have is my response test is failing, and I'm guessing it's because the button click is meant to submit a post request with an authentication token, which would therefore have to be included in the post call in my scenario's "when" step. My question is how do I go about determining the required value of the authentication_token? Or am I just really confused? Mark. From brian.takita at gmail.com Mon Oct 6 22:58:07 2008 From: brian.takita at gmail.com (Brian Takita) Date: Mon, 6 Oct 2008 22:58:07 -0400 Subject: [rspec-users] Adding Test Spy into Rspec mocking framework In-Reply-To: <49deff6c83e30353ff40a31aa4e562af@ruby-forum.com> References: <47c2f06bf2ef01bc90e2b4f0666a904e@ruby-forum.com> <810a540e0809150539r56d67952sb519e281fe9a3629@mail.gmail.com> <57c63afe0809150543i5fb73731s14d97c64528098fe@mail.gmail.com> <810a540e0809150549w503a351ek49308a4388b09d57@mail.gmail.com> <49deff6c83e30353ff40a31aa4e562af@ruby-forum.com> Message-ID: <1d7ddd110810061958s55964623m4e1672601debf4bc@mail.gmail.com> On Sun, Sep 21, 2008 at 11:17 AM, Joseph Wilk wrote: > I've been doing further work on adding the Test Spy to the RR mocking > framework. Awesome! Do you have a clone available? > > During my background research I came across a Spy like mocking framework > called 'Not A Mock' by Pete Yandell. > > This comes with Rspec hooks. It uses a similar syntax to what we have > discussed here and as Pat mentioned does some of this through a Rspec > Matcher: > >>object.should have_received(:length).without_args.and_returned(42) >>object.should have_received(:name).twice > > It works on real objects or stub objects and you have to register the > methods to track: > >>object.track_methods(:name, :length) > > http://notahat.com/not_a_mock > http://github.com/notahat/not_a_mock/tree/master > > Thought this might be of interest to you Pat. > > -- > Joseph Wilk > http://www.joesniff.co.uk > > > Pat Maddox wrote: >> On Mon, Sep 15, 2008 at 8:43 AM, David Chelimsky >> wrote: >>>>> x.should_have_received(:method).and_returned_with('some string') >>>> >>>> I actually started implementing this the day before Dan posted that. >>>> It works, but I don't have all the nice error messages and stuff yet. >>>> Will take me a couple days to get around to finishing it probably. >>> >>> Have you implemented this within the mock framework or as a separate concept? >> >> It's just a new matcher. I did mess with the mock framework a little >> in that I record calls every time it receives a message, rather than >> only when it hits method_missing. >> >> I will be restructuring the mock internals to better support this, I >> think. But of course it won't change the public API, and mocks will >> still have the fail-fast behavior by default if that's what you want. >> >> Basic example of what I'm doing... >> >> o = stub("stub", :foo => true) >> o.foo >> o.should have_received(:foo) >> >> It's not a true spy in the sense that it accepts any message (you can >> use :null_object for that). My only desire here was to unify the >> format of interaction-based tests with the arrange/act/assert format >> typical of state-based tests. >> >> Pat > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From greg.hauptmann.ruby at gmail.com Mon Oct 6 23:22:12 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Tue, 7 Oct 2008 13:22:12 +1000 Subject: [rspec-users] can I get more details in the "rake spec" output (e.g. for eql fail, what was the actual value that was returned)??? Message-ID: Hi, Can I get more details in the "rake spec" output (e.g. for eql fail, what was the actual value that was returned)??? Another example might be what the exception actually is in a case the "should not raise exception" fails... Regards Greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Mon Oct 6 23:43:44 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 06 Oct 2008 20:43:44 -0700 Subject: [rspec-users] can I get more details in the "rake spec" output (e.g. for eql fail, what was the actual value that was returned)??? In-Reply-To: (Greg Hauptmann's message of "Tue\, 7 Oct 2008 13\:22\:12 +1000") References: Message-ID: What are you currently seeing? afaik, you should currently see all the dots and a few F's when specs fail, and then after that you'll see detailed failure messages including backtraces. Pat "Greg Hauptmann" writes: > Hi, > > Can I get more details in the "rake spec" output (e.g. for eql fail, what was the actual value that was returned)??? Another example might be what the exception > actually is in a case the "should not raise exception" fails... > > Regards > Greg > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From greg.hauptmann.ruby at gmail.com Tue Oct 7 00:25:40 2008 From: greg.hauptmann.ruby at gmail.com (Greg Hauptmann) Date: Tue, 7 Oct 2008 14:25:40 +1000 Subject: [rspec-users] can I get more details in the "rake spec" output (e.g. for eql fail, what was the actual value that was returned)??? In-Reply-To: References: Message-ID: here's some examples: 'Recurring.add_projections: weekly & non-reconcile & starting in past should update balances appropriately' FAILED expected 1001, got # (using .eql?) ./spec/models/recurring_spec.rb:140: ==> Oh, actually seems to work but gives the figure in Engineering notation - I wonder if there's a way to improve the readability here? 'Recurring.add projections (perform credit card payment) should calculate amount based on offset provided' FAILED expected no Exception, got # ==> Actually does show exception name, but doesn't give a back trace? Is there a way to see the back trace if required? tks On Tue, Oct 7, 2008 at 1:43 PM, Pat Maddox wrote: > What are you currently seeing? afaik, you should currently see all the > dots and a few F's when specs fail, and then after that you'll see > detailed failure messages including backtraces. > > Pat > > > "Greg Hauptmann" writes: > > > Hi, > > > > Can I get more details in the "rake spec" output (e.g. for eql fail, what > was the actual value that was returned)??? Another example might be what the > exception > > actually is in a case the "should not raise exception" fails... > > > > Regards > > Greg > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Tue Oct 7 03:45:18 2008 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 7 Oct 2008 08:45:18 +0100 Subject: [rspec-users] post authentication token In-Reply-To: <48EAC0CC.7030205@ieee.org> References: <48EAC0CC.7030205@ieee.org> Message-ID: This is actually a pretty tough problem for a newbie, and sent me reeling away from the story runner with my gumption in tatters the first time I tried it. You could probably figure out how to post an authentication token in the HTTP headers if you use the basic underlying rails integration session method post(), but you may be better off just walking through the steps a real user would carry out in order to log in: Given /logged in/ do visits "/login" fills_in :username, "Matt" fills_in :password, "secret" presses_button end This is what we do, and though instinctively it feels a little bit slow and clunky to do this at the top of every scenario that requires the user to be authenticated, in practice it's working fine for us, and I actually find it rather nice to know you're only vaguely coupled to the implementation. Note that these steps above use the 'webrat' library which is the de- facto way to talk to your rails app from feature steps. On 7 Oct 2008, at 02:52, Mark Thomson wrote: > Hi, I have a simple story that involves the user clicking a button > and a new page being rendered. Seems like a simple situation, but > it's testing my limited knowledge. The problem I have is my response > test is failing, and I'm guessing it's because the button click is > meant to submit a post request with an authentication token, which > would therefore have to be included in the post call in my > scenario's "when" step. My question is how do I go about determining > the required value of the authentication_token? Or am I just really > confused? > > Mark. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Tue Oct 7 06:02:19 2008 From: lists at ruby-forum.com (Pau Cor) Date: Tue, 7 Oct 2008 12:02:19 +0200 Subject: [rspec-users] Testing Generators Message-ID: Hi, I have started writing my own generators, and I was wondering if anyone had any suggestions for testing them. I know I could just run the generator in a dummy application; write my tests; and then copy the tests back into the generator. But that seems backwards. Any ideas? Thanks -- Posted via http://www.ruby-forum.com/. From mark.thomson at ieee.org Tue Oct 7 08:36:14 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Tue, 07 Oct 2008 07:36:14 -0500 Subject: [rspec-users] post authentication token In-Reply-To: References: <48EAC0CC.7030205@ieee.org> Message-ID: <48EB57BE.6000405@ieee.org> Hmm, thanks. Still not sure if I'm diagnosing my problem correctly. Just to be clear, I don't have any user authentication going on, just a regular Rails button_to call. I tried installing webrat and put "visits '/' " in my "given" step and "clicks_button" in my "when" step. However I get an error from my_story.rb - "No such file or directory - open tmp/webrat-12233801950.html. Presumably my issue would also apply in posting a form in a regular Rails integration test. The example on pp207-208 of AWDR doesn't suggest that anything needs to be done in a post call to achieve session authentication. And I see here - http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html#M000693 that forgery protection is actually turned off in testing - which I've confirmed in my config/environments/test.rb. So maybe I have some other problem causing my response test to fail. Any other suggestions would be appreciated. Mark. Matt Wynne wrote: > This is actually a pretty tough problem for a newbie, and sent me > reeling away from the story runner with my gumption in tatters the > first time I tried it. > > You could probably figure out how to post an authentication token in > the HTTP headers if you use the basic underlying rails integration > session method post(), but you may be better off just walking through > the steps a real user would carry out in order to log in: > > Given /logged in/ do > visits "/login" > fills_in :username, "Matt" > fills_in :password, "secret" > presses_button > end > > This is what we do, and though instinctively it feels a little bit > slow and clunky to do this at the top of every scenario that requires > the user to be authenticated, in practice it's working fine for us, > and I actually find it rather nice to know you're only vaguely coupled > to the implementation. > > Note that these steps above use the 'webrat' library which is the > de-facto way to talk to your rails app from feature steps. > > On 7 Oct 2008, at 02:52, Mark Thomson wrote: > >> Hi, I have a simple story that involves the user clicking a button >> and a new page being rendered. Seems like a simple situation, but >> it's testing my limited knowledge. The problem I have is my response >> test is failing, and I'm guessing it's because the button click is >> meant to submit a post request with an authentication token, which >> would therefore have to be included in the post call in my scenario's >> "when" step. My question is how do I go about determining the >> required value of the authentication_token? Or am I just really >> confused? >> >> Mark. >> >> _______________________________________________ >> 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 zach.dennis at gmail.com Tue Oct 7 08:47:16 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 7 Oct 2008 08:47:16 -0400 Subject: [rspec-users] post authentication token In-Reply-To: <48EB57BE.6000405@ieee.org> References: <48EAC0CC.7030205@ieee.org> <48EB57BE.6000405@ieee.org> Message-ID: <85d99afe0810070547l484f16f4v94d5b293b351a4bf@mail.gmail.com> On Tue, Oct 7, 2008 at 8:36 AM, Mark Thomson wrote: > Hmm, thanks. Still not sure if I'm diagnosing my problem correctly. Just to > be clear, I don't have any user authentication going on, just a regular > Rails button_to call. I tried installing webrat and put "visits '/' " in my > "given" step and "clicks_button" in my "when" step. However I get an error > from my_story.rb - "No such file or directory - open > tmp/webrat-12233801950.html. > > Presumably my issue would also apply in posting a form in a regular Rails > integration test. The example on pp207-208 of AWDR doesn't suggest that > anything needs to be done in a post call to achieve session authentication. > And I see here - > http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html#M000693 > that forgery protection is actually turned off in testing - which I've > confirmed in my config/environments/test.rb. So maybe I have some other > problem causing my response test to fail. Any other suggestions would be > appreciated. > Have you looked at your log/test.log file to see if there are any exceptions being thrown? Or at least to see what is being rendered, perhaps you're hitting a path you don't intend. -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From ashley.moran at patchspace.co.uk Tue Oct 7 08:59:52 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 7 Oct 2008 13:59:52 +0100 Subject: [rspec-users] Expectation ordering Message-ID: <8B4575A2-03D3-49D6-BF51-08D61C91E74E@patchspace.co.uk> Hi Can I still rely on this RSpec behaviour? I've got a spec for a TCP socket client: it "should do things in a sane order" do @socket.should_receive(:write) do @socket.should_receive(:read) do @socket.should_receive(:close) end end @client.update_news_feeds end But this passes, where I was expecting it to fail: def update_news_feeds socket = TCPSocket.new(@server, @port) socket.read socket.write("UPDATE\n") socket.close end Has this form of expectation ordering been removed? Thanks Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From matt at mattwynne.net Tue Oct 7 09:17:05 2008 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 7 Oct 2008 14:17:05 +0100 Subject: [rspec-users] post authentication token In-Reply-To: <85d99afe0810070547l484f16f4v94d5b293b351a4bf@mail.gmail.com> References: <48EAC0CC.7030205@ieee.org> <48EB57BE.6000405@ieee.org> <85d99afe0810070547l484f16f4v94d5b293b351a4bf@mail.gmail.com> Message-ID: Another tip is to use script/console and walk the app manually. In script/console you get an app object which is the context that your story steps / integration tests run in. e.g. $script/console Loading rails blah blah blah >> app.post "/login", :username => "matt", :password => "secret" >> puts app.response.body >> app.visits "/hello" etc. Often quite handy for having an explore when you can't figure out how to drive something from a test. On 7 Oct 2008, at 13:47, Zach Dennis wrote: > On Tue, Oct 7, 2008 at 8:36 AM, Mark Thomson > wrote: >> Hmm, thanks. Still not sure if I'm diagnosing my problem correctly. >> Just to >> be clear, I don't have any user authentication going on, just a >> regular >> Rails button_to call. I tried installing webrat and put "visits '/' >> " in my >> "given" step and "clicks_button" in my "when" step. However I get >> an error >> from my_story.rb - "No such file or directory - open >> tmp/webrat-12233801950.html. >> >> Presumably my issue would also apply in posting a form in a regular >> Rails >> integration test. The example on pp207-208 of AWDR doesn't suggest >> that >> anything needs to be done in a post call to achieve session >> authentication. >> And I see here - >> http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html#M000693 >> that forgery protection is actually turned off in testing - which >> I've >> confirmed in my config/environments/test.rb. So maybe I have some >> other >> problem causing my response test to fail. Any other suggestions >> would be >> appreciated. >> > > Have you looked at your log/test.log file to see if there are any > exceptions being thrown? Or at least to see what is being rendered, > perhaps you're hitting a path you don't intend. > > -- > 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 ashley.moran at patchspace.co.uk Tue Oct 7 09:57:57 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 7 Oct 2008 14:57:57 +0100 Subject: [rspec-users] Specifying a specific error is re-raised Message-ID: <6F63F14B-D65E-4225-ADF0-179AA77B5898@patchspace.co.uk> Hi I've got code I want to intercept all errors (to report them) but re- raise them immediately. Currently the raise_error matcher doesn't support matching against instances of exception classes, so I've done this to prove that the actual exception was re-raised: describe "when the update is unsuccessful" do class WeirdError < StandardError; end before(:each) do @error = WeirdError.new("Error") @server.stub!(:check_feeds).and_raise(@error) end it "should re-raise the exception" do lambda { @connection.receive_data("UPDATE\n") }. should raise_error(WeirdError) end end Few questions: Is this an appropriate behaviour to spec? If so, is this currently the best way to do it? If so, would exception instance matching be useful? Thanks Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From dchelimsky at gmail.com Tue Oct 7 10:15:12 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Oct 2008 09:15:12 -0500 Subject: [rspec-users] Expectation ordering In-Reply-To: <8B4575A2-03D3-49D6-BF51-08D61C91E74E@patchspace.co.uk> References: <8B4575A2-03D3-49D6-BF51-08D61C91E74E@patchspace.co.uk> Message-ID: <57c63afe0810070715t1e2430fcq37340a8a93d173d0@mail.gmail.com> On Tue, Oct 7, 2008 at 7:59 AM, Ashley Moran wrote: > Hi > > Can I still rely on this RSpec behaviour? > > I've got a spec for a TCP socket client: > > it "should do things in a sane order" do > @socket.should_receive(:write) do > @socket.should_receive(:read) do > @socket.should_receive(:close) > end > end > @client.update_news_feeds > end > > But this passes, where I was expecting it to fail: > > def update_news_feeds > socket = TCPSocket.new(@server, @port) > socket.read > socket.write("UPDATE\n") > socket.close > end > > Has this form of expectation ordering been removed? As far as I know this form of expectation ordering was never supported. If you've seen documentation that suggests it should be, please point me to it so I can resolve the discrepancy. Ordering in rspec mocks is managed with the #ordered method: @socket.should_receive(:write).ordered @socket.should_receive(:read).ordered @socket.should_receive(:close).ordered See http://rspec.info/documentation/mocks/message_expectations.html - almost all the way down the page. Cheers, David > > Thanks > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Tue Oct 7 10:22:22 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 7 Oct 2008 10:22:22 -0400 Subject: [rspec-users] Testing Generators In-Reply-To: References: Message-ID: <4BD19DB2-2A05-4D39-86BB-CB8AB32DED07@railsnewbie.com> On Oct 7, 2008, at 6:02 AM, Pau Cor wrote: > Hi, > > I have started writing my own generators, and I was wondering if > anyone > had any suggestions for testing them. > > I know I could just run the generator in a dummy application; write my > tests; and then copy the tests back into the generator. But that seems > backwards. > > Any ideas? Why don't you generate the specs when you generate the code? Then, after you've generated the code you tell if the specs are actually working... Scott From dchelimsky at gmail.com Tue Oct 7 10:33:30 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Oct 2008 09:33:30 -0500 Subject: [rspec-users] Specifying a specific error is re-raised In-Reply-To: <6F63F14B-D65E-4225-ADF0-179AA77B5898@patchspace.co.uk> References: <6F63F14B-D65E-4225-ADF0-179AA77B5898@patchspace.co.uk> Message-ID: <57c63afe0810070733p5813bdaaxbaca1e34f1add4bd@mail.gmail.com> On Tue, Oct 7, 2008 at 8:57 AM, Ashley Moran wrote: > Hi > > I've got code I want to intercept all errors (to report them) but re-raise > them immediately. Currently the raise_error matcher doesn't support > matching against instances of exception classes, so I've done this to prove > that the actual exception was re-raised: > > describe "when the update is unsuccessful" do > class WeirdError < StandardError; end > > before(:each) do > @error = WeirdError.new("Error") > @server.stub!(:check_feeds).and_raise(@error) > end > > it "should re-raise the exception" do > lambda { @connection.receive_data("UPDATE\n") }. > should raise_error(WeirdError) > end > end > > Few questions: > > Is this an appropriate behaviour to spec? Hmmm, should inappropriate behaviour be spec'd? :) Code examples are not politically correct. If you want your app to behave some way, there should be a way to spec it. > If so, is this currently the best way to do it? > > If so, would exception instance matching be useful? Check out http://rspec.info/rdoc/classes/Spec/Matchers.html#M000434 I see that it is incomplete, because you can use just a string or regexp if you want (w/o the error itself). I'll adjust for the next release. Regardless, if you really care about the specific instance you can do this: lambda { @connection.receive_data("UPDATE\n") }.should raise_error {|error| error.should equal(@error)} If what you care about is the message, you can expect specific messages using strings or regexps: lambda { @connection.receive_data("UPDATE\n") }.should raise_error("with this message") lambda { @connection.receive_data("UPDATE\n") }.should raise_error(/with a message containing this/) lambda { @connection.receive_data("UPDATE\n") }.should raise_error(OfThisErrorType, "with this message") lambda { @connection.receive_data("UPDATE\n") }.should raise_error(OfThisErrorType, with a message containing this/) Cheers, David > > Thanks > Ashley From ashley.moran at patchspace.co.uk Tue Oct 7 10:40:30 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 7 Oct 2008 15:40:30 +0100 Subject: [rspec-users] Expectation ordering In-Reply-To: <57c63afe0810070715t1e2430fcq37340a8a93d173d0@mail.gmail.com> References: <8B4575A2-03D3-49D6-BF51-08D61C91E74E@patchspace.co.uk> <57c63afe0810070715t1e2430fcq37340a8a93d173d0@mail.gmail.com> Message-ID: On 7 Oct 2008, at 15:15, David Chelimsky wrote: > As far as I know this form of expectation ordering was never > supported. If you've seen documentation that suggests it should be, > please point me to it so I can resolve the discrepancy. Aslak told me himself... on this list :o) > Ordering in rspec mocks is managed with the #ordered method: > > @socket.should_receive(:write).ordered > @socket.should_receive(:read).ordered > @socket.should_receive(:close).ordered I forgot about that. When I asked on the list before it was because I needed a way to do inter-mock ordering. Thanks for the link, it solved the problem in the example I gave. Unfortunately looks like I've lost the ability to do this: it "should migrate the database (after initialising it)" do DataMapper.should_receive(:setup) do Database::Migrator.should_receive(:migrate_up!) end @server.start end Maybe I was the only person taking advantage of this? Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Tue Oct 7 10:50:33 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 7 Oct 2008 15:50:33 +0100 Subject: [rspec-users] Specifying a specific error is re-raised In-Reply-To: <57c63afe0810070733p5813bdaaxbaca1e34f1add4bd@mail.gmail.com> References: <6F63F14B-D65E-4225-ADF0-179AA77B5898@patchspace.co.uk> <57c63afe0810070733p5813bdaaxbaca1e34f1add4bd@mail.gmail.com> Message-ID: On 7 Oct 2008, at 15:33, David Chelimsky wrote: > Regardless, if you really care about the specific instance you can > do this: > > lambda { > @connection.receive_data("UPDATE\n") > }.should raise_error {|error| error.should equal(@error)} > > If what you care about is the message, you can expect specific > messages using strings or regexps: Thanks - that snippet does exactly what I want. Basically I want tee pipe-fitting for errors - the code now looks like this: class Connection < EventMachine::Connection attr_accessor :server def receive_data(data) if data.chomp == "UPDATE" handle_update else send_data("ERROR: Unknown command\n") end end def unbind raise @error if @error end private def handle_update server.check_feeds rescue StandardError => @error send_data("ERROR: #{@error.to_s}\n") close_connection_after_writing else send_data("OK\n") end end So I don't care about the exception beyond extracting enough data to feed back through the socket. Cheers Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From dchelimsky at gmail.com Tue Oct 7 10:55:25 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Oct 2008 09:55:25 -0500 Subject: [rspec-users] Expectation ordering In-Reply-To: References: <8B4575A2-03D3-49D6-BF51-08D61C91E74E@patchspace.co.uk> <57c63afe0810070715t1e2430fcq37340a8a93d173d0@mail.gmail.com> Message-ID: <57c63afe0810070755x62a47ca0k1616a550caea13e4@mail.gmail.com> On Tue, Oct 7, 2008 at 9:40 AM, Ashley Moran wrote: > > On 7 Oct 2008, at 15:15, David Chelimsky wrote: > >> As far as I know this form of expectation ordering was never >> supported. If you've seen documentation that suggests it should be, >> please point me to it so I can resolve the discrepancy. > > Aslak told me himself... on this list :o) > > >> Ordering in rspec mocks is managed with the #ordered method: >> >> @socket.should_receive(:write).ordered >> @socket.should_receive(:read).ordered >> @socket.should_receive(:close).ordered > > I forgot about that. When I asked on the list before it was because I > needed a way to do inter-mock ordering. Thanks for the link, it solved the > problem in the example I gave. Unfortunately looks like I've lost the > ability to do this: > > it "should migrate the database (after initialising it)" do > DataMapper.should_receive(:setup) do > Database::Migrator.should_receive(:migrate_up!) > end > @server.start > end > > Maybe I was the only person taking advantage of this? Is the block no longer being executed? If so, then we have a problem :) Please report this at http://rspec.lighthouseapp.com. Thanks, David > > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mark.thomson at ieee.org Tue Oct 7 11:23:04 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Tue, 07 Oct 2008 10:23:04 -0500 Subject: [rspec-users] post authentication token In-Reply-To: <85d99afe0810070547l484f16f4v94d5b293b351a4bf@mail.gmail.com> References: <48EAC0CC.7030205@ieee.org> <48EB57BE.6000405@ieee.org> <85d99afe0810070547l484f16f4v94d5b293b351a4bf@mail.gmail.com> Message-ID: <48EB7ED8.9090405@ieee.org> Hey thanks Zach. That was a good suggestion. What the log file showed me was that I had a nil object being accessed in my "new" action - and the reason is that it's an object that in my development code is read from a table of global variables in my db. I create that table, including the values of the global variable, in a migration. However, this doesn't exist in my test db. So I did a .create in my "given" step to instantiate the global variable and I'm now all good. Mark. Zach Dennis wrote: > On Tue, Oct 7, 2008 at 8:36 AM, Mark Thomson wrote: > >> Hmm, thanks. Still not sure if I'm diagnosing my problem correctly. Just to >> be clear, I don't have any user authentication going on, just a regular >> Rails button_to call. I tried installing webrat and put "visits '/' " in my >> "given" step and "clicks_button" in my "when" step. However I get an error >> from my_story.rb - "No such file or directory - open >> tmp/webrat-12233801950.html. >> >> Presumably my issue would also apply in posting a form in a regular Rails >> integration test. The example on pp207-208 of AWDR doesn't suggest that >> anything needs to be done in a post call to achieve session authentication. >> And I see here - >> http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html#M000693 >> that forgery protection is actually turned off in testing - which I've >> confirmed in my config/environments/test.rb. So maybe I have some other >> problem causing my response test to fail. Any other suggestions would be >> appreciated. >> >> > > Have you looked at your log/test.log file to see if there are any > exceptions being thrown? Or at least to see what is being rendered, > perhaps you're hitting a path you don't intend. > > From nick at deadorange.com Tue Oct 7 12:09:26 2008 From: nick at deadorange.com (Nick Hoffman) Date: Tue, 7 Oct 2008 12:09:26 -0400 Subject: [rspec-users] can I get more details in the "rake spec" output (e.g. for eql fail, what was the actual value that was returned)??? In-Reply-To: References: Message-ID: <37D6EAE2-3496-4097-9ADC-874D5E8A59F3@deadorange.com> On 2008-10-07, at 00:25, Greg Hauptmann wrote: > 'Recurring.add projections (perform credit card payment) should > calculate amount based on offset provided' FAILED > expected no Exception, got # exception> > ==> Actually does show exception name, but doesn't give a back > trace? Is there a way to see the back trace if required? Hi Greg. ``rake spec'' accepts --trace . Cheers, Nick From ashley.moran at patchspace.co.uk Tue Oct 7 12:15:57 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 7 Oct 2008 17:15:57 +0100 Subject: [rspec-users] Expectation ordering In-Reply-To: <57c63afe0810070755x62a47ca0k1616a550caea13e4@mail.gmail.com> References: <8B4575A2-03D3-49D6-BF51-08D61C91E74E@patchspace.co.uk> <57c63afe0810070715t1e2430fcq37340a8a93d173d0@mail.gmail.com> <57c63afe0810070755x62a47ca0k1616a550caea13e4@mail.gmail.com> Message-ID: On 7 Oct 2008, at 15:55, David Chelimsky wrote: > Is the block no longer being executed? If so, then we have a problem > :) Please report this at http://rspec.lighthouseapp.com. Bizarrely, my little test... require 'spec' describe "Blocks" do it "should be called" do b = mock(Object) b.should_receive(:this) do b.should_receive(:that) end b.that b.this end end Works as expected (the above fails) I'll have to investigate further... Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From aidy.lewis at googlemail.com Tue Oct 7 12:39:57 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Tue, 7 Oct 2008 17:39:57 +0100 Subject: [rspec-users] cucumber and html reports Message-ID: <7ac2300c0810070939t5c828904n32917b8e6fff3917@mail.gmail.com> Hi, Is there anyway I can cycle through all the features in a folder and pipe to html through the command line? For this: C:\SvnProjects\my_application\features> cucumber *.feature --format html > my_application.htm I am getting a wrong number of arguments (3 for 1). Or how could run all features with a HTML report in a rake file? Thanks Aidy From dchelimsky at gmail.com Tue Oct 7 12:47:55 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Oct 2008 11:47:55 -0500 Subject: [rspec-users] cucumber and html reports In-Reply-To: <7ac2300c0810070939t5c828904n32917b8e6fff3917@mail.gmail.com> References: <7ac2300c0810070939t5c828904n32917b8e6fff3917@mail.gmail.com> Message-ID: <57c63afe0810070947l4c334200m3336eaddd3087377@mail.gmail.com> On Tue, Oct 7, 2008 at 11:39 AM, aidy lewis wrote: > Hi, > > Is there anyway I can cycle through all the features in a folder and > pipe to html > through the command line? > > For this: > C:\SvnProjects\my_application\features> cucumber *.feature --format html > > my_application.htm This works for me: cucumber folder_name --format html > report.html Cheers, David > > I am getting a wrong number of arguments (3 for 1). > > Or how could run all features with a HTML report in a rake file? > > Thanks > > Aidy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Tue Oct 7 13:00:15 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 7 Oct 2008 19:00:15 +0200 Subject: [rspec-users] cucumber and html reports In-Reply-To: <57c63afe0810070947l4c334200m3336eaddd3087377@mail.gmail.com> References: <7ac2300c0810070939t5c828904n32917b8e6fff3917@mail.gmail.com> <57c63afe0810070947l4c334200m3336eaddd3087377@mail.gmail.com> Message-ID: <8d961d900810071000o37411dbdk64454b7e7c5c41f7@mail.gmail.com> On Tue, Oct 7, 2008 at 6:47 PM, David Chelimsky wrote: > On Tue, Oct 7, 2008 at 11:39 AM, aidy lewis wrote: >> Hi, >> >> Is there anyway I can cycle through all the features in a folder and >> pipe to html >> through the command line? >> >> For this: >> C:\SvnProjects\my_application\features> cucumber *.feature --format html >> > my_application.htm > > This works for me: > > cucumber folder_name --format html > report.html > Which should be obvious if you do cucumber --help Usage: cucumber [options] FILES|DIRS Aslak > Cheers, > David > >> >> I am getting a wrong number of arguments (3 for 1). >> >> Or how could run all features with a HTML report in a rake file? >> >> Thanks >> >> Aidy >> _______________________________________________ >> 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 aidy.lewis at googlemail.com Tue Oct 7 13:09:09 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Tue, 7 Oct 2008 18:09:09 +0100 Subject: [rspec-users] cucumber and html reports In-Reply-To: <57c63afe0810070947l4c334200m3336eaddd3087377@mail.gmail.com> References: <7ac2300c0810070939t5c828904n32917b8e6fff3917@mail.gmail.com> <57c63afe0810070947l4c334200m3336eaddd3087377@mail.gmail.com> Message-ID: <7ac2300c0810071009w4f5eadaco953d3bf8415ce89d@mail.gmail.com> Hi David, > cucumber folder_name --format html > report.html Thanks for your response. That doesn't seem to report for me (maybe it is because one of my tests fails - throws an exception and then writes to the console before it outputs to the html file). Cheers Aidy From aidy.lewis at googlemail.com Tue Oct 7 13:14:39 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Tue, 7 Oct 2008 18:14:39 +0100 Subject: [rspec-users] cucumber and html reports In-Reply-To: <7ac2300c0810071009w4f5eadaco953d3bf8415ce89d@mail.gmail.com> References: <7ac2300c0810070939t5c828904n32917b8e6fff3917@mail.gmail.com> <57c63afe0810070947l4c334200m3336eaddd3087377@mail.gmail.com> <7ac2300c0810071009w4f5eadaco953d3bf8415ce89d@mail.gmail.com> Message-ID: <7ac2300c0810071014s61a3388du1c62af323ada8356@mail.gmail.com> Guys. On 07/10/2008, aidy lewis wrote: > Thanks for your response. > > That doesn't seem to report for me (maybe it is because one of my > tests fails - throws an exception and then writes to the console > before it outputs to the html file). > Sorry for being a balloon. However, 1) The report seems to only colour in firefox 2) When an exception is thrown the rest of the report is grey. Do I need to raise a ticket? Aidy From aslak.hellesoy at gmail.com Tue Oct 7 13:22:38 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 7 Oct 2008 19:22:38 +0200 Subject: [rspec-users] cucumber and html reports In-Reply-To: <7ac2300c0810070939t5c828904n32917b8e6fff3917@mail.gmail.com> References: <7ac2300c0810070939t5c828904n32917b8e6fff3917@mail.gmail.com> Message-ID: <8d961d900810071022g4269a76eg9dc3640d1193a76@mail.gmail.com> On Tue, Oct 7, 2008 at 6:39 PM, aidy lewis wrote: > Hi, > > Is there anyway I can cycle through all the features in a folder and > pipe to html > through the command line? > > For this: > C:\SvnProjects\my_application\features> cucumber *.feature --format html > > my_application.htm > > I am getting a wrong number of arguments (3 for 1). > > Or how could run all features with a HTML report in a rake file? > I just made that a little easier: http://github.com/aslakhellesoy/cucumber/commit/ff6cb5143d49448a05c46c03180ed8f6ecb240af http://github.com/aslakhellesoy/cucumber/commit/7cbbc40e99ed278f172f85178c383ba7ae733bdd Essentially, just pass --format html --out yourfile.html to the rake task's cucumber_opts Aslak > Thanks > > Aidy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Tue Oct 7 13:25:05 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 7 Oct 2008 19:25:05 +0200 Subject: [rspec-users] cucumber and html reports In-Reply-To: <7ac2300c0810071014s61a3388du1c62af323ada8356@mail.gmail.com> References: <7ac2300c0810070939t5c828904n32917b8e6fff3917@mail.gmail.com> <57c63afe0810070947l4c334200m3336eaddd3087377@mail.gmail.com> <7ac2300c0810071009w4f5eadaco953d3bf8415ce89d@mail.gmail.com> <7ac2300c0810071014s61a3388du1c62af323ada8356@mail.gmail.com> Message-ID: <8d961d900810071025i59d6e836o174627fecca0b9ee@mail.gmail.com> On Tue, Oct 7, 2008 at 7:14 PM, aidy lewis wrote: > Guys. > On 07/10/2008, aidy lewis wrote: > >> Thanks for your response. >> >> That doesn't seem to report for me (maybe it is because one of my >> tests fails - throws an exception and then writes to the console >> before it outputs to the html file). >> > > Sorry for being a balloon. > > However, > > 1) The report seems to only colour in firefox > 2) When an exception is thrown the rest of the report is grey. > > Do I need to raise a ticket? > I just noticed that. It's definitely a bug. The bug can be reproduced like this: cd examples/calculator rake features PROFILE=html open features.html Please raise a ticket. Aslak > Aidy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Tue Oct 7 13:56:01 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 7 Oct 2008 13:56:01 -0400 Subject: [rspec-users] post authentication token In-Reply-To: <48EB7ED8.9090405@ieee.org> References: <48EAC0CC.7030205@ieee.org> <48EB57BE.6000405@ieee.org> <85d99afe0810070547l484f16f4v94d5b293b351a4bf@mail.gmail.com> <48EB7ED8.9090405@ieee.org> Message-ID: <85d99afe0810071056l73fb1060u2182c208b239f197@mail.gmail.com> You may want to look into using seed data. I currently use seed_fu by mbleigh: http://github.com/mbleigh/seed-fu/tree/master Here's the snippet I use to load them: ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test']) ActiveRecord::Schema.verbose = false load "#{RAILS_ROOT}/db/schema.rb" Dir[File.join(RAILS_ROOT, "features/fixtures", '*.rb')].sort.each { |fixture| load fixture } I do this rather than a rake task because that takes forever (thx Brandon Keepers for correcting my usage, you have saved me tons of minutes) Zach On Tue, Oct 7, 2008 at 11:23 AM, Mark Thomson wrote: > Hey thanks Zach. That was a good suggestion. What the log file showed me was > that I had a nil object being accessed in my "new" action - and the reason > is that it's an object that in my development code is read from a table of > global variables in my db. I create that table, including the values of the > global variable, in a migration. However, this doesn't exist in my test db. > So I did a .create in my "given" step to instantiate the global > variable and I'm now all good. > > Mark. > > > > Zach Dennis wrote: >> >> On Tue, Oct 7, 2008 at 8:36 AM, Mark Thomson >> wrote: >> >>> >>> Hmm, thanks. Still not sure if I'm diagnosing my problem correctly. Just >>> to >>> be clear, I don't have any user authentication going on, just a regular >>> Rails button_to call. I tried installing webrat and put "visits '/' " in >>> my >>> "given" step and "clicks_button" in my "when" step. However I get an >>> error >>> from my_story.rb - "No such file or directory - open >>> tmp/webrat-12233801950.html. >>> >>> Presumably my issue would also apply in posting a form in a regular Rails >>> integration test. The example on pp207-208 of AWDR doesn't suggest that >>> anything needs to be done in a post call to achieve session >>> authentication. >>> And I see here - >>> >>> http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html#M000693 >>> that forgery protection is actually turned off in testing - which I've >>> confirmed in my config/environments/test.rb. So maybe I have some other >>> problem causing my response test to fail. Any other suggestions would be >>> appreciated. >>> >>> >> >> Have you looked at your log/test.log file to see if there are any >> exceptions being thrown? Or at least to see what is being rendered, >> perhaps you're hitting a path you don't intend. >> >> > > _______________________________________________ > 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 mark.thomson at ieee.org Tue Oct 7 14:36:50 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Tue, 07 Oct 2008 13:36:50 -0500 Subject: [rspec-users] post authentication token In-Reply-To: <85d99afe0810071056l73fb1060u2182c208b239f197@mail.gmail.com> References: <48EAC0CC.7030205@ieee.org> <48EB57BE.6000405@ieee.org> <85d99afe0810070547l484f16f4v94d5b293b351a4bf@mail.gmail.com> <48EB7ED8.9090405@ieee.org> <85d99afe0810071056l73fb1060u2182c208b239f197@mail.gmail.com> Message-ID: <48EBAC42.9090601@ieee.org> Nice. Thanks. I had wondered if there was a way to separate the data initialization from the step definitions. Looks like that's what this does. Zach Dennis wrote: > You may want to look into using seed data. I currently use seed_fu by mbleigh: > http://github.com/mbleigh/seed-fu/tree/master > > Here's the snippet I use to load them: > > ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test']) > ActiveRecord::Schema.verbose = false > load "#{RAILS_ROOT}/db/schema.rb" > Dir[File.join(RAILS_ROOT, "features/fixtures", '*.rb')].sort.each { > |fixture| load fixture } > > I do this rather than a rake task because that takes forever (thx > Brandon Keepers for correcting my usage, you have saved me tons of > minutes) > > Zach > > > On Tue, Oct 7, 2008 at 11:23 AM, Mark Thomson wrote: > >> Hey thanks Zach. That was a good suggestion. What the log file showed me was >> that I had a nil object being accessed in my "new" action - and the reason >> is that it's an object that in my development code is read from a table of >> global variables in my db. I create that table, including the values of the >> global variable, in a migration. However, this doesn't exist in my test db. >> So I did a .create in my "given" step to instantiate the global >> variable and I'm now all good. >> >> Mark. >> >> >> >> Zach Dennis wrote: >> >>> On Tue, Oct 7, 2008 at 8:36 AM, Mark Thomson >>> wrote: >>> >>> >>>> Hmm, thanks. Still not sure if I'm diagnosing my problem correctly. Just >>>> to >>>> be clear, I don't have any user authentication going on, just a regular >>>> Rails button_to call. I tried installing webrat and put "visits '/' " in >>>> my >>>> "given" step and "clicks_button" in my "when" step. However I get an >>>> error >>>> from my_story.rb - "No such file or directory - open >>>> tmp/webrat-12233801950.html. >>>> >>>> Presumably my issue would also apply in posting a form in a regular Rails >>>> integration test. The example on pp207-208 of AWDR doesn't suggest that >>>> anything needs to be done in a post call to achieve session >>>> authentication. >>>> And I see here - >>>> >>>> http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html#M000693 >>>> that forgery protection is actually turned off in testing - which I've >>>> confirmed in my config/environments/test.rb. So maybe I have some other >>>> problem causing my response test to fail. Any other suggestions would be >>>> appreciated. >>>> >>>> >>>> >>> Have you looked at your log/test.log file to see if there are any >>> exceptions being thrown? Or at least to see what is being rendered, >>> perhaps you're hitting a path you don't intend. >>> >>> >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Tue Oct 7 17:56:55 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 7 Oct 2008 14:56:55 -0700 Subject: [rspec-users] gem generators on 1.2.6 Message-ID: <810a540e0810071456v772ce222m6d2bd1be5f6d03d6@mail.gmail.com> In a 1.2.6 app (don't ask), I don't see the generators available to me with the gems installed. However the documentation makes it look like it should work: Generator gems are also available: 1. gem search -r generator 2. gem install login_generator 3. ./script/generate login I've confirmed that with a fresh rails (2.x) app it works fine. Is this supposed to work with 1.2.6? Are there any workarounds that people have? Is my app just fucked atm? Pat From pergesu at gmail.com Tue Oct 7 17:58:55 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 7 Oct 2008 14:58:55 -0700 Subject: [rspec-users] gem generators on 1.2.6 In-Reply-To: <810a540e0810071456v772ce222m6d2bd1be5f6d03d6@mail.gmail.com> References: <810a540e0810071456v772ce222m6d2bd1be5f6d03d6@mail.gmail.com> Message-ID: <810a540e0810071458q4845470bxe8af1b132062c35@mail.gmail.com> > I've confirmed that with a fresh rails (2.x) app it works fine. Is > this supposed to work with 1.2.6? Are there any workarounds that > people have? Is my app just fucked atm? erm, I've also confirmed that with a fresh rails 1.2.6 app it DOESN'T see the gem generators. I'm pretty suspicious though because of that documentation. Pat From ben at benmabey.com Tue Oct 7 18:03:43 2008 From: ben at benmabey.com (Ben Mabey) Date: Tue, 07 Oct 2008 16:03:43 -0600 Subject: [rspec-users] gem generators on 1.2.6 In-Reply-To: <810a540e0810071456v772ce222m6d2bd1be5f6d03d6@mail.gmail.com> References: <810a540e0810071456v772ce222m6d2bd1be5f6d03d6@mail.gmail.com> Message-ID: <48EBDCBF.8050206@benmabey.com> Pat Maddox wrote: > In a 1.2.6 app (don't ask), I don't see the generators available to me > with the gems installed. However the documentation makes it look like > it should work: > Generator gems are also available: > 1. gem search -r generator > 2. gem install login_generator > 3. ./script/generate login > > I've confirmed that with a fresh rails (2.x) app it works fine. Is > this supposed to work with 1.2.6? Are there any workarounds that > people have? Is my app just fucked atm? > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > Hmm.. I don't know if that was supported in 1.2.6.. I know having generators in your home dir was. Try this workaround: mkdir -p ~/.rails/generators ln -s /your_gem_path/rspec-rails-1.1.8/generators ~/.rails/generators/rspec-rails-1.1.8 HTH, Ben From lists at ruby-forum.com Tue Oct 7 18:24:01 2008 From: lists at ruby-forum.com (Pau Cor) Date: Wed, 8 Oct 2008 00:24:01 +0200 Subject: [rspec-users] Testing Generators In-Reply-To: <4BD19DB2-2A05-4D39-86BB-CB8AB32DED07@railsnewbie.com> References: <4BD19DB2-2A05-4D39-86BB-CB8AB32DED07@railsnewbie.com> Message-ID: <7602a0569814db87994323850cbd7cbe@ruby-forum.com> Scott Taylor wrote: > Why don't you generate the specs when you generate the code? That's what I thought I'd have to do. The reason I'm reluctant to do it is that either I need to write the real code first (and not tests first). Or I need to rerun my generator every time I write a new test (or write the code to make the test pass). It seems awkward, but I guess it isn't avoidable. Thanks! -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Tue Oct 7 19:04:18 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 7 Oct 2008 16:04:18 -0700 Subject: [rspec-users] expected redirect to "/admin/account", got redirect to "/admin/account" ... Message-ID: <810a540e0810071604o58c2df95p8eb5d5ea239122c2@mail.gmail.com> Getting the failure message: expected redirect to "/admin/account", got redirect to "/admin/account" I'm on Rails 1.2.6 with edge rspec/rspec-rails. There's nothing funky inside that I can tell, but this is my first day with the app. I assume this has to do with the fact that it's old ass rails...but our suite passes against 1.2.6, so I'm pretty confused. Any ideas? Pat From mailing_lists at railsnewbie.com Tue Oct 7 19:26:32 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Tue, 7 Oct 2008 19:26:32 -0400 Subject: [rspec-users] expected redirect to "/admin/account", got redirect to "/admin/account" ... In-Reply-To: <810a540e0810071604o58c2df95p8eb5d5ea239122c2@mail.gmail.com> References: <810a540e0810071604o58c2df95p8eb5d5ea239122c2@mail.gmail.com> Message-ID: On Oct 7, 2008, at 7:04 PM, Pat Maddox wrote: > Getting the failure message: > expected redirect to "/admin/account", got redirect to "/admin/ > account" > > I'm on Rails 1.2.6 with edge rspec/rspec-rails. There's nothing funky > inside that I can tell, but this is my first day with the app. I > assume this has to do with the fact that it's old ass rails...but our > suite passes against 1.2.6, so I'm pretty confused. Any ideas? Does it work when you pass a hash parameter instead of a URL? Could it be a difference in the host? Scott From dchelimsky at gmail.com Tue Oct 7 19:34:38 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Oct 2008 18:34:38 -0500 Subject: [rspec-users] gem generators on 1.2.6 In-Reply-To: <810a540e0810071458q4845470bxe8af1b132062c35@mail.gmail.com> References: <810a540e0810071456v772ce222m6d2bd1be5f6d03d6@mail.gmail.com> <810a540e0810071458q4845470bxe8af1b132062c35@mail.gmail.com> Message-ID: <57c63afe0810071634o3338a077laf08c20937476313@mail.gmail.com> On Tue, Oct 7, 2008 at 4:58 PM, Pat Maddox wrote: >> I've confirmed that with a fresh rails (2.x) app it works fine. Is >> this supposed to work with 1.2.6? Are there any workarounds that >> people have? Is my app just fucked atm? > > erm, I've also confirmed that with a fresh rails 1.2.6 app it DOESN'T > see the gem generators. I'm pretty suspicious though because of that > documentation. Hey Pat - until recently, generator plugins were only found if they were named [something]_generator: http://github.com/rails/rails/commit/868e6b08df4b16fb71cc8a66308174253ff67bdb So on 1.2.6, you're kinda screwed unless you want to create a local copy of the rspec-rails gem named rspec-rails_generator :( Cheers, David > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Oct 7 19:39:35 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 7 Oct 2008 18:39:35 -0500 Subject: [rspec-users] Testing Generators In-Reply-To: <7602a0569814db87994323850cbd7cbe@ruby-forum.com> References: <4BD19DB2-2A05-4D39-86BB-CB8AB32DED07@railsnewbie.com> <7602a0569814db87994323850cbd7cbe@ruby-forum.com> Message-ID: <57c63afe0810071639k27052b30r14bace7d517732db@mail.gmail.com> On Tue, Oct 7, 2008 at 5:24 PM, Pau Cor wrote: > Scott Taylor wrote: >> Why don't you generate the specs when you generate the code? > > That's what I thought I'd have to do. The reason I'm reluctant to do it > is that either I need to write the real code first (and not tests > first). Or I need to rerun my generator every time I write a new test > (or write the code to make the test pass). If you know what code you're trying to generate, you could use the "gold master" approach, where you write a file with the code you want to produce (the "gold master") and use that as the source of expected values created by the generator. Using regular expressions or tools like Hpricot you can do this incrementally. It's not necessarily easy :) But it does let you write tests first. Cheers, David > > It seems awkward, but I guess it isn't avoidable. > > Thanks! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Tue Oct 7 19:48:52 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 7 Oct 2008 16:48:52 -0700 Subject: [rspec-users] gem generators on 1.2.6 In-Reply-To: <57c63afe0810071634o3338a077laf08c20937476313@mail.gmail.com> References: <810a540e0810071456v772ce222m6d2bd1be5f6d03d6@mail.gmail.com> <810a540e0810071458q4845470bxe8af1b132062c35@mail.gmail.com> <57c63afe0810071634o3338a077laf08c20937476313@mail.gmail.com> Message-ID: <810a540e0810071648u2b57d60bxee8219241434b237@mail.gmail.com> On Tue, Oct 7, 2008 at 4:34 PM, David Chelimsky wrote: > On Tue, Oct 7, 2008 at 4:58 PM, Pat Maddox wrote: >>> I've confirmed that with a fresh rails (2.x) app it works fine. Is >>> this supposed to work with 1.2.6? Are there any workarounds that >>> people have? Is my app just fucked atm? >> >> erm, I've also confirmed that with a fresh rails 1.2.6 app it DOESN'T >> see the gem generators. I'm pretty suspicious though because of that >> documentation. > > Hey Pat - until recently, generator plugins were only found if they > were named [something]_generator: > > http://github.com/rails/rails/commit/868e6b08df4b16fb71cc8a66308174253ff67bdb > > So on 1.2.6, you're kinda screwed unless you want to create a local > copy of the rspec-rails gem named rspec-rails_generator :( No prob, I'll just use the plugins then. Thanks for the info. Pat From josephwilk at joesniff.co.uk Wed Oct 8 05:05:10 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Wed, 08 Oct 2008 10:05:10 +0100 Subject: [rspec-users] Adding Test Spy into Rspec mocking framework In-Reply-To: <1d7ddd110810061958s55964623m4e1672601debf4bc@mail.gmail.com> References: <47c2f06bf2ef01bc90e2b4f0666a904e@ruby-forum.com> <810a540e0809150539r56d67952sb519e281fe9a3629@mail.gmail.com> <57c63afe0809150543i5fb73731s14d97c64528098fe@mail.gmail.com> <810a540e0809150549w503a351ek49308a4388b09d57@mail.gmail.com> <49deff6c83e30353ff40a31aa4e562af@ruby-forum.com> <1d7ddd110810061958s55964623m4e1672601debf4bc@mail.gmail.com> Message-ID: <48EC77C6.8030302@joesniff.co.uk> Brian Takita wrote: > On Sun, Sep 21, 2008 at 11:17 AM, Joseph Wilk wrote: > >> I've been doing further work on adding the Test Spy to the RR mocking >> framework. >> > Awesome! Do you have a clone available? I'm not quite ready to push my work up to Github. I've been trying lots of spikes experimenting with what a spy means in RR. I'll let you know as soon as I push my work up to github. I'll share my thoughts so far on what I think RR's interpretation of a Spy could be. In the traditional sense a spy is a stub object that records method invocations. But RR is all about taking real objects and using double injection. It feels out of place to introduce a stub object as a spy. So the direction I've been leaning towards is a spy should be a real object that logs its calls. Those calls follow the real implementation. You can still stub the spy. This feels like the most natural solution for RR, though its much harder to implement than just a stub object :) @@@ class Example def shout(words) "#{words}!" end end example = Example.new spy(example) example.shout("monkeys") >> "monkeys!" verify(example).shout("monkeys") @@@ Whats your opinion Brian? Anyone else? Oh, I've really enjoyed going through RR's source and I've learnt a lot from it, thanks! -- Joseph Wilk http://www.joesniff.co.uk From jeroentjevandijk at gmail.com Wed Oct 8 07:01:25 2008 From: jeroentjevandijk at gmail.com (Jeroen van Dijk) Date: Wed, 8 Oct 2008 13:01:25 +0200 Subject: [rspec-users] Refactoring and using each Message-ID: Hi all, I'm new to this list and new to RSpec so I have been trying out RSpec the last couple of days and I find it very a natural way of testing. So first of all thanks for providing this framework. Now, I have written some tests for my controllers and models and I saw myself writing similar code, so I began refactoring and came up with the following issue. Here is a simple example of what I first wrote: describe Example do it "should not be valid without attribute1" do Example.new(:attribute2 => "2").should_not be_valid end it "should not be valid without attribute2" do Example.new(:attribute1 => "1").should_not be_valid end end Which I rewrote into another working test: ###### module ExampleSpecHelper def required_valid_attributes {:attribute1 => "1", :attribute2 => "2"} end end describe Example do include ExampleSpecHelper [:attribute1, :attribute2].each do |attribute| before(:all) do @model_with_one_missing_attribute = TextMessage.new(required_valid_attributes.except(attribute)) end it "should not be valid without #{attribute}" do @model_with_one_missing_attribute.should_not be_valid end end ##### In this example in you might not see difference in lines of code, but imagine you would have 10 attributes and 10 more tests for each attribute.. Now I rewrote this I was still not satisfied because I thought I would like to use this same approach for several models with different attributes while keeping the logic of this test in one place. Unfortunately, I didn't come that far because of this: #this works: describe Example do include ExampleSpecHelper required_attributes = [:attribute1, :attribute2] required_attributes.each do |attribute| before(:all) do @model_with_one_missing_attribute = TextMessage.new(required_valid_attributes.except(attribute)) end it "should not be valid without #{attribute}" do @model_with_one_missing_attribute.should_not be_valid end end #However this which eventually will be more DRY, but does for some reason not work?! module ExampleSpecHelper ... def required_attributes [:attribute1, :attribute2] end ... end describe Example do include ExampleSpecHelper required_attributes.each do |attribute| before(:all) do @model_with_one_missing_attribute = TextMessage.new(required_valid_attributes.except(attribute)) end it "should not be valid without #{attribute}" do @model_with_one_missing_attribute.should_not be_valid end end ############ I don't understand why it does not work. In the last example required_attributes is nil while the other methods from the helper module such as 'required_valid_attributes' are available on an even lower level. Why? I hope you understand why I'm trying to refactor it like this. If I can do this I only need to define the required attributes for each model and use it_should_behave_like "an AR model" to keep it DRY. Hope someone can clarify this and that I haven't done something stupid! Thanks! Cheers, Jeroen -------------- next part -------------- An HTML attachment was scrubbed... URL: From aidy.lewis at googlemail.com Wed Oct 8 07:56:12 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Wed, 8 Oct 2008 12:56:12 +0100 Subject: [rspec-users] cucumber and printed step and line number Message-ID: <7ac2300c0810080456v591c65d8p7c907e4ea9053b1a@mail.gmail.com> Hi, Today I installed the latest cucumber gem. For some reason, the actual current step file and step line number is being printed to the right of the step in the console. E.g. And enters into job reference # steps/publish_content_steps.rb:134 Is this a switch I can turn off? Aidy From dchelimsky at gmail.com Wed Oct 8 08:21:16 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Oct 2008 07:21:16 -0500 Subject: [rspec-users] cucumber and printed step and line number In-Reply-To: <7ac2300c0810080456v591c65d8p7c907e4ea9053b1a@mail.gmail.com> References: <7ac2300c0810080456v591c65d8p7c907e4ea9053b1a@mail.gmail.com> Message-ID: <57c63afe0810080521r63864f21q1413b161977b5e07@mail.gmail.com> On Wed, Oct 8, 2008 at 6:56 AM, aidy lewis wrote: > Hi, > > Today I installed the latest cucumber gem. > > For some reason, the actual current step file and step line number is > being printed to the right of the step in the console. > > E.g. > > And enters into job reference # steps/publish_content_steps.rb:134 > > Is this a switch I can turn off? Did you try 'cucumber -h' as Aslak advised in a previous thread about cucumber? > > Aidy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From josephwilk at joesniff.co.uk Wed Oct 8 08:26:46 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Wed, 08 Oct 2008 13:26:46 +0100 Subject: [rspec-users] cucumber and printed step and line number In-Reply-To: <7ac2300c0810080456v591c65d8p7c907e4ea9053b1a@mail.gmail.com> References: <7ac2300c0810080456v591c65d8p7c907e4ea9053b1a@mail.gmail.com> Message-ID: <48ECA706.60605@joesniff.co.uk> aidy lewis wrote: > Hi, > > Today I installed the latest cucumber gem. > > For some reason, the actual current step file and step line number is > being printed to the right of the step in the console. > > E.g. > > And enters into job reference # steps/publish_content_steps.rb:134 > > Is this a switch I can turn off? > > Aidy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > Showing the step and line was made the default behavior. You can turn it off using --no-source -- Joseph Wilk http://www.joesniff.co.uk From dchelimsky at gmail.com Wed Oct 8 09:02:10 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Oct 2008 08:02:10 -0500 Subject: [rspec-users] Refactoring and using each In-Reply-To: References: Message-ID: <57c63afe0810080602i32fef783t231cbbf85386dbf1@mail.gmail.com> On Wed, Oct 8, 2008 at 6:01 AM, Jeroen van Dijk wrote: > Hi all, > > I'm new to this list and new to RSpec so I have been trying out RSpec the > last couple of days and I find it very a natural way of testing. So first of > all thanks for providing this framework. > > Now, I have written some tests for my controllers and models and I saw > myself writing similar code, so I began refactoring and came up with the > following issue. > > Here is a simple example of what I first wrote: > > describe Example do > > it "should not be valid without attribute1" do > Example.new(:attribute2 => "2").should_not be_valid > end > > it "should not be valid without attribute2" do > Example.new(:attribute1 => "1").should_not be_valid > end > end > > Which I rewrote into another working test: > > ###### > module ExampleSpecHelper > def required_valid_attributes > {:attribute1 => "1", :attribute2 => "2"} > end > end > > describe Example do > include ExampleSpecHelper > [:attribute1, :attribute2].each do |attribute| > before(:all) do > @model_with_one_missing_attribute = > TextMessage.new(required_valid_attributes.except(attribute)) > end > > it "should not be valid without #{attribute}" do > @model_with_one_missing_attribute.should_not be_valid > end > end > ##### > > In this example in you might not see difference in lines of code, but > imagine you would have 10 attributes and 10 more tests for each attribute.. > Now I rewrote this I was still not satisfied because I thought I would like > to use this same approach for several models with different attributes > while keeping the logic of this test in one place. Unfortunately, I didn't > come that far because of this: > > #this works: > describe Example do > include ExampleSpecHelper > required_attributes = [:attribute1, :attribute2] > required_attributes.each do |attribute| > before(:all) do > @model_with_one_missing_attribute = > TextMessage.new(required_valid_attributes.except(attribute)) > end > > it "should not be valid without #{attribute}" do > @model_with_one_missing_attribute.should_not be_valid > end > end > > #However this which eventually will be more DRY, but does for some reason > not work?! > module ExampleSpecHelper > ... > def required_attributes > [:attribute1, :attribute2] > end > ... > end > > describe Example do > include ExampleSpecHelper > required_attributes.each do |attribute| > before(:all) do > @model_with_one_missing_attribute = > TextMessage.new(required_valid_attributes.except(attribute)) > end > > it "should not be valid without #{attribute}" do > @model_with_one_missing_attribute.should_not be_valid > end > end > > > ############ > > I don't understand why it does not work. In the last example > required_attributes is nil while the other methods from the helper module > such as 'required_valid_attributes' are available on an even lower level. > Why? I hope you understand why I'm trying to refactor it like this. If I can > do this I only need to define the required attributes for each model and use > it_should_behave_like "an AR model" to keep it DRY. > > Hope someone can clarify this and that I haven't done something stupid! There are a couple of problems with this approach. First of all, before(:all) runs only once per group, whereas before(:each) runs repeatedly before(:each) example. This means that whatever gets created before(:all) is shared across examples, whereas what is created in before(:each) is not. Generally speaking, you should avoid before(:all) except for setting up expensive things like database connections. Also, you can write as many different before(:each) or before(:all) blocks and they will all be run, so this: [:attribute1, :attribute2].each do |attribute| before(:all) do @model_with_one_missing_attribute = TextMessage.new(required_valid_attributes.except(attribute)) end end is the equivalent of this: before(:all) do @model_with_one_missing_attribute = TextMessage.new(required_valid_attributes.except(:attribute1)) end before(:all) do @model_with_one_missing_attribute = TextMessage.new(required_valid_attributes.except(:attribute2)) end They get run in order, one time each, resulting in @model_with_one_missing_attribute missing :attribute2 for every time the example gets run. The same problem would happen with before(:each) in this case. What might work here would be something like this: describe "this model" do def valid_attributes {:first => 'valid', :second => 'valid'} end valid_attributes.keys.each do |attribute| it "should require #{attribute} @model.new(valid_attributes.dup.delete(attribute)).should_not be_valid end end end I've seen a number of variations like this posted to this list, so you might want to search the archives for 'model validation'. Also, there are a few plugins that offer ways to do this already: http://github.com/joshknowles/rspec-on-rails-matchers http://github.com/pelargir/rspec_validation_expectations I'm sure there are others. HTH, Cheers, David > Thanks! > > Cheers, > > Jeroen From lists at ruby-forum.com Wed Oct 8 09:16:00 2008 From: lists at ruby-forum.com (Daniel Higginbotham) Date: Wed, 8 Oct 2008 15:16:00 +0200 Subject: [rspec-users] cucumber and fixtures Message-ID: Is it possible to use spec fixtures with Cucumber, and if so, how? Thanks, Daniel Higginbotham -- Posted via http://www.ruby-forum.com/. From aslak.hellesoy at gmail.com Wed Oct 8 10:28:25 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 8 Oct 2008 16:28:25 +0200 Subject: [rspec-users] cucumber and fixtures In-Reply-To: References: Message-ID: <8d961d900810080728s4ba72cdawc4af9360396e811c@mail.gmail.com> On Wed, Oct 8, 2008 at 3:16 PM, Daniel Higginbotham wrote: > Is it possible to use spec fixtures with Cucumber, and if so, how? > Google for cucumber fixtures http://www.ruby-forum.com/topic/165215 http://www.ruby-forum.com/topic/165777 > Thanks, > Daniel Higginbotham > -- > 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 Wed Oct 8 10:44:49 2008 From: lists at ruby-forum.com (Daniel Higginbotham) Date: Wed, 8 Oct 2008 16:44:49 +0200 Subject: [rspec-users] cucumber and fixtures In-Reply-To: <8d961d900810080728s4ba72cdawc4af9360396e811c@mail.gmail.com> References: <8d961d900810080728s4ba72cdawc4af9360396e811c@mail.gmail.com> Message-ID: aslak hellesoy wrote: > On Wed, Oct 8, 2008 at 3:16 PM, Daniel Higginbotham > wrote: >> Is it possible to use spec fixtures with Cucumber, and if so, how? >> > > Google for cucumber fixtures > > http://www.ruby-forum.com/topic/165215 > http://www.ruby-forum.com/topic/165777 Yep, I've read those threads and they both explain how to use alternatives to fixtures, not fixtures themselves. In the first thread you posted, the OP mentions that he was trying to use fixtures and they were never loaded into his DB. Is there some way to use fixtures with Cucumber - not FixtureReplacement, not mocks, not ObjectDaddy, just fixtures? Thanks, Daniel Higginbotham -- Posted via http://www.ruby-forum.com/. From josephwilk at joesniff.co.uk Wed Oct 8 11:43:19 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Wed, 08 Oct 2008 16:43:19 +0100 Subject: [rspec-users] Making Rspec errors with anything less verbose. Message-ID: <48ECD517.8010102@joesniff.co.uk> Hello, I was doing some work on cucumber and it hit me that this error message from a failed spec was a little too verbose. The spec test is: Cucumber::Tree::RowScenario.should_receive(:new).with(anything, anything, ['I can have spaces'], anything) And when the test fails the output is: --- Spec::Mocks::MockExpectationError in 'Cucumber::TreetopParser::FeatureParser should allow backslashed | in FIT values' Mock 'Class' expected :new with (#, #, ["I can have | and its ok"], #) but received it with (#, @steps_and_given_scenarios=[#>], @table_header=["c"]>]>, #]>, @steps_and_given_scenarios=[#>], @table_header=["c"]>, ["I can have \\", "and its ok"], 7) --- Its a little hard to read! What I think might be more helpful is to replace arguments that match 'anything' with a wild card such as '_'. This would give me the much easier to read error message: --- Spec::Mocks::MockExpectationError in 'Cucumber::TreetopParser::FeatureParser should allow backslashed | in FIT values' Mock 'Class' expected :new with (_, _, ["I can have | and its ok"], _) but received it with (_, _, ["I can have \\", "and its ok"], _) --- So what I'm suggesting is 1. Replace: # With: '_' 2. Replace received with parameters which are marked in the expectation as anything with '_' Does that seem sensible? Is there value to seeing arguments received when you have marked them as 'anything'? -- Joseph Wilk http://www.joesniff.co.uk From weyus at att.net Wed Oct 8 14:09:47 2008 From: weyus at att.net (Wes Gamble) Date: Wed, 08 Oct 2008 13:09:47 -0500 Subject: [rspec-users] Rspec: gem vs. plugin? Message-ID: <48ECF76B.508@att.net> All, I have some experience with Rspec from about a year ago. At that time, there was a gem and a plugin, and a Rspec on Rails plugin. Should I only be using the gem? With the 1.1.8 gem, if I try to do "rake rspec" in my Rails app., nothing happens. Do I need to use the Rspec Rails plugin to get that behavior. I took a look at the main RSpec site, but was unable to answer these questions by going there. My suspicion is that only the gem should be used, but then how do I get the rake task? Thanks, Wes From matt at mattwynne.net Wed Oct 8 14:15:04 2008 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 8 Oct 2008 19:15:04 +0100 Subject: [rspec-users] ArgumentError in "is a pending example" - block not supplied Message-ID: <57B0E1C5-6CB8-45F1-80F8-9D558037BB60@mattwynne.net> We have a few unfinished examples in our code of the form it "should and does do something" do # stuff end it "should do something someday" it "should and does do something else" do # more stuff end Now since I upgraded my gem to rspec 1.8 today, the empty example is failing with the error ArgumentError in "should do something someday": block not supplied Is this by design? What's the recommended way to deal with these pending examples? write a block and call pending within it? cheers, Matt From mailing_lists at railsnewbie.com Wed Oct 8 14:24:22 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 8 Oct 2008 14:24:22 -0400 Subject: [rspec-users] Rspec: gem vs. plugin? In-Reply-To: <48ECF76B.508@att.net> References: <48ECF76B.508@att.net> Message-ID: <2D1E3AC0-CBF0-4D0F-ABAD-88A5AC9FB62E@railsnewbie.com> On Oct 8, 2008, at 2:09 PM, Wes Gamble wrote: > All, > > I have some experience with Rspec from about a year ago. At that > time, there was a gem and a plugin, and a Rspec on Rails plugin. > > Should I only be using the gem? If you're using a rails app, install the two plugins. If not, use the gem. Scott From weyus at att.net Wed Oct 8 14:39:11 2008 From: weyus at att.net (Wes Gamble) Date: Wed, 08 Oct 2008 13:39:11 -0500 Subject: [rspec-users] Rspec: gem vs. plugin? In-Reply-To: <2D1E3AC0-CBF0-4D0F-ABAD-88A5AC9FB62E@railsnewbie.com> References: <48ECF76B.508@att.net> <2D1E3AC0-CBF0-4D0F-ABAD-88A5AC9FB62E@railsnewbie.com> Message-ID: <48ECFE4F.7010402@att.net> I know that this is all probably rather boring for the expert RSpec-ers out there, and I apologize for that. Both Rspec and Rspec-Rails are currently distributed as both plugins AND gems? Are the plugins just available in case you don't have the ability/permission to install gems? I can understand why there would be an RSpec gem (to use outside of Rails, of course), and I can understand why there is a Rails plugin to give you additional RSpec functionality for Rails. But I'm not sure what the purpose of the RSpec plugin is, and also not sure what the purpose of the RSpec-Rails gem is? Is there a place online that summarizes the various distribution methods and when to use which? Thanks, Wes Scott Taylor wrote: > > On Oct 8, 2008, at 2:09 PM, Wes Gamble wrote: > >> All, >> >> I have some experience with Rspec from about a year ago. At that >> time, there was a gem and a plugin, and a Rspec on Rails plugin. >> >> Should I only be using the gem? > > If you're using a rails app, install the two plugins. If not, use the > gem. > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Wed Oct 8 14:48:13 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 8 Oct 2008 14:48:13 -0400 Subject: [rspec-users] Rspec: gem vs. plugin? In-Reply-To: <48ECFE4F.7010402@att.net> References: <48ECF76B.508@att.net> <2D1E3AC0-CBF0-4D0F-ABAD-88A5AC9FB62E@railsnewbie.com> <48ECFE4F.7010402@att.net> Message-ID: <85d99afe0810081148v7f6fdd89y702aa53b40b0bfab@mail.gmail.com> This recently came up, rather than re-discussing please see: http://www.ruby-forum.com/topic/167379#new Zach On Wed, Oct 8, 2008 at 2:39 PM, Wes Gamble wrote: > I know that this is all probably rather boring for the expert RSpec-ers out > there, and I apologize for that. > > Both Rspec and Rspec-Rails are currently distributed as both plugins AND > gems? Are the plugins just available in case you don't have the > ability/permission to install gems? > > I can understand why there would be an RSpec gem (to use outside of Rails, > of course), and I can understand why there is a Rails plugin to give you > additional RSpec functionality for Rails. > But I'm not sure what the purpose of the RSpec plugin is, and also not sure > what the purpose of the RSpec-Rails gem is? > > Is there a place online that summarizes the various distribution methods and > when to use which? > > Thanks, > Wes > > Scott Taylor wrote: >> >> On Oct 8, 2008, at 2:09 PM, Wes Gamble wrote: >> >>> All, >>> >>> I have some experience with Rspec from about a year ago. At that time, >>> there was a gem and a plugin, and a Rspec on Rails plugin. >>> >>> Should I only be using the gem? >> >> If you're using a rails app, install the two plugins. If not, use the >> gem. >> >> Scott >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From weyus at att.net Wed Oct 8 15:09:48 2008 From: weyus at att.net (Wes Gamble) Date: Wed, 08 Oct 2008 14:09:48 -0500 Subject: [rspec-users] Rspec: gem vs. plugin? In-Reply-To: <85d99afe0810081148v7f6fdd89y702aa53b40b0bfab@mail.gmail.com> References: <48ECF76B.508@att.net> <2D1E3AC0-CBF0-4D0F-ABAD-88A5AC9FB62E@railsnewbie.com> <48ECFE4F.7010402@att.net> <85d99afe0810081148v7f6fdd89y702aa53b40b0bfab@mail.gmail.com> Message-ID: <48ED057C.2080008@att.net> Zach, Thanks for this. I installed the gem and ran "script/generate rspec" and it appears that I don't need the plugins anymore. Wes Zach Dennis wrote: > This recently came up, rather than re-discussing please see: > > http://www.ruby-forum.com/topic/167379#new > > Zach > > On Wed, Oct 8, 2008 at 2:39 PM, Wes Gamble wrote: > >> I know that this is all probably rather boring for the expert RSpec-ers out >> there, and I apologize for that. >> >> Both Rspec and Rspec-Rails are currently distributed as both plugins AND >> gems? Are the plugins just available in case you don't have the >> ability/permission to install gems? >> >> I can understand why there would be an RSpec gem (to use outside of Rails, >> of course), and I can understand why there is a Rails plugin to give you >> additional RSpec functionality for Rails. >> But I'm not sure what the purpose of the RSpec plugin is, and also not sure >> what the purpose of the RSpec-Rails gem is? >> >> Is there a place online that summarizes the various distribution methods and >> when to use which? >> >> Thanks, >> Wes >> >> Scott Taylor wrote: >> >>> On Oct 8, 2008, at 2:09 PM, Wes Gamble wrote: >>> >>> >>>> All, >>>> >>>> I have some experience with Rspec from about a year ago. At that time, >>>> there was a gem and a plugin, and a Rspec on Rails plugin. >>>> >>>> Should I only be using the gem? >>>> >>> If you're using a rails app, install the two plugins. If not, use the >>> gem. >>> >>> Scott >>> >>> _______________________________________________ >>> 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 pergesu at gmail.com Wed Oct 8 15:09:50 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 08 Oct 2008 12:09:50 -0700 Subject: [rspec-users] Rspec: gem vs. plugin? In-Reply-To: <2D1E3AC0-CBF0-4D0F-ABAD-88A5AC9FB62E@railsnewbie.com> (Scott Taylor's message of "Wed\, 8 Oct 2008 14\:24\:22 -0400") References: <48ECF76B.508@att.net> <2D1E3AC0-CBF0-4D0F-ABAD-88A5AC9FB62E@railsnewbie.com> Message-ID: Scott Taylor writes: > On Oct 8, 2008, at 2:09 PM, Wes Gamble wrote: > >> All, >> >> I have some experience with Rspec from about a year ago. At that >> time, there was a gem and a plugin, and a Rspec on Rails plugin. >> >> Should I only be using the gem? > > If you're using a rails app, install the two plugins. If not, use the > gem. I don't actually see any reason to use the plugins anymore. Personally I go with gems. To OP: you said that "rake spec" doesn't do anything...did you run "script/generate rspec" to get the rspec rake tasks? Pat From weyus at att.net Wed Oct 8 15:15:14 2008 From: weyus at att.net (Wes Gamble) Date: Wed, 08 Oct 2008 14:15:14 -0500 Subject: [rspec-users] Basic Rspec operation questions Message-ID: <48ED06C2.9000200@att.net> With Rails, is "rake spec" supposed to automatically run under the test environment? I have to do "rake spec RAILS_ENV=test" in order to get the environments/test.rb file to load. Also, are the standard Test::Unit fixtures automatically loaded before each test in each spec file? This appears to be the case based on my current spec's behavior, but wanted to verify. Thanks, Wes From zach.dennis at gmail.com Wed Oct 8 15:51:31 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 8 Oct 2008 15:51:31 -0400 Subject: [rspec-users] Basic Rspec operation questions In-Reply-To: <48ED06C2.9000200@att.net> References: <48ED06C2.9000200@att.net> Message-ID: <85d99afe0810081251p39bda626y969c40f0b803812@mail.gmail.com> In your spec/spec_helper.rb file you should see a line at the to which says RAILS_ENV="test". If you haven't modified your spec_helper.rb file I would remove it and re-run "script/generate rspec". It should be there. I just generated a new Rails project with rspec and rspec-rails gems. Here's the top of my spec/spec_helper.rb: # This file is copied to ~/spec when you run 'ruby script/generate rspec' # from the project root directory. ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'spec' require 'spec/rails' Zach On Wed, Oct 8, 2008 at 3:15 PM, Wes Gamble wrote: > With Rails, is "rake spec" supposed to automatically run under the test > environment? I have to do "rake spec RAILS_ENV=test" in order to get the > environments/test.rb file to load. > > Also, are the standard Test::Unit fixtures automatically loaded before each > test in each spec file? This appears to be the case based on my current > spec's behavior, but wanted to verify. > > Thanks, > Wes > _______________________________________________ > 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 zach.dennis at gmail.com Wed Oct 8 15:55:58 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 8 Oct 2008 15:55:58 -0400 Subject: [rspec-users] cucumber and fixtures In-Reply-To: References: <8d961d900810080728s4ba72cdawc4af9360396e811c@mail.gmail.com> Message-ID: <85d99afe0810081255w3c541264j6405b6707f959425@mail.gmail.com> I use seed_fu with cucumber. http://github.com/mbleigh/seed-fu/tree To load them I use the following my features/steps/env.rb. I reload them for every scenarios: Before do ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test']) ActiveRecord::Schema.verbose = false load "#{RAILS_ROOT}/db/schema.rb" Dir[File.join(RAILS_ROOT, "features/fixtures", '*.rb')].sort.each { |fixture| load fixture } end My fixture files live in features/fixtures/ and each looks like: # my_model.rb MyModel.transaction do MyModel.seed_many(:id, [ { :name => "blah", :id => 1 }, { :name => "foo", :id => 2 ]) end I use seed_fu for seeding production data as well. I don't use it in the sense of Rails fixtures. I use it in the sense of "the app needs this data to even run, period." Seems maybe this is what you're looking for, Zach On Wed, Oct 8, 2008 at 10:44 AM, Daniel Higginbotham wrote: > aslak hellesoy wrote: >> On Wed, Oct 8, 2008 at 3:16 PM, Daniel Higginbotham >> wrote: >>> Is it possible to use spec fixtures with Cucumber, and if so, how? >>> >> >> Google for cucumber fixtures >> >> http://www.ruby-forum.com/topic/165215 >> http://www.ruby-forum.com/topic/165777 > > Yep, I've read those threads and they both explain how to use > alternatives to fixtures, not fixtures themselves. In the first thread > you posted, the OP mentions that he was trying to use fixtures and they > were never loaded into his DB. > > Is there some way to use fixtures with Cucumber - not > FixtureReplacement, not mocks, not ObjectDaddy, just fixtures? > > Thanks, > Daniel Higginbotham > -- > 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 http://www.mutuallyhuman.com From weyus at att.net Wed Oct 8 16:41:37 2008 From: weyus at att.net (Wes Gamble) Date: Wed, 08 Oct 2008 15:41:37 -0500 Subject: [rspec-users] Basic Rspec operation questions In-Reply-To: <85d99afe0810081251p39bda626y969c40f0b803812@mail.gmail.com> References: <48ED06C2.9000200@att.net> <85d99afe0810081251p39bda626y969c40f0b803812@mail.gmail.com> Message-ID: <48ED1B01.9060600@att.net> Zach, Zach Dennis wrote: > # This file is copied to ~/spec when you run 'ruby script/generate rspec' > # from the project root directory. > ENV["RAILS_ENV"] = "test" > require File.expand_path(File.dirname(__FILE__) + "/../config/environment") > require 'spec' > require 'spec/rails' > This is exactly what the top of my spec_helper.rb file looks like. I have several specs, and the success of running them is different depending on what I do. I'm really just trying to figure out how to take advantage of the "rake spec" task. I'm on Windows XP. Rails 2.1.0. Rspec and Rspec-Rails 1.1.8 gems. No Rspec plugins. Freshly generate rspec stuff using "ruby script/generate rspec" 1) If I run each of my specs separately on the command line using "spec spec/whatever.rb" they run fine. 2) If I run "spec spec/*spec.rb", then all _but one_ run without error (note that the one that files can be run successfully using a direct call to it as in #1 above). 3) If I run "rake spec", I get multiple failures, all because the config/environments/test.rb file is not loaded (I know this because they fail due to the lack of a variable that is set only in test.rb). The spec that failed in #2 works in this case. 4) If I run "rake spec RAILS_ENV=test", all _but one_ run without error (same error as in #2). I draw the following conclustions: 1) I only get the color output if I use "rake spec" (not sure why) 2) spec loads test.rb by default, but "rake spec" does not and that's why I have to pass RAILS_ENV=test to the "rake" command. Wes rspec 1.1.8 gem rspec-rails 1.1.8 gem From lists at ruby-forum.com Wed Oct 8 16:46:16 2008 From: lists at ruby-forum.com (Wes Gamble) Date: Wed, 8 Oct 2008 22:46:16 +0200 Subject: [rspec-users] Basic Rspec operation questions In-Reply-To: <48ED1B01.9060600@att.net> References: <48ED06C2.9000200@att.net> <85d99afe0810081251p39bda626y969c40f0b803812@mail.gmail.com> <48ED1B01.9060600@att.net> Message-ID: Correction to above: Wes Gamble wrote: > 2) If I run "spec spec/*spec.rb", then all _but one_ run without error > (note that the one that fails can be run successfully using a direct > call to it as in #1 above). -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Oct 8 17:41:46 2008 From: lists at ruby-forum.com (Anita Anita) Date: Wed, 8 Oct 2008 23:41:46 +0200 Subject: [rspec-users] route_for() Message-ID: <16de84d0e317a0c5cf7d3e07987fa931@ruby-forum.com> Hello, Can I test in the spec the route taken by the redirect_to from the controller? The URL is not controller/action. I tried: route_for(:controller => "signup", :action => "confirmation").should == "/my/set/URL" but no it absolutely wants: ...should == "signup/confirmation" So how can I test my real URL? Thank you, Anita. -- Posted via http://www.ruby-forum.com/. From zach.dennis at gmail.com Wed Oct 8 17:47:01 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 8 Oct 2008 17:47:01 -0400 Subject: [rspec-users] route_for() In-Reply-To: <16de84d0e317a0c5cf7d3e07987fa931@ruby-forum.com> References: <16de84d0e317a0c5cf7d3e07987fa931@ruby-forum.com> Message-ID: <85d99afe0810081447t4d43d5c2p6378c2919b9d178f@mail.gmail.com> Look at the below, I think it entails what you want: describe YourController do it "redirects to the home page" do get :index response.should redirect_to("your_path_here") end end Zach On Wed, Oct 8, 2008 at 5:41 PM, Anita Anita wrote: > Hello, > > Can I test in the spec the route taken by the redirect_to from the > controller? The URL is not controller/action. > I tried: > route_for(:controller => "signup", :action => "confirmation").should == > "/my/set/URL" but no it absolutely wants: ...should == > "signup/confirmation" > So how can I test my real URL? > > Thank you, > Anita. > -- > 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 http://www.mutuallyhuman.com From mailing_lists at railsnewbie.com Wed Oct 8 17:47:30 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 8 Oct 2008 17:47:30 -0400 Subject: [rspec-users] route_for() In-Reply-To: <16de84d0e317a0c5cf7d3e07987fa931@ruby-forum.com> References: <16de84d0e317a0c5cf7d3e07987fa931@ruby-forum.com> Message-ID: <836177F1-ABDE-40CF-87AC-511D9BA25ED7@railsnewbie.com> On Oct 8, 2008, at 5:41 PM, Anita Anita wrote: > Hello, > > Can I test in the spec the route taken by the redirect_to from the > controller? The URL is not controller/action. > I tried: > route_for(:controller => "signup", :action => "confirmation").should > == > "/my/set/URL" but no it absolutely wants: ...should == > "signup/confirmation" > So how can I test my real URL? There may be a more straightforward way, but params_from may help: http://rspec.info/rdoc-rails/classes/Spec/Rails/Example/ControllerExampleGroup.html#M000066 Scott From lists at ruby-forum.com Wed Oct 8 18:26:11 2008 From: lists at ruby-forum.com (Wes Gamble) Date: Thu, 9 Oct 2008 00:26:11 +0200 Subject: [rspec-users] When is spec_helper.rb actually executed? Message-ID: <4ef1a8c488b15e8af68ca539bff50ca2@ruby-forum.com> I'm trying to debug what I suspect is a case where spec_helper.rb is not being executed. I put a puts statement inside the Spec::Runner.configure do |config| block, and I can't ever see the printout. When does spec_helper.rb get run during rspec operation? Thanks, Wes -- Posted via http://www.ruby-forum.com/. From cdemyanovich at gmail.com Wed Oct 8 18:27:54 2008 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Wed, 8 Oct 2008 18:27:54 -0400 Subject: [rspec-users] Rspec: gem vs. plugin? In-Reply-To: References: <48ECF76B.508@att.net> <2D1E3AC0-CBF0-4D0F-ABAD-88A5AC9FB62E@railsnewbie.com> Message-ID: <61c885db0810081527o7322accal77a4e492598591ef@mail.gmail.com> On Wed, Oct 8, 2008 at 3:09 PM, Pat Maddox wrote: > To OP: you said that "rake spec" doesn't do anything...did you run > "script/generate rspec" to get the rspec rake tasks? The OP wrote, "rake rspec." Either that was a typo or he needs to run "rake spec" instead. Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: From weyus at att.net Wed Oct 8 18:32:06 2008 From: weyus at att.net (Wes Gamble) Date: Wed, 08 Oct 2008 17:32:06 -0500 Subject: [rspec-users] Rspec: gem vs. plugin? In-Reply-To: <61c885db0810081527o7322accal77a4e492598591ef@mail.gmail.com> References: <48ECF76B.508@att.net> <2D1E3AC0-CBF0-4D0F-ABAD-88A5AC9FB62E@railsnewbie.com> <61c885db0810081527o7322accal77a4e492598591ef@mail.gmail.com> Message-ID: <48ED34E6.7030704@att.net> I, the OP, meant "rake spec". Sorry for the confusion. Craig Demyanovich wrote: > On Wed, Oct 8, 2008 at 3:09 PM, Pat Maddox > wrote: > > To OP: you said that "rake spec" doesn't do anything...did you run > "script/generate rspec" to get the rspec rake tasks? > > > The OP wrote, "rake rspec." Either that was a typo or he needs to run > "rake spec" instead. > > Regards, > Craig > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Wed Oct 8 18:35:06 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 8 Oct 2008 18:35:06 -0400 Subject: [rspec-users] When is spec_helper.rb actually executed? In-Reply-To: <4ef1a8c488b15e8af68ca539bff50ca2@ruby-forum.com> References: <4ef1a8c488b15e8af68ca539bff50ca2@ruby-forum.com> Message-ID: <59F5748C-642F-4C86-8A72-3B8D6B8795F1@railsnewbie.com> On Oct 8, 2008, at 6:26 PM, Wes Gamble wrote: > I'm trying to debug what I suspect is a case where spec_helper.rb is > not > being executed. > > I put a puts statement inside the Spec::Runner.configure do |config| > block, and I can't ever see the printout. > > When does spec_helper.rb get run during rspec operation? > What does your spec_helper.rb contain? AFAIK, it gets executed before anything else - usually it contains Spec::Runner.configure { .. } > Thanks, > Wes > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From weyus at att.net Wed Oct 8 18:49:45 2008 From: weyus at att.net (Wes Gamble) Date: Wed, 08 Oct 2008 17:49:45 -0500 Subject: [rspec-users] When is spec_helper.rb actually executed? In-Reply-To: <59F5748C-642F-4C86-8A72-3B8D6B8795F1@railsnewbie.com> References: <4ef1a8c488b15e8af68ca539bff50ca2@ruby-forum.com> <59F5748C-642F-4C86-8A72-3B8D6B8795F1@railsnewbie.com> Message-ID: <48ED3909.1070101@att.net> Scott Taylor wrote: > > On Oct 8, 2008, at 6:26 PM, Wes Gamble wrote: > >> I'm trying to debug what I suspect is a case where spec_helper.rb is not >> being executed. >> >> I put a puts statement inside the Spec::Runner.configure do |config| >> block, and I can't ever see the printout. >> >> When does spec_helper.rb get run during rspec operation? >> > > What does your spec_helper.rb contain? > > AFAIK, it gets executed before anything else - usually it contains > Spec::Runner.configure { .. } It is the standard default spec_helper.rb (see below). I could find no reference to it in the rake "spec" task. I added this: require '../../spec/spec_helper' to the "spec" task and now it gets all of the config from spec_helper (including RAILS_ENV which was not being set before). Wes It contains: # This file is copied to ~/spec when you run 'ruby script/generate rspec' # from the project root directory. ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'spec' require 'spec/rails' Spec::Runner.configure do |config| puts "In config block of Spec::Runner" # If you're not using ActiveRecord you should remove these # lines, delete config/database.yml and disable :active_record # in your config/boot.rb config.use_transactional_fixtures = true config.use_instantiated_fixtures = false config.fixture_path = RAILS_ROOT + '/spec/fixtures/' # == Fixtures # # You can declare fixtures for each example_group like this: # describe "...." do # fixtures :table_a, :table_b # # Alternatively, if you prefer to declare them only once, you can # do so right here. Just uncomment the next line and replace the fixture # names with your fixtures. # # config.global_fixtures = :table_a, :table_b # # If you declare global fixtures, be aware that they will be declared # for all of your examples, even those that don't use them. # # == Mock Framework # # RSpec uses it's own mocking framework by default. If you prefer to # use mocha, flexmock or RR, uncomment the appropriate line: # # config.mock_with :mocha # config.mock_with :flexmock # config.mock_with :rr end From pergesu at gmail.com Wed Oct 8 18:58:44 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 08 Oct 2008 15:58:44 -0700 Subject: [rspec-users] When is spec_helper.rb actually executed? In-Reply-To: <48ED3909.1070101@att.net> (Wes Gamble's message of "Wed\, 08 Oct 2008 17\:49\:45 -0500") References: <4ef1a8c488b15e8af68ca539bff50ca2@ruby-forum.com> <59F5748C-642F-4C86-8A72-3B8D6B8795F1@railsnewbie.com> <48ED3909.1070101@att.net> Message-ID: Wes Gamble writes: > Scott Taylor wrote: >> >> On Oct 8, 2008, at 6:26 PM, Wes Gamble wrote: >> >>> I'm trying to debug what I suspect is a case where spec_helper.rb is not >>> being executed. >>> >>> I put a puts statement inside the Spec::Runner.configure do |config| >>> block, and I can't ever see the printout. >>> >>> When does spec_helper.rb get run during rspec operation? >>> >> >> What does your spec_helper.rb contain? >> >> AFAIK, it gets executed before anything else - usually it contains >> Spec::Runner.configure { .. } > It is the standard default spec_helper.rb (see below). I could find > no reference to it in the rake "spec" task. I added this: > > require '../../spec/spec_helper' > > to the "spec" task and now it gets all of the config from spec_helper > (including RAILS_ENV which was not being set before). You don't want to put this in the spec task itself...you should require it from your spec files. It wasn't ever being run because it wasn't ever being loaded :) Pat From lists at ruby-forum.com Wed Oct 8 19:05:23 2008 From: lists at ruby-forum.com (Daniel Higginbotham) Date: Thu, 9 Oct 2008 01:05:23 +0200 Subject: [rspec-users] cucumber and fixtures In-Reply-To: <85d99afe0810081255w3c541264j6405b6707f959425@mail.gmail.com> References: <8d961d900810080728s4ba72cdawc4af9360396e811c@mail.gmail.com> <85d99afe0810081255w3c541264j6405b6707f959425@mail.gmail.com> Message-ID: <55a81029f1194807d52edbbed64a2033@ruby-forum.com> Zach Dennis wrote: > I use seed_fu with cucumber. > > http://github.com/mbleigh/seed-fu/tree > > To load them I use the following my features/steps/env.rb. I reload > them for every scenarios: > > Before do > ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test']) > ActiveRecord::Schema.verbose = false > load "#{RAILS_ROOT}/db/schema.rb" > Dir[File.join(RAILS_ROOT, "features/fixtures", '*.rb')].sort.each { > |fixture| load fixture } > end > > My fixture files live in features/fixtures/ and each looks like: > > # my_model.rb > MyModel.transaction do > MyModel.seed_many(:id, [ > { :name => "blah", :id => 1 }, > { :name => "foo", :id => 2 > ]) > end > > I use seed_fu for seeding production data as well. I don't use it in > the sense of Rails fixtures. I use it in the sense of "the app needs > this data to even run, period." Seems maybe this is what you're > looking for, > > Zach This isn't quite what I'm looking for. I'd actually like to be able to use the fixtures in spec/fixtures , just as I can for plain old specs. With specs, you can define which fixtures to use in each "describe" block, using something like describe TodoList do fixtures :todo_lists, :todos, :users it "should return an error when blah blah blah" do ... end end Are you similarly able to load your YAML fixtures from spec/fixtures when you're running a Cucumber feature? Thanks, Daniel Higginbotham -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Wed Oct 8 19:18:58 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 08 Oct 2008 16:18:58 -0700 Subject: [rspec-users] cucumber and fixtures In-Reply-To: <55a81029f1194807d52edbbed64a2033@ruby-forum.com> (Daniel Higginbotham's message of "Thu\, 9 Oct 2008 01\:05\:23 +0200") References: <8d961d900810080728s4ba72cdawc4af9360396e811c@mail.gmail.com> <85d99afe0810081255w3c541264j6405b6707f959425@mail.gmail.com> <55a81029f1194807d52edbbed64a2033@ruby-forum.com> Message-ID: Daniel Higginbotham writes: > Zach Dennis wrote: >> I use seed_fu with cucumber. >> >> http://github.com/mbleigh/seed-fu/tree >> >> To load them I use the following my features/steps/env.rb. I reload >> them for every scenarios: >> >> Before do >> ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test']) >> ActiveRecord::Schema.verbose = false >> load "#{RAILS_ROOT}/db/schema.rb" >> Dir[File.join(RAILS_ROOT, "features/fixtures", '*.rb')].sort.each { >> |fixture| load fixture } >> end >> >> My fixture files live in features/fixtures/ and each looks like: >> >> # my_model.rb >> MyModel.transaction do >> MyModel.seed_many(:id, [ >> { :name => "blah", :id => 1 }, >> { :name => "foo", :id => 2 >> ]) >> end >> >> I use seed_fu for seeding production data as well. I don't use it in >> the sense of Rails fixtures. I use it in the sense of "the app needs >> this data to even run, period." Seems maybe this is what you're >> looking for, >> >> Zach > > This isn't quite what I'm looking for. I'd actually like to be able to > use the fixtures in spec/fixtures , just as I can for plain old specs. > With specs, you can define which fixtures to use in each "describe" > block, using something like > > describe TodoList do > fixtures :todo_lists, :todos, :users > > it "should return an error when blah blah blah" do > ... > end > end > > Are you similarly able to load your YAML fixtures from spec/fixtures > when you're running a Cucumber feature? > > Thanks, > Daniel Higginbotham I don't know that it's built into Cucumber, but loading fixtures is pretty simple from what I remember. Something like AR::Fixtures.load('path/to/file.yml') or something. Look around and I'm sure you can find the couple lines to make it work. Pat From dchelimsky at gmail.com Wed Oct 8 19:27:47 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Oct 2008 18:27:47 -0500 Subject: [rspec-users] Basic Rspec operation questions In-Reply-To: <48ED1B01.9060600@att.net> References: <48ED06C2.9000200@att.net> <85d99afe0810081251p39bda626y969c40f0b803812@mail.gmail.com> <48ED1B01.9060600@att.net> Message-ID: <57c63afe0810081627kb12460aoe5bf86b630983912@mail.gmail.com> On Wed, Oct 8, 2008 at 3:41 PM, Wes Gamble wrote: > Zach, > > Zach Dennis wrote: >> >> # This file is copied to ~/spec when you run 'ruby script/generate rspec' >> # from the project root directory. >> ENV["RAILS_ENV"] = "test" >> require File.expand_path(File.dirname(__FILE__) + >> "/../config/environment") >> require 'spec' >> require 'spec/rails' >> > > This is exactly what the top of my spec_helper.rb file looks like. > > I have several specs, and the success of running them is different depending > on what I do. I'm really just trying to figure out how to take advantage of > the "rake spec" task. > I'm on Windows XP. Rails 2.1.0. Rspec and Rspec-Rails 1.1.8 gems. No > Rspec plugins. Freshly generate rspec stuff using "ruby script/generate > rspec" > > 1) If I run each of my specs separately on the command line using "spec > spec/whatever.rb" they run fine. > > 2) If I run "spec spec/*spec.rb", then all _but one_ run without error (note > that the one that files can be run successfully using a direct call to it as > in #1 above). > > 3) If I run "rake spec", I get multiple failures, all because the > config/environments/test.rb file is not loaded (I know this because they > fail due to the lack of a variable that is set only in test.rb). The spec > that failed in #2 works in this case. > > 4) If I run "rake spec RAILS_ENV=test", all _but one_ run without error > (same error as in #2). > > I draw the following conclustions: > > 1) I only get the color output if I use "rake spec" (not sure why) > > 2) spec loads test.rb by default, but "rake spec" does not and that's why I > have to pass RAILS_ENV=test to the "rake" command. What is test.rb? As for getting different results if you run files individually, with the spec command or with the rake command, that is *usually* a sign that there is some state leaking between examples. 'rake spec' and 'spec spec' don't load the files in the same order, so the fact that you also get different failures from each of those also supports this theory in your case. Do you have a spec/spec.opts file? What does that look like? > Wes > > rspec 1.1.8 gem > rspec-rails 1.1.8 gem From dchelimsky at gmail.com Wed Oct 8 19:31:06 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Oct 2008 18:31:06 -0500 Subject: [rspec-users] When is spec_helper.rb actually executed? In-Reply-To: References: <4ef1a8c488b15e8af68ca539bff50ca2@ruby-forum.com> <59F5748C-642F-4C86-8A72-3B8D6B8795F1@railsnewbie.com> <48ED3909.1070101@att.net> Message-ID: <57c63afe0810081631g7e6a50behf30f395d30d458c2@mail.gmail.com> On Wed, Oct 8, 2008 at 5:58 PM, Pat Maddox wrote: > Wes Gamble writes: > >> Scott Taylor wrote: >>> >>> On Oct 8, 2008, at 6:26 PM, Wes Gamble wrote: >>> >>>> I'm trying to debug what I suspect is a case where spec_helper.rb is not >>>> being executed. >>>> >>>> I put a puts statement inside the Spec::Runner.configure do |config| >>>> block, and I can't ever see the printout. >>>> >>>> When does spec_helper.rb get run during rspec operation? RSpec does not "run" spec_helper. By default, rspec loads files that end with "_spec.rb" and it is up to those files to require spec_helper.rb. HTH, David >>>> >>> >>> What does your spec_helper.rb contain? >>> >>> AFAIK, it gets executed before anything else - usually it contains >>> Spec::Runner.configure { .. } >> It is the standard default spec_helper.rb (see below). I could find >> no reference to it in the rake "spec" task. I added this: >> >> require '../../spec/spec_helper' >> >> to the "spec" task and now it gets all of the config from spec_helper >> (including RAILS_ENV which was not being set before). > > You don't want to put this in the spec task itself...you should require > it from your spec files. It wasn't ever being run because it wasn't > ever being loaded :) > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dhf0820 at gmail.com Wed Oct 8 19:31:26 2008 From: dhf0820 at gmail.com (Donald French) Date: Wed, 8 Oct 2008 13:31:26 -1000 Subject: [rspec-users] Testing Views with Authentication In-Reply-To: References: Message-ID: I am trying to figure out how to properly test a view when part of the view is is protected with a role check <% if current_user.admin? %>.. How do I force a log in or mock the current user. I need to do it in a DRY way as this is used throughout the system checking various privileges. Don French From lists at ruby-forum.com Wed Oct 8 19:40:51 2008 From: lists at ruby-forum.com (Wes Gamble) Date: Thu, 9 Oct 2008 01:40:51 +0200 Subject: [rspec-users] When is spec_helper.rb actually executed? In-Reply-To: <57c63afe0810081631g7e6a50behf30f395d30d458c2@mail.gmail.com> References: <4ef1a8c488b15e8af68ca539bff50ca2@ruby-forum.com> <59F5748C-642F-4C86-8A72-3B8D6B8795F1@railsnewbie.com> <48ED3909.1070101@att.net> <57c63afe0810081631g7e6a50behf30f395d30d458c2@mail.gmail.com> Message-ID: OK, got it. I have a follow-up question though. If a given spec DID NOT require spec_helper.rb, doesn't that imply that the spec would be run against the Rails "development" environment. I just did a test where I printed out the configuration of one of my classes DB connnections (e.g. Blah.connection.inspect where Blah is an AR model). And I saw that the "database" setting in this was development. My spec definitely inserts data into the DB. I kind of expected to see additional rows in the table in question. But I just realized that each spec is probably surrounded by a transaction - is that correct? Wes -- Posted via http://www.ruby-forum.com/. From weyus at att.net Wed Oct 8 19:42:25 2008 From: weyus at att.net (Wes Gamble) Date: Wed, 08 Oct 2008 18:42:25 -0500 Subject: [rspec-users] Basic Rspec operation questions In-Reply-To: <57c63afe0810081627kb12460aoe5bf86b630983912@mail.gmail.com> References: <48ED06C2.9000200@att.net> <85d99afe0810081251p39bda626y969c40f0b803812@mail.gmail.com> <48ED1B01.9060600@att.net> <57c63afe0810081627kb12460aoe5bf86b630983912@mail.gmail.com> Message-ID: <48ED4561.4060608@att.net> David Chelimsky wrote: > On Wed, Oct 8, 2008 at 3:41 PM, Wes Gamble wrote: > >> Zach, >> >> Zach Dennis wrote: >> >>> # This file is copied to ~/spec when you run 'ruby script/generate rspec' >>> # from the project root directory. >>> ENV["RAILS_ENV"] = "test" >>> require File.expand_path(File.dirname(__FILE__) + >>> "/../config/environment") >>> require 'spec' >>> require 'spec/rails' >>> >>> >> This is exactly what the top of my spec_helper.rb file looks like. >> >> I have several specs, and the success of running them is different depending >> on what I do. I'm really just trying to figure out how to take advantage of >> the "rake spec" task. >> I'm on Windows XP. Rails 2.1.0. Rspec and Rspec-Rails 1.1.8 gems. No >> Rspec plugins. Freshly generate rspec stuff using "ruby script/generate >> rspec" >> >> 1) If I run each of my specs separately on the command line using "spec >> spec/whatever.rb" they run fine. >> >> 2) If I run "spec spec/*spec.rb", then all _but one_ run without error (note >> that the one that files can be run successfully using a direct call to it as >> in #1 above). >> >> 3) If I run "rake spec", I get multiple failures, all because the >> config/environments/test.rb file is not loaded (I know this because they >> fail due to the lack of a variable that is set only in test.rb). The spec >> that failed in #2 works in this case. >> >> 4) If I run "rake spec RAILS_ENV=test", all _but one_ run without error >> (same error as in #2). >> >> I draw the following conclustions: >> >> 1) I only get the color output if I use "rake spec" (not sure why) >> >> 2) spec loads test.rb by default, but "rake spec" does not and that's why I >> have to pass RAILS_ENV=test to the "rake" command. >> > > What is test.rb? > config/environments/test.rb - has test specific stuff set in it. > As for getting different results if you run files individually, with > the spec command or with the rake command, that is *usually* a sign > that there is some state leaking between examples. 'rake spec' and > 'spec spec' don't load the files in the same order, so the fact that > you also get different failures from each of those also supports this > theory in your case. > I agree with this although it is still unclear to me what the state problems are. Thanks, Wes From dchelimsky at gmail.com Wed Oct 8 19:46:12 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Oct 2008 18:46:12 -0500 Subject: [rspec-users] When is spec_helper.rb actually executed? In-Reply-To: References: <4ef1a8c488b15e8af68ca539bff50ca2@ruby-forum.com> <59F5748C-642F-4C86-8A72-3B8D6B8795F1@railsnewbie.com> <48ED3909.1070101@att.net> <57c63afe0810081631g7e6a50behf30f395d30d458c2@mail.gmail.com> Message-ID: <57c63afe0810081646n19c19524meb247d174ac62c66@mail.gmail.com> On Wed, Oct 8, 2008 at 6:40 PM, Wes Gamble wrote: > OK, got it. > > I have a follow-up question though. If a given spec DID NOT require > spec_helper.rb, doesn't that imply that the spec would be run against > the Rails "development" environment. Not necessarily. Depends on what was loaded before that file. So if first_spec.rb requires spec_helper.rb and second_spec.rb does not, if they run in order (first, second) then since the first loads spec_helper.rb the second will run in the "test" environment. In that same scenario, if you run second_spec.rb by itself, it will run in development. > I just did a test where I printed out the configuration of one of my > classes DB connnections (e.g. Blah.connection.inspect where Blah is an > AR model). And I saw that the "database" setting in this was > development. My spec definitely inserts data into the DB. > > I kind of expected to see additional rows in the table in question. > > But I just realized that each spec is probably surrounded by a > transaction - is that correct? As long as you see this in spec_helper.rb (and it is loaded ;) ) config.use_transactional_fixtures = true That variable has NOTHING to do with fixtures, but it is rails hook into running each test (using test/unit) or spec (using rspec) in a transaction. > > Wes From dchelimsky at gmail.com Wed Oct 8 19:48:19 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Oct 2008 18:48:19 -0500 Subject: [rspec-users] Basic Rspec operation questions In-Reply-To: <48ED4561.4060608@att.net> References: <48ED06C2.9000200@att.net> <85d99afe0810081251p39bda626y969c40f0b803812@mail.gmail.com> <48ED1B01.9060600@att.net> <57c63afe0810081627kb12460aoe5bf86b630983912@mail.gmail.com> <48ED4561.4060608@att.net> Message-ID: <57c63afe0810081648if97a670g16e238df24b0875f@mail.gmail.com> On Wed, Oct 8, 2008 at 6:42 PM, Wes Gamble wrote: > David Chelimsky wrote: >> >> On Wed, Oct 8, 2008 at 3:41 PM, Wes Gamble wrote: >> >>> >>> Zach, >>> >>> Zach Dennis wrote: >>> >>>> >>>> # This file is copied to ~/spec when you run 'ruby script/generate >>>> rspec' >>>> # from the project root directory. >>>> ENV["RAILS_ENV"] = "test" >>>> require File.expand_path(File.dirname(__FILE__) + >>>> "/../config/environment") >>>> require 'spec' >>>> require 'spec/rails' >>>> >>>> >>> >>> This is exactly what the top of my spec_helper.rb file looks like. >>> >>> I have several specs, and the success of running them is different >>> depending >>> on what I do. I'm really just trying to figure out how to take advantage >>> of >>> the "rake spec" task. >>> I'm on Windows XP. Rails 2.1.0. Rspec and Rspec-Rails 1.1.8 gems. No >>> Rspec plugins. Freshly generate rspec stuff using "ruby script/generate >>> rspec" >>> >>> 1) If I run each of my specs separately on the command line using "spec >>> spec/whatever.rb" they run fine. >>> >>> 2) If I run "spec spec/*spec.rb", then all _but one_ run without error >>> (note >>> that the one that files can be run successfully using a direct call to it >>> as >>> in #1 above). >>> >>> 3) If I run "rake spec", I get multiple failures, all because the >>> config/environments/test.rb file is not loaded (I know this because they >>> fail due to the lack of a variable that is set only in test.rb). The >>> spec >>> that failed in #2 works in this case. >>> >>> 4) If I run "rake spec RAILS_ENV=test", all _but one_ run without error >>> (same error as in #2). >>> >>> I draw the following conclustions: >>> >>> 1) I only get the color output if I use "rake spec" (not sure why) >>> >>> 2) spec loads test.rb by default, but "rake spec" does not and that's why >>> I >>> have to pass RAILS_ENV=test to the "rake" command. >>> >> >> What is test.rb? >> > > config/environments/test.rb - has test specific stuff set in it. >> >> As for getting different results if you run files individually, with >> the spec command or with the rake command, that is *usually* a sign >> that there is some state leaking between examples. 'rake spec' and >> 'spec spec' don't load the files in the same order, so the fact that >> you also get different failures from each of those also supports this >> theory in your case. >> > > I agree with this although it is still unclear to me what the state problems > are. Based on the other thread you started about the environment - it might be the lack of environments/test.rb being loaded (rather than a state problem). Make sure every _spec.rb file requires spec_helper.rb and see if that solves the problem. Cheers, David > > Thanks, > Wes > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Wed Oct 8 19:50:24 2008 From: lists at ruby-forum.com (Wes Gamble) Date: Thu, 9 Oct 2008 01:50:24 +0200 Subject: [rspec-users] What makes specs run against the test database? Message-ID: I just did a test where I ran one spec and deep deep within the code under test, I printed out the DB connection of the AR class of a given object, like so: puts invoice.class.connection.inspect My spec requires spec_helper.rb, which supposedly sets the Rails environment to be "test". However, the output of that inspect looks like this: .#>, @run time=0.0, @quoted_table_names={"draft_invoices"=>"`draft_invoices`"}, @connectio n=#, @quoted_column_names={"draft_invoices"=>"`draft_invoices`"}, @query_ cache_enabled=false, @config={:password=>"blah", :username=>"root", :adapt er=>"mysql", :database=>"my_db_development", :encoding=>"utf8", :host=>"mach ost", :allow_concurrency=>false}, @connection_options=["machost", "root", "r3n&s t1mpy", "aafes_vss_development", nil, nil]> Notice @config={:password=>"blah", :username=>"root", :adapt er=>"mysql", :database=>"my_db_development", :encoding=>"utf8", :host=>"mach ost", :allow_concurrency=>false} which shows that I am hitting my development database. Why would I see this output when running a spec that AFAIK, should be running against the test DB? Thanks, wes -- Posted via http://www.ruby-forum.com/. From nick at deadorange.com Wed Oct 8 19:54:23 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 8 Oct 2008 19:54:23 -0400 Subject: [rspec-users] What makes specs run against the test database? In-Reply-To: References: Message-ID: <561948B9-3954-4EC4-915F-66F66F8950CE@deadorange.com> On 2008-10-08, at 19:50, Wes Gamble wrote: > I just did a test where I ran one spec and deep deep within the code > under test, I printed out the DB connection of the AR class of a given > object, like so: > > <..snip..> > > which shows that I am hitting my development database. Why would I > see > this output when running a spec that AFAIK, should be running against > the test DB? > > Thanks, > wes This sounds like a dumb question, but in database.yml , have you confirmed that your test DB is configured for use in the test environment? Cheers, Nick From dchelimsky at gmail.com Wed Oct 8 20:00:57 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Oct 2008 19:00:57 -0500 Subject: [rspec-users] Testing Views with Authentication In-Reply-To: References: Message-ID: <57c63afe0810081700n77bddff6x56ccde5bb214afb@mail.gmail.com> On Wed, Oct 8, 2008 at 6:31 PM, Donald French wrote: > I am trying to figure out how to properly test a view when part of the view > is is protected with a role check <% if current_user.admin? %>.. How do I > force a log in or mock the current user. I need to do it in a DRY way as > this is used throughout the system checking various privileges. View examples are decoupled from controllers, so logging in won't do anything. What you want to do is stub the current user, like this: template.stub!(:current_user).and_return(mock_model(User, :admin? => true) In terms of keeping things DRY, there are a couple of things you can do. First, you can simplify things by adding a helper in application_helper.rb: def admin? current_user.admin? end Now there's less to stub in the view examples. This could also be a block helper: def admin_only yield if block_given? && current_user.admin? end That lets you write this in your views: <% admin_only do %> ... super privileged stuff ... <% end %> And this in the code examples that you want to yield: template.stub!(:admin_only).and_yield And this in the code examples that you don't want to yield: template.stub!(:admin_only) Now if ALL of your examples should render the admin-only stuff, you could do this: Spec::Runner.configure do |config| config.before(:each, :type => :view) do template.stub!(:admin_only).and_yield end end However, this means that all the view examples will be doing this IMPLICITLY and is likely to cause some confusion down the road (why the hell is this admin-only stuff getting rendered?), so that risk needs to be taken into account. HTH, David > Don French From weyus at att.net Wed Oct 8 20:09:13 2008 From: weyus at att.net (Wes Gamble) Date: Wed, 08 Oct 2008 19:09:13 -0500 Subject: [rspec-users] Basic Rspec operation questions In-Reply-To: <57c63afe0810081627kb12460aoe5bf86b630983912@mail.gmail.com> References: <48ED06C2.9000200@att.net> <85d99afe0810081251p39bda626y969c40f0b803812@mail.gmail.com> <48ED1B01.9060600@att.net> <57c63afe0810081627kb12460aoe5bf86b630983912@mail.gmail.com> Message-ID: <48ED4BA9.1090407@att.net> David Chelimsky wrote: > On Wed, Oct 8, 2008 at 3:41 PM, Wes Gamble wrote: > >> Zach, >> >> Zach Dennis wrote: >> >>> # This file is copied to ~/spec when you run 'ruby script/generate rspec' >>> # from the project root directory. >>> ENV["RAILS_ENV"] = "test" >>> require File.expand_path(File.dirname(__FILE__) + >>> "/../config/environment") >>> require 'spec' >>> require 'spec/rails' >>> >>> 1) If I run each of my specs separately on the command line using "spec >>> spec/whatever.rb" they run fine. >>> >>> 2) If I run "spec spec/*spec.rb", then all _but one_ run without error (note >>> that the one that files can be run successfully using a direct call to it as >>> in #1 above). >>> >>> > As for getting different results if you run files individually, with > the spec command or with the rake command, that is *usually* a sign > that there is some state leaking between examples. 'rake spec' and > 'spec spec' don't load the files in the same order, so the fact that > you also get different failures from each of those also supports this > theory in your case. > > I agree with your statement, but I can reproduce a case where I can run all of my specs using the "spec" command using "spec spec/**/*_spec.rb" and one of them will fail. I can either leave in or remove the "--reverse" option in my spec.opts file and get that failure. But...when I run the spec standalone, using "spec spec/.rb" it works fine. So this is a difference in behavior within the spec command and the only difference is that it's one test (SUCCESS) vs. 22 tests (FAIL). To the best of my knowledge, the other tests don't even touch the stuff that is under test in the spec that fails, so I can't figure out where the state would be leaking. (Argh - of course if I reverse the order of the 22 tests, while in both cases the individual spec that I'm talking about always fails, if I reverse the order, one set is a lot more successful than the other. Sigh.) Wes Wes From weyus at att.net Wed Oct 8 20:10:41 2008 From: weyus at att.net (Wes Gamble) Date: Wed, 08 Oct 2008 19:10:41 -0500 Subject: [rspec-users] What makes specs run against the test database? In-Reply-To: <561948B9-3954-4EC4-915F-66F66F8950CE@deadorange.com> References: <561948B9-3954-4EC4-915F-66F66F8950CE@deadorange.com> Message-ID: <48ED4C01.1090805@att.net> Yes. Nick Hoffman wrote: > On 2008-10-08, at 19:50, Wes Gamble wrote: >> I just did a test where I ran one spec and deep deep within the code >> under test, I printed out the DB connection of the AR class of a given >> object, like so: >> >> <..snip..> >> >> which shows that I am hitting my development database. Why would I see >> this output when running a spec that AFAIK, should be running against >> the test DB? >> >> Thanks, >> wes > > > This sounds like a dumb question, but in database.yml , have you > confirmed that your test DB is configured for use in the test > environment? > > Cheers, > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Oct 8 20:18:18 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 8 Oct 2008 19:18:18 -0500 Subject: [rspec-users] ArgumentError in "is a pending example" - block not supplied In-Reply-To: <57B0E1C5-6CB8-45F1-80F8-9D558037BB60@mattwynne.net> References: <57B0E1C5-6CB8-45F1-80F8-9D558037BB60@mattwynne.net> Message-ID: <57c63afe0810081718g7aa71823jc9db59034896ccdf@mail.gmail.com> On Wed, Oct 8, 2008 at 1:15 PM, Matt Wynne wrote: > We have a few unfinished examples in our code of the form > > it "should and does do something" do > # stuff > end > > it "should do something someday" > > it "should and does do something else" do > # more stuff > end > > Now since I upgraded my gem to rspec 1.8 today, the empty example is failing > with the error ArgumentError in "should do something someday": block not > supplied > > Is this by design? Absolutely not, though I am not having the same experience (blockless examples are correctly reported as pending). > What's the recommended way to deal with these pending examples? write a > block and call pending within it? That's how we used to do it before rspec started treating blockless examples as pending. It will band-aid your problem so you can progress. But what you're experiencing is not what is expected, nor am I able to reproduce it. Is this a rails app? Are you mixing gems and plugins perchance? > > cheers, > Matt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Wed Oct 8 20:22:08 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 08 Oct 2008 17:22:08 -0700 Subject: [rspec-users] Testing Views with Authentication In-Reply-To: (Donald French's message of "Wed\, 8 Oct 2008 13\:31\:26 -1000") References: Message-ID: Donald French writes: > I am trying to figure out how to properly test a view when part of the > view is is protected with a role check <% if current_user.admin? %>.. > How do I force a log in or mock the current user. I need to do it in a > DRY way as this is used throughout the system checking various > privileges. > > Don French > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users You can stub the template object: template.stub!(:current_user).and_return mock_admin Pat From weyus at att.net Wed Oct 8 20:45:55 2008 From: weyus at att.net (Wes Gamble) Date: Wed, 08 Oct 2008 19:45:55 -0500 Subject: [rspec-users] Basic Rspec operation questions In-Reply-To: <57c63afe0810081648if97a670g16e238df24b0875f@mail.gmail.com> References: <48ED06C2.9000200@att.net> <85d99afe0810081251p39bda626y969c40f0b803812@mail.gmail.com> <48ED1B01.9060600@att.net> <57c63afe0810081627kb12460aoe5bf86b630983912@mail.gmail.com> <48ED4561.4060608@att.net> <57c63afe0810081648if97a670g16e238df24b0875f@mail.gmail.com> Message-ID: <48ED5443.3040602@att.net> David Chelimsky wrote: > On Wed, Oct 8, 2008 at 6:42 PM, Wes Gamble wrote: > >> David Chelimsky wrote: >> >>> On Wed, Oct 8, 2008 at 3:41 PM, Wes Gamble wrote: >>> >>> >>>> Zach, >>>> >>>> Zach Dennis wrote: >>>> >>>> >>>>> # This file is copied to ~/spec when you run 'ruby script/generate >>>>> rspec' >>>>> # from the project root directory. >>>>> ENV["RAILS_ENV"] = "test" >>>>> require File.expand_path(File.dirname(__FILE__) + >>>>> "/../config/environment") >>>>> require 'spec' >>>>> require 'spec/rails' >>>>> >>>>> >>>>> >>>> This is exactly what the top of my spec_helper.rb file looks like. >>>> >>>> I have several specs, and the success of running them is different >>>> depending >>>> on what I do. I'm really just trying to figure out how to take advantage >>>> of >>>> the "rake spec" task. >>>> I'm on Windows XP. Rails 2.1.0. Rspec and Rspec-Rails 1.1.8 gems. No >>>> Rspec plugins. Freshly generate rspec stuff using "ruby script/generate >>>> rspec" >>>> >>>> 1) If I run each of my specs separately on the command line using "spec >>>> spec/whatever.rb" they run fine. >>>> >>>> 2) If I run "spec spec/*spec.rb", then all _but one_ run without error >>>> (note >>>> that the one that files can be run successfully using a direct call to it >>>> as >>>> in #1 above). >>>> >>>> 3) If I run "rake spec", I get multiple failures, all because the >>>> config/environments/test.rb file is not loaded (I know this because they >>>> fail due to the lack of a variable that is set only in test.rb). The >>>> spec >>>> that failed in #2 works in this case. >>>> >>>> 4) If I run "rake spec RAILS_ENV=test", all _but one_ run without error >>>> (same error as in #2). >>>> >>>> I draw the following conclustions: >>>> >>>> 1) I only get the color output if I use "rake spec" (not sure why) >>>> >>>> 2) spec loads test.rb by default, but "rake spec" does not and that's why >>>> I >>>> have to pass RAILS_ENV=test to the "rake" command. >>>> >>>> >>> What is test.rb? >>> >>> >> config/environments/test.rb - has test specific stuff set in it. >> >>> As for getting different results if you run files individually, with >>> the spec command or with the rake command, that is *usually* a sign >>> that there is some state leaking between examples. 'rake spec' and >>> 'spec spec' don't load the files in the same order, so the fact that >>> you also get different failures from each of those also supports this >>> theory in your case. >>> >>> >> I agree with this although it is still unclear to me what the state problems >> are. >> Make sure every _spec.rb file requires spec_helper.rb and see if that >> solves the problem. >> >> Interesting. So I made sure that the first line in every spec file was "require File.join(File.dirname(__FILE__), 'spec_helper.rb')" [ and I assume that this should be a Cardinal Rule to live by ] and now my 22 tests behave the same way with or without the spec.opts file in play (either in alphabetical order or by mtime and reversed, etc.). 21 tests will pass and the 1 test will fail. Here's the offending spec. describe "User account fixtures" do it "should exist" do existing=User.all.map(&:login) ["admin", "bor_admin", "dell_admin", "ibm_admin", "ibm_user1", "proc", "van_admin"].each do |login| existing.include?(login).should==true end end end This is pretty straight forward - it's just testing the presence of a fixture. Now, this fixture is under the test/fixtures directory. Note that I have NOT changed the fixture path in spec_helper.rb from spec/fixtures to text/fixtures, and I have not asked for a fixture to be loaded in any test. However, why would all of my other tests work if no fixtures were ever being loaded? I'm still looking into this. Will report results. Wes From mailing_lists at railsnewbie.com Wed Oct 8 21:52:14 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 8 Oct 2008 21:52:14 -0400 Subject: [rspec-users] When is spec_helper.rb actually executed? In-Reply-To: References: <4ef1a8c488b15e8af68ca539bff50ca2@ruby-forum.com> <59F5748C-642F-4C86-8A72-3B8D6B8795F1@railsnewbie.com> <48ED3909.1070101@att.net> <57c63afe0810081631g7e6a50behf30f395d30d458c2@mail.gmail.com> Message-ID: <993683E0-0D4C-4503-A5D5-112D94FA6EB9@railsnewbie.com> On Oct 8, 2008, at 7:40 PM, Wes Gamble wrote: > OK, got it. > > I have a follow-up question though. If a given spec DID NOT require > spec_helper.rb, doesn't that imply that the spec would be run against > the Rails "development" environment. Basically, the normal operation is that your spec requires spec_helper, which eventually requires the test_helper which comes with rails, which sets the constant: RAILS_ENV = "test" > > > I just did a test where I printed out the configuration of one of my > classes DB connnections (e.g. Blah.connection.inspect where Blah is an > AR model). And I saw that the "database" setting in this was > development. My spec definitely inserts data into the DB. > > I kind of expected to see additional rows in the table in question. > > But I just realized that each spec is probably surrounded by a > transaction - is that correct? Yes. Assuming you have transaction_fixtures = true. This is how rails resets the database between each test (at least after rails 1.2). Scott From mark.thomson at ieee.org Wed Oct 8 21:55:51 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Wed, 08 Oct 2008 20:55:51 -0500 Subject: [rspec-users] fills_in NoMethodError Message-ID: <48ED64A7.3040407@ieee.org> I have an RSpec story with an overall structure that looks something like this - ---- Given the user is on the start page When the user clicks the 'new' button Then the 'new record' page should be displayed When the user fills in the form And the user submits the form Then the updated form should be displayed When the user fills in the updated form And the user submits the form Then a conformation message should be displayed ---- In the last When step, I have a fills_in call that is failing with the following: ---- NoMethodError: 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.attributes. ---- I think the ActiveRecord thing is a red herring. Poking through the Webrat source code, it seems like the problem is more likely a failure to find any input fields. But I'm not sure why. Is there anything inappropriate with the way I've organized the story, stringing together multiple When-Then segments? One thing that seems curious is that I have a completely identical fills_in call in the When step that precedes the one that is failing and yet that one runs without any problem. Does this ring any bells with anyone? Mark. -------------- next part -------------- An HTML attachment was scrubbed... URL: From weyus at att.net Thu Oct 9 01:43:01 2008 From: weyus at att.net (Wes Gamble) Date: Thu, 09 Oct 2008 00:43:01 -0500 Subject: [rspec-users] Basic Rspec operation questions In-Reply-To: <48ED5443.3040602@att.net> References: <48ED06C2.9000200@att.net> <85d99afe0810081251p39bda626y969c40f0b803812@mail.gmail.com> <48ED1B01.9060600@att.net> <57c63afe0810081627kb12460aoe5bf86b630983912@mail.gmail.com> <48ED4561.4060608@att.net> <57c63afe0810081648if97a670g16e238df24b0875f@mail.gmail.com> <48ED5443.3040602@att.net> Message-ID: <48ED99E5.1030606@att.net> Wes Gamble wrote: > David Chelimsky wrote: >> On Wed, Oct 8, 2008 at 6:42 PM, Wes Gamble wrote: >> >>> David Chelimsky wrote: >>> >>>> On Wed, Oct 8, 2008 at 3:41 PM, Wes Gamble wrote: >>>> >>>> >>>>> Zach, >>>>> >>>>> Zach Dennis wrote: >>>>> >>>>> >>>>>> # This file is copied to ~/spec when you run 'ruby script/generate >>>>>> rspec' >>>>>> # from the project root directory. >>>>>> ENV["RAILS_ENV"] = "test" >>>>>> require File.expand_path(File.dirname(__FILE__) + >>>>>> "/../config/environment") >>>>>> require 'spec' >>>>>> require 'spec/rails' >>>>>> >>>>>> >>>>>> >>>>> This is exactly what the top of my spec_helper.rb file looks like. >>>>> >>>>> I have several specs, and the success of running them is different >>>>> depending >>>>> on what I do. I'm really just trying to figure out how to take >>>>> advantage >>>>> of >>>>> the "rake spec" task. >>>>> I'm on Windows XP. Rails 2.1.0. Rspec and Rspec-Rails 1.1.8 >>>>> gems. No >>>>> Rspec plugins. Freshly generate rspec stuff using "ruby >>>>> script/generate >>>>> rspec" >>>>> >>>>> 1) If I run each of my specs separately on the command line using >>>>> "spec >>>>> spec/whatever.rb" they run fine. >>>>> >>>>> 2) If I run "spec spec/*spec.rb", then all _but one_ run without >>>>> error >>>>> (note >>>>> that the one that files can be run successfully using a direct >>>>> call to it >>>>> as >>>>> in #1 above). >>>>> >>>>> 3) If I run "rake spec", I get multiple failures, all because the >>>>> config/environments/test.rb file is not loaded (I know this >>>>> because they >>>>> fail due to the lack of a variable that is set only in test.rb). The >>>>> spec >>>>> that failed in #2 works in this case. >>>>> >>>>> 4) If I run "rake spec RAILS_ENV=test", all _but one_ run without >>>>> error >>>>> (same error as in #2). >>>>> >>>>> I draw the following conclustions: >>>>> >>>>> 1) I only get the color output if I use "rake spec" (not sure why) >>>>> >>>>> 2) spec loads test.rb by default, but "rake spec" does not and >>>>> that's why >>>>> I >>>>> have to pass RAILS_ENV=test to the "rake" command. >>>>> >>>>> >>>> What is test.rb? >>>> >>>> >>> config/environments/test.rb - has test specific stuff set in it. >>> >>>> As for getting different results if you run files individually, with >>>> the spec command or with the rake command, that is *usually* a sign >>>> that there is some state leaking between examples. 'rake spec' and >>>> 'spec spec' don't load the files in the same order, so the fact that >>>> you also get different failures from each of those also supports this >>>> theory in your case. >>>> >>>> >>> I agree with this although it is still unclear to me what the state >>> problems >>> are. >>> Make sure every _spec.rb file requires spec_helper.rb and see if that >>> solves the problem. >>> >>> > Interesting. So I made sure that the first line in every spec file was > > "require File.join(File.dirname(__FILE__), 'spec_helper.rb')" [ and I > assume that this should be a Cardinal Rule to live by ] > > and now my 22 tests behave the same way with or without the spec.opts > file in play (either in alphabetical order or by mtime and reversed, > etc.). 21 tests will pass and the 1 test will fail. > Here's the offending spec. > > describe "User account fixtures" do > it "should exist" do > existing=User.all.map(&:login) > > ["admin", "bor_admin", "dell_admin", "ibm_admin", "ibm_user1", > "proc", "van_admin"].each do |login| > existing.include?(login).should==true > end > end > end > > This is pretty straight forward - it's just testing the presence of a > fixture. Now, this fixture is under the test/fixtures directory. > Note that I have NOT changed the fixture path in spec_helper.rb from > spec/fixtures to text/fixtures, and I have not asked for a fixture to > be loaded in any test. However, why would all of my other tests work > if no fixtures were ever being loaded? ANSWER: The other specs are actually using Watir (the IE GUI test framework), and these tests are implicit hitting a server running in development. So, there's no need to load the data that those test use into the test database using fixtures (we probably need to fix this, etc.). So, my oddball test that was breaking was in fact, the only test hitting the test database that needed any fixture data loaded, and as we see above, it wasn't getting it. Adding "fixtures :users" in the describe block worked like you would expect. Thanks for all the help, everyone. Wes From matt at mattwynne.net Thu Oct 9 02:57:37 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 9 Oct 2008 07:57:37 +0100 Subject: [rspec-users] fills_in NoMethodError In-Reply-To: <48ED64A7.3040407@ieee.org> References: <48ED64A7.3040407@ieee.org> Message-ID: <2552F40F-85BE-48D6-A71D-54368B39E29C@mattwynne.net> On 9 Oct 2008, at 02:55, Mark Thomson wrote: > I have an RSpec story with an overall structure that looks something > like this - > > ---- > Given the user is on the start page > When the user clicks the 'new' button > Then the 'new record' page should be displayed > > When the user fills in the form > And the user submits the form > Then the updated form should be displayed > > When the user fills in the updated form > And the user submits the form > Then a conformation message should be displayed > ---- > > In the last When step, I have a fills_in call that is failing with > the following: > > ---- > NoMethodError: 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.attributes. > ---- > > I think the ActiveRecord thing is a red herring. Poking through the > Webrat source code, it seems like the problem is more likely a > failure to find any input fields. But I'm not sure why. Is there > anything inappropriate with the way I've organized the story, > stringing together multiple When-Then segments? One thing that seems > curious is that I have a completely identical fills_in call in the > When step that precedes the one that is failing and yet that one > runs without any problem. I think this sort of error tends to happen while a view is being rendered, so my guess is it's something to do with your data setup. Sorry to bang on about this, but cucumber has much better support for error messages - you might want to consider making the switch before you waste too much time on this issue. From matt at mattwynne.net Thu Oct 9 03:04:06 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 9 Oct 2008 08:04:06 +0100 Subject: [rspec-users] ArgumentError in "is a pending example" - block not supplied In-Reply-To: <57c63afe0810081718g7aa71823jc9db59034896ccdf@mail.gmail.com> References: <57B0E1C5-6CB8-45F1-80F8-9D558037BB60@mattwynne.net> <57c63afe0810081718g7aa71823jc9db59034896ccdf@mail.gmail.com> Message-ID: <5678A8CB-E43D-4AF2-B777-59F326E0CEA4@mattwynne.net> On 9 Oct 2008, at 01:18, David Chelimsky wrote: >> Now since I upgraded my gem to rspec 1.8 today, the empty example >> is failing >> with the error ArgumentError in "should do something someday": >> block not >> supplied >> >> Is this by design? > > Absolutely not, though I am not having the same experience (blockless > examples are correctly reported as pending). > >> What's the recommended way to deal with these pending examples? >> write a >> block and call pending within it? > > That's how we used to do it before rspec started treating blockless > examples as pending. It will band-aid your problem so you can > progress. But what you're experiencing is not what is expected, nor am > I able to reproduce it. > > Is this a rails app? Are you mixing gems and plugins perchance? Yes and yes. Aha. I hadn't bothered to upgrade the plugin as I figured that using 'spec' from the command line would run the 1.1.8 version from my gems folder, and not touch the plugin at all. Let me upgrade the plugin too and see what happens. thanks, Matt From mailing_lists at railsnewbie.com Thu Oct 9 03:21:27 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 9 Oct 2008 03:21:27 -0400 Subject: [rspec-users] Rspec @ UC Berkley Message-ID: <6BFED86B-EDB0-4894-BE26-25B4323FCAC8@railsnewbie.com> I find it sort of interesting that they are using RSpec in one of the courses @ UC Berkley: http://radlab.cs.berkeley.edu/wiki/Cs198 Scott From lists at ruby-forum.com Thu Oct 9 05:40:18 2008 From: lists at ruby-forum.com (Guofeng Ma) Date: Thu, 9 Oct 2008 11:40:18 +0200 Subject: [rspec-users] About received unexpected message :code with (no args) Message-ID: I use rspec_scaffold to generate a part of examples as below: it "should expose a newly created awarding_body as @awarding_body" do AwardingBody.should_receive(:new).with({'these' => 'params'}).and_return(mock_awarding_body(:save => true)) post :create, :awarding_body => {:these => 'params'} assigns(:awarding_body).should equal(mock_awarding_body) end After i execute the example, below error occurs: Mock 'AwardingBody_1193' received unexpected message :code with (no args) how to deal with it? -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Thu Oct 9 06:10:17 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Oct 2008 05:10:17 -0500 Subject: [rspec-users] ArgumentError in "is a pending example" - block not supplied In-Reply-To: <5678A8CB-E43D-4AF2-B777-59F326E0CEA4@mattwynne.net> References: <57B0E1C5-6CB8-45F1-80F8-9D558037BB60@mattwynne.net> <57c63afe0810081718g7aa71823jc9db59034896ccdf@mail.gmail.com> <5678A8CB-E43D-4AF2-B777-59F326E0CEA4@mattwynne.net> Message-ID: <57c63afe0810090310i51501ea5k99903a69a313424f@mail.gmail.com> On Thu, Oct 9, 2008 at 2:04 AM, Matt Wynne wrote: > On 9 Oct 2008, at 01:18, David Chelimsky wrote: >>> >>> Now since I upgraded my gem to rspec 1.8 today, the empty example is >>> failing >>> with the error ArgumentError in "should do something someday": block not >>> supplied >>> >>> Is this by design? >> >> Absolutely not, though I am not having the same experience (blockless >> examples are correctly reported as pending). >> >>> What's the recommended way to deal with these pending examples? write a >>> block and call pending within it? >> >> That's how we used to do it before rspec started treating blockless >> examples as pending. It will band-aid your problem so you can >> progress. But what you're experiencing is not what is expected, nor am >> I able to reproduce it. >> >> Is this a rails app? Are you mixing gems and plugins perchance? > > Yes and yes. > > Aha. > > I hadn't bothered to upgrade the plugin as I figured that using 'spec' from > the command line would run the 1.1.8 version from my gems folder, and not > touch the plugin at all. > > Let me upgrade the plugin too and see what happens. Actually, I'd recommend the other way around: get rid of the plugins and use the 1.1.8 gems for rspec and rspec-rails. Cheers, David > > thanks, > Matt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Oct 9 06:13:47 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Oct 2008 05:13:47 -0500 Subject: [rspec-users] Rspec @ UC Berkley In-Reply-To: <6BFED86B-EDB0-4894-BE26-25B4323FCAC8@railsnewbie.com> References: <6BFED86B-EDB0-4894-BE26-25B4323FCAC8@railsnewbie.com> Message-ID: <57c63afe0810090313m4bfabc3el27c3b3b1bb5a0a01@mail.gmail.com> On Thu, Oct 9, 2008 at 2:21 AM, Scott Taylor wrote: > > I find it sort of interesting that they are using RSpec in one of the > courses @ UC Berkley: > > http://radlab.cs.berkeley.edu/wiki/Cs198 Ah - but look at the install instructions. They're using svn at rubyforge :( That's pretty old at this point. Bummer. > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Oct 9 06:24:33 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Oct 2008 05:24:33 -0500 Subject: [rspec-users] About received unexpected message :code with (no args) In-Reply-To: References: Message-ID: <57c63afe0810090324y1d646be1p9275ae251535510e@mail.gmail.com> On Thu, Oct 9, 2008 at 4:40 AM, Guofeng Ma wrote: > > I use rspec_scaffold to generate a part of examples as below: > > it "should expose a newly created awarding_body as @awarding_body" do > AwardingBody.should_receive(:new).with({'these' => > 'params'}).and_return(mock_awarding_body(:save => true)) > post :create, :awarding_body => {:these => 'params'} > assigns(:awarding_body).should equal(mock_awarding_body) > end > > > After i execute the example, below error occurs: > > Mock 'AwardingBody_1193' received unexpected message :code with (no > args) > > > how to deal with it? That is very odd. Did you have an AwardingBody model, view, or controller before you ran 'script/generate rspec_scaffold AwardingBody'? Did you make any changes to the code after running it? Or did you just do this: script/generate rspec_scaffold AwardingBody rake db:migrate rake spec From dchelimsky at gmail.com Thu Oct 9 06:34:03 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Oct 2008 05:34:03 -0500 Subject: [rspec-users] fills_in NoMethodError In-Reply-To: <2552F40F-85BE-48D6-A71D-54368B39E29C@mattwynne.net> References: <48ED64A7.3040407@ieee.org> <2552F40F-85BE-48D6-A71D-54368B39E29C@mattwynne.net> Message-ID: <57c63afe0810090334p3cb8e6b8xa16dae36a9f82e37@mail.gmail.com> On Thu, Oct 9, 2008 at 1:57 AM, Matt Wynne wrote: > On 9 Oct 2008, at 02:55, Mark Thomson wrote: > >> I have an RSpec story with an overall structure that looks something like >> this - >> >> ---- >> Given the user is on the start page >> When the user clicks the 'new' button >> Then the 'new record' page should be displayed >> >> When the user fills in the form >> And the user submits the form >> Then the updated form should be displayed >> >> When the user fills in the updated form >> And the user submits the form >> Then a conformation message should be displayed >> ---- >> >> In the last When step, I have a fills_in call that is failing with the >> following: >> >> ---- >> NoMethodError: 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.attributes. >> ---- >> >> I think the ActiveRecord thing is a red herring. Poking through the Webrat >> source code, it seems like the problem is more likely a failure to find any >> input fields. But I'm not sure why. Is there anything inappropriate with the >> way I've organized the story, stringing together multiple When-Then >> segments? One thing that seems curious is that I have a completely identical >> fills_in call in the When step that precedes the one that is failing and yet >> that one runs without any problem. > > I think this sort of error tends to happen while a view is being rendered, > so my guess is it's something to do with your data setup. > > Sorry to bang on about this, but cucumber has much better support for error > messages - you might want to consider making the switch before you waste too > much time on this issue. Matt is correct, you should definitely consider moving to cucumber, though I don't know that cucumber will necessary help you shed any more light on this particular issue. Mark, with the little bit of information you've provided, my best guess would be that the :new action is providing some instance variable that is not being provided by the :create action in the case where the data from "When the user fills in the form" is incorrect or insufficient to save the model. If that's not correct, please post the code for the steps and the relevant controller actions. Cheers, David From thomasmarek_ at web.de Thu Oct 9 09:22:17 2008 From: thomasmarek_ at web.de (Thomas Marek) Date: Thu, 09 Oct 2008 15:22:17 +0200 Subject: [rspec-users] Cucumber: Migrating RSpec Story Listeners to Cucumber In-Reply-To: <4086be02-537e-4e93-b6ac-aba4903c3ddd@71g2000hse.googlegroups.com> References: <4086be02-537e-4e93-b6ac-aba4903c3ddd@71g2000hse.googlegroups.com> Message-ID: <48EE0589.1000900@web.de> Hello, i written a rails plugin for driving Selenium from the RSpec Story Runner: http://github.com/tmak/rspec-rails-selenium-story Now, i want to migrate my plugin to cucumber. My question: I used the scenario_failed method of the Story Listener to make screenshots of failing story scenarios. How can i do that with cucumber? Thanks, Thomas From lists at ruby-forum.com Thu Oct 9 10:30:42 2008 From: lists at ruby-forum.com (Daniel Higginbotham) Date: Thu, 9 Oct 2008 16:30:42 +0200 Subject: [rspec-users] cucumber and fixtures In-Reply-To: References: <8d961d900810080728s4ba72cdawc4af9360396e811c@mail.gmail.com> <85d99afe0810081255w3c541264j6405b6707f959425@mail.gmail.com> <55a81029f1194807d52edbbed64a2033@ruby-forum.com> Message-ID: Pat Maddox wrote: > Daniel Higginbotham writes: > >>> ActiveRecord::Schema.verbose = false >>> { :name => "blah", :id => 1 }, >> >> end >> end >> >> Are you similarly able to load your YAML fixtures from spec/fixtures >> when you're running a Cucumber feature? >> >> Thanks, >> Daniel Higginbotham > > I don't know that it's built into Cucumber, but loading fixtures is > pretty simple from what I remember. Something like > AR::Fixtures.load('path/to/file.yml') or something. Look around and I'm > sure you can find the couple lines to make it work. > > Pat Thanks Pat! It looks like Fixtures.create_fixtures("spec/fixtures", "users") works. -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Thu Oct 9 12:09:48 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 09 Oct 2008 09:09:48 -0700 Subject: [rspec-users] Rspec @ UC Berkley In-Reply-To: <6BFED86B-EDB0-4894-BE26-25B4323FCAC8@railsnewbie.com> (Scott Taylor's message of "Thu\, 9 Oct 2008 03\:21\:27 -0400") References: <6BFED86B-EDB0-4894-BE26-25B4323FCAC8@railsnewbie.com> Message-ID: Scott Taylor writes: > I find it sort of interesting that they are using RSpec in one of the > courses @ UC Berkley: > > http://radlab.cs.berkeley.edu/wiki/Cs198 > > Scott I'd like to study at Berkeley. I wonder if this would help me get in? Pat From hongli at plan99.net Thu Oct 9 13:20:40 2008 From: hongli at plan99.net (Hongli Lai) Date: Thu, 09 Oct 2008 19:20:40 +0200 Subject: [rspec-users] What's the best way to test inherited behavior? Message-ID: <48EE3D68.50007@plan99.net> I currently have a base class and 2 subclasses. I'm struggling with finding the best way to test them. This is the current situation. The base class is called AbstractServer. It's not really abstract because it can be instantiated and used, but some important methods are defined as no-ops, and are meant to be overrided by child classes. The spec for AbstractServer looks like: describe AbstractServer do it_should_behave_like "AbstractServer-like behavior" ... AbstractServer tests ... end For the child classes, their specs look like this: describe ApplicationSpawner do it_should_behave_like "AbstractServer-like behavior" ... ApplicationSpawner-specific tests ... end describe FrameworkSpawner do it_should_behave_like "AbstractServer-like behavior" ... FrameworkSpawner-specific tests ... end However, this looks very ugly. 'it_should_behave_like "AbstractServer-like behavior"' doesn't read like a normal sentence, and saying that AbstractServer has AbstractServer-like behavior is redundant. What's the best way to solve this? What are good practices for testing inherited behavior? Should I be testing my child classes for parent class behavior at all? Right now I'm doing it anyway in order to detect bugs that I might have missed otherwise. From raasdnil at gmail.com Thu Oct 9 14:07:58 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Fri, 10 Oct 2008 05:07:58 +1100 Subject: [rspec-users] Cucumber / Webrat clicks_button problem Message-ID: <57a815bf0810091107u67fe9b38h7874ba52354b1d51@mail.gmail.com> Before I dive into the code and fix it, has anyone else worked around / found the solution to calling 'clicks_button' when the button is actually a button and not an input? ie:
Calling clicks on this doesn't find it as webrat only looks for input[type=submit]. Mikel -- http://lindsaar.net/ Rails, RSpec and Life blog.... From dchelimsky at gmail.com Thu Oct 9 14:11:09 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Oct 2008 13:11:09 -0500 Subject: [rspec-users] What's the best way to test inherited behavior? In-Reply-To: <48EE3D68.50007@plan99.net> References: <48EE3D68.50007@plan99.net> Message-ID: <57c63afe0810091111p7e953e54sff9d4de2da4871aa@mail.gmail.com> On Thu, Oct 9, 2008 at 12:20 PM, Hongli Lai wrote: > I currently have a base class and 2 subclasses. I'm struggling with finding > the best way to test them. This is the current situation. > > The base class is called AbstractServer. It's not really abstract because it > can be instantiated and used, but some important methods are defined as > no-ops, and are meant to be overrided by child classes. The spec for > AbstractServer looks like: > > describe AbstractServer do > it_should_behave_like "AbstractServer-like behavior" > > ... AbstractServer tests ... > end > > For the child classes, their specs look like this: > > describe ApplicationSpawner do > it_should_behave_like "AbstractServer-like behavior" > > ... ApplicationSpawner-specific tests ... > end > > describe FrameworkSpawner do > it_should_behave_like "AbstractServer-like behavior" > > ... FrameworkSpawner-specific tests ... > end > > However, this looks very ugly. 'it_should_behave_like "AbstractServer-like > behavior"' doesn't read like a normal sentence, and saying that > AbstractServer has AbstractServer-like behavior is redundant. > > What's the best way to solve this? What are good practices for testing > inherited behavior? Should I be testing my child classes for parent class > behavior at all? Right now I'm doing it anyway in order to detect bugs that > I might have missed otherwise. Not sure why what you're doing works at all, but try this (which is how it should work): describe "AbstractServer", :shared => true do ... end describe ApplicationSpawner do it_should_behave_like "AbstractServer" .. end etc From matt at mattwynne.net Thu Oct 9 14:37:58 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 9 Oct 2008 19:37:58 +0100 Subject: [rspec-users] What's the best way to test inherited behavior? In-Reply-To: <48EE3D68.50007@plan99.net> References: <48EE3D68.50007@plan99.net> Message-ID: <06900870-E9D2-4C11-9AD8-3F9C3BB34C19@mattwynne.net> On 9 Oct 2008, at 18:20, Hongli Lai wrote: > I currently have a base class and 2 subclasses. I'm struggling with > finding the best way to test them. This is the current situation. > What's the best way to solve this? What are good practices for > testing inherited behavior? Should I be testing my child classes for > parent class behavior at all? Right now I'm doing it anyway in order > to detect bugs that I might have missed otherwise. I've been meaning to blog about this, as I recently had an epiphany about how brilliantly rspec handles this, IMO. I actually do it pretty much the way you're doing it, but I don't think it's ugly at all. To me, the abstract superclass is just an implementation detail of the concrete subclass - I don't need to or want to care that implementation detail when I'm writing specifications about how the concrete class should behave. Therefore while the behaviour which is common between it and other classes that have the same superclass does tend to end up in shared example groups, that's just because I'm keeping my code nicely factored - the same specs would still be valid if I copied and pasted the superclass code out into the two subclasses and collapsed the hierarchy, or moved them into modules, or whatever. It's a subtle shift, but if you try to let go of the implementation, and think about the *behaviour* when you name your example groups, you'll find they start to read more naturally. In your case, the two concrete servers can just say it_should_behave_like "a server" and pull in the specifications for the behaviour that is common to both. At songkick, for example, we're modelling bands playing gigs. We have an abstract Event superclass, subclassed by Concert and Festival. The spec for Event reads like this: describe Event do it "should be abstract" lambda { Event.new }.should raise_error(TypeError) end end Then the two subclasses mix in a module containing the shared example groups, and at the top, they say describe Concert do extend SK::Spec::Models::ExampleGroups #shared example groups for models live in here it_should_behave_like "an event" # special concert behaviour spec'd here... I've tried to find a pattern I was comfortable with for this with xUnit tests, and never managed it. For me, rspec's solution fits the problem like a glove. HTH, Matt From mark.thomson at ieee.org Thu Oct 9 14:38:23 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Thu, 09 Oct 2008 13:38:23 -0500 Subject: [rspec-users] fills_in NoMethodError In-Reply-To: <57c63afe0810090334p3cb8e6b8xa16dae36a9f82e37@mail.gmail.com> References: <48ED64A7.3040407@ieee.org> <2552F40F-85BE-48D6-A71D-54368B39E29C@mattwynne.net> <57c63afe0810090334p3cb8e6b8xa16dae36a9f82e37@mail.gmail.com> Message-ID: <48EE4F9F.9060206@ieee.org> Thanks guys. I took your advice and moved to cucumber. It did turn out to be useful in that the more verbose error reporting led me to dive more deeply into the webrat source, eventually leading me to my problem - which actually was essentially the same noob error I made a few days when I failed to realize my development code had a data migration that hadn't populated the test db. In this case the updated form mentioned in my earlier post had selection inputs whose options are meant to be stored in the db. Since they weren't actually there, there were no select options in the form. What was puzzling initially was that an error related to selection inputs was showing up in the fills_in call. But it turns out that webrat looks for the named text field by searching over all the input tags in the form. In the process of parsing the selection inputs it was throwing up when it didn't find the option tags it was expecting. Mark. David Chelimsky wrote: > On Thu, Oct 9, 2008 at 1:57 AM, Matt Wynne wrote: > >> On 9 Oct 2008, at 02:55, Mark Thomson wrote: >> >> >>> I have an RSpec story with an overall structure that looks something like >>> this - >>> >>> ---- >>> Given the user is on the start page >>> When the user clicks the 'new' button >>> Then the 'new record' page should be displayed >>> >>> When the user fills in the form >>> And the user submits the form >>> Then the updated form should be displayed >>> >>> When the user fills in the updated form >>> And the user submits the form >>> Then a conformation message should be displayed >>> ---- >>> >>> In the last When step, I have a fills_in call that is failing with the >>> following: >>> >>> ---- >>> NoMethodError: 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.attributes. >>> ---- >>> >>> I think the ActiveRecord thing is a red herring. Poking through the Webrat >>> source code, it seems like the problem is more likely a failure to find any >>> input fields. But I'm not sure why. Is there anything inappropriate with the >>> way I've organized the story, stringing together multiple When-Then >>> segments? One thing that seems curious is that I have a completely identical >>> fills_in call in the When step that precedes the one that is failing and yet >>> that one runs without any problem. >>> >> I think this sort of error tends to happen while a view is being rendered, >> so my guess is it's something to do with your data setup. >> >> Sorry to bang on about this, but cucumber has much better support for error >> messages - you might want to consider making the switch before you waste too >> much time on this issue. >> > > Matt is correct, you should definitely consider moving to cucumber, > though I don't know that cucumber will necessary help you shed any > more light on this particular issue. > > Mark, with the little bit of information you've provided, my best > guess would be that the :new action is providing some instance > variable that is not being provided by the :create action in the case > where the data from "When the user fills in the form" is incorrect or > insufficient to save the model. > > If that's not correct, please post the code for the steps and the > relevant controller actions. > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hongli at plan99.net Thu Oct 9 15:07:55 2008 From: hongli at plan99.net (Hongli Lai) Date: Thu, 09 Oct 2008 21:07:55 +0200 Subject: [rspec-users] What's the best way to test inherited behavior? In-Reply-To: <57c63afe0810091111p7e953e54sff9d4de2da4871aa@mail.gmail.com> References: <48EE3D68.50007@plan99.net> <57c63afe0810091111p7e953e54sff9d4de2da4871aa@mail.gmail.com> Message-ID: <48EE568B.8060909@plan99.net> David Chelimsky wrote: > Not sure why what you're doing works at all Oh oops, I forgot to mention that I also have 'shared_examples_for "AbstractServer-like" behavior'. From pergesu at gmail.com Thu Oct 9 15:18:43 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 9 Oct 2008 12:18:43 -0700 Subject: [rspec-users] What's the best way to test inherited behavior? In-Reply-To: <48EE3D68.50007@plan99.net> References: <48EE3D68.50007@plan99.net> Message-ID: <810a540e0810091218r45fc30a0mf0aed6b20c9298fe@mail.gmail.com> I've written [1] about using shared example groups to do this sort of things. You're already using them :) but maybe you can still get something out of that post. What specifically don't you like about this solution? Pat [1] http://evang.eli.st/blog/2008/5/14/refactoring-with-shared-example-groups From chris at cobaltedge.com Thu Oct 9 15:24:06 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Thu, 9 Oct 2008 12:24:06 -0700 Subject: [rspec-users] Need help using URL helpers in controller tests Message-ID: <443c240c0810091224p342a98c1i402aee02d2f9145f@mail.gmail.com> I have a controller test, where I want to do a GET on a page. Our URL's are complex, and need to be correct (duh, but we allow some slop, but that causes a redirect which I want to avoid). Anyway, in my controller test I do a get to the URL that is produced by a helper method which calls a named route URL helper. This is not working, and I'm wondering why/what I'm messing up. Here's the line in the spec code that starts things off (@widget is a real ActiveRecord object): get @controller.widget_path_for_seo(@widget) The widget_path_for_seo method is defined in our ApplicationController. It digs some info out of the widget instance that then get passed to the named route URL helper method, so it looks like this: def widget_path_for_seo(widget) location = seo_name_for_url widget.location.name building = seo_name_for_url(building_name_for_seo_url(widget.building), true) + "-widgets" widget_id = seo_name_for_url(widget.name) + "-" + widget.id.to_s seo_widget_path(:location => location, : building => building, :id => widget_id) end It's the "seo_widget_path" named route helper method that is failing. I've checked that all values going into it are valid, but the error I get is in ActionController::Base.url_for, where it's looking at the options hash of values that are passed in, and doing this: @url.rewrite(rewrite_options(options)) It compalins that @url is nil. I'm wondering if this is due to being run under the test environment or what I'm missing/not realizing, etc. What's strange is that some of the restful resource route url helpers work fine. Can anyone clue me in? -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at deadorange.com Thu Oct 9 15:27:07 2008 From: nick at deadorange.com (Nick Hoffman) Date: Thu, 9 Oct 2008 15:27:07 -0400 Subject: [rspec-users] Refactoring and using each In-Reply-To: References: Message-ID: On 2008-10-08, at 07:01, Jeroen van Dijk wrote: > Hi all, > > I'm new to this list and new to RSpec so I have been trying out > RSpec the last couple of days and I find it very a natural way of > testing. So first of all thanks for providing this framework. > > Now, I have written some tests for my controllers and models and I > saw myself writing similar code, so I began refactoring and came up > with the following issue. > > Here is a simple example of what I first wrote: > > describe Example do > > it "should not be valid without attribute1" do > Example.new(:attribute2 => "2").should_not be_valid > end > > it "should not be valid without attribute2" do > Example.new(:attribute1 => "1").should_not be_valid > end > end > > Which I rewrote into another working test: > > ###### > module ExampleSpecHelper > def required_valid_attributes > {:attribute1 => "1", :attribute2 => "2"} > end > end > > describe Example do > include ExampleSpecHelper > [:attribute1, :attribute2].each do |attribute| > before(:all) do > @model_with_one_missing_attribute = > TextMessage.new(required_valid_attributes.except(attribute)) > end > > it "should not be valid without #{attribute}" do > @model_with_one_missing_attribute.should_not be_valid > end > end > ##### > > In this example in you might not see difference in lines of code, > but imagine you would have 10 attributes and 10 more tests for each > attribute.. Now I rewrote this I was still not satisfied because I > thought I would like to use this same approach for several models > with different attributes while keeping the logic of this test in > one place. Unfortunately, I didn't come that far because of this: > > #this works: > describe Example do > include ExampleSpecHelper > required_attributes = [:attribute1, :attribute2] > required_attributes.each do |attribute| > before(:all) do > @model_with_one_missing_attribute = > TextMessage.new(required_valid_attributes.except(attribute)) > end > > it "should not be valid without #{attribute}" do > @model_with_one_missing_attribute.should_not be_valid > end > end > > #However this which eventually will be more DRY, but does for some > reason not work?! > module ExampleSpecHelper > ... > def required_attributes > [:attribute1, :attribute2] > end > ... > end > > describe Example do > include ExampleSpecHelper > required_attributes.each do |attribute| > before(:all) do > @model_with_one_missing_attribute = > TextMessage.new(required_valid_attributes.except(attribute)) > end > > it "should not be valid without #{attribute}" do > @model_with_one_missing_attribute.should_not be_valid > end > end > > > ############ > > I don't understand why it does not work. In the last example > required_attributes is nil while the other methods from the helper > module such as 'required_valid_attributes' are available on an even > lower level. Why? I hope you understand why I'm trying to refactor > it like this. If I can do this I only need to define the required > attributes for each model and use it_should_behave_like "an AR > model" to keep it DRY. > > Hope someone can clarify this and that I haven't done something > stupid! Thanks! > > Cheers, > > Jeroen Hi Jeroen. As I was getting into RSpec and writing specs for my various models, I too found that my code could be a lot DRYer. I ended up writing a module that generates specs for my model attributes. I've put it up on GitHub, along with full, lengthy example of how to use it. Have a look: http://github.com/nickhoffman/modelspeccer/ Cheers, Nick From hongli at plan99.net Thu Oct 9 15:35:42 2008 From: hongli at plan99.net (Hongli Lai) Date: Thu, 09 Oct 2008 21:35:42 +0200 Subject: [rspec-users] What's the best way to test inherited behavior? In-Reply-To: <810a540e0810091218r45fc30a0mf0aed6b20c9298fe@mail.gmail.com> References: <48EE3D68.50007@plan99.net> <810a540e0810091218r45fc30a0mf0aed6b20c9298fe@mail.gmail.com> Message-ID: <48EE5D0E.2030007@plan99.net> Pat Maddox wrote: > I've written [1] about using shared example groups to do this sort of > things. You're already using them :) but maybe you can still get > something out of that post. > > What specifically don't you like about this solution? What Matt proposed is very nice. :) I was struggling with finding a good way to name my specs. However, by calling the shared example "a server" I can still end up with weird names: describe FrameworkSpawner describe "when in conservative spawning mode" before :each do .. end it_should_behave_like "an AbstractServer" end describe "when in smart spawning mode" before :each do end it_should_behave_like "an AbstractServer" end end So I can end up with a weird sentence like: "FrameworkSpawner when in smart spawning mode an AbstractServer raises AlreadyStarted if the child process is still running" Shared example groups *are* a blessing. Just the constructed sentences bother me sometimes. :) I'm also wondering whether it's a good idea to test my child classes like this, or whether I should test the parent class separately, and not test the child classes for the parent class's behaviors. From mark at mwilden.com Thu Oct 9 19:47:03 2008 From: mark at mwilden.com (Mark Wilden) Date: Thu, 9 Oct 2008 16:47:03 -0700 Subject: [rspec-users] should != Message-ID: <3c30da400810091647p2955416du695e254b809b4dd0@mail.gmail.com> I expected 'should !=' to act the same as 'should_not =='. That turned out to be incorrect (by design?): require 'spec' require 'spec/rails' describe "using 'should !='" do it "seems to treat != as the same as ==" do 1.should != 1 # passes 1.should != 2 # fails end end -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Oct 9 20:07:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 9 Oct 2008 19:07:53 -0500 Subject: [rspec-users] should != In-Reply-To: <3c30da400810091647p2955416du695e254b809b4dd0@mail.gmail.com> References: <3c30da400810091647p2955416du695e254b809b4dd0@mail.gmail.com> Message-ID: <57c63afe0810091707k4be3d649xff69f3b094352878@mail.gmail.com> On Thu, Oct 9, 2008 at 6:47 PM, Mark Wilden wrote: > I expected 'should !=' to act the same as 'should_not =='. That turned out > to be incorrect (by design?): We'd love to do that, but Ruby doesn't provide us the tools we need. As far as we know, the only way to do that would be to do string evals on the files instead of using actual code. Brief explanation: Object.instance_methods.sort.grep /\=/ => ["==", "===", "=~", "taguri="] Note the absence of "!=". Try this in irb: irb(main):001:0> 5.==(5) => true irb(main):002:0> 5.!=(4) SyntaxError: compile error (irb):2: syntax error, unexpected tNEQ 5.!=(4) ^ Essentially, ruby interprets this: 5.should == 5 as this: 5.should.==(5) but it interprets this: 5.should != 4 as this: !(5.should.==(4)) And since 5 has no way of knowing that it's part of a negated expression, there's no way for rspec (that I know of) to handle this as you would expect. Sorry - we all wish it could be so. I imagine the rubinius extended version will support it though ;) Cheers, David > require 'spec' > require 'spec/rails' > > describe "using 'should !='" do > it "seems to treat != as the same as ==" do > 1.should != 1 # passes > 1.should != 2 # fails > end > end > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Thu Oct 9 20:07:51 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 09 Oct 2008 17:07:51 -0700 Subject: [rspec-users] should != In-Reply-To: <3c30da400810091647p2955416du695e254b809b4dd0@mail.gmail.com> (Mark Wilden's message of "Thu\, 9 Oct 2008 16\:47\:03 -0700") References: <3c30da400810091647p2955416du695e254b809b4dd0@mail.gmail.com> Message-ID: "Mark Wilden" writes: > I expected 'should !=' to act the same as 'should_not =='. That turned out to be incorrect (by design?): > > require 'spec' > require 'spec/rails' > > describe "using 'should !='" do > it "seems to treat != as the same as ==" do > 1.should != 1 # passes > 1.should != 2 # fails > end > end Sorry for the short message, but yeah this is known. You can search the mailing list archives and the tracker for other emails. Basically, Ruby doesn't let us do this, because it translates should != 1 into !(should == 1) and since (should == 1) is a passing expectation, the thing passes. You can get around it by using paresetree or a similar technique but it's sloooooooow thus has not become a part of rspec. Pat From mark at mwilden.com Thu Oct 9 20:19:12 2008 From: mark at mwilden.com (Mark Wilden) Date: Thu, 9 Oct 2008 17:19:12 -0700 Subject: [rspec-users] should != In-Reply-To: <57c63afe0810091707k4be3d649xff69f3b094352878@mail.gmail.com> References: <3c30da400810091647p2955416du695e254b809b4dd0@mail.gmail.com> <57c63afe0810091707k4be3d649xff69f3b094352878@mail.gmail.com> Message-ID: <3c30da400810091719y39b21060gbec3c9d4905ccd2e@mail.gmail.com> Ahh, one of the cool things about Ruby compared to the C family of languages comes back to bite me. :) ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis at sutch.com Fri Oct 10 00:17:27 2008 From: dennis at sutch.com (Dennis Sutch) Date: Fri, 10 Oct 2008 00:17:27 -0400 Subject: [rspec-users] Solution for autospec not working Message-ID: Hello, I have noticed that, since version 1.1.4, autotest/autospec does not run any of my specs. After getting a hint from http://b.logi.cx/2008/10/9/non-auto-spec, I dove a bit deeper into the code and found that spec is no longer being run by ruby. I monkey-patched Autotest::Rspec in my .autotest file so that spec is again executed (using code taken from version 1.1.4). autospec is now working for me. Applicable code from my .autotest file: http://pastie.org/289183 github shows that the spec_command was removed on 7/12, with the comment: "removed spec_command from autotest/rspec (ruby works just fine)". See: http://github.com/dchelimsky/rspec/commit/1aca72d0c5b5dc92c1ac9a4b94ccb8f6961067d2 Does autospec work for anyone? Does this issue only affect those of us using Windows? -- Dennis Sutch dennis at sutch.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From luislavena at gmail.com Fri Oct 10 00:23:51 2008 From: luislavena at gmail.com (Luis Lavena) Date: Fri, 10 Oct 2008 01:23:51 -0300 Subject: [rspec-users] Solution for autospec not working In-Reply-To: References: Message-ID: <71166b3b0810092123h59c4e748j2275f71b17174c91@mail.gmail.com> On Fri, Oct 10, 2008 at 1:17 AM, Dennis Sutch wrote: > Hello, > I have noticed that, since version 1.1.4, autotest/autospec does not run any > of my specs. After getting a hint > from http://b.logi.cx/2008/10/9/non-auto-spec, I dove a bit deeper into the > code and found that spec is no longer being run by ruby. > I monkey-patched Autotest::Rspec in my .autotest file so that spec is again > executed (using code taken from version 1.1.4). autospec is now working for > me. Applicable code from my .autotest file: http://pastie.org/289183 > github shows that the spec_command was removed on 7/12, with the comment: > "removed spec_command from autotest/rspec (ruby works just fine)". See: > http://github.com/dchelimsky/rspec/commit/1aca72d0c5b5dc92c1ac9a4b94ccb8f6961067d2 > > Does autospec work for anyone? Does this issue only affect those of us > using Windows? Works here: Luis at KEORE (D:\Users\Luis\projects\area17\a17_redux\a17_redux.git) $ ruby -v ruby 1.8.6 (2008-03-03 patchlevel 114) [i386-mingw32] Luis at KEORE (D:\Users\Luis\projects\area17\a17_redux\a17_redux.git) $ spec -v rspec 1.1.8 Luis at KEORE (D:\Users\Luis\projects\area17\a17_redux\a17_redux.git) $ gem list ZenTest *** LOCAL GEMS *** ZenTest (3.10.0) ==== Luis at KEORE (D:\Users\Luis\projects\area17\a17_redux\a17_redux.git) $ ruby script\about About your application's environment Ruby version 1.8.6 (i386-mingw32) RubyGems version 1.2.0 Rails version 2.1.1 ==== My .autotest file: http://pastie.org/289187 (exceptions are at ~/.autotest while other stuff is in the RAILS_ROOT of my app. HTH, -- 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 Fri Oct 10 02:56:53 2008 From: lists at ruby-forum.com (Mano ah) Date: Fri, 10 Oct 2008 08:56:53 +0200 Subject: [rspec-users] rspec - undefined method `describe' for main:Object Message-ID: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> When i run a spec file i am getting the following error D:\Diwakar\spec_diwa\spec\controllers>spec sandbox_controller_spec.rb c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/lib/spec/api/sugar.rb:17:in `method_ missing': undefined method `describe' for main:Object (NoMethodError) from ./sandbox_controller_spec.rb:7 from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:28:in `ge m_original_require' from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:28:in `re quire' from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/bin/spec:13 from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/bin/spec:7:in `each' from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/bin/spec:7 from c:/ruby/bin/spec:19:in `load' from c:/ruby/bin/spec:19 My spec controller is require File.dirname(__FILE__) + '/../spec_helper' #require './../../vendor/generators/rspec/lib/rspec_on_rails' #require 'sandbox_controller.rb' require 'spec' gem 'rspec' describe SandboxController,"handling someaction" do it "should get real value 10" do get :someaction assigns[:value].should equal(10) end end My controller is class SandboxController < ApplicationController def someaction @value = somemethod end protected def somemethod return 10 end end Please help me to solve the issue -- Posted via http://www.ruby-forum.com/. From mark.thomson at ieee.org Fri Oct 10 03:23:27 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Fri, 10 Oct 2008 02:23:27 -0500 Subject: [rspec-users] cucumber and fixtures In-Reply-To: References: <8d961d900810080728s4ba72cdawc4af9360396e811c@mail.gmail.com> <85d99afe0810081255w3c541264j6405b6707f959425@mail.gmail.com> <55a81029f1194807d52edbbed64a2033@ruby-forum.com> Message-ID: <48EF02EF.9040705@ieee.org> Hilarious. This is exactly what I needed today as well and eventually found this thread through Google, not realizing it was already sitting in my inbox. :-). In my case I wanted to use fixtures in testing because the development db had already been populated by a data migration, and I didn't want to write more code to both define and load the data as would be required using seed-fu. It seemed easier to install the ar_fixtures plugin and use that to dump the data to a yaml file and then load the data in as part of my story execution. Hence my need for the solution Daniel mentioned. Despite my inexperience, I was a little surprised that I had difficulty figuring out how to do this. I'm still not sure why "fixtures :model" like you would use in Test::Unit does not work. And I can report that "self.class.fixtures :all" recommended here: http://www.mail-archive.com/rspec-users at rubyforge.org/msg03194.html, did not work for me. I presume that at some point some more extensive documentation for Cucumber will appear and I think this is an example of an issue that would be helpful to have described in more detail. Mark. Daniel Higginbotham wrote: > Pat Maddox wrote: > >> Daniel Higginbotham writes: >> >> >>>> ActiveRecord::Schema.verbose = false >>>> { :name => "blah", :id => 1 }, >>>> >>> end >>> end >>> >>> Are you similarly able to load your YAML fixtures from spec/fixtures >>> when you're running a Cucumber feature? >>> >>> Thanks, >>> Daniel Higginbotham >>> >> I don't know that it's built into Cucumber, but loading fixtures is >> pretty simple from what I remember. Something like >> AR::Fixtures.load('path/to/file.yml') or something. Look around and I'm >> sure you can find the couple lines to make it work. >> >> Pat >> > > Thanks Pat! > > It looks like > > Fixtures.create_fixtures("spec/fixtures", "users") > > works. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Fri Oct 10 03:53:11 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 10 Oct 2008 08:53:11 +0100 Subject: [rspec-users] What's the best way to test inherited behavior? In-Reply-To: <48EE5D0E.2030007@plan99.net> References: <48EE3D68.50007@plan99.net> <810a540e0810091218r45fc30a0mf0aed6b20c9298fe@mail.gmail.com> <48EE5D0E.2030007@plan99.net> Message-ID: On 9 Oct 2008, at 20:35, Hongli Lai wrote: > Pat Maddox wrote: >> I've written [1] about using shared example groups to do this sort of >> things. You're already using them :) but maybe you can still get >> something out of that post. >> What specifically don't you like about this solution? > > What Matt proposed is very nice. :) I was struggling with finding a > good way to name my specs. ta! :) > However, by calling the shared example "a server" I can still end up > with weird names: > > describe FrameworkSpawner > describe "when in conservative spawning mode" > before :each do > .. > end > > it_should_behave_like "an AbstractServer" > end > > describe "when in smart spawning mode" > before :each do > end > > it_should_behave_like "an AbstractServer" > end > end > > So I can end up with a weird sentence like: > "FrameworkSpawner when in smart spawning mode an AbstractServer > raises AlreadyStarted if the child process is still running" You're right, these do read funny don't they? I still don't think you've got far enough along the implementation- >behavioiur spectrum in your example names and that's partly why it still feels weird. I'd rid of that reference to the AbstractServer altogether, for starters. Don't forget that the name of the shared example group does not go into the specdoc - it's just a label you use when pulling it in with it_should_behave_like. Maybe you could put another ExampleGroup block inside your shared group to describe the context? e.g.: "FrameworkSpawner when in smart spawning mode when the child process is still running should raise an AlreadyStarted error" Also bear in mind that you can split your shared behaviour and have more than one shared example group, and 'mix them in' to define the appropriate behaviour in different contexts. > Shared example groups *are* a blessing. Just the constructed > sentences bother me sometimes. :) I'm also wondering whether it's a > good idea to test my child classes like this, or whether I should > test the parent class separately, and not test the child classes for > the parent class's behaviors. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Fri Oct 10 04:04:08 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 10 Oct 2008 09:04:08 +0100 Subject: [rspec-users] Need help using URL helpers in controller tests In-Reply-To: <443c240c0810091224p342a98c1i402aee02d2f9145f@mail.gmail.com> References: <443c240c0810091224p342a98c1i402aee02d2f9145f@mail.gmail.com> Message-ID: <5C8F5CA6-674A-4113-ACEB-AD7CD9EF518C@mattwynne.net> On 9 Oct 2008, at 20:24, Christopher Bailey wrote: > I have a controller test, where I want to do a GET on a page. Our > URL's are complex, and need to be correct (duh, but we allow some > slop, but that causes a redirect which I want to avoid). Anyway, in > my controller test I do a get to the URL that is produced by a > helper method which calls a named route URL helper. This is not > working, and I'm wondering why/what I'm messing up. Here's the line > in the spec code that starts things off (@widget is a real > ActiveRecord object): > > get @controller.widget_path_for_seo(@widget) > > The widget_path_for_seo method is defined in our > ApplicationController. It digs some info out of the widget instance > that then get passed to the named route URL helper method, so it > looks like this: > > def widget_path_for_seo(widget) > location = seo_name_for_url widget.location.name > building = > seo_name_for_url(building_name_for_seo_url(widget.building), true) + > "-widgets" > widget_id = seo_name_for_url(widget.name) + "-" + widget.id.to_s > > seo_widget_path(:location => location, : building => > building, :id => widget_id) > end > > It's the "seo_widget_path" named route helper method that is > failing. I've checked that all values going into it are valid, but > the error I get is in ActionController::Base.url_for, where it's > looking at the options hash of values that are passed in, and doing > this: > > @url.rewrite(rewrite_options(options)) > > It compalins that @url is nil. I'm wondering if this is due to > being run under the test environment or what I'm missing/not > realizing, etc. What's strange is that some of the restful resource > route url helpers work fine. Can anyone clue me in? > > -- > Christopher Bailey > Cobalt Edge LLC > http://cobaltedge.com Quick thought - it doesn't look like you have 'spun' up the routes when you test this method. If you haven't already made a get/post request through the rails integration session infrastructure the named routes don't get loaded, and that can be quite confusing. I'm not sure if that could be the cause of your issue but I thought it was worth mentioning. From matt at mattwynne.net Fri Oct 10 04:05:44 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 10 Oct 2008 09:05:44 +0100 Subject: [rspec-users] fills_in NoMethodError In-Reply-To: <48EE4F9F.9060206@ieee.org> References: <48ED64A7.3040407@ieee.org> <2552F40F-85BE-48D6-A71D-54368B39E29C@mattwynne.net> <57c63afe0810090334p3cb8e6b8xa16dae36a9f82e37@mail.gmail.com> <48EE4F9F.9060206@ieee.org> Message-ID: Do we need to make it a bit clearer on the rspec.info site that cucumber is the way forward? The trail of blog posts etc with the up- to-date info is probably fairly bewildering to a newbie. On 9 Oct 2008, at 19:38, Mark Thomson wrote: > Thanks guys. I took your advice and moved to cucumber. It did turn > out to be useful in that the more verbose error reporting led me to > dive more deeply into the webrat source, eventually leading me to my > problem - which actually was essentially the same noob error I made > a few days when I failed to realize my development code had a data > migration that hadn't populated the test db. > > In this case the updated form mentioned in my earlier post had > selection inputs whose options are meant to be stored in the db. > Since they weren't actually there, there were no select options in > the form. > > What was puzzling initially was that an error related to selection > inputs was showing up in the fills_in call. But it turns out that > webrat looks for the named text field by searching over all the > input tags in the form. In the process of parsing the selection > inputs it was throwing up when it didn't find the option tags it was > expecting. > > Mark. > > > > David Chelimsky wrote: >> >> On Thu, Oct 9, 2008 at 1:57 AM, Matt Wynne >> wrote: >> >>> On 9 Oct 2008, at 02:55, Mark Thomson wrote: >>> >>> >>>> I have an RSpec story with an overall structure that looks >>>> something like >>>> this - >>>> >>>> ---- >>>> Given the user is on the start page >>>> When the user clicks the 'new' button >>>> Then the 'new record' page should be displayed >>>> >>>> When the user fills in the form >>>> And the user submits the form >>>> Then the updated form should be displayed >>>> >>>> When the user fills in the updated form >>>> And the user submits the form >>>> Then a conformation message should be displayed >>>> ---- >>>> >>>> In the last When step, I have a fills_in call that is failing >>>> with the >>>> following: >>>> >>>> ---- >>>> NoMethodError: 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.attributes. >>>> ---- >>>> >>>> I think the ActiveRecord thing is a red herring. Poking through >>>> the Webrat >>>> source code, it seems like the problem is more likely a failure >>>> to find any >>>> input fields. But I'm not sure why. Is there anything >>>> inappropriate with the >>>> way I've organized the story, stringing together multiple When-Then >>>> segments? One thing that seems curious is that I have a >>>> completely identical >>>> fills_in call in the When step that precedes the one that is >>>> failing and yet >>>> that one runs without any problem. >>>> >>> I think this sort of error tends to happen while a view is being >>> rendered, >>> so my guess is it's something to do with your data setup. >>> >>> Sorry to bang on about this, but cucumber has much better support >>> for error >>> messages - you might want to consider making the switch before you >>> waste too >>> much time on this issue. >>> >> Matt is correct, you should definitely consider moving to cucumber, >> though I don't know that cucumber will necessary help you shed any >> more light on this particular issue. >> >> Mark, with the little bit of information you've provided, my best >> guess would be that the :new action is providing some instance >> variable that is not being provided by the :create action in the case >> where the data from "When the user fills in the form" is incorrect or >> insufficient to save the model. >> >> If that's not correct, please post the code for the steps and the >> relevant controller actions. >> >> 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 tastapod at gmail.com Fri Oct 10 04:48:27 2008 From: tastapod at gmail.com (Dan North) Date: Fri, 10 Oct 2008 09:48:27 +0100 Subject: [rspec-users] What's the best way to test inherited behavior? In-Reply-To: References: <48EE3D68.50007@plan99.net> <810a540e0810091218r45fc30a0mf0aed6b20c9298fe@mail.gmail.com> <48EE5D0E.2030007@plan99.net> Message-ID: Another approach would be to prefer composition over inheritance, and either inject the server in a constructor (with a suitable name for the class) or mix it in as a module. Then you could describe the common server behaviour in one set of examples, and just have a couple of mock-based examples to verify that the "subclasses" interact correctly with the Server. Cheers, Dan 2008/10/10 Matt Wynne > On 9 Oct 2008, at 20:35, Hongli Lai wrote: > > Pat Maddox wrote: >> >>> I've written [1] about using shared example groups to do this sort of >>> things. You're already using them :) but maybe you can still get >>> something out of that post. >>> What specifically don't you like about this solution? >>> >> >> What Matt proposed is very nice. :) I was struggling with finding a good >> way to name my specs. >> > > ta! :) > > However, by calling the shared example "a server" I can still end up with >> weird names: >> >> describe FrameworkSpawner >> describe "when in conservative spawning mode" >> before :each do >> .. >> end >> >> it_should_behave_like "an AbstractServer" >> end >> >> describe "when in smart spawning mode" >> before :each do >> end >> >> it_should_behave_like "an AbstractServer" >> end >> end >> >> So I can end up with a weird sentence like: >> "FrameworkSpawner when in smart spawning mode an AbstractServer raises >> AlreadyStarted if the child process is still running" >> > > You're right, these do read funny don't they? > > I still don't think you've got far enough along the > implementation->behavioiur spectrum in your example names and that's partly > why it still feels weird. I'd rid of that reference to the AbstractServer > altogether, for starters. > > Don't forget that the name of the shared example group does not go into the > specdoc - it's just a label you use when pulling it in with > it_should_behave_like. > > Maybe you could put another ExampleGroup block inside your shared group to > describe the context? > > e.g.: "FrameworkSpawner when in smart spawning mode when the child process > is still running should raise an AlreadyStarted error" > > Also bear in mind that you can split your shared behaviour and have more > than one shared example group, and 'mix them in' to define the appropriate > behaviour in different contexts. > > > > Shared example groups *are* a blessing. Just the constructed sentences >> bother me sometimes. :) I'm also wondering whether it's a good idea to test >> my child classes like this, or whether I should test the parent class >> separately, and not test the child classes for the parent class's behaviors. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From raasdnil at gmail.com Fri Oct 10 04:50:50 2008 From: raasdnil at gmail.com (Mikel Lindsaar) Date: Fri, 10 Oct 2008 19:50:50 +1100 Subject: [rspec-users] Cucumber / Webrat clicks_button problem In-Reply-To: <57a815bf0810091107u67fe9b38h7874ba52354b1d51@mail.gmail.com> References: <57a815bf0810091107u67fe9b38h7874ba52354b1d51@mail.gmail.com> Message-ID: <57a815bf0810100150x368f0bc6sf9feb620a4619cea@mail.gmail.com> Never mind, fixed in trunk of Webrat. On Fri, Oct 10, 2008 at 5:07 AM, Mikel Lindsaar wrote: > Before I dive into the code and fix it, has anyone else worked around > / found the solution to calling 'clicks_button' when the button is > actually a button and not an input? > > ie: > >
> > >
> > Calling clicks on this doesn't find it as webrat only looks for > input[type=submit]. > > Mikel > > > -- > http://lindsaar.net/ > Rails, RSpec and Life blog.... > -- http://lindsaar.net/ Rails, RSpec and Life blog.... From tastapod at gmail.com Fri Oct 10 04:51:34 2008 From: tastapod at gmail.com (Dan North) Date: Fri, 10 Oct 2008 09:51:34 +0100 Subject: [rspec-users] Rspec @ UC Berkley In-Reply-To: References: <6BFED86B-EDB0-4894-BE26-25B4323FCAC8@railsnewbie.com> Message-ID: That's actually a pretty awesome endorsement. We should put something on the website: Who is using rspec? 2008/10/9 Pat Maddox > Scott Taylor writes: > > > I find it sort of interesting that they are using RSpec in one of the > > courses @ UC Berkley: > > > > http://radlab.cs.berkeley.edu/wiki/Cs198 > > > > Scott > > I'd like to study at Berkeley. I wonder if this would help me get in? > > Pat > _______________________________________________ > 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 aslak.hellesoy at gmail.com Fri Oct 10 06:43:44 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 10 Oct 2008 12:43:44 +0200 Subject: [rspec-users] Rspec @ UC Berkley In-Reply-To: References: <6BFED86B-EDB0-4894-BE26-25B4323FCAC8@railsnewbie.com> Message-ID: <8d961d900810100343r70604e66x7280a7dd7f4a45e0@mail.gmail.com> On Fri, Oct 10, 2008 at 10:51 AM, Dan North wrote: > That's actually a pretty awesome endorsement. We should put something on the > website: Who is using rspec? > Good idea! Thanks for doing that, Dan :-) Aslak > > 2008/10/9 Pat Maddox >> >> Scott Taylor writes: >> >> > I find it sort of interesting that they are using RSpec in one of the >> > courses @ UC Berkley: >> > >> > http://radlab.cs.berkeley.edu/wiki/Cs198 >> > >> > Scott >> >> I'd like to study at Berkeley. I wonder if this would help me get in? >> >> Pat >> _______________________________________________ >> 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 dennis at sutch.com Fri Oct 10 07:12:06 2008 From: dennis at sutch.com (Dennis Sutch) Date: Fri, 10 Oct 2008 07:12:06 -0400 Subject: [rspec-users] Solution for autospec not working In-Reply-To: <71166b3b0810092123h59c4e748j2275f71b17174c91@mail.gmail.com> References: <71166b3b0810092123h59c4e748j2275f71b17174c91@mail.gmail.com> Message-ID: My setup is similar, except I'm developing a Ruby script as opposed to a Rails applications, thus no script/about output: C:\Users\Dennis>ruby -v ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] C:\Users\Dennis>spec -v rspec 1.1.8 C:\Users\Dennis>gem list ZenTest *** LOCAL GEMS *** ZenTest (3.10.0) -- Dennis Sutch dennis at sutch.com On Fri, Oct 10, 2008 at 12:23 AM, Luis Lavena wrote: > On Fri, Oct 10, 2008 at 1:17 AM, Dennis Sutch wrote: > > Hello, > > I have noticed that, since version 1.1.4, autotest/autospec does not run > any > > of my specs. After getting a hint > > from http://b.logi.cx/2008/10/9/non-auto-spec, I dove a bit deeper into > the > > code and found that spec is no longer being run by ruby. > > I monkey-patched Autotest::Rspec in my .autotest file so that spec is > again > > executed (using code taken from version 1.1.4). autospec is now working > for > > me. Applicable code from my .autotest file: http://pastie.org/289183 > > github shows that the spec_command was removed on 7/12, with the comment: > > "removed spec_command from autotest/rspec (ruby works just fine)". See: > > > http://github.com/dchelimsky/rspec/commit/1aca72d0c5b5dc92c1ac9a4b94ccb8f6961067d2 > > > > Does autospec work for anyone? Does this issue only affect those of us > > using Windows? > > Works here: > > Luis at KEORE (D:\Users\Luis\projects\area17\a17_redux\a17_redux.git) > $ ruby -v > ruby 1.8.6 (2008-03-03 patchlevel 114) [i386-mingw32] > > Luis at KEORE (D:\Users\Luis\projects\area17\a17_redux\a17_redux.git) > $ spec -v > rspec 1.1.8 > > Luis at KEORE (D:\Users\Luis\projects\area17\a17_redux\a17_redux.git) > $ gem list ZenTest > > *** LOCAL GEMS *** > > ZenTest (3.10.0) > > ==== > Luis at KEORE (D:\Users\Luis\projects\area17\a17_redux\a17_redux.git) > $ ruby script\about > About your application's environment > Ruby version 1.8.6 (i386-mingw32) > RubyGems version 1.2.0 > Rails version 2.1.1 > > ==== > > My .autotest file: > > http://pastie.org/289187 > > (exceptions are at ~/.autotest while other stuff is in the RAILS_ROOT of my > app. > > HTH, > -- > 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 mark.thomson at ieee.org Fri Oct 10 09:12:31 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Fri, 10 Oct 2008 08:12:31 -0500 Subject: [rspec-users] fills_in NoMethodError In-Reply-To: References: <48ED64A7.3040407@ieee.org> <2552F40F-85BE-48D6-A71D-54368B39E29C@mattwynne.net> <57c63afe0810090334p3cb8e6b8xa16dae36a9f82e37@mail.gmail.com> <48EE4F9F.9060206@ieee.org> Message-ID: <48EF54BF.2010703@ieee.org> Yeah, I think that would be a very good idea. Some info on how Webrat fits in with RSpec would be helpful also. FWIW, from the perspective of someone coming to this with absolutely no past Rails testing experience and only a few months of RoR experience, here's what I saw when I started looking into stories for the first time at the beginning of the week... 1. the rspec.info home page begins with a description of how stories work in the old framework. 2. the most detailed information available on how to actually implement story-based testing applies to the old (or older) framework. In particular, the following were critical for me to get going (not all referenced on rspec.info) - http://blog.davidchelimsky.net/articles/2007/10/21/story-runner-in-plain-english http://blog.emson.co.uk/2008/06/understanding-rspec-stories-a-tutorial/ http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app http://www.vaporbase.com/postings/Beginners_Guide_to_Rspec_on_Story_Runner http://evang.eli.st/blog/2007/10/8/story-runner-top-to-bottom-screencast 3. David's 9/22 blog post (http://blog.davidchelimsky.net/) seemed to indicate that cucumber was for the future and suggested (to me) that it might be premature for mainstream use before Rails 2.2. 4. Aslak's story migration posting seemed to involve a whole bunch of new things I was going to have to learn (of course it doesn't really) So for me, just struggling to get my arms around how this thing works, Cucumber just looked like an unnecessary step too far. Of course I see now that it's not such a big deal, but that sure wasn't obvious at the start. Incidentally, I would not have come to RSpec at all had it not been for Obie Fernandez' book. Mark. Matt Wynne wrote: > Do we need to make it a bit clearer on the rspec.info site that > cucumber is the way forward? The trail of blog posts etc with the > up-to-date info is probably fairly bewildering to a newbie. > > On 9 Oct 2008, at 19:38, Mark Thomson wrote: > >> Thanks guys. I took your advice and moved to cucumber. It did turn >> out to be useful in that the more verbose error reporting led me to >> dive more deeply into the webrat source, eventually leading me to my >> problem - which actually was essentially the same noob error I made a >> few days when I failed to realize my development code had a data >> migration that hadn't populated the test db. >> >> In this case the updated form mentioned in my earlier post had >> selection inputs whose options are meant to be stored in the db. >> Since they weren't actually there, there were no select options in >> the form. >> >> What was puzzling initially was that an error related to selection >> inputs was showing up in the fills_in call. But it turns out that >> webrat looks for the named text field by searching over all the input >> tags in the form. In the process of parsing the selection inputs it >> was throwing up when it didn't find the option tags it was expecting. >> >> Mark. >> >> >> >> David Chelimsky wrote: >>> >>> On Thu, Oct 9, 2008 at 1:57 AM, Matt Wynne wrote: >>> >>>> On 9 Oct 2008, at 02:55, Mark Thomson wrote: >>>> >>>> >>>>> I have an RSpec story with an overall structure that looks >>>>> something like >>>>> this - >>>>> >>>>> ---- >>>>> Given the user is on the start page >>>>> When the user clicks the 'new' button >>>>> Then the 'new record' page should be displayed >>>>> >>>>> When the user fills in the form >>>>> And the user submits the form >>>>> Then the updated form should be displayed >>>>> >>>>> When the user fills in the updated form >>>>> And the user submits the form >>>>> Then a conformation message should be displayed >>>>> ---- >>>>> >>>>> In the last When step, I have a fills_in call that is failing with >>>>> the >>>>> following: >>>>> >>>>> ---- >>>>> NoMethodError: 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.attributes. >>>>> ---- >>>>> >>>>> I think the ActiveRecord thing is a red herring. Poking through >>>>> the Webrat >>>>> source code, it seems like the problem is more likely a failure to >>>>> find any >>>>> input fields. But I'm not sure why. Is there anything >>>>> inappropriate with the >>>>> way I've organized the story, stringing together multiple When-Then >>>>> segments? One thing that seems curious is that I have a completely >>>>> identical >>>>> fills_in call in the When step that precedes the one that is >>>>> failing and yet >>>>> that one runs without any problem. >>>>> >>>> I think this sort of error tends to happen while a view is being >>>> rendered, >>>> so my guess is it's something to do with your data setup. >>>> >>>> Sorry to bang on about this, but cucumber has much better support >>>> for error >>>> messages - you might want to consider making the switch before you >>>> waste too >>>> much time on this issue. >>>> >>> Matt is correct, you should definitely consider moving to cucumber, >>> though I don't know that cucumber will necessary help you shed any >>> more light on this particular issue. >>> >>> Mark, with the little bit of information you've provided, my best >>> guess would be that the :new action is providing some instance >>> variable that is not being provided by the :create action in the case >>> where the data from "When the user fills in the form" is incorrect or >>> insufficient to save the model. >>> >>> If that's not correct, please post the code for the steps and the >>> relevant controller actions. >>> >>> 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 mailing_lists at railsnewbie.com Fri Oct 10 09:46:08 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 10 Oct 2008 09:46:08 -0400 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> Message-ID: <0EBA4971-FBE3-413F-BB65-989CEF067846@railsnewbie.com> On Oct 10, 2008, at 2:56 AM, Mano ah wrote: > > > When i run a spec file i am getting the following error > > D:\Diwakar\spec_diwa\spec\controllers>spec sandbox_controller_spec.rb > > c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/lib/spec/api/sugar.rb: > 17:in > `method_ > missing': undefined method `describe' for main:Object (NoMethodError) > from ./sandbox_controller_spec.rb:7 > from > c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:28:in `ge > m_original_require' > from > c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:28:in `re > quire' > from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/bin/spec:13 > from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/bin/spec:7:in > `each' > from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/bin/spec:7 > from c:/ruby/bin/spec:19:in `load' > from c:/ruby/bin/spec:19 > > > > My spec controller is > > require File.dirname(__FILE__) + '/../spec_helper' What's in this file? > > #require './../../vendor/generators/rspec/lib/rspec_on_rails' You wont' need this. > > #require 'sandbox_controller.rb' You won't need this one, either > > require 'spec' Nor this > > gem 'rspec' Nor this. > > > describe SandboxController,"handling someaction" do > > it "should get real value 10" do > > get :someaction > > assigns[:value].should equal(10) > > end > > end > > > > My controller is > Why do you have a controller already? Scott From chris at cobaltedge.com Fri Oct 10 10:37:08 2008 From: chris at cobaltedge.com (Christopher Bailey) Date: Fri, 10 Oct 2008 07:37:08 -0700 Subject: [rspec-users] Need help using URL helpers in controller tests In-Reply-To: <5C8F5CA6-674A-4113-ACEB-AD7CD9EF518C@mattwynne.net> References: <443c240c0810091224p342a98c1i402aee02d2f9145f@mail.gmail.com> <5C8F5CA6-674A-4113-ACEB-AD7CD9EF518C@mattwynne.net> Message-ID: <443c240c0810100737k29b656act7b8032bd02147f62@mail.gmail.com> I've moved on from this with a bit different approach. But, I also found that the "get" (or whichever http method used) call expects the first parameter to be an action, so passing in a string that is a path or URL doesn't work for that. On Fri, Oct 10, 2008 at 1:04 AM, Matt Wynne wrote: > > On 9 Oct 2008, at 20:24, Christopher Bailey wrote: > > I have a controller test, where I want to do a GET on a page. Our URL's >> are complex, and need to be correct (duh, but we allow some slop, but that >> causes a redirect which I want to avoid). Anyway, in my controller test I >> do a get to the URL that is produced by a helper method which calls a named >> route URL helper. This is not working, and I'm wondering why/what I'm >> messing up. Here's the line in the spec code that starts things off >> (@widget is a real ActiveRecord object): >> >> get @controller.widget_path_for_seo(@widget) >> >> The widget_path_for_seo method is defined in our ApplicationController. >> It digs some info out of the widget instance that then get passed to the >> named route URL helper method, so it looks like this: >> >> def widget_path_for_seo(widget) >> location = seo_name_for_url widget.location.name >> building = seo_name_for_url(building_name_for_seo_url(widget.building), >> true) + "-widgets" >> widget_id = seo_name_for_url(widget.name) + "-" + widget.id.to_s >> >> seo_widget_path(:location => location, : building => building, :id => >> widget_id) >> end >> >> It's the "seo_widget_path" named route helper method that is failing. >> I've checked that all values going into it are valid, but the error I get >> is in ActionController::Base.url_for, where it's looking at the options hash >> of values that are passed in, and doing this: >> >> @url.rewrite(rewrite_options(options)) >> >> It compalins that @url is nil. I'm wondering if this is due to being run >> under the test environment or what I'm missing/not realizing, etc. What's >> strange is that some of the restful resource route url helpers work fine. >> Can anyone clue me in? >> >> -- >> Christopher Bailey >> Cobalt Edge LLC >> http://cobaltedge.com >> > > Quick thought - it doesn't look like you have 'spun' up the routes when you > test this method. If you haven't already made a get/post request through the > rails integration session infrastructure the named routes don't get loaded, > and that can be quite confusing. I'm not sure if that could be the cause of > your issue but I thought it was worth mentioning. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Fri Oct 10 11:20:01 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 10 Oct 2008 10:20:01 -0500 Subject: [rspec-users] fills_in NoMethodError In-Reply-To: References: <48ED64A7.3040407@ieee.org> <2552F40F-85BE-48D6-A71D-54368B39E29C@mattwynne.net> <57c63afe0810090334p3cb8e6b8xa16dae36a9f82e37@mail.gmail.com> <48EE4F9F.9060206@ieee.org> Message-ID: <57c63afe0810100820l50bb6fby2c9e88c0b772abb@mail.gmail.com> On Fri, Oct 10, 2008 at 3:05 AM, Matt Wynne wrote: > Do we need to make it a bit clearer on the rspec.info site that cucumber is > the way forward? The trail of blog posts etc with the up-to-date info is > probably fairly bewildering to a newbie. I updated the website (just a quick few tweaks). FYI - the website is in the rspec-dev project on github: http://github.com/dchelimsky/rspec-dev Please feel absolutely free at any time to contribute patches to this if you learn info that you think should be up there. Thanks, David > > On 9 Oct 2008, at 19:38, Mark Thomson wrote: > >> Thanks guys. I took your advice and moved to cucumber. It did turn out to >> be useful in that the more verbose error reporting led me to dive more >> deeply into the webrat source, eventually leading me to my problem - which >> actually was essentially the same noob error I made a few days when I failed >> to realize my development code had a data migration that hadn't populated >> the test db. >> >> In this case the updated form mentioned in my earlier post had selection >> inputs whose options are meant to be stored in the db. Since they weren't >> actually there, there were no select options in the form. >> >> What was puzzling initially was that an error related to selection inputs >> was showing up in the fills_in call. But it turns out that webrat looks for >> the named text field by searching over all the input tags in the form. In >> the process of parsing the selection inputs it was throwing up when it >> didn't find the option tags it was expecting. >> >> Mark. >> >> >> >> David Chelimsky wrote: >>> >>> On Thu, Oct 9, 2008 at 1:57 AM, Matt Wynne wrote: >>> >>>> On 9 Oct 2008, at 02:55, Mark Thomson wrote: >>>> >>>> >>>>> I have an RSpec story with an overall structure that looks something >>>>> like >>>>> this - >>>>> >>>>> ---- >>>>> Given the user is on the start page >>>>> When the user clicks the 'new' button >>>>> Then the 'new record' page should be displayed >>>>> >>>>> When the user fills in the form >>>>> And the user submits the form >>>>> Then the updated form should be displayed >>>>> >>>>> When the user fills in the updated form >>>>> And the user submits the form >>>>> Then a conformation message should be displayed >>>>> ---- >>>>> >>>>> In the last When step, I have a fills_in call that is failing with the >>>>> following: >>>>> >>>>> ---- >>>>> NoMethodError: 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.attributes. >>>>> ---- >>>>> >>>>> I think the ActiveRecord thing is a red herring. Poking through the >>>>> Webrat >>>>> source code, it seems like the problem is more likely a failure to find >>>>> any >>>>> input fields. But I'm not sure why. Is there anything inappropriate >>>>> with the >>>>> way I've organized the story, stringing together multiple When-Then >>>>> segments? One thing that seems curious is that I have a completely >>>>> identical >>>>> fills_in call in the When step that precedes the one that is failing >>>>> and yet >>>>> that one runs without any problem. >>>>> >>>> I think this sort of error tends to happen while a view is being >>>> rendered, >>>> so my guess is it's something to do with your data setup. >>>> >>>> Sorry to bang on about this, but cucumber has much better support for >>>> error >>>> messages - you might want to consider making the switch before you waste >>>> too >>>> much time on this issue. >>>> >>> Matt is correct, you should definitely consider moving to cucumber, >>> though I don't know that cucumber will necessary help you shed any >>> more light on this particular issue. >>> >>> Mark, with the little bit of information you've provided, my best >>> guess would be that the :new action is providing some instance >>> variable that is not being provided by the :create action in the case >>> where the data from "When the user fills in the form" is incorrect or >>> insufficient to save the model. >>> >>> If that's not correct, please post the code for the steps and the >>> relevant controller actions. >>> >>> 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 jgeiger at gmail.com Fri Oct 10 11:29:58 2008 From: jgeiger at gmail.com (Joey Geiger) Date: Fri, 10 Oct 2008 10:29:58 -0500 Subject: [rspec-users] Mocking Kernel.system or Kernel.` for external application calls Message-ID: <466af3440810100829y4734173euebdf51657e8e91aa@mail.gmail.com> I'm running into an issue while trying to test the execution of some external applications called from inside my models. class OmssaPacker def self.run_omssa_aws2ez2_unix(parameters) system("perl /pipeline/vipdac/lib/omssa_aws2ez2_unix.pl #{parameters}") end end ..spec code... describe "run omssa aws2ez2 unix" do it "should run the perl file" do Kernel.should_receive(:system).with(/omssa_aws2ez2_unix\.pl/).and_return(true) OmssaPacker.run_omssa_aws2ez2_unix("file").should be_true end end ...spec code... Returns: should run the perl file Mock 'Module' expected :system with (/omssa_aws2ez2_unix\.pl/) once, but received it 0 times And it also actually attempts to run the perl script, since I can see the output in the window. If I change the code to: def self.run_omssa_aws2ez2_unix(parameters) %x{ perl /pipeline/vipdac/lib/omssa_aws2ez2_unix.pl #{parameters} } end ...spec code... describe "run omssa aws2ez2 unix" do it "should run the perl file" do Kernel.should_receive(:`).with(/omssa_aws2ez2_unix\.pl/).and_return(true) OmssaPacker.run_omssa_aws2ez2_unix("file").should be_true end end ...spec code... Returns: should run the perl file expected true, got ""Program: omssa_aws2ez2.pl ...output from perl program about command line options..." It seems that the attempts to mock Kernel are being ignored and it's just running the scripts anyway. I'm guessing that I'm setting up the mock incorrectly, but I'm not sure how. I've also tried Kernel.stub!(:system).and_return(true) with the same results. From dchelimsky at gmail.com Fri Oct 10 11:40:36 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 10 Oct 2008 10:40:36 -0500 Subject: [rspec-users] Need help using URL helpers in controller tests In-Reply-To: <443c240c0810100737k29b656act7b8032bd02147f62@mail.gmail.com> References: <443c240c0810091224p342a98c1i402aee02d2f9145f@mail.gmail.com> <5C8F5CA6-674A-4113-ACEB-AD7CD9EF518C@mattwynne.net> <443c240c0810100737k29b656act7b8032bd02147f62@mail.gmail.com> Message-ID: <57c63afe0810100840g57efa6aer1e681c1aa8bcb3d9@mail.gmail.com> On Fri, Oct 10, 2008 at 9:37 AM, Christopher Bailey wrote: > I've moved on from this with a bit different approach. But, I also found > that the "get" (or whichever http method used) call expects the first > parameter to be an action, so passing in a string that is a path or URL > doesn't work for that. That is correct. rspec delegates the get, post, put, delete, etc methods off to rails. In the case of controller examples, they work like rails functional tests. In the case of stories/features, they work like rails integration tests (which work differently). > > On Fri, Oct 10, 2008 at 1:04 AM, Matt Wynne wrote: >> >> On 9 Oct 2008, at 20:24, Christopher Bailey wrote: >> >>> I have a controller test, where I want to do a GET on a page. Our URL's >>> are complex, and need to be correct (duh, but we allow some slop, but that >>> causes a redirect which I want to avoid). Anyway, in my controller test I >>> do a get to the URL that is produced by a helper method which calls a named >>> route URL helper. This is not working, and I'm wondering why/what I'm >>> messing up. Here's the line in the spec code that starts things off >>> (@widget is a real ActiveRecord object): >>> >>> get @controller.widget_path_for_seo(@widget) >>> >>> The widget_path_for_seo method is defined in our ApplicationController. >>> It digs some info out of the widget instance that then get passed to the >>> named route URL helper method, so it looks like this: >>> >>> def widget_path_for_seo(widget) >>> location = seo_name_for_url widget.location.name >>> building = >>> seo_name_for_url(building_name_for_seo_url(widget.building), true) + >>> "-widgets" >>> widget_id = seo_name_for_url(widget.name) + "-" + widget.id.to_s >>> >>> seo_widget_path(:location => location, : building => building, :id => >>> widget_id) >>> end >>> >>> It's the "seo_widget_path" named route helper method that is failing. >>> I've checked that all values going into it are valid, but the error I get >>> is in ActionController::Base.url_for, where it's looking at the options hash >>> of values that are passed in, and doing this: >>> >>> @url.rewrite(rewrite_options(options)) >>> >>> It compalins that @url is nil. I'm wondering if this is due to being run >>> under the test environment or what I'm missing/not realizing, etc. What's >>> strange is that some of the restful resource route url helpers work fine. >>> Can anyone clue me in? >>> >>> -- >>> Christopher Bailey >>> Cobalt Edge LLC >>> http://cobaltedge.com >> >> Quick thought - it doesn't look like you have 'spun' up the routes when >> you test this method. If you haven't already made a get/post request through >> the rails integration session infrastructure the named routes don't get >> loaded, and that can be quite confusing. I'm not sure if that could be the >> cause of your issue but I thought it was worth mentioning. >> _______________________________________________ >> 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 pergesu at gmail.com Fri Oct 10 12:06:43 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 10 Oct 2008 09:06:43 -0700 Subject: [rspec-users] Mocking Kernel.system or Kernel.` for external application calls In-Reply-To: <466af3440810100829y4734173euebdf51657e8e91aa@mail.gmail.com> (Joey Geiger's message of "Fri\, 10 Oct 2008 10\:29\:58 -0500") References: <466af3440810100829y4734173euebdf51657e8e91aa@mail.gmail.com> Message-ID: "Joey Geiger" writes: > I'm running into an issue while trying to test the execution of some > external applications called from inside my models. > > class OmssaPacker > def self.run_omssa_aws2ez2_unix(parameters) > system("perl /pipeline/vipdac/lib/omssa_aws2ez2_unix.pl #{parameters}") > end > end > > ..spec code... > describe "run omssa aws2ez2 unix" do > it "should run the perl file" do > Kernel.should_receive(:system).with(/omssa_aws2ez2_unix\.pl/).and_return(true) > OmssaPacker.run_omssa_aws2ez2_unix("file").should be_true > end > end > ...spec code... > > Returns: > should run the perl file > Mock 'Module' expected :system with (/omssa_aws2ez2_unix\.pl/) once, > but received it 0 times > > And it also actually attempts to run the perl script, since I can see > the output in the window. If I change the code to: > > def self.run_omssa_aws2ez2_unix(parameters) > %x{ perl /pipeline/vipdac/lib/omssa_aws2ez2_unix.pl #{parameters} } > end > > ...spec code... > describe "run omssa aws2ez2 unix" do > it "should run the perl file" do > Kernel.should_receive(:`).with(/omssa_aws2ez2_unix\.pl/).and_return(true) > OmssaPacker.run_omssa_aws2ez2_unix("file").should be_true > end > end > ...spec code... > > Returns: > should run the perl file > expected true, got ""Program: omssa_aws2ez2.pl ...output from perl > program about command line options..." > > It seems that the attempts to mock Kernel are being ignored and it's > just running the scripts anyway. I'm guessing that I'm setting up the > mock incorrectly, but I'm not sure how. > > I've also tried Kernel.stub!(:system).and_return(true) with the same results. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Hi Joey, In Ruby, any time you send a message without an explicit receiver, the message has an implicit receiver of 'self'. So from this we can infer that you don't want to stub Kernel#system, but rather OmssaPacker.system. The other side of the coin for understanding this is that while the method is defined in Kernel, it's not defined ON Kernel. Kernel is a module that's mixed into Object, so its methods are defined on all Objects. Kernel.should_receive(:system).with(/omssa_aws2ez2_unix\.pl/).and_return(true) is what you're looking for. Pat From pergesu at gmail.com Fri Oct 10 12:07:58 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 10 Oct 2008 09:07:58 -0700 Subject: [rspec-users] Mocking Kernel.system or Kernel.` for external application calls In-Reply-To: References: <466af3440810100829y4734173euebdf51657e8e91aa@mail.gmail.com> Message-ID: <810a540e0810100907x5fab5df5k787dcb6cedaa97f0@mail.gmail.com> > Kernel.should_receive(:system).with(/omssa_aws2ez2_unix\.pl/).and_return(true) > is what you're looking for. erm, that's a tad embarrasing :) I copy/pasted your line without editing it! It should be: OmssaPacker.should_receive(:system).with(/omssa_aws2ez2_unix\.pl/).and_return(true) Pat From jgeiger at gmail.com Fri Oct 10 13:54:57 2008 From: jgeiger at gmail.com (Joey Geiger) Date: Fri, 10 Oct 2008 12:54:57 -0500 Subject: [rspec-users] Mocking Kernel.system or Kernel.` for external application calls Message-ID: <466af3440810101054y75dede5ay38b22d5966636e46@mail.gmail.com> Thank you, it's now working as expected. I was basing the code on what I had seen before, with examples of people stubbing Kernel.system, so I wasn't thinking about just using the object itself. From luislavena at gmail.com Fri Oct 10 14:06:18 2008 From: luislavena at gmail.com (Luis Lavena) Date: Fri, 10 Oct 2008 15:06:18 -0300 Subject: [rspec-users] Solution for autospec not working In-Reply-To: References: <71166b3b0810092123h59c4e748j2275f71b17174c91@mail.gmail.com> Message-ID: <71166b3b0810101106t1b9cadeeg48bd1df618c626fb@mail.gmail.com> On Fri, Oct 10, 2008 at 8:12 AM, Dennis Sutch wrote: > My setup is similar, except I'm developing a Ruby script as opposed to a > Rails applications, thus no script/about output: > C:\Users\Dennis>ruby -v > ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] > C:\Users\Dennis>spec -v > rspec 1.1.8 > C:\Users\Dennis>gem list ZenTest > *** LOCAL GEMS *** > ZenTest (3.10.0) I had the same problem while developming my scripts. RSpec changed the way paths get loaded by autotest, so I'll suggest you create a mappins in your .autotest file similar to the one from rspec-rails, since seems the one in rspec no longer "maps" properly: http://github.com/dchelimsky/rspec/tree/master/lib/autotest/rspec.rb#L3-16 And this: http://github.com/dchelimsky/rspec-rails/tree/master/lib/autotest/rails_rspec.rb I cannot find my customized version (for a console based MVC, it's on backup now). Or maybe I'm missing the need to set AUTOTEST and RSPEC env variables first? HTH, -- 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 Fri Oct 10 15:40:57 2008 From: lists at ruby-forum.com (Anita Anita) Date: Fri, 10 Oct 2008 21:40:57 +0200 Subject: [rspec-users] private methode Message-ID: <791a037c68025c5d0b9cac30c9377325@ruby-forum.com> Hi, Can I test private methods directly? Or should I pass by the methods that are calling these private methods? Or can I make the method private after testing? What is the best way? Thank you -- Posted via http://www.ruby-forum.com/. From hayafirst at gmail.com Fri Oct 10 16:07:49 2008 From: hayafirst at gmail.com (Yi Wen) Date: Fri, 10 Oct 2008 15:07:49 -0500 Subject: [rspec-users] private methode In-Reply-To: <791a037c68025c5d0b9cac30c9377325@ruby-forum.com> References: <791a037c68025c5d0b9cac30c9377325@ruby-forum.com> Message-ID: IMHO, one should never directly test a private method. So I prefer the second way you mentioned in your email. Better yet, think of why you want to test a private method. Is it too complicated? If this is the case, way too often this private method should not really belong to the class it's currently in. This class might be doing too much and this private method is not part of core functionality this class provides (or else it should be made public as part of the class's interface). So you may want to refactor the code to find a proper home for your private method and make it public in that class and you can unit testing this new public method. Yi On Fri, Oct 10, 2008 at 2:40 PM, Anita Anita wrote: > Hi, > > Can I test private methods directly? > Or should I pass by the methods that are calling these private methods? > Or can I make the method private after testing? > What is the best way? > > Thank you > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Fri Oct 10 16:12:57 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 10 Oct 2008 13:12:57 -0700 Subject: [rspec-users] private methode In-Reply-To: <791a037c68025c5d0b9cac30c9377325@ruby-forum.com> (Anita Anita's message of "Fri\, 10 Oct 2008 21\:40\:57 +0200") References: <791a037c68025c5d0b9cac30c9377325@ruby-forum.com> Message-ID: Anita Anita writes: > Hi, > > Can I test private methods directly? > Or should I pass by the methods that are calling these private methods? > Or can I make the method private after testing? > What is the best way? > > Thank you The party line is not to test private methods. Either test them indirectly via a public method, or extract it to a separate object and make it public there. Pat From lists at ruby-forum.com Fri Oct 10 16:18:25 2008 From: lists at ruby-forum.com (Anita Anita) Date: Fri, 10 Oct 2008 22:18:25 +0200 Subject: [rspec-users] private methode In-Reply-To: References: <791a037c68025c5d0b9cac30c9377325@ruby-forum.com> Message-ID: <3f58f79a08e973a08fab48888a75a3f1@ruby-forum.com> Well, it's a methods for buying with credit card info and everything. So I wanted to test it to make sure that all my code works but I can't make it public. -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Fri Oct 10 18:00:41 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 10 Oct 2008 23:00:41 +0100 Subject: [rspec-users] private methode In-Reply-To: <3f58f79a08e973a08fab48888a75a3f1@ruby-forum.com> References: <791a037c68025c5d0b9cac30c9377325@ruby-forum.com> <3f58f79a08e973a08fab48888a75a3f1@ruby-forum.com> Message-ID: <0C69E061-E688-4743-B31B-25A587C8EEF2@mattwynne.net> On 10 Oct 2008, at 21:18, Anita Anita wrote: > but I can't make it public. Why not? Who are you afraid is going to call it that shouldn't? From lists at ruby-forum.com Fri Oct 10 23:16:10 2008 From: lists at ruby-forum.com (Mano ah) Date: Sat, 11 Oct 2008 05:16:10 +0200 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <0EBA4971-FBE3-413F-BB65-989CEF067846@railsnewbie.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> <0EBA4971-FBE3-413F-BB65-989CEF067846@railsnewbie.com> Message-ID: <044e3118d73486a9386fc477da8ccdc2@ruby-forum.com> Dear Scott, I am new to rspec and i am confused to test using it. Can you please help me with an easy example or link to get clear about it Regards M -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Oct 10 23:50:15 2008 From: lists at ruby-forum.com (Mano ah) Date: Sat, 11 Oct 2008 05:50:15 +0200 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <044e3118d73486a9386fc477da8ccdc2@ruby-forum.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> <0EBA4971-FBE3-413F-BB65-989CEF067846@railsnewbie.com> <044e3118d73486a9386fc477da8ccdc2@ruby-forum.com> Message-ID: <9a901b3aa204e0c355d31f933fef318e@ruby-forum.com> How to solve the below error 1) NoMethodError in 'LoginController index should get successfully' You have a nil object when you didn't expect it! The error occurred while evaluating nil.status ./login_controller_spec.rb:9: 2) NoMethodError in 'LoginController index should render 202 file' undefined method `render_template' for # ./login_controller_spec.rb:13: Finished in 0.437 seconds -- Posted via http://www.ruby-forum.com/. From mailing_lists at railsnewbie.com Sat Oct 11 00:01:16 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 11 Oct 2008 00:01:16 -0400 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <9a901b3aa204e0c355d31f933fef318e@ruby-forum.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> <0EBA4971-FBE3-413F-BB65-989CEF067846@railsnewbie.com> <044e3118d73486a9386fc477da8ccdc2@ruby-forum.com> <9a901b3aa204e0c355d31f933fef318e@ruby-forum.com> Message-ID: <443E3E29-2836-4E71-9C6D-0C3C3F62F29D@railsnewbie.com> On Oct 10, 2008, at 11:50 PM, Mano ah wrote: > How to solve the below error > > 1) > NoMethodError in 'LoginController index should get successfully' > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.status > ./login_controller_spec.rb:9: > > 2) > NoMethodError in 'LoginController index should render 202 file' > undefined method `render_template' for > # :0x47bc128> > ./login_controller_spec.rb:13: Looks like you're writing controller specs. Have you checked out the rspec site? Specifically: http://rspec.info/documentation/rails/writing/controllers.html Scott From mailing_lists at railsnewbie.com Sat Oct 11 00:08:47 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 11 Oct 2008 00:08:47 -0400 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <9a901b3aa204e0c355d31f933fef318e@ruby-forum.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> <0EBA4971-FBE3-413F-BB65-989CEF067846@railsnewbie.com> <044e3118d73486a9386fc477da8ccdc2@ruby-forum.com> <9a901b3aa204e0c355d31f933fef318e@ruby-forum.com> Message-ID: On Oct 10, 2008, at 11:50 PM, Mano ah wrote: > How to solve the below error > > 1) > NoMethodError in 'LoginController index should get successfully' > You have a nil object when you didn't expect it! > The error occurred while evaluating nil.status > ./login_controller_spec.rb:9: > > 2) > NoMethodError in 'LoginController index should render 202 file' > undefined method `render_template' for > # :0x47bc128> > ./login_controller_spec.rb:13: "Spec::Example::ExampleGroup::Subclass_1" - this part suggests it's not running as a controller spec. A few things: 1. Is the file in correct path? It should be in the path #{RAILS_ROOT}/spec/controller/my_controller_spec.rb 2. Have you installed the two plugins, and run "script/generate rspec" ? 3. (I don't recommend this, but:) You can force this to run as a controller spec by passing a :type => :controller to describe, like so: describe "my controller", :type => :controller do ... end 4. Worse comes to worse, try running the generator to get some example code: ./script/generate rspec_controller MyController That should generate a sample spec. You could work from there. Hope that helps, Scott From lists at ruby-forum.com Sat Oct 11 00:42:36 2008 From: lists at ruby-forum.com (Mano ah) Date: Sat, 11 Oct 2008 06:42:36 +0200 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <443E3E29-2836-4E71-9C6D-0C3C3F62F29D@railsnewbie.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> <0EBA4971-FBE3-413F-BB65-989CEF067846@railsnewbie.com> <044e3118d73486a9386fc477da8ccdc2@ruby-forum.com> <9a901b3aa204e0c355d31f933fef318e@ruby-forum.com> <443E3E29-2836-4E71-9C6D-0C3C3F62F29D@railsnewbie.com> Message-ID: <354e7cc511345cace0a752ff1855d7ba@ruby-forum.com> rails 2.1.1 and rspec 1.1.8 never worked out for me So i downgraded rails to 1.2.3. while execiting ruby /script/generate rspec_controller MyController it ask rails version 2.1.1. i was getting the describe method error as mention earlier in using 2.1.1 -- Posted via http://www.ruby-forum.com/. From mailing_lists at railsnewbie.com Sat Oct 11 00:53:07 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 11 Oct 2008 00:53:07 -0400 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <354e7cc511345cace0a752ff1855d7ba@ruby-forum.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> <0EBA4971-FBE3-413F-BB65-989CEF067846@railsnewbie.com> <044e3118d73486a9386fc477da8ccdc2@ruby-forum.com> <9a901b3aa204e0c355d31f933fef318e@ruby-forum.com> <443E3E29-2836-4E71-9C6D-0C3C3F62F29D@railsnewbie.com> <354e7cc511345cace0a752ff1855d7ba@ruby-forum.com> Message-ID: <6293EA14-3E1F-4C4C-B102-54ED2CEF3217@railsnewbie.com> On Oct 11, 2008, at 12:42 AM, Mano ah wrote: > rails 2.1.1 and rspec 1.1.8 never worked out for me > > So i downgraded rails to 1.2.3. > > while execiting ruby /script/generate rspec_controller MyController > > it ask rails version 2.1.1. > > > i was getting the describe method error as mention earlier in using > 2.1.1 Why don't you post your spec? It would be a lot easier to help if we could look at the same thing you were looking at. Scott From lists at ruby-forum.com Sat Oct 11 01:12:10 2008 From: lists at ruby-forum.com (Mano ah) Date: Sat, 11 Oct 2008 07:12:10 +0200 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <6293EA14-3E1F-4C4C-B102-54ED2CEF3217@railsnewbie.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> <0EBA4971-FBE3-413F-BB65-989CEF067846@railsnewbie.com> <044e3118d73486a9386fc477da8ccdc2@ruby-forum.com> <9a901b3aa204e0c355d31f933fef318e@ruby-forum.com> <443E3E29-2836-4E71-9C6D-0C3C3F62F29D@railsnewbie.com> <354e7cc511345cace0a752ff1855d7ba@ruby-forum.com> <6293EA14-3E1F-4C4C-B102-54ED2CEF3217@railsnewbie.com> Message-ID: Scott Taylor wrote: > On Oct 11, 2008, at 12:42 AM, Mano ah wrote: > >> 2.1.1 > Why don't you post your spec? It would be a lot easier to help if we > could look at the same thing you were looking at. > > Scott sorry spec? -- Posted via http://www.ruby-forum.com/. From luislavena at gmail.com Sat Oct 11 01:25:34 2008 From: luislavena at gmail.com (Luis Lavena) Date: Sat, 11 Oct 2008 02:25:34 -0300 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> Message-ID: <71166b3b0810102225m71e0742ej9b4d0383ca57fbfc@mail.gmail.com> On Fri, Oct 10, 2008 at 3:56 AM, Mano ah wrote: > > > When i run a spec file i am getting the following error > > D:\Diwakar\spec_diwa\spec\controllers>spec sandbox_controller_spec.rb > c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/lib/spec/api/sugar.rb:17:in > `method_ > missing': undefined method `describe' for main:Object (NoMethodError) > from ./sandbox_controller_spec.rb:7 > from > c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:28:in `ge > m_original_require' > from > c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:28:in `re > quire' > from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/bin/spec:13 > from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/bin/spec:7:in > `each' > from c:/ruby/lib/ruby/gems/1.8/gems/rspec-0.5.15/bin/spec:7 > from c:/ruby/bin/spec:19:in `load' > from c:/ruby/bin/spec:19 > > > > My spec controller is > > require File.dirname(__FILE__) + '/../spec_helper' > #require './../../vendor/generators/rspec/lib/rspec_on_rails' > #require 'sandbox_controller.rb' > require 'spec' > gem 'rspec' > > describe SandboxController,"handling someaction" do > > it "should get real value 10" do > > get :someaction > > assigns[:value].should equal(10) > > end > > end > > > > My controller is > > > > class SandboxController < ApplicationController > > def someaction > > @value = somemethod > > end > > > protected > > > def somemethod > > return 10 > > end > > end > > Please help me to solve the issue > Sorry, jumping late on this issue. It appears you're calling 'spec' from the command line, which is loading your installed gem of RSpec. Based on the output of the backtrace, it appears to be version 0.5.15 You should have used "ruby script/spec" from the root of your rails application instead. Also, if you changed versions of Rails, you need to update config/environment.rb to match the Rails gem version since you downgraded to 1.2.3 but forgot to change that file. I suggest you do this: gem install rake gem install rails gem install rspec gem install rspec-rails rails my-test-app cd my-test-app ruby script/generate rspec rake spec That, at least, should work and not generate empty errors (well, I've skipped database setup, controller and such, please add those after). HTH, -- 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 Sat Oct 11 02:44:11 2008 From: lists at ruby-forum.com (Mano ah) Date: Sat, 11 Oct 2008 08:44:11 +0200 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <71166b3b0810102225m71e0742ej9b4d0383ca57fbfc@mail.gmail.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> <71166b3b0810102225m71e0742ej9b4d0383ca57fbfc@mail.gmail.com> Message-ID: Luis Lavena wrote: > On Fri, Oct 10, 2008 at 3:56 AM, Mano ah wrote: >> c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:28:in `ge >> >> describe SandboxController,"handling someaction" do >> >> @value = somemethod >> >> end >> >> end >> >> Please help me to solve the issue >> > > Sorry, jumping late on this issue. > > It appears you're calling 'spec' from the command line, which is > loading your installed gem of RSpec. > > Based on the output of the backtrace, it appears to be version 0.5.15 > > You should have used "ruby script/spec" from the root of your rails > application instead. Thank you for the reply. I done the same and got the below error ** Invoke spec (first_time) ** Execute spec ** Invoke spec:models (first_time) ** Invoke db:test:prepare (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:test:prepare ** Invoke db:test:clone (first_time) ** Invoke db:schema:dump (first_time) ** Invoke environment ** Execute db:schema:dump ** Invoke spec:controllers (first_time) ** Invoke db:test:prepare ** Execute spec:controllers rake aborted! RSpec failures D:/Diwakar/my_spec/config/../lib/tasks/rspec.rake:13 c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `execute' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `each' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `execute' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in `invoke_with_call_c hain' c:/ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in `invoke_with_call_c hain' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in `invoke' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in `invoke_task' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `each' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard_exceptio n_handling' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in `top_level' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in `run' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard_exceptio n_handling' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in `run' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/bin/rake:31 c:/ruby/bin/rake:19:in `load' c:/ruby/bin/rake:19 > > Also, if you changed versions of Rails, you need to update > config/environment.rb to match the Rails gem version since you > downgraded to 1.2.3 but forgot to change that file. > > I suggest you do this: > > gem install rake > gem install rails > gem install rspec > gem install rspec-rails > > rails my-test-app > cd my-test-app > ruby script/generate rspec > rake spec > > That, at least, should work and not generate empty errors (well, I've > skipped database setup, controller and such, please add those after). > > HTH, > -- > 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 -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sat Oct 11 02:53:27 2008 From: lists at ruby-forum.com (Mano ah) Date: Sat, 11 Oct 2008 08:53:27 +0200 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> <71166b3b0810102225m71e0742ej9b4d0383ca57fbfc@mail.gmail.com> Message-ID: <2bb3db95858f6d430edaac53600a8693@ruby-forum.com> my gem list is actionmailer (2.1.1, 1.3.3) actionpack (2.1.1, 1.13.3) actionwebservice (1.2.3) activerecord (2.1.1, 1.15.3) activeresource (2.1.1) activesupport (2.1.1, 1.4.2) fxri (0.3.6) fxruby (1.6.12) hoe (1.7.0) hpricot (0.6) log4r (1.0.5) rails (1.2.3) rake (0.8.3) rspec (1.1.8, 0.5.15) rspec-rails (1.1.8) rspec_generator (0.5.15) rubyforge (1.0.0) sources (0.0.1) win32-api (1.0.4) win32-clipboard (0.4.3) win32-dir (0.3.2) win32-eventlog (0.4.6) win32-file (0.5.4) win32-file-stat (1.2.7) win32-process (0.5.3) win32-sapi (0.1.4) win32-sound (0.4.1) win32console (1.1.0) windows-api (0.2.0) windows-pr (0.7.2) ZenTest (3.10.0) D:\Diwakar\my_spec> -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Sat Oct 11 06:44:34 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 11 Oct 2008 03:44:34 -0700 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <2bb3db95858f6d430edaac53600a8693@ruby-forum.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> <71166b3b0810102225m71e0742ej9b4d0383ca57fbfc@mail.gmail.com> <2bb3db95858f6d430edaac53600a8693@ruby-forum.com> Message-ID: <810a540e0810110344x436b82c0u3ab7e5574b4a8dd9@mail.gmail.com> Dude, post your code On 10/10/08, Mano ah wrote: > my gem list is > > > > actionmailer (2.1.1, 1.3.3) > actionpack (2.1.1, 1.13.3) > actionwebservice (1.2.3) > activerecord (2.1.1, 1.15.3) > activeresource (2.1.1) > activesupport (2.1.1, 1.4.2) > fxri (0.3.6) > fxruby (1.6.12) > hoe (1.7.0) > hpricot (0.6) > log4r (1.0.5) > rails (1.2.3) > rake (0.8.3) > rspec (1.1.8, 0.5.15) > rspec-rails (1.1.8) > rspec_generator (0.5.15) > rubyforge (1.0.0) > sources (0.0.1) > win32-api (1.0.4) > win32-clipboard (0.4.3) > win32-dir (0.3.2) > win32-eventlog (0.4.6) > win32-file (0.5.4) > win32-file-stat (1.2.7) > win32-process (0.5.3) > win32-sapi (0.1.4) > win32-sound (0.4.1) > win32console (1.1.0) > windows-api (0.2.0) > windows-pr (0.7.2) > ZenTest (3.10.0) > > D:\Diwakar\my_spec> > -- > 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 Sat Oct 11 06:59:14 2008 From: lists at ruby-forum.com (Mano ah) Date: Sat, 11 Oct 2008 12:59:14 +0200 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <810a540e0810110344x436b82c0u3ab7e5574b4a8dd9@mail.gmail.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> <71166b3b0810102225m71e0742ej9b4d0383ca57fbfc@mail.gmail.com> <2bb3db95858f6d430edaac53600a8693@ruby-forum.com> <810a540e0810110344x436b82c0u3ab7e5574b4a8dd9@mail.gmail.com> Message-ID: <53fd14af37b7ce34bd359f9b0d054f1a@ruby-forum.com> I followed the below ways of installation gem install rake gem install rails gem install rspec gem install rspec-rails rails my-test-app cd my-test-app ruby script/generate rspec When i used 'rake spec' i received no error. After that I created a controller then installed the two plugins ruby script/plugin install http://rspec.rubyforge.org/svn/tags/CURRENT/rspec ruby script/plugin install http://rspec.rubyforge.org/svn/tags/CURRENT/rspec_on_rails Then i used 'ruby script/generate rspec_scaffold myspec_con' which created the spec for the controller,model etc Then i used the below command to run the spec file and received the below error D:\Diwakar\my_spec\spec>ruby script/spec controllers/myspec_cons_controller_spec .rb ruby: No such file or directory -- script/spec (LoadError) Please give your suggestions -- Posted via http://www.ruby-forum.com/. From luislavena at gmail.com Sat Oct 11 11:16:19 2008 From: luislavena at gmail.com (Luis Lavena) Date: Sat, 11 Oct 2008 12:16:19 -0300 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <53fd14af37b7ce34bd359f9b0d054f1a@ruby-forum.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> <71166b3b0810102225m71e0742ej9b4d0383ca57fbfc@mail.gmail.com> <2bb3db95858f6d430edaac53600a8693@ruby-forum.com> <810a540e0810110344x436b82c0u3ab7e5574b4a8dd9@mail.gmail.com> <53fd14af37b7ce34bd359f9b0d054f1a@ruby-forum.com> Message-ID: <71166b3b0810110816k8649cb8h87cd39499885f8f9@mail.gmail.com> On Sat, Oct 11, 2008 at 7:59 AM, Mano ah wrote: > > I followed the below ways of installation > > > gem install rake > gem install rails > gem install rspec > gem install rspec-rails > > rails my-test-app > cd my-test-app > ruby script/generate rspec > > > When i used > > 'rake spec' > > i received no error. > > After that I created a controller > > then installed the two plugins > > ruby script/plugin install > http://rspec.rubyforge.org/svn/tags/CURRENT/rspec > ruby script/plugin install > http://rspec.rubyforge.org/svn/tags/CURRENT/rspec_on_rails > You're pulling a old SVN repository, latest releases are distributed through Git repo, please see the install instructions in the website: http://rspec.info > Then i used 'ruby script/generate rspec_scaffold myspec_con' which > created the spec for the controller,model etc > > Then i used the below command to run the spec file and received the > below error > > D:\Diwakar\my_spec\spec>ruby script/spec > controllers/myspec_cons_controller_spec > .rb > ruby: No such file or directory -- script/spec (LoadError) > > Please give your suggestions > You forgot to: ruby script/generate rspec This is required for rspec to work, it generates the needed files in script and also spec folder to make RSpec work. Please do that and then try executing ruby script/spec. FYI: There are plenty of tutorials around the web that explain how to get started with RSpec. I guess english is not your main language and can be difficult to search for it, but: google with keywords "rspec rails getting started": http://www.jbrains.ca/permalink/127 http://github.com/dchelimsky/rspec-rails/wikis HTH, -- 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 dchelimsky at gmail.com Sat Oct 11 11:42:05 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 11 Oct 2008 10:42:05 -0500 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <71166b3b0810110816k8649cb8h87cd39499885f8f9@mail.gmail.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> <71166b3b0810102225m71e0742ej9b4d0383ca57fbfc@mail.gmail.com> <2bb3db95858f6d430edaac53600a8693@ruby-forum.com> <810a540e0810110344x436b82c0u3ab7e5574b4a8dd9@mail.gmail.com> <53fd14af37b7ce34bd359f9b0d054f1a@ruby-forum.com> <71166b3b0810110816k8649cb8h87cd39499885f8f9@mail.gmail.com> Message-ID: <57c63afe0810110842p1200b0b2x49151642ed5d30f7@mail.gmail.com> On Sat, Oct 11, 2008 at 10:16 AM, Luis Lavena wrote: > On Sat, Oct 11, 2008 at 7:59 AM, Mano ah wrote: >> >> I followed the below ways of installation >> >> >> gem install rake >> gem install rails >> gem install rspec >> gem install rspec-rails >> >> rails my-test-app >> cd my-test-app >> ruby script/generate rspec >> >> >> When i used >> >> 'rake spec' >> >> i received no error. >> >> After that I created a controller >> >> then installed the two plugins >> >> ruby script/plugin install >> http://rspec.rubyforge.org/svn/tags/CURRENT/rspec >> ruby script/plugin install >> http://rspec.rubyforge.org/svn/tags/CURRENT/rspec_on_rails >> > > You're pulling a old SVN repository, latest releases are distributed > through Git repo, please see the install instructions in the website: I just blew away the contents of CURRENT, leaving a README that points to relevant information: http://rspec.rubyforge.org/svn/tags/CURRENT/README So this confusion over CURRENT should no longer be a problem :) > > http://rspec.info > >> Then i used 'ruby script/generate rspec_scaffold myspec_con' which >> created the spec for the controller,model etc >> >> Then i used the below command to run the spec file and received the >> below error >> >> D:\Diwakar\my_spec\spec>ruby script/spec >> controllers/myspec_cons_controller_spec >> .rb >> ruby: No such file or directory -- script/spec (LoadError) >> >> Please give your suggestions >> > > You forgot to: > > ruby script/generate rspec > > This is required for rspec to work, it generates the needed files in > script and also spec folder to make RSpec work. > > Please do that and then try executing ruby script/spec. > > FYI: There are plenty of tutorials around the web that explain how to > get started with RSpec. I guess english is not your main language and > can be difficult to search for it, but: > > google with keywords "rspec rails getting started": > > http://www.jbrains.ca/permalink/127 > http://github.com/dchelimsky/rspec-rails/wikis > > HTH, > -- > 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 nick at deadorange.com Sat Oct 11 17:19:25 2008 From: nick at deadorange.com (Nick Hoffman) Date: Sat, 11 Oct 2008 17:19:25 -0400 Subject: [rspec-users] How to improve this spec Message-ID: <3EDC7B43-F40B-4A33-A692-4E6CC948A9D9@deadorange.com> Hi guys. One of my specs is very weak, and I'd really like to improve it. Lines 111-116 are what I'm having trouble speccing, and depend on lines 105-109. 105 # Grab all of the properties, filtering using the given conditions. 106 @properties = Property.find :all, :conditions => [ 107 processed_conditions[:conditions_string], 108 processed_conditions[:conditions_hash] 109 ] 110 111 # Generate a table of properties to list. 112 @property_data = render_to_string( 113 :partial => 'properties/map_properties_table', 114 :collection => @properties, 115 :locals => {:index_of_last_row => @properties.size} 116 ) 117 118 @number_of_properties_found_sentence = render_to_string :partial => 'properties/number_of_properties_found' My spec for lines 104-108 are fine. Below is what I have for 111-16, which I'd like to improve: 498 it "should render the 'map_properties_table' partial" do 499 pending 500 controller.should_receive(:render_to_string).with(any_args()).twice 501 do_xhr @params 502 end Specifically, I'd like to improve what's passed to #with . However, my specs don't have the variable "@properties", so I'm not sure how to go about this. Any suggestions? I'm all ears! Thanks, Nick From mark at mwilden.com Sat Oct 11 17:31:22 2008 From: mark at mwilden.com (Mark Wilden) Date: Sat, 11 Oct 2008 14:31:22 -0700 Subject: [rspec-users] How to improve this spec In-Reply-To: <3EDC7B43-F40B-4A33-A692-4E6CC948A9D9@deadorange.com> References: <3EDC7B43-F40B-4A33-A692-4E6CC948A9D9@deadorange.com> Message-ID: <3c30da400810111431v1fc12b31p706d265b39ed675e@mail.gmail.com> On Sat, Oct 11, 2008 at 2:19 PM, Nick Hoffman wrote: > Hi guys. One of my specs is very weak, and I'd really like to improve it. > > Lines 111-116 are what I'm having trouble speccing, and depend on lines > 105-109. > > 105 # Grab all of the properties, filtering using the given > conditions. > 106 @properties = Property.find :all, :conditions => [ > 107 processed_conditions[:conditions_string], > 108 processed_conditions[:conditions_hash] > 109 ] > 110 > 111 # Generate a table of properties to list. > 112 @property_data = render_to_string( > 113 :partial => 'properties/map_properties_table', > 114 :collection => @properties, > 115 :locals => {:index_of_last_row => @properties.size} > 116 ) > 117 > 118 @number_of_properties_found_sentence = render_to_string :partial > => 'properties/number_of_properties_found' > > > My spec for lines 104-108 are fine. Below is what I have for 111-16, which > I'd like to improve: > > 498 it "should render the 'map_properties_table' partial" do > 499 pending > 500 > controller.should_receive(:render_to_string).with(any_args()).twice > 501 do_xhr @params > 502 end > > Specifically, I'd like to improve what's passed to #with . However, my > specs don't have the variable "@properties" If you mocked the Property.find call, you'd have @properties. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From dennis at sutch.com Sat Oct 11 23:41:58 2008 From: dennis at sutch.com (Dennis Sutch) Date: Sat, 11 Oct 2008 23:41:58 -0400 Subject: [rspec-users] Solution for autospec not working In-Reply-To: <71166b3b0810101106t1b9cadeeg48bd1df618c626fb@mail.gmail.com> References: <71166b3b0810092123h59c4e748j2275f71b17174c91@mail.gmail.com> <71166b3b0810101106t1b9cadeeg48bd1df618c626fb@mail.gmail.com> Message-ID: Luis, As you suggested, I created the mappings and autotest is now working as expected. Thank you for your help. -- Dennis Sutch dennis at sutch.com On Fri, Oct 10, 2008 at 2:06 PM, Luis Lavena wrote: > On Fri, Oct 10, 2008 at 8:12 AM, Dennis Sutch wrote: > > My setup is similar, except I'm developing a Ruby script as opposed to a > > Rails applications, thus no script/about output: > > C:\Users\Dennis>ruby -v > > ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] > > C:\Users\Dennis>spec -v > > rspec 1.1.8 > > C:\Users\Dennis>gem list ZenTest > > *** LOCAL GEMS *** > > ZenTest (3.10.0) > > I had the same problem while developming my scripts. > > RSpec changed the way paths get loaded by autotest, so I'll suggest > you create a mappins in your .autotest file similar to the one from > rspec-rails, since seems the one in rspec no longer "maps" properly: > > http://github.com/dchelimsky/rspec/tree/master/lib/autotest/rspec.rb#L3-16 > > And this: > > > http://github.com/dchelimsky/rspec-rails/tree/master/lib/autotest/rails_rspec.rb > > I cannot find my customized version (for a console based MVC, it's on > backup now). > > Or maybe I'm missing the need to set AUTOTEST and RSPEC env variables > first? > > HTH, > -- > 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 Sat Oct 11 23:47:47 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 12 Oct 2008 01:47:47 -0200 Subject: [rspec-users] Solution for autospec not working In-Reply-To: References: <71166b3b0810092123h59c4e748j2275f71b17174c91@mail.gmail.com> <71166b3b0810101106t1b9cadeeg48bd1df618c626fb@mail.gmail.com> Message-ID: <57c63afe0810112047j63ca120epc481f8e02bec00c@mail.gmail.com> On Sun, Oct 12, 2008 at 1:41 AM, Dennis Sutch wrote: > Luis, > As you suggested, I created the mappings and autotest is now working as > expected. Thank you for your help. Yes, Luis. Thank you, as always! Cheers, David > -- > Dennis Sutch > dennis at sutch.com > > > On Fri, Oct 10, 2008 at 2:06 PM, Luis Lavena wrote: >> >> On Fri, Oct 10, 2008 at 8:12 AM, Dennis Sutch wrote: >> > My setup is similar, except I'm developing a Ruby script as opposed to a >> > Rails applications, thus no script/about output: >> > C:\Users\Dennis>ruby -v >> > ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] >> > C:\Users\Dennis>spec -v >> > rspec 1.1.8 >> > C:\Users\Dennis>gem list ZenTest >> > *** LOCAL GEMS *** >> > ZenTest (3.10.0) >> >> I had the same problem while developming my scripts. >> >> RSpec changed the way paths get loaded by autotest, so I'll suggest >> you create a mappins in your .autotest file similar to the one from >> rspec-rails, since seems the one in rspec no longer "maps" properly: >> >> http://github.com/dchelimsky/rspec/tree/master/lib/autotest/rspec.rb#L3-16 >> >> And this: >> >> >> http://github.com/dchelimsky/rspec-rails/tree/master/lib/autotest/rails_rspec.rb >> >> I cannot find my customized version (for a console based MVC, it's on >> backup now). >> >> Or maybe I'm missing the need to set AUTOTEST and RSPEC env variables >> first? >> >> HTH, >> -- >> 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 O.Frabjous.Dey at gmail.com Sun Oct 12 22:33:33 2008 From: O.Frabjous.Dey at gmail.com (O. Frabjous-Dey) Date: Sun, 12 Oct 2008 19:33:33 -0700 Subject: [rspec-users] Checking that a controller created a separate model object Message-ID: <177dcc160810121933vc8f5218yc668b749800f9d0c@mail.gmail.com> Hi everyone, RSpec newbie here. I'm looking forward to interacting with the community as I learn more about TDD, RSpec, Rails, and... TDD through RSpec in Rails. Having watched the Peepcode screencasts and read a lot of documentation, I'm trying to write my first comprehensive applications using TDD from the ground up. I'm stuck writing a test for my controller, though. This application is your basic crappy social network. There are three relevant models in play right now: User, Group, and Membership. User and Group have :has_many relationships with each other :through Membership; Membership, in addition to having a user_id and a group_id, also has a column called "rank", to which I write in either "officer" or "member" as a value. Group also defines the following relationships just for convenience: has_many :memberships has_many :officers, :through => :memberships, :source => :user, :conditions => "rank = 'officer'" has_many :members, :through => :memberships, :source => :user, :conditions => "rank = 'member'" I'm trying to test the CREATE functionality in my Group controller. Unfortunately, this test is not working. it "should make the creating user an officer" do Group.stub!(:new).and_return(mock_group(:save => true)) post :create, :group => {} assigns[:group].should have(1).officer end The error message: Mock 'Group_1008' received unexpected message :officer with (no args) If I understand this correctly, I am getting the error because assigns[:group] isn't really an ActiveRecord object, just a mock, and I guess the relationships don't carry over? If this is the case, what's the right way to test it, assuming that a Membership really is being created in my controller's create function? Thanks, O. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at deadorange.com Sun Oct 12 23:21:37 2008 From: nick at deadorange.com (Nick Hoffman) Date: Sun, 12 Oct 2008 23:21:37 -0400 Subject: [rspec-users] How to improve this spec In-Reply-To: <3c30da400810111431v1fc12b31p706d265b39ed675e@mail.gmail.com> References: <3EDC7B43-F40B-4A33-A692-4E6CC948A9D9@deadorange.com> <3c30da400810111431v1fc12b31p706d265b39ed675e@mail.gmail.com> Message-ID: On 2008-10-11, at 17:31, Mark Wilden wrote: > If you mocked the Property.find call, you'd have @properties. Hah, good point. Apologies for the obvious question. Cheers, Nick From nick at deadorange.com Sun Oct 12 23:33:43 2008 From: nick at deadorange.com (Nick Hoffman) Date: Sun, 12 Oct 2008 23:33:43 -0400 Subject: [rspec-users] Checking that a controller created a separate model object In-Reply-To: <177dcc160810121933vc8f5218yc668b749800f9d0c@mail.gmail.com> References: <177dcc160810121933vc8f5218yc668b749800f9d0c@mail.gmail.com> Message-ID: On 2008-10-12, at 22:33, O. Frabjous-Dey wrote: > Hi everyone, RSpec newbie here. I'm looking forward to interacting > with the community as I learn more about TDD, RSpec, Rails, and... > TDD through RSpec in Rails. > > Having watched the Peepcode screencasts and read a lot of > documentation, I'm trying to write my first comprehensive > applications using TDD from the ground up. I'm stuck writing a test > for my controller, though. > > This application is your basic crappy social network. There are > three relevant models in play right now: User, Group, and > Membership. User and Group have :has_many relationships with each > other :through Membership; Membership, in addition to having a > user_id and a group_id, also has a column called "rank", to which I > write in either "officer" or "member" as a value. > > Group also defines the following relationships just for convenience: > > has_many :memberships > has_many :officers, :through => :memberships, :source > => :user, :conditions => "rank = 'officer'" > has_many :members, :through => :memberships, :source > => :user, :conditions => "rank = 'member'" > > I'm trying to test the CREATE functionality in my Group controller. > Unfortunately, this test is not working. > > it "should make the creating user an officer" do > Group.stub!(:new).and_return(mock_group(:save => true)) > post :create, :group => {} > assigns[:group].should have(1).officer > end > > The error message: > Mock 'Group_1008' received unexpected message :officer with (no > args) > > If I understand this correctly, I am getting the error because > assigns[:group] isn't really an ActiveRecord object, just a mock, > and I guess the relationships don't carry over? If this is the > case, what's the right way to test it, assuming that a Membership > really is being created in my controller's create function? > > Thanks, > O. Hi O. The Group that you're creating is a Mock. Thus, it doesn't have any of the methods (Eg: #officer) that a real Group has. Since #officer hasn't been stubbed out on the mock Group, the error occurs. As for how to spec that the relationships are being setup correctly, can you provide the code for the Group's "new" action? Cheers, Nick From lists at ruby-forum.com Mon Oct 13 11:15:54 2008 From: lists at ruby-forum.com (Oscar Del ben) Date: Mon, 13 Oct 2008 17:15:54 +0200 Subject: [rspec-users] RSpec Book(s) on the radar In-Reply-To: <57c63afe0808290802w5c7e49e1u1b304af970e1d821@mail.gmail.com> References: <1299.216.167.174.73.1191590398.squirrel@webmail.skidmore.us> <8244a5ee7150b6f670511260a69eed98@ruby-forum.com> <57c63afe0801020652w32871bebsc6876eb3c4ab9566@mail.gmail.com> <604BD6AC-D087-4810-B970-87A61BBA7A83@superinfinite.com> <57c63afe0801021412n2c22df17n7bdb84c245331693@mail.gmail.com> <57c63afe0808290802w5c7e49e1u1b304af970e1d821@mail.gmail.com> Message-ID: <459ed80d5d4503c81dc058983c98c2bf@ruby-forum.com> David Chelimsky wrote: > It's definitely happening. We've enlisted a few additional > contributors and the wheels are spinning faster now. > > As for the beta book, I don't know if there will be on at this point. > We may go straight to print. Either way, I'll update as I know more > and I'll start blogging about progress shortly. > > Cheers, > David New info about the book? -- Posted via http://www.ruby-forum.com/. From jonathan at parkerhill.com Mon Oct 13 13:54:45 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Mon, 13 Oct 2008 13:54:45 -0400 Subject: [rspec-users] webrat within selector Message-ID: <832FC53E-85E3-4D74-878C-5F0FAB21EE46@parkerhill.com> anyone know if/how webrat can scope a clicks_link within a selector? eg, if I have more than one "Foo" link on a page, I want to make sure I click the one within a specific div Tia linoj From mailing_lists at railsnewbie.com Mon Oct 13 15:36:09 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 13 Oct 2008 15:36:09 -0400 Subject: [rspec-users] webrat within selector In-Reply-To: <832FC53E-85E3-4D74-878C-5F0FAB21EE46@parkerhill.com> References: <832FC53E-85E3-4D74-878C-5F0FAB21EE46@parkerhill.com> Message-ID: <0AD03D71-2685-49A9-AB77-AF21F7DFF980@railsnewbie.com> On Oct 13, 2008, at 1:54 PM, Jonathan Linowes wrote: > anyone know if/how webrat can scope a clicks_link within a selector? > eg, if I have more than one "Foo" link on a page, I want to make > sure I click the one within a specific div I'm pretty sure clicks link can also take an id. It's not the prettiest solution (in fact, I'm sure Bryan would say webrat was developed to *explicitly* so that you wouldn't use an id...but I digress). Scott From nick at deadorange.com Mon Oct 13 16:47:14 2008 From: nick at deadorange.com (Nick Hoffman) Date: Mon, 13 Oct 2008 16:47:14 -0400 Subject: [rspec-users] Checking that a controller created a separate model object In-Reply-To: <177dcc160810122049j4f2efc48kc22667df0d1af351@mail.gmail.com> References: <177dcc160810121933vc8f5218yc668b749800f9d0c@mail.gmail.com> <177dcc160810122049j4f2efc48kc22667df0d1af351@mail.gmail.com> Message-ID: On 2008-10-12, at 23:49, O. Frabjous-Dey wrote: > Hi Nick, > > The :new action comes straight from script/generate rspec_scaffold: > > def new > @group = Group.new > > respond_to do |format| > format.html > end > end > > I took out the XML rendering, but left in the respond_to block just > in case I wanted to add it or something else later. > And here's :create. > > def create > @group = Group.new(params[:group]) > > respond_to do |format| > if @group.save > flash[:notice] = 'Group was successfully created.' > # Make this user an officer of the group > Membership.create(:user_id => session[:user_id], :group_id > => @group.id, :rank => 'officer') > format.html { redirect_to(@group) } > else > format.html { render :action => "new" } > end > end > end > > Thanks! > O. Hi again, O. In your spec, you're stubbing Group#new and returning a mock. As a result, the "create" action uses that mock when creating the Membership object. I've never specced relationships, so I'm not sure what to suggest. Hopefully someone else can give some advice. Cheers, Nick BTW, that last email of yours was sent directly to me, rather than to the mailing list. Let's keep all of the messages on the list. From O.Frabjous.Dey at gmail.com Mon Oct 13 17:14:17 2008 From: O.Frabjous.Dey at gmail.com (O. Frabjous-Dey) Date: Mon, 13 Oct 2008 14:14:17 -0700 Subject: [rspec-users] Checking that a controller created a separate model object In-Reply-To: References: <177dcc160810121933vc8f5218yc668b749800f9d0c@mail.gmail.com> <177dcc160810122049j4f2efc48kc22667df0d1af351@mail.gmail.com> Message-ID: <177dcc160810131414r1f4dd416k80ec257e73f0691d@mail.gmail.com> On Mon, Oct 13, 2008 at 1:47 PM, Nick Hoffman wrote: > On 2008-10-12, at 23:49, O. Frabjous-Dey wrote: > >> Hi Nick, >> >> The :new action comes straight from script/generate rspec_scaffold: >> >> def new >> @group = Group.new >> >> respond_to do |format| >> format.html >> end >> end >> >> I took out the XML rendering, but left in the respond_to block just in >> case I wanted to add it or something else later. >> And here's :create. >> >> def create >> @group = Group.new(params[:group]) >> >> respond_to do |format| >> if @group.save >> flash[:notice] = 'Group was successfully created.' >> # Make this user an officer of the group >> Membership.create(:user_id => session[:user_id], :group_id => @ >> group.id, :rank => 'officer') >> format.html { redirect_to(@group) } >> else >> format.html { render :action => "new" } >> end >> end >> end >> >> Thanks! >> O. >> > > Hi again, O. In your spec, you're stubbing Group#new and returning a mock. > As a result, the "create" action uses that mock when creating the Membership > object. I've never specced relationships, so I'm not sure what to suggest. > Hopefully someone else can give some advice. > > Cheers, > Nick > > BTW, that last email of yours was sent directly to me, rather than to the > mailing list. Let's keep all of the messages on the list. > Whoops! Sorry this was sent straight to you, Nick. I should have hit Reply-all. (Also that the subject line isn't formatted correctly; I mistakenly thought that the listserv software would prepend [rspec-users] on its own.) I thought some more about the issue and I think I'm approaching the problem the wrong way to begin with. As I understand it, part of the philosophy of RSpec is that using mocks and stubs when testing controllers and views instead of touching the database helps to keep each test context self-contained. So I really ought to be checking to see if Membership.create or or Membership.new is being called instead of examining the model object's relationships themselves - not that I can anyway, since it's a mock model. Can anyone confirm if that sounds right? If so, what method should I be using? #should_receive? Thanks again in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Mon Oct 13 20:56:19 2008 From: lists at ruby-forum.com (Chris Olsen) Date: Tue, 14 Oct 2008 02:56:19 +0200 Subject: [rspec-users] RSpec Book(s) on the radar In-Reply-To: <459ed80d5d4503c81dc058983c98c2bf@ruby-forum.com> References: <1299.216.167.174.73.1191590398.squirrel@webmail.skidmore.us> <8244a5ee7150b6f670511260a69eed98@ruby-forum.com> <57c63afe0801020652w32871bebsc6876eb3c4ab9566@mail.gmail.com> <604BD6AC-D087-4810-B970-87A61BBA7A83@superinfinite.com> <57c63afe0801021412n2c22df17n7bdb84c245331693@mail.gmail.com> <57c63afe0808290802w5c7e49e1u1b304af970e1d821@mail.gmail.com> <459ed80d5d4503c81dc058983c98c2bf@ruby-forum.com> Message-ID: Oscar Del ben wrote: > David Chelimsky wrote: >> It's definitely happening. We've enlisted a few additional >> contributors and the wheels are spinning faster now. >> >> As for the beta book, I don't know if there will be on at this point. >> We may go straight to print. Either way, I'll update as I know more >> and I'll start blogging about progress shortly. >> >> Cheers, >> David > > New info about the book? It's funny that you just asked the question because after getting the Pragmatic b-day discount I wondered the exact same thing :) -- Posted via http://www.ruby-forum.com/. From nick at deadorange.com Mon Oct 13 22:03:58 2008 From: nick at deadorange.com (Nick Hoffman) Date: Mon, 13 Oct 2008 22:03:58 -0400 Subject: [rspec-users] Checking that a controller created a separate model object In-Reply-To: <177dcc160810131414r1f4dd416k80ec257e73f0691d@mail.gmail.com> References: <177dcc160810121933vc8f5218yc668b749800f9d0c@mail.gmail.com> <177dcc160810122049j4f2efc48kc22667df0d1af351@mail.gmail.com> <177dcc160810131414r1f4dd416k80ec257e73f0691d@mail.gmail.com> Message-ID: On 2008-10-13, at 17:14, O. Frabjous-Dey wrote: > I thought some more about the issue and I think I'm approaching the > problem the wrong way to begin with. As I understand it, part of > the philosophy of RSpec is that using mocks and stubs when testing > controllers and views instead of touching the database helps to keep > each test context self-contained. So I really ought to be checking > to see if Membership.create or or Membership.new is being called > instead of examining the model object's relationships themselves - > not that I can anyway, since it's a mock model. > > Can anyone confirm if that sounds right? If so, what method should > I be using? #should_receive? Thanks again in advance. Hi O. You're correct about using mocks and stubs to prevent hitting the database. More importantly though, they allow you to test discrete pieces of code without depending on the state of its surrounding code. To spec the 'create' action, just go through it one "step" at a time. Eg: describe "create" do before :each do @group = mock_model Group, :save => true # somehow spec the assignment to flash[:notice] Membership.stub! :create end it "should create a new group" it "should respond to ..." it "should save the group" it "should assign the flash message" it "should create a new Membership" etc... end That doesn't seem complete. What'd I miss? =P Cheers, Nick From zach.dennis at gmail.com Tue Oct 14 00:48:31 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 14 Oct 2008 00:48:31 -0400 Subject: [rspec-users] Rails config.gem and rspec, rspec-rails Message-ID: <85d99afe0810132148o38944398o16ee2bd7b3a42402@mail.gmail.com> In #rspec the instructions for installing rspec and rspec-rails on a Rails project. Specifically talking about the following line from http://github.com/dchelimsky/rspec-rails/wikis/home config.gem "rspec-rails", :lib => "spec" I think this should be updated to not instruct people to do this. Rails config.gem will *load* all configured gems in all environments which isn't what I thikn people expect. Simply having people move these config.gem statements into the appropriate environment file also doesn't work quite as expected (at least not with the rake tasks that surround gem usage in Rails). If folks use the gem versions I think the wiki should advise them to run "gem unpack rspec rspec-rails" inside of vendor/gems. Thoughts? -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From dchelimsky at gmail.com Tue Oct 14 01:25:38 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 14 Oct 2008 03:25:38 -0200 Subject: [rspec-users] Rails config.gem and rspec, rspec-rails In-Reply-To: <85d99afe0810132148o38944398o16ee2bd7b3a42402@mail.gmail.com> References: <85d99afe0810132148o38944398o16ee2bd7b3a42402@mail.gmail.com> Message-ID: <57c63afe0810132225l65097884m42ce816dadcef186@mail.gmail.com> On Tue, Oct 14, 2008 at 2:48 AM, Zach Dennis wrote: > In #rspec the instructions for installing rspec and rspec-rails on a > Rails project. Specifically talking about the following line from > http://github.com/dchelimsky/rspec-rails/wikis/home > > config.gem "rspec-rails", :lib => "spec" > > I think this should be updated to not instruct people to do this. > Rails config.gem will *load* all configured gems in all environments > which isn't what I thikn people expect. Simply having people move > these config.gem statements into the appropriate environment file also > doesn't work quite as expected (at least not with the rake tasks that > surround gem usage in Rails). > > If folks use the gem versions I think the wiki should advise them to > run "gem unpack rspec rspec-rails" inside of vendor/gems. Actually, I've just been using the gems without any reference to them in the app configuration. Just 'gem install rspec-rails', 'script/generate rspec', and go. So reflected on the wiki. Thanks Zach, David > > Thoughts? > > -- > 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 lists at ruby-forum.com Tue Oct 14 01:53:30 2008 From: lists at ruby-forum.com (Oscar Del ben) Date: Tue, 14 Oct 2008 07:53:30 +0200 Subject: [rspec-users] RSpec Book(s) on the radar In-Reply-To: References: <1299.216.167.174.73.1191590398.squirrel@webmail.skidmore.us> <8244a5ee7150b6f670511260a69eed98@ruby-forum.com> <57c63afe0801020652w32871bebsc6876eb3c4ab9566@mail.gmail.com> <604BD6AC-D087-4810-B970-87A61BBA7A83@superinfinite.com> <57c63afe0801021412n2c22df17n7bdb84c245331693@mail.gmail.com> <57c63afe0808290802w5c7e49e1u1b304af970e1d821@mail.gmail.com> <459ed80d5d4503c81dc058983c98c2bf@ruby-forum.com> Message-ID: <3d67dc587c6664ae79fbf273e0f91119@ruby-forum.com> Chris Olsen wrote: > Oscar Del ben wrote: >> David Chelimsky wrote: >>> It's definitely happening. We've enlisted a few additional >>> contributors and the wheels are spinning faster now. >>> >>> As for the beta book, I don't know if there will be on at this point. >>> We may go straight to print. Either way, I'll update as I know more >>> and I'll start blogging about progress shortly. >>> >>> Cheers, >>> David >> >> New info about the book? > > It's funny that you just asked the question because after getting the > Pragmatic b-day discount I wondered the exact same thing :) No really i was looking for a rspec-book during the last week without success and i wondered about the status of this book :) -- Posted via http://www.ruby-forum.com/. From lists at brynary.com Tue Oct 14 02:13:56 2008 From: lists at brynary.com (Bryan Helmkamp) Date: Tue, 14 Oct 2008 02:13:56 -0400 Subject: [rspec-users] webrat within selector In-Reply-To: <0AD03D71-2685-49A9-AB77-AF21F7DFF980@railsnewbie.com> References: <832FC53E-85E3-4D74-878C-5F0FAB21EE46@parkerhill.com> <0AD03D71-2685-49A9-AB77-AF21F7DFF980@railsnewbie.com> Message-ID: Jonathan, This should work: within "#user_43" do |scope| scope.click_link "Edit" end If you're using Rails' record identification HTML helpers, you can do something like within('#' + dom_id(user)) to save some typing. Scott's right that I'd recommend avoiding targeting IDs when possible, but Webrat supports it in a few ways for cases where it's needed. -Bryan On Mon, Oct 13, 2008 at 3:36 PM, Scott Taylor wrote: > > On Oct 13, 2008, at 1:54 PM, Jonathan Linowes wrote: > >> anyone know if/how webrat can scope a clicks_link within a selector? eg, >> if I have more than one "Foo" link on a page, I want to make sure I click >> the one within a specific div > > I'm pretty sure clicks link can also take an id. It's not the prettiest > solution (in fact, I'm sure Bryan would say webrat was developed to > *explicitly* so that you wouldn't use an id...but I digress). > > Scott > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Bryan Helmkamp http://brynary.com -- My blog From lists at ruby-forum.com Tue Oct 14 02:32:30 2008 From: lists at ruby-forum.com (Mano ah) Date: Tue, 14 Oct 2008 08:32:30 +0200 Subject: [rspec-users] rspec - undefined method `describe' for main:Object In-Reply-To: <57c63afe0810110842p1200b0b2x49151642ed5d30f7@mail.gmail.com> References: <1bb11ef7def49c2e4cc5418e7b8572a0@ruby-forum.com> <71166b3b0810102225m71e0742ej9b4d0383ca57fbfc@mail.gmail.com> <2bb3db95858f6d430edaac53600a8693@ruby-forum.com> <810a540e0810110344x436b82c0u3ab7e5574b4a8dd9@mail.gmail.com> <53fd14af37b7ce34bd359f9b0d054f1a@ruby-forum.com> <71166b3b0810110816k8649cb8h87cd39499885f8f9@mail.gmail.com> <57c63afe0810110842p1200b0b2x49151642ed5d30f7@mail.gmail.com> Message-ID: Thank you Pat Maddox,Douglas Adams,Luis Lavena,Scott Taylor for your kind help. I have installed the plugins rspec and rspec-rails using git. I was not running the spec controller from the root thats the main problem. I followed all of your useful suggestions and able to build and run a project sucessfully. Thank you once again. -- Posted via http://www.ruby-forum.com/. From weiwei9 at gmail.com Tue Oct 14 02:47:50 2008 From: weiwei9 at gmail.com (wei wei) Date: Tue, 14 Oct 2008 14:47:50 +0800 Subject: [rspec-users] Any Plans on Tag support in Cucumber Message-ID: <784ae8ca0810132347q1d2f67f3k414bdd558464aa52@mail.gmail.com> Hi, ThoughtWorks just released the auto test toolset Twist, the "tagging" feature seems pretty useful, http://studios.thoughtworks.com/twist-agile-test-automation/twist-features-and-benefits "Tags allow you to organize test suites in multiple dimensions. With tags, you can include a test in a smoke test suite by just tagging it smoke, or exclude unfinished tests from running by tagging them with a keyword of your choosing." I wonder if there are plans to support this in cucumber? I also wanna try to implement it. -- Wei Wei -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonathan at parkerhill.com Tue Oct 14 02:51:34 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Tue, 14 Oct 2008 02:51:34 -0400 Subject: [rspec-users] webrat within selector In-Reply-To: References: <832FC53E-85E3-4D74-878C-5F0FAB21EE46@parkerhill.com> <0AD03D71-2685-49A9-AB77-AF21F7DFF980@railsnewbie.com> Message-ID: <990E4EC0-2EDD-4312-A3AB-CFC1B5994A70@parkerhill.com> thanks guys yeah, my case is a step like When "I click on the $tab tab"... I want to make sure its a link in a tab, not some other link on the page with the same text On Oct 14, 2008, at 2:13 AM, Bryan Helmkamp wrote: > Jonathan, > > This should work: > > within "#user_43" do |scope| > scope.click_link "Edit" > end > > If you're using Rails' record identification HTML helpers, you can do > something like within('#' + dom_id(user)) to save some typing. > > Scott's right that I'd recommend avoiding targeting IDs when possible, > but Webrat supports it in a few ways for cases where it's needed. > > -Bryan > > On Mon, Oct 13, 2008 at 3:36 PM, Scott Taylor > wrote: >> >> On Oct 13, 2008, at 1:54 PM, Jonathan Linowes wrote: >> >>> anyone know if/how webrat can scope a clicks_link within a >>> selector? eg, >>> if I have more than one "Foo" link on a page, I want to make sure >>> I click >>> the one within a specific div >> >> I'm pretty sure clicks link can also take an id. It's not the >> prettiest >> solution (in fact, I'm sure Bryan would say webrat was developed to >> *explicitly* so that you wouldn't use an id...but I digress). >> >> Scott >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Bryan Helmkamp > http://brynary.com -- My blog > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From aslak.hellesoy at gmail.com Tue Oct 14 03:16:45 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 14 Oct 2008 09:16:45 +0200 Subject: [rspec-users] Any Plans on Tag support in Cucumber In-Reply-To: <784ae8ca0810132347q1d2f67f3k414bdd558464aa52@mail.gmail.com> References: <784ae8ca0810132347q1d2f67f3k414bdd558464aa52@mail.gmail.com> Message-ID: <8d961d900810140016v11bd2657q97ac6e89127aef60@mail.gmail.com> On Tue, Oct 14, 2008 at 8:47 AM, wei wei wrote: > Hi, > ThoughtWorks just released the auto test toolset Twist, the "tagging" > feature seems pretty > useful, http://studios.thoughtworks.com/twist-agile-test-automation/twist-features-and-benefits > "Tags > allow you to organize test suites in multiple dimensions. With tags, you can include a test in a smoke test suite by just tagging it smoke, or exclude unfinished tests from running by tagging them with a keyword of your choosing." > > I wonder if there are plans to support this in cucumber? I also wanna try to > implement it. I've been thinking about tags for a long time - it's just had lower priority than other things. Please start by opening a ticket in Lighthouse where you give some examples of how tags can be entered. I'd also like to see examples of how you'd like to tell Cucumber what tags you want to run, and whether you want any other kind of output. Let's continue the discussion in Lighthouse. It's great that you're volunteering to implement it! Cheers, Aslak > -- > Wei Wei > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ThomasMarek_ at web.de Tue Oct 14 03:38:13 2008 From: ThomasMarek_ at web.de (Thomas Marek) Date: Tue, 14 Oct 2008 09:38:13 +0200 Subject: [rspec-users] =?iso-8859-15?q?Cucumber=3A_Migrating_RSpec_Story_L?= =?iso-8859-15?q?isteners_to_Cucumber?= Message-ID: <1343314469@web.de> No advice on that? Should i open a ticket on Lighthouse? I also would try to implement that... Thanks, Thomas > -----Urspr?ngliche Nachricht----- > Von: "Thomas Marek" > Gesendet: 09.10.08 15:25:14 > An: rspec-users > Betreff: [rspec-users] Cucumber: Migrating RSpec Story Listeners to Cucumber > Hello, > > i written a rails plugin for driving Selenium from > the RSpec Story Runner: > > http://github.com/tmak/rspec-rails-selenium-story > > > Now, i want to migrate my plugin to cucumber. > > > My question: > I used the scenario_failed method of the Story Listener to make > screenshots of failing story scenarios. > How can i do that with cucumber? > > > Thanks, > Thomas > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > _____________________________________________________________________ Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! http://smartsurfer.web.de/?mc=100071&distributionid=000000000066 From aslak.hellesoy at gmail.com Tue Oct 14 04:31:29 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 14 Oct 2008 10:31:29 +0200 Subject: [rspec-users] Cucumber: Migrating RSpec Story Listeners to Cucumber In-Reply-To: <1343314469@web.de> References: <1343314469@web.de> Message-ID: <8d961d900810140131y1e86620etaca6138ae6b993fa@mail.gmail.com> On Tue, Oct 14, 2008 at 9:38 AM, Thomas Marek wrote: > No advice on that? > > Should i open a ticket on Lighthouse? Please do. > I also would try to implement that... > Great! Some suggestions: I'd like to be able to do something like this: After do # cucumber_scenario would return the Scenario instance # The cucumber_scenario method could be defined in a similar way to #run_step, # see Executor#define_step_call_methods if cucumber_scenario.successful? take_screenshot(cucumber_scenario.id) # Each scenario should have a unique id that can be used in e.g. file names. end end Aslak > Thanks, > Thomas > >> -----Urspr?ngliche Nachricht----- >> Von: "Thomas Marek" >> Gesendet: 09.10.08 15:25:14 >> An: rspec-users >> Betreff: [rspec-users] Cucumber: Migrating RSpec Story Listeners to Cucumber > >> Hello, >> >> i written a rails plugin for driving Selenium from >> the RSpec Story Runner: >> >> http://github.com/tmak/rspec-rails-selenium-story >> >> >> Now, i want to migrate my plugin to cucumber. >> >> >> My question: >> I used the scenario_failed method of the Story Listener to make >> screenshots of failing story scenarios. >> How can i do that with cucumber? >> >> >> Thanks, >> Thomas >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > _____________________________________________________________________ > Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! > http://smartsurfer.web.de/?mc=100071&distributionid=000000000066 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lattam at mac.com Tue Oct 14 11:29:40 2008 From: lattam at mac.com (Michael Latta) Date: Tue, 14 Oct 2008 08:29:40 -0700 Subject: [rspec-users] Cucumber: Migrating RSpec Story Listeners to Cucumber In-Reply-To: <8d961d900810140131y1e86620etaca6138ae6b993fa@mail.gmail.com> References: <1343314469@web.de> <8d961d900810140131y1e86620etaca6138ae6b993fa@mail.gmail.com> Message-ID: <81462B05-053E-45F4-BDD1-1F937AD95132@mac.com> Why use a cucumber_scenario method when the After method could just pass it to the block? Michael On Oct 14, 2008, at 1:31 AM, aslak hellesoy wrote: > On Tue, Oct 14, 2008 at 9:38 AM, Thomas Marek > wrote: >> No advice on that? >> >> Should i open a ticket on Lighthouse? > > Please do. > >> I also would try to implement that... >> > > Great! Some suggestions: > > I'd like to be able to do something like this: > > After do > # cucumber_scenario would return the Scenario instance > # The cucumber_scenario method could be defined in a similar way to > #run_step, > # see Executor#define_step_call_methods > if cucumber_scenario.successful? > take_screenshot(cucumber_scenario.id) # Each scenario should have > a unique id that can be used in e.g. file names. > end > end > > Aslak > >> Thanks, >> Thomas >> >>> -----Urspr?ngliche Nachricht----- >>> Von: "Thomas Marek" >>> Gesendet: 09.10.08 15:25:14 >>> An: rspec-users >>> Betreff: [rspec-users] Cucumber: Migrating RSpec Story Listeners >>> to Cucumber >> >>> Hello, >>> >>> i written a rails plugin for driving Selenium from >>> the RSpec Story Runner: >>> >>> http://github.com/tmak/rspec-rails-selenium-story >>> >>> >>> Now, i want to migrate my plugin to cucumber. >>> >>> >>> My question: >>> I used the scenario_failed method of the Story Listener to make >>> screenshots of failing story scenarios. >>> How can i do that with cucumber? >>> >>> >>> Thanks, >>> Thomas >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> >> _____________________________________________________________________ >> Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! >> http://smartsurfer.web.de/?mc=100071&distributionid=000000000066 >> >> _______________________________________________ >> 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 ThomasMarek_ at web.de Tue Oct 14 11:43:43 2008 From: ThomasMarek_ at web.de (Thomas Marek) Date: Tue, 14 Oct 2008 17:43:43 +0200 Subject: [rspec-users] =?iso-8859-15?q?Cucumber=3A_Migrating_RSpec_Story_L?= =?iso-8859-15?q?isteners_to=09Cucumber?= Message-ID: <1344095820@web.de> I opened a ticket for that: http://rspec.lighthouseapp.com/projects/16211/tickets/44-ability-to-teardown-failing-or-pending-scenarios-in-different-ways Thomas > -----Urspr?ngliche Nachricht----- > Von: "Michael Latta" > Gesendet: 14.10.08 17:31:58 > An: rspec-users > Betreff: Re: [rspec-users] Cucumber: Migrating RSpec Story Listeners to Cucumber > Why use a cucumber_scenario method when the After method could just > pass it to the block? > > Michael > > > On Oct 14, 2008, at 1:31 AM, aslak hellesoy wrote: > > > On Tue, Oct 14, 2008 at 9:38 AM, Thomas Marek > > wrote: > >> No advice on that? > >> > >> Should i open a ticket on Lighthouse? > > > > Please do. > > > >> I also would try to implement that... > >> > > > > Great! Some suggestions: > > > > I'd like to be able to do something like this: > > > > After do > > # cucumber_scenario would return the Scenario instance > > # The cucumber_scenario method could be defined in a similar way to > > #run_step, > > # see Executor#define_step_call_methods > > if cucumber_scenario.successful? > > take_screenshot(cucumber_scenario.id) # Each scenario should have > > a unique id that can be used in e.g. file names. > > end > > end > > > > Aslak > > > >> Thanks, > >> Thomas > >> > >>> -----Urspr?ngliche Nachricht----- > >>> Von: "Thomas Marek" > >>> Gesendet: 09.10.08 15:25:14 > >>> An: rspec-users > >>> Betreff: [rspec-users] Cucumber: Migrating RSpec Story Listeners > >>> to Cucumber > >> > >>> Hello, > >>> > >>> i written a rails plugin for driving Selenium from > >>> the RSpec Story Runner: > >>> > >>> http://github.com/tmak/rspec-rails-selenium-story > >>> > >>> > >>> Now, i want to migrate my plugin to cucumber. > >>> > >>> > >>> My question: > >>> I used the scenario_failed method of the Story Listener to make > >>> screenshots of failing story scenarios. > >>> How can i do that with cucumber? > >>> > >>> > >>> Thanks, > >>> Thomas > >>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >>> > >> > >> > >> _____________________________________________________________________ > >> Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! > >> http://smartsurfer.web.de/?mc=100071&distributionid=000000000066 > >> > >> _______________________________________________ > >> 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 > ________________________________________________________________________ Schon geh?rt? Bei WEB.DE gibt' s viele kostenlose Spiele: http://games.entertainment.web.de/de/entertainment/games/free/index.html From aslak.hellesoy at gmail.com Tue Oct 14 11:49:07 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 14 Oct 2008 17:49:07 +0200 Subject: [rspec-users] Cucumber: Migrating RSpec Story Listeners to Cucumber In-Reply-To: <81462B05-053E-45F4-BDD1-1F937AD95132@mac.com> References: <1343314469@web.de> <8d961d900810140131y1e86620etaca6138ae6b993fa@mail.gmail.com> <81462B05-053E-45F4-BDD1-1F937AD95132@mac.com> Message-ID: <8d961d900810140849h5cb3235dnaeb5da86177b52b8@mail.gmail.com> On Tue, Oct 14, 2008 at 5:29 PM, Michael Latta wrote: > Why use a cucumber_scenario method when the After method could just pass it > to the block? > Good idea! > Michael > > > On Oct 14, 2008, at 1:31 AM, aslak hellesoy wrote: > >> On Tue, Oct 14, 2008 at 9:38 AM, Thomas Marek wrote: >>> >>> No advice on that? >>> >>> Should i open a ticket on Lighthouse? >> >> Please do. >> >>> I also would try to implement that... >>> >> >> Great! Some suggestions: >> >> I'd like to be able to do something like this: >> >> After do >> # cucumber_scenario would return the Scenario instance >> # The cucumber_scenario method could be defined in a similar way to >> #run_step, >> # see Executor#define_step_call_methods >> if cucumber_scenario.successful? >> take_screenshot(cucumber_scenario.id) # Each scenario should have >> a unique id that can be used in e.g. file names. >> end >> end >> >> Aslak >> >>> Thanks, >>> Thomas >>> >>>> -----Urspr?ngliche Nachricht----- >>>> Von: "Thomas Marek" >>>> Gesendet: 09.10.08 15:25:14 >>>> An: rspec-users >>>> Betreff: [rspec-users] Cucumber: Migrating RSpec Story Listeners to >>>> Cucumber >>> >>>> Hello, >>>> >>>> i written a rails plugin for driving Selenium from >>>> the RSpec Story Runner: >>>> >>>> http://github.com/tmak/rspec-rails-selenium-story >>>> >>>> >>>> Now, i want to migrate my plugin to cucumber. >>>> >>>> >>>> My question: >>>> I used the scenario_failed method of the Story Listener to make >>>> screenshots of failing story scenarios. >>>> How can i do that with cucumber? >>>> >>>> >>>> Thanks, >>>> Thomas >>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> >>> >>> _____________________________________________________________________ >>> Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! >>> http://smartsurfer.web.de/?mc=100071&distributionid=000000000066 >>> >>> _______________________________________________ >>> 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 weiwei9 at gmail.com Tue Oct 14 12:30:54 2008 From: weiwei9 at gmail.com (wei wei) Date: Wed, 15 Oct 2008 00:30:54 +0800 Subject: [rspec-users] [cucumber] Is it possbile to access scenario name in steps? Message-ID: <784ae8ca0810140930u7ca98865n2ec5fb8f16daaa6d@mail.gmail.com> One of my examples now is like below ### case_1001.feature Feature: case_1001 Scenario: 10001 Given the network is CBS Given the data : Then there should be an asset with internal id and title1 in DB -- Wei Wei -------------- next part -------------- An HTML attachment was scrubbed... URL: From weiwei9 at gmail.com Tue Oct 14 12:40:31 2008 From: weiwei9 at gmail.com (wei wei) Date: Wed, 15 Oct 2008 00:40:31 +0800 Subject: [rspec-users] [cucumber] Is it possbile to access scenario name in steps? In-Reply-To: <784ae8ca0810140930u7ca98865n2ec5fb8f16daaa6d@mail.gmail.com> References: <784ae8ca0810140930u7ca98865n2ec5fb8f16daaa6d@mail.gmail.com> Message-ID: <784ae8ca0810140940o4c63e872j912462d5d45a3d1@mail.gmail.com> One of my examples now is like below ### 1001.feature Feature: 1001 1001 is the internal id for QAs to identify case Scenario: 1001 Given the title is "function1_1001" ..... ### function1.steps Given /the title is "(.*)"/ do |title| @title = title end Actually the title is generated by the rule "function1_#{scenario_name}". So ideally it could be written in this way ### 1001.feature Feature: 1001 1001 is the internal id for QAs to identify case Scenario: 1001 Given the generated title ..... ### function1.steps Given /the generated title/ do @title = "function1_#{@scenario_name}" #though the variable @scenario_name isn't available end So my question is: is it possible to get the name of the scenario/feature in the step block? ps: sorry, last message was sent by mistake. -- Wei Wei -------------- next part -------------- An HTML attachment was scrubbed... URL: From aslak.hellesoy at gmail.com Tue Oct 14 15:23:21 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 14 Oct 2008 21:23:21 +0200 Subject: [rspec-users] [cucumber] Is it possbile to access scenario name in steps? In-Reply-To: <784ae8ca0810140940o4c63e872j912462d5d45a3d1@mail.gmail.com> References: <784ae8ca0810140930u7ca98865n2ec5fb8f16daaa6d@mail.gmail.com> <784ae8ca0810140940o4c63e872j912462d5d45a3d1@mail.gmail.com> Message-ID: <8d961d900810141223u269792a9i9ca292eec5675744@mail.gmail.com> On Tue, Oct 14, 2008 at 6:40 PM, wei wei wrote: > One of my examples now is like below > ### 1001.feature > Feature: 1001 > 1001 is the internal id for QAs to identify case > Scenario: 1001 > Given the title is "function1_1001" > ..... > ### function1.steps > Given /the title is "(.*)"/ do |title| > @title = title > end > Actually the title is generated by the rule "function1_#{scenario_name}". So > ideally it could be written in this way > ### 1001.feature > Feature: 1001 > 1001 is the internal id for QAs to identify case > Scenario: 1001 > Given the generated title > ..... > ### function1.steps > Given /the generated title/ do > @title = "function1_#{@scenario_name}" #though the variable @scenario_name > isn't available > end Please try to exclude irrelevant information when asking a question. Everything you said above doesn't make your question any clearer. > So my question is: is it possible to get the name of the scenario/feature in > the step block? It's not, but you can register a feature request. Take a look at http://rspec.lighthouseapp.com/projects/16211-cucumber/tickets/44 It sounds like what you're asking for is related. Aslak > ps: sorry, last message was sent by mistake. > -- > Wei Wei > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Oct 14 15:39:54 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 14 Oct 2008 17:39:54 -0200 Subject: [rspec-users] Cucumber: Migrating RSpec Story Listeners to Cucumber In-Reply-To: <8d961d900810140849h5cb3235dnaeb5da86177b52b8@mail.gmail.com> References: <1343314469@web.de> <8d961d900810140131y1e86620etaca6138ae6b993fa@mail.gmail.com> <81462B05-053E-45F4-BDD1-1F937AD95132@mac.com> <8d961d900810140849h5cb3235dnaeb5da86177b52b8@mail.gmail.com> Message-ID: <57c63afe0810141239n7adf3185y2203e68577569ae5@mail.gmail.com> On Tue, Oct 14, 2008 at 1:49 PM, aslak hellesoy wrote: > On Tue, Oct 14, 2008 at 5:29 PM, Michael Latta wrote: >> Why use a cucumber_scenario method when the After method could just pass it >> to the block? > > Good idea! Can the Before do the same? Then you could grab the name or whatever before printing anything out. > >> Michael >> >> >> On Oct 14, 2008, at 1:31 AM, aslak hellesoy wrote: >> >>> On Tue, Oct 14, 2008 at 9:38 AM, Thomas Marek wrote: >>>> >>>> No advice on that? >>>> >>>> Should i open a ticket on Lighthouse? >>> >>> Please do. >>> >>>> I also would try to implement that... >>>> >>> >>> Great! Some suggestions: >>> >>> I'd like to be able to do something like this: >>> >>> After do >>> # cucumber_scenario would return the Scenario instance >>> # The cucumber_scenario method could be defined in a similar way to >>> #run_step, >>> # see Executor#define_step_call_methods >>> if cucumber_scenario.successful? >>> take_screenshot(cucumber_scenario.id) # Each scenario should have >>> a unique id that can be used in e.g. file names. >>> end >>> end >>> >>> Aslak >>> >>>> Thanks, >>>> Thomas >>>> >>>>> -----Urspr?ngliche Nachricht----- >>>>> Von: "Thomas Marek" >>>>> Gesendet: 09.10.08 15:25:14 >>>>> An: rspec-users >>>>> Betreff: [rspec-users] Cucumber: Migrating RSpec Story Listeners to >>>>> Cucumber >>>> >>>>> Hello, >>>>> >>>>> i written a rails plugin for driving Selenium from >>>>> the RSpec Story Runner: >>>>> >>>>> http://github.com/tmak/rspec-rails-selenium-story >>>>> >>>>> >>>>> Now, i want to migrate my plugin to cucumber. >>>>> >>>>> >>>>> My question: >>>>> I used the scenario_failed method of the Story Listener to make >>>>> screenshots of failing story scenarios. >>>>> How can i do that with cucumber? >>>>> >>>>> >>>>> Thanks, >>>>> Thomas >>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>> >>>> >>>> _____________________________________________________________________ >>>> Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! >>>> http://smartsurfer.web.de/?mc=100071&distributionid=000000000066 >>>> >>>> _______________________________________________ >>>> 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 zach.dennis at gmail.com Tue Oct 14 15:52:44 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 14 Oct 2008 15:52:44 -0400 Subject: [rspec-users] Cucumber: Migrating RSpec Story Listeners to Cucumber In-Reply-To: <57c63afe0810141239n7adf3185y2203e68577569ae5@mail.gmail.com> References: <1343314469@web.de> <8d961d900810140131y1e86620etaca6138ae6b993fa@mail.gmail.com> <81462B05-053E-45F4-BDD1-1F937AD95132@mac.com> <8d961d900810140849h5cb3235dnaeb5da86177b52b8@mail.gmail.com> <57c63afe0810141239n7adf3185y2203e68577569ae5@mail.gmail.com> Message-ID: <85d99afe0810141252n3049e257gcc128b7d97526714@mail.gmail.com> On Tue, Oct 14, 2008 at 3:39 PM, David Chelimsky wrote: > On Tue, Oct 14, 2008 at 1:49 PM, aslak hellesoy > wrote: >> On Tue, Oct 14, 2008 at 5:29 PM, Michael Latta wrote: >>> Why use a cucumber_scenario method when the After method could just pass it >>> to the block? >> >> Good idea! > > Can the Before do the same? Then you could grab the name or whatever > before printing anything out. > Based on Aslak's example and the content in the ticket and this thread I think that is the intent. Although, mentioned in passing it as an example in the After, Aslak's code exactly on the ticket showed only passing the scenario through to the Before as a block argument. The ticket has been updated, perhaps we should defer future communication on this thread to the ticket? -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From aslak.hellesoy at gmail.com Tue Oct 14 17:04:52 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Tue, 14 Oct 2008 23:04:52 +0200 Subject: [rspec-users] Cucumber: Migrating RSpec Story Listeners to Cucumber In-Reply-To: <85d99afe0810141252n3049e257gcc128b7d97526714@mail.gmail.com> References: <1343314469@web.de> <8d961d900810140131y1e86620etaca6138ae6b993fa@mail.gmail.com> <81462B05-053E-45F4-BDD1-1F937AD95132@mac.com> <8d961d900810140849h5cb3235dnaeb5da86177b52b8@mail.gmail.com> <57c63afe0810141239n7adf3185y2203e68577569ae5@mail.gmail.com> <85d99afe0810141252n3049e257gcc128b7d97526714@mail.gmail.com> Message-ID: <8d961d900810141404u92594b8ke0929a1580cbf274@mail.gmail.com> On Tue, Oct 14, 2008 at 9:52 PM, Zach Dennis wrote: > On Tue, Oct 14, 2008 at 3:39 PM, David Chelimsky wrote: >> On Tue, Oct 14, 2008 at 1:49 PM, aslak hellesoy >> wrote: >>> On Tue, Oct 14, 2008 at 5:29 PM, Michael Latta wrote: >>>> Why use a cucumber_scenario method when the After method could just pass it >>>> to the block? >>> >>> Good idea! >> >> Can the Before do the same? Then you could grab the name or whatever >> before printing anything out. >> > > Based on Aslak's example and the content in the ticket and this thread > I think that is the intent. Although, mentioned in passing it as an > example in the After, Aslak's code exactly on the ticket showed only > passing the scenario through to the Before as a block argument. > > The ticket has been updated, perhaps we should defer future > communication on this thread to the ticket? > Yes, let's > -- > 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 smingins at elctech.com Tue Oct 14 23:07:47 2008 From: smingins at elctech.com (Shane Mingins) Date: Wed, 15 Oct 2008 16:07:47 +1300 Subject: [rspec-users] Just a quick question on David's new-controller-examples Message-ID: http://blog.davidchelimsky.net/2008/7/1/new-controller-examples BTW .... great post, thanks :-) I was wondering the thinking of this one .... describe "responding to POST /accounts" do describe "with failed save" do it "should create a new account" do Account.should_receive(:new).with({'these' => 'params'}).and_return(mock_account(:save => false)) post :create, :account => {:these => 'params'} end compared to the similar example in describe "with successful save". The expected behaviour seems the same and I wondered why it would not be pulled into just the responding to POST /accounts block? Cheers Shane Shane Mingins ELC Technologies (TM) 1921 State Street Santa Barbara, CA 93101 Phone: +64 4 568 6684 Mobile: +64 21 435 586 Email: smingins at elctech.com AIM: ShaneMingins Skype: shane.mingins (866) 863-7365 Tel - Santa Barbara Office (866) 893-1902 Fax - Santa Barbara Office +44 020 7504 1346 Tel - London Office +44 020 7504 1347 Fax - London Office http://www.elctech.com -------------------------------------------------------------------- Privacy and Confidentiality Notice: The information contained in this electronic mail message is intended for the named recipient(s) only. It may contain privileged and confidential information. If you are not an intended recipient, you must not copy, forward, distribute or take any action in reliance on it. If you have received this electronic mail message in -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 4000 bytes Desc: not available URL: From lists at ruby-forum.com Wed Oct 15 00:10:51 2008 From: lists at ruby-forum.com (Alr Alr) Date: Wed, 15 Oct 2008 06:10:51 +0200 Subject: [rspec-users] how to play with rSpec using irb Message-ID: Hi, Is there any way to experiment with rSpec in irb or script/console session? Tried this: >> require 'spec' => true >> [1,2,3].should have(3).items => NoMethodError: undefined method `have' for main:Object from (irb):4 from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/fileutils.rb:1576 What I am doing wrong? Thx -- Posted via http://www.ruby-forum.com/. From caius at caius.name Wed Oct 15 02:43:05 2008 From: caius at caius.name (Caius Durling) Date: Wed, 15 Oct 2008 07:43:05 +0100 Subject: [rspec-users] how to play with rSpec using irb In-Reply-To: References: Message-ID: On 15 Oct 2008, at 05:10, Alr Alr wrote: > Hi, > > Is there any way to experiment with rSpec in irb or script/console > session? > > Tried this: > >>> require 'spec' > => true >>> [1,2,3].should have(3).items > => NoMethodError: undefined method `have' for main:Object > from (irb):4 > from > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ > 1.8/fileutils.rb:1576 > > What I am doing wrong? %w(1 2 3).should have(3).items the call to have is Object#have, which doesn't exist. If you include the Spec::Matchers module however, then it adds Object#have, etc. Julius:~ caius$ irb >> require "spec" => true >> include Spec::Matchers => Object >> %w(1 2 3).should have(3).items => true C --- Caius Durling caius at caius.name +44 (0) 7960 268 100 http://caius.name/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Wed Oct 15 03:10:49 2008 From: lists at ruby-forum.com (Alr Alr) Date: Wed, 15 Oct 2008 09:10:49 +0200 Subject: [rspec-users] how to play with rSpec using irb In-Reply-To: References: Message-ID: > Julius:~ caius$ irb > >> require "spec" > => true > >> include Spec::Matchers > => Object > >> %w(1 2 3).should have(3).items > => true > > C > --- > Caius Durling > caius at caius.name > +44 (0) 7960 268 100 > http://caius.name/ thx, its working. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Wed Oct 15 04:52:11 2008 From: lists at ruby-forum.com (Juanma Cervera) Date: Wed, 15 Oct 2008 10:52:11 +0200 Subject: [rspec-users] Rails config.gem and rspec, rspec-rails In-Reply-To: <85d99afe0810132148o38944398o16ee2bd7b3a42402@mail.gmail.com> References: <85d99afe0810132148o38944398o16ee2bd7b3a42402@mail.gmail.com> Message-ID: Zach Dennis wrote: > In #rspec the instructions for installing rspec and rspec-rails on a > Rails project. Specifically talking about the following line from > http://github.com/dchelimsky/rspec-rails/wikis/home > > config.gem "rspec-rails", :lib => "spec" > > I think this should be updated to not instruct people to do this. > Rails config.gem will *load* all configured gems in all environments > which isn't what I thikn people expect. Simply having people move > these config.gem statements into the appropriate environment file also > doesn't work quite as expected (at least not with the rake tasks that > surround gem usage in Rails). > > If folks use the gem versions I think the wiki should advise them to > run "gem unpack rspec rspec-rails" inside of vendor/gems. > Besides, I get this warning when that line in environment.rb irb: warn: can't alias context from irb_context I don't understand the implications, only telling this because may be useful for someone. -- Posted via http://www.ruby-forum.com/. From aidy.lewis at googlemail.com Wed Oct 15 06:26:56 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Wed, 15 Oct 2008 11:26:56 +0100 Subject: [rspec-users] extend Cucumber's arguments Message-ID: <7ac2300c0810150326o495e54e5s9c8f070d258ad0c2@mail.gmail.com> Hi, We would like to pass in some additional command line arguments into Cucumber (for example to specify which browser to run the tests with). Is there any way to extend Cucumber's arguments, or could you suggest an alternative way of going about this? Aid From aslak.hellesoy at gmail.com Wed Oct 15 07:11:50 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 15 Oct 2008 13:11:50 +0200 Subject: [rspec-users] extend Cucumber's arguments In-Reply-To: <7ac2300c0810150326o495e54e5s9c8f070d258ad0c2@mail.gmail.com> References: <7ac2300c0810150326o495e54e5s9c8f070d258ad0c2@mail.gmail.com> Message-ID: <8d961d900810150411m2f900427id82eb4bbedf39438@mail.gmail.com> On Wed, Oct 15, 2008 at 12:26 PM, aidy lewis wrote: > Hi, > > We would like to pass in some additional command line arguments into > Cucumber (for example to specify which browser to run the tests with). > > Is there any way to extend Cucumber's arguments, or could you suggest > an alternative way of going about this? > I recommend you use environment variables for this. ENV['BROWSER_NAME'] in Ruby and BROWSER_NAME=firefox on the command line. Aslak > Aid > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mark at mwilden.com Wed Oct 15 13:26:00 2008 From: mark at mwilden.com (Mark Wilden) Date: Wed, 15 Oct 2008 10:26:00 -0700 Subject: [rspec-users] Just a quick question on David's new-controller-examples In-Reply-To: References: Message-ID: <3c30da400810151026j48a76b81v4aded1af07b1fcec@mail.gmail.com> I have a different question about the article (pity comments are closed). def mock_account(stubs={}) stubs = { :save => true, :update_attributes => true, :destroy => true, :to_xml => '' }.merge(stubs) @mock_account ||= mock_model(Account, stubs) end With this helper, doesn't @mock_account only get set once inside its 'describe' block? Any future tests would use the same @mock_account, even if other stubs were designated. I'm probably missing something very obvious. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From smingins at elctech.com Wed Oct 15 13:58:40 2008 From: smingins at elctech.com (Shane Mingins) Date: Thu, 16 Oct 2008 06:58:40 +1300 Subject: [rspec-users] Just a quick question on David's new-controller-examples In-Reply-To: <3c30da400810151026j48a76b81v4aded1af07b1fcec@mail.gmail.com> References: <3c30da400810151026j48a76b81v4aded1af07b1fcec@mail.gmail.com> Message-ID: <7D090ED5-CC60-4BE3-AC34-82E69F3AB50E@elctech.com> Hi Mark Yeah I was looking at that later on too. And yes if you use in a 'before' it does. Only setting in an 'it' block is ok. I was using this as a quick test as we are on an older version of rspec and I was checking if it may have changed but this fails on 1.1.8 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe PersonController do def mock_person(stubs={}) @person ||= mock_model(Person, stubs) end describe "GET" do before(:each) do mock_person(:name => "fred") end it "should have name fred" do @person.name.should == "fred" end it "should have name steve" do mock_person(:name => "steve") @person.name.should == "steve" end end describe "POST" do it "should have name steve" do mock_person(:name => "steve") @person.name.should == "steve" end it "should have name bob" do mock_person(:name => "bob") @person.name.should == "bob" end end end 1) 'PersonController GET should have name steve' FAILED expected: "steve", got: "fred" (using ==) ./spec/controllers/person_controller_spec.rb:21: Finished in 0.295898 seconds 6 examples, 1 failure On 16/10/2008, at 6:26 AM, Mark Wilden wrote: > I have a different question about the article (pity comments are > closed). > > def mock_account(stubs={}) > stubs = { > :save => true, > :update_attributes => true, > :destroy => true, > > :to_xml => '' > }.merge(stubs) > @mock_account ||= mock_model(Account, stubs) > end > > > With this helper, doesn't @mock_account only get set once inside its > 'describe' block? Any future tests would use the same @mock_account, > even if other stubs were designated. > > I'm probably missing something very obvious. > > ///ark > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Shane Mingins ELC Technologies (TM) 1921 State Street Santa Barbara, CA 93101 Phone: +64 4 568 6684 Mobile: +64 21 435 586 Email: smingins at elctech.com AIM: ShaneMingins Skype: shane.mingins (866) 863-7365 Tel - Santa Barbara Office (866) 893-1902 Fax - Santa Barbara Office +44 020 7504 1346 Tel - London Office +44 020 7504 1347 Fax - London Office http://www.elctech.com -------------------------------------------------------------------- Privacy and Confidentiality Notice: The information contained in this electronic mail message is intended for the named recipient(s) only. It may contain privileged and confidential information. If you are not an intended recipient, you must not copy, forward, distribute or take any action in reliance on it. If you have received this electronic mail message in -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 4000 bytes Desc: not available URL: From nick at deadorange.com Wed Oct 15 16:31:37 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 15 Oct 2008 16:31:37 -0400 Subject: [rspec-users] How to spec accessing a constant Message-ID: <4D8A62C5-3AC9-4D2F-B052-862D2AC1DCFC@deadorange.com> Hi guys. One of my methods uses a constant in another method, like this: class A def something "foo: #{B::BAR}" end end When writing the spec for A#something , how would you mock or stub #{B::BAR}, and how would you set an expectation that B::BAR is used? Thanks, Nick From cdemyanovich at gmail.com Wed Oct 15 16:39:12 2008 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Wed, 15 Oct 2008 16:39:12 -0400 Subject: [rspec-users] How to spec accessing a constant In-Reply-To: <4D8A62C5-3AC9-4D2F-B052-862D2AC1DCFC@deadorange.com> References: <4D8A62C5-3AC9-4D2F-B052-862D2AC1DCFC@deadorange.com> Message-ID: <61c885db0810151339h6c2ef226g385be032d55fa0c9@mail.gmail.com> Probably, I would just check the outcome of the method instead of checking interaction with a constant. Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Wed Oct 15 16:43:20 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 15 Oct 2008 16:43:20 -0400 Subject: [rspec-users] How to spec accessing a constant In-Reply-To: <61c885db0810151339h6c2ef226g385be032d55fa0c9@mail.gmail.com> References: <4D8A62C5-3AC9-4D2F-B052-862D2AC1DCFC@deadorange.com> <61c885db0810151339h6c2ef226g385be032d55fa0c9@mail.gmail.com> Message-ID: <85d99afe0810151343q96f498j911147ace95a9cca@mail.gmail.com> On Wed, Oct 15, 2008 at 4:39 PM, Craig Demyanovich wrote: > Probably, I would just check the outcome of the method instead of checking > interaction with a constant. > What he said, -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From lists at ruby-forum.com Wed Oct 15 18:24:18 2008 From: lists at ruby-forum.com (Jon Dahl) Date: Thu, 16 Oct 2008 00:24:18 +0200 Subject: [rspec-users] autotest with a non-rspec project In-Reply-To: <57c63afe0809171131m7a0adcb1w89b23905bfaf9a36@mail.gmail.com> References: <39f10c3d-f545-4de8-9fbb-778d0171b5ff@b38g2000prf.googlegroups.com> <57c63afe0809171131m7a0adcb1w89b23905bfaf9a36@mail.gmail.com> Message-ID: I'm getting the same error - I'm using Test::Unit with Shoulda for this particular project, and can't autotest because it is trying to load autotest/rails_rspec. David Chelimsky wrote: > The only reason that I know of that this would be happening would be > that there are both a spec directory in your app and the rspec gem > somewhere on your path. I don't have a spec directory in the app, except perhaps in a plugin; and I tried uninstalling the RSpec gem. But it is still trying to load autotest/rails_rspec, and failing. > > We've introduced an autospec command since the last release just to > avoid this conflict. So one thing you might try doing is cloning the > git repo, building and installing the gem from source (see > http://github.com/dchelimsky/rspec/wikis). > Are you talking about autospec as a replacement for autotest (which wouldn't seem to help the Test::Unit autotest problem), or a rewrite of autotest/Zentest that includes separate commands for autospec (RSpec-only) and autotest (Test::Unit only)? Thanks! -- Posted via http://www.ruby-forum.com/. From nick at deadorange.com Wed Oct 15 20:47:52 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 15 Oct 2008 20:47:52 -0400 Subject: [rspec-users] How to spec accessing a constant In-Reply-To: <61c885db0810151339h6c2ef226g385be032d55fa0c9@mail.gmail.com> References: <4D8A62C5-3AC9-4D2F-B052-862D2AC1DCFC@deadorange.com> <61c885db0810151339h6c2ef226g385be032d55fa0c9@mail.gmail.com> Message-ID: On 2008-10-15, at 16:39, Craig Demyanovich wrote: > Probably, I would just check the outcome of the method instead of > checking interaction with a constant. > > Craig So you guys wouldn't worry about the spec for class A being coupled to this constant in class B? -Nick From cdemyanovich at gmail.com Wed Oct 15 21:59:09 2008 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Wed, 15 Oct 2008 21:59:09 -0400 Subject: [rspec-users] How to spec accessing a constant In-Reply-To: References: <4D8A62C5-3AC9-4D2F-B052-862D2AC1DCFC@deadorange.com> <61c885db0810151339h6c2ef226g385be032d55fa0c9@mail.gmail.com> Message-ID: <61c885db0810151859r14ff5a5ai389bc1726456d4a9@mail.gmail.com> On Wed, Oct 15, 2008 at 8:47 PM, Nick Hoffman wrote: > On 2008-10-15, at 16:39, Craig Demyanovich wrote: > >> Probably, I would just check the outcome of the method instead of checking >> interaction with a constant. >> >> Craig >> > > So you guys wouldn't worry about the spec for class A being coupled to this > constant in class B? Since class A is coupled to class B, the specs for A are also coupled to class B through class A. Thus, I wouldn't worry about the coupling. Why does a method of class A directly access a constant of class B? Does the constant belong in class A? Does the method belong in class B? If you can and want to be more specific with your code and specs, I'm sure that we can all write some specs together. Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Oct 15 23:34:28 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 16 Oct 2008 01:34:28 -0200 Subject: [rspec-users] autotest with a non-rspec project In-Reply-To: References: <39f10c3d-f545-4de8-9fbb-778d0171b5ff@b38g2000prf.googlegroups.com> <57c63afe0809171131m7a0adcb1w89b23905bfaf9a36@mail.gmail.com> Message-ID: <57c63afe0810152034vb1fcb49q142d89cb3ede7ac6@mail.gmail.com> On Wed, Oct 15, 2008 at 8:24 PM, Jon Dahl wrote: > I'm getting the same error - I'm using Test::Unit with Shoulda for this > particular project, and can't autotest because it is trying to load > autotest/rails_rspec. > > David Chelimsky wrote: >> The only reason that I know of that this would be happening would be >> that there are both a spec directory in your app and the rspec gem >> somewhere on your path. > > I don't have a spec directory in the app, except perhaps in a plugin; > and I tried uninstalling the RSpec gem. But it is still trying to load > autotest/rails_rspec, and failing. > >> >> We've introduced an autospec command since the last release just to >> avoid this conflict. So one thing you might try doing is cloning the >> git repo, building and installing the gem from source (see >> http://github.com/dchelimsky/rspec/wikis). >> > > Are you talking about autospec as a replacement for autotest (which > wouldn't seem to help the Test::Unit autotest problem), or a rewrite of > autotest/Zentest that includes separate commands for autospec > (RSpec-only) and autotest (Test::Unit only)? I introduced autospec in 1.1.5 in response to this ticket: http://rspec.lighthouseapp.com/projects/5645/tickets/394 Basically, we set it up so when you run autotest, rspec won't announce itself to autotest's discovery system unless an env variable is set. autospec sets this variable and then calls autotest. That's it. So, unless there's a bug that I'm not seeing, the only way this could be happening is if you have either an rspec gem older than 1.1.5 or you have an older version of the rspec plugin. HTH, David > > Thanks! > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Thu Oct 16 01:47:31 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 16 Oct 2008 01:47:31 -0400 Subject: [rspec-users] How to spec accessing a constant In-Reply-To: <4D8A62C5-3AC9-4D2F-B052-862D2AC1DCFC@deadorange.com> References: <4D8A62C5-3AC9-4D2F-B052-862D2AC1DCFC@deadorange.com> Message-ID: On Oct 15, 2008, at 4:31 PM, Nick Hoffman wrote: > Hi guys. One of my methods uses a constant in another method, like > this: > > class A > def something > "foo: #{B::BAR}" > end > end > > When writing the spec for A#something , how would you mock or stub > #{B::BAR}, and how would you set an expectation that B::BAR is used? Just hide the constant behind a method, something like this: class A def something; "foo :#{bar}"; end def bar; B::BAR; end end This allows you to stub the constant, if need be. Scott From davegamphaniphiri at gmail.com Thu Oct 16 02:50:27 2008 From: davegamphaniphiri at gmail.com (Dave Gamphani Phiri) Date: Thu, 16 Oct 2008 08:50:27 +0200 Subject: [rspec-users] testing a render layout statement in a controller Message-ID: <48F6E433.9020405@gmail.com> I am new to rSpec and I am writing a test for a controller which has already been developed This is the example in my reports_controller_spec.rb: it "should render the layouts/menu template" do get :select_missing_persons response.should render_template("layouts/menu") end and this is the method in the reports_controller.rb def select_missing_identifiers render(:layout => "layouts/menu") end I am getting the following output when running autotest: 'ReportsController should render the layouts/menu template' FAILED expected "layouts/menu", got "reports/select_missing_persons" ./spec/controllers/reports_controller_spec.rb:39: script/spec:4: Here, I was trying to test if the out put displays with a layouts/menu template. Can somebody help on how you test the render(:layout => "layouts/ menu") statement in a controller or this is supposed to be tested in the view? -------------- next part -------------- A non-text attachment was scrubbed... Name: davegamphaniphiri.vcf Type: text/x-vcard Size: 165 bytes Desc: not available URL: From weiwei9 at gmail.com Thu Oct 16 02:56:27 2008 From: weiwei9 at gmail.com (wei wei) Date: Thu, 16 Oct 2008 14:56:27 +0800 Subject: [rspec-users] testing a render layout statement in a controller In-Reply-To: <48F6E433.9020405@gmail.com> References: <48F6E433.9020405@gmail.com> Message-ID: <784ae8ca0810152356h16d07588ude5e81fc7b212245@mail.gmail.com> Try to write a customized matcher, here is an example # custom matchers #--------------------- class UseLayout def initialize(expected) @expected = 'layouts/' + expected + '_layout' end def matches?(controller) @actual = controller.layout #@actual.equal?(@expected) @actual == @expected end def failure_message return "use_layout expected #{@expected.inspect}, got #{@actual.inspect}", @expected, @actual end def negative_failure_message return "use_layout expected #{@expected.inspect} not to equal #{@actual.inspect}", @expected, @actual end end def use_layout(expected) UseLayout.new(expected) end On Thu, Oct 16, 2008 at 2:50 PM, Dave Gamphani Phiri < davegamphaniphiri at gmail.com> wrote: > I am new to rSpec and I am writing a test for a controller which has > already been developed > > This is the example in my reports_controller_spec.rb: > > it "should render the layouts/menu template" do > get :select_missing_persons > response.should render_template("layouts/menu") > end > > and this is the method in the reports_controller.rb > > def select_missing_identifiers > render(:layout => "layouts/menu") > end > > I am getting the following output when running autotest: > > 'ReportsController should render the layouts/menu template' FAILED > expected "layouts/menu", got "reports/select_missing_persons" > ./spec/controllers/reports_controller_spec.rb:39: > script/spec:4: > > Here, I was trying to test if the out put displays with a layouts/menu > template. > Can somebody help on how you test the render(:layout => "layouts/ > menu") statement in a controller or this is supposed to be tested in > the view? > > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- Wei Wei -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Thu Oct 16 06:31:40 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 16 Oct 2008 11:31:40 +0100 Subject: [rspec-users] Rails: View specs and implicit parameters in link_to() Message-ID: Hi all, I've been cleaning up our routing file, and removed the default map.connect ":controller/:action" route. It's thrown up a bunch of sloppy mistakes, which is great, but I also think I've found a problem with the view specs. We have a generic navbar partial which is rendered in the index page of several different controllers. The navbar contains some call to link_to of the form: <%= link_to "By Concert", :sort => 'by_concert' %> Since I removed the default (catch-all) route, this fails in the view specs: > No route matches {:action => "index", :sort => "by_concert" At runtime, rails seems to figure out the controller as well, and we get a full URL built fine. I tried adding this to my specs params[:controller] = "images" but nothing changed. I've worked around it by also doing this in the view: <%= link_to "By Concert", :controller => params[:controller], :sort => 'by_concert' %> This seems kind of dirty... and it's also weird that I can't seem to be able to fake the context that the views render in at runtime. What do other people do with this sort of problem? Am I missing something obvious? cheers, Matt From lists at ruby-forum.com Thu Oct 16 07:59:42 2008 From: lists at ruby-forum.com (Dave Phiri) Date: Thu, 16 Oct 2008 13:59:42 +0200 Subject: [rspec-users] specifying a controller's layout In-Reply-To: <57c63afe0809040705k6febf022q104956ef8a5a2e7d@mail.gmail.com> References: <5158D394-5811-41A5-9102-0CB8D0CE5D70@mattwynne.net> <57c63afe0809040705k6febf022q104956ef8a5a2e7d@mail.gmail.com> Message-ID: David Chelimsky wrote: > On Thu, Sep 4, 2008 at 8:42 AM, Matt Wynne wrote: >> I want to spec that a controller uses a particular layout >> how do I do that? > > Depends on what else is going on, but this is the simplest situation: > > controller.expect_render(:layout => 'special_layout') > get :some_action David: Why is it that get :some_action controller.expect_render(:layout => 'special_layout') ie having the get statement before the controller.expect.. statement produces the ff error: Mock 'expect_render_mock_proxy' expected :render with ({:layout=>"special_layout"}) once, but received it 0 times Thanks -- Posted via http://www.ruby-forum.com/. From mark.thomson at ieee.org Thu Oct 16 09:16:08 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Thu, 16 Oct 2008 08:16:08 -0500 Subject: [rspec-users] Mocking documentation Message-ID: <48F73E98.4020003@ieee.org> Can I make a suggestion for the RSpec documentation? In the discussion of Spec::Mocks (http://rspec.info/documentation/mocks/), it would be helpful for there to be some explanation of mock_model. There's a reference to mock_model in an example in the section on controller specs, but as far I can see no indication of how it differs from mock. If I've just missed it please let me know. "The Rails Way" has a nice simple explanation. Something like that would be helpful in the official documentation. Mark. From jarmo.p at gmail.com Thu Oct 16 09:17:25 2008 From: jarmo.p at gmail.com (juuuser) Date: Thu, 16 Oct 2008 06:17:25 -0700 (PDT) Subject: [rspec-users] Any good conferences this year about ruby/rspec/watir? Message-ID: <20013634.post@talk.nabble.com> Hello. Sorry for this little offtopic question, but I was wondering if anyone happens to know if there's any good conferences coming up about rspec or ruby or watir in this year where I could attend to? Or any good website where such things are listed or something similar. All suggested conferences should not take place before one month from now (employer needs some time to get good plane tickets and so on). -- View this message in context: http://www.nabble.com/Any-good-conferences-this-year-about-ruby-rspec-watir--tp20013634p20013634.html Sent from the rspec-users mailing list archive at Nabble.com. From jim at saturnflyer.com Thu Oct 16 09:49:07 2008 From: jim at saturnflyer.com (Jim Gay) Date: Thu, 16 Oct 2008 09:49:07 -0400 Subject: [rspec-users] specifying a controller's layout In-Reply-To: References: <5158D394-5811-41A5-9102-0CB8D0CE5D70@mattwynne.net> <57c63afe0809040705k6febf022q104956ef8a5a2e7d@mail.gmail.com> Message-ID: <902549D2-62CB-43ED-B598-F672D630D36C@saturnflyer.com> On Oct 16, 2008, at 7:59 AM, Dave Phiri wrote: > David Chelimsky wrote: >> On Thu, Sep 4, 2008 at 8:42 AM, Matt Wynne >> wrote: >>> I want to spec that a controller uses a particular layout >>> how do I do that? >> >> Depends on what else is going on, but this is the simplest situation: >> >> controller.expect_render(:layout => 'special_layout') >> get :some_action > > David: > Why is it that > > get :some_action > controller.expect_render(:layout => 'special_layout') > > ie having the get statement before the controller.expect.. statement > produces the ff error: > Mock 'expect_render_mock_proxy' expected :render with > ({:layout=>"special_layout"}) once, but received it 0 times Because you are creating an expectation for the following action. In your code above, you are doing the action, and then creating an expectation for a following action which never occurs, so it receives it 0 times following that expectation. -Jim From lists at ruby-forum.com Thu Oct 16 10:06:05 2008 From: lists at ruby-forum.com (Dave Phiri) Date: Thu, 16 Oct 2008 16:06:05 +0200 Subject: [rspec-users] specifying a controller's layout In-Reply-To: <902549D2-62CB-43ED-B598-F672D630D36C@saturnflyer.com> References: <5158D394-5811-41A5-9102-0CB8D0CE5D70@mattwynne.net> <57c63afe0809040705k6febf022q104956ef8a5a2e7d@mail.gmail.com> <902549D2-62CB-43ED-B598-F672D630D36C@saturnflyer.com> Message-ID: Jim Gay wrote: > On Oct 16, 2008, at 7:59 AM, Dave Phiri wrote: > >> >> David: >> Why is it that >> >> get :some_action >> controller.expect_render(:layout => 'special_layout') >> >> ie having the get statement before the controller.expect.. statement >> produces the ff error: >> Mock 'expect_render_mock_proxy' expected :render with >> ({:layout=>"special_layout"}) once, but received it 0 times > > Because you are creating an expectation for the following action. > In your code above, you are doing the action, and then creating an > expectation for a following action which never occurs, so it receives > it 0 times following that expectation. > > -Jim Thanks Jim, It all now makes sense to me. I am barely a wk old in rspec. A lot many thanks! Dave -- Posted via http://www.ruby-forum.com/. From jarkko at jlaine.net Thu Oct 16 10:45:25 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Thu, 16 Oct 2008 17:45:25 +0300 Subject: [rspec-users] Any good conferences this year about ruby/rspec/watir? In-Reply-To: <20013634.post@talk.nabble.com> References: <20013634.post@talk.nabble.com> Message-ID: On 16.10.2008, at 16.17, juuuser wrote: > Hello. > > Sorry for this little offtopic question, but I was wondering if anyone > happens to know if there's any good conferences coming up about > rspec or > ruby or watir in this year where I could attend to? Since you seem to be fluent in Finnish: http://rapidstraining.fi/ ;-) //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 sfeley at gmail.com Thu Oct 16 11:02:44 2008 From: sfeley at gmail.com (Stephen Eley) Date: Thu, 16 Oct 2008 11:02:44 -0400 Subject: [rspec-users] specifying a controller's layout In-Reply-To: <902549D2-62CB-43ED-B598-F672D630D36C@saturnflyer.com> References: <5158D394-5811-41A5-9102-0CB8D0CE5D70@mattwynne.net> <57c63afe0809040705k6febf022q104956ef8a5a2e7d@mail.gmail.com> <902549D2-62CB-43ED-B598-F672D630D36C@saturnflyer.com> Message-ID: <1fb4df0810160802q4e0cf256lea7b25b019f199a@mail.gmail.com> On Thu, Oct 16, 2008 at 9:49 AM, Jim Gay wrote: > > Because you are creating an expectation for the following action. > In your code above, you are doing the action, and then creating an > expectation for a following action which never occurs, so it receives it 0 > times following that expectation. This confused me too at first. To put it another way: (1) controller.expect_render(:layout => 'index') [set expectation] (2) get :index [perform action] ...is equivalent to... (1) Call spouse to say "Honey, I'm coming home, see you shortly." (2) Go home and kiss spouse. Putting the "get" first and then setting the "expect" would be equivalent to: (1) Go home and kiss spouse. (2) Call spouse to say "Honey, I'm coming home, see you shortly." Your spouse's natural reaction would be "Ummmm...." Which is basically what RSpec is telling you by that error message when you do the 'get' then the 'expect.' -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From nick at deadorange.com Thu Oct 16 11:22:19 2008 From: nick at deadorange.com (Nick Hoffman) Date: Thu, 16 Oct 2008 11:22:19 -0400 Subject: [rspec-users] How to spec accessing a constant In-Reply-To: <61c885db0810151859r14ff5a5ai389bc1726456d4a9@mail.gmail.com> References: <4D8A62C5-3AC9-4D2F-B052-862D2AC1DCFC@deadorange.com> <61c885db0810151339h6c2ef226g385be032d55fa0c9@mail.gmail.com> <61c885db0810151859r14ff5a5ai389bc1726456d4a9@mail.gmail.com> Message-ID: On 2008-10-15, at 21:59, Craig Demyanovich wrote: > Since class A is coupled to class B, the specs for A are also > coupled to class B through class A. Thus, I wouldn't worry about the > coupling. Why does a method of class A directly access a constant of > class B? Does the constant belong in class A? Does the method belong > in class B? If you can and want to be more specific with your code > and specs, I'm sure that we can all write some specs together. > > Regards, > Craig Hi Craig. Here're some code snippets: http://pastie.org/293925 Property#javascript_map_marker_code generates the Javascript code necessary to: 1) Create a [Google] map marker that represents a property instance. 2) Add the marker to the map. To perform #2, RentalMap::MAP_NAME must be accessed somehow, be it directly, or through a method as Scott suggested. RentalMap::MAP_NAME should definitely be part of the RentalMap model. It should not be part of the Property model. Property#javascript_map_marker_code belongs in the Property model, because it acts upon (IE: uses several attributes of) a Property instance. Cheers, Nick From baz at madeofstone.net Thu Oct 16 11:18:39 2008 From: baz at madeofstone.net (Rahoul Baruah) Date: Thu, 16 Oct 2008 16:18:39 +0100 Subject: [rspec-users] specifying a controller's layout In-Reply-To: <1fb4df0810160802q4e0cf256lea7b25b019f199a@mail.gmail.com> References: <5158D394-5811-41A5-9102-0CB8D0CE5D70@mattwynne.net> <57c63afe0809040705k6febf022q104956ef8a5a2e7d@mail.gmail.com> <902549D2-62CB-43ED-B598-F672D630D36C@saturnflyer.com> <1fb4df0810160802q4e0cf256lea7b25b019f199a@mail.gmail.com> Message-ID: <32287665-86B0-47B1-AE77-BA57FD992017@madeofstone.net> On 16 Oct 2008, at 16:02, Stephen Eley wrote: > This confused me too at first. To put it another way: > > (1) controller.expect_render(:layout => 'index') [set expectation] > (2) get :index [perform action] > > ...is equivalent to... > > (1) Call spouse to say "Honey, I'm coming home, see you shortly." > (2) Go home and kiss spouse. I've written some helpers for this - nothing complex, just reverses the order that things happen in: when_getting :index do expect_some_stuff_to_happen end The helper itself looks like this: def when_getting action, parameters = {} yield if block_given? get action, parameters end Likewise there is when_posting_to, when_putting_to and when_deleting_from One day (soon) I'll get round to packaging them up and submitting them as a patch. Rahoul Baruah Web design and development: http://www.3hv.co.uk/ Nottingham Forest: http://www.eighteensixtyfive.co.uk/ Serious Rails Hosting: http://www.brightbox.co.uk/ Lifecast: http://www.madeofstone.net/ From cdemyanovich at gmail.com Thu Oct 16 15:12:22 2008 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Thu, 16 Oct 2008 15:12:22 -0400 Subject: [rspec-users] How to spec accessing a constant In-Reply-To: References: <4D8A62C5-3AC9-4D2F-B052-862D2AC1DCFC@deadorange.com> <61c885db0810151339h6c2ef226g385be032d55fa0c9@mail.gmail.com> <61c885db0810151859r14ff5a5ai389bc1726456d4a9@mail.gmail.com> Message-ID: <61c885db0810161212l15e6cfa6h704cb1088a0b94eb@mail.gmail.com> Cool. Having seen something a little more concrete, I like your design decisions. In this case, I'd go with Scott's recommendation of hiding the constant behind a method. Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashley.moran at patchspace.co.uk Thu Oct 16 16:28:26 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 16 Oct 2008 21:28:26 +0100 Subject: [rspec-users] RSpec vs Screw.Unit Message-ID: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> Hi Hope this isn't OT. I'm currently contemplating using the Dojo[1] JavaScript framework, and I suspect it's powerful enough that using Cucumber features and Celerity alone will quickly leave me wanting lower-level unit specs for the JS. So I just wondered if anyone here has used Screw.Unit[2], and if so, how does it compare to RSpec? It seems to offer many of the features of RSpec (with the notable exception of shared behaviours). Thanks Ashley [1] http://dojotoolkit.org/ [2] http://github.com/nkallen/screw-unit/tree/master -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Thu Oct 16 16:47:10 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 16 Oct 2008 21:47:10 +0100 Subject: [rspec-users] Mocks: expectations vs spying Message-ID: <60782FC3-38CF-4469-BEA7-BBAA9E8DC862@patchspace.co.uk> Hi again Ok, so I'm having a little research fling with JavaScript, and I've uncovered something I hadn't seen before: "spying". Basically, inspecting mocks after-the-fact, rather than setting expectations upfront. Here are the articles I found: http://ajaxian.com/archives/mockme-a-new-javascript-mocking-framework http://blog.johanneslink.net/2008/08/08/ajax-travelogue-part-6-mocking-in-javascript/ http://blog.johanneslink.net/2008/08/09/ajax-travelogue-part-7-mockme/ Does anyone know more about this technique, and its pros and cons vs expectation-based mocking as used in RSpec mocks? Thanks for any info Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ben at benmabey.com Thu Oct 16 17:02:21 2008 From: ben at benmabey.com (Ben Mabey) Date: Thu, 16 Oct 2008 15:02:21 -0600 Subject: [rspec-users] Mocks: expectations vs spying In-Reply-To: <60782FC3-38CF-4469-BEA7-BBAA9E8DC862@patchspace.co.uk> References: <60782FC3-38CF-4469-BEA7-BBAA9E8DC862@patchspace.co.uk> Message-ID: <48F7ABDD.4050900@benmabey.com> Ashley Moran wrote: > Hi again > > Ok, so I'm having a little research fling with JavaScript, and I've > uncovered something I hadn't seen before: "spying". Basically, > inspecting mocks after-the-fact, rather than setting expectations > upfront. > > Here are the articles I found: > http://ajaxian.com/archives/mockme-a-new-javascript-mocking-framework > http://blog.johanneslink.net/2008/08/08/ajax-travelogue-part-6-mocking-in-javascript/ > > http://blog.johanneslink.net/2008/08/09/ajax-travelogue-part-7-mockme/ > > Does anyone know more about this technique, and its pros and cons vs > expectation-based mocking as used in RSpec mocks? > > Thanks for any info > Ashley > Pat has been working on adding the spy pattern to rspec and JoeSniff has already added it to the rr mocking framework on github I believe. There have been some recent posts on this mailing list about it. Searching for spy in this groups past threads should give you some links to learn more. HTH -Ben From nick at deadorange.com Thu Oct 16 17:24:14 2008 From: nick at deadorange.com (Nick Hoffman) Date: Thu, 16 Oct 2008 17:24:14 -0400 Subject: [rspec-users] How to spec accessing a constant In-Reply-To: <61c885db0810161212l15e6cfa6h704cb1088a0b94eb@mail.gmail.com> References: <4D8A62C5-3AC9-4D2F-B052-862D2AC1DCFC@deadorange.com> <61c885db0810151339h6c2ef226g385be032d55fa0c9@mail.gmail.com> <61c885db0810151859r14ff5a5ai389bc1726456d4a9@mail.gmail.com> <61c885db0810161212l15e6cfa6h704cb1088a0b94eb@mail.gmail.com> Message-ID: On 2008-10-16, at 15:12, Craig Demyanovich wrote: > Cool. Having seen something a little more concrete, I like your > design decisions. In this case, I'd go with Scott's recommendation > of hiding the constant behind a method. > > Regards, > Craig Thanks for taking a look, Craig, and giving me your opinion. Cheers, Nick From ashley.moran at patchspace.co.uk Thu Oct 16 18:41:44 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 16 Oct 2008 23:41:44 +0100 Subject: [rspec-users] Mocks: expectations vs spying In-Reply-To: <48F7ABDD.4050900@benmabey.com> References: <60782FC3-38CF-4469-BEA7-BBAA9E8DC862@patchspace.co.uk> <48F7ABDD.4050900@benmabey.com> Message-ID: <62526A7D-C3FD-4D2C-95E4-C2AFA94DCDD0@patchspace.co.uk> On Oct 16, 2008, at 10:02 pm, Ben Mabey wrote: > Pat has been working on adding the spy pattern to rspec and JoeSniff > has already added it to the rr mocking framework on github I > believe. There have been some recent posts on this mailing list > about it. Searching for spy in this groups past threads should give > you some links to learn more. HTH Hi Ben Ah, the original post about this was on my birthday, no wonder I missed it :) Sorry for the I'm-too-damn-lazy-too-search-my-inbox post! Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From dchelimsky at gmail.com Thu Oct 16 18:43:44 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 16 Oct 2008 20:43:44 -0200 Subject: [rspec-users] Just a quick question on David's new-controller-examples In-Reply-To: <7D090ED5-CC60-4BE3-AC34-82E69F3AB50E@elctech.com> References: <3c30da400810151026j48a76b81v4aded1af07b1fcec@mail.gmail.com> <7D090ED5-CC60-4BE3-AC34-82E69F3AB50E@elctech.com> Message-ID: <57c63afe0810161543y60baef5cl78df0c718a6ba00c@mail.gmail.com> On Wed, Oct 15, 2008 at 3:58 PM, Shane Mingins wrote: > Hi Mark > > Yeah I was looking at that later on too. And yes if you use in a 'before' > it does. Only setting in an 'it' block is ok. > > I was using this as a quick test as we are on an older version of rspec and > I was checking if it may have changed but this fails on 1.1.8 > > require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') > > describe PersonController do > > def mock_person(stubs={}) > @person ||= mock_model(Person, stubs) > end > > describe "GET" do > > before(:each) do > mock_person(:name => "fred") > end > > it "should have name fred" do > @person.name.should == "fred" > end > > it "should have name steve" do > mock_person(:name => "steve") > @person.name.should == "steve" > end > > end > > describe "POST" do > > it "should have name steve" do > mock_person(:name => "steve") > @person.name.should == "steve" > end > > it "should have name bob" do > mock_person(:name => "bob") > @person.name.should == "bob" > end > > end > > end > > > > 1) > 'PersonController GET should have name steve' FAILED > expected: "steve", > got: "fred" (using ==) > ./spec/controllers/person_controller_spec.rb:21: > > Finished in 0.295898 seconds > > 6 examples, 1 failure Admittedly, this is a violation of the principal of least surprise, but your analysis of the problem is not quite accurate. Each example is run in its own instance of the group (just like xUnit frameworks) and has its own state. before(:each) gets run, as it says, before each example in the context of its own instance of the group. So what's happening is that the mock_person(:name => "fred") in the before is creating the instance, whereas the mock_person(:name => "steve") in the example is not actually creating a new object - it essentially does nothing :( I think that the mock_person method probably needs to be smarter so if it's already been called AND it gets args it raises an error. WDYT? > > > > > > > On 16/10/2008, at 6:26 AM, Mark Wilden wrote: > >> I have a different question about the article (pity comments are closed). >> >> def mock_account(stubs={}) >> stubs = { >> :save => true, >> :update_attributes => true, >> :destroy => true, >> >> :to_xml => '' >> }.merge(stubs) >> @mock_account ||= mock_model(Account, stubs) >> end >> >> >> With this helper, doesn't @mock_account only get set once inside its >> 'describe' block? Any future tests would use the same @mock_account, even if >> other stubs were designated. >> >> I'm probably missing something very obvious. >> >> ///ark >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > Shane Mingins > ELC Technologies (TM) > 1921 State Street > Santa Barbara, CA 93101 > > > Phone: +64 4 568 6684 > Mobile: +64 21 435 586 > Email: smingins at elctech.com > AIM: ShaneMingins > Skype: shane.mingins > > (866) 863-7365 Tel - Santa Barbara Office > (866) 893-1902 Fax - Santa Barbara Office > > +44 020 7504 1346 Tel - London Office > +44 020 7504 1347 Fax - London Office > > http://www.elctech.com > > -------------------------------------------------------------------- > Privacy and Confidentiality Notice: > The information contained in this electronic mail message is intended for > the named recipient(s) only. It may contain privileged and confidential > information. If you are not an intended recipient, you must not copy, > forward, distribute or take any action in reliance on it. If you have > received this electronic mail message in > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Fri Oct 17 01:14:38 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 17 Oct 2008 03:14:38 -0200 Subject: [rspec-users] Mocking documentation In-Reply-To: <48F73E98.4020003@ieee.org> References: <48F73E98.4020003@ieee.org> Message-ID: <57c63afe0810162214m5a9060f1gc9c682281170d69f@mail.gmail.com> On Thu, Oct 16, 2008 at 11:16 AM, Mark Thomson wrote: > Can I make a suggestion for the RSpec documentation? Please put requests like this in lighthouse. Even though we're behind on tickets there, it's the only way to ensure things stay on the radar. Thanks, David > In the discussion of > Spec::Mocks (http://rspec.info/documentation/mocks/), it would be helpful > for there to be some explanation of mock_model. There's a reference to > mock_model in an example in the section on controller specs, but as far I > can see no indication of how it differs from mock. If I've just missed it > please let me know. "The Rails Way" has a nice simple explanation. Something > like that would be helpful in the official documentation. > > Mark. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Fri Oct 17 01:35:13 2008 From: lists at ruby-forum.com (Mano ah) Date: Fri, 17 Oct 2008 07:35:13 +0200 Subject: [rspec-users] How to test a controller Message-ID: <62b7e35300f7a185148ac754d0e037ad@ruby-forum.com> I want to test the controllers of an existing project. How can i do it. Actually when I use ruby script/spec rspec_scaffold modelname it creates a spec controller for that model and a controller inside the app folder. So for testing an already existing project how should i proceed. -- Posted via http://www.ruby-forum.com/. From aslak.hellesoy at gmail.com Fri Oct 17 01:37:53 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Fri, 17 Oct 2008 07:37:53 +0200 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> Message-ID: <8d961d900810162237h63eb2bbdw481cc9653e45fbca@mail.gmail.com> On Thu, Oct 16, 2008 at 10:28 PM, Ashley Moran wrote: > Hi > > Hope this isn't OT. I'm currently contemplating using the Dojo[1] > JavaScript framework, and I suspect it's powerful enough that using Cucumber > features and Celerity alone will quickly leave me wanting lower-level unit > specs for the JS. > > So I just wondered if anyone here has used Screw.Unit[2], and if so, how > does it compare to RSpec? It seems to offer many of the features of RSpec > (with the notable exception of shared behaviours). > I haven't used it, but I have heard good things about JSSpec and Jack javascript mocking. Aslak > Thanks > Ashley > > [1] http://dojotoolkit.org/ > [2] http://github.com/nkallen/screw-unit/tree/master > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Fri Oct 17 01:44:59 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Fri, 17 Oct 2008 01:44:59 -0400 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> Message-ID: On Oct 16, 2008, at 4:28 PM, Ashley Moran wrote: > Hi > > Hope this isn't OT. I'm currently contemplating using the Dojo[1] > JavaScript framework, and I suspect it's powerful enough that using > Cucumber features and Celerity alone will quickly leave me wanting > lower-level unit specs for the JS. > > So I just wondered if anyone here has used Screw.Unit[2], and if so, > how does it compare to RSpec? It seems to offer many of the > features of RSpec (with the notable exception of shared behaviours). I've been using it a bunch, and I must say that so far I've really enjoyed it. Here are the downsides that I've noticed: 1. It's much more verbose, and doesn't read quite as cleanly as rspec. Instead of foo.should == "bar", you'll end up with: expect(foo()).to(equal, bar()); Which just gets a bit syntax heavy. I'm sure that they didn't want to polute the global namespace, but maybe a function like this might solve the problem: Object.prototype.should = function(obj) { expect(this).to(equal, arg); }; 2. The matchers just aren't there the way they are for rspec. This can make a big difference to code readability. Obviously, you could build them yourself. (This is just a matter of time, and standing on the shoulders of giants sort of thing). 3. I haven't looked very hard, but I haven't found a plain text runner yet. Obviously it's going to need a browser if you're planning on doing DOM interaction (which is very easy). For me, though, a plain text runner would be awsome. Scott > > > Thanks > Ashley > > [1] http://dojotoolkit.org/ > [2] http://github.com/nkallen/screw-unit/tree/master > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From sfeley at gmail.com Fri Oct 17 02:28:30 2008 From: sfeley at gmail.com (Stephen Eley) Date: Fri, 17 Oct 2008 02:28:30 -0400 Subject: [rspec-users] How to test a controller In-Reply-To: <62b7e35300f7a185148ac754d0e037ad@ruby-forum.com> References: <62b7e35300f7a185148ac754d0e037ad@ruby-forum.com> Message-ID: <1fb4df0810162328w23fdc303u34e4981f2ded1823@mail.gmail.com> On Fri, Oct 17, 2008 at 1:35 AM, Mano ah wrote: > I want to test the controllers of an existing project. How can i do it. > > Actually when I use ruby script/spec rspec_scaffold modelname it > creates a spec controller for that model and a controller inside the app > folder. The really obvious (and probably unhelpful) answer would be, "Just write the specs, dude." Expanding on that: there's nothing magic about the specs generated by the scaffold. I'm not even sure that they're great specs; they're just one opinion on how to test the default, plain-vanilla Rails actions. They'll stop passing the moment you change anything, and then you'll have to understand what they're doing and fix them. (And any non-trivial Rails app _will_ end up doing _something_ different than what the default scaffold controllers do.) I know in my case, I didn't understand the controller specs at all until I wrote some by hand. And then I wrote some more by hand, and understood them better. For a while I was using make_resourceful and mock_resourceful... I stopped, and rewrote those by hand, because there was too much magic and I couldn't follow what was going on. The end result was more lines of code, but it was just as good as what the plugins did and better-suited to my requirements, and I _understood_ it. That's worth more than the specs themselves are worth. So ignore the scaffold stuff, unless you want to look back at it as a reference example, and write some specs for the way your controller currently behaves. Do some mock objects for your models...or don't, as mocking too is just a matter of opinion. But test that the models are at least being called to find the right objects. Write at least one spec for the output of each controller action, making sure it renders what you want it to, and then write more if you think you need them. Keep doing this, and keep maintaining your specs the same way you'd refactor the actual code, and eventually you'll start to Get It. You'll feel good about your specs without having to ask anyone. Eventually you'll look at the example code and go, "Man, I can do better!" At that point, congratulations. You've cleared the level. Proceed to Level 2 -- whatever that may be for your particular style. Just don't stop learning things. If you stop, Donkey Kong keeps the girl. Hope this was helpful. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From lists at ruby-forum.com Fri Oct 17 02:57:24 2008 From: lists at ruby-forum.com (Mano ah) Date: Fri, 17 Oct 2008 08:57:24 +0200 Subject: [rspec-users] How to test a controller In-Reply-To: <1fb4df0810162328w23fdc303u34e4981f2ded1823@mail.gmail.com> References: <62b7e35300f7a185148ac754d0e037ad@ruby-forum.com> <1fb4df0810162328w23fdc303u34e4981f2ded1823@mail.gmail.com> Message-ID: Thank you stephen. Though it is easy to write spec for controller something stoped me like I am proceeding the wrong way. Your words gives confidence. so let me try and get back to you. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Oct 17 03:26:30 2008 From: lists at ruby-forum.com (Mano ah) Date: Fri, 17 Oct 2008 09:26:30 +0200 Subject: [rspec-users] How to test a controller In-Reply-To: References: <62b7e35300f7a185148ac754d0e037ad@ruby-forum.com> <1fb4df0810162328w23fdc303u34e4981f2ded1823@mail.gmail.com> Message-ID: <0575545e9a3293194c071d9c697de35c@ruby-forum.com> Steph I sucessfully wrote my first test -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Fri Oct 17 05:41:28 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 17 Oct 2008 10:41:28 +0100 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> Message-ID: <1403D871-4F47-4D46-A86B-91732D8AD4CB@mattwynne.net> On 17 Oct 2008, at 06:44, Scott Taylor wrote: > On Oct 16, 2008, at 4:28 PM, Ashley Moran wrote: > >> Hi >> >> Hope this isn't OT. I'm currently contemplating using the Dojo[1] >> JavaScript framework, and I suspect it's powerful enough that using >> Cucumber features and Celerity alone will quickly leave me wanting >> lower-level unit specs for the JS. >> >> So I just wondered if anyone here has used Screw.Unit[2], and if >> so, how does it compare to RSpec? It seems to offer many of the >> features of RSpec (with the notable exception of shared behaviours). I'm also interested in this, as we're currently deciding which route to go. I like the philosophy behind screw unit - it feels like the team want to give us RSpec for javascript. One of the things that has irritated me (and generally does with javascript unit testing) is that running the tests is quite slow and requires selenium. I did a little spike to run them via celerity instead: http://gist.github.com/15273 > 3. I haven't looked very hard, but I haven't found a plain text > runner yet. Obviously it's going to need a browser if you're > planning on doing DOM interaction (which is very easy). For me, > though, a plain text runner would be awsome. Do you mean a story-runner that just works on the javascript / HTML, as opposed to running the full stack including the server-side? From avdi at avdi.org Fri Oct 17 09:47:19 2008 From: avdi at avdi.org (Avdi Grimm) Date: Fri, 17 Oct 2008 09:47:19 -0400 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> Message-ID: On Thu, Oct 16, 2008 at 4:28 PM, Ashley Moran wrote: > So I just wondered if anyone here has used Screw.Unit[2], and if so, how > does it compare to RSpec? It seems to offer many of the features of RSpec > (with the notable exception of shared behaviours). I just want to thank you for reminding to checkout Screw.Unit. Somebody mentioned it the other day but I forgot to look it up. We've been using JSSpec for our JS tests, but it looks like Screw is JSSpec on crack. It addresses the main thing I missed form RSpec: nested describes. I'm definitely going to be trying this on my next project. -- Avdi Home: http://avdi.org Developer Blog: http://avdi.org/devblog/ Twitter: http://twitter.com/avdi Journal: http://avdi.livejournal.com From ashley.moran at patchspace.co.uk Fri Oct 17 10:47:48 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 17 Oct 2008 15:47:48 +0100 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: <1403D871-4F47-4D46-A86B-91732D8AD4CB@mattwynne.net> References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> <1403D871-4F47-4D46-A86B-91732D8AD4CB@mattwynne.net> Message-ID: On Oct 17, 2008, at 10:41 am, Matt Wynne wrote: > I'm also interested in this, as we're currently deciding which route > to go. > > I like the philosophy behind screw unit - it feels like the team > want to give us RSpec for javascript. That's the feeling I got, that SU is trying to be a cleaner, slicker implementation of JSSpec. I saw someone try JSSpec a few months back and very quickly hit issues with message expectations. As for whether it's "JSSpec on crack*" I will have to try it to see... > One of the things that has irritated me (and generally does with > javascript unit testing) is that running the tests is quite slow and > requires selenium. I did a little spike to run them via celerity > instead: > http://gist.github.com/15273 Awesome! I'll have to try that when I get into JS. Thanks Ashley * Or Akuz if you're in the UK -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From josephwilk at joesniff.co.uk Fri Oct 17 10:54:15 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Fri, 17 Oct 2008 15:54:15 +0100 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> Message-ID: <48F8A717.8010409@joesniff.co.uk> On of the things I've noticed with ScrewUnit is to quote the ScrewUnit wiki: "The dynamic nature of JavaScript makes mocking frameworks mostly unnecessary" A small but interesting difference from using Ruby, Rspec and its built-in mocking framework. -- Joseph Wilk http://www.joesniff.co.uk Scott Taylor wrote: > > On Oct 16, 2008, at 4:28 PM, Ashley Moran wrote: > >> Hi >> >> Hope this isn't OT. I'm currently contemplating using the Dojo[1] >> JavaScript framework, and I suspect it's powerful enough that using >> Cucumber features and Celerity alone will quickly leave me wanting >> lower-level unit specs for the JS. >> >> So I just wondered if anyone here has used Screw.Unit[2], and if so, >> how does it compare to RSpec? It seems to offer many of the features >> of RSpec (with the notable exception of shared behaviours). > > I've been using it a bunch, and I must say that so far I've really > enjoyed it. Here are the downsides that I've noticed: > > 1. It's much more verbose, and doesn't read quite as cleanly as > rspec. Instead of foo.should == "bar", you'll end up with: > > expect(foo()).to(equal, bar()); > > Which just gets a bit syntax heavy. I'm sure that they didn't want to > polute the global namespace, but maybe a function like this might > solve the problem: > > Object.prototype.should = function(obj) { > expect(this).to(equal, arg); > }; > > 2. The matchers just aren't there the way they are for rspec. This > can make a big difference to code readability. Obviously, you could > build them yourself. (This is just a matter of time, and standing on > the shoulders of giants sort of thing). > > 3. I haven't looked very hard, but I haven't found a plain text > runner yet. Obviously it's going to need a browser if you're planning > on doing DOM interaction (which is very easy). For me, though, a > plain text runner would be awsome. > > Scott > > >> >> >> Thanks >> Ashley >> >> [1] http://dojotoolkit.org/ >> [2] http://github.com/nkallen/screw-unit/tree/master >> >> -- >> http://www.patchspace.co.uk/ >> http://aviewfromafar.net/ >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sfeley at gmail.com Fri Oct 17 11:42:25 2008 From: sfeley at gmail.com (Stephen Eley) Date: Fri, 17 Oct 2008 11:42:25 -0400 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: <48F8A717.8010409@joesniff.co.uk> References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> <48F8A717.8010409@joesniff.co.uk> Message-ID: <1fb4df0810170842g55b528a0p5face7b51a876aa1@mail.gmail.com> On Fri, Oct 17, 2008 at 10:54 AM, Joseph Wilk wrote: > > "The dynamic nature of JavaScript makes mocking frameworks mostly > unnecessary" > > A small but interesting difference from using Ruby, Rspec and its built-in > mocking framework. So... Wait. Is the implication here that Ruby is *too static?* Or just the way people are using Ruby, including RSpec? I guess I'll have to check that other framework out to see what that means. It's not very often that you hear anyone suggesting that Ruby isn't dynamic enough. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From lists at ruby-forum.com Fri Oct 17 14:46:58 2008 From: lists at ruby-forum.com (Rasmus Rasmussen) Date: Fri, 17 Oct 2008 20:46:58 +0200 Subject: [rspec-users] Where are those tables listed for fixtures? Message-ID: <945556fa1748b8deb2016d1c96727db1@ruby-forum.com> I'm sorry if this is posted in wrong forum. I am new to all of this with rails and rspec. Something got messed up when I changed a table's name from 'works' to 'work_periods'. Now the fixture:load thing does not work. Obviously the old table is still in there in some file. Anyone have any idea on where to find that file? Where does rspec read all tables when it deletes table-entries? > >rake db:fixtures:load > >rake aborted! >Mysql::Error: #42S02Table 'db_development.works' doesn't exist: DELETE FROM works > -- Posted via http://www.ruby-forum.com/. From mark.thomson at ieee.org Fri Oct 17 14:55:22 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Fri, 17 Oct 2008 13:55:22 -0500 Subject: [rspec-users] Surprising mock behavior Message-ID: <48F8DF9A.6040708@ieee.org> I'm writing my first controller spec - for a controller that already exists, and in the process have observed some behavior I find a little surprising. I'd like to know whether I'm interpreting the situation correctly... In my controller I have some stuff written to a file, i.e. file = File.new(...) ... file.puts "a string" ... file.puts "another string" etc In my spec I mock the file object - file = mock('file') File.stub!(:new).and_return(file) and then check that the expected messages are being received - file.should_receive(:puts).with("a string").once file.should_receive(:puts).with("another string").once etc. Here's what I'm puzzled about. If I don't include the expectation for the first string in the spec, the spec will fail the expectation for the second string. It seems as if "should_receive" is queuing up the messages that come into the file object and when it tests an expectation it just looks at the next one in line. If it doesn't match then the expectation will fail. Is that really what happens? Or have I missed some important insight? Seems counterintuitive to me. What is strange is that I was working away on this yesterday and just picking out a number of particular puts to test that I was concerned about. It seemed to be working the way I expected it to. Then late yesterday I started seeing some spec failures I didn't understand and my investigation led me to the conclusion above. Interested to know if what I think I'm seeing is consistent with other people's experience and with the intended behavior of mocks. Mark. From zach.dennis at gmail.com Fri Oct 17 14:57:49 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 17 Oct 2008 14:57:49 -0400 Subject: [rspec-users] Where are those tables listed for fixtures? In-Reply-To: <945556fa1748b8deb2016d1c96727db1@ruby-forum.com> References: <945556fa1748b8deb2016d1c96727db1@ruby-forum.com> Message-ID: <85d99afe0810171157j23fadd78l5558c0923d8b4a8c@mail.gmail.com> Do you still have "works.yml" in your fixtures/ directory? If so you'll need to rename that to "work_periods.yml". Zach On Fri, Oct 17, 2008 at 2:46 PM, Rasmus Rasmussen wrote: > I'm sorry if this is posted in wrong forum. I am new to all of this with > rails and rspec. > > Something got messed up when I changed a table's name from 'works' to > 'work_periods'. Now the fixture:load thing does not work. Obviously the > old table is still in there in some file. > > Anyone have any idea on where to find that file? Where does rspec read > all tables when it deletes table-entries? > >> >>rake db:fixtures:load >> >>rake aborted! >>Mysql::Error: #42S02Table 'db_development.works' doesn't exist: DELETE FROM works >> > -- > 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 http://www.mutuallyhuman.com From lists at ruby-forum.com Fri Oct 17 15:08:42 2008 From: lists at ruby-forum.com (Rasmus Rasmussen) Date: Fri, 17 Oct 2008 21:08:42 +0200 Subject: [rspec-users] Where are those tables listed for fixtures? In-Reply-To: <85d99afe0810171157j23fadd78l5558c0923d8b4a8c@mail.gmail.com> References: <945556fa1748b8deb2016d1c96727db1@ruby-forum.com> <85d99afe0810171157j23fadd78l5558c0923d8b4a8c@mail.gmail.com> Message-ID: Zach Dennis wrote: > Do you still have "works.yml" in your fixtures/ directory? If so > you'll need to rename that to "work_periods.yml". > > Zach > > On Fri, Oct 17, 2008 at 2:46 PM, Rasmus Rasmussen > wrote: >>> >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Zach Dennis > http://www.continuousthinking.com > http://www.mutuallyhuman.com Nope, but I really wished it was this simple. (it probably is!) I cannot find any traces from "works" or "Work" anywhere in whole project. I found the file in rspec that prints the msg: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/fixtures.rb. Perhaps there is a clever way to redefine that class to get more tracing? -- Posted via http://www.ruby-forum.com/. From mark.thomson at ieee.org Fri Oct 17 15:10:07 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Fri, 17 Oct 2008 14:10:07 -0500 Subject: [rspec-users] Surprising mock behavior In-Reply-To: <48F8DF9A.6040708@ieee.org> References: <48F8DF9A.6040708@ieee.org> Message-ID: <48F8E30F.7050306@ieee.org> Actually, this is evidently not the whole story. I actually have two examples in the same spec, and I just realized that the other one has instances of file.should_receive(:puts) that don't seem to suffer the same limitation I described. So it looks like there is something about the example I described that is causing it to behave strangely. Will investigate further. Mark. Mark Thomson wrote: > I'm writing my first controller spec - for a controller that already > exists, and in the process have observed some behavior I find a little > surprising. I'd like to know whether I'm interpreting the situation > correctly... > > In my controller I have some stuff written to a file, i.e. > > file = File.new(...) > ... > file.puts "a string" > ... > file.puts "another string" > > etc > > > In my spec I mock the file object - > > file = mock('file') > File.stub!(:new).and_return(file) > > and then check that the expected messages are being received - > > file.should_receive(:puts).with("a string").once > file.should_receive(:puts).with("another string").once > > etc. > > > Here's what I'm puzzled about. If I don't include the expectation for > the first string in the spec, the spec will fail the expectation for > the second string. It seems as if "should_receive" is queuing up the > messages that come into the file object and when it tests an > expectation it just looks at the next one in line. If it doesn't match > then the expectation will fail. > > Is that really what happens? Or have I missed some important insight? > Seems counterintuitive to me. What is strange is that I was working > away on this yesterday and just picking out a number of particular > puts to test that I was concerned about. It seemed to be working the > way I expected it to. Then late yesterday I started seeing some spec > failures I didn't understand and my investigation led me to the > conclusion above. > > Interested to know if what I think I'm seeing is consistent with other > people's experience and with the intended behavior of mocks. > > Mark. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > From nick at deadorange.com Fri Oct 17 15:14:18 2008 From: nick at deadorange.com (Nick Hoffman) Date: Fri, 17 Oct 2008 15:14:18 -0400 Subject: [rspec-users] Surprising mock behavior In-Reply-To: <48F8DF9A.6040708@ieee.org> References: <48F8DF9A.6040708@ieee.org> Message-ID: On 2008-10-17, at 14:55, Mark Thomson wrote: > ..snip.. > It seems as if "should_receive" is queuing up the messages that come > into the file object and when it tests an expectation it just looks > at the next one in line. If it doesn't match then the expectation > will fail. Hi Mark. From my understanding and experiences with RSpec, that's correct behaviour. Essentially, you're defining an ordered list of messages you expect to be called on the 'file' object. Cheers, Nick From nick at deadorange.com Fri Oct 17 15:17:28 2008 From: nick at deadorange.com (Nick Hoffman) Date: Fri, 17 Oct 2008 15:17:28 -0400 Subject: [rspec-users] Where are those tables listed for fixtures? In-Reply-To: <945556fa1748b8deb2016d1c96727db1@ruby-forum.com> References: <945556fa1748b8deb2016d1c96727db1@ruby-forum.com> Message-ID: On 2008-10-17, at 14:46, Rasmus Rasmussen wrote: > I'm sorry if this is posted in wrong forum. I am new to all of this > with > rails and rspec. > > Something got messed up when I changed a table's name from 'works' to > 'work_periods'. Now the fixture:load thing does not work. Obviously > the > old table is still in there in some file. > > Anyone have any idea on where to find that file? Where does rspec read > all tables when it deletes table-entries? > >> >> rake db:fixtures:load >> >> rake aborted! >> Mysql::Error: #42S02Table 'db_development.works' doesn't exist: >> DELETE FROM works >> Hi Rasmus. Have you grepped through your application for "works", and looked for all files named "*works*"? Eg: $ grep -rni 'works' /path/to/app/ $ find /path/to/app/ -iname '*works*' Hope that helps, Nick From lists at ruby-forum.com Fri Oct 17 15:28:24 2008 From: lists at ruby-forum.com (Rasmus Rasmussen) Date: Fri, 17 Oct 2008 21:28:24 +0200 Subject: [rspec-users] Where are those tables listed for fixtures? In-Reply-To: References: <945556fa1748b8deb2016d1c96727db1@ruby-forum.com> <85d99afe0810171157j23fadd78l5558c0923d8b4a8c@mail.gmail.com> Message-ID: <4161d3f8dbe811df9f8e93dbf25bfb6f@ruby-forum.com> Rasmus Rasmussen wrote: > Zach Dennis wrote: >> Do you still have "works.yml" in your fixtures/ directory? If so >> you'll need to rename that to "work_periods.yml". >> >> Zach, you are right, there is another fixture under "test". I only searched in "spec"-dir. And I am in the wrong forum :-) Guess the yaml's are placed under test because i ran generators with "model" instead of "spec_model" this feels like a duplication. If I write rspec-tests I should not do ordinary tests, because then I need to maintain two fixtures. Right? -- Posted via http://www.ruby-forum.com/. From sfeley at gmail.com Fri Oct 17 15:37:01 2008 From: sfeley at gmail.com (Stephen Eley) Date: Fri, 17 Oct 2008 15:37:01 -0400 Subject: [rspec-users] Surprising mock behavior In-Reply-To: <48F8DF9A.6040708@ieee.org> References: <48F8DF9A.6040708@ieee.org> Message-ID: <1fb4df0810171237k5e5425d0ye954364bc3e58ab8@mail.gmail.com> On Fri, Oct 17, 2008 at 2:55 PM, Mark Thomson wrote: > > and then check that the expected messages are being received - > file.should_receive(:puts).with("a string").once > file.should_receive(:puts).with("another string").once > > Here's what I'm puzzled about. If I don't include the expectation for the > first string in the spec, the spec will fail the expectation for the second > string. It seems as if "should_receive" is queuing up the messages that come > into the file object and when it tests an expectation it just looks at the > next one in line. If it doesn't match then the expectation will fail. That sounds right to me. You declared 'file' as a mock. Mocks are bratty little children that treat it as an error and throw a tantrum if you don't give them everything they expect, no more nor less. (As contrasted to stubs, which are couch potatoes that will respond if you call them but don't complain if you don't.) So when you create a mock, you need to be very thorough about it. Every message has to be accounted for somehow. If it gets more messages than you tell it, or different messages, it'll error. If it doesn't get enough messages, it'll error. This is correct behavior. If the exact parameters aren't part of your test plan, you could always say file.should_receive(:puts).twice and leave off the parameter expectation. Or just file.should_receive(:puts) if you know it should happen but don't care how often, or file.should_receive(:puts).any_number_of_times if it could be zero as well. Or, if that all sounds like too much work, make 'file' a stub object instead of a mock object and stub the :puts method: file = stub('file', :puts => true) File.stub!(:new).and_return(file) ...and then only set should_receive for the things you care about in specific tests. Does that help, or is the behavior still anomalous even knowing that mocks are super-finicky? -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From sfeley at gmail.com Fri Oct 17 15:42:36 2008 From: sfeley at gmail.com (Stephen Eley) Date: Fri, 17 Oct 2008 15:42:36 -0400 Subject: [rspec-users] Where are those tables listed for fixtures? In-Reply-To: <945556fa1748b8deb2016d1c96727db1@ruby-forum.com> References: <945556fa1748b8deb2016d1c96727db1@ruby-forum.com> Message-ID: <1fb4df0810171242h368d7b5eib4cfd5aab7e3977e@mail.gmail.com> On Fri, Oct 17, 2008 at 2:46 PM, Rasmus Rasmussen wrote: > > Something got messed up when I changed a table's name from 'works' to > 'work_periods'. Now the fixture:load thing does not work. Obviously the > old table is still in there in some file. Dumb question, but did you clone or re-migrate your test database after you made this change? This trips me up all the time. I'll do something clever with the database, run db:migrate, and totally forget that that doesn't update the test environment, just development. Then my specs fail and I freak out. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From mark at mwilden.com Fri Oct 17 15:42:33 2008 From: mark at mwilden.com (Mark Wilden) Date: Fri, 17 Oct 2008 12:42:33 -0700 Subject: [rspec-users] Surprising mock behavior In-Reply-To: <48F8DF9A.6040708@ieee.org> References: <48F8DF9A.6040708@ieee.org> Message-ID: <3c30da400810171242l5a24e6e3h30478ac3782f351f@mail.gmail.com> On Fri, Oct 17, 2008 at 11:55 AM, Mark Thomson wrote: > It seems as if "should_receive" is queuing up the messages that come into > the file object and when it tests an expectation it just looks at the next > one in line. If it doesn't match then the expectation will fail. > Yup. Pretty cool, huh? ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Fri Oct 17 15:51:13 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 17 Oct 2008 15:51:13 -0400 Subject: [rspec-users] Where are those tables listed for fixtures? In-Reply-To: <1fb4df0810171242h368d7b5eib4cfd5aab7e3977e@mail.gmail.com> References: <945556fa1748b8deb2016d1c96727db1@ruby-forum.com> <1fb4df0810171242h368d7b5eib4cfd5aab7e3977e@mail.gmail.com> Message-ID: <85d99afe0810171251p64eb2522h271c758d1c2bb8b@mail.gmail.com> On Fri, Oct 17, 2008 at 3:42 PM, Stephen Eley wrote: > On Fri, Oct 17, 2008 at 2:46 PM, Rasmus Rasmussen wrote: >> >> Something got messed up when I changed a table's name from 'works' to >> 'work_periods'. Now the fixture:load thing does not work. Obviously the >> old table is still in there in some file. > > Dumb question, but did you clone or re-migrate your test database > after you made this change? > > This trips me up all the time. I'll do something clever with the > database, run db:migrate, and totally forget that that doesn't update > the test environment, just development. Then my specs fail and I > freak out. I use this command line alias after I write a migration: alias tmig='rake db:migrate && rake db:rollback && rake db:migrate && rake db:test:prepare' It makes sure that I can migrate up and down for the migration I just wrote, and it will make sure the test database is prepared. Zach > > > -- > Have Fun, > Steve Eley (sfeley at gmail.com) > ESCAPE POD - The Science Fiction Podcast Magazine > http://www.escapepod.org > _______________________________________________ > 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 zach.dennis at gmail.com Fri Oct 17 15:54:36 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Fri, 17 Oct 2008 15:54:36 -0400 Subject: [rspec-users] Surprising mock behavior In-Reply-To: <1fb4df0810171237k5e5425d0ye954364bc3e58ab8@mail.gmail.com> References: <48F8DF9A.6040708@ieee.org> <1fb4df0810171237k5e5425d0ye954364bc3e58ab8@mail.gmail.com> Message-ID: <85d99afe0810171254v9e9698bic8ab38b91ea60414@mail.gmail.com> On Fri, Oct 17, 2008 at 3:37 PM, Stephen Eley wrote: > On Fri, Oct 17, 2008 at 2:55 PM, Mark Thomson wrote: >> >> and then check that the expected messages are being received - >> file.should_receive(:puts).with("a string").once >> file.should_receive(:puts).with("another string").once >> >> Here's what I'm puzzled about. If I don't include the expectation for the >> first string in the spec, the spec will fail the expectation for the second >> string. It seems as if "should_receive" is queuing up the messages that come >> into the file object and when it tests an expectation it just looks at the >> next one in line. If it doesn't match then the expectation will fail. > > That sounds right to me. You declared 'file' as a mock. Mocks are > bratty little children that treat it as an error and throw a tantrum > if you don't give them everything they expect, no more nor less. Are you a proud parent? :) -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From sfeley at gmail.com Fri Oct 17 16:11:02 2008 From: sfeley at gmail.com (Stephen Eley) Date: Fri, 17 Oct 2008 16:11:02 -0400 Subject: [rspec-users] Surprising mock behavior In-Reply-To: <85d99afe0810171254v9e9698bic8ab38b91ea60414@mail.gmail.com> References: <48F8DF9A.6040708@ieee.org> <1fb4df0810171237k5e5425d0ye954364bc3e58ab8@mail.gmail.com> <85d99afe0810171254v9e9698bic8ab38b91ea60414@mail.gmail.com> Message-ID: <1fb4df0810171311pa5ccc83m1f2f6125aa00b8aa@mail.gmail.com> On Fri, Oct 17, 2008 at 3:54 PM, Zach Dennis wrote: > On Fri, Oct 17, 2008 at 3:37 PM, Stephen Eley wrote: >> >> That sounds right to me. You declared 'file' as a mock. Mocks are >> bratty little children that treat it as an error and throw a tantrum >> if you don't give them everything they expect, no more nor less. > > Are you a proud parent? :) Yes, very. And I mock my three-year-old's behavior often. I also tell him what he should_receive; what he returns, alas, is not yet deterministic. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From mark at mwilden.com Fri Oct 17 16:25:35 2008 From: mark at mwilden.com (Mark Wilden) Date: Fri, 17 Oct 2008 13:25:35 -0700 Subject: [rspec-users] Where are those tables listed for fixtures? In-Reply-To: <85d99afe0810171251p64eb2522h271c758d1c2bb8b@mail.gmail.com> References: <945556fa1748b8deb2016d1c96727db1@ruby-forum.com> <1fb4df0810171242h368d7b5eib4cfd5aab7e3977e@mail.gmail.com> <85d99afe0810171251p64eb2522h271c758d1c2bb8b@mail.gmail.com> Message-ID: <3c30da400810171325l195ef392g79d532ca8a083698@mail.gmail.com> On Fri, Oct 17, 2008 at 12:51 PM, Zach Dennis wrote: > alias tmig='rake db:migrate && rake db:rollback && rake db:migrate > && rake db:test:prepare' > Sounds good. Nice to see someone paying attention to their downs as well as their ups. rake db:migrate:redo will do the rollback + the re-migration in one step, saving some time. ///ar -------------- next part -------------- An HTML attachment was scrubbed... URL: From sfeley at gmail.com Fri Oct 17 16:56:34 2008 From: sfeley at gmail.com (Stephen Eley) Date: Fri, 17 Oct 2008 16:56:34 -0400 Subject: [rspec-users] Where are those tables listed for fixtures? In-Reply-To: <4161d3f8dbe811df9f8e93dbf25bfb6f@ruby-forum.com> References: <945556fa1748b8deb2016d1c96727db1@ruby-forum.com> <85d99afe0810171157j23fadd78l5558c0923d8b4a8c@mail.gmail.com> <4161d3f8dbe811df9f8e93dbf25bfb6f@ruby-forum.com> Message-ID: <1fb4df0810171356g1f2dc27fmcd1b19d37ff8e316@mail.gmail.com> On Fri, Oct 17, 2008 at 3:28 PM, Rasmus Rasmussen wrote: > > this feels like a duplication. If I write rspec-tests I should not do > ordinary tests, because then I need to maintain two fixtures. Right? Correct. You don't need it. But the standard Rails generator doesn't know that you're sneaking around on it with RSpec, so it keeps putting boxes of chocolates in your /test directory hoping you'll pay more attention to it and never knowing why you don't come home. It's quite touching, really. Maybe even a little poignant. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From dchelimsky at gmail.com Fri Oct 17 17:16:03 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 17 Oct 2008 19:16:03 -0200 Subject: [rspec-users] specifying a controller's layout In-Reply-To: <32287665-86B0-47B1-AE77-BA57FD992017@madeofstone.net> References: <5158D394-5811-41A5-9102-0CB8D0CE5D70@mattwynne.net> <57c63afe0809040705k6febf022q104956ef8a5a2e7d@mail.gmail.com> <902549D2-62CB-43ED-B598-F672D630D36C@saturnflyer.com> <1fb4df0810160802q4e0cf256lea7b25b019f199a@mail.gmail.com> <32287665-86B0-47B1-AE77-BA57FD992017@madeofstone.net> Message-ID: <57c63afe0810171416w320aca95r68ca7dd88c2c017c@mail.gmail.com> On Thu, Oct 16, 2008 at 1:18 PM, Rahoul Baruah wrote: > > On 16 Oct 2008, at 16:02, Stephen Eley wrote: > >> This confused me too at first. To put it another way: >> >> (1) controller.expect_render(:layout => 'index') [set expectation] >> (2) get :index [perform action] >> >> ...is equivalent to... >> >> (1) Call spouse to say "Honey, I'm coming home, see you shortly." >> (2) Go home and kiss spouse. > > I've written some helpers for this - nothing complex, just reverses the > order that things happen in: > > when_getting :index do > expect_some_stuff_to_happen > end > > The helper itself looks like this: > > def when_getting action, parameters = {} > yield if block_given? > get action, parameters > end > > Likewise there is when_posting_to, when_putting_to and when_deleting_from > > One day (soon) I'll get round to packaging them up and submitting them as a > patch. Cool. Don't forget the seldom used #head, though I don't know what to call it: when_heading_to? > > > Rahoul Baruah > Web design and development: http://www.3hv.co.uk/ > Nottingham Forest: http://www.eighteensixtyfive.co.uk/ > Serious Rails Hosting: http://www.brightbox.co.uk/ > Lifecast: http://www.madeofstone.net/ > > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bill at williamtozier.com Fri Oct 17 20:34:38 2008 From: bill at williamtozier.com (William Tozier) Date: Fri, 17 Oct 2008 20:34:38 -0400 Subject: [rspec-users] Cucumber "standard base" setup? Message-ID: I'm trying to set up cucumber so we can try it in some Ruby automation scripts I'm working on. These will be straight Ruby, for use in BBEdit and TextMate (on the Mac). NOT Rails. The big early-stage stumbling block I'm having is setting up the initial Rakefile and directory structure. I think I'm rtfm'ing, but clearly I'm missing whatever I need to get past square one. We'll be working on Leopard boxes, with clean and up-to-date gem installs across the board. Most of our coding is in TextMate, and the cucumber gem works AOK already. All the gems seem to be here, and the example files in the cucumber repository work as expected. But I'm not understanding what a minimal setup for a NEW project should be. * I need a Rakefile... but with what exactly in it? Many of the examples are different, and at least a few fail to run on my box (but that's external dependencies). What's the bare minimum I need to have in a plain, empty Rakefile? * A cucumber.yml file, which as I understand it is only needed if I want to set params away from defaults. * A "fixtures" directory... but with what necessary subdirectories in it? * A "lib" directory sometimes... but not in all examples? Am I missing a simple generator script somewhere in the base cucumber install? NOT for Rails -- just for a plain Ruby project? Thanks very much. Again, all I'd really like to do is see a noobs' walkthrough like: (1) create an empty project directory (2) build standard directory tree (3) clone in standard Rakefile (4) get started speccing. (2) and (3) are my problem. Thanks much! ----- Bill Tozier AIM:vaguery at mac.com ? Twitter:Vaguery http://williamtozier.com/slurry "The brotherhood of man is not a mere poet's dream; it is a most depressing and humiliating reality." -- Oscar Wilde From bill at williamtozier.com Fri Oct 17 20:44:32 2008 From: bill at williamtozier.com (William Tozier) Date: Fri, 17 Oct 2008 20:44:32 -0400 Subject: [rspec-users] Cucumber "standard base" setup? In-Reply-To: References: Message-ID: On Oct 17, 2008, at 8:34 PM, William Tozier wrote: > * A "fixtures" directory... but with what necessary subdirectories > in it? Sorry. Meant "features" directory. ----- Bill Tozier AIM:vaguery at mac.com ? Twitter:Vaguery http://williamtozier.com/slurry "The brotherhood of man is not a mere poet's dream; it is a most depressing and humiliating reality." -- Oscar Wilde From nick at deadorange.com Sat Oct 18 00:44:02 2008 From: nick at deadorange.com (Nick Hoffman) Date: Sat, 18 Oct 2008 00:44:02 -0400 Subject: [rspec-users] specifying a controller's layout In-Reply-To: <57c63afe0810171416w320aca95r68ca7dd88c2c017c@mail.gmail.com> References: <5158D394-5811-41A5-9102-0CB8D0CE5D70@mattwynne.net> <57c63afe0809040705k6febf022q104956ef8a5a2e7d@mail.gmail.com> <902549D2-62CB-43ED-B598-F672D630D36C@saturnflyer.com> <1fb4df0810160802q4e0cf256lea7b25b019f199a@mail.gmail.com> <32287665-86B0-47B1-AE77-BA57FD992017@madeofstone.net> <57c63afe0810171416w320aca95r68ca7dd88c2c017c@mail.gmail.com> Message-ID: <73494ED9-6DF5-4675-830A-2EC46B4E8BDB@deadorange.com> On 2008-10-17, at 17:16, David Chelimsky wrote: > Cool. Don't forget the seldom used #head, though I don't know what to > call it: when_heading_to? I looked through the docs at http://rspec.rubyforge.org/rspec/1.1.8/ for #head , but the closest thing I found was #header , which is undocumented. When you have a minute, would you mind telling us about #head please? Thanks! Nick From mailing_lists at railsnewbie.com Sat Oct 18 00:53:18 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 18 Oct 2008 00:53:18 -0400 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: <1fb4df0810170842g55b528a0p5face7b51a876aa1@mail.gmail.com> References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> <48F8A717.8010409@joesniff.co.uk> <1fb4df0810170842g55b528a0p5face7b51a876aa1@mail.gmail.com> Message-ID: On Oct 17, 2008, at 11:42 AM, Stephen Eley wrote: > On Fri, Oct 17, 2008 at 10:54 AM, Joseph Wilk > wrote: >> >> "The dynamic nature of JavaScript makes mocking frameworks mostly >> unnecessary" >> >> A small but interesting difference from using Ruby, Rspec and its >> built-in >> mocking framework. > > So... Wait. Is the implication here that Ruby is *too static?* Or > just the way people are using Ruby, including RSpec? Depends on what you want to do. Honestly, I find it much easier to manipulate methods in javascript rather then ruby. Here's the essential complexity of a stub framework: 1. Store the original method definition (if there is one). 2. Replace the method definition with a new method, this time returning nil/undefined, or a set value. after(:each) => 3. Restore the original method definition 4. Cleanup any mess you've made In Ruby, the first two steps ends up more or less like this: (class << my_obj; self; end).instance_eval <<-HERE alias_method :my_#{original_method}, #{my_method} def #{my_method} #{my_return_value} end HERE In Javascript, it might look more or less like this: var old_method = obj[my_method]; my_obj[my_method] = my_return_value; The point is not that ruby is more static, but that it's just a lot more typing and metaprogramming hoops that you'll need to jump through. Also - notice that javascript, a prototype based language, you can deal with the metaclass/singleton class seamlessly (since there is no class). In Ruby you'll want to be safe and not redefine the method for the whole class (i.e., all instances of the class), but only for the *particular* object you're stubbing. As for the mocking part, this too seems to be an issue of language. I suppose it would depend on how sophisticated you want to get. Here's what appears to be essential for a mock: 1. the ability to stub methods on it 2. An "empty" object - one with no predefined methods. 3. complaining when a method is called on it which hasn't explicitly been defined. #2 seems to be a shoe-in for Javascript - since a regular old object is an "empty" object. In Ruby, you'll need something more or less like BlankSlate, which undef's all it's methods. As for #3, I'm pretty sure that Ruby's method_missing allows one to raise an exception easily. Not sure what a Javascript mocking framework would do in this case. Scott From aslak.hellesoy at gmail.com Sat Oct 18 02:45:35 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 18 Oct 2008 08:45:35 +0200 Subject: [rspec-users] Cucumber "standard base" setup? In-Reply-To: References: Message-ID: <8d961d900810172345r7a6914e0v600c78490e74587a@mail.gmail.com> On Sat, Oct 18, 2008 at 2:34 AM, William Tozier wrote: > I'm trying to set up cucumber so we can try it in some Ruby automation > scripts I'm working on. These will be straight Ruby, for use in BBEdit and > TextMate (on the Mac). > > NOT Rails. > > The big early-stage stumbling block I'm having is setting up the initial > Rakefile and directory structure. I think I'm rtfm'ing, but clearly I'm > missing whatever I need to get past square one. > > We'll be working on Leopard boxes, with clean and up-to-date gem installs > across the board. Most of our coding is in TextMate, and the cucumber gem > works AOK already. All the gems seem to be here, and the example files in > the cucumber repository work as expected. > > But I'm not understanding what a minimal setup for a NEW project should be. > > * I need a Rakefile... but with what exactly in it? Many of the examples are > different, and at least a few fail to run on my box (but that's external > dependencies). What's the bare minimum I need to have in a plain, empty > Rakefile? This: http://github.com/aslakhellesoy/cucumber/tree/master/examples/calculator/Rakefile > * A cucumber.yml file, which as I understand it is only needed if I want to > set params away from defaults. You don't need that - I've removed it from the Calculator example since it might be confusing for newcomers. > * A "fixtures" directory... but with what necessary subdirectories in it? features/ +--*.features +--steps/ +--*_steps.rb > * A "lib" directory sometimes... but not in all examples? Using lib is just a Ruby/Ruby gems convention. You should adjust your $LOAD_PATH to include it. Some examples are simple, so they have the code straight in the steps file. I thought it was obvious that this is not what you'd do on a real project, but rather stick it in lib like 98% of all other Ruby projects do. > > Am I missing a simple generator script somewhere in the base cucumber > install? NOT for Rails -- just for a plain Ruby project? > There is none - you're the first to ask for it. > Thanks very much. Again, all I'd really like to do is see a noobs' > walkthrough like: > (1) create an empty project directory > (2) build standard directory tree > (3) clone in standard Rakefile > (4) get started speccing. > > (2) and (3) are my problem. > Please file individual tickets for things you're missing (docs, generator) and someone will hopefully get to it. Aslak > Thanks much! > ----- > Bill Tozier > AIM:vaguery at mac.com ? Twitter:Vaguery > http://williamtozier.com/slurry > > "The brotherhood of man is not a mere poet's dream; it is a most depressing > and humiliating reality." > -- Oscar Wilde > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Oct 18 03:35:26 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 18 Oct 2008 05:35:26 -0200 Subject: [rspec-users] specifying a controller's layout In-Reply-To: <73494ED9-6DF5-4675-830A-2EC46B4E8BDB@deadorange.com> References: <5158D394-5811-41A5-9102-0CB8D0CE5D70@mattwynne.net> <57c63afe0809040705k6febf022q104956ef8a5a2e7d@mail.gmail.com> <902549D2-62CB-43ED-B598-F672D630D36C@saturnflyer.com> <1fb4df0810160802q4e0cf256lea7b25b019f199a@mail.gmail.com> <32287665-86B0-47B1-AE77-BA57FD992017@madeofstone.net> <57c63afe0810171416w320aca95r68ca7dd88c2c017c@mail.gmail.com> <73494ED9-6DF5-4675-830A-2EC46B4E8BDB@deadorange.com> Message-ID: <57c63afe0810180035x4480c9e4ved018571224e0268@mail.gmail.com> On Sat, Oct 18, 2008 at 2:44 AM, Nick Hoffman wrote: > On 2008-10-17, at 17:16, David Chelimsky wrote: >> >> Cool. Don't forget the seldom used #head, though I don't know what to >> call it: when_heading_to? > > I looked through the docs at http://rspec.rubyforge.org/rspec/1.1.8/ for > #head , but the closest thing I found was #header , which is undocumented. > When you have a minute, would you mind telling us about #head please? It's a rails method, not rspec. Check out ActionController::Base#head. Cheers, David > > Thanks! > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From twa at 3dbyggeri.dk Sat Oct 18 04:40:04 2008 From: twa at 3dbyggeri.dk (Thomas Watson Steen) Date: Sat, 18 Oct 2008 10:40:04 +0200 Subject: [rspec-users] Test HTML output from Rails helper Message-ID: <66BEF894-4C4A-4C3F-B044-1DDFE806E776@3dbyggeri.dk> Hi I'm using RSpec in with Ruby on Rails. I've made a helper module method that generates some HTML and would like to create a rspec test to validate this HTML. I can of cause use regex to validate it as a string, but would much rather validate it by traversing the DOM and checking that the elements I expect is present. Any pointers? /thomas From mailing_lists at railsnewbie.com Sat Oct 18 05:50:22 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 18 Oct 2008 05:50:22 -0400 Subject: [rspec-users] Test HTML output from Rails helper In-Reply-To: <66BEF894-4C4A-4C3F-B044-1DDFE806E776@3dbyggeri.dk> References: <66BEF894-4C4A-4C3F-B044-1DDFE806E776@3dbyggeri.dk> Message-ID: <0A0E308D-3933-437C-AF63-2A617B565E03@railsnewbie.com> On Oct 18, 2008, at 4:40 AM, Thomas Watson Steen wrote: > Hi > > I'm using RSpec in with Ruby on Rails. I've made a helper module > method that generates some HTML and would like to create a rspec > test to validate this HTML. I can of cause use regex to validate it > as a string, but would much rather validate it by traversing the DOM > and checking that the elements I expect is present. Any pointers? No - that's not really an option. The rails stack has no idea about a DOM. One option, though, is to stub methods and use message expectations. For instance, if you had a helper like the following: module MyHelper def my_method(a_name) link_to(a_name, {:controller => "foo", :action => "foo"}) end end You'd be able to write a spec like the following: it "should link with the correct name" do helper.should_receive(:link_to).with("foo", {:controller => "foo", :action => "foo"}) helper.my_method("foo") end Hope that helps, Scott From bill at williamtozier.com Sat Oct 18 07:33:22 2008 From: bill at williamtozier.com (William Tozier) Date: Sat, 18 Oct 2008 07:33:22 -0400 Subject: [rspec-users] Cucumber "standard base" setup? In-Reply-To: <8d961d900810172345r7a6914e0v600c78490e74587a@mail.gmail.com> References: <8d961d900810172345r7a6914e0v600c78490e74587a@mail.gmail.com> Message-ID: <0AF70506-2167-4426-A7BF-6BF5B696C250@williamtozier.com> On Oct 18, 2008, at 2:45 AM, aslak hellesoy wrote: > On Sat, Oct 18, 2008 at 2:34 AM, William Tozier > wrote: >> * I need a Rakefile... but with what exactly in it? Many of the >> examples are >> different, and at least a few fail to run on my box (but that's >> external >> dependencies). What's the bare minimum I need to have in a plain, >> empty >> Rakefile? > > This: http://github.com/aslakhellesoy/cucumber/tree/master/examples/calculator/Rakefile This was the one I had cut-and-pasted in a hand-cooked project that acytually ran, but it might be useful to have some prescriptive word- based infrastructure somewhere that says so. Will ticket it. >> Am I missing a simple generator script somewhere in the base cucumber >> install? NOT for Rails -- just for a plain Ruby project? >> >> Thanks very much. Again, all I'd really like to do is see a noobs' >> walkthrough like: >> (1) create an empty project directory >> (2) build standard directory tree >> (3) clone in standard Rakefile >> (4) get started speccing. >> >> (2) and (3) are my problem. >> > > Please file individual tickets for things you're missing (docs, > generator) and someone will hopefully get to it. Will do. AOK here now. Thanks. ----- Bill Tozier AIM:vaguery at mac.com ? Twitter:Vaguery http://williamtozier.com/slurry "The brotherhood of man is not a mere poet's dream; it is a most depressing and humiliating reality." -- Oscar Wilde From ashley.moran at patchspace.co.uk Sat Oct 18 07:39:06 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sat, 18 Oct 2008 12:39:06 +0100 Subject: [rspec-users] Test HTML output from Rails helper In-Reply-To: <0A0E308D-3933-437C-AF63-2A617B565E03@railsnewbie.com> References: <66BEF894-4C4A-4C3F-B044-1DDFE806E776@3dbyggeri.dk> <0A0E308D-3933-437C-AF63-2A617B565E03@railsnewbie.com> Message-ID: On Oct 18, 2008, at 10:50 am, Scott Taylor wrote: > No - that's not really an option. The rails stack has no idea about > a DOM. > > One option, though, is to stub methods and use message > expectations. For instance, if you had a helper like the following: Hi Scott Another option would be Hpricot[1], which makes manipulating HTML easier than CSV data. Ashley [1] http://code.whytheluckystiff.net/hpricot/ -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From pergesu at gmail.com Sat Oct 18 09:16:19 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 18 Oct 2008 07:16:19 -0600 Subject: [rspec-users] Test HTML output from Rails helper In-Reply-To: <0A0E308D-3933-437C-AF63-2A617B565E03@railsnewbie.com> (Scott Taylor's message of "Sat\, 18 Oct 2008 05\:50\:22 -0400") References: <66BEF894-4C4A-4C3F-B044-1DDFE806E776@3dbyggeri.dk> <0A0E308D-3933-437C-AF63-2A617B565E03@railsnewbie.com> Message-ID: Scott Taylor writes: > On Oct 18, 2008, at 4:40 AM, Thomas Watson Steen wrote: > >> Hi >> >> I'm using RSpec in with Ruby on Rails. I've made a helper module >> method that generates some HTML and would like to create a rspec >> test to validate this HTML. I can of cause use regex to validate it >> as a string, but would much rather validate it by traversing the DOM >> and checking that the elements I expect is present. Any pointers? > > No - that's not really an option. The rails stack has no idea about a > DOM. Hrm...he's just generating HTML, he should be able to use Hpricot. Does have_tag work with plain strings, or only in examples where there's a response body? If it's the latter, we should make it work with plain strings as well. But Hpricot would certainly be useful I would think. > You'd be able to write a spec like the following: > > it "should link with the correct name" do > helper.should_receive(:link_to).with("foo", {:controller => "foo", > :action => "foo"}) > helper.my_method("foo") > end I don't like this, I don't think you're testing anything here. Pat From pergesu at gmail.com Sat Oct 18 09:19:31 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 18 Oct 2008 07:19:31 -0600 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: (Scott Taylor's message of "Sat\, 18 Oct 2008 00\:53\:18 -0400") References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> <48F8A717.8010409@joesniff.co.uk> <1fb4df0810170842g55b528a0p5face7b51a876aa1@mail.gmail.com> Message-ID: Scott Taylor writes: > As for #3, I'm > pretty sure that Ruby's method_missing allows one to raise an > exception easily. Not sure what a Javascript mocking framework would > do in this case. I'm not sure that I buy that this feature is very important. Both Javascript and Ruby blow up when you call a method that doesn't exist on it anyway. What's the difference between "Received unexpected message 'foo'" and "NoMethodError 'foo'"? Pat From pergesu at gmail.com Sat Oct 18 09:30:57 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 18 Oct 2008 07:30:57 -0600 Subject: [rspec-users] Any good conferences this year about ruby/rspec/watir? In-Reply-To: <20013634.post@talk.nabble.com> (juuuser's message of "Thu\, 16 Oct 2008 06\:17\:25 -0700 \(PDT\)") References: <20013634.post@talk.nabble.com> Message-ID: juuuser writes: > Hello. > > Sorry for this little offtopic question, but I was wondering if anyone > happens to know if there's any good conferences coming up about rspec or > ruby or watir in this year where I could attend to? > > Or any good website where such things are listed or something similar. > > All suggested conferences should not take place before one month from now > (employer needs some time to get good plane tickets and so on). Addison-Wesley is hosting a Pro Ruby conference soon in Boston. I'll be giving a workshop on RSpec (won't discuss watir though) as well as sitting on a panel about testing. There are also a couple other sessions about testing. http://www.voicesthatmatter.com/ruby2008/ for details. Pat From pergesu at gmail.com Sat Oct 18 09:53:34 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 18 Oct 2008 07:53:34 -0600 Subject: [rspec-users] Mocks: expectations vs spying In-Reply-To: <48F7ABDD.4050900@benmabey.com> (Ben Mabey's message of "Thu\, 16 Oct 2008 15\:02\:21 -0600") References: <60782FC3-38CF-4469-BEA7-BBAA9E8DC862@patchspace.co.uk> <48F7ABDD.4050900@benmabey.com> Message-ID: Ben Mabey writes: > Pat has been working on adding the spy pattern to rspec I quit once I found not_a_mock [1] which works nicely. My preference would be to pull spies into RSpec eventually, but I want to use it a bit more first (and hopefully others will too). Pat [1] http://notahat.com/not_a_mock From sfeley at gmail.com Sat Oct 18 10:30:40 2008 From: sfeley at gmail.com (Stephen Eley) Date: Sat, 18 Oct 2008 10:30:40 -0400 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> <48F8A717.8010409@joesniff.co.uk> <1fb4df0810170842g55b528a0p5face7b51a876aa1@mail.gmail.com> Message-ID: <1fb4df0810180730u1891a90sca8bae1373c4df7f@mail.gmail.com> On Sat, Oct 18, 2008 at 12:53 AM, Scott Taylor wrote: > > In Javascript, it might look more or less like this: > > var old_method = obj[my_method]; > my_obj[my_method] = my_return_value; That's an interesting syntax comparison, thanks, but not really what I was reacting to. The statement of import (with emphasis added) was ""The dynamic nature of JavaScript makes mocking frameworks MOSTLY UNNECESSARY." This doesn't imply a simpler mocking framework, as you describe. It implies a fundamental mindshift in how testing gets done. I should probably stop speculating about it here and just do some reading about it. (Or some coding, but I've already invented two "distract myself" projects this week and don't need a third in a new language.) -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From nick at deadorange.com Sat Oct 18 11:34:59 2008 From: nick at deadorange.com (Nick Hoffman) Date: Sat, 18 Oct 2008 11:34:59 -0400 Subject: [rspec-users] Test HTML output from Rails helper In-Reply-To: References: <66BEF894-4C4A-4C3F-B044-1DDFE806E776@3dbyggeri.dk> <0A0E308D-3933-437C-AF63-2A617B565E03@railsnewbie.com> Message-ID: On 2008-10-18, at 09:16, Pat Maddox wrote: > Scott Taylor writes: >> You'd be able to write a spec like the following: >> >> it "should link with the correct name" do >> helper.should_receive(:link_to).with("foo", {:controller => "foo", >> :action => "foo"}) >> helper.my_method("foo") >> end > > I don't like this, I don't think you're testing anything here. > > Pat Hi Pat. I'm interested to hear how you'd spec that helper method, because some of specs are similar to what Scott proposed, and I'm always looking to improve them. Cheers, Nick From mark at mwilden.com Sat Oct 18 11:43:13 2008 From: mark at mwilden.com (Mark Wilden) Date: Sat, 18 Oct 2008 08:43:13 -0700 Subject: [rspec-users] Test HTML output from Rails helper In-Reply-To: References: <66BEF894-4C4A-4C3F-B044-1DDFE806E776@3dbyggeri.dk> <0A0E308D-3933-437C-AF63-2A617B565E03@railsnewbie.com> Message-ID: <3c30da400810180843r11b9b130mc12e6dff09ab061b@mail.gmail.com> On Sat, Oct 18, 2008 at 6:16 AM, Pat Maddox wrote: > Does have_tag work with plain strings > Yep, it does. That's how I spec #to_amcharts. :) ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From benilov at gmail.com Sat Oct 18 12:13:03 2008 From: benilov at gmail.com (Jake Benilov) Date: Sat, 18 Oct 2008 18:13:03 +0200 Subject: [rspec-users] Problems when programmatically defining examples Message-ID: <6fc165060810180913n54b867dalfd55d4b86080b60e@mail.gmail.com> Hi, I am trying to code an application that is based on Rspec; I am programmatically building examples, and launching the runner with a custom formatter. Here are the code snippets from my app: Launching the runner: example_groups = test_expectation.example_groups_for(system_state) @output = StringIO.new options = Spec::Runner::OptionParser.parse(["--format", "RAutotest::Runner::Formatter"], @output, @output) example_groups.each {|example_group| options.add_example_group(example_group) } Spec::Runner::CommandLine.run(options) Building the example groups: examples = Class.new(Spec::Example::ExampleGroup).describe("Statistics") @expectations.map do |expectation| examples.it examples.description do actual_stats_counters.should expectation end end examples This is working fine, except for one problem. When I am writing examples for my app (also using rspec), the examples that are generated within my application (the inner examples, so to say) are being added to the application's examples (the outer examples). This means that if inner expected failures are causing my outer examples to fail. How is it possible for me to verify expected failures without causing my examples to fail? Thanks in advance, Jake -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Sat Oct 18 12:18:36 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sat, 18 Oct 2008 12:18:36 -0400 Subject: [rspec-users] Test HTML output from Rails helper In-Reply-To: References: <66BEF894-4C4A-4C3F-B044-1DDFE806E776@3dbyggeri.dk> <0A0E308D-3933-437C-AF63-2A617B565E03@railsnewbie.com> Message-ID: <85d99afe0810180918v24f22709i839375004ebc5677@mail.gmail.com> On Sat, Oct 18, 2008 at 11:34 AM, Nick Hoffman wrote: > On 2008-10-18, at 09:16, Pat Maddox wrote: >> >> Scott Taylor writes: >>> >>> You'd be able to write a spec like the following: >>> >>> it "should link with the correct name" do >>> helper.should_receive(:link_to).with("foo", {:controller => "foo", >>> :action => "foo"}) >>> helper.my_method("foo") >>> end >> >> I don't like this, I don't think you're testing anything here. >> >> Pat > > Hi Pat. I'm interested to hear how you'd spec that helper method, because > some of specs are similar to what Scott proposed, and I'm always looking to > improve them. I'm pretty sure Pat is simply suggesting: it "should link with the correct name" do helper.my_method("foo").should have_tag("a[href=?]", the_path, "foo") end If my_method returns a string then have_tag will work. If my_method returns an object that responds to "body" then it will also work (this is how response.should have_tag('...') works as well, -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From dchelimsky at gmail.com Sat Oct 18 12:50:35 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 18 Oct 2008 14:50:35 -0200 Subject: [rspec-users] Problems when programmatically defining examples In-Reply-To: <6fc165060810180913n54b867dalfd55d4b86080b60e@mail.gmail.com> References: <6fc165060810180913n54b867dalfd55d4b86080b60e@mail.gmail.com> Message-ID: <57c63afe0810180950u68abdf44p4c8b324cda11c62@mail.gmail.com> On Sat, Oct 18, 2008 at 2:13 PM, Jake Benilov wrote: > Hi, > > I am trying to code an application that is based on Rspec; I am > programmatically building examples, and launching the runner with a custom > formatter. Here are the code snippets from my app: > > Launching the runner: > > example_groups = > test_expectation.example_groups_for(system_state) > > @output = StringIO.new > options = Spec::Runner::OptionParser.parse(["--format", > "RAutotest::Runner::Formatter"], @output, @output) > example_groups.each {|example_group| > options.add_example_group(example_group) } > > Spec::Runner::CommandLine.run(options) > > Building the example groups: > > examples = > Class.new(Spec::Example::ExampleGroup).describe("Statistics") > @expectations.map do |expectation| > examples.it examples.description do > actual_stats_counters.should expectation > end > end > examples > > This is working fine, except for one problem. When I am writing examples for > my app (also using rspec), the examples that are generated within my > application (the inner examples, so to say) are being added to the > application's examples (the outer examples). > This means that if inner expected failures are causing my outer examples to > fail. > > How is it possible for me to verify expected failures without causing my > examples to fail? If I understand your question correctly, you can do this: lambda { # stuff that should fail }.should raise_error(Spec::Expectations::ExpectationNotMetError) See http://rspec.rubyforge.org/rspec/1.1.8/classes/Spec/Matchers.html#M000434 for more info. Cheers, David > > Thanks in advance, > Jake > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Sat Oct 18 14:13:53 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sat, 18 Oct 2008 14:13:53 -0400 Subject: [rspec-users] Cucumber, more examples, tabular data input sets Message-ID: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> Writing feature inputs in the tabular format has recently been very helpful. However, there are some things that seem kind of funny when writing. For example, let's say we wanted to ensure that certain requests resulted in the access denied page: Given Joe is a staff member without the 'admin' privilege When I GET /admin as Joe Then I am notified that access was denied The possible variables here based on step implementations are: Given XXXX is a staff member without the 'XXXX' privilege When I XXX XXXX as XXXX Then I am notified that access was denied This requires the More Examples to look like: | name | privilege | request_method | path | name | | Joe | admin | POST | /invoices | Joe | | Joe | admin | PUT | /invoices/1 | Joe | etc... This isn't that bad, but it'd be nice if we could specify only the variable inputs that we care about -- the privilege, the request method and the path. As the scenario involves more steps you have to grow your tabular data, unless I am missing how to do something (which could be the case). It also seems somewhat odd that the first example is the scenario itself. It almost seems like the scenario should define the placeholders and the More Examples section should define all the input data sets. For example: Given Joe is a staff member without the '$privilege$' privilege When I $request$ $path$ as Joe Then I am notified that access was denied Examples: | privilege | request_method | path | | admin | GET | /admin | | admin | POST | /invoices | | admin | PUT | /invoices/1 | It would somewhat rely on using the \$\w+\$ pattern to denote what should be replaced by the Examples input data set. I'm not tied to how the inputs are grabbed, but it seems like moving in this direction allows the tabular inputs to be more streamlined to what you wanted to include in a scenario. WDYT? -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From ben at benmabey.com Sat Oct 18 14:22:56 2008 From: ben at benmabey.com (Ben Mabey) Date: Sat, 18 Oct 2008 12:22:56 -0600 Subject: [rspec-users] Cucumber, more examples, tabular data input sets In-Reply-To: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> References: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> Message-ID: <48FA2980.3000904@benmabey.com> Zach Dennis wrote: > Writing feature inputs in the tabular format has recently been very > helpful. However, there are some things that seem kind of funny when > writing. For example, let's say we wanted to ensure that certain > requests resulted in the access denied page: > > Given Joe is a staff member without the 'admin' privilege > When I GET /admin as Joe > Then I am notified that access was denied > > The possible variables here based on step implementations are: > > Given XXXX is a staff member without the 'XXXX' privilege > When I XXX XXXX as XXXX > Then I am notified that access was denied > > This requires the More Examples to look like: > > | name | privilege | request_method | path | name | > | Joe | admin | POST | /invoices | Joe | > | Joe | admin | PUT | /invoices/1 | Joe | > etc... > > This isn't that bad, but it'd be nice if we could specify only the > variable inputs that we care about -- the privilege, the request > method and the path. As the scenario involves more steps you have to > grow your tabular data, unless I am missing how to do something (which > could be the case). > > It also seems somewhat odd that the first example is the scenario > itself. It almost seems like the scenario should define the > placeholders and the More Examples section should define all the input > data sets. For example: > > Given Joe is a staff member without the '$privilege$' privilege > When I $request$ $path$ as Joe > Then I am notified that access was denied > > Examples: > | privilege | request_method | path | > | admin | GET | /admin | > | admin | POST | /invoices | > | admin | PUT | /invoices/1 | > > It would somewhat rely on using the \$\w+\$ pattern to denote what > should be replaced by the Examples input data set. I'm not tied to how > the inputs are grabbed, but it seems like moving in this direction > allows the tabular inputs to be more streamlined to what you wanted to > include in a scenario. > > WDYT? > > Why is name even being used? Since you are talking in first person in the other steps couldn't you remove the name altogether: Given I'm a staff member without the 'admin' privilege When I GET /admin Then I am notified that access was denied As far as your suggestion about using placeholders instead of a real example set- I like it. This was actually brought up a little while ago by Evan Light on this list so I think it is something that people naturally move towards. I think this way would be clearer to non-developers as well since the column names would appear in the actual scenario. -Ben From lists at ruby-forum.com Sat Oct 18 14:40:19 2008 From: lists at ruby-forum.com (Rasmus Rasmussen) Date: Sat, 18 Oct 2008 20:40:19 +0200 Subject: [rspec-users] Where are those tables listed for fixtures? In-Reply-To: <1fb4df0810171356g1f2dc27fmcd1b19d37ff8e316@mail.gmail.com> References: <945556fa1748b8deb2016d1c96727db1@ruby-forum.com> <85d99afe0810171157j23fadd78l5558c0923d8b4a8c@mail.gmail.com> <4161d3f8dbe811df9f8e93dbf25bfb6f@ruby-forum.com> <1fb4df0810171356g1f2dc27fmcd1b19d37ff8e316@mail.gmail.com> Message-ID: <1f69416a1d1bad97ab148b957b53b27d@ruby-forum.com> Stephen Eley wrote: > On Fri, Oct 17, 2008 at 3:28 PM, Rasmus Rasmussen > wrote: >> >> this feels like a duplication. If I write rspec-tests I should not do >> ordinary tests, because then I need to maintain two fixtures. Right? > > Correct. You don't need it. But the standard Rails generator doesn't > know that you're sneaking around on it with RSpec, so it keeps putting > boxes of chocolates in your /test directory hoping you'll pay more > attention to it and never knowing why you don't come home. It's quite > touching, really. Maybe even a little poignant. > > > -- > Have Fun, > Steve Eley (sfeley at gmail.com) > ESCAPE POD - The Science Fiction Podcast Magazine > http://www.escapepod.org That is a very nice way of putting it. Guess I still got some pending feelings for rails. Those scripts are evil! :-) Also, they are no good when practicing TDD IMO. Again, only rookie impressions... -- Posted via http://www.ruby-forum.com/. From mailing_lists at railsnewbie.com Sat Oct 18 14:54:37 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 18 Oct 2008 14:54:37 -0400 Subject: [rspec-users] Test HTML output from Rails helper In-Reply-To: References: <66BEF894-4C4A-4C3F-B044-1DDFE806E776@3dbyggeri.dk> <0A0E308D-3933-437C-AF63-2A617B565E03@railsnewbie.com> Message-ID: <6B09EBA4-9BC4-492D-BD1D-3E1CE402800A@railsnewbie.com> On Oct 18, 2008, at 9:16 AM, Pat Maddox wrote: > Scott Taylor writes: > >> On Oct 18, 2008, at 4:40 AM, Thomas Watson Steen wrote: >> >>> Hi >>> >>> I'm using RSpec in with Ruby on Rails. I've made a helper module >>> method that generates some HTML and would like to create a rspec >>> test to validate this HTML. I can of cause use regex to validate it >>> as a string, but would much rather validate it by traversing the DOM >>> and checking that the elements I expect is present. Any pointers? >> >> No - that's not really an option. The rails stack has no idea >> about a >> DOM. > > Hrm...he's just generating HTML, he should be able to use Hpricot. > Does have_tag work with plain strings, or only in examples where > there's > a response body? If it's the latter, we should make it work with > plain > strings as well. But Hpricot would certainly be useful I would think. > Yeah. +1. Not sure why I didn't think of that. Scott From scottburton11 at gmail.com Sat Oct 18 14:55:02 2008 From: scottburton11 at gmail.com (Scott Burton) Date: Sat, 18 Oct 2008 11:55:02 -0700 Subject: [rspec-users] Error loading Rails fixtures Message-ID: <504319E3-1E44-44A7-82DE-724284609C6F@gmail.com> Hi all; I'm getting a weird error from the rspec gem when using rake to load fixtures in rails: % rake db:fixtures:load RAILS_ENV=test /path/to/Ruby/Gems/1.8/gems/rspec-1.1.8/lib/spec/runner/options.rb: 229:in `files_to_load': File or directory not found: db:fixtures:load (RuntimeError) from /path/to/Ruby/Gems/1.8/gems/rspec-1.1.8/lib/spec/runner/ options.rb:221:in `each' from /path/to/Ruby/Gems/1.8/gems/rspec-1.1.8/lib/spec/runner/ options.rb:221:in `files_to_load' from /path/to/Ruby/Gems/1.8/gems/rspec-1.1.8/lib/spec/runner/ options.rb:98:in `run_examples' from /path/to/Ruby/Gems/1.8/gems/rspec-1.1.8/lib/spec.rb:21:in `run' from /path/to/Ruby/Gems/1.8/gems/rspec-1.1.8/lib/spec/runner.rb: 192:in `register_at_exit_hook' from /usr/bin/rake:19 It's getting something in files_to_load that isn't a file or directory. It's isolated to one project, so it seems configuration- related. Anyone know what might be going on here? Many thanks, Scott From lists at ruby-forum.com Sat Oct 18 14:55:33 2008 From: lists at ruby-forum.com (Joseph Wilk) Date: Sat, 18 Oct 2008 20:55:33 +0200 Subject: [rspec-users] Cucumber, more examples, tabular data input sets In-Reply-To: <48FA2980.3000904@benmabey.com> References: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> <48FA2980.3000904@benmabey.com> Message-ID: <7a2e5f3afc6c1ed375ea99f86d263703@ruby-forum.com> Ben Mabey wrote: > > As far as your suggestion about using placeholders instead of a real > example set- I like it. This was actually brought up a little while ago > by Evan Light on this list so I think it is something that people > naturally move towards. As Ben said this has cropped up in a couple of places. http://www.ruby-forum.com/topic/165523#new http://evan.tiggerpalace.com/2008/09/11/plain-text-stories-at-dcrug/ http://rspec.lighthouseapp.com/projects/16211/tickets/4-add-multiline-step-support It probably needs a new issue in lighthouse so we can focus discussion there. http://rspec.lighthouseapp.com/projects/16211-cucumber/overview > I think this way would be clearer to > non-developers as well since the column names would appear in the actual > scenario. > > -Ben I like the idea. Though I have some questions like how 'GivenScenario' would behave with such a scenario. -- Joseph Wilk http://www.joesniff.co.uk -- Posted via http://www.ruby-forum.com/. From mailing_lists at railsnewbie.com Sat Oct 18 14:59:44 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 18 Oct 2008 14:59:44 -0400 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> <48F8A717.8010409@joesniff.co.uk> <1fb4df0810170842g55b528a0p5face7b51a876aa1@mail.gmail.com> Message-ID: <0372781A-E151-4538-8477-AE41076EFCB1@railsnewbie.com> On Oct 18, 2008, at 9:19 AM, Pat Maddox wrote: > Scott Taylor writes: > >> As for #3, I'm >> pretty sure that Ruby's method_missing allows one to raise an >> exception easily. Not sure what a Javascript mocking framework would >> do in this case. > > I'm not sure that I buy that this feature is very important. Both > Javascript and Ruby blow up when you call a method that doesn't > exist on > it anyway. What's the difference between "Received unexpected message > 'foo'" and "NoMethodError 'foo'"? Unless I'm mistaken, it's only when *another* method gets called on a missing method that an error gets raised: >>> o = {}; Object >>> o.foo >>> o.foo === undefined true >>> o.foo.bar TypeError: o.foo is undefined Also, I found this last night: http://developer.mozilla.org/En/Core_JavaScript_1.5_Reference:Global_Objects:Object:_noSuchMethod . BTW, Pat - Have you still been working on integrating test spy into rspec? Scott > > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Sat Oct 18 15:12:47 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sat, 18 Oct 2008 15:12:47 -0400 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: <1fb4df0810180730u1891a90sca8bae1373c4df7f@mail.gmail.com> References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> <48F8A717.8010409@joesniff.co.uk> <1fb4df0810170842g55b528a0p5face7b51a876aa1@mail.gmail.com> <1fb4df0810180730u1891a90sca8bae1373c4df7f@mail.gmail.com> Message-ID: <22625413-7218-47AF-8FA4-FEA27370C11D@railsnewbie.com> On Oct 18, 2008, at 10:30 AM, Stephen Eley wrote: > On Sat, Oct 18, 2008 at 12:53 AM, Scott Taylor > wrote: >> >> In Javascript, it might look more or less like this: >> >> var old_method = obj[my_method]; >> my_obj[my_method] = my_return_value; > > That's an interesting syntax comparison, thanks, but not really what I > was reacting to. The statement of import (with emphasis added) was > ""The dynamic nature of JavaScript makes mocking frameworks MOSTLY > UNNECESSARY." > > This doesn't imply a simpler mocking framework, as you describe. It > implies a fundamental mindshift in how testing gets done. AH - that's interesting. I didn't take it as any sort of mindshift in testing. I thought that README/blogpost was simply saying that a mock framework is unnecessary because the syntax is so easy. But only *mostly* unnecessary, because either 1) there will be times where you'll need to tear things down, AND/OR 2) You could build a tiny stub/ mock framework around this stuff very easily for small syntactical gains. Interesting idea, though, and maybe it does cause a mindshift in testing. Scott From sfeley at gmail.com Sat Oct 18 16:25:54 2008 From: sfeley at gmail.com (Stephen Eley) Date: Sat, 18 Oct 2008 16:25:54 -0400 Subject: [rspec-users] Cucumber, more examples, tabular data input sets In-Reply-To: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> References: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> Message-ID: <1fb4df0810181325xb3c9071m1829f8b685d87bc1@mail.gmail.com> On Sat, Oct 18, 2008 at 2:13 PM, Zach Dennis wrote: > > Given Joe is a staff member without the '$privilege$' privilege > When I $request$ $path$ as Joe > Then I am notified that access was denied My only beef with this is that it breaks the pattern of writing scenarios in plain English. I don't know if I can pin that down in terms of technical value, but it makes me _feel_ good to follow a chain of turning prose into code. If you put variable names in there that *look* like variable names, it sullies that. But by the way, thanks for posting this. I didn't really grok the tables feature in Cucumber before, and when I tried 'script/generate feature' the table part threw errors so I deleted it. Your asking made me look in the wiki on Github again, and I found this, which I must have missed before: http://github.com/aslakhellesoy/cucumber/wikis/using-fit-tables-in-a-feature Posting that for the benefit of anyone else who missed it and didn't know they missed it. So thank you! -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From lists at ruby-forum.com Sat Oct 18 16:33:11 2008 From: lists at ruby-forum.com (Ben Emson) Date: Sat, 18 Oct 2008 22:33:11 +0200 Subject: [rspec-users] Running Cucumber with a Rails Rake task Message-ID: Hi All I've just started experimenting with Cucumber and its great. However I wasn't quite sure how I should integrate it into my Rails application. What I would like to do is set my Rails app up so that I can run a Cucumber rake task using the standard Rails Rake system. I've looked through the example source and understand how the Calculator demo Rake file works, but I'm not sure I've set it up correctly in my Rails app. This is what I've done. Created a new file: my_app/lib/tasks/cucumber.rake I experimented trying to use the following Cucumber rake task but could not get my steps to load my model code as I was hoping that I could tell Cucumber what my Rails lib files were: Cucumber::Rake::Task.new do |t| t.libs = ["#{RAILS_ROOT}/config/environment"] # This doesn't seem to work Dir.chdir("#{RAILS_ROOT}/stories/") profile = ENV['PROFILE'] || 'default' t.cucumber_opts = "--profile #{profile}" end In the end I opted to just call Cucumber from the commandline: desc "run stories" task :runner do cucumber = "cucumber stories" sh cucumber end And then add a helper file to my stories directory and tell my steps to load the Rails environment, such that my_steps.rb looks like this: require 'spec' require File.expand_path(File.dirname(__FILE__) + "/../../helper") # then all my step code...... And my helper.rb file looks like this: ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") So is this the correct way for adding a Rake task to the main Rails Rake file so that it will run all my stories? Should I still include the old all.rb file in the stories directory so that I can run it without using Rake? Many thanks BE... -- Posted via http://www.ruby-forum.com/. From zach.dennis at gmail.com Sat Oct 18 16:51:03 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sat, 18 Oct 2008 16:51:03 -0400 Subject: [rspec-users] Cucumber, more examples, tabular data input sets In-Reply-To: <1fb4df0810181325xb3c9071m1829f8b685d87bc1@mail.gmail.com> References: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> <1fb4df0810181325xb3c9071m1829f8b685d87bc1@mail.gmail.com> Message-ID: <85d99afe0810181351v5aeb6707j6a9953fe11d0929c@mail.gmail.com> On Sat, Oct 18, 2008 at 4:25 PM, Stephen Eley wrote: > On Sat, Oct 18, 2008 at 2:13 PM, Zach Dennis wrote: >> >> Given Joe is a staff member without the '$privilege$' privilege >> When I $request$ $path$ as Joe >> Then I am notified that access was denied > > My only beef with this is that it breaks the pattern of writing > scenarios in plain English. I don't know if I can pin that down in > terms of technical value, but it makes me _feel_ good to follow a > chain of turning prose into code. If you put variable names in there > that *look* like variable names, it sullies that. I don't know if it damages the scenario as a whole. After all, the reason you're using tabular data in the first place is so you can re-use scenarios with different inputs. I would argue that using variable names in the scenarios that use tabular data makes it more readable. You can easily see where you are changing the inputs. Otherwise you have to map each piece of tabular data with the corresponding variable substitution locations for each step definition. And if you update the step definitions at any point you may break the scenarios that use tabular data because you need to go update each row with updates or deletions of possible variables. For example: Given I login as Joe without the 'admin' privilege When I GET /admin Then I am notified that access was denied More Examples: | name | privilege | request_method | path | name | | Joe | admin | POST | /invoices | Joe | | Joe | admin | PUT | /invoices/1 | Joe | The focus of these scenario is to make sure that when a user without a particular privilege requests a specific path that they get sent to the access denied page. So the three inputs I'm interested in are: privilege, request method and path. The other ones are superfluous and don't speak clearly to actual intent of the tabular data that is important. Let's say new types of users are added to the system, and I need update the Given step to reflect that: Given /^I login as the (.*) (\w+) without the '([^]'+)' privilege$/ This makes the step in the scenario get updated to: Given I login as the staff member Joe without the 'admin' privilege Now I have to update each row of inputs to make sure they supply the user type: | name | user_type | privilege | request_method | path | name | | Joe | staff member | admin | POST | /invoices | Joe | Perhaps this scenario would have needed to be updated anyways because I wanted to include varying user types for each run. But that isn't necessarily always the case. Perhaps the user type would never vary. Why should it go in the tabular data? It's not speaking clearly to the intent the test, and the variables involved. > > But by the way, thanks for posting this. I didn't really grok the > tables feature in Cucumber before, and when I tried 'script/generate > feature' the table part threw errors so I deleted it. Your asking > made me look in the wiki on Github again, and I found this, which I > must have missed before: > http://github.com/aslakhellesoy/cucumber/wikis/using-fit-tables-in-a-feature > > Posting that for the benefit of anyone else who missed it and didn't > know they missed it. So thank you! yw! thx for joining the conversation, -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From zach.dennis at gmail.com Sat Oct 18 16:53:44 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sat, 18 Oct 2008 16:53:44 -0400 Subject: [rspec-users] Running Cucumber with a Rails Rake task In-Reply-To: References: Message-ID: <85d99afe0810181353r1437b6ecyc9fda0dc84414c1e@mail.gmail.com> To run all features you can run: rake features To run specific features you can do something like: script/cucumber --require features/steps features/path/to/my.feature If you want to run a particular scenario find out the line number of the first Given and run: script/cucumber --line 41 --require features/steps features/path/to/my.feature Zach On Sat, Oct 18, 2008 at 4:33 PM, Ben Emson wrote: > Hi All > > I've just started experimenting with Cucumber and its great. > However I wasn't quite sure how I should integrate it into my Rails > application. > > What I would like to do is set my Rails app up so that I can run a > Cucumber rake task using the standard Rails Rake system. > > I've looked through the example source and understand how the Calculator > demo Rake file works, but I'm not sure I've set it up correctly in my > Rails app. > > This is what I've done. > > Created a new file: > my_app/lib/tasks/cucumber.rake > > I experimented trying to use the following Cucumber rake task but could > not get my steps to load my model code as I was hoping that I could tell > Cucumber what my Rails lib files were: > > Cucumber::Rake::Task.new do |t| > t.libs = ["#{RAILS_ROOT}/config/environment"] # This doesn't seem to > work > Dir.chdir("#{RAILS_ROOT}/stories/") > profile = ENV['PROFILE'] || 'default' > t.cucumber_opts = "--profile #{profile}" > end > > In the end I opted to just call Cucumber from the commandline: > > desc "run stories" > task :runner do > cucumber = "cucumber stories" > sh cucumber > end > > And then add a helper file to my stories directory and tell my steps to > load the Rails environment, such that my_steps.rb looks like this: > > require 'spec' > require File.expand_path(File.dirname(__FILE__) + "/../../helper") > > # then all my step code...... > > And my helper.rb file looks like this: > > ENV["RAILS_ENV"] = "test" > require File.expand_path(File.dirname(__FILE__) + > "/../config/environment") > > > So is this the correct way for adding a Rake task to the main Rails Rake > file so that it will run all my stories? > Should I still include the old all.rb file in the stories directory so > that I can run it without using Rake? > > Many thanks > > BE... > -- > 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 http://www.mutuallyhuman.com From aslak.hellesoy at gmail.com Sat Oct 18 16:58:12 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sat, 18 Oct 2008 22:58:12 +0200 Subject: [rspec-users] Cucumber, more examples, tabular data input sets In-Reply-To: <1fb4df0810181325xb3c9071m1829f8b685d87bc1@mail.gmail.com> References: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> <1fb4df0810181325xb3c9071m1829f8b685d87bc1@mail.gmail.com> Message-ID: <8d961d900810181358h7c551f0eha2b96dd8702b73fc@mail.gmail.com> On Sat, Oct 18, 2008 at 10:25 PM, Stephen Eley wrote: > On Sat, Oct 18, 2008 at 2:13 PM, Zach Dennis wrote: >> >> Given Joe is a staff member without the '$privilege$' privilege >> When I $request$ $path$ as Joe >> Then I am notified that access was denied > > My only beef with this is that it breaks the pattern of writing > scenarios in plain English. I don't know if I can pin that down in > terms of technical value, but it makes me _feel_ good to follow a > chain of turning prose into code. If you put variable names in there > that *look* like variable names, it sullies that. > > But by the way, thanks for posting this. I didn't really grok the > tables feature in Cucumber before, and when I tried 'script/generate > feature' the table part threw errors so I deleted it. Your asking > made me look in the wiki on Github again, and I found this, which I > must have missed before: > http://github.com/aslakhellesoy/cucumber/wikis/using-fit-tables-in-a-feature > > Posting that for the benefit of anyone else who missed it and didn't > know they missed it. So thank you! > Even *I* didn't know about that page :-) I've just updated it. (Let's not call them FIT tables. Let's call them scenario tables and step tables instead). Aslak > > -- > Have Fun, > Steve Eley (sfeley at gmail.com) > ESCAPE POD - The Science Fiction Podcast Magazine > http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Sat Oct 18 17:42:01 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sat, 18 Oct 2008 22:42:01 +0100 Subject: [rspec-users] Cucumber, more examples, tabular data input sets In-Reply-To: <85d99afe0810181351v5aeb6707j6a9953fe11d0929c@mail.gmail.com> References: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> <1fb4df0810181325xb3c9071m1829f8b685d87bc1@mail.gmail.com> <85d99afe0810181351v5aeb6707j6a9953fe11d0929c@mail.gmail.com> Message-ID: On Oct 18, 2008, at 9:51 pm, Zach Dennis wrote: > Given I login as Joe without the 'admin' privilege > When I GET /admin > Then I am notified that access was denied > > More Examples: > | name | privilege | request_method | path | name | > | Joe | admin | POST | /invoices | Joe | > | Joe | admin | PUT | /invoices/1 | Joe | How about just annotating them? eg Given I login as [name] Joe without the 'admin' privilege [missing_privilege] When I GET [request_method] /admin [path] Then I am notified that access was denied Or whatever. Maybe do it selectively, I don't think all of them are necessary. Maybe writing scenarios that read well above a table is just a skill we have to develop. Just a few thoughts really, I'm thinking out loud. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From lists at ruby-forum.com Sat Oct 18 18:10:35 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Sun, 19 Oct 2008 00:10:35 +0200 Subject: [rspec-users] Why @controller is nil error on loading fixtures in model? Message-ID: Hi, I'm new to rspec and working on catching up my app with rspec testing. I'm running OSX 10.5.5 with Rails 2.1.0 and Rspec 1.1.8. Most things I've tried work except loading fixtures. I setup a describe block for the model as require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/../helpers/motions_spec_helper') require File.expand_path(File.dirname(__FILE__) + '/../helpers/votes_spec_helper') describe "description" do fixtures :motions it "reads from fixtures" do put "#{motions(:one).inspect}" end end I receive @controller is nil: make sure you set it in your test's setup method. as the error when running the example test in rspec. I know it is finding the fixture because it balked at duplicate id entries with SQLite. I fixed that and now receive the above message. I tried various setting changes in spec_helper.rb but nothing seems to work. After searching around I tried various terminal entries like rake spec:db:fixtures:load but no change. I would appreciate some assistance here to get this off the ground. TIA, HR -- Posted via http://www.ruby-forum.com/. From aslak.hellesoy at gmail.com Sat Oct 18 18:11:43 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sun, 19 Oct 2008 00:11:43 +0200 Subject: [rspec-users] Running Cucumber with a Rails Rake task In-Reply-To: References: Message-ID: <8d961d900810181511q3e3f524fkac6a90c3c31507e6@mail.gmail.com> On Sat, Oct 18, 2008 at 10:33 PM, Ben Emson wrote: > Hi All > > I've just started experimenting with Cucumber and its great. > However I wasn't quite sure how I should integrate it into my Rails > application. > Have you read this? http://github.com/aslakhellesoy/cucumber/wikis/ruby-on-rails Aslak > What I would like to do is set my Rails app up so that I can run a > Cucumber rake task using the standard Rails Rake system. > > I've looked through the example source and understand how the Calculator > demo Rake file works, but I'm not sure I've set it up correctly in my > Rails app. > > This is what I've done. > > Created a new file: > my_app/lib/tasks/cucumber.rake > > I experimented trying to use the following Cucumber rake task but could > not get my steps to load my model code as I was hoping that I could tell > Cucumber what my Rails lib files were: > > Cucumber::Rake::Task.new do |t| > t.libs = ["#{RAILS_ROOT}/config/environment"] # This doesn't seem to > work > Dir.chdir("#{RAILS_ROOT}/stories/") > profile = ENV['PROFILE'] || 'default' > t.cucumber_opts = "--profile #{profile}" > end > > In the end I opted to just call Cucumber from the commandline: > > desc "run stories" > task :runner do > cucumber = "cucumber stories" > sh cucumber > end > > And then add a helper file to my stories directory and tell my steps to > load the Rails environment, such that my_steps.rb looks like this: > > require 'spec' > require File.expand_path(File.dirname(__FILE__) + "/../../helper") > > # then all my step code...... > > And my helper.rb file looks like this: > > ENV["RAILS_ENV"] = "test" > require File.expand_path(File.dirname(__FILE__) + > "/../config/environment") > > > So is this the correct way for adding a Rake task to the main Rails Rake > file so that it will run all my stories? > Should I still include the old all.rb file in the stories directory so > that I can run it without using Rake? > > Many thanks > > BE... > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From benilov at gmail.com Sat Oct 18 18:34:20 2008 From: benilov at gmail.com (Jake Benilov) Date: Sun, 19 Oct 2008 00:34:20 +0200 Subject: [rspec-users] Problems when programmatically defining examples In-Reply-To: <57c63afe0810180950u68abdf44p4c8b324cda11c62@mail.gmail.com> References: <6fc165060810180913n54b867dalfd55d4b86080b60e@mail.gmail.com> <57c63afe0810180950u68abdf44p4c8b324cda11c62@mail.gmail.com> Message-ID: <6fc165060810181534j25549eaex21d652f9cf9e45bb@mail.gmail.com> David, Thanks for your reply; however I probably wasn't very clear in my explanation. What I am really trying to do is to create a builder for example group objects, without automatically adding the example groups to the rspec runner when the builder code is invoked. As an example, when I call the following code: describe "a group" do examples = Class.new(Spec::Example::ExampleGroup).describe("example") examples.it "should not be added to the outer group" do true.should be_false end end I get: ~~~ 1) 'example should not be added to the outer group' FAILED expected false, got true Finished in 0.027012 seconds 1 example, 1 failure ~~~ This is probably expected, but what I really want is that the "examples" example group is NOT picked up by rspec. I suppose that I need to stay away from the "it" and "describe" methods... right? Regards, Jake On Sat, Oct 18, 2008 at 6:50 PM, David Chelimsky wrote: > On Sat, Oct 18, 2008 at 2:13 PM, Jake Benilov wrote: > > Hi, > > > > I am trying to code an application that is based on Rspec; I am > > programmatically building examples, and launching the runner with a > custom > > formatter. Here are the code snippets from my app: > > > > Launching the runner: > > > > example_groups = > > test_expectation.example_groups_for(system_state) > > > > @output = StringIO.new > > options = Spec::Runner::OptionParser.parse(["--format", > > "RAutotest::Runner::Formatter"], @output, @output) > > example_groups.each {|example_group| > > options.add_example_group(example_group) } > > > > Spec::Runner::CommandLine.run(options) > > > > Building the example groups: > > > > examples = > > Class.new(Spec::Example::ExampleGroup).describe("Statistics") > > @expectations.map do |expectation| > > examples.it examples.description do > > actual_stats_counters.should expectation > > end > > end > > examples > > > > This is working fine, except for one problem. When I am writing examples > for > > my app (also using rspec), the examples that are generated within my > > application (the inner examples, so to say) are being added to the > > application's examples (the outer examples). > > This means that if inner expected failures are causing my outer examples > to > > fail. > > > > How is it possible for me to verify expected failures without causing my > > examples to fail? > > If I understand your question correctly, you can do this: > > lambda { > # stuff that should fail > }.should raise_error(Spec::Expectations::ExpectationNotMetError) > > See > http://rspec.rubyforge.org/rspec/1.1.8/classes/Spec/Matchers.html#M000434 > for more info. > > Cheers, > David > > > > > Thanks in advance, > > Jake > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Sat Oct 18 20:48:42 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sat, 18 Oct 2008 20:48:42 -0400 Subject: [rspec-users] Cucumber, more examples, tabular data input sets In-Reply-To: References: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> <1fb4df0810181325xb3c9071m1829f8b685d87bc1@mail.gmail.com> <85d99afe0810181351v5aeb6707j6a9953fe11d0929c@mail.gmail.com> Message-ID: <85d99afe0810181748j48ead9f0i2d2d77ead3dacf53@mail.gmail.com> On Sat, Oct 18, 2008 at 5:42 PM, Ashley Moran wrote: > > On Oct 18, 2008, at 9:51 pm, Zach Dennis wrote: > >> Given I login as Joe without the 'admin' privilege >> When I GET /admin >> Then I am notified that access was denied >> >> More Examples: >> | name | privilege | request_method | path | name | >> | Joe | admin | POST | /invoices | Joe | >> | Joe | admin | PUT | /invoices/1 | Joe | > > How about just annotating them? eg > > Given I login as [name] Joe without the 'admin' privilege > [missing_privilege] > When I GET [request_method] /admin [path] > Then I am notified that access was denied > > Or whatever. Maybe do it selectively, I don't think all of them are > necessary. > > Maybe writing scenarios that read well above a table is just a skill we have > to develop. > > Just a few thoughts really, I'm thinking out loud. > I like what you're thinking, -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From zach.dennis at gmail.com Sat Oct 18 21:24:01 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sat, 18 Oct 2008 21:24:01 -0400 Subject: [rspec-users] Problems when programmatically defining examples In-Reply-To: <6fc165060810181534j25549eaex21d652f9cf9e45bb@mail.gmail.com> References: <6fc165060810180913n54b867dalfd55d4b86080b60e@mail.gmail.com> <57c63afe0810180950u68abdf44p4c8b324cda11c62@mail.gmail.com> <6fc165060810181534j25549eaex21d652f9cf9e45bb@mail.gmail.com> Message-ID: <85d99afe0810181824y74389c06v2d371c3624ffc918@mail.gmail.com> On Sat, Oct 18, 2008 at 6:34 PM, Jake Benilov wrote: > David, > > Thanks for your reply; however I probably wasn't very clear in my > explanation. What I am really trying to do is to create a builder for > example group objects, without automatically adding the example groups to > the rspec runner when the builder code is invoked. > > As an example, when I call the following code: > > describe "a group" do > examples = Class.new(Spec::Example::ExampleGroup).describe("example") > examples.it "should not be added to the outer group" do > true.should be_false > end > end When you create a subclass of Spec:Example::ExampleGroup, it automatically gets registered. You want to make sure you unregister it so rspec's Runner doesn't try to run it. Try this: describe "a group" do example_group = Class.new(Spec::Example::ExampleGroup) example_group.unregister examples = example_group.describe("example") examples.it "should not be added to the outer group" do true.should be_false end end > > I get: > ~~~ > 1) > 'example should not be added to the outer group' FAILED > expected false, got true > > Finished in 0.027012 seconds > > 1 example, 1 failure > ~~~ > This is probably expected, but what I really want is that the "examples" > example group is NOT picked up by rspec. I suppose that I need to stay away > from the "it" and "describe" methods... right? > > Regards, > Jake > > On Sat, Oct 18, 2008 at 6:50 PM, David Chelimsky > wrote: >> >> On Sat, Oct 18, 2008 at 2:13 PM, Jake Benilov wrote: >> > Hi, >> > >> > I am trying to code an application that is based on Rspec; I am >> > programmatically building examples, and launching the runner with a >> > custom >> > formatter. Here are the code snippets from my app: >> > >> > Launching the runner: >> > >> > example_groups = >> > test_expectation.example_groups_for(system_state) >> > >> > @output = StringIO.new >> > options = Spec::Runner::OptionParser.parse(["--format", >> > "RAutotest::Runner::Formatter"], @output, @output) >> > example_groups.each {|example_group| >> > options.add_example_group(example_group) } >> > >> > Spec::Runner::CommandLine.run(options) >> > >> > Building the example groups: >> > >> > examples = >> > Class.new(Spec::Example::ExampleGroup).describe("Statistics") >> > @expectations.map do |expectation| >> > examples.it examples.description do >> > actual_stats_counters.should expectation >> > end >> > end >> > examples >> > >> > This is working fine, except for one problem. When I am writing examples >> > for >> > my app (also using rspec), the examples that are generated within my >> > application (the inner examples, so to say) are being added to the >> > application's examples (the outer examples). >> > This means that if inner expected failures are causing my outer examples >> > to >> > fail. >> > >> > How is it possible for me to verify expected failures without causing my >> > examples to fail? >> >> If I understand your question correctly, you can do this: >> >> lambda { >> # stuff that should fail >> }.should raise_error(Spec::Expectations::ExpectationNotMetError) >> >> See >> http://rspec.rubyforge.org/rspec/1.1.8/classes/Spec/Matchers.html#M000434 >> for more info. >> >> Cheers, >> David >> >> > >> > Thanks in advance, >> > Jake >> > >> > _______________________________________________ >> > 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 > -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From zach.dennis at gmail.com Sat Oct 18 21:32:15 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sat, 18 Oct 2008 21:32:15 -0400 Subject: [rspec-users] Why @controller is nil error on loading fixtures in model? In-Reply-To: References: Message-ID: <85d99afe0810181832l50e46c3fj2e676092420bae95@mail.gmail.com> On Sat, Oct 18, 2008 at 6:10 PM, Harry Bishop wrote: > Hi, > I'm new to rspec and working on catching up my app with rspec testing. > I'm running OSX 10.5.5 with Rails 2.1.0 and Rspec 1.1.8. > Most things I've tried work except loading fixtures. I setup a describe > block for the model as > > require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') > require File.expand_path(File.dirname(__FILE__) + > '/../helpers/motions_spec_helper') > require File.expand_path(File.dirname(__FILE__) + > '/../helpers/votes_spec_helper') > > describe "description" do > > fixtures :motions > > it "reads from fixtures" do > > put "#{motions(:one).inspect}" > end > end > > I receive @controller is nil: make sure you set it in your test's setup > method. > as the error when running the example test in rspec. I know it is > finding the fixture because it balked at duplicate id entries with > SQLite. I fixed that and now receive the above message. > > I tried various setting changes in spec_helper.rb but nothing seems to > work. > After searching around I tried various terminal entries like > rake spec:db:fixtures:load > but no change. > > I would appreciate some assistance here to get this off the ground. It's being you are calling "put" and I believe you want "puts". The method "put" is a Rails testing method which tries to invoke a PUT http request on a given controller action. That is why you are getting @controller is nil. -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From mark.thomson at ieee.org Sat Oct 18 21:49:35 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Sat, 18 Oct 2008 20:49:35 -0500 Subject: [rspec-users] Surprising mock behavior In-Reply-To: <1fb4df0810171237k5e5425d0ye954364bc3e58ab8@mail.gmail.com> References: <48F8DF9A.6040708@ieee.org> <1fb4df0810171237k5e5425d0ye954364bc3e58ab8@mail.gmail.com> Message-ID: <48FA922F.90708@ieee.org> Stephen Eley wrote: > On Fri, Oct 17, 2008 at 2:55 PM, Mark Thomson wrote: > >> and then check that the expected messages are being received - >> file.should_receive(:puts).with("a string").once >> file.should_receive(:puts).with("another string").once >> >> Here's what I'm puzzled about. If I don't include the expectation for the >> first string in the spec, the spec will fail the expectation for the second >> string. It seems as if "should_receive" is queuing up the messages that come >> into the file object and when it tests an expectation it just looks at the >> next one in line. If it doesn't match then the expectation will fail. >> > > That sounds right to me. You declared 'file' as a mock. Mocks are > bratty little children that treat it as an error and throw a tantrum > if you don't give them everything they expect, no more nor less. (As > contrasted to stubs, which are couch potatoes that will respond if you > call them but don't complain if you don't.) > > So when you create a mock, you need to be very thorough about it. > Every message has to be accounted for somehow. If it gets more > messages than you tell it, or different messages, it'll error. If it > doesn't get enough messages, it'll error. This is correct behavior. > Thanks for the explanation Stephen. However, if that is the intention, I'm puzzled by something else - as I said the spec fails if I don't include an expectation for each output message. However it turns out that that's actually not always true. What I've observed is that it behaves differently if I include a "should_not_receive('...')" expectation somewhere in the spec. In that case it seems that I can have as many "file.puts()" in the component being tested as I like without specifying expectations for them, and they pass just fine. In fact I did have such a situation in my initial spec and I think that's what led me to my mistaken understanding of how should_receive is meant to work. But I'm struggling to understand what the rationale is that explains both of these cases. That aside, I also can't help questioning the way the "should_receive" expectation is expressed. Maybe specifying every message sent to the mock is absolutely the right way to test the component. But in view of the general philosophy of expressing expectations in a way that reflects what they actually mean, in my mind this doesn't quite hit the mark. If you say "should receive", the way I read that is that if the object /does /receive what you specify then it should pass. But that's clearly not what happens. Nor is it an expectation on what will be received next. If that were the case you might call the method "should_next_receive". However, in fact, as long as all messages are accounted for, you can reorder the individual "should_receive" expectations any way you like and the spec will still pass. In fact "should_receive" does not appear to be an expectation on a single message at all (even if you say "should_receive().once", and leaving aside the exception with "should_not_receive" I noted above). I think a better way to think about this is that the total set of "should_receive" calls are _together_ an expectation on the totality of messages received by the object. In view of this, I wonder if a better way to formulate this test might be to say something like - object.should_receive :method => :method_name, :with_each_of => [arg1, arg2,... argN] where arg1, arg2 etc represent the parameters for each individual call to :method_name. i.e. declare the whole of what we _really_ expect the object to receive in a single call to should_receive. You could take this one step further and declare all of the required calls to any number of methods on the object in a single expectation, by making the argument to should_receive an array - object.should_receive [{:method => :method1, :with_each_of => [...]}, {:method => :method2, :with_each_of => [...]}, ...] Yeah it gets a little wordy, but if I'm understanding the behavior correctly, this is what we are actually trying to test. Does this make sense? Mark. From zach.dennis at gmail.com Sat Oct 18 22:46:30 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sat, 18 Oct 2008 22:46:30 -0400 Subject: [rspec-users] Surprising mock behavior In-Reply-To: <48FA922F.90708@ieee.org> References: <48F8DF9A.6040708@ieee.org> <1fb4df0810171237k5e5425d0ye954364bc3e58ab8@mail.gmail.com> <48FA922F.90708@ieee.org> Message-ID: <85d99afe0810181946w65bdcbf8t2ab12c4b3f7e9d5f@mail.gmail.com> I'm top posting... I wish I could inline post, but you provided a lot of generalizations for how you think things are working on your code, but you don't actually post concrete code (the should_receive and should_not_receive case you mentioned that wasn't acting like you'd expect). Perhaps this will help: * Mocks are not ordered by default. * If you want ordered message expectations on a mock you have to explicitly tell them to be ordered. * You cannot enforce ordering across mocks. So without explicitly ordering, message expectations can be fulfilled in any order. For example the below will pass even though the expectation for 1 and 3 does not match the order in when the bar method is called: file = Object.new file.should_receive(:bar).with("1") file.should_receive(:bar).with("3") file.bar "3" file.bar "1" Once a message expectation is fulfilled, if the object receives another message matching that expectation it will force it to fail. For example, the following would fail even though there are two expectations for "bar" to be called with "1", which match the two calls to file.bar: file = Object.new file.should_receive(:bar).with("1") file.should_receive(:bar).with("1") file.bar "1" file.bar "1" Using should_not_receive and should_receive on the same message gets tricky, because you can trick yourself into thinking the thing is passing when it shouldn't be. For example the below will fail because even though you call file.bar with "2", that matches the expectation that file.bar should not be called with "3": file = Object.new file.should_receive(:bar).with("1") file.should_not_receive(:bar).with("3") file.bar "1" file.bar "2" Hopefully this helps clarify some things for you about rspec's mocks. However... > object.should_receive :method => :method_name, :with_each_of => [arg1, > arg2,... argN] I really don't like this. This is hard to read and can lead to something that is very convoluted. Can you share the actual code and spec you're having issues with so we can try to provide concrete help back to you? Zach On Sat, Oct 18, 2008 at 9:49 PM, Mark Thomson wrote: > Stephen Eley wrote: >> >> On Fri, Oct 17, 2008 at 2:55 PM, Mark Thomson >> wrote: >> >>> >>> and then check that the expected messages are being received - >>> file.should_receive(:puts).with("a string").once >>> file.should_receive(:puts).with("another string").once >>> >>> Here's what I'm puzzled about. If I don't include the expectation for the >>> first string in the spec, the spec will fail the expectation for the >>> second >>> string. It seems as if "should_receive" is queuing up the messages that >>> come >>> into the file object and when it tests an expectation it just looks at >>> the >>> next one in line. If it doesn't match then the expectation will fail. >>> >> >> That sounds right to me. You declared 'file' as a mock. Mocks are >> bratty little children that treat it as an error and throw a tantrum >> if you don't give them everything they expect, no more nor less. (As >> contrasted to stubs, which are couch potatoes that will respond if you >> call them but don't complain if you don't.) >> >> So when you create a mock, you need to be very thorough about it. >> Every message has to be accounted for somehow. If it gets more >> messages than you tell it, or different messages, it'll error. If it >> doesn't get enough messages, it'll error. This is correct behavior. >> > > Thanks for the explanation Stephen. However, if that is the intention, I'm > puzzled by something else - as I said the spec fails if I don't include an > expectation for each output message. However it turns out that that's > actually not always true. What I've observed is that it behaves differently > if I include a "should_not_receive('...')" expectation somewhere in the > spec. In that case it seems that I can have as many "file.puts()" in the > component being tested as I like without specifying expectations for them, > and they pass just fine. In fact I did have such a situation in my initial > spec and I think that's what led me to my mistaken understanding of how > should_receive is meant to work. But I'm struggling to understand what the > rationale is that explains both of these cases. > > That aside, I also can't help questioning the way the "should_receive" > expectation is expressed. Maybe specifying every message sent to the mock is > absolutely the right way to test the component. But in view of the general > philosophy of expressing expectations in a way that reflects what they > actually mean, in my mind this doesn't quite hit the mark. If you say > "should receive", the way I read that is that if the object /does /receive > what you specify then it should pass. But that's clearly not what happens. > Nor is it an expectation on what will be received next. If that were the > case you might call the method "should_next_receive". However, in fact, as > long as all messages are accounted for, you can reorder the individual > "should_receive" expectations any way you like and the spec will still pass. > > In fact "should_receive" does not appear to be an expectation on a single > message at all (even if you say "should_receive().once", and leaving aside > the exception with "should_not_receive" I noted above). I think a better way > to think about this is that the total set of "should_receive" calls are > _together_ an expectation on the totality of messages received by the > object. In view of this, I wonder if a better way to formulate this test > might be to say something like - > > object.should_receive :method => :method_name, :with_each_of => [arg1, > arg2,... argN] > > where arg1, arg2 etc represent the parameters for each individual call to > :method_name. i.e. declare the whole of what we _really_ expect the object > to receive in a single call to should_receive. > > You could take this one step further and declare all of the required calls > to any number of methods on the object in a single expectation, by making > the argument to should_receive an array - > > object.should_receive [{:method => :method1, :with_each_of => [...]}, > {:method => :method2, :with_each_of => [...]}, ...] > > Yeah it gets a little wordy, but if I'm understanding the behavior > correctly, this is what we are actually trying to test. > > Does this make sense? > > Mark. > _______________________________________________ > 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 sfeley at gmail.com Sat Oct 18 22:51:57 2008 From: sfeley at gmail.com (Stephen Eley) Date: Sat, 18 Oct 2008 22:51:57 -0400 Subject: [rspec-users] Surprising mock behavior In-Reply-To: <48FA922F.90708@ieee.org> References: <48F8DF9A.6040708@ieee.org> <1fb4df0810171237k5e5425d0ye954364bc3e58ab8@mail.gmail.com> <48FA922F.90708@ieee.org> Message-ID: <1fb4df0810181951v3878ae5aw40a350082459cdfa@mail.gmail.com> On Sat, Oct 18, 2008 at 9:49 PM, Mark Thomson wrote: > > [...] What I've observed is that it behaves differently > if I include a "should_not_receive('...')" expectation somewhere in the > spec. In that case it seems that I can have as many "file.puts()" in the > component being tested as I like without specifying expectations for them, > and they pass just fine. Hmm, that does seem weird. Without seeing your actual code I think it'd be difficult for anyone to say if it's a bug, or expected behavior with unexpected results, or something else causing the issue, etc. It _smells_ like a bug to me the way you describe it -- specifying messages you shouldn't get ought not change the expectation of messages you _do_ get -- but then, I've often been flummoxed by test behavior in my own code when it was really my misunderstanding causing the problem. Maybe file a Lighthouse ticket with code samples clearly showing failing and passing tests. > That aside, I also can't help questioning the way the "should_receive" > expectation is expressed. Maybe specifying every message sent to the mock is > absolutely the right way to test the component. But in view of the general > philosophy of expressing expectations in a way that reflects what they > actually mean, in my mind this doesn't quite hit the mark. [ . . . ] I think the difference in perspective here is that you're focusing in very closely on the individual "should_receive" calls. That's not the level at which this expectation is set. It's not the presence of a single should_receive that makes the mock want to know about every message it gets. It's the fact that *it's a mock.* Unless you tell them otherwise, that's just the way mocks work. If you don't want to have to specify everything, then that's what stubs are for. > In view of this, I wonder if a better way to formulate this test > might be to say something like - > > object.should_receive :method => :method_name, :with_each_of => [arg1, > arg2,... argN] That's not a bad idea, but I suspect your tests in which you're calling 'puts' over and over might be a bit of an edge case. Most spec examples are much simpler, and I suspect it's uncommon to have a need to call a given method more than once in a single example. Even if you're testing an iteration, you don't have to use a _large_ loop in a test case. One or two iterations and logical induction ought to suffice to prove that it works. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From sfeley at gmail.com Sat Oct 18 23:48:03 2008 From: sfeley at gmail.com (Stephen Eley) Date: Sat, 18 Oct 2008 23:48:03 -0400 Subject: [rspec-users] Cucumber, more examples, tabular data input sets In-Reply-To: <85d99afe0810181351v5aeb6707j6a9953fe11d0929c@mail.gmail.com> References: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> <1fb4df0810181325xb3c9071m1829f8b685d87bc1@mail.gmail.com> <85d99afe0810181351v5aeb6707j6a9953fe11d0929c@mail.gmail.com> Message-ID: <1fb4df0810182048t7859b5eaubfbab2d8785dbc5d@mail.gmail.com> (I just realized that Zach was doing some sort of reply-all that included my address separately, and had my reply going to him instead of the list. So I'm sending it to the list now as I originally intended.) On Sat, Oct 18, 2008 at 4:51 PM, Zach Dennis wrote: > > I don't know if it damages the scenario as a whole. After all, the > reason you're using tabular data in the first place is so you can > re-use scenarios with different inputs. I would argue that using > variable names in the scenarios that use tabular data makes it more > readable. I didn't say it damaged it. Your logic is fine. It simply makes it look less like an English prose sentence, and that's counter to the aesthetic that's part of Rspec's/Cucumber's appeal to my personal taste. Which I guess is less a strenuous objection, and more just to say: Aslak, if this suggestion is officially implemented in Cucumber, please make sure the current form continues to work too. Then those of us who are persnickety fiction editors can continue doing things the way we like them, and everybody wins. >8-> -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From zach.dennis at gmail.com Sat Oct 18 23:56:49 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sat, 18 Oct 2008 23:56:49 -0400 Subject: [rspec-users] Cucumber, more examples, tabular data input sets In-Reply-To: <1fb4df0810182048t7859b5eaubfbab2d8785dbc5d@mail.gmail.com> References: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> <1fb4df0810181325xb3c9071m1829f8b685d87bc1@mail.gmail.com> <85d99afe0810181351v5aeb6707j6a9953fe11d0929c@mail.gmail.com> <1fb4df0810182048t7859b5eaubfbab2d8785dbc5d@mail.gmail.com> Message-ID: <85d99afe0810182056s19c404aev3160bfb20fa7d386@mail.gmail.com> On Sat, Oct 18, 2008 at 7:37 PM, Stephen Eley wrote: > On Sat, Oct 18, 2008 at 4:51 PM, Zach Dennis wrote: >> >> I don't know if it damages the scenario as a whole. After all, the >> reason you're using tabular data in the first place is so you can >> re-use scenarios with different inputs. I would argue that using >> variable names in the scenarios that use tabular data makes it more >> readable. You can easily see where you are changing the inputs. > > I didn't say it damaged it. Well you said sully, and that is defined as "damaging the purity or integrity of; defile". > Your logic is fine. It simply makes it > look less like an English prose sentence, and that's counter to the > aesthetic that's part of Rspec's/Cucumber's appeal to my personal > taste. > > Which I guess is less a strenuous objection, and more just to say: > Aslak, if this suggestion is officially implemented in Cucumber, > please make sure the current form continues to work too. Then those > of us who are persnickety fiction editors can continue doing things > the way we like them, and everybody wins. Based on your earlier email you mentioned you hadn't really grokked the tabular inputs of features, so I'm guessing you haven't been using the current form. I'm not asking to change how single scenarios are written. I am just asking for a more useful way to write scenarios which use tabular data inputs. The typical scenario wouldn't be affected by this. I like Ashley's idea of annotating the inputs. You could annotate only those that should be replaced with data from the tabular inputs. -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From mark.thomson at ieee.org Sun Oct 19 00:56:32 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Sat, 18 Oct 2008 23:56:32 -0500 Subject: [rspec-users] Surprising mock behavior In-Reply-To: <1fb4df0810181951v3878ae5aw40a350082459cdfa@mail.gmail.com> References: <48F8DF9A.6040708@ieee.org> <1fb4df0810171237k5e5425d0ye954364bc3e58ab8@mail.gmail.com> <48FA922F.90708@ieee.org> <1fb4df0810181951v3878ae5aw40a350082459cdfa@mail.gmail.com> Message-ID: <48FABE00.7070604@ieee.org> Stephen Eley wrote: > On Sat, Oct 18, 2008 at 9:49 PM, Mark Thomson wrote: > >> [...] What I've observed is that it behaves differently >> if I include a "should_not_receive('...')" expectation somewhere in the >> spec. In that case it seems that I can have as many "file.puts()" in the >> component being tested as I like without specifying expectations for them, >> and they pass just fine. >> > > Hmm, that does seem weird. ... Maybe file a Lighthouse ticket with code samples > clearly showing failing and passing tests. > > > Will do. > It's not the presence of a > single should_receive that makes the mock want to know about every > message it gets. It's the fact that *it's a mock.* Unless you tell > them otherwise, that's just the way mocks work. Thanks, I think that's really the key concept I've been missing. I see how that changes the perspective on should_receive. > If you don't want to > have to specify everything, then that's what stubs are for. > I think I understand your point here, though am I right that a stub is restricted to specifying only one response to any particular method? You can't specify parameters in the way you do using :with in should_receive on a mock. OTOH taking a different tack, it seems from the documentation (http://rspec.info/documentation/mocks/) that the :null_object option to mock() may allow you to leave some messages unspecified. I'll check on this. >> In view of this, I wonder if a better way to formulate this test >> might be to say something like - >> >> object.should_receive :method => :method_name, :with_each_of => [arg1, >> arg2,... argN] >> > > That's not a bad idea, but I suspect your tests in which you're > calling 'puts' over and over might be a bit of an edge case. Yeah, I think that's true. I was actually trying to debug the spec, rather than object being tested. Still, it has turned out to be a useful learning exercise. From mark.thomson at ieee.org Sun Oct 19 01:34:44 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Sun, 19 Oct 2008 00:34:44 -0500 Subject: [rspec-users] Surprising mock behavior In-Reply-To: <85d99afe0810181946w65bdcbf8t2ab12c4b3f7e9d5f@mail.gmail.com> References: <48F8DF9A.6040708@ieee.org> <1fb4df0810171237k5e5425d0ye954364bc3e58ab8@mail.gmail.com> <48FA922F.90708@ieee.org> <85d99afe0810181946w65bdcbf8t2ab12c4b3f7e9d5f@mail.gmail.com> Message-ID: <48FAC6F4.2090608@ieee.org> Zach Dennis wrote: > I'm top posting... I wish I could inline post, but you provided a lot > of generalizations for how you think things are working on your code, > but you don't actually post concrete code (the should_receive and > should_not_receive case you mentioned that wasn't acting like you'd > expect). Perhaps this will help: > > * Mocks are not ordered by default. > Yeah that's consistent with what I'm seeing. I mentioned ordering only because it was one of the things that came up in my mind as I was searching for a way to understand the different behaviors I was seeing. > * If you want ordered message expectations on a mock you have to > explicitly tell them to be ordered. > Really, you can do that? I'm curious about how. > * You cannot enforce ordering across mocks. > > So without explicitly ordering, message expectations can be fulfilled > in any order. For example the below will pass even though the > expectation for 1 and 3 does not match the order in when the bar > method is called: > > file = Object.new > file.should_receive(:bar).with("1") > file.should_receive(:bar).with("3") > > file.bar "3" > file.bar "1" > > Ok got that. > Once a message expectation is fulfilled, if the object receives > another message matching that expectation it will force it to fail. > For example, the following would fail even though there are two > expectations for "bar" to be called with "1", which match the two > calls to file.bar: > > file = Object.new > file.should_receive(:bar).with("1") > file.should_receive(:bar).with("1") > > file.bar "1" > file.bar "1" > This one kind of surprises me, but I understand your point. > Using should_not_receive and should_receive on the same message gets > tricky, because you can trick yourself into thinking the thing is > passing when it shouldn't be. For example the below will fail because > even though you call file.bar with "2", that matches the expectation > that file.bar should not be called with "3": > > file = Object.new > file.should_receive(:bar).with("1") > file.should_not_receive(:bar).with("3") > > file.bar "1" > file.bar "2" > Did you mean to say that will *not* fail since "2" will match "not 3"? If so that's really good to know. I had imagined that should_not_receive was purely a statement about something that doesn't happen, not about something different happening. That may explain what I had thought was anomalous behavior. I'll have to take another look at that. > Hopefully this helps clarify some things for you about rspec's mocks. > > However... > > >> object.should_receive :method => :method_name, :with_each_of => [arg1, >> arg2,... argN] >> > > I really don't like this. This is hard to read and can lead to > something that is very convoluted. Can you share the actual code and > spec you're having issues with so we can try to provide concrete help > back to you? > Steve's comments helped me understand why this approach isn't necessary. Mark. > Zach > > > On Sat, Oct 18, 2008 at 9:49 PM, Mark Thomson wrote: > >> Stephen Eley wrote: >> >>> On Fri, Oct 17, 2008 at 2:55 PM, Mark Thomson >>> wrote: >>> >>> >>>> and then check that the expected messages are being received - >>>> file.should_receive(:puts).with("a string").once >>>> file.should_receive(:puts).with("another string").once >>>> >>>> Here's what I'm puzzled about. If I don't include the expectation for the >>>> first string in the spec, the spec will fail the expectation for the >>>> second >>>> string. It seems as if "should_receive" is queuing up the messages that >>>> come >>>> into the file object and when it tests an expectation it just looks at >>>> the >>>> next one in line. If it doesn't match then the expectation will fail. >>>> >>>> >>> That sounds right to me. You declared 'file' as a mock. Mocks are >>> bratty little children that treat it as an error and throw a tantrum >>> if you don't give them everything they expect, no more nor less. (As >>> contrasted to stubs, which are couch potatoes that will respond if you >>> call them but don't complain if you don't.) >>> >>> So when you create a mock, you need to be very thorough about it. >>> Every message has to be accounted for somehow. If it gets more >>> messages than you tell it, or different messages, it'll error. If it >>> doesn't get enough messages, it'll error. This is correct behavior. >>> >>> >> Thanks for the explanation Stephen. However, if that is the intention, I'm >> puzzled by something else - as I said the spec fails if I don't include an >> expectation for each output message. However it turns out that that's >> actually not always true. What I've observed is that it behaves differently >> if I include a "should_not_receive('...')" expectation somewhere in the >> spec. In that case it seems that I can have as many "file.puts()" in the >> component being tested as I like without specifying expectations for them, >> and they pass just fine. In fact I did have such a situation in my initial >> spec and I think that's what led me to my mistaken understanding of how >> should_receive is meant to work. But I'm struggling to understand what the >> rationale is that explains both of these cases. >> >> That aside, I also can't help questioning the way the "should_receive" >> expectation is expressed. Maybe specifying every message sent to the mock is >> absolutely the right way to test the component. But in view of the general >> philosophy of expressing expectations in a way that reflects what they >> actually mean, in my mind this doesn't quite hit the mark. If you say >> "should receive", the way I read that is that if the object /does /receive >> what you specify then it should pass. But that's clearly not what happens. >> Nor is it an expectation on what will be received next. If that were the >> case you might call the method "should_next_receive". However, in fact, as >> long as all messages are accounted for, you can reorder the individual >> "should_receive" expectations any way you like and the spec will still pass. >> >> In fact "should_receive" does not appear to be an expectation on a single >> message at all (even if you say "should_receive().once", and leaving aside >> the exception with "should_not_receive" I noted above). I think a better way >> to think about this is that the total set of "should_receive" calls are >> _together_ an expectation on the totality of messages received by the >> object. In view of this, I wonder if a better way to formulate this test >> might be to say something like - >> >> object.should_receive :method => :method_name, :with_each_of => [arg1, >> arg2,... argN] >> >> where arg1, arg2 etc represent the parameters for each individual call to >> :method_name. i.e. declare the whole of what we _really_ expect the object >> to receive in a single call to should_receive. >> >> You could take this one step further and declare all of the required calls >> to any number of methods on the object in a single expectation, by making >> the argument to should_receive an array - >> >> object.should_receive [{:method => :method1, :with_each_of => [...]}, >> {:method => :method2, :with_each_of => [...]}, ...] >> >> Yeah it gets a little wordy, but if I'm understanding the behavior >> correctly, this is what we are actually trying to test. >> >> Does this make sense? >> >> Mark. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> >> > > > > From matt at mattwynne.net Sun Oct 19 04:26:47 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 19 Oct 2008 09:26:47 +0100 Subject: [rspec-users] Cucumber, more examples, tabular data input sets In-Reply-To: References: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> <1fb4df0810181325xb3c9071m1829f8b685d87bc1@mail.gmail.com> <85d99afe0810181351v5aeb6707j6a9953fe11d0929c@mail.gmail.com> Message-ID: <8C7CD501-50F7-4C2E-A1BA-73DA0EFD44E2@mattwynne.net> On 18 Oct 2008, at 22:42, Ashley Moran wrote: > > On Oct 18, 2008, at 9:51 pm, Zach Dennis wrote: > >> Given I login as Joe without the 'admin' privilege >> When I GET /admin >> Then I am notified that access was denied >> >> More Examples: >> | name | privilege | request_method | path | name | >> | Joe | admin | POST | /invoices | Joe | >> | Joe | admin | PUT | /invoices/1 | Joe | > > How about just annotating them? eg > > Given I login as [name] Joe without the 'admin' privilege > [missing_privilege] > When I GET [request_method] /admin [path] > Then I am notified that access was denied I like this, and I agree with Joe that it's quite painful to have to (a) include every substitutable step parameter in the table columns, even if it doesn't change in any scenario table row (b) go hunting around in step definitions (or pretty console output looking for the underlines) to figure out which param is which But I do also feel like it clutters up the scenario bit. I wonder whether it might also work to have a different definition, like ScenarioTemplate: which doesn't actually run, but defines the skeleton into which the table values will be substituted. So Joe's example will work like this: ScenarioTemplate: Non admins are rejected Given I login as Joe without the '[privilege]' privilege When I [request_method] /admin[path] Then I am notified that access was denied | privilege | request_method | path | | Joe | GET | /admin | | Joe | POST | /invoces/1 | etc. WDYT? cheers, Matt From matt at mattwynne.net Sun Oct 19 04:32:25 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 19 Oct 2008 09:32:25 +0100 Subject: [rspec-users] Mocks: expectations vs spying In-Reply-To: References: <60782FC3-38CF-4469-BEA7-BBAA9E8DC862@patchspace.co.uk> <48F7ABDD.4050900@benmabey.com> Message-ID: <51122F6B-D2B8-41E7-9134-FF3AF5FC0F3F@mattwynne.net> On 18 Oct 2008, at 14:53, Pat Maddox wrote: > more first (and hopefully others will too). > > Pat > > [1] http://notahat.com/not_a_mock Looks sweet - it will be in my first mock on Monday! cheers, Matt From lists at ruby-forum.com Sun Oct 19 09:36:08 2008 From: lists at ruby-forum.com (Ben Emson) Date: Sun, 19 Oct 2008 15:36:08 +0200 Subject: [rspec-users] Running Cucumber with a Rails Rake task In-Reply-To: <85d99afe0810181353r1437b6ecyc9fda0dc84414c1e@mail.gmail.com> References: <85d99afe0810181353r1437b6ecyc9fda0dc84414c1e@mail.gmail.com> Message-ID: <24616f080ea9db4830df06906c16b8c1@ruby-forum.com> Zach Dennis wrote: > To run all features you can run: > > rake features > > To run specific features you can do something like: > > script/cucumber --require features/steps features/path/to/my.feature > > If you want to run a particular scenario find out the line number of > the first Given and run: > > script/cucumber --line 41 --require features/steps > features/path/to/my.feature > > Zach > > > On Sat, Oct 18, 2008 at 4:33 PM, Ben Emson wrote: >> demo Rake file works, but I'm not sure I've set it up correctly in my >> >> desc "run stories" >> >> file so that it will run all my stories? >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Zach Dennis > http://www.continuousthinking.com > http://www.mutuallyhuman.com Thanks Aslak and Zach I must apologise in my excitement I completely missed the Rails wiki section. Thats just what I was looking for. Thanks and keep up the good work. BE... -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Sun Oct 19 10:12:00 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Sun, 19 Oct 2008 16:12:00 +0200 Subject: [rspec-users] Why @controller is nil error on loading fixtures in model? In-Reply-To: <85d99afe0810181832l50e46c3fj2e676092420bae95@mail.gmail.com> References: <85d99afe0810181832l50e46c3fj2e676092420bae95@mail.gmail.com> Message-ID: <7c2afaa76290bba6e7ccd0ed623d1535@ruby-forum.com> Zach Dennis wrote: > On Sat, Oct 18, 2008 at 6:10 PM, Harry Bishop > wrote: >> '/../helpers/votes_spec_helper') >> >> but no change. >> >> I would appreciate some assistance here to get this off the ground. > > It's being you are calling "put" and I believe you want "puts". The > method "put" is a Rails testing method which tries to invoke a PUT > http request on a given controller action. That is why you are getting > @controller is nil. > > -- > Zach Dennis > http://www.continuousthinking.com > http://www.mutuallyhuman.com yes that was the problem. That d*** dyslexia again. Thanks very much, as frustration had set in. HR -- Posted via http://www.ruby-forum.com/. From zach.dennis at gmail.com Sun Oct 19 10:40:37 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Sun, 19 Oct 2008 10:40:37 -0400 Subject: [rspec-users] Surprising mock behavior In-Reply-To: <48FAC6F4.2090608@ieee.org> References: <48F8DF9A.6040708@ieee.org> <1fb4df0810171237k5e5425d0ye954364bc3e58ab8@mail.gmail.com> <48FA922F.90708@ieee.org> <85d99afe0810181946w65bdcbf8t2ab12c4b3f7e9d5f@mail.gmail.com> <48FAC6F4.2090608@ieee.org> Message-ID: <85d99afe0810190740x69b412c7kbe0436d699b71aa8@mail.gmail.com> On Sun, Oct 19, 2008 at 1:34 AM, Mark Thomson wrote: > > Zach Dennis wrote: >> >> I'm top posting... I wish I could inline post, but you provided a lot >> of generalizations for how you think things are working on your code, >> but you don't actually post concrete code (the should_receive and >> should_not_receive case you mentioned that wasn't acting like you'd >> expect). Perhaps this will help: >> >> * Mocks are not ordered by default. >> > > Yeah that's consistent with what I'm seeing. I mentioned ordering only > because it was one of the things that came up in my mind as I was searching > for a way to understand the different behaviors I was seeing. > >> * If you want ordered message expectations on a mock you have to >> explicitly tell them to be ordered. >> > > Really, you can do that? I'm curious about how. Checkout http://rspec.info/documentation/mocks/message_expectations.html And look at the Ordering section. > >> * You cannot enforce ordering across mocks. >> >> So without explicitly ordering, message expectations can be fulfilled >> in any order. For example the below will pass even though the >> expectation for 1 and 3 does not match the order in when the bar >> method is called: >> >> file = Object.new >> file.should_receive(:bar).with("1") >> file.should_receive(:bar).with("3") >> >> file.bar "3" >> file.bar "1" >> >> > > Ok got that. > >> Once a message expectation is fulfilled, if the object receives >> another message matching that expectation it will force it to fail. >> For example, the following would fail even though there are two >> expectations for "bar" to be called with "1", which match the two >> calls to file.bar: >> >> file = Object.new >> file.should_receive(:bar).with("1") >> file.should_receive(:bar).with("1") >> >> file.bar "1" >> file.bar "1" >> > > This one kind of surprises me, but I understand your point. > >> Using should_not_receive and should_receive on the same message gets >> tricky, because you can trick yourself into thinking the thing is >> passing when it shouldn't be. For example the below will fail because >> even though you call file.bar with "2", that matches the expectation >> that file.bar should not be called with "3": >> >> file = Object.new >> file.should_receive(:bar).with("1") >> file.should_not_receive(:bar).with("3") >> >> file.bar "1" >> file.bar "2" >> > > Did you mean to say that will *not* fail since "2" will match "not 3"? Yes, that's what I meant. -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From pergesu at gmail.com Sun Oct 19 11:58:46 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 19 Oct 2008 09:58:46 -0600 Subject: [rspec-users] Surprising mock behavior In-Reply-To: <48FA922F.90708@ieee.org> (Mark Thomson's message of "Sat\, 18 Oct 2008 20\:49\:35 -0500") References: <48F8DF9A.6040708@ieee.org> <1fb4df0810171237k5e5425d0ye954364bc3e58ab8@mail.gmail.com> <48FA922F.90708@ieee.org> Message-ID: Can you please post an example of the spec and production code that isn't behaving as you expect? Pat From mark.thomson at ieee.org Sun Oct 19 12:06:27 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Sun, 19 Oct 2008 11:06:27 -0500 Subject: [rspec-users] Surprising mock behavior In-Reply-To: <85d99afe0810190740x69b412c7kbe0436d699b71aa8@mail.gmail.com> References: <48F8DF9A.6040708@ieee.org> <1fb4df0810171237k5e5425d0ye954364bc3e58ab8@mail.gmail.com> <48FA922F.90708@ieee.org> <85d99afe0810181946w65bdcbf8t2ab12c4b3f7e9d5f@mail.gmail.com> <48FAC6F4.2090608@ieee.org> <85d99afe0810190740x69b412c7kbe0436d699b71aa8@mail.gmail.com> Message-ID: <48FB5B03.504@ieee.org> Zach Dennis wrote: >>> * If you want ordered message expectations on a mock you have to >>> explicitly tell them to be ordered. >>> >>> >> Really, you can do that? I'm curious about how. >> > > Checkout http://rspec.info/documentation/mocks/message_expectations.html > > And look at the Ordering section. > Thanks for that pointer. Somehow I never made it that far into the document tree. If you hadn't mentioned it I would not have realized that was there. No wonder I was having trouble! M. From pergesu at gmail.com Sun Oct 19 12:11:37 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 19 Oct 2008 10:11:37 -0600 Subject: [rspec-users] Test HTML output from Rails helper In-Reply-To: <85d99afe0810180918v24f22709i839375004ebc5677@mail.gmail.com> (Zach Dennis's message of "Sat\, 18 Oct 2008 12\:18\:36 -0400") References: <66BEF894-4C4A-4C3F-B044-1DDFE806E776@3dbyggeri.dk> <0A0E308D-3933-437C-AF63-2A617B565E03@railsnewbie.com> <85d99afe0810180918v24f22709i839375004ebc5677@mail.gmail.com> Message-ID: "Zach Dennis" writes: > On Sat, Oct 18, 2008 at 11:34 AM, Nick Hoffman wrote: >> On 2008-10-18, at 09:16, Pat Maddox wrote: >>> >>> Scott Taylor writes: >>>> >>>> You'd be able to write a spec like the following: >>>> >>>> it "should link with the correct name" do >>>> helper.should_receive(:link_to).with("foo", {:controller => "foo", >>>> :action => "foo"}) >>>> helper.my_method("foo") >>>> end >>> >>> I don't like this, I don't think you're testing anything here. >>> >>> Pat >> >> Hi Pat. I'm interested to hear how you'd spec that helper method, because >> some of specs are similar to what Scott proposed, and I'm always looking to >> improve them. > > > I'm pretty sure Pat is simply suggesting: > > it "should link with the correct name" do > helper.my_method("foo").should have_tag("a[href=?]", the_path, "foo") > end Yup Pat From pergesu at gmail.com Sun Oct 19 12:14:52 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sun, 19 Oct 2008 10:14:52 -0600 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: <0372781A-E151-4538-8477-AE41076EFCB1@railsnewbie.com> (Scott Taylor's message of "Sat\, 18 Oct 2008 14\:59\:44 -0400") References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> <48F8A717.8010409@joesniff.co.uk> <1fb4df0810170842g55b528a0p5face7b51a876aa1@mail.gmail.com> <0372781A-E151-4538-8477-AE41076EFCB1@railsnewbie.com> Message-ID: Scott Taylor writes: > On Oct 18, 2008, at 9:19 AM, Pat Maddox wrote: > >> Scott Taylor writes: >> >>> As for #3, I'm >>> pretty sure that Ruby's method_missing allows one to raise an >>> exception easily. Not sure what a Javascript mocking framework would >>> do in this case. >> >> I'm not sure that I buy that this feature is very important. Both >> Javascript and Ruby blow up when you call a method that doesn't >> exist on >> it anyway. What's the difference between "Received unexpected message >> 'foo'" and "NoMethodError 'foo'"? > > Unless I'm mistaken, it's only when *another* method gets called on a > missing method that an error gets raised: > >>>> o = {}; > Object >>>> o.foo You would need to do o.foo() to actually call the method. That will give you "o.foo is undefined" > BTW, Pat - Have you still been working on integrating test spy into > rspec? Nope, I found not_a_mock [1] and it works well. Pat [1] http://notahat.com/not_a_mock From benilov at gmail.com Sun Oct 19 13:40:13 2008 From: benilov at gmail.com (Jake Benilov) Date: Sun, 19 Oct 2008 19:40:13 +0200 Subject: [rspec-users] Problems when programmatically defining examples In-Reply-To: <85d99afe0810181824y74389c06v2d371c3624ffc918@mail.gmail.com> References: <6fc165060810180913n54b867dalfd55d4b86080b60e@mail.gmail.com> <57c63afe0810180950u68abdf44p4c8b324cda11c62@mail.gmail.com> <6fc165060810181534j25549eaex21d652f9cf9e45bb@mail.gmail.com> <85d99afe0810181824y74389c06v2d371c3624ffc918@mail.gmail.com> Message-ID: <6fc165060810191040j6547bcc1y61725b12318af778@mail.gmail.com> Hi Zach, That worked a treat. Thanks! Regards, Jake On Sun, Oct 19, 2008 at 3:24 AM, Zach Dennis wrote: > On Sat, Oct 18, 2008 at 6:34 PM, Jake Benilov wrote: > > David, > > > > Thanks for your reply; however I probably wasn't very clear in my > > explanation. What I am really trying to do is to create a builder for > > example group objects, without automatically adding the example groups to > > the rspec runner when the builder code is invoked. > > > > As an example, when I call the following code: > > > > describe "a group" do > > examples = Class.new(Spec::Example::ExampleGroup).describe("example") > > examples.it "should not be added to the outer group" do > > true.should be_false > > end > > end > > When you create a subclass of Spec:Example::ExampleGroup, it > automatically gets registered. You want to make sure you unregister it > so rspec's Runner doesn't try to run it. Try this: > > describe "a group" do > example_group = Class.new(Spec::Example::ExampleGroup) > example_group.unregister > examples = example_group.describe("example") > examples.it "should not be added to the outer group" do > true.should be_false > end > end > > > > > > > I get: > > ~~~ > > 1) > > 'example should not be added to the outer group' FAILED > > expected false, got true > > > > Finished in 0.027012 seconds > > > > 1 example, 1 failure > > ~~~ > > This is probably expected, but what I really want is that the "examples" > > example group is NOT picked up by rspec. I suppose that I need to stay > away > > from the "it" and "describe" methods... right? > > > > Regards, > > Jake > > > > On Sat, Oct 18, 2008 at 6:50 PM, David Chelimsky > > wrote: > >> > >> On Sat, Oct 18, 2008 at 2:13 PM, Jake Benilov > wrote: > >> > Hi, > >> > > >> > I am trying to code an application that is based on Rspec; I am > >> > programmatically building examples, and launching the runner with a > >> > custom > >> > formatter. Here are the code snippets from my app: > >> > > >> > Launching the runner: > >> > > >> > example_groups = > >> > test_expectation.example_groups_for(system_state) > >> > > >> > @output = StringIO.new > >> > options = > Spec::Runner::OptionParser.parse(["--format", > >> > "RAutotest::Runner::Formatter"], @output, @output) > >> > example_groups.each {|example_group| > >> > options.add_example_group(example_group) } > >> > > >> > Spec::Runner::CommandLine.run(options) > >> > > >> > Building the example groups: > >> > > >> > examples = > >> > Class.new(Spec::Example::ExampleGroup).describe("Statistics") > >> > @expectations.map do |expectation| > >> > examples.it examples.description do > >> > actual_stats_counters.should expectation > >> > end > >> > end > >> > examples > >> > > >> > This is working fine, except for one problem. When I am writing > examples > >> > for > >> > my app (also using rspec), the examples that are generated within my > >> > application (the inner examples, so to say) are being added to the > >> > application's examples (the outer examples). > >> > This means that if inner expected failures are causing my outer > examples > >> > to > >> > fail. > >> > > >> > How is it possible for me to verify expected failures without causing > my > >> > examples to fail? > >> > >> If I understand your question correctly, you can do this: > >> > >> lambda { > >> # stuff that should fail > >> }.should raise_error(Spec::Expectations::ExpectationNotMetError) > >> > >> See > >> > http://rspec.rubyforge.org/rspec/1.1.8/classes/Spec/Matchers.html#M000434 > >> for more info. > >> > >> Cheers, > >> David > >> > >> > > >> > Thanks in advance, > >> > Jake > >> > > >> > _______________________________________________ > >> > 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 > > > > > > -- > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashley.moran at patchspace.co.uk Sun Oct 19 15:36:29 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 19 Oct 2008 20:36:29 +0100 Subject: [rspec-users] Merb Message-ID: <2346471A-B6F5-46C2-A9DC-0E98512C2F99@patchspace.co.uk> Hi Two questions: Anyone using Merb here, and writing specs for it? (I've just started tonight, so I'm figuring stuff out as I go along.) And WDYAT of their spec extensions[1]? Specifically their "given" given "a item exists" do request(resource(:items), :method => "POST", :params => { :item => { }}) end describe "resource(:items)" do describe "GET", :given => "a item exists" do before(:each) do @response = request(resource(:items)) end it "has a list of items" do pending @response.should have_xpath("//ul/li") end end end Have to say I was a bit surprised to learn they'd monkey-patched RSpec... Ashley [1] http://github.com/wycats/merb-core/tree/master/lib/merb-core/test/test_ext/rspec.rb -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Sun Oct 19 16:18:38 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 19 Oct 2008 21:18:38 +0100 Subject: [rspec-users] Mocks: expectations vs spying In-Reply-To: <51122F6B-D2B8-41E7-9134-FF3AF5FC0F3F@mattwynne.net> References: <60782FC3-38CF-4469-BEA7-BBAA9E8DC862@patchspace.co.uk> <48F7ABDD.4050900@benmabey.com> <51122F6B-D2B8-41E7-9134-FF3AF5FC0F3F@mattwynne.net> Message-ID: <4DE1E7EB-DC01-4E76-9E95-10703C7A34FD@patchspace.co.uk> On Oct 19, 2008, at 9:32 am, Matt Wynne wrote: >> [1] http://notahat.com/not_a_mock > > Looks sweet - it will be in my first mock on Monday! Wow, there's some serious work gone into that, and I never knew it existed! Searched my local archives (from March this year) for Pete Yandell and he hasn't posted once to promote it. Gonna see if I can shoe-horn it into my Merb app somehow, now is the best time to inflict maximum learning pain on myself :) Thanks for the link Pat. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From dchelimsky at gmail.com Sun Oct 19 16:43:03 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 19 Oct 2008 15:43:03 -0500 Subject: [rspec-users] Merb In-Reply-To: <2346471A-B6F5-46C2-A9DC-0E98512C2F99@patchspace.co.uk> References: <2346471A-B6F5-46C2-A9DC-0E98512C2F99@patchspace.co.uk> Message-ID: <57c63afe0810191343p556b9941i5e205ac5d4a399cd@mail.gmail.com> On Sun, Oct 19, 2008 at 2:36 PM, Ashley Moran wrote: > Hi > > Two questions: > > Anyone using Merb here, and writing specs for it? (I've just started > tonight, so I'm figuring stuff out as I go along.) > > And WDYAT of their spec extensions[1]? Specifically their "given" > > given "a item exists" do > request(resource(:items), :method => "POST", > :params => { :item => { }}) > end > > describe "resource(:items)" do > > describe "GET", :given => "a item exists" do > before(:each) do > @response = request(resource(:items)) > end > > it "has a list of items" do > pending > @response.should have_xpath("//ul/li") > end > end > > end > > Have to say I was a bit surprised to learn they'd monkey-patched RSpec... Well, in fairness to wycats, rspec doesn't really offer formal extension points that would support this syntax, so he did the best he could given what is available. We've had some discussion about this and haven't landed anywhere firm yet. My opinion is that rspec, as it stands right now, needs a bit of internal cleanup before we start adding new features like that one. Also, the way I'd like to see this go is that rspec exposes a formal extension point - some sort of hook into pre and post-processing of each example including any arguments it was given. Then the merb extension could use a published API rather than monkey patching. FWIW, David > > Ashley > > [1] > http://github.com/wycats/merb-core/tree/master/lib/merb-core/test/test_ext/rspec.rb > > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Sun Oct 19 17:11:55 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 19 Oct 2008 22:11:55 +0100 Subject: [rspec-users] Merb In-Reply-To: <57c63afe0810191343p556b9941i5e205ac5d4a399cd@mail.gmail.com> References: <2346471A-B6F5-46C2-A9DC-0E98512C2F99@patchspace.co.uk> <57c63afe0810191343p556b9941i5e205ac5d4a399cd@mail.gmail.com> Message-ID: On Oct 19, 2008, at 9:43 pm, David Chelimsky wrote: > Well, in fairness to wycats, rspec doesn't really offer formal > extension points that would support this syntax, so he did the best he > could given what is available. We've had some discussion about this > and haven't landed anywhere firm yet. > > My opinion is that rspec, as it stands right now, needs a bit of > internal cleanup before we start adding new features like that one. > Also, the way I'd like to see this go is that rspec exposes a formal > extension point - some sort of hook into pre and post-processing of > each example including any arguments it was given. Then the merb > extension could use a published API rather than monkey patching. Ah, I understand now. I didn't mean my comment in a negative way, just that Merb has a philosophy of simplicity and transparency, and monkey-patching is the Rails way to do things. Hence my surprise. And spec code too... if anything's gonna make me nervous! Is the Merb spec syntax (or something like it) something you'd like in the future? (RSpec 2?) Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From dchelimsky at gmail.com Sun Oct 19 17:19:11 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 19 Oct 2008 16:19:11 -0500 Subject: [rspec-users] Merb In-Reply-To: References: <2346471A-B6F5-46C2-A9DC-0E98512C2F99@patchspace.co.uk> <57c63afe0810191343p556b9941i5e205ac5d4a399cd@mail.gmail.com> Message-ID: <57c63afe0810191419n12d63fcan67d2a5f2b754fe21@mail.gmail.com> On Sun, Oct 19, 2008 at 4:11 PM, Ashley Moran wrote: > > On Oct 19, 2008, at 9:43 pm, David Chelimsky wrote: > >> Well, in fairness to wycats, rspec doesn't really offer formal >> extension points that would support this syntax, so he did the best he >> could given what is available. We've had some discussion about this >> and haven't landed anywhere firm yet. >> >> My opinion is that rspec, as it stands right now, needs a bit of >> internal cleanup before we start adding new features like that one. >> Also, the way I'd like to see this go is that rspec exposes a formal >> extension point - some sort of hook into pre and post-processing of >> each example including any arguments it was given. Then the merb >> extension could use a published API rather than monkey patching. > > > Ah, I understand now. I didn't mean my comment in a negative way, just that > Merb has a philosophy of simplicity and transparency, and monkey-patching is > the Rails way to do things. Hence my surprise. And spec code too... if > anything's gonna make me nervous! > > Is the Merb spec syntax (or something like it) something you'd like in the > future? (RSpec 2?) Not sure about that yet. You can already accomplish the same thing with a variety of existing structures and I think that this structure brings up other questions like: * how about a :when and :then? * how does this impact the output? * etc However, I'm definitely interested in developing and committing to an API that makes it easy to write extensions like this. Then wycats could publish this as a separate extension gem, for example, and those who like it can easily use it w/o concern for the fact that it is monkey patching another library. > > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From caius at caius.name Sun Oct 19 17:31:21 2008 From: caius at caius.name (Caius Durling) Date: Sun, 19 Oct 2008 22:31:21 +0100 Subject: [rspec-users] Merb In-Reply-To: <2346471A-B6F5-46C2-A9DC-0E98512C2F99@patchspace.co.uk> References: <2346471A-B6F5-46C2-A9DC-0E98512C2F99@patchspace.co.uk> Message-ID: On 19 Oct 2008, at 20:36, Ashley Moran wrote: > Anyone using Merb here, and writing specs for it? (I've just > started tonight, so I'm figuring stuff out as I go along.) Funny you should post this, I picked up merb today as well (seeing as the API is finally frozen) and was thinking about posting to see if anyone else was. You attempted to throw cucumber into the mix yet? C --- Caius Durling caius at caius.name +44 (0) 7960 268 100 http://caius.name/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben at benmabey.com Sun Oct 19 17:36:23 2008 From: ben at benmabey.com (Ben Mabey) Date: Sun, 19 Oct 2008 15:36:23 -0600 Subject: [rspec-users] Merb In-Reply-To: References: <2346471A-B6F5-46C2-A9DC-0E98512C2F99@patchspace.co.uk> Message-ID: <48FBA857.2020306@benmabey.com> Caius Durling wrote: > > On 19 Oct 2008, at 20:36, Ashley Moran wrote: > >> Anyone using Merb here, and writing specs for it? (I've just started >> tonight, so I'm figuring stuff out as I go along.) > > Funny you should post this, I picked up merb today as well (seeing as > the API is finally frozen) and was thinking about posting to see if > anyone else was. > > You attempted to throw cucumber into the mix yet? I used the told story runner with merb and I had no issues. I haven't done any merb apps since cucumber but it looks like there is already a library to make using Cucumber in merb easy: http://github.com/david/merb_cucumber/tree/master -Ben From ashley.moran at patchspace.co.uk Sun Oct 19 19:04:07 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 20 Oct 2008 00:04:07 +0100 Subject: [rspec-users] Merb In-Reply-To: References: <2346471A-B6F5-46C2-A9DC-0E98512C2F99@patchspace.co.uk> Message-ID: <85CE5F39-7638-4AE0-ACE9-8E1F6DF42CC1@patchspace.co.uk> On Oct 19, 2008, at 10:31 pm, Caius Durling wrote: > Funny you should post this, I picked up merb today as well (seeing > as the API is finally frozen) and was thinking about posting to see > if anyone else was. > > You attempted to throw cucumber into the mix yet? Of course! :D However, I'm using hand-rolled Celerity-based stuff, rather than the Webrat stuff in the generator. So there's nothing merby about my cucumber files (well, file, right now), but then I like restricting Cucumber to talk over HTTP. I've been taking notes, and hope to blog about the experience in the next week or two. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From mailing_lists at railsnewbie.com Sun Oct 19 22:44:24 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Sun, 19 Oct 2008 22:44:24 -0400 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> <48F8A717.8010409@joesniff.co.uk> <1fb4df0810170842g55b528a0p5face7b51a876aa1@mail.gmail.com> <0372781A-E151-4538-8477-AE41076EFCB1@railsnewbie.com> Message-ID: <06FEBB46-D9A8-43C0-B6E4-DA6D11620116@railsnewbie.com> On Oct 19, 2008, at 12:14 PM, Pat Maddox wrote: > Scott Taylor writes: > >> On Oct 18, 2008, at 9:19 AM, Pat Maddox wrote: >> >>> Scott Taylor writes: >>> >>>> As for #3, I'm >>>> pretty sure that Ruby's method_missing allows one to raise an >>>> exception easily. Not sure what a Javascript mocking framework >>>> would >>>> do in this case. >>> >>> I'm not sure that I buy that this feature is very important. Both >>> Javascript and Ruby blow up when you call a method that doesn't >>> exist on >>> it anyway. What's the difference between "Received unexpected >>> message >>> 'foo'" and "NoMethodError 'foo'"? >> >> Unless I'm mistaken, it's only when *another* method gets called on a >> missing method that an error gets raised: >> >>>>> o = {}; >> Object >>>>> o.foo > > You would need to do o.foo() to actually call the method. That will > give you "o.foo is undefined" > Oops. I feel like a tool. Guess ruby syntax still invades my brain. > >> BTW, Pat - Have you still been working on integrating test spy into >> rspec? > > Nope, I found not_a_mock [1] and it works well. Any plans to roll not_a_mock into rspec core? Scott From lists at ruby-forum.com Mon Oct 20 01:00:53 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Mon, 20 Oct 2008 07:00:53 +0200 Subject: [rspec-users] Where is current_user? Message-ID: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> Hi, I have a controller that uses the current_user attributes to determine if a motion is showable. I can see the motion track through from a fixture to the show action, but not the current_user. My rspec test is describe MotionsController, "handling GET /motions/1" do fixtures :people, :motions before(:each) do @current_user = people(:someuser) @request.session[:user_id] = @current_user.id @motion = motions(:four) controller.stub!(:logged_in?).and_return(true) controller.stub!(:retrieve_user).and_return(@current_user) end it "should match motion and user" do showable = controller.is_showable?(@current_user, @motion) puts "..Motion is showable = #{showable}" # is_showable? shows as true. end def do_get get :show, :id => @motion.id end it "should be successful" do do_get response.should be_success end end In the MotionsController show action the motion is collected with the params[:id] but the @current_user doesn't show. The @current_user and @motion are supplied to is_showable? in the controller for which they have attributes that are compared. Any reason why @current_user isn't showing up in the show action? If I take out the controller stubs in before(:each) then the redirect from session shows as a 302 but the process doesn't proceed to the show action. A mock would require rebuilding the User model for all the checks done in the controller and I am trying to avoid that by using a fixture called from the database to test the true interaction between user and motion. Also, my protected qualifier on is_showable? works in the controller for a browser initiated request by not with the rspec test. I removed protected to get the test done, but how is that supposed to be handled? Thanks very much for your support, HR -- Posted via http://www.ruby-forum.com/. From mailing_lists at railsnewbie.com Mon Oct 20 01:40:21 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 20 Oct 2008 01:40:21 -0400 Subject: [rspec-users] Where is current_user? In-Reply-To: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> Message-ID: On Oct 20, 2008, at 1:00 AM, Harry Bishop wrote: > Hi, > I have a controller that uses the current_user attributes to > determine > if a motion is showable. I can see the motion track through from a > fixture to the show action, but not the current_user. My rspec test > is > > describe MotionsController, "handling GET /motions/1" do > fixtures :people, :motions > > before(:each) do > @current_user = people(:someuser) > @request.session[:user_id] = @current_user.id > @motion = motions(:four) > controller.stub!(:logged_in?).and_return(true) > controller.stub!(:retrieve_user).and_return(@current_user) > end > > it "should match motion and user" do > showable = controller.is_showable?(@current_user, @motion) > puts "..Motion is showable = #{showable}" # is_showable? shows as > true. > end > > def do_get > get :show, :id => @motion.id > end > > it "should be successful" do > do_get > response.should be_success > end > end > > In the MotionsController show action the motion is collected with the > params[:id] but the @current_user doesn't show. > The @current_user and @motion are supplied to is_showable? in the > controller for which they have attributes that are compared. > Any reason why @current_user isn't showing up in the show action? > > If I take out the controller stubs in before(:each) then the redirect > from session shows as a 302 but the process doesn't proceed to the > show > action. > > A mock would require rebuilding the User model for all the checks done > in the controller and I am trying to avoid that by using a fixture > called from the database to test the true interaction between user and > motion. Not necessarily. Have you looked into using a null_object mock? Scott From lists at ruby-forum.com Mon Oct 20 02:12:32 2008 From: lists at ruby-forum.com (Mano ah) Date: Mon, 20 Oct 2008 08:12:32 +0200 Subject: [rspec-users] how should i use response.should be sucess method pass Message-ID: <7eadb1412c3e63e77d808f0513c4131c@ruby-forum.com> I want to test the basic controller test action and to make response.should be_sucess method work for it. How can i do -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Mon Oct 20 03:03:00 2008 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 20 Oct 2008 08:03:00 +0100 Subject: [rspec-users] Mocks: expectations vs spying In-Reply-To: <4DE1E7EB-DC01-4E76-9E95-10703C7A34FD@patchspace.co.uk> References: <60782FC3-38CF-4469-BEA7-BBAA9E8DC862@patchspace.co.uk> <48F7ABDD.4050900@benmabey.com> <51122F6B-D2B8-41E7-9134-FF3AF5FC0F3F@mattwynne.net> <4DE1E7EB-DC01-4E76-9E95-10703C7A34FD@patchspace.co.uk> Message-ID: <021F449B-E61F-408F-8EAE-0544922719DC@mattwynne.net> On 19 Oct 2008, at 21:18, Ashley Moran wrote: > > On Oct 19, 2008, at 9:32 am, Matt Wynne wrote: > >>> [1] http://notahat.com/not_a_mock >> >> Looks sweet - it will be in my first mock on Monday! Thinking about it - how do you use multiple mocking frameworks in a given project? Is it safe to re-open a Spec::Runner.configure do |config| block at the top of an individual spec after I've loaded spec_helper (which will have to be configured to use the default rspec mocking that 90% of the project uses)? cheers, Matt From matt at mattwynne.net Mon Oct 20 03:24:09 2008 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 20 Oct 2008 08:24:09 +0100 Subject: [rspec-users] how should i use response.should be sucess method pass In-Reply-To: <7eadb1412c3e63e77d808f0513c4131c@ruby-forum.com> References: <7eadb1412c3e63e77d808f0513c4131c@ruby-forum.com> Message-ID: Have you looked at this: http://rspec.info/documentation/rails/writing/controllers.html Have you tried using the generators for rspec controllers? On 20 Oct 2008, at 07:12, Mano ah wrote: > > I want to test the basic controller test action and to make > response.should be_sucess method work for it. How can i do > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From mailing_lists at railsnewbie.com Mon Oct 20 04:08:21 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Mon, 20 Oct 2008 04:08:21 -0400 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> <48F8A717.8010409@joesniff.co.uk> <1fb4df0810170842g55b528a0p5face7b51a876aa1@mail.gmail.com> <0372781A-E151-4538-8477-AE41076EFCB1@railsnewbie.com> Message-ID: On Oct 19, 2008, at 12:14 PM, Pat Maddox wrote: > > >> BTW, Pat - Have you still been working on integrating test spy into >> rspec? > > Nope, I found not_a_mock [1] and it works well. Also, relevant to the Screw.Unit and the spying threads, I've hacked together a Javascript mocking/stubbing framework which uses the test- spy pattern, if anyone is interested: http://github.com/smtlaissezfaire/espionage/tree/master Scott From u.alberton at gmail.com Mon Oct 20 07:30:27 2008 From: u.alberton at gmail.com (Bira) Date: Mon, 20 Oct 2008 09:30:27 -0200 Subject: [rspec-users] RSpec-Rails bug with to_xml? Message-ID: Hello, everyone. I've been lurking here for a while, but this is my first post. I think I've run into a RSpec bug in a Rails project I'm working on. I was working on a few REST controllers, and started getting failures on a specific spec that verified whether a certain action returned XML output. I spent quite a lot of time checking my code to see if it was something I did wrong, but it works when I test it manually. So I created an empty Rails app, and wrote the bare minimum of code necessary to reproduce this problem. I'm using Rails 2.1.1, with rspec-1.1.8 and rspec-rails-1.1.8, all installed as gems. I started by creating a dead-simple model with two string attributes and no validations, along with this fixture: # spec/fixtures/users.yml one: name: Name email: email Then I created a simple controller, and its corresponding spec. class UsersController < ApplicationController def index respond_to do |format| format.xml { render :xml => User.find(:all).to_xml} end end end # spec require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe UsersController do fixtures :users it "should return a XML user list" do get :index, :format => :xml response.body.should == User.find(:all).to_xml end end It all looks straightforward enough - I use the same call on both the controller and the spec, so the two results should indeed be the same. However, when I run the spec I get this failure: 1) 'UsersController should return a XML user list' FAILED expected: "\n\n \n 2008-10-20T11:24:28Z\n email\n 953125641\n Name\n 2008-10-20T11:24:28Z\n \n\n", got: " " (using ==) ./spec/controllers/users_controller_spec.rb:10: /usr/lib64/ruby/1.8/timeout.rb:53:in `timeout' Finished in 0.256981 seconds This happens both when using "rake spec" and when running only that spec file. Firing up the app and accessing localhost:3000/users.xml returns the correct result. In the "real" project, it's even weirder: the "expected" site of the assertion shows a string composed of the XML out put concatenated to itself, and the "got" side has the correct output. Something like "Expected 'aa' but got 'a'". What could the problem be? Is it really a RSpec bug, or is it something I did wrong? -- Bira http://compexplicita.wordpress.com http://compexplicita.tumblr.com From zuperinfinite at gmail.com Mon Oct 20 07:35:24 2008 From: zuperinfinite at gmail.com (Bart Zonneveld) Date: Mon, 20 Oct 2008 13:35:24 +0200 Subject: [rspec-users] testing a render layout statement in a controller In-Reply-To: <48F6E433.9020405@gmail.com> References: <48F6E433.9020405@gmail.com> Message-ID: <19EC77D3-45A5-4541-AC47-106577D30CF3@gmail.com> On 16-okt-2008, at 8:50, Dave Gamphani Phiri wrote: > Here, I was trying to test if the out put displays with a layouts/menu > template. > Can somebody help on how you test the render(:layout => "layouts/ > menu") statement in a controller or this is supposed to be tested in > the view? Try this: render(:layout => "layouts/menu") and return cheers, bartz From lists at ruby-forum.com Mon Oct 20 07:53:23 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Mon, 20 Oct 2008 13:53:23 +0200 Subject: [rspec-users] Where is current_user? In-Reply-To: References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> Message-ID: <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> Scott Taylor wrote: > On Oct 20, 2008, at 1:00 AM, Harry Bishop wrote: > >> before(:each) do >> true. >> end >> action. >> >> A mock would require rebuilding the User model for all the checks done >> in the controller and I am trying to avoid that by using a fixture >> called from the database to test the true interaction between user and >> motion. > > Not necessarily. Have you looked into using a null_object mock? > > Scott Yes, I tried null object but it doesn't get past is_showable? which says it has a nil object passed in. The idea is to use @current_user to determine if @motion is shown on the view. So how come @current_user isn't available in the controller? TIA, HR -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Oct 20 08:00:01 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 20 Oct 2008 07:00:01 -0500 Subject: [rspec-users] Where is current_user? In-Reply-To: <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> Message-ID: <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> On Mon, Oct 20, 2008 at 6:53 AM, Harry Bishop wrote: > Scott Taylor wrote: >> On Oct 20, 2008, at 1:00 AM, Harry Bishop wrote: >> >>> before(:each) do >>> true. >>> end >>> action. >>> >>> A mock would require rebuilding the User model for all the checks done >>> in the controller and I am trying to avoid that by using a fixture >>> called from the database to test the true interaction between user and >>> motion. >> >> Not necessarily. Have you looked into using a null_object mock? >> >> Scott > > Yes, I tried null object but it doesn't get past is_showable? which says > it has a nil object passed in. > The idea is to use @current_user to determine if @motion is shown on the > view. So how come @current_user isn't available in the controller? Can you please post the controller code? > > TIA, > HR > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Oct 20 08:24:48 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Mon, 20 Oct 2008 14:24:48 +0200 Subject: [rspec-users] Where is current_user? In-Reply-To: <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> Message-ID: David Chelimsky wrote: > On Mon, Oct 20, 2008 at 6:53 AM, Harry Bishop > wrote: >>>> called from the database to test the true interaction between user and >>>> motion. >>> >>> Not necessarily. Have you looked into using a null_object mock? >>> >>> Scott >> >> Yes, I tried null object but it doesn't get past is_showable? which says >> it has a nil object passed in. >> The idea is to use @current_user to determine if @motion is shown on the >> view. So how come @current_user isn't available in the controller? > > Can you please post the controller code? Hi, The controller show action is: def show @motion = Motion.find(params[:id]) if is_showable?(@current_user, @motion) (@vote = @motion.votes.find_by_shortname(@current_user.shortname)) if is_votable?(@current_user, @motion) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @motion } end else flash[:error] = "You are not in that group." redirect_to motions_path end end HR -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Oct 20 08:27:14 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 20 Oct 2008 07:27:14 -0500 Subject: [rspec-users] Where is current_user? In-Reply-To: References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> Message-ID: <57c63afe0810200527n6cb25f0au7849de5d7709c454@mail.gmail.com> On Mon, Oct 20, 2008 at 7:24 AM, Harry Bishop wrote: > David Chelimsky wrote: >> On Mon, Oct 20, 2008 at 6:53 AM, Harry Bishop >> wrote: >>>>> called from the database to test the true interaction between user and >>>>> motion. >>>> >>>> Not necessarily. Have you looked into using a null_object mock? >>>> >>>> Scott >>> >>> Yes, I tried null object but it doesn't get past is_showable? which says >>> it has a nil object passed in. >>> The idea is to use @current_user to determine if @motion is shown on the >>> view. So how come @current_user isn't available in the controller? >> >> Can you please post the controller code? > > Hi, > The controller show action is: > > def show > @motion = Motion.find(params[:id]) > if is_showable?(@current_user, @motion) > (@vote = @motion.votes.find_by_shortname(@current_user.shortname)) > if is_votable?(@current_user, @motion) > > respond_to do |format| > format.html # show.html.erb > format.xml { render :xml => @motion } > end > else > flash[:error] = "You are not in that group." > redirect_to motions_path > end > end Where is @current_user defined in the controller? > > HR > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Oct 20 08:28:04 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Mon, 20 Oct 2008 14:28:04 +0200 Subject: [rspec-users] Where is current_user? In-Reply-To: References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> Message-ID: <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> Harry Bishop wrote: > David Chelimsky wrote: >> On Mon, Oct 20, 2008 at 6:53 AM, Harry Bishop >> wrote: >>>>> called from the database to test the true interaction between user and >>>>> motion. >>>> >>>> Not necessarily. Have you looked into using a null_object mock? >>>> >>>> Scott >>> >>> Yes, I tried null object but it doesn't get past is_showable? which says >>> it has a nil object passed in. >>> The idea is to use @current_user to determine if @motion is shown on the >>> view. So how come @current_user isn't available in the controller? >> >> Can you please post the controller code? > > Hi, The controller show action is: def show @motion = Motion.find(params[:id]) if is_showable?(@current_user, @motion) (@vote = @motion.votes.find_by_shortname(@current_user.shortname)) if is_votable?(@current_user, @motion) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @motion } end else flash[:error] = "You are not in that group." redirect_to motions_path end end HR and is_showable? here: def is_showable?(user, motion) user.group_member?( motion.group_name ) end -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Oct 20 08:30:04 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Mon, 20 Oct 2008 14:30:04 +0200 Subject: [rspec-users] Where is current_user? In-Reply-To: <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> Message-ID: <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> @current_user is retrieved in the application controller with retrieve_user. -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Oct 20 08:36:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 20 Oct 2008 07:36:21 -0500 Subject: [rspec-users] Where is current_user? In-Reply-To: <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> Message-ID: <57c63afe0810200536r2eb597e5ge70cc799c4497c57@mail.gmail.com> On Mon, Oct 20, 2008 at 7:30 AM, Harry Bishop wrote: > @current_user is retrieved in the application controller with > retrieve_user. I don't see where retrieve_user is getting called in the rspec example code or in the show action. Maybe it's not actually getting called anywhere? > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Mon Oct 20 08:30:33 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 20 Oct 2008 07:30:33 -0500 Subject: [rspec-users] Error loading Rails fixtures In-Reply-To: <504319E3-1E44-44A7-82DE-724284609C6F@gmail.com> References: <504319E3-1E44-44A7-82DE-724284609C6F@gmail.com> Message-ID: <57c63afe0810200530l3600e4ebuda974084bbfa2188@mail.gmail.com> On Sat, Oct 18, 2008 at 1:55 PM, Scott Burton wrote: > Hi all; > > I'm getting a weird error from the rspec gem when using rake to load > fixtures in rails: > > % rake db:fixtures:load RAILS_ENV=test > /path/to/Ruby/Gems/1.8/gems/rspec-1.1.8/lib/spec/runner/options.rb:229:in > `files_to_load': File or directory not found: db:fixtures:load > (RuntimeError) > from > /path/to/Ruby/Gems/1.8/gems/rspec-1.1.8/lib/spec/runner/options.rb:221:in > `each' > from > /path/to/Ruby/Gems/1.8/gems/rspec-1.1.8/lib/spec/runner/options.rb:221:in > `files_to_load' > from > /path/to/Ruby/Gems/1.8/gems/rspec-1.1.8/lib/spec/runner/options.rb:98:in > `run_examples' > from /path/to/Ruby/Gems/1.8/gems/rspec-1.1.8/lib/spec.rb:21:in `run' > from > /path/to/Ruby/Gems/1.8/gems/rspec-1.1.8/lib/spec/runner.rb:192:in > `register_at_exit_hook' > from /usr/bin/rake:19 > > It's getting something in files_to_load that isn't a file or directory. It's > isolated to one project, so it seems configuration-related. > > Anyone know what might be going on here? Would you please file a bug report at http://rspec.lighthouseapp.com? > > Many thanks, > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Oct 20 09:02:00 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Mon, 20 Oct 2008 15:02:00 +0200 Subject: [rspec-users] Where is current_user? In-Reply-To: <57c63afe0810200536r2eb597e5ge70cc799c4497c57@mail.gmail.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> <57c63afe0810200536r2eb597e5ge70cc799c4497c57@mail.gmail.com> Message-ID: <1daa44bdd5419fced37fc915f62bd002@ruby-forum.com> David Chelimsky wrote: > On Mon, Oct 20, 2008 at 7:30 AM, Harry Bishop > wrote: >> @current_user is retrieved in the application controller with >> retrieve_user. > > I don't see where retrieve_user is getting called in the rspec example > code or in the show action. Maybe it's not actually getting called > anywhere? I guess that is what's happening, although I have this line in the before(:each) controller.stub!(:retrieve_user).and_return(@current_user) and the show action has a :login_required which calls :logged_in? since MotionsController is a subclass of ApplicationController doesn't running the rspec test invoke the methods here: class ApplicationController < ActionController::Base helper :all # include all helpers, all the time before_filter :retrieve_user protected def retrieve_user return unless session[:user_id] @current_user = Person.current_auth_record(session[:user_id]) end def logged_in? @current_user.is_a?(Person) end helper_method :logged_in? def login_required return true if logged_in? session[:return_to] = request.request_uri redirect_to new_session_path and return false end end -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Oct 20 09:08:39 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 20 Oct 2008 08:08:39 -0500 Subject: [rspec-users] Where is current_user? In-Reply-To: <1daa44bdd5419fced37fc915f62bd002@ruby-forum.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> <57c63afe0810200536r2eb597e5ge70cc799c4497c57@mail.gmail.com> <1daa44bdd5419fced37fc915f62bd002@ruby-forum.com> Message-ID: <57c63afe0810200608y3bab2582l5df08c954b67810@mail.gmail.com> On Mon, Oct 20, 2008 at 8:02 AM, Harry Bishop wrote: > David Chelimsky wrote: >> On Mon, Oct 20, 2008 at 7:30 AM, Harry Bishop >> wrote: >>> @current_user is retrieved in the application controller with >>> retrieve_user. >> >> I don't see where retrieve_user is getting called in the rspec example >> code or in the show action. Maybe it's not actually getting called >> anywhere? > > I guess that is what's happening, although I have this line in the > before(:each) > > controller.stub!(:retrieve_user).and_return(@current_user) > > and the show action has a :login_required which calls :logged_in? > since MotionsController is a subclass of ApplicationController doesn't > running the rspec test invoke the methods here: > > class ApplicationController < ActionController::Base > helper :all # include all helpers, all the time > before_filter :retrieve_user > > protected > > def retrieve_user > return unless session[:user_id] > @current_user = Person.current_auth_record(session[:user_id]) > end retrieve_user, the real method, sets an instance variable that other methods expect to be set rather than returning a value. When this is stubbed with a *return value* of the user, the instance variable never gets set inside the controller. I'd add a current_user method that returns @current_user, and then stub *that* in the code examples: # in ApplicationController def current_user @current_user end # in MotionsController def show ... if is_showable?(current_user, @motion) ... end # in example controller.stub!(:current_user).and_return(@current_user) HTH, David > > def logged_in? > @current_user.is_a?(Person) > end > helper_method :logged_in? > > def login_required > return true if logged_in? > session[:return_to] = request.request_uri > redirect_to new_session_path and return false > end > > end > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Mon Oct 20 09:19:50 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 20 Oct 2008 09:19:50 -0400 Subject: [rspec-users] RSpec-Rails bug with to_xml? In-Reply-To: References: Message-ID: <85d99afe0810200619y752a44cey9b730308f55513fc@mail.gmail.com> On Mon, Oct 20, 2008 at 7:30 AM, Bira wrote: > Hello, everyone. I've been lurking here for a while, but this is my first post. > > I think I've run into a RSpec bug in a Rails project I'm working on. I > was working on a few REST controllers, and started getting failures on > a specific spec that verified whether a certain action returned XML > output. I spent quite a lot of time checking my code to see if it was > something I did wrong, but it works when I test it manually. > > So I created an empty Rails app, and wrote the bare minimum of code > necessary to reproduce this problem. I'm using Rails 2.1.1, with > rspec-1.1.8 and rspec-rails-1.1.8, all installed as gems. > > I started by creating a dead-simple model with two string attributes > and no validations, along with this fixture: > > # spec/fixtures/users.yml > one: > name: Name > email: email > > Then I created a simple controller, and its corresponding spec. > > class UsersController < ApplicationController > > def index > respond_to do |format| > format.xml { render :xml => User.find(:all).to_xml} > end > end > > end > > # spec > > require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') > > describe UsersController do > > fixtures :users > > it "should return a XML user list" do > get :index, :format => :xml > response.body.should == User.find(:all).to_xml > end > > > end > > It all looks straightforward enough - I use the same call on both the > controller and the spec, so the two results should indeed be the same. > However, when I run the spec I get this failure: > > 1) > 'UsersController should return a XML user list' FAILED > expected: "\n type=\"array\">\n \n type=\"datetime\">2008-10-20T11:24:28Z\n > email\n 953125641\n > Name\n type=\"datetime\">2008-10-20T11:24:28Z\n > \n\n", > got: " " (using ==) > ./spec/controllers/users_controller_spec.rb:10: > /usr/lib64/ruby/1.8/timeout.rb:53:in `timeout' > > Finished in 0.256981 seconds > > > This happens both when using "rake spec" and when running only that > spec file. Firing up the app and accessing localhost:3000/users.xml > returns the correct result. In the "real" project, it's even weirder: > the "expected" site of the assertion shows a string composed of the > XML out put concatenated to itself, and the "got" side has the correct > output. Something like "Expected 'aa' but got 'a'". > > What could the problem be? Is it really a RSpec bug, or is it > something I did wrong? Look up "integrate_views" on the rspec-rails docs: http://rspec.rubyforge.org/rspec-rails/1.1.8/ Also there is a section called "Integration Model". Read that. If you have any further questions don't hesitate to ask. HTH, -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From lists at ruby-forum.com Mon Oct 20 09:29:16 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Mon, 20 Oct 2008 15:29:16 +0200 Subject: [rspec-users] Where is current_user? In-Reply-To: <57c63afe0810200608y3bab2582l5df08c954b67810@mail.gmail.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> <57c63afe0810200536r2eb597e5ge70cc799c4497c57@mail.gmail.com> <1daa44bdd5419fced37fc915f62bd002@ruby-forum.com> <57c63afe0810200608y3bab2582l5df08c954b67810@mail.gmail.com> Message-ID: <284cf96e5c080d4da7251d134028ba5d@ruby-forum.com> David Chelimsky wrote: > retrieve_user, the real method, sets an instance variable that other > methods expect to be set rather than returning a value. When this is > stubbed with a *return value* of the user, the instance variable never > gets set inside the controller. > > I'd add a current_user method that returns @current_user, and then > stub *that* in the code examples: Hi David, I understand your response now that its pointed out what is happening between controller and rspec, however, this means changing my code to test it. This strikes me as backward. Isn't there another way to get the @current_user "set" for use in the controller? BTW - the actual code runs fine. HR -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Oct 20 09:39:43 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Mon, 20 Oct 2008 15:39:43 +0200 Subject: [rspec-users] Where is current_user? In-Reply-To: <284cf96e5c080d4da7251d134028ba5d@ruby-forum.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> <57c63afe0810200536r2eb597e5ge70cc799c4497c57@mail.gmail.com> <1daa44bdd5419fced37fc915f62bd002@ruby-forum.com> <57c63afe0810200608y3bab2582l5df08c954b67810@mail.gmail.com> <284cf96e5c080d4da7251d134028ba5d@ruby-forum.com> Message-ID: <2d7710a4f4af767ed5950da81bc6be8c@ruby-forum.com> > David Chelimsky wrote: >> >> I'd add a current_user method that returns @current_user, and then >> stub *that* in the code examples: Hi David, I found that I can stub out is_showable?(@current_user, @motion) and the test passes. I was trying to use the code logic to do this, but now see that @current_user won't be seen by the show action as it is set in the actual code. Thanks for your help. HR -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Oct 20 09:52:06 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 20 Oct 2008 08:52:06 -0500 Subject: [rspec-users] Where is current_user? In-Reply-To: <284cf96e5c080d4da7251d134028ba5d@ruby-forum.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> <57c63afe0810200536r2eb597e5ge70cc799c4497c57@mail.gmail.com> <1daa44bdd5419fced37fc915f62bd002@ruby-forum.com> <57c63afe0810200608y3bab2582l5df08c954b67810@mail.gmail.com> <284cf96e5c080d4da7251d134028ba5d@ruby-forum.com> Message-ID: <57c63afe0810200652qa1089c5g7f9f6e8357750c42@mail.gmail.com> On Mon, Oct 20, 2008 at 8:29 AM, Harry Bishop wrote: > David Chelimsky wrote: >> retrieve_user, the real method, sets an instance variable that other >> methods expect to be set rather than returning a value. When this is >> stubbed with a *return value* of the user, the instance variable never >> gets set inside the controller. >> >> I'd add a current_user method that returns @current_user, and then >> stub *that* in the code examples: > > Hi David, > I understand your response now that its pointed out what is happening > between controller and rspec, however, this means changing my code to > test it. This strikes me as backward. When things are hard to test they are hard to maintain, so maintainability requires testability. When a simple change makes something easier to test, that change brings a lot of value. That's the spirit of rspec, BDD and even TDD. > Isn't there another way to get > the @current_user "set" for use in the controller? Sure, but it's fugly: controller.instance_eval { @current_user = people(:someuser) } > BTW - the actual code runs fine. Since maintainability requires testability, just because it works doesn't mean it's maintainable. FWIW, David > > HR > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Oct 20 10:09:46 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Mon, 20 Oct 2008 16:09:46 +0200 Subject: [rspec-users] Where is current_user? In-Reply-To: <57c63afe0810200652qa1089c5g7f9f6e8357750c42@mail.gmail.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> <57c63afe0810200536r2eb597e5ge70cc799c4497c57@mail.gmail.com> <1daa44bdd5419fced37fc915f62bd002@ruby-forum.com> <57c63afe0810200608y3bab2582l5df08c954b67810@mail.gmail.com> <284cf96e5c080d4da7251d134028ba5d@ruby-forum.com> <57c63afe0810200652qa1089c5g7f9f6e8357750c42@mail.gmail.com> Message-ID: <73808a61e92fa7edc11b9ba99d88d36c@ruby-forum.com> David Chelimsky wrote: > When things are hard to test they are hard to maintain, so > maintainability requires testability. When a simple change makes > something easier to test, that change brings a lot of value. That's > the spirit of rspec, BDD and even TDD. Thanks David, I am new to rspec and am enjoying the interchange between build a test then build the code. In this case I'm late to the party. This particular setup for @current_user makes sense to me but I understand your point about maintainability. In trying to understand what rspec is doing, my thinking was that since MotionsController is a subclass of ApplicationController any instance variable set in ApplicationController was available to MotionsController. I think you are telling me that rspec doesn't invoke this. So I need to think about the implications here. Yes, I want the advantages of rspec and having maintainable code. HR -- Posted via http://www.ruby-forum.com/. From zach.dennis at gmail.com Mon Oct 20 10:44:29 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 20 Oct 2008 10:44:29 -0400 Subject: [rspec-users] Where is current_user? In-Reply-To: <73808a61e92fa7edc11b9ba99d88d36c@ruby-forum.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> <57c63afe0810200536r2eb597e5ge70cc799c4497c57@mail.gmail.com> <1daa44bdd5419fced37fc915f62bd002@ruby-forum.com> <57c63afe0810200608y3bab2582l5df08c954b67810@mail.gmail.com> <284cf96e5c080d4da7251d134028ba5d@ruby-forum.com> <57c63afe0810200652qa1089c5g7f9f6e8357750c42@mail.gmail.com> <73808a61e92fa7edc11b9ba99d88d36c@ruby-forum.com> Message-ID: <85d99afe0810200744x4755e564t85d014accbe1d871@mail.gmail.com> On Mon, Oct 20, 2008 at 10:09 AM, Harry Bishop wrote: > David Chelimsky wrote: > >> When things are hard to test they are hard to maintain, so >> maintainability requires testability. When a simple change makes >> something easier to test, that change brings a lot of value. That's >> the spirit of rspec, BDD and even TDD. > > Thanks David, > I am new to rspec and am enjoying the interchange between build a test > then build the code. In this case I'm late to the party. This > particular setup for @current_user makes sense to me but I understand > your point about maintainability. > > In trying to understand what rspec is doing, my thinking was that since > MotionsController is a subclass of ApplicationController any instance > variable set in ApplicationController was available to > MotionsController. I think you are telling me that rspec doesn't invoke > this. So I need to think about the implications here. The @current_user instance variable was being set by the ApplicationController#retrieve_user method, but your spec was stubbing out the #retrieve_user method. This means that the original ApplicationController#retreieve_user method is not going to get called because you have explicitly told RSpec to stub out that method and return the current user from your spec. Since the original method is not going to get called the @current_user instance variable in the controller never gets set. -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From nick at deadorange.com Mon Oct 20 11:21:59 2008 From: nick at deadorange.com (Nick Hoffman) Date: Mon, 20 Oct 2008 11:21:59 -0400 Subject: [rspec-users] RSpec-Rails bug with to_xml? In-Reply-To: <85d99afe0810200619y752a44cey9b730308f55513fc@mail.gmail.com> References: <85d99afe0810200619y752a44cey9b730308f55513fc@mail.gmail.com> Message-ID: <10DED607-D3A6-4794-B197-4EF40E60F14A@deadorange.com> On 2008-10-20, at 09:19, Zach Dennis wrote: > Look up "integrate_views" on the rspec-rails docs: > http://rspec.rubyforge.org/rspec-rails/1.1.8/ > > Also there is a section called "Integration Model". Read that. If you > have any further questions don't hesitate to ask. HTH, Hi Zach. I searched for "integration" on that page, searched Google, and did a Google site-search on rspec.info and rspec.rubyforge.org for "integration model", but no relevant hits came up. When you have a minute, would you mind sending a link our way, please? Thanks, Nick From dchelimsky at gmail.com Mon Oct 20 11:24:22 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 20 Oct 2008 10:24:22 -0500 Subject: [rspec-users] RSpec-Rails bug with to_xml? In-Reply-To: <10DED607-D3A6-4794-B197-4EF40E60F14A@deadorange.com> References: <85d99afe0810200619y752a44cey9b730308f55513fc@mail.gmail.com> <10DED607-D3A6-4794-B197-4EF40E60F14A@deadorange.com> Message-ID: <57c63afe0810200824r6665ad35h89178ec827c62d94@mail.gmail.com> On Mon, Oct 20, 2008 at 10:21 AM, Nick Hoffman wrote: > On 2008-10-20, at 09:19, Zach Dennis wrote: >> >> Look up "integrate_views" on the rspec-rails docs: >> http://rspec.rubyforge.org/rspec-rails/1.1.8/ >> >> Also there is a section called "Integration Model". Read that. If you >> have any further questions don't hesitate to ask. HTH, > > Hi Zach. I searched for "integration" on that page, searched Google, and did > a Google site-search on rspec.info and rspec.rubyforge.org for "integration > model", but no relevant hits came up. When you have a minute, would you mind > sending a link our way, please? It's Integration Mode, not Model :) http://rspec.rubyforge.org/rspec-rails/1.1.8/classes/Spec/Rails/Example/ControllerExampleGroup.html Cheers, David > > Thanks, > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Mon Oct 20 11:25:40 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 20 Oct 2008 11:25:40 -0400 Subject: [rspec-users] RSpec-Rails bug with to_xml? In-Reply-To: <57c63afe0810200824r6665ad35h89178ec827c62d94@mail.gmail.com> References: <85d99afe0810200619y752a44cey9b730308f55513fc@mail.gmail.com> <10DED607-D3A6-4794-B197-4EF40E60F14A@deadorange.com> <57c63afe0810200824r6665ad35h89178ec827c62d94@mail.gmail.com> Message-ID: <85d99afe0810200825h9700f87p2e025b2c595abaf2@mail.gmail.com> On Mon, Oct 20, 2008 at 11:24 AM, David Chelimsky wrote: > On Mon, Oct 20, 2008 at 10:21 AM, Nick Hoffman wrote: >> On 2008-10-20, at 09:19, Zach Dennis wrote: >>> >>> Look up "integrate_views" on the rspec-rails docs: >>> http://rspec.rubyforge.org/rspec-rails/1.1.8/ >>> >>> Also there is a section called "Integration Model". Read that. If you >>> have any further questions don't hesitate to ask. HTH, >> >> Hi Zach. I searched for "integration" on that page, searched Google, and did >> a Google site-search on rspec.info and rspec.rubyforge.org for "integration >> model", but no relevant hits came up. When you have a minute, would you mind >> sending a link our way, please? > > It's Integration Mode, not Model :) Sorry about that Nick, typo on my end! > > http://rspec.rubyforge.org/rspec-rails/1.1.8/classes/Spec/Rails/Example/ControllerExampleGroup.html > > Cheers, > David > -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From nick at deadorange.com Mon Oct 20 11:28:32 2008 From: nick at deadorange.com (Nick Hoffman) Date: Mon, 20 Oct 2008 11:28:32 -0400 Subject: [rspec-users] RSpec-Rails bug with to_xml? In-Reply-To: <57c63afe0810200824r6665ad35h89178ec827c62d94@mail.gmail.com> References: <85d99afe0810200619y752a44cey9b730308f55513fc@mail.gmail.com> <10DED607-D3A6-4794-B197-4EF40E60F14A@deadorange.com> <57c63afe0810200824r6665ad35h89178ec827c62d94@mail.gmail.com> Message-ID: <4D3F902F-78FE-4071-8A6E-113DC3DD132A@deadorange.com> On 2008-10-20, at 11:24, David Chelimsky wrote: > It's Integration Mode, not Model :) > > http://rspec.rubyforge.org/rspec-rails/1.1.8/classes/Spec/Rails/Example/ControllerExampleGroup.html Ah! Thanks for the clarification, David. No worries about the typo, Zach. My fingers often have a mind of their own, too. -Nick From lists at ruby-forum.com Mon Oct 20 12:34:40 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Mon, 20 Oct 2008 18:34:40 +0200 Subject: [rspec-users] Where is current_user? In-Reply-To: <85d99afe0810200744x4755e564t85d014accbe1d871@mail.gmail.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> <57c63afe0810200536r2eb597e5ge70cc799c4497c57@mail.gmail.com> <1daa44bdd5419fced37fc915f62bd002@ruby-forum.com> <57c63afe0810200608y3bab2582l5df08c954b67810@mail.gmail.com> <284cf96e5c080d4da7251d134028ba5d@ruby-forum.com> <57c63afe0810200652qa1089c5g7f9f6e8357750c42@mail.gmail.com> <73808a61e92fa7edc11b9ba99d88d36c@ruby-forum.com> <85d99afe0810200744x4755e564t85d014accbe1d871@mail.gmail.com> Message-ID: Zach Dennis wrote: > The @current_user instance variable was being set by the > ApplicationController#retrieve_user method, but your spec was stubbing > out the #retrieve_user method. This means that the original > ApplicationController#retreieve_user method is not going to get called > because you have explicitly told RSpec to stub out that method and > return the current user from your spec. Since the original method is > not going to get called the @current_user instance variable in the > controller never gets set. > Hi Zack, I put the stub in to advance the process to the MotionsController because without it the process hangs in ApplicationController with a redirect to show. My test log shows the 302 but show doesn't get called. Is there some way around that? So far David's method of making retrieve_user return @current_user and stubbing the protected method is_showable? works but doesn't recognize the inheritance that should be there for @current_user. HR -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Mon Oct 20 12:49:11 2008 From: lists at ruby-forum.com (Rasmus Rasmussen) Date: Mon, 20 Oct 2008 18:49:11 +0200 Subject: [rspec-users] ????? lots of Q's about integration tests with rspec Message-ID: <6a4d2b24410aa3d112e83423d2f8b327@ruby-forum.com> Hello all, where should I put the integration tests when using rspec? There is an integration-folder in test-directory, but if I place tests here then how can I benefit from the fixtures-dir in spec-folder? I want to stay in the spec-folder, right? I do not want to maintain two fixtures. I'm not sure how important it is to stick with the default-folders that come with rspec and rails. What if I need those scripts someday. According to rspec's documentation they recommend that I stub out the model when testing controller. For me there is not much value from testing controllers this way. Controller-code is small, it is often mostly workflow-code. Also, I thought that part of the whole method of BDD was to begin with full-integration tests at the outermost level and that I then perhaps could work my way in to the model with unit tests. I cannot understand why I should stub out model in controller-tests and call db in model-tests. Shouldn't it be the other way round? Drill through the whole cake from controller-tsts and stub everything else out from model-tests ? I would rather delete spec/controller and have something like spec/full or maybe spec/requirements. That would give me my full-integration tests and the controller-tests. Are there any problems with this strategy? Thanks for advice! /Rasmus -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Oct 20 12:53:47 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 20 Oct 2008 11:53:47 -0500 Subject: [rspec-users] Where is current_user? In-Reply-To: References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> <57c63afe0810200536r2eb597e5ge70cc799c4497c57@mail.gmail.com> <1daa44bdd5419fced37fc915f62bd002@ruby-forum.com> <57c63afe0810200608y3bab2582l5df08c954b67810@mail.gmail.com> <284cf96e5c080d4da7251d134028ba5d@ruby-forum.com> <57c63afe0810200652qa1089c5g7f9f6e8357750c42@mail.gmail.com> <73808a61e92fa7edc11b9ba99d88d36c@ruby-forum.com> <85d99afe0810200744x4755e564t85d014accbe1d871@mail.gmail.com> Message-ID: <57c63afe0810200953v1eb7d44do5aa32eee4503102b@mail.gmail.com> On Mon, Oct 20, 2008 at 11:34 AM, Harry Bishop wrote: > Zach Dennis wrote: > >> The @current_user instance variable was being set by the >> ApplicationController#retrieve_user method, but your spec was stubbing >> out the #retrieve_user method. This means that the original >> ApplicationController#retreieve_user method is not going to get called >> because you have explicitly told RSpec to stub out that method and >> return the current user from your spec. Since the original method is >> not going to get called the @current_user instance variable in the >> controller never gets set. >> > Hi Zack, > I put the stub in to advance the process to the MotionsController > because without it the process hangs in ApplicationController with a > redirect to show. > My test log shows the 302 but show doesn't get called. Is there some > way around that? > > So far David's method of making retrieve_user return @current_user That's not what I recommended. I recommended adding a new method named current_user that returns @current_user, so you can refer to just current_user in method calls and stub that out if you want to control its value from the code example. > and stubbing the protected method is_showable? works but doesn't > recognize the inheritance that should be there for @current_user. Inheritance? > > HR > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Mon Oct 20 13:01:30 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Mon, 20 Oct 2008 19:01:30 +0200 Subject: [rspec-users] Where is current_user? In-Reply-To: <57c63afe0810200953v1eb7d44do5aa32eee4503102b@mail.gmail.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> <57c63afe0810200536r2eb597e5ge70cc799c4497c57@mail.gmail.com> <1daa44bdd5419fced37fc915f62bd002@ruby-forum.com> <57c63afe0810200608y3bab2582l5df08c954b67810@mail.gmail.com> <284cf96e5c080d4da7251d134028ba5d@ruby-forum.com> <57c63afe0810200652qa1089c5g7f9f6e8357750c42@mail.gmail.com> <73808a61e92fa7edc11b9ba99d88d36c@ruby-forum.com> <85d99afe0810200744x4755e564t85d014accbe1d871@mail.gmail.com> <57c63afe0810200953v1eb7d44do5aa32eee4503102b@mail.gmail.com> Message-ID: <0aea9c8303de390c98ae84bd679d62d9@ruby-forum.com> Hi David, Yes, I understand. I was trying to answer Zack with regard to my attempt to set the @current_user and what happened. I will be using your method as a test shortly. Thanks, HR -- Posted via http://www.ruby-forum.com/. From dchelimsky at gmail.com Mon Oct 20 13:03:08 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Mon, 20 Oct 2008 12:03:08 -0500 Subject: [rspec-users] Where is current_user? In-Reply-To: <0aea9c8303de390c98ae84bd679d62d9@ruby-forum.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <1daa44bdd5419fced37fc915f62bd002@ruby-forum.com> <57c63afe0810200608y3bab2582l5df08c954b67810@mail.gmail.com> <284cf96e5c080d4da7251d134028ba5d@ruby-forum.com> <57c63afe0810200652qa1089c5g7f9f6e8357750c42@mail.gmail.com> <73808a61e92fa7edc11b9ba99d88d36c@ruby-forum.com> <85d99afe0810200744x4755e564t85d014accbe1d871@mail.gmail.com> <57c63afe0810200953v1eb7d44do5aa32eee4503102b@mail.gmail.com> <0aea9c8303de390c98ae84bd679d62d9@ruby-forum.com> Message-ID: <57c63afe0810201003n4bb6d745l88f1209dd005999b@mail.gmail.com> On Mon, Oct 20, 2008 at 12:01 PM, Harry Bishop wrote: > Hi David, > > Yes, I understand. I was trying to answer Zack with regard to my > attempt to set the @current_user and what happened. > > I will be using your method as a test shortly. Cool. > > Thanks, > HR > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Mon Oct 20 13:24:37 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Mon, 20 Oct 2008 13:24:37 -0400 Subject: [rspec-users] ????? lots of Q's about integration tests with rspec In-Reply-To: <6a4d2b24410aa3d112e83423d2f8b327@ruby-forum.com> References: <6a4d2b24410aa3d112e83423d2f8b327@ruby-forum.com> Message-ID: <85d99afe0810201024ne999ee9wf0710886ba47e145@mail.gmail.com> On Mon, Oct 20, 2008 at 12:49 PM, Rasmus Rasmussen wrote: > Hello all, > > where should I put the integration tests when using rspec? > > There is an integration-folder in test-directory, but if I place tests > here then how can I benefit from the fixtures-dir in spec-folder? I want > to stay in the spec-folder, right? I do not want to maintain two > fixtures. I'm not sure how important it is to stick with the > default-folders that come with rspec and rails. What if I need those > scripts someday. > If you don't need it today and it's not being used, delete it. If you find you need it, well, that's why use version control. > According to rspec's documentation they recommend that I stub out the > model when testing controller. For me there is not much value from > testing controllers this way. Controller-code is small, it is often > mostly workflow-code. Also, I thought that part of the whole method of > BDD was to begin with full-integration tests at the outermost level and > that I then perhaps could work my way in to the model with unit tests. I > cannot understand why I should stub out model in controller-tests and > call db in model-tests. Shouldn't it be the other way round? Drill > through the whole cake from controller-tsts and stub everything else out > from model-tests ? A controller test is not an integration test. In default Rails testing (non-rspec) controllers are often tested this way, but in RSpec controllers are treated as objects that should be tested in isolation. Stories/features are used to run through the whole stack. Cucumber is the tool that you'll want to look into for providing that full-stack integration testing when using RSpec: http://github.com/aslakhellesoy/cucumber/wikis I know there are people who use controller specs are integration-style tests with RSpec. You'll want to look into "Integration Mode" if you are interested in doing that: http://rspec.rubyforge.org/rspec-rails/1.1.8/classes/Spec/Rails/Example/ControllerExampleGroup.html I don't do that, and I don't encourage others to do that, but there are situations where people feel it is valuable, just not me. The fact that controllers are simple is a great thing. Spec'ing controllers in isolation puts you in a position to leave controllers simple as the application grows and changes > > I would rather delete spec/controller and have something like spec/full > or maybe spec/requirements. That would give me my full-integration tests > and the controller-tests. Are there any problems with this strategy? There is a well-defined directory structure for a reason. When writing Rails apps you get a lot of niceties for free from rspec-rails based on how the directory structure is laid out. You could come up with whatever directory you want, but you'll have to configure and/or tweak rspec so it gives you the same niceties. I recommend trying to do things the default rspec way, and then as you become familiar with it you should start branching out into trying different ways of doing things, and post back to the mailing list along the way so you can share. Perhaps some of what you find out will prove to be helpful to others, or will even lead to changes for the betterment of writing software using RSpec. I'm off to catch a plane, hopefully this has helped and not added further confusion or frustration, -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From matt at mattwynne.net Mon Oct 20 13:28:11 2008 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 20 Oct 2008 18:28:11 +0100 Subject: [rspec-users] ????? lots of Q's about integration tests with rspec In-Reply-To: <6a4d2b24410aa3d112e83423d2f8b327@ruby-forum.com> References: <6a4d2b24410aa3d112e83423d2f8b327@ruby-forum.com> Message-ID: <9C9DF6B9-0227-4699-B863-23808C1B2133@mattwynne.net> On 20 Oct 2008, at 17:49, Rasmus Rasmussen wrote: > I would rather delete spec/controller and have something like spec/ > full > or maybe spec/requirements. That would give me my full-integration > tests > and the controller-tests. Are there any problems with this strategy? Find the cucumber project on github and you'll get a /features folder where you can write your full-stack tests, like rails 'integration' tests, or what the XP crowd like to call 'acceptance tests'. You can then use the specs in the spec folder to drive out changes to individual classes, what the XP crowd calls unit testing. How isolated you make those specs is up to you, but you'll find most people on this list will advocate using mocking to isolate controllers, I certainly do. cheers, Matt From ashley.moran at patchspace.co.uk Mon Oct 20 15:05:06 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 20 Oct 2008 20:05:06 +0100 Subject: [rspec-users] Merb In-Reply-To: References: <2346471A-B6F5-46C2-A9DC-0E98512C2F99@patchspace.co.uk> Message-ID: <3F505B0C-254E-40B0-9F4A-4CCE75B88C5B@patchspace.co.uk> On Oct 19, 2008, at 10:31 pm, Caius Durling wrote: > Funny you should post this, I picked up merb today as well (seeing > as the API is finally frozen) and was thinking about posting to see > if anyone else was. Well, I've done a bit more research (asking around on the Merb list), and it seems the best practice* in Merbland is to use controller specs in much the same way as Rails integration tests[1]. While I see the point that you should test behaviour not implementation, I think that goes a *little* too far. In short, it's not recommended to do the equivalent of: it "should create a new, unsaved person on GET to create" do Person.should_receive(:new).and_return(@person) get 'create' end There is an API for this though[2], and it was deprecated as of RC1, but has now apparently been reintroduced. Lawrence Pit on the merb list explains the syntax: > # ==== Example > # dispatch_to(MyController, :create, :name => 'Homer' ) do > |controller| > # controller.stub!(:current_user).and_return(@user) > # end And I assume it works similarly with the #get, #post etc. (I have yet to try it though, and I can't visualise a clean way to write specs with it.) Anyway the whole discussion provoked me to crystallise my thoughts on Ruby web BDD, which I decided to blog[3], and I thought it may be of interest to people here, in case there's yet a third "right way" of doing things. (If anyone finds this of interest, let me know. If so, I might start an "Adventures in Merb BDD" series - or something - on my blog.) Ashley * I've padded up in anticipation of the chair I know Aslak will hurl when he reads that ;o) [1] http://www.slideshare.net/wycats/testing-merb-presentation [2] http://merbivore.com/documentation/0.9.9/doc/rdoc/merb-core/index.html?a=C00000147&name=RequestHelper [3] http://aviewfromafar.net/2008/10/20/web-app-bdd-thoughts-as-i-move-to-merb -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ben at benmabey.com Mon Oct 20 16:22:09 2008 From: ben at benmabey.com (Ben Mabey) Date: Mon, 20 Oct 2008 14:22:09 -0600 Subject: [rspec-users] Merb In-Reply-To: <3F505B0C-254E-40B0-9F4A-4CCE75B88C5B@patchspace.co.uk> References: <2346471A-B6F5-46C2-A9DC-0E98512C2F99@patchspace.co.uk> <3F505B0C-254E-40B0-9F4A-4CCE75B88C5B@patchspace.co.uk> Message-ID: <48FCE871.9070806@benmabey.com> Ashley Moran wrote: > > On Oct 19, 2008, at 10:31 pm, Caius Durling wrote: > >> Funny you should post this, I picked up merb today as well (seeing as >> the API is finally frozen) and was thinking about posting to see if >> anyone else was. > > Well, I've done a bit more research (asking around on the Merb list), > and it seems the best practice* in Merbland is to use controller specs > in much the same way as Rails integration tests[1]. While I see the > point that you should test behaviour not implementation, I think that > goes a *little* too far. In short, it's not recommended to do the > equivalent of: > > it "should create a new, unsaved person on GET to create" do > Person.should_receive(:new).and_return(@person) > get 'create' > end > > There is an API for this though[2], and it was deprecated as of RC1, > but has now apparently been reintroduced. > > Lawrence Pit on the merb list explains the syntax: >> # ==== Example >> # dispatch_to(MyController, :create, :name => 'Homer' ) do >> |controller| >> # controller.stub!(:current_user).and_return(@user) >> # end > > > And I assume it works similarly with the #get, #post etc. (I have yet > to try it though, and I can't visualise a clean way to write specs > with it.) > > > Anyway the whole discussion provoked me to crystallise my thoughts on > Ruby web BDD, which I decided to blog[3], and I thought it may be of > interest to people here, in case there's yet a third "right way" of > doing things. > > (If anyone finds this of interest, let me know. If so, I might start > an "Adventures in Merb BDD" series - or something - on my blog.) > > > Ashley > > > * I've padded up in anticipation of the chair I know Aslak will hurl > when he reads that ;o) > > [1] http://www.slideshare.net/wycats/testing-merb-presentation > [2] > http://merbivore.com/documentation/0.9.9/doc/rdoc/merb-core/index.html?a=C00000147&name=RequestHelper > > [3] > http://aviewfromafar.net/2008/10/20/web-app-bdd-thoughts-as-i-move-to-merb > > > Yeah... In regards to the controller specs... I wouldn't call that 'best practice' or 'the' right way. I would call that wycats's way of testing and how most of the merb community has decided to follow suite. I'm not saying a purely mock-based approach is 'best practices' either- they are both good practices and infinitively better than the alternative of having no tests at all! That being said, I'm a big proponent of outside-in development which is largely made possible by being able to spec out your interface with mocks *before* it exists. We had a good discussion on the tradeoffs of using mocks on this list recently. Here is a message from that thread, by Zach Dennis, in which he explains outside-in development very well: http://rubyforge.org/pipermail/rspec-users/2008-September/008426.html It seems like the merb community places more emphasis on application wide tests- which is good since that is all the customer will really care about in the end. Application wide tests are great (and that is why we have cucumber) but I wouldn't forgoe having a fast object level suite. Without a lightning fast suite the refactoring process will be drawn out and tracking down breaks can be harder without the focused object examples. That has been my experience at least and so that is why I like to have application level features which touch the entire stack and then have faster and more focussed object level specs that rely on mocking. Like I said, that is how I like to development my apps and not 'the' right way to do it. Anyways, thanks for sharing your findings. -Ben From ashley.moran at patchspace.co.uk Mon Oct 20 17:43:12 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 20 Oct 2008 22:43:12 +0100 Subject: [rspec-users] Merb In-Reply-To: <48FCE871.9070806@benmabey.com> References: <2346471A-B6F5-46C2-A9DC-0E98512C2F99@patchspace.co.uk> <3F505B0C-254E-40B0-9F4A-4CCE75B88C5B@patchspace.co.uk> <48FCE871.9070806@benmabey.com> Message-ID: <86342B5E-ECB7-40BC-A85A-A50AD383895B@patchspace.co.uk> On Oct 20, 2008, at 9:22 pm, Ben Mabey wrote: > That being said, I'm a big proponent of outside-in development which > is largely made possible by being able to spec out your interface > with mocks *before* it exists. We had a good discussion on the > tradeoffs of using mocks on this list recently. Here is a message > from that thread, by Zach Dennis, in which he explains outside-in > development very well: > http://rubyforge.org/pipermail/rspec-users/2008-September/008426.html Hi Ben That's a great post by Zach, thanks for the link to it. Zach - if you're reading this - please blog it. I've had to delicious the RubyForge page. > It seems like the merb community places more emphasis on application > wide tests- which is good since that is all the customer will really > care about in the end. Application wide tests are great (and that > is why we have cucumber) I agree, which is why I find it odd that the Merb community is using RSpec to do Cucumber's (or the classic Story Runner's) job. > but I wouldn't forgoe having a fast object level suite. Without a > lightning fast suite the refactoring process will be drawn out and > tracking down breaks can be harder without the focused object > examples. That has been my experience at least and so that is why I > like to have application level features which touch the entire stack > and then have faster and more focussed object level specs that rely > on mocking. Exactly how I work, and (I imagine) the way most people here work. Not that that makes it right, of course. But I find it invaluable to have pure interaction-level spec, or one that wraps behaviour where the output is more important than the interactions (eg parsing XML, in my experience). > Anyways, thanks for sharing your findings. My quest for enlightenment continues... Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From dchelimsky at gmail.com Tue Oct 21 01:14:11 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 21 Oct 2008 00:14:11 -0500 Subject: [rspec-users] [ANN] rspec 1.1.9 Released Message-ID: <57c63afe0810202214w3c163bercf78c55f81e78aa2@mail.gmail.com> rspec version 1.1.9 has been released! * Behaviour Driven Development for Ruby. Changes: ### Version 1.1.9 / 2008-10-20 WARNING: This release removes implicit inclusion of modules in example groups. This means that if you have 'describe MyModule do', MyModule will not be included in the group. * 2 major enhancements * Add extend to configuration (thanks to advice from Chad Fowler) * Modules are no longer implicitly included in example groups * 4 minor enhancements * mingw indicates windows too (thanks to Luis Lavena for the tip) * improved output for partial mock expecation failures * it_should_behave_like now accepts n names of shared groups * eliminated redundant inclusion/extension of ExampleGroupMethods * 6 bug fixes * spec command with no arguments prints help * fixed typo in help. Fixes #73. * fixed bug where should_receive..and_yield after similar stub added the args_to_yield to the stub's original args_to_yield (Pat Maddox) * fixed bug where rspec-autotest (autospec) was loading non-spec files in spec directory. Fixes #559. * fixed bug where should_not_receive was reporting twice * fixed bug where rspec tries to run examples just because it is required (even if there are no examples loaded). Fixes #575. * From dchelimsky at gmail.com Tue Oct 21 01:14:44 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 21 Oct 2008 00:14:44 -0500 Subject: [rspec-users] [ANN] rspec-rails 1.1.9 Released Message-ID: <57c63afe0810202214w72c43cfetbb016150d0c2987c@mail.gmail.com> rspec-rails version 1.1.9 has been released! * Behaviour Driven Development for Ruby on Rails. Changes: ### Version 1.1.9 / 2008-10-20 * 4 bug fixes * require 'rubygems' in script/spec * fix failure message for error_on and errors_on (Patch from Mike Vincent). Fixes #566. * fix issues that arise in view spec if passing actual template name to render (Patch from Mike Vincent). Fixes #551. * fixed bug accessing assigns from helper examples * From jarkko at jlaine.net Tue Oct 21 02:24:55 2008 From: jarkko at jlaine.net (Jarkko Laine) Date: Tue, 21 Oct 2008 09:24:55 +0300 Subject: [rspec-users] Merb In-Reply-To: <3F505B0C-254E-40B0-9F4A-4CCE75B88C5B@patchspace.co.uk> References: <2346471A-B6F5-46C2-A9DC-0E98512C2F99@patchspace.co.uk> <3F505B0C-254E-40B0-9F4A-4CCE75B88C5B@patchspace.co.uk> Message-ID: <59329F82-490B-4EDA-85AA-4F633AB4C00A@jlaine.net> On 20.10.2008, at 22.05, Ashley Moran wrote: > There is an API for this though[2], and it was deprecated as of RC1, > but has now apparently been reintroduced. > > Lawrence Pit on the merb list explains the syntax: >> # ==== Example >> # dispatch_to(MyController, :create, :name => 'Homer' ) do >> |controller| >> # controller.stub!(:current_user).and_return(@user) >> # end Yeah, I was using that API to a great extent with a recent project and was pretty successful at doing outside-in development with rspec and merb. The syntax used in merb controller specs is a bit different from what Rails uses, but once you got around it, it was actually pretty cool and flexible. Here's a snippet from a controller spec in the project: http://pastie.org/private/6uijgfwwzjngvhbkgxwqq Note that I generally stub both render and display for the controller to make the tests run faster. There's probably a lot of optimization left to do with the specs but I find the dispatch helpers pretty cool for building more specialized methods such as do_post. I hope the merb folks will keep us outside-(s)inners in mind and not scrap the API. Cheers, //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://odesign.fi Check out my latest book, Unobtrusive Prototype, fresh off the Peepcode oven: http://peepcode.com/products/unobtrusive-prototype-js From robl at mail.pigdestroyer.co.uk Tue Oct 21 05:45:40 2008 From: robl at mail.pigdestroyer.co.uk (Rob Lacey) Date: Tue, 21 Oct 2008 10:45:40 +0100 Subject: [rspec-users] Dreading Controller Specs Message-ID: <48FDA4C4.7040505@mail.pigdestroyer.co.uk> Hi there, I was look for a little advice really. I've been using RSpec for about 4 months now and I find it an absolute joy for model work and a really nice tool it makes everything so much more readable and nicer to organise However, I seem to dread spec-ing out controllers, they end up being quite untidy, I think maybe I am approaching them in the wrong way as it probably shouldn't be as hard as I am making it. For example I had a problem over the past few days where I am creating a way of logging in a customer to our site through a token. There is a UserController, the customer does a get to the action token_login, we authenticate the token, check a few other things and then set a session variable to keep them logged in. -----8<---------------- it "should find a single sign on" do mock_user(:generate_security_token => 'newtoken') ms = mock_model(MusicService, :users => [mock_user]) sso = mock_model(SingleSignOn, :music_service => ms) SingleSignOn.should_receive(:find_by_secret_and_remote_host).with(@secret, @remote_host).and_return(sso) ms.users.stub!(:find_by_email).and_return(mock_user) post :request_token, :secret => @secret, :email_address => @email assigns(:single_sign_on).should equal(sso) end -----8<----------------------- To be honest I feel very uncomfortable about the way this is arranged as I am mocking several objects and their associations. I am trying to stick to the "don't touch the database" way of testing for controllers and I feel that I am almost writing the implementation in the test just by the way I am mocking / stubbing and therefore it makes the test pointless as its just a confirmation of how I've written it. Can anyone give me any ideas of how to do this *properly*? How far do you go do you go with your mocking? I almost am tempted to simplify the controller by using only the User model and moving most of the checks out of the controller action entirely and putting all into User, although that would mean that the user model, single_sign_on and music_service would then be really tightly coupled which wouldn't be great either. I then don't feel comfortable because this approach would be as a reaction to making the test simpler rather than making the controller code work which is the whole point of the test. Any help would be greatly appreciated. Cheers. RobL From baz at madeofstone.net Tue Oct 21 04:48:31 2008 From: baz at madeofstone.net (Rahoul Baruah) Date: Tue, 21 Oct 2008 09:48:31 +0100 Subject: [rspec-users] Mocks: expectations vs spying In-Reply-To: References: <60782FC3-38CF-4469-BEA7-BBAA9E8DC862@patchspace.co.uk> <48F7ABDD.4050900@benmabey.com> Message-ID: <789A222C-353E-485D-AE7D-0E9FA33D1FEA@madeofstone.net> On 18 Oct 2008, at 14:53, Pat Maddox wrote: > I quit once I found not_a_mock [1] which works nicely. My preference Yay! Thanks for the pointer Pat. Baz. Rahoul Baruah Web design and development: http://www.3hv.co.uk/ Nottingham Forest: http://www.eighteensixtyfive.co.uk/ Serious Rails Hosting: http://www.brightbox.co.uk/ Lifecast: http://www.madeofstone.net/ From baz at madeofstone.net Tue Oct 21 08:08:23 2008 From: baz at madeofstone.net (Rahoul Baruah) Date: Tue, 21 Oct 2008 13:08:23 +0100 Subject: [rspec-users] Dreading Controller Specs In-Reply-To: <48FDA4C4.7040505@mail.pigdestroyer.co.uk> References: <48FDA4C4.7040505@mail.pigdestroyer.co.uk> Message-ID: <598008DC-7D2D-4D86-9DEE-A00BC2DF28B8@madeofstone.net> On 21 Oct 2008, at 10:45, Rob Lacey wrote: > I almost am tempted to simplify the controller by using only the > User model and moving most of the checks out of the controller > action entirely and putting all into User, although that would mean > that the user model, single_sign_on and music_service would then be > really tightly coupled which wouldn't be great either. I The "Rails Way" (assuming you are using Rails) is to make your controllers do virtually nothing - find/create an object, call a method on it, decide which view to render and that's it. So, actually what you suggest would be best. However, rather than talking to your models directly, the controller could talk to a "presenter" object, which does the "glue work" (finding the associated models, calling the relevant methods in the correct order and packaging up the results) - you can then RSpec your presenter in the same way as you would a model. This makes your controller specs (and implementations) trivial: it "should find a single sign-on" do @presenter = mock 'SingleSignOnPresenter' @presenter.should_receive(:request_token).with(secret, email_address).and_return(:whatever) post :request_token, :secret => 'secret', :email_address => 'billg at hotmail.com ' response.should redirect_to(some_path) end I actually use helpers (given_a_single_sign_on_presenter and expect_to_request_a_token) instead of setting up the mocks and expectations within the spec, just to make it a bit more readable. Then you can RSpec your SingleSignOnPresenter separately, in much the same way as you would spec a model, and keep the associations (and implementation details) away from your controller. Baz. Rahoul Baruah Web design and development: http://www.3hv.co.uk/ Nottingham Forest: http://www.eighteensixtyfive.co.uk/ Serious Rails Hosting: http://www.brightbox.co.uk/ Lifecast: http://www.madeofstone.net/ From dchelimsky at gmail.com Tue Oct 21 09:47:55 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 21 Oct 2008 08:47:55 -0500 Subject: [rspec-users] Mocks: expectations vs spying In-Reply-To: <021F449B-E61F-408F-8EAE-0544922719DC@mattwynne.net> References: <60782FC3-38CF-4469-BEA7-BBAA9E8DC862@patchspace.co.uk> <48F7ABDD.4050900@benmabey.com> <51122F6B-D2B8-41E7-9134-FF3AF5FC0F3F@mattwynne.net> <4DE1E7EB-DC01-4E76-9E95-10703C7A34FD@patchspace.co.uk> <021F449B-E61F-408F-8EAE-0544922719DC@mattwynne.net> Message-ID: <57c63afe0810210647j41fafbedwe979711bcbce8e52@mail.gmail.com> On Mon, Oct 20, 2008 at 2:03 AM, Matt Wynne wrote: > > On 19 Oct 2008, at 21:18, Ashley Moran wrote: > >> >> On Oct 19, 2008, at 9:32 am, Matt Wynne wrote: >> >>>> [1] http://notahat.com/not_a_mock >>> >>> Looks sweet - it will be in my first mock on Monday! > > Thinking about it - how do you use multiple mocking frameworks in a given > project? > > Is it safe to re-open a Spec::Runner.configure do |config| block at the top > of an individual spec after I've loaded spec_helper (which will have to be > configured to use the default rspec mocking that 90% of the project uses)? Not really. The problem is that examples are stored for evaluation later, whereas the configuration is evaluated right away. The reason rspec won't support using multiple mock frameworks is rspec mocks and mocha both extend Object (to support mock behaviour on real objects) and they use the same methods to create instances of mocks. I think that if we wanted to support multiple mock frameworks, all of the frameworks would have to offer an explicit mode where you could extend objects to behave like mocks but would have to do so explicitly for each object. Flexmock already works this way. FWIW, David > > cheers, > Matt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From josephwilk at joesniff.co.uk Tue Oct 21 10:47:23 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Tue, 21 Oct 2008 15:47:23 +0100 Subject: [rspec-users] Cucumber, more examples, tabular data input sets In-Reply-To: <8C7CD501-50F7-4C2E-A1BA-73DA0EFD44E2@mattwynne.net> References: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> <1fb4df0810181325xb3c9071m1829f8b685d87bc1@mail.gmail.com> <85d99afe0810181351v5aeb6707j6a9953fe11d0929c@mail.gmail.com> <8C7CD501-50F7-4C2E-A1BA-73DA0EFD44E2@mattwynne.net> Message-ID: <48FDEB7B.5000104@joesniff.co.uk> Matt Wynne wrote: > ScenarioTemplate: Non admins are rejected > Given I login as Joe without the '[privilege]' privilege > When I [request_method] /admin[path] > Then I am notified that access was denied > > | privilege | request_method | path | > | Joe | GET | /admin | > | Joe | POST | /invoces/1 | > > etc. > > WDYT? > > cheers, > Matt This sounds like a good direction Matt. I think its important to make it clear that it is not a normal scenario to avoid step matching confusion/why is this not being run. Would you mind creating a ticket for it in lighthouse please? Thanks, -- Joseph Wilk http://www.joesniff.co.uk From matt at mattwynne.net Tue Oct 21 11:41:29 2008 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 21 Oct 2008 16:41:29 +0100 Subject: [rspec-users] Mocks: expectations vs spying In-Reply-To: <57c63afe0810210647j41fafbedwe979711bcbce8e52@mail.gmail.com> References: <60782FC3-38CF-4469-BEA7-BBAA9E8DC862@patchspace.co.uk> <48F7ABDD.4050900@benmabey.com> <51122F6B-D2B8-41E7-9134-FF3AF5FC0F3F@mattwynne.net> <4DE1E7EB-DC01-4E76-9E95-10703C7A34FD@patchspace.co.uk> <021F449B-E61F-408F-8EAE-0544922719DC@mattwynne.net> <57c63afe0810210647j41fafbedwe979711bcbce8e52@mail.gmail.com> Message-ID: So if I want to have a spec suite which uses a combination of mocking frameworks, is this possible? Maybe if some of the files include ../not_a_mock_spec_helper and the others include ../default_spec_helper and then both those files require some common spec_helper file? On 21 Oct 2008, at 14:47, David Chelimsky wrote: > On Mon, Oct 20, 2008 at 2:03 AM, Matt Wynne > wrote: >> >> On 19 Oct 2008, at 21:18, Ashley Moran wrote: >> >>> >>> On Oct 19, 2008, at 9:32 am, Matt Wynne wrote: >>> >>>>> [1] http://notahat.com/not_a_mock >>>> >>>> Looks sweet - it will be in my first mock on Monday! >> >> Thinking about it - how do you use multiple mocking frameworks in a >> given >> project? >> >> Is it safe to re-open a Spec::Runner.configure do |config| block at >> the top >> of an individual spec after I've loaded spec_helper (which will >> have to be >> configured to use the default rspec mocking that 90% of the project >> uses)? > > Not really. The problem is that examples are stored for evaluation > later, whereas the configuration is evaluated right away. > > The reason rspec won't support using multiple mock frameworks is rspec > mocks and mocha both extend Object (to support mock behaviour on real > objects) and they use the same methods to create instances of mocks. > > I think that if we wanted to support multiple mock frameworks, all of > the frameworks would have to offer an explicit mode where you could > extend objects to behave like mocks but would have to do so explicitly > for each object. Flexmock already works this way. > > FWIW, > David > >> >> cheers, >> Matt >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From matt at mattwynne.net Tue Oct 21 11:51:10 2008 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 21 Oct 2008 16:51:10 +0100 Subject: [rspec-users] Dreading Controller Specs In-Reply-To: <598008DC-7D2D-4D86-9DEE-A00BC2DF28B8@madeofstone.net> References: <48FDA4C4.7040505@mail.pigdestroyer.co.uk> <598008DC-7D2D-4D86-9DEE-A00BC2DF28B8@madeofstone.net> Message-ID: <4C854A62-BC82-4161-8809-C1F4F1E12B3C@mattwynne.net> On 21 Oct 2008, at 13:08, Rahoul Baruah wrote: > > On 21 Oct 2008, at 10:45, Rob Lacey wrote: > >> I almost am tempted to simplify the controller by using only the >> User model and moving most of the checks out of the controller >> action entirely and putting all into User, although that would mean >> that the user model, single_sign_on and music_service would then be >> really tightly coupled which wouldn't be great either. I > > Then you can RSpec your SingleSignOnPresenter separately, in much > the same way as you would spec a model, and keep the associations > (and implementation details) away from your controller. Doesn't this just end up shifting the ugly mocking code into the Presenter specs though? The stock answer to this question is to move this logic down into the model layer, so that the interface the Presenter / Controller uses to work with the database is simpler. This is what people call 'listening to your tests' - if it's hard to mock, it's probably indicative of a problem in your design. However, I worry about this 'skinny controller, fat model' advice, it still doesn't feel like the final answer. To me, ActiveRecord classes already have too many responsibilities, without making them also orchestrate calls to other models. I have been thinking about this a lot lately, and I am starting to feel like I also need a Service layer between the Controller / Presenters and the 'Data Access Layer' (Models) to orchestrate the work. cheers, Matt From dchelimsky at gmail.com Tue Oct 21 12:01:35 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 21 Oct 2008 11:01:35 -0500 Subject: [rspec-users] Mocks: expectations vs spying In-Reply-To: References: <60782FC3-38CF-4469-BEA7-BBAA9E8DC862@patchspace.co.uk> <48F7ABDD.4050900@benmabey.com> <51122F6B-D2B8-41E7-9134-FF3AF5FC0F3F@mattwynne.net> <4DE1E7EB-DC01-4E76-9E95-10703C7A34FD@patchspace.co.uk> <021F449B-E61F-408F-8EAE-0544922719DC@mattwynne.net> <57c63afe0810210647j41fafbedwe979711bcbce8e52@mail.gmail.com> Message-ID: <57c63afe0810210901l556f583o1e969c6dd72563a8@mail.gmail.com> On Tue, Oct 21, 2008 at 10:41 AM, Matt Wynne wrote: > So if I want to have a spec suite which uses a combination of mocking > frameworks, is this possible? > > Maybe if some of the files include ../not_a_mock_spec_helper and the others > include ../default_spec_helper and then both those files require some common > spec_helper file? That could work - but the conflict I described is a process-wide conflict - so you'd need to run the examples in those dirs w/ separate rake tasks to really eliminate the conflict. > > On 21 Oct 2008, at 14:47, David Chelimsky wrote: > >> On Mon, Oct 20, 2008 at 2:03 AM, Matt Wynne wrote: >>> >>> On 19 Oct 2008, at 21:18, Ashley Moran wrote: >>> >>>> >>>> On Oct 19, 2008, at 9:32 am, Matt Wynne wrote: >>>> >>>>>> [1] http://notahat.com/not_a_mock >>>>> >>>>> Looks sweet - it will be in my first mock on Monday! >>> >>> Thinking about it - how do you use multiple mocking frameworks in a given >>> project? >>> >>> Is it safe to re-open a Spec::Runner.configure do |config| block at the >>> top >>> of an individual spec after I've loaded spec_helper (which will have to >>> be >>> configured to use the default rspec mocking that 90% of the project >>> uses)? >> >> Not really. The problem is that examples are stored for evaluation >> later, whereas the configuration is evaluated right away. >> >> The reason rspec won't support using multiple mock frameworks is rspec >> mocks and mocha both extend Object (to support mock behaviour on real >> objects) and they use the same methods to create instances of mocks. >> >> I think that if we wanted to support multiple mock frameworks, all of >> the frameworks would have to offer an explicit mode where you could >> extend objects to behave like mocks but would have to do so explicitly >> for each object. Flexmock already works this way. >> >> FWIW, >> David >> >>> >>> cheers, >>> Matt >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sfeley at gmail.com Tue Oct 21 13:35:18 2008 From: sfeley at gmail.com (Stephen Eley) Date: Tue, 21 Oct 2008 13:35:18 -0400 Subject: [rspec-users] Dreading Controller Specs In-Reply-To: <48FDA4C4.7040505@mail.pigdestroyer.co.uk> References: <48FDA4C4.7040505@mail.pigdestroyer.co.uk> Message-ID: <1fb4df0810211035t743c05d2oeac1149be1941f2e@mail.gmail.com> On Tue, Oct 21, 2008 at 5:45 AM, Rob Lacey wrote: > > However, I seem to dread spec-ing out controllers, they end up being quite > untidy, I think maybe I am approaching them in the wrong way as it probably > shouldn't be as hard as I am making it. For what it's worth, Rob, I'm totally with you. The generated code for controller specs has always felt...well, wrong to me. And it's been a frustration every time I've sat down to try to write new controller specs the same way, taking many times longer than it takes to write the controller. The bad part has been the work required to set up the stubs and mocks -- for just the reason you cite. Conforming to the "single expectation per test" pattern means I have to figure out and stub every method that gets called and make it return a reasonable value, and then I have to *mock* each call at least once to confirm that it gets called. By this point I've essentially written the model interface twice, which feels like extraordinary extra work -- and it also feels brittle. Reasonable changes in the model require unreasonable maintenance in the controller stubs and mocks. The only reason for all of this work is the principle of code isolation. You're supposed to make sure you're only running the code in the unit you're testing -- but because controllers sit at the heart of your app, *of course* they're going to have a great deal of interaction with everything else. That isn't wrong and it doesn't necessarily make the controllers too fat. But it makes the testing fat. Just stubbing the relationship between model collections and objects is complex. It also looks screwy -- and it isn't really a test of the controller. But it has to be done if you're not going to talk to the model. There are some cheats, of course. You can make blanket responses to stuff you don't feel like mocking. The null_object option to RSpec mocks is such a cheat; so's stub_everything in Mocha. But to me they feel like copouts, and they return null by default, which is most often the wrong behavior, so they don't save work. Mock_model and stub_model are intended for views, and stub_model doesn't isolate you from the model. There are some extension plugins that do some of the mocking/stubbing "grunt work" for you, but that reduces transparency and they don't know about anything but the most common 'formula' methods. The conclusion I'm starting to reach is that it often isn't worth it. All these hours of work to avoid talking with actual models... But if you just plain used the models, so what? Yes, your controller specs could fail if your model is buggy or unimplemented. But if your model's properly spec'ed you'll get failures on the bug there too, pinning the problem down, and the implementation constraint simply means you can't write models *last*. You'd implement methods on them before or simultaneous with the controllers that call them. That's not a bad order of things. So now I'm experimenting with live models. I'm using simple, basic factory methods (I use fixture_replacement2) to create objects for my controller specs to operate on, saved or unsaved as necessary, and using Mocha to inject expectations into the actual objects for specific examples. I may look at not_a_mock for that, too, now that it's being talked about here. This may not be as philosophically pristine as total isolation, but it's simpler and cleaner. You don't have to replicate fake model complexity it in the controller spec. Most of the lines in the controller spec are once again about the _controller,_ not about setting up models. It's also slower, but only a bit. Even with autospec, waiting on my tests to begin is already slow enough that I don't feel it makes a huge difference. I'm documenting my approach, too, and what I've been thinking and learning about RSpec from a "thoughtful beginner" perspective, and hope to have something I can post on that soon. (That documentation is, in fact, one of the motivations for my current project.) That's my take. It's working for me so far, but with the caveat that I haven't carried a project through to completion with this approach. If any of the _cognoscenti_ can offer reasons why this is a horribly bad idea that'll blow up in my face sooner or later, I'm open to being convinced. I also offer my apologies if this is a topic that comes up on this list over and over again, and if my little rant here is a common and tired one. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From dchelimsky at gmail.com Tue Oct 21 14:51:42 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 21 Oct 2008 13:51:42 -0500 Subject: [rspec-users] config.gem/rspec-rails/rspec bug (#577) Message-ID: <57c63afe0810211151v72f432cbo63e1d59abd8c2442@mail.gmail.com> Hey all, Just a heads up about a bug related to configuring the rspec gems in your rails 2.1.1 projects: http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/577 Apparently, if you config.gem both rspec and rspec-rails 1.1.9 w/ rspec first, you'll get an error: # DON'T DO THIS: config.gem 'rspec', :lib => 'spec', :version => '1.1.9' config.gem 'rspec-rails', :lib => 'spec/rails', :version => '1.1.9' The workaround is to either reverse these lines: # OK config.gem 'rspec-rails', :lib => 'spec/rails', :version => '1.1.9' config.gem 'rspec', :lib => 'spec', :version => '1.1.9' or just require rspec-rails if you're using rubygems >= 1.2 (since installing rspec-rails will, by default, install rspec) # OK config.gem 'rspec-rails', :lib => 'spec/rails', :version => '1.1.9' Keep your eye on the ticket (http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/577) to see when this is resolved. Cheers, David From baz at madeofstone.net Tue Oct 21 15:57:46 2008 From: baz at madeofstone.net (Rahoul Baruah) Date: Tue, 21 Oct 2008 20:57:46 +0100 Subject: [rspec-users] Dreading Controller Specs In-Reply-To: <4C854A62-BC82-4161-8809-C1F4F1E12B3C@mattwynne.net> References: <48FDA4C4.7040505@mail.pigdestroyer.co.uk> <598008DC-7D2D-4D86-9DEE-A00BC2DF28B8@madeofstone.net> <4C854A62-BC82-4161-8809-C1F4F1E12B3C@mattwynne.net> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 21 Oct 2008, at 16:51, Matt Wynne wrote: > Doesn't this just end up shifting the ugly mocking code into the > Presenter specs though? > > The stock answer to this question is to move this logic down into > the model layer, so that the interface the Presenter / Controller > uses to work with the database is simpler. This is what people call > 'listening to your tests' - if it's hard to mock, it's probably > indicative of a problem in your design. > > However, I worry about this 'skinny controller, fat model' advice, > it still doesn't feel like the final answer. To me, ActiveRecord > classes already have too many responsibilities, without making them > also orchestrate calls to other models. > > I have been thinking about this a lot lately, and I am starting to > feel like I also need a Service layer between the Controller / > Presenters and the 'Data Access Layer' (Models) to orchestrate the > work. Personally I dislike the name "Presenter" - and much prefer Service, Builder or Adapter depending upon what its doing; everyone else seems to call it a presenter however. But the point of the "Presenter/Service/Whatever" is precisely so that neither the controller nor the models have to orchestrate the calls between associated models. If you think of it that way then I think it deals with your points above: * the presenter/service's role is to coordinate the models - so its specs are purely about mocking the associations and the calls inbetween them * the presenter/service isn't a model (not ActiveRecord::Base) - so it's not adding extra responsibilities to the models * it is pretty much a service layer sat between controllers and models Rahoul Baruah Web design and development: http://www.3hv.co.uk/ Nottingham Forest: http://www.eighteensixtyfive.co.uk/ Serious Rails Hosting: http://www.brightbox.co.uk/ Lifecast: http://www.madeofstone.net/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) iEYEARECAAYFAkj+NDoACgkQu0BNRvjN8xRIsQCfQMkAVClEQOqPmdF9dPDm8Afq o1sAnRF5gYkDI1qgfM8G2S+PpdLOUHaz =fIkf -----END PGP SIGNATURE----- From sfeley at gmail.com Tue Oct 21 17:13:09 2008 From: sfeley at gmail.com (Stephen Eley) Date: Tue, 21 Oct 2008 17:13:09 -0400 Subject: [rspec-users] Dreading Controller Specs In-Reply-To: References: <48FDA4C4.7040505@mail.pigdestroyer.co.uk> <598008DC-7D2D-4D86-9DEE-A00BC2DF28B8@madeofstone.net> <4C854A62-BC82-4161-8809-C1F4F1E12B3C@mattwynne.net> Message-ID: <1fb4df0810211413ye98101dl90d562c44ad4a25e@mail.gmail.com> On Tue, Oct 21, 2008 at 3:57 PM, Rahoul Baruah wrote: > > * the presenter/service's role is to coordinate the models - so its specs > are purely about mocking the associations and the calls inbetween them > * the presenter/service isn't a model (not ActiveRecord::Base) - so it's not > adding extra responsibilities to the models > * it is pretty much a service layer sat between controllers and models There seems to be some overload on the word "Presenter" in Railsspeak. As best I can tell, people are using it to refer to two or more totally different patterns. Initially I thought presenters were for encapsulating limited-domain *controller and view logic* in such a way that they could be embedded in other controllers, thus allowing composition in views. Things like sidebar widgets, or components of a dashboard, or a reusable address box, etc. Stuff that benefits from maintaining its own data so you can't just a partial, but it's still more about the view than the model. On Googling this post, however, I've found that some people do use it that way, but other people talk about the Presenter pattern as a class to aggregate data before sending it to (or split data after receiving it from) the controller. I.e., what you're saying. I think Jay Fields confused the issue by talking about presenters in this way, but saying you're doing it for the sake of the *view.* All of this has convinced me that the name "Presenter" sucks and nobody should use it. My thinking this is unlikely to change anything, but at least people ought to agree on what they are. What you're talking about, Rahoul, at least one or two people are calling a "Conductor": http://blog.new-bamboo.co.uk/2007/8/31/presenters-conductors-on-rails Personally I prefer handling it in the model, and letting models act as compositions of other models if need be, but that's just me. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From lists at ruby-forum.com Tue Oct 21 22:39:09 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Wed, 22 Oct 2008 04:39:09 +0200 Subject: [rspec-users] Where is current_user? In-Reply-To: <57c63afe0810201003n4bb6d745l88f1209dd005999b@mail.gmail.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> <57c63afe0810200536r2eb597e5ge70cc799c4497c57@mail.gmail.com> <1daa44bdd5419fced37fc915f62bd002@ruby-forum.com> <57c63afe0810200608y3bab2582l5df08c954b67810@mail.gmail.com> <284cf96e5c080d4da7251d134028ba5d@ruby-forum.com> <57c63afe0810200652qa1089c5g7f9f6e8357750c42@mail.gmail.com> <73808a61e92fa7edc11b9ba99d88d36c@ruby-forum.com> <85d99afe0810200744x4755e564t85d014accbe1d871@mail.gmail.com> <57c63afe0810200953v1eb7d44do5aa32eee4503102b@mail.gmail.com> <0aea9c8303de390c98ae84bd679d62d9@ruby-forum.com> <57c63afe0810201003n4bb6d745l88f1209dd005999b@mail.gmail.com> Message-ID: <2e222877f6bac505fca6ea4ba8a220cd@ruby-forum.com> Thanks David, Your method works well and rspec succeeds now. Is the preferred way of using code with rspec to not rely on instance variables set in a parent during execution but to rely on the method only construct to be able to interact? I see the way this works for the outline you provided. I am wondering what the implications are with respect to writing ruby code with the assumption parent instance variables will be inherited by children. The approach you are providing would indicate that an attr_read method is preferred so that the retrieve method can be stubbed since the instance variable doesn't get set when tested. Is this a general rule of practice with rspec? As a beginner I'm trying to get the larger picture here and appreciate your insight with this. HR -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Wed Oct 22 03:11:51 2008 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 22 Oct 2008 08:11:51 +0100 Subject: [rspec-users] Cucumber, more examples, tabular data input sets In-Reply-To: <48FDEB7B.5000104@joesniff.co.uk> References: <85d99afe0810181113v32162b31m5ca6808768b4a567@mail.gmail.com> <1fb4df0810181325xb3c9071m1829f8b685d87bc1@mail.gmail.com> <85d99afe0810181351v5aeb6707j6a9953fe11d0929c@mail.gmail.com> <8C7CD501-50F7-4C2E-A1BA-73DA0EFD44E2@mattwynne.net> <48FDEB7B.5000104@joesniff.co.uk> Message-ID: <307080EC-DEEE-4DA4-82A9-6E04F32A1A4A@mattwynne.net> On 21 Oct 2008, at 15:47, Joseph Wilk wrote: > Would you mind creating a ticket for it in lighthouse please? Sure, that's the easy part ;) http://rspec.lighthouseapp.com/projects/16211-cucumber/tickets/57-scenario-templates-to-allow-for-terse-scenario-tables From thibaut.barrere at gmail.com Wed Oct 22 03:40:20 2008 From: thibaut.barrere at gmail.com (=?ISO-8859-1?Q?Thibaut_Barr=E8re?=) Date: Wed, 22 Oct 2008 00:40:20 -0700 (PDT) Subject: [rspec-users] 'uninitialized constant Dispatcher' when calling rake features Message-ID: Hi, I'm facing an issue with cucumber: when calling 'rake features' I get an uninitialized constant Dispatcher (full stacktrace here: http://pastie.org/297842). I'm using Rails 2.0.5, the latest webrat/cucumber/rspec/rspec-rails. Did anyone meet this issue ? cheers, Thibaut -- http://evolvingworker.com http://blog.logeek.fr From matt at mattwynne.net Wed Oct 22 03:45:52 2008 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 22 Oct 2008 08:45:52 +0100 Subject: [rspec-users] Dreading Controller Specs In-Reply-To: <1fb4df0810211413ye98101dl90d562c44ad4a25e@mail.gmail.com> References: <48FDA4C4.7040505@mail.pigdestroyer.co.uk> <598008DC-7D2D-4D86-9DEE-A00BC2DF28B8@madeofstone.net> <4C854A62-BC82-4161-8809-C1F4F1E12B3C@mattwynne.net> <1fb4df0810211413ye98101dl90d562c44ad4a25e@mail.gmail.com> Message-ID: <34C486C4-EC2B-4707-A221-DAC90931A854@mattwynne.net> On 21 Oct 2008, at 22:13, Stephen Eley wrote: > On Tue, Oct 21, 2008 at 3:57 PM, Rahoul Baruah > wrote: >> >> * the presenter/service's role is to coordinate the models - so its >> specs >> are purely about mocking the associations and the calls inbetween >> them >> * the presenter/service isn't a model (not ActiveRecord::Base) - so >> it's not >> adding extra responsibilities to the models >> * it is pretty much a service layer sat between controllers and >> models > > There seems to be some overload on the word "Presenter" in Railsspeak. > As best I can tell, people are using it to refer to two or more > totally different patterns. Initially I thought presenters were for > encapsulating limited-domain *controller and view logic* in such a way > that they could be embedded in other controllers, thus allowing > composition in views. Things like sidebar widgets, or components of a > dashboard, or a reusable address box, etc. Stuff that benefits from > maintaining its own data so you can't just a partial, but it's still > more about the view than the model. Right on - that was going to be my response too. Martin Fowler actually retired the 'Model View Presenter' pattern precisely because of this confusion.[1] If we say that a Controller should be responsible for handling HTTP requests, and co-ordinating the appropriate (persistence / presentation / etc) work, that seems like enough responsibility. If we assume that the work to be done against the database or other sub-systems is non-trivial, then we should not directly call the persistence layer (= Models in Railsspeak) from the Controller, but delegate that to another class. It seems like Service is a much more appropriate name than Presenter here, since this work nothing to do with presentation. I buy the thing about conductors, and I like the new-bamboo guys, but I do wonder whether there's some wheel reinvention going on there. If we also assume that the data to be presented is non-trivial, composed of data from multiple database tables, then we need some object to model the data in this presentation domain. I think this is where Presenter comes in, although I'm still not sure this is really an appropriate name. This class can be facade over the various persistence-layer objects needed for the specific presentation task. On another project, in another language, in a galaxy far, far, away, we sprouted a whole layer of POCO presenation 'models' like this, and it felt like such a relief once we'd broken out this extra layer. Does this make sense to anyone else? cheers, Matt [1]http://martinfowler.com/eaaDev/ModelViewPresenter.html From matt at mattwynne.net Wed Oct 22 03:48:05 2008 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 22 Oct 2008 08:48:05 +0100 Subject: [rspec-users] config.gem/rspec-rails/rspec bug (#577) In-Reply-To: <57c63afe0810211151v72f432cbo63e1d59abd8c2442@mail.gmail.com> References: <57c63afe0810211151v72f432cbo63e1d59abd8c2442@mail.gmail.com> Message-ID: On 21 Oct 2008, at 19:51, David Chelimsky wrote: > Hey all, > > Just a heads up about a bug related to configuring the rspec gems in > your rails 2.1.1 projects: I had a little crack at this, but I got scared off as there seems to be some chicken-and-egg stuff going on. My rake tasks require rspec, but if rspec gem isn't installed yet, the rake environment won't load and I can't run rake gems:install. Am I doing something dumb? From luislavena at gmail.com Wed Oct 22 05:58:17 2008 From: luislavena at gmail.com (Luis Lavena) Date: Wed, 22 Oct 2008 06:58:17 -0300 Subject: [rspec-users] config.gem/rspec-rails/rspec bug (#577) In-Reply-To: References: <57c63afe0810211151v72f432cbo63e1d59abd8c2442@mail.gmail.com> Message-ID: <71166b3b0810220258t624b958aha59bf39e8b44f31c@mail.gmail.com> On Wed, Oct 22, 2008 at 4:48 AM, Matt Wynne wrote: > On 21 Oct 2008, at 19:51, David Chelimsky wrote: > >> Hey all, >> >> Just a heads up about a bug related to configuring the rspec gems in >> your rails 2.1.1 projects: > > I had a little crack at this, but I got scared off as there seems to be some > chicken-and-egg stuff going on. My rake tasks require rspec, but if rspec > gem isn't installed yet, the rake environment won't load and I can't run > rake gems:install. > > Am I doing something dumb? Did you updated the generate rake tasks? Since you're using the gem based one, require 'rubygems' before require 'spec' should work. I was bitten several time by RubyGems dependencies that I just try to avoid them, the more explicit you are, the better :-D -- 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 mattwynne.net Wed Oct 22 06:24:52 2008 From: matt at mattwynne.net (Matt Wynne) Date: Wed, 22 Oct 2008 11:24:52 +0100 Subject: [rspec-users] config.gem/rspec-rails/rspec bug (#577) In-Reply-To: <71166b3b0810220258t624b958aha59bf39e8b44f31c@mail.gmail.com> References: <57c63afe0810211151v72f432cbo63e1d59abd8c2442@mail.gmail.com> <71166b3b0810220258t624b958aha59bf39e8b44f31c@mail.gmail.com> Message-ID: <39E5521F-7F63-45CF-BECF-8BBA4FCCF132@mattwynne.net> On 22 Oct 2008, at 10:58, Luis Lavena wrote: > On Wed, Oct 22, 2008 at 4:48 AM, Matt Wynne > wrote: >> On 21 Oct 2008, at 19:51, David Chelimsky wrote: >> >>> Hey all, >>> >>> Just a heads up about a bug related to configuring the rspec gems in >>> your rails 2.1.1 projects: >> >> I had a little crack at this, but I got scared off as there seems >> to be some >> chicken-and-egg stuff going on. My rake tasks require rspec, but if >> rspec >> gem isn't installed yet, the rake environment won't load and I >> can't run >> rake gems:install. >> >> Am I doing something dumb? > > Did you updated the generate rake tasks? As in script/generate rspec? I think so. Is there some update to the file dropped into lib/tasks/rspec.rake that fixes this? > Since you're using the gem based one, require 'rubygems' before > require 'spec' should work. But if I'm on a machine that doesn't have the gems installed (e.g. the production server)...? What then? We have the gem frozen into vendor gems, but that doesn't seem to be enough... From dchelimsky at gmail.com Wed Oct 22 08:05:34 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 22 Oct 2008 07:05:34 -0500 Subject: [rspec-users] Where is current_user? In-Reply-To: <2e222877f6bac505fca6ea4ba8a220cd@ruby-forum.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <284cf96e5c080d4da7251d134028ba5d@ruby-forum.com> <57c63afe0810200652qa1089c5g7f9f6e8357750c42@mail.gmail.com> <73808a61e92fa7edc11b9ba99d88d36c@ruby-forum.com> <85d99afe0810200744x4755e564t85d014accbe1d871@mail.gmail.com> <57c63afe0810200953v1eb7d44do5aa32eee4503102b@mail.gmail.com> <0aea9c8303de390c98ae84bd679d62d9@ruby-forum.com> <57c63afe0810201003n4bb6d745l88f1209dd005999b@mail.gmail.com> <2e222877f6bac505fca6ea4ba8a220cd@ruby-forum.com> Message-ID: <57c63afe0810220505x7417b92dqaef5bbc89435b2b4@mail.gmail.com> On Tue, Oct 21, 2008 at 9:39 PM, Harry Bishop wrote: > Thanks David, > Your method works well and rspec succeeds now. > > Is the preferred way of using code with rspec to not rely on instance > variables set in a parent during execution but to rely on the method > only construct to be able to interact? > > I see the way this works for the outline you provided. I am wondering > what the implications are with respect to writing ruby code with the > assumption parent instance variables will be inherited by children. The > approach you are providing would indicate that an attr_read method is > preferred so that the retrieve method can be stubbed since the instance > variable doesn't get set when tested. > > Is this a general rule of practice with rspec? As a beginner I'm trying > to get the larger picture here and appreciate your insight with this. This is more of a design thing than an rspec thing. While hierarchies can be useful for sharing behaviour and the concept of class, sharing state up and down a hierarchy can be quite confusing and error prone. * Variable names are far more likely to change than method names. The implication is that you're more likely to get bitten because somebody else changed an instance variable name in another class in the hierarchy (above OR below) than if a method name changes. People just take greater care when changing method names. * To understand that an instance variable is shared up and down a hierarchy I have to look at the code, whereas to understand that an instance method is overridden, I simply need look at the instance methods, which I easily do in irb, or looking at rdoc. * Overriding methods goes in one direction in a hierarchy, while resetting instance variables can go in either direction and lead to some nasty bugs. And, of course, relying on methods instead of variables also makes it easier to mock and stub :) For me, that is very important. FWIW, David > HR From dchelimsky at gmail.com Wed Oct 22 09:46:12 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 22 Oct 2008 08:46:12 -0500 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: <06FEBB46-D9A8-43C0-B6E4-DA6D11620116@railsnewbie.com> References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> <48F8A717.8010409@joesniff.co.uk> <1fb4df0810170842g55b528a0p5face7b51a876aa1@mail.gmail.com> <0372781A-E151-4538-8477-AE41076EFCB1@railsnewbie.com> <06FEBB46-D9A8-43C0-B6E4-DA6D11620116@railsnewbie.com> Message-ID: <57c63afe0810220646g24d3ec90v2dff37055f252a3e@mail.gmail.com> On Sun, Oct 19, 2008 at 9:44 PM, Scott Taylor wrote: > > On Oct 19, 2008, at 12:14 PM, Pat Maddox wrote: > >> Scott Taylor writes: >> >>> On Oct 18, 2008, at 9:19 AM, Pat Maddox wrote: >>> >>>> Scott Taylor writes: >>>> >>>>> As for #3, I'm >>>>> pretty sure that Ruby's method_missing allows one to raise an >>>>> exception easily. Not sure what a Javascript mocking framework would >>>>> do in this case. >>>> >>>> I'm not sure that I buy that this feature is very important. Both >>>> Javascript and Ruby blow up when you call a method that doesn't >>>> exist on >>>> it anyway. What's the difference between "Received unexpected message >>>> 'foo'" and "NoMethodError 'foo'"? >>> >>> Unless I'm mistaken, it's only when *another* method gets called on a >>> missing method that an error gets raised: >>> >>>>>> o = {}; >>> >>> Object >>>>>> >>>>>> o.foo >> >> You would need to do o.foo() to actually call the method. That will >> give you "o.foo is undefined" >> > > Oops. I feel like a tool. Guess ruby syntax still invades my brain. > >> >>> BTW, Pat - Have you still been working on integrating test spy into >>> rspec? >> >> Nope, I found not_a_mock [1] and it works well. > > > Any plans to roll not_a_mock into rspec core? No, but if you'd like to submit a patch w/ a wrapper we can add it to the list of supported frameworks. > > Scott > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Wed Oct 22 11:24:47 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Wed, 22 Oct 2008 17:24:47 +0200 Subject: [rspec-users] Where is current_user? In-Reply-To: <57c63afe0810220505x7417b92dqaef5bbc89435b2b4@mail.gmail.com> References: <09f1c129595089c319060aaa03ced2aa@ruby-forum.com> <59041e62936eb78c85a1f4255d20c4ce@ruby-forum.com> <57c63afe0810200500p6c0ce1f0u9f031799b7739a69@mail.gmail.com> <2c6bf466bd1adf383c2a298d86528790@ruby-forum.com> <8382062d06171fcf9d60d61ad049c81c@ruby-forum.com> <57c63afe0810200536r2eb597e5ge70cc799c4497c57@mail.gmail.com> <1daa44bdd5419fced37fc915f62bd002@ruby-forum.com> <57c63afe0810200608y3bab2582l5df08c954b67810@mail.gmail.com> <284cf96e5c080d4da7251d134028ba5d@ruby-forum.com> <57c63afe0810200652qa1089c5g7f9f6e8357750c42@mail.gmail.com> <73808a61e92fa7edc11b9ba99d88d36c@ruby-forum.com> <85d99afe0810200744x4755e564t85d014accbe1d871@mail.gmail.com> <57c63afe0810200953v1eb7d44do5aa32eee4503102b@mail.gmail.com> <0aea9c8303de390c98ae84bd679d62d9@ruby-forum.com> <57c63afe0810201003n4bb6d745l88f1209dd005999b@mail.gmail.com> <2e222877f6bac505fca6ea4ba8a220cd@ruby-forum.com> <57c63afe0810220505x7417b92dqaef5bbc89435b2b4@mail.gmail.com> Message-ID: <1e2baacfb7e6d140ec8ab577dd64bf95@ruby-forum.com> David Chelimsky wrote: > On Tue, Oct 21, 2008 at 9:39 PM, Harry Bishop > wrote: >> approach you are providing would indicate that an attr_read method is >> preferred so that the retrieve method can be stubbed since the instance >> variable doesn't get set when tested. >> >> Is this a general rule of practice with rspec? As a beginner I'm trying >> to get the larger picture here and appreciate your insight with this. > > This is more of a design thing than an rspec thing. While hierarchies > can be useful for sharing behaviour and the concept of class, sharing > state up and down a hierarchy can be quite confusing and error prone. > > * Variable names are far more likely to change than method names. The > implication is that you're more likely to get bitten because somebody > else changed an instance variable name in another class in the > hierarchy (above OR below) than if a method name changes. People just > take greater care when changing method names. > * To understand that an instance variable is shared up and down a > hierarchy I have to look at the code, whereas to understand that an > instance method is overridden, I simply need look at the instance > methods, which I easily do in irb, or looking at rdoc. > * Overriding methods goes in one direction in a hierarchy, while > resetting instance variables can go in either direction and lead to > some nasty bugs. > > And, of course, relying on methods instead of variables also makes it > easier to mock and stub :) For me, that is very important. > > FWIW, > David David, I agree with this philosophy. Sometimes in using a language it isn't always clear which approach will be a better payoff. I appreciate your advice here. HR -- Posted via http://www.ruby-forum.com/. From mailing_lists at railsnewbie.com Wed Oct 22 11:38:12 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 22 Oct 2008 11:38:12 -0400 Subject: [rspec-users] RSpec vs Screw.Unit In-Reply-To: <57c63afe0810220646g24d3ec90v2dff37055f252a3e@mail.gmail.com> References: <43AC09CF-CB97-4B78-94B9-39ABBAE3E167@patchspace.co.uk> <48F8A717.8010409@joesniff.co.uk> <1fb4df0810170842g55b528a0p5face7b51a876aa1@mail.gmail.com> <0372781A-E151-4538-8477-AE41076EFCB1@railsnewbie.com> <06FEBB46-D9A8-43C0-B6E4-DA6D11620116@railsnewbie.com> <57c63afe0810220646g24d3ec90v2dff37055f252a3e@mail.gmail.com> Message-ID: <80FF906B-78C2-4D2B-BF28-2D5FF3AC6289@railsnewbie.com> On Oct 22, 2008, at 9:46 AM, David Chelimsky wrote: > On Sun, Oct 19, 2008 at 9:44 PM, Scott Taylor > wrote: >> >> On Oct 19, 2008, at 12:14 PM, Pat Maddox wrote: >> >>> Scott Taylor writes: >>> >>>> On Oct 18, 2008, at 9:19 AM, Pat Maddox wrote: >>>> >>>>> Scott Taylor writes: >>>>> >>>>>> As for #3, I'm >>>>>> pretty sure that Ruby's method_missing allows one to raise an >>>>>> exception easily. Not sure what a Javascript mocking framework >>>>>> would >>>>>> do in this case. >>>>> >>>>> I'm not sure that I buy that this feature is very important. Both >>>>> Javascript and Ruby blow up when you call a method that doesn't >>>>> exist on >>>>> it anyway. What's the difference between "Received unexpected >>>>> message >>>>> 'foo'" and "NoMethodError 'foo'"? >>>> >>>> Unless I'm mistaken, it's only when *another* method gets called >>>> on a >>>> missing method that an error gets raised: >>>> >>>>>>> o = {}; >>>> >>>> Object >>>>>>> >>>>>>> o.foo >>> >>> You would need to do o.foo() to actually call the method. That will >>> give you "o.foo is undefined" >>> >> >> Oops. I feel like a tool. Guess ruby syntax still invades my brain. >> >>> >>>> BTW, Pat - Have you still been working on integrating test spy into >>>> rspec? >>> >>> Nope, I found not_a_mock [1] and it works well. >> >> >> Any plans to roll not_a_mock into rspec core? > > No, but if you'd like to submit a patch w/ a wrapper we can add it to > the list of supported frameworks. Yeah, I'll do this eventually if no one else does it, although I'll probably want to add support for LH #576 first: http://rspec.lighthouseapp.com/projects/5645/tickets/576-switch-mock-frameworks-at-run-time#ticket-576-1 Scott From ashley.moran at patchspace.co.uk Wed Oct 22 16:19:27 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 22 Oct 2008 21:19:27 +0100 Subject: [rspec-users] Merb In-Reply-To: <59329F82-490B-4EDA-85AA-4F633AB4C00A@jlaine.net> References: <2346471A-B6F5-46C2-A9DC-0E98512C2F99@patchspace.co.uk> <3F505B0C-254E-40B0-9F4A-4CCE75B88C5B@patchspace.co.uk> <59329F82-490B-4EDA-85AA-4F633AB4C00A@jlaine.net> Message-ID: <96F24065-A62F-4C3B-A7EA-B57D02317758@patchspace.co.uk> On Oct 21, 2008, at 7:24 am, Jarkko Laine wrote: > Yeah, I was using that API to a great extent with a recent project > and was pretty successful at doing outside-in development with rspec > and merb. The syntax used in merb controller specs is a bit > different from what Rails uses, but once you got around it, it was > actually pretty cool and flexible. Here's a snippet from a > controller spec in the project: > > http://pastie.org/private/6uijgfwwzjngvhbkgxwqq > > Note that I generally stub both render and display for the > controller to make the tests run faster. > > There's probably a lot of optimization left to do with the specs but > I find the dispatch helpers pretty cool for building more > specialized methods such as do_post. Hi Jarkko Thanks a lot for that. I've just got my first controller spec working, that's a big win! How do you handle #only_provides ? The merb format handler is way slicker than respond_to, but I can't get a handle on how to spec its behaviour. (Should you fake an XML request for controllers with "only_provides :html", or is controller.should_receive(:only_provides).with(:html) more appropriate?) And actually: it "should display a new Item" do do_get do |controller| controller.should_receive(:display).with(@item) end end is really nice syntax. Just need to work on factoring out the helper: def do_get(&blk) dispatch_to(Items, :new) do |controller| controller.stub!(:render) controller.stub!(:display) yield controller if block_given? end end from specs, but you can't abstract one file! In this case, RSpec mocks are simpler than not_a_mock. (More reason to be able to switch framework at runtime?) > I hope the merb folks will keep us outside-(s)inners in mind and not > scrap the API. I notice you're on both list so hopefully you can give me nudges in the right Merb direction and Merb nudges in the right BDD direction :) But I also hope they will make concessions to isolated controller fans. All the more reason for me to write up what I find, I guess. Cheers Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From pergesu at gmail.com Wed Oct 22 16:32:29 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 22 Oct 2008 13:32:29 -0700 Subject: [rspec-users] Dreading Controller Specs In-Reply-To: <34C486C4-EC2B-4707-A221-DAC90931A854@mattwynne.net> (Matt Wynne's message of "Wed\, 22 Oct 2008 08\:45\:52 +0100") References: <48FDA4C4.7040505@mail.pigdestroyer.co.uk> <598008DC-7D2D-4D86-9DEE-A00BC2DF28B8@madeofstone.net> <4C854A62-BC82-4161-8809-C1F4F1E12B3C@mattwynne.net> <1fb4df0810211413ye98101dl90d562c44ad4a25e@mail.gmail.com> <34C486C4-EC2B-4707-A221-DAC90931A854@mattwynne.net> Message-ID: Matt Wynne writes: > If we assume that the work to be done against the database or other > sub-systems is non-trivial, then we should not directly call the > persistence layer (= Models in Railsspeak) from the Controller, but > delegate that to another class. It seems like Service is a much more > appropriate name than Presenter here, since this work nothing to do > with presentation. I buy the thing about conductors, and I like the > new-bamboo guys, but I do wonder whether there's some wheel > reinvention going on there. I think any app with a rich domain model benefits from a service layer that uses that model. When building Rails apps, stuff is relatively simple and the controllers *are* the service layer. That's how I think of it, anyway. Most of the time that's sufficient, but sometimes it gets complex enough that you want to split out some of the logic. Whenever I've had to do that, I've created some kind of Service object to handle the coordination of domain objects, and I let the controller handle all the HTTP shit and pass required info into the Service. Now, I haven't had to do that often - I think I've written like 5 or 6 of these Service objects in the last 3 years of daily Rails work - but when I have, I've been happy with the testability and maintenance benefits. Separation of concerns ftw! Pat From bastien.vaucher at gmail.com Thu Oct 23 05:16:55 2008 From: bastien.vaucher at gmail.com (Bastien) Date: Thu, 23 Oct 2008 02:16:55 -0700 (PDT) Subject: [rspec-users] Specing protected methods Message-ID: <92c6738e-f46a-4bef-89d4-5a66e90e5c50@m73g2000hsh.googlegroups.com> Hi everyone, Do anyone know if there's a way to spec protected methods ? Thanks in advance -- Bastien From matt at mattwynne.net Thu Oct 23 06:37:28 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 23 Oct 2008 11:37:28 +0100 Subject: [rspec-users] Specing protected methods In-Reply-To: <92c6738e-f46a-4bef-89d4-5a66e90e5c50@m73g2000hsh.googlegroups.com> References: <92c6738e-f46a-4bef-89d4-5a66e90e5c50@m73g2000hsh.googlegroups.com> Message-ID: <6A6CAA15-DC7B-4960-8470-E24BFDD5539C@mattwynne.net> On 23 Oct 2008, at 10:16, Bastien wrote: > Hi everyone, > Do anyone know if there's a way to spec protected methods ? > Thanks in advance Sorry if this sounds preachy, but I would always advise you to factor out the code in the method into another class, then test that class. If the behaviour of the method is so complex you need to test it on it's own, it deserves to be in a class all by itself. This is what we call, 'listening to your specs' - if it's hard to spec, you've probably got the design wrong. HTH, Matt From matt at mattwynne.net Thu Oct 23 07:00:20 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 23 Oct 2008 12:00:20 +0100 Subject: [rspec-users] How to Spec a Module to be used in a Controller Message-ID: I want to be able to factor out bits of a controller's behaviour into modules, and spec them independently. E.g. modules like Authentication and ExceptionHandling that are mixed into ApplicationController. In my spec, I create a FakeController class which inherits from ActionController::Base, and mix in the module. This is working OK, but I'm struggling with the routing so that I can use the integration session #get method to spin up my FakeController. I have to set up the routing for this FakeController in a before(:all), then reload the default routing in after(:all) so as not to pollute the other specs. Is this how other people do this? Is there a trick that I'm missing? cheers, Matt From bastien.vaucher at gmail.com Thu Oct 23 07:49:53 2008 From: bastien.vaucher at gmail.com (Bastien) Date: Thu, 23 Oct 2008 04:49:53 -0700 (PDT) Subject: [rspec-users] Specing protected methods In-Reply-To: <6A6CAA15-DC7B-4960-8470-E24BFDD5539C@mattwynne.net> References: <92c6738e-f46a-4bef-89d4-5a66e90e5c50@m73g2000hsh.googlegroups.com> <6A6CAA15-DC7B-4960-8470-E24BFDD5539C@mattwynne.net> Message-ID: <50e5d676-af0e-43bf-b30c-852da867d449@l77g2000hse.googlegroups.com> I totally agree with the ''listening to your specs" concepts and always divide my code into small methods easier to spec. Now let me get you right, here's my code : class Survey < ActiveRecord::Base has_many :participants ... def generate_reports ... sub_total = sub_total(participants.reports) ... end protected def sub_total(reports) sub_total = 0 reports.collect do |report| sub_total = sub_total + report.score end return sub_total end end I m already specing the "generate_reports" methods with a mock on "sub_total", but I would also like to spec that method. I've put this method into protected because it doesn't make sens to call it from outside this class. But you're arguing that I should put that method into a lib ? I m not sure it would make sense as this method is very specific to that class, and would actually be easy to spec. Except that it's not possible to call a protected method from a spec as far as I know, correct me if I m wrong. (I maybe didn't explain my problem well in the first place) Regards -- Bastien On Oct 23, 12:37?pm, Matt Wynne wrote: > On 23 Oct 2008, at 10:16, Bastien wrote: > > > Hi everyone, > > Do anyone know if there's a way to spec protected methods ? > > Thanks in advance > > Sorry if this sounds preachy, but I would always advise you to factor ? > out the code in the method into another class, then test that class. > > If the behaviour of the method is so complex you need to test it on ? > it's own, it deserves to be in a class all by itself. > > This is what we call, 'listening to your specs' - if it's hard to ? > spec, you've probably got the design wrong. > > HTH, > Matt > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From ashley.moran at patchspace.co.uk Thu Oct 23 08:43:16 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 23 Oct 2008 13:43:16 +0100 Subject: [rspec-users] RSpec 1.1.9 on JRuby Message-ID: <613B48A6-DB45-458A-A3E8-1F1E8B538204@patchspace.co.uk> Hi Can you use RSpec 1.1.9 on JRuby? Now it depends on spicycode-rcov, I can't install it: # jgem install rspec --development Building native extensions. This could take a while... ERROR: Error installing rspec: ERROR: Failed to build gem native extension. /opt/local/share/java/jruby/bin/jruby extconf.rb install rspec -- development Gem files will remain installed in /opt/local/share/java/jruby/lib/ ruby/gems/1.8/gems/spicycode-rcov-0.8.1.3.0 for inspection. Results logged to /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/ spicycode-rcov-0.8.1.3.0/ext/rcovrt/gem_make.out Thanks Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From sfeley at gmail.com Thu Oct 23 08:51:35 2008 From: sfeley at gmail.com (Stephen Eley) Date: Thu, 23 Oct 2008 08:51:35 -0400 Subject: [rspec-users] How to Spec a Module to be used in a Controller In-Reply-To: References: Message-ID: <1fb4df0810230551g77beaa87lda8c38bf7ef4b2b4@mail.gmail.com> On Thu, Oct 23, 2008 at 7:00 AM, Matt Wynne wrote: > > This is working OK, but I'm struggling with the routing so that I can use > the integration session #get method to spin up my FakeController. Is that strictly necessary? Your fake controller's never going to get routed to in real life, so testing that isn't important. Why not just put things in the params[] array that matter to your module and call the controller method directly? (I.e., don't call "get :index" -- just call "index.") Another option would be to skip the fake controller, put the tests for your module into a shared behavior spec, and include that shared behavior in the spec for every controller that uses the module with it_should_behave_like. You'd be testing the module's behavior a few times over, but you'd be doing it in the real controllers that really use it. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From cdemyanovich at gmail.com Thu Oct 23 09:37:05 2008 From: cdemyanovich at gmail.com (Craig Demyanovich) Date: Thu, 23 Oct 2008 09:37:05 -0400 Subject: [rspec-users] Specing protected methods In-Reply-To: <50e5d676-af0e-43bf-b30c-852da867d449@l77g2000hse.googlegroups.com> References: <92c6738e-f46a-4bef-89d4-5a66e90e5c50@m73g2000hsh.googlegroups.com> <6A6CAA15-DC7B-4960-8470-E24BFDD5539C@mattwynne.net> <50e5d676-af0e-43bf-b30c-852da867d449@l77g2000hse.googlegroups.com> Message-ID: <61c885db0810230637r329ffc2bi22e7459d3360be3d@mail.gmail.com> On Thu, Oct 23, 2008 at 7:49 AM, Bastien wrote: > I m already specing the "generate_reports" methods with a mock on > "sub_total", but I would also like to spec that method. I've put this > method into protected because it doesn't make sens to call it from > outside this class. But you're arguing that I should put that method > into a lib ? I m not sure it would make sense as this method is very > specific to that class, and would actually be easy to spec. Except > that it's not possible to call a protected method from a spec as far > as I know, correct me if I m wrong. (I maybe didn't explain my problem > well in the first place) If you're somehow mocking the sub_total method while specing the generate_reports method, don't do that. Don't stub/mock the thing that you're specing, only stub/mock its collaborators, i.e., its dependencies. I would either verify via generate_reports that the sub totals on the report are correct, or I'd factor out something like a ReportGenerator class and spec it. Then, I'd stub/mock out the ReportGenerator in the specs for the Survey class. Regards, Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Thu Oct 23 09:49:23 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 23 Oct 2008 06:49:23 -0700 Subject: [rspec-users] How to Spec a Module to be used in a Controller In-Reply-To: (Matt Wynne's message of "Thu\, 23 Oct 2008 12\:00\:20 +0100") References: Message-ID: Matt Wynne writes: > I want to be able to factor out bits of a controller's behaviour into > modules, and spec them independently. E.g. modules like Authentication > and ExceptionHandling that are mixed into ApplicationController. > > In my spec, I create a FakeController class which inherits from > ActionController::Base, and mix in the module. > > This is working OK, but I'm struggling with the routing so that I can > use the integration session #get method to spin up my FakeController. > I have to set up the routing for this FakeController in a > before(:all), then reload the default routing in after(:all) so as not > to pollute the other specs. > > Is this how other people do this? Is there a trick that I'm missing? Yeah, it's kind of a bummer, just something you have to deal with cause of Rails. What I do is set up a default route, you know the old-school ':controller/:action/:id' kind. Pat From pergesu at gmail.com Thu Oct 23 09:50:30 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 23 Oct 2008 06:50:30 -0700 Subject: [rspec-users] Specing protected methods In-Reply-To: <50e5d676-af0e-43bf-b30c-852da867d449@l77g2000hse.googlegroups.com> (Bastien's message of "Thu\, 23 Oct 2008 04\:49\:53 -0700 \(PDT\)") References: <92c6738e-f46a-4bef-89d4-5a66e90e5c50@m73g2000hsh.googlegroups.com> <6A6CAA15-DC7B-4960-8470-E24BFDD5539C@mattwynne.net> <50e5d676-af0e-43bf-b30c-852da867d449@l77g2000hse.googlegroups.com> Message-ID: Bastien writes: > I totally agree with the ''listening to your specs" concepts and > always divide my code into small methods easier to spec. > Now let me get you right, here's my code : > > class Survey < ActiveRecord::Base > has_many :participants > ... > def generate_reports > ... > sub_total = sub_total(participants.reports) > ... > end > > protected > > def sub_total(reports) > sub_total = 0 > reports.collect do |report| > sub_total = sub_total + report.score > end > return sub_total > end > > end > > I m already specing the "generate_reports" methods with a mock on > "sub_total" Why are you mocking #sub_total? Pat From dchelimsky at gmail.com Thu Oct 23 09:51:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 23 Oct 2008 08:51:53 -0500 Subject: [rspec-users] Specing protected methods In-Reply-To: <50e5d676-af0e-43bf-b30c-852da867d449@l77g2000hse.googlegroups.com> References: <92c6738e-f46a-4bef-89d4-5a66e90e5c50@m73g2000hsh.googlegroups.com> <6A6CAA15-DC7B-4960-8470-E24BFDD5539C@mattwynne.net> <50e5d676-af0e-43bf-b30c-852da867d449@l77g2000hse.googlegroups.com> Message-ID: <57c63afe0810230651o1cc84161y32cffb7efa2410@mail.gmail.com> On Thu, Oct 23, 2008 at 6:49 AM, Bastien wrote: > I totally agree with the ''listening to your specs" concepts and > always divide my code into small methods easier to spec. > Now let me get you right, here's my code : > > class Survey < ActiveRecord::Base > has_many :participants > ... > def generate_reports > ... > sub_total = sub_total(participants.reports) > ... > end > > protected > > def sub_total(reports) > sub_total = 0 > reports.collect do |report| > sub_total = sub_total + report.score > end > return sub_total > end > > end > > I m already specing the "generate_reports" methods with a mock on > "sub_total", but I would also like to spec that method. I've put this > method into protected because it doesn't make sens to call it from > outside this class. But you're arguing that I should put that method > into a lib ? I m not sure it would make sense as this method is very > specific to that class, and would actually be easy to spec. Except > that it's not possible to call a protected method from a spec as far > as I know, correct me if I m wrong. (I maybe didn't explain my problem > well in the first place) This sort of decision is always a balancing act. Leaving it where it is means you have to either * unprotect it, which you clearly prefer not to do * expose it for you code example using clever ruby trickery * give up testing it directly * move it to another class, adding conceptual weight to your system None of these are perfect and all come with some tradeoff. I'll confess that, in practice, I'd probably not test this directly. More often than not, for me, the sub_total method is a result of refactoring the generate_reports method, which by that time would have at least two code examples in which the only difference is the sum of scores of the reports. In this case, however, assuming participants and reports are AR backed models, you don't really need to introduce a new class: subtotal = participants.reports.sum('score') Cheers, David > > Regards > > -- Bastien > > On Oct 23, 12:37 pm, Matt Wynne wrote: >> On 23 Oct 2008, at 10:16, Bastien wrote: >> >> > Hi everyone, >> > Do anyone know if there's a way to spec protected methods ? >> > Thanks in advance >> >> Sorry if this sounds preachy, but I would always advise you to factor >> out the code in the method into another class, then test that class. >> >> If the behaviour of the method is so complex you need to test it on >> it's own, it deserves to be in a class all by itself. >> >> This is what we call, 'listening to your specs' - if it's hard to >> spec, you've probably got the design wrong. >> >> HTH, >> Matt >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Thu Oct 23 09:58:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 23 Oct 2008 08:58:53 -0500 Subject: [rspec-users] RSpec 1.1.9 on JRuby In-Reply-To: <613B48A6-DB45-458A-A3E8-1F1E8B538204@patchspace.co.uk> References: <613B48A6-DB45-458A-A3E8-1F1E8B538204@patchspace.co.uk> Message-ID: <57c63afe0810230658g1757df2ex41fd7e8c3664665b@mail.gmail.com> On Thu, Oct 23, 2008 at 7:43 AM, Ashley Moran wrote: > Hi > > Can you use RSpec 1.1.9 on JRuby? Now it depends on spicycode-rcov, I can't > install it: > > # jgem install rspec --development > Building native extensions. This could take a while... > ERROR: Error installing rspec: > ERROR: Failed to build gem native extension. > > /opt/local/share/java/jruby/bin/jruby extconf.rb install rspec --development > > > Gem files will remain installed in > /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/spicycode-rcov-0.8.1.3.0 > for inspection. > Results logged to > /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/spicycode-rcov-0.8.1.3.0/ext/rcovrt/gem_make.out For rspec-1.1.9 you have to be on rubygems 1.3 to avoid those dependencies (as they are developer deps and I just used hoe to create the gemspec, which makes them normal deps for rubygems <= 1.2). I'll make sure that dep is not there for the next rspec release, but in the mean time, upgrading to rubygems 1.3 and reinstalling rspec will solve your problem. That assumes that there is a jgem-1.3. If not, you can probably do this: git clone git://github.com/dchelimsky/rspec.git git co 1.1.9 Then modify rspec.gemspec to eliminate the dependency and build the gem locally: jgem build rspec.gemspec jgem install pkg/rspec-1.1.9.gem HTH, David > > Thanks > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From bastien.vaucher at gmail.com Thu Oct 23 11:00:56 2008 From: bastien.vaucher at gmail.com (Bastien) Date: Thu, 23 Oct 2008 08:00:56 -0700 (PDT) Subject: [rspec-users] Specing protected methods In-Reply-To: <57c63afe0810230651o1cc84161y32cffb7efa2410@mail.gmail.com> References: 57c63afe0810230651o1cc84161y32cffb7efa2410@mail.gmail.com Message-ID: Thanks for all your answers. I was just wondering how about using send in my specs ? It would bypass the protected limitation without altering my code : @survey.send( :sub_total, [@mock_report] ) Is that the kind of trickery you were referring to David ? Would that be bad practice ? Regards -- Bastien On Oct 23, 3:51?pm, "David Chelimsky" wrote: > On Thu, Oct 23, 2008 at 6:49 AM, Bastien wrote: > > I totally agree with the ''listening to your specs" concepts and > > always divide my code into small methods easier to spec. > > Now let me get you right, here's my code : > > > class Survey < ActiveRecord::Base > > ?has_many :participants > > ?... > > ?def generate_reports > > ? ?... > > ? ?sub_total = sub_total(participants.reports) > > ? ?... > > ?end > > > protected > > > ?def sub_total(reports) > > ? ?sub_total = 0 > > ? ?reports.collect do |report| > > ? ? ?sub_total = sub_total + report.score > > ? ?end > > ? return sub_total > > ?end > > > end > > > I m already specing the "generate_reports" methods with a mock on > > "sub_total", but I would also like to spec that method. I've put this > > method into protected because it doesn't make sens to call it from > > outside this class. But you're arguing that I should put that method > > into a lib ? I m not sure it would make sense as this method is very > > specific to that class, and would actually be easy to spec. Except > > that it's not possible to call a protected method from a spec as far > > as I know, correct me if I m wrong. (I maybe didn't explain my problem > > well in the first place) > > This sort of decision is always a balancing act. Leaving it where it > is means you have to either > > * unprotect it, which you clearly prefer not to do > * expose it for you code example using clever ruby trickery > * give up testing it directly > * move it to another class, adding conceptual weight to your system > > None of these are perfect and all come with some tradeoff. > > I'll confess that, in practice, I'd probably not test this directly. > More often than not, for me, the sub_total method is a result of > refactoring the generate_reports method, which by that time would have > at least two code examples in which the only difference is the sum of > scores of the reports. > > In this case, however, assuming participants and reports are AR backed > models, you don't really need to introduce a new class: > > subtotal = participants.reports.sum('score') > > Cheers, > David > > > > > > > Regards > > > -- Bastien > > > On Oct 23, 12:37 pm, Matt Wynne wrote: > >> On 23 Oct 2008, at 10:16, Bastien wrote: > > >> > Hi everyone, > >> > Do anyone know if there's a way to spec protected methods ? > >> > Thanks in advance > > >> Sorry if this sounds preachy, but I would always advise you to factor > >> out the code in the method into another class, then test that class. > > >> If the behaviour of the method is so complex you need to test it on > >> it's own, it deserves to be in a class all by itself. > > >> This is what we call, 'listening to your specs' - if it's hard to > >> spec, you've probably got the design wrong. > > >> HTH, > >> Matt > >> _______________________________________________ > >> 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 Thu Oct 23 11:33:17 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 23 Oct 2008 10:33:17 -0500 Subject: [rspec-users] Specing protected methods In-Reply-To: References: <57c63afe0810230651o1cc84161y32cffb7efa2410@mail.gmail.com> Message-ID: <57c63afe0810230833me6a3d09p222d2533028e815a@mail.gmail.com> On Thu, Oct 23, 2008 at 10:00 AM, Bastien wrote: > Thanks for all your answers. > > I was just wondering how about using send in my specs ? It would > bypass the protected limitation without altering my code : > > @survey.send( :sub_total, [@mock_report] ) > > Is that the kind of trickery you were referring to David ? Would that > be bad practice ? If you're going to do this, use __send__ or your code examples will break if/when you go to Ruby >= 1.9. As for good/bad practice, here's the way I see it: there is a lot of evidence that encapsulation is a good thing in that it constrains contact points between objects, making them less coupled and easier to modify internally, swap in and out (polymorphism), etc, etc. Every time you violate encapsulation by using __send__, even in code examples, you increase coupling by a little bit, and make your system that much more brittle. So while one violation might seem harmless, it's a slippery slope (sorry for the clich?). With all that - you'll find __send__ in my code, and in my code examples. But I'm conscious of the risks. FWIW. Cheers, David > > Regards > > -- Bastien > > On Oct 23, 3:51 pm, "David Chelimsky" wrote: >> On Thu, Oct 23, 2008 at 6:49 AM, Bastien wrote: >> > I totally agree with the ''listening to your specs" concepts and >> > always divide my code into small methods easier to spec. >> > Now let me get you right, here's my code : >> >> > class Survey < ActiveRecord::Base >> > has_many :participants >> > ... >> > def generate_reports >> > ... >> > sub_total = sub_total(participants.reports) >> > ... >> > end >> >> > protected >> >> > def sub_total(reports) >> > sub_total = 0 >> > reports.collect do |report| >> > sub_total = sub_total + report.score >> > end >> > return sub_total >> > end >> >> > end >> >> > I m already specing the "generate_reports" methods with a mock on >> > "sub_total", but I would also like to spec that method. I've put this >> > method into protected because it doesn't make sens to call it from >> > outside this class. But you're arguing that I should put that method >> > into a lib ? I m not sure it would make sense as this method is very >> > specific to that class, and would actually be easy to spec. Except >> > that it's not possible to call a protected method from a spec as far >> > as I know, correct me if I m wrong. (I maybe didn't explain my problem >> > well in the first place) >> >> This sort of decision is always a balancing act. Leaving it where it >> is means you have to either >> >> * unprotect it, which you clearly prefer not to do >> * expose it for you code example using clever ruby trickery >> * give up testing it directly >> * move it to another class, adding conceptual weight to your system >> >> None of these are perfect and all come with some tradeoff. >> >> I'll confess that, in practice, I'd probably not test this directly. >> More often than not, for me, the sub_total method is a result of >> refactoring the generate_reports method, which by that time would have >> at least two code examples in which the only difference is the sum of >> scores of the reports. >> >> In this case, however, assuming participants and reports are AR backed >> models, you don't really need to introduce a new class: >> >> subtotal = participants.reports.sum('score') >> >> Cheers, >> David >> >> >> >> >> >> > Regards >> >> > -- Bastien >> >> > On Oct 23, 12:37 pm, Matt Wynne wrote: >> >> On 23 Oct 2008, at 10:16, Bastien wrote: >> >> >> > Hi everyone, >> >> > Do anyone know if there's a way to spec protected methods ? >> >> > Thanks in advance >> >> >> Sorry if this sounds preachy, but I would always advise you to factor >> >> out the code in the method into another class, then test that class. >> >> >> If the behaviour of the method is so complex you need to test it on >> >> it's own, it deserves to be in a class all by itself. >> >> >> This is what we call, 'listening to your specs' - if it's hard to >> >> spec, you've probably got the design wrong. >> >> >> HTH, >> >> Matt >> >> _______________________________________________ >> >> 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 lattam at mac.com Thu Oct 23 13:20:48 2008 From: lattam at mac.com (Michael Latta) Date: Thu, 23 Oct 2008 10:20:48 -0700 Subject: [rspec-users] Too Clever? In-Reply-To: <57c63afe0810230833me6a3d09p222d2533028e815a@mail.gmail.com> References: <57c63afe0810230651o1cc84161y32cffb7efa2410@mail.gmail.com> <57c63afe0810230833me6a3d09p222d2533028e815a@mail.gmail.com> Message-ID: <3F5EF628-47F5-4CED-A01E-71079B9F1D26@mac.com> It appears we were too clever, but I think this would be a reasonable use of stories. We tried to have a story file run with 2 different sets of steps to use the same story against both the UI using selenium and against the server API using regular get/put/post. This way we could spec the server API and the UI while ensuring they are in sync for the scenario in question. But stories get confused when there are stories or scenarios with the same names. Does Cucumber deal with this any better than the story runner? Given that it searches for steps rather than having them declared, I would think you can not share story files for different steps? Michael From aslak.hellesoy at gmail.com Thu Oct 23 14:39:03 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 23 Oct 2008 20:39:03 +0200 Subject: [rspec-users] Too Clever? In-Reply-To: <3F5EF628-47F5-4CED-A01E-71079B9F1D26@mac.com> References: <57c63afe0810230651o1cc84161y32cffb7efa2410@mail.gmail.com> <57c63afe0810230833me6a3d09p222d2533028e815a@mail.gmail.com> <3F5EF628-47F5-4CED-A01E-71079B9F1D26@mac.com> Message-ID: <8d961d900810231139t23a2f1eaqf2d5e5e9698e9ae9@mail.gmail.com> On Thu, Oct 23, 2008 at 7:20 PM, Michael Latta wrote: > It appears we were too clever, but I think this would be a reasonable use of > stories. > > We tried to have a story file run with 2 different sets of steps to use the > same story against both the UI using selenium and against the server API > using regular get/put/post. This way we could spec the server API and the > UI while ensuring they are in sync for the scenario in question. But > stories get confused when there are stories or scenarios with the same > names. > > Does Cucumber deal with this any better than the story runner? Given that > it searches for steps rather than having them declared, I would think you > can not share story files for different steps? > I've done this on a couple of projects. steps/common/*_steps.rb steps/watir/*_steps.rb steps/rails/*_steps.rb Set up two tasks and use --require. Or use --profile. See http://github.com/aslakhellesoy/cucumber/wikis/migration-from-rspec-stories for details. Aslak > Michael > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Thu Oct 23 14:49:57 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 23 Oct 2008 14:49:57 -0400 Subject: [rspec-users] Too Clever? In-Reply-To: <3F5EF628-47F5-4CED-A01E-71079B9F1D26@mac.com> References: <57c63afe0810230651o1cc84161y32cffb7efa2410@mail.gmail.com> <57c63afe0810230833me6a3d09p222d2533028e815a@mail.gmail.com> <3F5EF628-47F5-4CED-A01E-71079B9F1D26@mac.com> Message-ID: <85d99afe0810231149l3fefca23lbdc1358bb2529cbf@mail.gmail.com> On Thu, Oct 23, 2008 at 1:20 PM, Michael Latta wrote: > It appears we were too clever, but I think this would be a reasonable use of > stories. > > We tried to have a story file run with 2 different sets of steps to use the > same story against both the UI using selenium and against the server API > using regular get/put/post. This way we could spec the server API and the > UI while ensuring they are in sync for the scenario in question. But > stories get confused when there are stories or scenarios with the same > names. > > Does Cucumber deal with this any better than the story runner? Given that > it searches for steps rather than having them declared, I would think you > can not share story files for different steps? You can do this, you'd just put the steps in different directories and tell cucumber to require the files in one directory for one run, and another for another run. ie: cucumber --require features/steps/selenium/ features/ AND cucumber --require features/steps/normal/ features/ -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com From ashley.moran at patchspace.co.uk Thu Oct 23 16:41:07 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 23 Oct 2008 21:41:07 +0100 Subject: [rspec-users] RSpec 1.1.9 on JRuby In-Reply-To: <57c63afe0810230658g1757df2ex41fd7e8c3664665b@mail.gmail.com> References: <613B48A6-DB45-458A-A3E8-1F1E8B538204@patchspace.co.uk> <57c63afe0810230658g1757df2ex41fd7e8c3664665b@mail.gmail.com> Message-ID: <5C9CCFF4-5BC6-41DF-AA92-84B61401BD1A@patchspace.co.uk> On Oct 23, 2008, at 2:58 pm, David Chelimsky wrote: > For rspec-1.1.9 you have to be on rubygems 1.3 to avoid those > dependencies (as they are developer deps and I just used hoe to create > the gemspec, which makes them normal deps for rubygems <= 1.2). > > I'll make sure that dep is not there for the next rspec release, but > in the mean time, upgrading to rubygems 1.3 and reinstalling rspec > will solve your problem. That assumes that there is a jgem-1.3. If > not, you can probably do this: > > git clone git://github.com/dchelimsky/rspec.git > git co 1.1.9 > > Then modify rspec.gemspec to eliminate the dependency and build the > gem locally: > > jgem build rspec.gemspec > jgem install pkg/rspec-1.1.9.gem > > HTH, > David Hi David Thanks for the explanation. I can live with 1.1.8 in the meantime: I only need it for Cucumber+Celerity, so I won't be doing anything complex in JRuby. I assume the next JRuby release will include RubyGems 1.3. Cheers Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From avdi at avdi.org Thu Oct 23 17:00:26 2008 From: avdi at avdi.org (Avdi Grimm) Date: Thu, 23 Oct 2008 17:00:26 -0400 Subject: [rspec-users] Specing protected methods In-Reply-To: <92c6738e-f46a-4bef-89d4-5a66e90e5c50@m73g2000hsh.googlegroups.com> References: <92c6738e-f46a-4bef-89d4-5a66e90e5c50@m73g2000hsh.googlegroups.com> Message-ID: On Thu, Oct 23, 2008 at 5:16 AM, Bastien wrote: > Hi everyone, > Do anyone know if there's a way to spec protected methods ? > Thanks in advance FWIW, I blogged my answer to this question recently: http://avdi.org/devblog/2008/10/21/testing-private-methods/ -- Avdi Home: http://avdi.org Developer Blog: http://avdi.org/devblog/ Twitter: http://twitter.com/avdi Journal: http://avdi.livejournal.com From avdi at avdi.org Thu Oct 23 17:09:45 2008 From: avdi at avdi.org (Avdi Grimm) Date: Thu, 23 Oct 2008 17:09:45 -0400 Subject: [rspec-users] Specing protected methods In-Reply-To: References: <92c6738e-f46a-4bef-89d4-5a66e90e5c50@m73g2000hsh.googlegroups.com> Message-ID: On Thu, Oct 23, 2008 at 5:00 PM, Avdi Grimm wrote: > FWIW, I blogged my answer to this question recently: > http://avdi.org/devblog/2008/10/21/testing-private-methods/ ...and to be a little more concrete, at first glance the way I'd apply that advice to your code example is to make a class that either subclasses or wraps (via DelegateClass/SimpleDelegate) Array and adds a #sub_total method, something like the following: class Survey < ActiveRecord::Base has_many :participants ... def generate_reports ... sub_total = ReportCollection.new(participants.reports).sub_total ... end class ReportCollection < SimpleDelegator def sub_total sub_total = 0 self.collect do |report| sub_total = sub_total + report.score end return sub_total end end end -- Avdi Home: http://avdi.org Developer Blog: http://avdi.org/devblog/ Twitter: http://twitter.com/avdi Journal: http://avdi.livejournal.com From lattam at mac.com Thu Oct 23 17:20:26 2008 From: lattam at mac.com (Michael Latta) Date: Thu, 23 Oct 2008 14:20:26 -0700 Subject: [rspec-users] Too Clever? In-Reply-To: <85d99afe0810231149l3fefca23lbdc1358bb2529cbf@mail.gmail.com> References: <57c63afe0810230651o1cc84161y32cffb7efa2410@mail.gmail.com> <57c63afe0810230833me6a3d09p222d2533028e815a@mail.gmail.com> <3F5EF628-47F5-4CED-A01E-71079B9F1D26@mac.com> <85d99afe0810231149l3fefca23lbdc1358bb2529cbf@mail.gmail.com> Message-ID: That works when running one at a time. When I want to run all my specs how do I ensure the requires are applied to the appropriate features? It is not all my stories, only a subset that are dual- purposed. Do I need to have directories for those that can be run dual mode and those that are not, and then have a script that runs the 3 cases? Michael On Oct 23, 2008, at 11:49 AM, Zach Dennis wrote: > On Thu, Oct 23, 2008 at 1:20 PM, Michael Latta wrote: >> It appears we were too clever, but I think this would be a >> reasonable use of >> stories. >> >> We tried to have a story file run with 2 different sets of steps to >> use the >> same story against both the UI using selenium and against the >> server API >> using regular get/put/post. This way we could spec the server API >> and the >> UI while ensuring they are in sync for the scenario in question. But >> stories get confused when there are stories or scenarios with the >> same >> names. >> >> Does Cucumber deal with this any better than the story runner? >> Given that >> it searches for steps rather than having them declared, I would >> think you >> can not share story files for different steps? > > You can do this, you'd just put the steps in different directories and > tell cucumber to require the files in one directory for one run, and > another for another run. ie: > > cucumber --require features/steps/selenium/ features/ > AND > cucumber --require features/steps/normal/ features/ > > -- > 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 scottburton11 at gmail.com Thu Oct 23 17:31:16 2008 From: scottburton11 at gmail.com (Scott Burton) Date: Thu, 23 Oct 2008 14:31:16 -0700 Subject: [rspec-users] Autospec running over and over, without changes? Message-ID: <8577893F-E319-4EB6-AA39-8B9F2D6F8FD5@gmail.com> Hi all; I have several Rails projects where RSpec is working correctly, and one in which it is not. Running autospec continuously reloads all files, running my tests over and over again, without making any changes. Each time it reloads, it runs a smaller subset of specs until it settles at around 24. Using Rspec 1.1.9, Rspec-Rails 1.1.9, ZenTest 3.11.0 This happened to me a while back, was fixed in ZenTest. I can't figure out why this only affects one project. Any ideas what's going on here? Thanks, Scott From aslak.hellesoy at gmail.com Thu Oct 23 17:53:56 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 23 Oct 2008 23:53:56 +0200 Subject: [rspec-users] Too Clever? In-Reply-To: References: <57c63afe0810230651o1cc84161y32cffb7efa2410@mail.gmail.com> <57c63afe0810230833me6a3d09p222d2533028e815a@mail.gmail.com> <3F5EF628-47F5-4CED-A01E-71079B9F1D26@mac.com> <85d99afe0810231149l3fefca23lbdc1358bb2529cbf@mail.gmail.com> Message-ID: <8d961d900810231453y34f460b3q5a2f208fafb78ead@mail.gmail.com> On Thu, Oct 23, 2008 at 11:20 PM, Michael Latta wrote: > That works when running one at a time. When I want to run all my specs how > do I ensure the requires are applied to the appropriate features? It is not > all my stories, only a subset that are dual-purposed. Do I need to have > directories for those that can be run dual mode and those that are not, and > then have a script that runs the 3 cases? > You have to run once for each "environment". So if you have say selenium and rails, you'll have to run all features that use selenium in one run and those that use rails in another. (Of course you can have overlap - some features that include run in both runs) Aslak > Michael > > > On Oct 23, 2008, at 11:49 AM, Zach Dennis wrote: > >> On Thu, Oct 23, 2008 at 1:20 PM, Michael Latta wrote: >>> >>> It appears we were too clever, but I think this would be a reasonable use >>> of >>> stories. >>> >>> We tried to have a story file run with 2 different sets of steps to use >>> the >>> same story against both the UI using selenium and against the server API >>> using regular get/put/post. This way we could spec the server API and >>> the >>> UI while ensuring they are in sync for the scenario in question. But >>> stories get confused when there are stories or scenarios with the same >>> names. >>> >>> Does Cucumber deal with this any better than the story runner? Given >>> that >>> it searches for steps rather than having them declared, I would think you >>> can not share story files for different steps? >> >> You can do this, you'd just put the steps in different directories and >> tell cucumber to require the files in one directory for one run, and >> another for another run. ie: >> >> cucumber --require features/steps/selenium/ features/ >> AND >> cucumber --require features/steps/normal/ features/ >> >> -- >> 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 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From alex.rudyk at gmail.com Thu Oct 23 21:07:35 2008 From: alex.rudyk at gmail.com (Oleksandr Rudyk) Date: Thu, 23 Oct 2008 18:07:35 -0700 Subject: [rspec-users] Correct way to spec partials Message-ID: <6e9d2bb40810231807p48485868td431255bb387ac7f@mail.gmail.com> Hi everybody, 1) Does anybody have full working example of how to test partial templates? 2) What the correct place to test partials: controller or view spec? If controller correct place, should I use integrate_views? 3) Is it true that expect_render is deprecated and I have to use should_receive(:render) 4) How to test that partial's locals hash is correct? Thx -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.thomson at ieee.org Fri Oct 24 00:12:00 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Thu, 23 Oct 2008 23:12:00 -0500 Subject: [rspec-users] Surprising mock behavior In-Reply-To: References: <48F8DF9A.6040708@ieee.org> <1fb4df0810171237k5e5425d0ye954364bc3e58ab8@mail.gmail.com> <48FA922F.90708@ieee.org> Message-ID: <49014B10.8080800@ieee.org> Pat Maddox wrote: > Can you please post an example of the spec and production code that > isn't behaving as you expect? > > Pat > Sure, sorry been tied up with business travel this week. Here's my controller... ---- class SubscribersController < ApplicationController def test file = File.new("test.txt", "w") file.puts "one" file.puts "two" file.puts "three" file.puts "four" file.puts "five" file.puts "six" render :action => "index" end end ----- and a spec containing two examples that illustrate what I was talking about - ----- describe SubscribersController do it "does not pass" do file = mock('file') File.stub!(:new).and_return(file) file.should_receive(:puts).with("one") file.should_receive(:puts).with("two") file.should_receive(:puts).with("six") get 'test' end it "does pass" do file = mock('file') File.stub!(:new).and_return(file) file.should_receive(:puts).with("one") file.should_receive(:puts).with("two") file.should_receive(:puts).with("six") file.should_not_receive(:puts).with("ten") get 'test' end end ---- The first example fails with error message "Mock 'file' expected :puts with ("one") but received it with ("three")" (The message seems a little strange since "one" is clearly received, but I can live with that. I understand the point Steve made that a mock should have all messages specified in expectations). The second example passes fine, which is the thing I still find surprising. It seems as if "should_not_receive" doesn't just match the absence of the specified message but also the presence of any message other than the specified message. Mark. -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Fri Oct 24 03:15:19 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 24 Oct 2008 08:15:19 +0100 Subject: [rspec-users] How to Spec a Module to be used in a Controller In-Reply-To: <1fb4df0810230551g77beaa87lda8c38bf7ef4b2b4@mail.gmail.com> References: <1fb4df0810230551g77beaa87lda8c38bf7ef4b2b4@mail.gmail.com> Message-ID: <3968E432-FCF9-4104-8A1E-9DF7D82DCFDA@mattwynne.net> On 23 Oct 2008, at 13:51, Stephen Eley wrote: > On Thu, Oct 23, 2008 at 7:00 AM, Matt Wynne > wrote: >> >> This is working OK, but I'm struggling with the routing so that I >> can use >> the integration session #get method to spin up my FakeController. > > Is that strictly necessary? Your fake controller's never going to get > routed to in real life, so testing that isn't important. Why not just > put things in the params[] array that matter to your module and call > the controller method directly? (I.e., don't call "get :index" -- > just call "index.") I guess not, but when I'm doing things that work with the ActionController lifecycle, like listening for callbacks etc, I'd prefer my specs to to depend too much on the interaction with ActionController's internals. > Another option would be to skip the fake controller, put the tests for > your module into a shared behavior spec, and include that shared > behavior in the spec for every controller that uses the module with > it_should_behave_like. You'd be testing the module's behavior a few > times over, but you'd be doing it in the real controllers that really > use it. Yeah, I have been doing this, but it's starting to feel like a headache to debug - the specs feel like they are a long way away from the code. Do you know what I mean? From matt at mattwynne.net Fri Oct 24 03:53:16 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 24 Oct 2008 08:53:16 +0100 Subject: [rspec-users] How to Spec a Module to be used in a Controller In-Reply-To: References: Message-ID: On 23 Oct 2008, at 14:49, Pat Maddox wrote: > Matt Wynne writes: >> >> Is this how other people do this? Is there a trick that I'm missing? > > Yeah, it's kind of a bummer, just something you have to deal with > cause > of Rails. What I do is set up a default route, you know the old- > school > ':controller/:action/:id' kind. > > Pat > Ok, so here's my best attempt at this: # Briefly enables the old-fashioned wide-open routing for the block, allowing you to run code that spins up a random controller def with_basic_routing ActionController::Routing::Routes.clear! ActionController::Routing::Routes.draw do |map| map.connect ':controller/:action' end yield SK::Routing::DefaultRoutes.load_routes end Any advance? From lists at ruby-forum.com Fri Oct 24 06:07:54 2008 From: lists at ruby-forum.com (Togetherne Togetherne) Date: Fri, 24 Oct 2008 12:07:54 +0200 Subject: [rspec-users] Mulitbrowser selenium ruby Message-ID: <1730f07835c53026b54a5d23140194d4@ruby-forum.com> Hope all is well, Striaght to the point I wonder if someone has any ideas to help me with the following problem: I have written an automation framework in ruby, that uses selenium and rspec and is run by an ant task, as thats the build process that is implemented here. Im currently running all my spec tests in firefox on my local machine by passing the selenium variable: @selenium = Selenium::SeleniumDriver.new("localhost", 4444, "*chrome", "#{URL_BASE_1}", 10000); if i want to change it to use ie then i would do the following @selenium = Selenium::SeleniumDriver.new("localhost", 4444, "*iehta", "#{URL_BASE_1}", 10000); This is fine, bu i want to modify the run so it runs the tests against all the browsers in one go without having to manually edit that line after each run. Anyone have any ideas on how i can do this using rspec? -- Posted via http://www.ruby-forum.com/. From josephwilk at joesniff.co.uk Fri Oct 24 06:39:43 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Fri, 24 Oct 2008 11:39:43 +0100 Subject: [rspec-users] Mulitbrowser selenium ruby In-Reply-To: <1730f07835c53026b54a5d23140194d4@ruby-forum.com> References: <1730f07835c53026b54a5d23140194d4@ruby-forum.com> Message-ID: <4901A5EF.5080903@joesniff.co.uk> Togetherne Togetherne wrote: > Anyone have any ideas on how i can do this using rspec? > We run Integration tests across multi browsers simultaneously using Selenium Grid. Perhaps you could use that (I believe it comes with ant tasks that do some of the magic). http://selenium-grid.openqa.org/ Alternatively if you just want to run them sequentially why don't you write a simple wrapper script. Something like: %w{iehta chrome}.each |browser| do @selenium = Selenium::SeleniumDriver.new("localhost", 4444, "*#{browser}","#{URL_BASE_1}", 10000); #go rspec go! # spec --format html spec/ @selenium.stop end A further note, it does seem a bit odd to have specs that touch Selenium if thats what you are doing. Perhaps look towards using Features and something like Cucumber http://github.com/aslakhellesoy/cucumber/tree/master rather than specs. HTH -- Joseph Wilk http://www.joesniff.co.uk From lists at ruby-forum.com Fri Oct 24 13:15:14 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Fri, 24 Oct 2008 19:15:14 +0200 Subject: [rspec-users] can't seem to test redirect? Message-ID: I'm posting to the create action and seeing the line "at the motion save part of create in the following: def create @motion = Motion.new(params[:motion]) respond_to do |format| if @motion.save puts "at the motion save part of create" flash[:notice] = 'Motion was successfully created. Needs a second' format.html { redirect_to(@motion) } but when I insert the line in motions_controller_spec.rb response.should redirect_to(@motion) I receive "got no redirect" expected redirect to #>, got no redirect Is there something missing in the test? TIA, Harry -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Fri Oct 24 14:06:40 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 24 Oct 2008 11:06:40 -0700 Subject: [rspec-users] can't seem to test redirect? In-Reply-To: (Harry Bishop's message of "Fri\, 24 Oct 2008 19\:15\:14 +0200") References: Message-ID: Harry Bishop writes: > I'm posting to the create action and seeing the line "at the motion save > part of create in the following: > > def create > @motion = Motion.new(params[:motion]) > respond_to do |format| > if @motion.save > puts "at the motion save part of create" > flash[:notice] = 'Motion was successfully created. Needs a > second' > format.html { redirect_to(@motion) } > > but when I insert the line in motions_controller_spec.rb > > response.should redirect_to(@motion) > > I receive "got no redirect" > expected redirect to # 20, title:........>>, got no redirect > > Is there something missing in the test? > > TIA, > Harry Can you post your example code as well? Also, are there any errors? Here are my two guesses at this point: * you forgot to make a request in the example (post :create) * there's some error that is keeping the action from getting to the redirect Also, what is the value of response.code in the example? Pat From lists at ruby-forum.com Fri Oct 24 14:24:39 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Fri, 24 Oct 2008 20:24:39 +0200 Subject: [rspec-users] can't seem to test redirect? In-Reply-To: References: Message-ID: <8cc1570fba6f68545cc46365253576df@ruby-forum.com> Pat Maddox wrote: > Harry Bishop writes: > >> format.html { redirect_to(@motion) } >> >> TIA, >> Harry > > Can you post your example code as well? Also, are there any errors? > Here are my two guesses at this point: > > * you forgot to make a request in the example (post :create) > * there's some error that is keeping the action from getting to the > redirect > > Also, what is the value of response.code in the example? > > Pat Hi Pat, My examples code is before(:each) do login_as(:username) @motion = mock(motions(:four)) @motion.stub!(:new_record?).and_return(true) Motion.stub!(:new).and_return(@motion) @motion.stub!(:save).and_return(@motion) controller.stub!(:redirect_to).with(@motion).and_return(true) end def do_post post :create, {:motion => do_motion_input("ten")} #reads yml input as hash end it "create new proposal with proposer set" do do_post response.should be_success response.should render_template("motions/create") response.should redirect_to(@motion) end The only error is the "got no redirect" response.code is 200 HR -- Posted via http://www.ruby-forum.com/. From pergesu at gmail.com Fri Oct 24 15:29:30 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 24 Oct 2008 12:29:30 -0700 Subject: [rspec-users] can't seem to test redirect? In-Reply-To: <8cc1570fba6f68545cc46365253576df@ruby-forum.com> (Harry Bishop's message of "Fri\, 24 Oct 2008 20\:24\:39 +0200") References: <8cc1570fba6f68545cc46365253576df@ruby-forum.com> Message-ID: > controller.stub!(:redirect_to).with(@motion).and_return(true) Well, I bet this is your problem. You're stubbing redirect_to, so there can't possibly be a redirect! Also, the following example doesn't make any sense: > it "create new proposal with proposer set" do > do_post > response.should be_success > response.should render_template("motions/create") > response.should redirect_to(@motion) > end Your response can be a success (HTTP 200) OR a redirect (HTTP 302), not both. So there are two points you need to address right now: * How do you want this action to behave? (success or redirect?) * Don't stub behavior that you want to verify (if you want it to redirect, let it redirect) Pat From lists at ruby-forum.com Fri Oct 24 16:29:16 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Fri, 24 Oct 2008 22:29:16 +0200 Subject: [rspec-users] can't seem to test redirect? In-Reply-To: References: <8cc1570fba6f68545cc46365253576df@ruby-forum.com> Message-ID: Pat Maddox wrote: > > So there are two points you need to address right now: > * How do you want this action to behave? (success or redirect?) > * Don't stub behavior that you want to verify (if you want it to > redirect, let it redirect) > > Pat Hi Pat, I am new to rspec and still trying to figure out testing the controller. I'm not finding it straightforward for me since my app is built and I am catching up with rspec. I had done unit and functional testing with TestCase. But I found the individual tests awkward. So, I constructed this example to get the create action called and a successful response (200). That worked. The next part of the create action on a successful @motion save is to redirect back to show the motion. How do I test this redirect action? When I take out the stub for redirect I get the following error: undefined method `spec_mocks_mocks_url' for # Harry -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Oct 24 16:57:47 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Fri, 24 Oct 2008 22:57:47 +0200 Subject: [rspec-users] can't seem to test redirect? In-Reply-To: References: <8cc1570fba6f68545cc46365253576df@ruby-forum.com> Message-ID: <94a8769f38a0e3b8494c1428dc257e67@ruby-forum.com> Harry Bishop wrote: > Pat Maddox wrote: > >> >> So there are two points you need to address right now: >> * How do you want this action to behave? (success or redirect?) >> * Don't stub behavior that you want to verify (if you want it to >> redirect, let it redirect) >> >> Pat > > Hi Pat, > I am new to rspec and still trying to figure out testing the > controller. I'm not finding it straightforward for me since my app is > built and I am catching up with rspec. I had done unit and functional > testing with TestCase. But I found the individual tests awkward. > > So, I constructed this example to get the create action called and a > successful response (200). That worked. The next part of the create > action on a successful @motion save is to redirect back to show the > motion. > How do I test this redirect action? > > When I take out the stub for redirect I get the following error: > > undefined method `spec_mocks_mocks_url' for > # > > Harry I have the following example: it "once motion is saved render it with show" do @motion = mock(motions(:four)) puts "#{@motion.id}" Motion.stub!(:new).and_return(@motion) @motion.stub!(:save).and_return(@motion) do_post response.should redirect_to(@motion) with result: undefined method `spec_mocks_mock_url' for # If I change the first line to @motion = motions(:four) the result is: private method `split' called for #. Harry -- Posted via http://www.ruby-forum.com/. From matt at mattwynne.net Fri Oct 24 17:04:45 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 24 Oct 2008 22:04:45 +0100 Subject: [rspec-users] can't seem to test redirect? In-Reply-To: <94a8769f38a0e3b8494c1428dc257e67@ruby-forum.com> References: <8cc1570fba6f68545cc46365253576df@ruby-forum.com> <94a8769f38a0e3b8494c1428dc257e67@ruby-forum.com> Message-ID: On 24 Oct 2008, at 21:57, Harry Bishop wrote: > Harry Bishop wrote: >> response.should redirect_to(@motion) What is this Motion? is it really something that you can redirect people to? Maybe you meant redirect_to(url_for(@motion))? > private method `split' called for #. My guess is that this is rails / rspec-rails trying to make a URL out of your Motion instance. These path method errors are often rather unhelpful. From lists at ruby-forum.com Fri Oct 24 17:34:15 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Fri, 24 Oct 2008 23:34:15 +0200 Subject: [rspec-users] can't seem to test redirect? In-Reply-To: References: <8cc1570fba6f68545cc46365253576df@ruby-forum.com> <94a8769f38a0e3b8494c1428dc257e67@ruby-forum.com> Message-ID: Matt Wynne wrote: > On 24 Oct 2008, at 21:57, Harry Bishop wrote: >> Harry Bishop wrote: >>> response.should redirect_to(@motion) > > What is this Motion? is it really something that you can redirect > people to? Maybe you meant redirect_to(url_for(@motion))? > >> private method `split' called for #. > > My guess is that this is rails / rspec-rails trying to make a URL out > of your Motion instance. These path method errors are often rather > unhelpful. Hi Matt, @motion is an instance of Motion which is the item being created here. I used a mock or a fixture and get different results. Once saved the redirect should take me back to the show action and render the motion object. I tried your suggestion of url_for(@motion) and received the error: undefined method `url_for' for # BTW - is there a way to turn off the six spec::rails::example tests? Harry -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Fri Oct 24 19:39:54 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Sat, 25 Oct 2008 01:39:54 +0200 Subject: [rspec-users] can't seem to test redirect? In-Reply-To: References: <8cc1570fba6f68545cc46365253576df@ruby-forum.com> <94a8769f38a0e3b8494c1428dc257e67@ruby-forum.com> Message-ID: Hi All, I got the redirect to work with: def do_post post :create, {:motion => do_motion_input("ten")} end it "creates new proposal with proposer set" do do_post response.should be_success end it "once motion is saved redirects to show motion" do @motion = motions(:ten) @motion.stub!(:new_record?).and_return(false) Motion.stub!(:new).and_return(@motion) @motion.stub!(:save).and_return(@motion) do_post response.should redirect_to("motions/10") end Seems I had a little wrong with each combination of lines I tried. Thanks Pat for the input about testing only one response. I stubbed out the last response I was trying to test. In my several hours of doing this I'm not sure whether something didn't get saved before a test but it isn't clear to me what the pattern should be. I found that using fixtures seems cleaner to me as far as getting the right input although I'm seeing that most users are relying on mocks. I tried mocks but it seems my tests are sensitive. Obviously I'm not yet getting it. Not sure why more people don't use fixtures. I used them in unit and functional tests and didn't have any problems there. Hopefully my productivity with rspec will improve from here. Thanks for your help, Harry -- Posted via http://www.ruby-forum.com/. From jachenry at gmail.com Fri Oct 24 22:45:21 2008 From: jachenry at gmail.com (jacobhenry) Date: Fri, 24 Oct 2008 19:45:21 -0700 (PDT) Subject: [rspec-users] using config.gem to freeze rspec (not #577) Message-ID: <20118125.post@talk.nabble.com> We have a project running on edge rails that has rspec and rspec-rails 1.1.9 frozen in vendor/gems. To freeze the gems we added two lines of code to environment.rb: config.gem 'rspec-rails', :lib => 'spec/rails', :version => '1.1.9' config.gem 'rspec', :lib => 'spec', :version => '1.1.9' and then ran: rake gems:install rake gems:unpack rake gems:unpack:dependencies rake gems:build The main goal is to freeze all common gems into the project so the production server can simply run 'rake gems:build' and not worry about installing anything. This method of deployment is causing me to receive the following error on my production machine whenever I run rake: rake aborted! no such file to load -- spec/rake/spectask /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' /Users/Jacob/git/scratchco_back/vendor/rails/activesupport/lib/active_support/dependencies.rb:148:in `require' /Users/Jacob/git/scratchco_back/vendor/rails/activesupport/lib/active_support/dependencies.rb:507:in `new_constants_in' /Users/Jacob/git/scratchco_back/vendor/rails/activesupport/lib/active_support/dependencies.rb:148:in `require' /Users/Jacob/git/scratchco_back/lib/tasks/rspec.rake:9 ... I can see that spectask.rb exists in vendor/gems/rspec-1.1.9/lib/spec/rake/. Running 'script/generate rspec' did not solve my problem. -- View this message in context: http://www.nabble.com/using-config.gem-to-freeze-rspec-%28not--577%29-tp20118125p20118125.html Sent from the rspec-users mailing list archive at Nabble.com. From luislavena at gmail.com Sat Oct 25 02:45:14 2008 From: luislavena at gmail.com (Luis Lavena) Date: Sat, 25 Oct 2008 03:45:14 -0300 Subject: [rspec-users] RSpec a DSL Message-ID: <71166b3b0810242345h494943bagb5541b9877feda6@mail.gmail.com> Hello Guys, I'm creating a small DSL that simplifies the creation of Rake tasks to handle multiple packages and their dependencies. (sorry David, tried Thor, do not do what I need). The thing is that basically I have several classes that "help" constructing the final Rake tasks, and also are not called directly but using some helpers in the middle. These tasks involves the creation, download, extraction, compilation and installation of several files and some hooks pre and post these actions. Since the goal is try to specify the behavior, I wonder if any of you guys succeed spec'ing your Rake actions and if so, what was your approach. Right now I'm using a fake "fixtures" folder where I put the different rake files for specs and adjust the "dumping" to a temporary folder that I use to verify the results. Maybe should I go with a feature/scenario design instead of low level specs? BTW: The DSL looks like this: http://gist.github.com/19707 Thanks in advance for any suggestions. 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 shot at hot.pl Sat Oct 25 03:08:12 2008 From: shot at hot.pl (Shot (Piotr Szotkowski)) Date: Sat, 25 Oct 2008 09:08:12 +0200 Subject: [rspec-users] =?utf-8?b?UlNwZWNpbmcgYSDigJhiaW5hcnnigJk=?= Message-ID: <20081025070812.GA15630@durance.shot.pl> Hello, good folk of rspec-users. I?m writing my first Ruby ?binary? (i.e., a script meant to be used as a standalone system command) and I?m wondering how to RSpec it. (Caveat: With all of my other code I almost alwyas do BDD, but as this was my first ?binary? and these were my first Trollop steps, I ended up writing the code first.) ?From inside?? This means turning most of the script into one (or few) callable method(s) and then testing them; the idea of accomodating the code to be easier to test seems to miss the point, though. ?From outside? (i.e., run it with Kernel#` and observe output and side-effects)? This feels more like behaviour testing, and I?m leaning towards it, but I have a gut feeling there might be another choice that I?m missing? -- Shot -- Exchange actually reports two different INTERNALDATEs for the exact same message when queried at different points in time. [...] Of course no OTHER imap server I've encountered returns DIFFERENT values for the SAME message. But it's Microsoft; what do you expect? If their programmers were any good they'd be working at Google. -- sup/imap.rb -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 191 bytes Desc: not available URL: From tom at experthuman.com Sat Oct 25 05:34:53 2008 From: tom at experthuman.com (Tom Stuart) Date: Sat, 25 Oct 2008 10:34:53 +0100 Subject: [rspec-users] Working outside-in with Cucumber and RSpec Message-ID: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> Hi, Going to dive into Cucumber soon, and just reading through all the docs now. Can anyone point to an example of writing Cucumber features first and then "when you get down to nitty gritty details, drop down one abstraction level and use RSpec to write some specs for your classes" (as per Cucumber wiki)? I'm trying to get a good feeling for the process of starting with a feature, dropping straight down to implementing code, and then somehow coming halfway back up and filling in the specs. Which levels of granularity are we talking about here? If you write a feature and then write enough code to make the feature pass, how do the specs still have traction to drive the design? Cheers, -Tom From matt at mattwynne.net Sat Oct 25 06:12:39 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 25 Oct 2008 11:12:39 +0100 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> Message-ID: <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> There are screencasts on peepcode and also Pat Maddox has done one, but I think they may be a bit out of date, and more focussed on just the mechanics of getting up and running with the old story runner rather than the workflow once you get going. Ben Mabey's blog[1] has some useful experiences to draw on. In answer to your question though, if this isn't too vague, I think this really sums it up: http://sirenian.livejournal.com/42871.html Start with a plain-text feature, then implement the steps behind it one by one. As you implement each step you'll find you need the system to do something. Maybe your step says "Given there is a User". Do you have a User class yet? Then you'd better make one. Each time you change the system itself (as opposed to the steps), drive out that change by writing rspec examples that fail because you haven't written the code yet. This is crucial: resist the urge to touch the code until you have a failing spec. You can then use the usual TDD cycle to change the classes that make up the system, then finally surface back up to the feature, run it, and see what you need to do next. The point of the cucumber features is not to exhaustively cover every single path in your code - that's the job of the specs (examples). The features give you a safety net to tell you that it all fits together. Does that make any more sense or have I just regurgetated Aslak's words from the Cucumber readme?! [1]http://www.benmabey.com/ On 25 Oct 2008, at 10:34, Tom Stuart wrote: > Hi, > > Going to dive into Cucumber soon, and just reading through all the > docs now. > > Can anyone point to an example of writing Cucumber features first > and then "when you get down to nitty gritty details, drop down one > abstraction level and use RSpec to write some specs for your > classes" (as per Cucumber wiki)? I'm trying to get a good feeling > for the process of starting with a feature, dropping straight down > to implementing code, and then somehow coming halfway back up and > filling in the specs. Which levels of granularity are we talking > about here? If you write a feature and then write enough code to > make the feature pass, how do the specs still have traction to drive > the design? > > Cheers, > -Tom > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ashley.moran at patchspace.co.uk Sat Oct 25 07:28:11 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sat, 25 Oct 2008 12:28:11 +0100 Subject: [rspec-users] =?windows-1252?q?RSpecing_a_=91binary=92?= In-Reply-To: <20081025070812.GA15630@durance.shot.pl> References: <20081025070812.GA15630@durance.shot.pl> Message-ID: <08AF7A3F-E489-4CB0-BD6A-FD90B53ED753@patchspace.co.uk> On Oct 25, 2008, at 8:08 am, Shot (Piotr Szotkowski) wrote: > ?From outside? (i.e., run it with Kernel#` and observe output and > side-effects)? This feels more like behaviour testing, and I?m leaning > towards it, but I have a gut feeling there might be another choice > that > I?m missing? Hi Shot When I've written command-line tools, I've done exactly this. Use Dir.tmpdir to give you a working space to hold any input/output files, and call it with Kernel#` to capture its STDOUT. Doing it this way proves your binary command works, because RSpec (or Cucumber, which may be more appropriate here) is doing nothing you can't do in a shell yourself. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Sat Oct 25 07:30:06 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sat, 25 Oct 2008 12:30:06 +0100 Subject: [rspec-users] Cucumber hoe dependency Message-ID: <7D38066D-D5EE-4B76-B65D-971C0EE182BB@patchspace.co.uk> Hi Am I right thinking that Cucumber needs hoe, but it's not an explicit gem dependency? If so, how come? Thanks Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From dchelimsky at gmail.com Sat Oct 25 09:06:04 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 25 Oct 2008 08:06:04 -0500 Subject: [rspec-users] using config.gem to freeze rspec (not #577) In-Reply-To: <20118125.post@talk.nabble.com> References: <20118125.post@talk.nabble.com> Message-ID: <57c63afe0810250606j78ec1442q57cbf8261ab53566@mail.gmail.com> On Fri, Oct 24, 2008 at 9:45 PM, jacobhenry wrote: > > We have a project running on edge rails that has rspec and rspec-rails 1.1.9 > frozen in vendor/gems. To freeze the gems we added two lines of code to > environment.rb: > > config.gem 'rspec-rails', :lib => 'spec/rails', :version => '1.1.9' > config.gem 'rspec', :lib => 'spec', :version => '1.1.9' First - there were some problems with 1.1.9 gems that have been mostly addressed in 1.1.11, so please upgrade to 1.1.11. Second, there is still one open issue with 1.1.11 gems, which is that if you configure both rspec and rspec-rails gems, in that order (rspec first), you'll have problems with rake tasks. To workaround that you can either configure them in the order you have them (rspec-rails, then rspec), or you can just configure rspec-rails, which has a hard dependency on rspec so rspec will also get installed w/ rake gems:install (unless you're on an older version of rubygems - I forget which one started installing deps by default, but that definitely happens w/ >= 1.2). HTH, David > > and then ran: > > rake gems:install > rake gems:unpack > rake gems:unpack:dependencies > rake gems:build > > The main goal is to freeze all common gems into the project so the > production server can simply run 'rake gems:build' and not worry about > installing anything. This method of deployment is causing me to receive the > following error on my production machine whenever I run rake: > > rake aborted! > no such file to load -- spec/rake/spectask > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `gem_original_require' > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' > /Users/Jacob/git/scratchco_back/vendor/rails/activesupport/lib/active_support/dependencies.rb:148:in > `require' > /Users/Jacob/git/scratchco_back/vendor/rails/activesupport/lib/active_support/dependencies.rb:507:in > `new_constants_in' > /Users/Jacob/git/scratchco_back/vendor/rails/activesupport/lib/active_support/dependencies.rb:148:in > `require' > /Users/Jacob/git/scratchco_back/lib/tasks/rspec.rake:9 > ... > > I can see that spectask.rb exists in vendor/gems/rspec-1.1.9/lib/spec/rake/. > Running 'script/generate rspec' did not solve my problem. > -- > View this message in context: http://www.nabble.com/using-config.gem-to-freeze-rspec-%28not--577%29-tp20118125p20118125.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 dchelimsky at gmail.com Sat Oct 25 09:14:37 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 25 Oct 2008 08:14:37 -0500 Subject: [rspec-users] RSpec a DSL In-Reply-To: <71166b3b0810242345h494943bagb5541b9877feda6@mail.gmail.com> References: <71166b3b0810242345h494943bagb5541b9877feda6@mail.gmail.com> Message-ID: <57c63afe0810250614o73fe6b35p3b9343cf64ec4bbc@mail.gmail.com> On Sat, Oct 25, 2008 at 1:45 AM, Luis Lavena wrote: > Hello Guys, > > I'm creating a small DSL that simplifies the creation of Rake tasks to > handle multiple packages and their dependencies. > (sorry David, tried Thor, do not do what I need). > > The thing is that basically I have several classes that "help" > constructing the final Rake tasks, and also are not called directly > but using some helpers in the middle. > > These tasks involves the creation, download, extraction, compilation > and installation of several files and some hooks pre and post these > actions. > > Since the goal is try to specify the behavior, I wonder if any of you > guys succeed spec'ing your Rake actions and if so, what was your > approach. Right now I'm using a fake "fixtures" folder where I put the > different rake files for specs and adjust the "dumping" to a temporary > folder that I use to verify the results. > > Maybe should I go with a feature/scenario design instead of low level specs? I'd start with that anyhow, using cucumber. Then crack open rspec when you have some details that you want to drive in a more granular way (probably influencing your design in the process). Last year I heard Martin Fowler speak about DSLs and one thing he said that really stuck with me (largely because it's been a pain point w/ RSpec) is that you should make a clean separation between the DSL and the underlying framework. I don't know what that looks like yet, but I can imagine that you'd end up with a bunch of cucumber scenarios for the DSL and then rspec code examples for the underlying framework. Please report back on your progress. Cheers, David > > BTW: The DSL looks like this: > > http://gist.github.com/19707 > > Thanks in advance for any suggestions. > > 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 > From dchelimsky at gmail.com Sat Oct 25 09:33:14 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 25 Oct 2008 08:33:14 -0500 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> Message-ID: <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> On Sat, Oct 25, 2008 at 5:12 AM, Matt Wynne wrote: > There are screencasts on peepcode and also Pat Maddox has done one, but I > think they may be a bit out of date, and more focussed on just the mechanics > of getting up and running with the old story runner rather than the workflow > once you get going. > > Ben Mabey's blog[1] has some useful experiences to draw on. > > In answer to your question though, if this isn't too vague, I think this > really sums it up: > http://sirenian.livejournal.com/42871.html > > Start with a plain-text feature, then implement the steps behind it one by > one. As you implement each step you'll find you need the system to do > something. Maybe your step says "Given there is a User". Do you have a User > class yet? Then you'd better make one. Each time you change the system > itself (as opposed to the steps), drive out that change by writing rspec > examples that fail because you haven't written the code yet. This is > crucial: resist the urge to touch the code until you have a failing spec. At the risk of creating controversy, confusion, etc, I've been playing with the boundaries of this notion of "resisting the urge to touch the code until you have a failing spec." This really needs a blog post, so I'll try and drum one up, but the short version is this: In the past I've been very disciplined about following this rule, as it is something that I learned back in my FitNesse/JUnit days. The thing is, those two tools are completely decoupled. The FitNesse tests (which map to cucumber in our ruby/bdd land) could be changed at any time by any number of non-developer folks. They were also stored outside of the SCM repo that the code was in. So there was a risk to manage, which was that if somebody deleted or changed a FitNesse test, there could be a coverage problem at the code level, therefore high coverage from JUnit was essential. These days I work on scenarios w/ customers, but they are ultimately checked in directly with the rest of the code and run before a push (I'm doing a lot of solo dev right now, so I'm not using CI since I'm essentially integrating with every change I make :) ). Since it's all part of the same code base, I don't feel the need to create a code example for User just to bring a User into existence. Using webrat within cucumber scenarios for a rails app largely eliminates the need for view specs as well. The combination of these tools usually provides excellent feedback and, in my view, sufficient fault isolation, when something falls apart in a view. Of course, as soon as an object has to do something interesting (other than mere existence), I'll usually drop down to rspec. I don't have a "rule" for when to do this. I'm just going by feel, and so far have not been bitten by this approach. And once we have a disconnected in-browser editor for scenarios, I'm sure I'll go back to being more disciplined about starting from a code example in rspec. But in the mean time, cucumber steps ARE code examples, and as long as they live closely bound to the code (in the same SCM repo), I think it's OK to consider them your starting point (example first) and not require an rspec code example just to bring an object into existence. And *that* was the short version :) FWIW, David > You can then use the usual TDD cycle to change the classes that make up the > system, then finally surface back up to the feature, run it, and see what > you need to do next. > > The point of the cucumber features is not to exhaustively cover every single > path in your code - that's the job of the specs (examples). The features > give you a safety net to tell you that it all fits together. > > Does that make any more sense or have I just regurgetated Aslak's words from > the Cucumber readme?! > > [1]http://www.benmabey.com/ > > On 25 Oct 2008, at 10:34, Tom Stuart wrote: > >> Hi, >> >> Going to dive into Cucumber soon, and just reading through all the docs >> now. >> >> Can anyone point to an example of writing Cucumber features first and then >> "when you get down to nitty gritty details, drop down one abstraction level >> and use RSpec to write some specs for your classes" (as per Cucumber wiki)? >> I'm trying to get a good feeling for the process of starting with a feature, >> dropping straight down to implementing code, and then somehow coming halfway >> back up and filling in the specs. Which levels of granularity are we talking >> about here? If you write a feature and then write enough code to make the >> feature pass, how do the specs still have traction to drive the design? >> >> Cheers, >> -Tom >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sat Oct 25 09:36:04 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 25 Oct 2008 08:36:04 -0500 Subject: [rspec-users] Cucumber hoe dependency In-Reply-To: <7D38066D-D5EE-4B76-B65D-971C0EE182BB@patchspace.co.uk> References: <7D38066D-D5EE-4B76-B65D-971C0EE182BB@patchspace.co.uk> Message-ID: <57c63afe0810250636x2bf17ec4oe1602b2bb58f0dfa@mail.gmail.com> On Sat, Oct 25, 2008 at 6:30 AM, Ashley Moran wrote: > Hi > > Am I right thinking that Cucumber needs hoe, but it's not an explicit gem > dependency? If so, how come? It only needs hoe if you're developing/extending cucumber itself. If you're just using it, you don't need hoe. It should probably be listed as a developer dep for rubygems >= 1.2. > > Thanks > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt at mattwynne.net Sat Oct 25 10:12:27 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sat, 25 Oct 2008 15:12:27 +0100 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> Message-ID: <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> On 25 Oct 2008, at 14:33, David Chelimsky wrote: > On Sat, Oct 25, 2008 at 5:12 AM, Matt Wynne > wrote: >> examples that fail because you haven't written the code yet. This is >> crucial: resist the urge to touch the code until you have a failing >> spec. > > At the risk of creating controversy, confusion, etc, I've been playing > with the boundaries of this notion of "resisting the urge to touch the > code until you have a failing spec." Crazy talk! Somebody kick this heretic off the list! ;) I actually know what you mean, and found myself this week driving out what I'd initially intended as a spike from a cucumber scenario, using rspec examples to shape it later. I think what you're talking about is a pretty 'ri' technique[1] though - I strongly believe you need to have experienced full-blown disciplined 100% TDD before you could honestly and responsibly know when to pull back like you're describing. [1]http://en.wikipedia.org/wiki/Shuhari cheers, Matt From aslak.hellesoy at gmail.com Sat Oct 25 10:54:17 2008 From: aslak.hellesoy at gmail.com (=?UTF-8?Q?Aslak_Helles=C3=B8y?=) Date: Sat, 25 Oct 2008 16:54:17 +0200 Subject: [rspec-users] Cucumber hoe dependency In-Reply-To: <7D38066D-D5EE-4B76-B65D-971C0EE182BB@patchspace.co.uk> References: <7D38066D-D5EE-4B76-B65D-971C0EE182BB@patchspace.co.uk> Message-ID: <013918FE-BCC1-4D17-BF10-69EB6A1831BD@gmail.com> On 25. okt.. 2008, at 13.30, Ashley Moran wrote: > Hi > > Am I right thinking that Cucumber needs hoe, but it's not an > explicit gem dependency? If so, how come? > You need hoe to develop on Cucumber, but not to use it. > Thanks > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From dchelimsky at gmail.com Sat Oct 25 13:19:24 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sat, 25 Oct 2008 12:19:24 -0500 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> Message-ID: <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> On Sat, Oct 25, 2008 at 9:12 AM, Matt Wynne wrote: > On 25 Oct 2008, at 14:33, David Chelimsky wrote: > >> On Sat, Oct 25, 2008 at 5:12 AM, Matt Wynne wrote: >>> >>> examples that fail because you haven't written the code yet. This is >>> crucial: resist the urge to touch the code until you have a failing spec. >> >> At the risk of creating controversy, confusion, etc, I've been playing >> with the boundaries of this notion of "resisting the urge to touch the >> code until you have a failing spec." > > Crazy talk! Somebody kick this heretic off the list! > > ;) > > I actually know what you mean, and found myself this week driving out what > I'd initially intended as a spike from a cucumber scenario, using rspec > examples to shape it later. I think what you're talking about is a pretty > 'ri' technique[1] though - I strongly believe you need to have experienced > full-blown disciplined 100% TDD before you could honestly and responsibly > know when to pull back like you're describing. Excellent point. That's actually something Kent Beck talks about in TDD by Example - it is important to first develop the discipline and skill to do TDD in very, very small steps before you start taking bigger steps. That way, when you do push the envelope too far (and you *will*), you can easily back up a step and work your way through the problem with a more granular approach. > > [1]http://en.wikipedia.org/wiki/Shuhari > > cheers, > Matt > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Sat Oct 25 13:44:03 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sat, 25 Oct 2008 18:44:03 +0100 Subject: [rspec-users] Cucumber hoe dependency In-Reply-To: <013918FE-BCC1-4D17-BF10-69EB6A1831BD@gmail.com> References: <7D38066D-D5EE-4B76-B65D-971C0EE182BB@patchspace.co.uk> <013918FE-BCC1-4D17-BF10-69EB6A1831BD@gmail.com> Message-ID: <9B080BA6-1C3B-4639-99EE-F5CDF128FD11@patchspace.co.uk> On Oct 25, 2008, at 3:54 pm, Aslak Helles?y wrote: > You need hoe to develop on Cucumber, but not to use it. Ah ok. I've had Cucumber complain about hoe been missing when I was just using it like a normal user. Not sure what I was doing now, I just installed hoe and carried on... Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Sat Oct 25 14:24:44 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sat, 25 Oct 2008 19:24:44 +0100 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> Message-ID: <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> On Oct 25, 2008, at 6:19 pm, David Chelimsky wrote: >> I actually know what you mean, and found myself this week driving >> out what >> I'd initially intended as a spike from a cucumber scenario, using >> rspec >> examples to shape it later. I think what you're talking about is a >> pretty >> 'ri' technique[1] though - I strongly believe you need to have >> experienced >> full-blown disciplined 100% TDD before you could honestly and >> responsibly >> know when to pull back like you're describing. > > Excellent point. That's actually something Kent Beck talks about in > TDD by Example - it is important to first develop the discipline and > skill to do TDD in very, very small steps before you start taking > bigger steps. That way, when you do push the envelope too far (and you > *will*), you can easily back up a step and work your way through the > problem with a more granular approach. I started this week doing BDD training with someone I've worked with for a while. We held off on the BDD because we knew we had a greenfield project round the corner. Cucumber was fine. It takes minutes to knock up a feature file and steps. But the next thing we hit was the controller (in Merb, which adds a bit of overhead while it's new). This was AGONISINGLY painful. And, pretty much every time I teach BDD (especially in a web environment) is the same: the time from me explaining things and writing some code myself to having a lightbulb come on so they can write the same code themself is at least one order of magnitude longer than it would take to write that code (or generate it...) with no specs. This means the first impression I give of BDD is that it's frustrating and slow. Clearly since I'm the common factor in these situations, it's my fault it goes wrong... Anyway this thread made me think of ways round this problem, and I wondered if anyone had feedback on them. * Become a superhumanly good programmer and learn every feature of ever framework Ok, this is a non-starter :) * Use canned code This could reduce some typing, but not much, seeing how little you have to write with the RSpec TextMate bundle. And writing more than strictly necessary is a bad demo of incremental BDD. * Start with pure-Ruby code I've done this before, and it makes it much quicker to that important keyboard handover. But unfortunately it eats into time that could be spent "building value". There are two situations where this is bad: companies where the reaction is "why are you learning when you could be coding???", and companies that have no, or even negative, slack time. * Skip the controller specs. Eeek, more heresy! Can you tell it's Hallowe'en soon? But... you can't break a controller without breaking a Cucumber file, that would be an Epic Fail at the feature level. And the controllers shouldn't be doing more than deciding what response to return, so they should always be covered fully by Cucumber. Matt - as it happens, I used a tai chi analogue of Shuhari, "no shape, no form", yesterday when I mentioned this to said victim^H^H^H^H^H^H client. That is, when you have mastered drills, you apply them how you need them, not in the way they were practised. But I'm scared that this will give the wrong impression. If I say we're going to skip controller specs because they don't add enough value, how do I know that won't be interpreted as "controller specs are too hard, don't write specs when it's hard"? I know the person I'm working with, and I know he will understand what I'm saying. But it's still sending the wrong message. Any words of wisdom will be much appreciated... Thanks Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From aslak.hellesoy at gmail.com Sat Oct 25 14:48:22 2008 From: aslak.hellesoy at gmail.com (=?UTF-8?Q?Aslak_Helles=C3=B8y?=) Date: Sat, 25 Oct 2008 20:48:22 +0200 Subject: [rspec-users] Cucumber hoe dependency In-Reply-To: <9B080BA6-1C3B-4639-99EE-F5CDF128FD11@patchspace.co.uk> References: <7D38066D-D5EE-4B76-B65D-971C0EE182BB@patchspace.co.uk> <013918FE-BCC1-4D17-BF10-69EB6A1831BD@gmail.com> <9B080BA6-1C3B-4639-99EE-F5CDF128FD11@patchspace.co.uk> Message-ID: <4D4C1ED3-5F94-466D-9961-1C70F731D83C@gmail.com> On 25. okt.. 2008, at 19.44, Ashley Moran wrote: > > On Oct 25, 2008, at 3:54 pm, Aslak Helles?y wrote: > >> You need hoe to develop on Cucumber, but not to use it. > > Ah ok. I've had Cucumber complain about hoe been missing when I was > just using it like a normal user. Not sure what I was doing now, I > just installed hoe and carried on... > That means you have discovered a bug. Or maybe some other gem needs it. > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From ashley.moran at patchspace.co.uk Sat Oct 25 15:07:16 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sat, 25 Oct 2008 20:07:16 +0100 Subject: [rspec-users] Cucumber hoe dependency In-Reply-To: <4D4C1ED3-5F94-466D-9961-1C70F731D83C@gmail.com> References: <7D38066D-D5EE-4B76-B65D-971C0EE182BB@patchspace.co.uk> <013918FE-BCC1-4D17-BF10-69EB6A1831BD@gmail.com> <9B080BA6-1C3B-4639-99EE-F5CDF128FD11@patchspace.co.uk> <4D4C1ED3-5F94-466D-9961-1C70F731D83C@gmail.com> Message-ID: <90764576-193F-4B21-96EF-30BFA6B9F6F1@patchspace.co.uk> On Oct 25, 2008, at 7:48 pm, Aslak Helles?y wrote: > That means you have discovered a bug. Or maybe some other gem needs > it. Sometime soon I'll dig hoe out of my system (ho, ho*), and see if it still complains... Ashley * oh dear, infinitely recursive joke, and a really bad one too -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From pergesu at gmail.com Sat Oct 25 17:37:25 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 25 Oct 2008 14:37:25 -0700 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> (Ashley Moran's message of "Sat\, 25 Oct 2008 19\:24\:44 +0100") References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> Message-ID: > If I say we're going to > skip controller specs because they don't add enough value, how do I > know that won't be interpreted as "controller specs are too hard, > don't write specs when it's hard"? I have a three-headed defense of rarely writing controller specs anymore: * Controllers are already exercised by cucumber * Most of the logic is provided by the framework. * Controllers tend to be procedural instead of OO The first one should be obvious. As for the second, since I'm not actually writing most of the code, I'm not that worried about it breaking. Procedural code is no fun to test. You have to use a lot of mocks, and your example looks more or less the same as the production code. Blech. Rails controllers don't encapsulate state or iteration, the only encapsulation-worthy behavior usually is a simple if statement. Controllers also typically aren't very cohesive, you're never going to call more than one method on them. Put simply, controllers, as used in Rails, are a collection of transaction scripts grouped together by the resource on which they operate. Now, when I don't write cucumber features, I absolutely do write controller specs. But I'll have those hit the db, with integrate_views turned on, acting essentially as an integration test. The thing is, there isn't a lot of value in writing both features and controller specs, unless your controllers have some pretty complex logic (which they shouldn't when using Rails!) So I guess that were I to be teaching someone this stuff, I would explain the benefits of testing, and evaluate how controller specs add value. Specifically, they don't add regression value over features, and they provide marginal design value, particularly if you follow typical Rails controller patterns. I would explain that I don't see much benefit to the controller specs, and that they're kinda tough to test because they're not very OO. And I'd use that as an opportunity to notice smells - when you're writing specs and it's difficult, and you control all the code, then your code could probably use some design improvements. But yeah, I like working outside-in :) Pat From mark.thomson at ieee.org Sat Oct 25 18:25:59 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Sat, 25 Oct 2008 17:25:59 -0500 Subject: [rspec-users] cucumber feature description Message-ID: <49039CF7.2040307@ieee.org> In the old Story Runner framework the feature description had a preamble that looked like As a... I want... So that... When I was moving to cucumber I seem to remember reading somewhere that that formulation was being changed, and indeed the example here - http://github.com/aslakhellesoy/cucumber/tree/master/examples/calculator/features/addition.feature , looks like this - In order to... As a... I want to... However I can't find specific documentation that spells that out. The discussion about migrating from stories here - http://github.com/aslakhellesoy/cucumber/wikis/migration-from-rspec-stories doesn't say anything about it and I've also written features successfully using the original formulation. So I'm just curious about what the significance of the preamble is. Is it purely an aid to help the writer think correctly about what they are supposed to be describing? Does it make any real difference how it is formulated or whether it's even present? Mark. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sfeley at gmail.com Sat Oct 25 18:47:45 2008 From: sfeley at gmail.com (Stephen Eley) Date: Sat, 25 Oct 2008 18:47:45 -0400 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> Message-ID: <1fb4df0810251547y4742033dtd6b5764de71e93d6@mail.gmail.com> On Sat, Oct 25, 2008 at 10:12 AM, Matt Wynne wrote: > > [ . . . ] I think what you're talking about is a pretty > 'ri' technique[1] though - I strongly believe you need to have experienced > full-blown disciplined 100% TDD before you could honestly and responsibly > know when to pull back like you're describing. > > [1]http://en.wikipedia.org/wiki/Shuhari Thank you for posting this link. That's one of the most valuable things I've read all week. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From ben at benmabey.com Sat Oct 25 19:19:50 2008 From: ben at benmabey.com (Ben Mabey) Date: Sat, 25 Oct 2008 17:19:50 -0600 Subject: [rspec-users] cucumber feature description In-Reply-To: <49039CF7.2040307@ieee.org> References: <49039CF7.2040307@ieee.org> Message-ID: <4903A996.2040903@benmabey.com> Mark Thomson wrote: > In the old Story Runner framework the feature description had a > preamble that looked like > > As a... > I want... > So that... > > When I was moving to cucumber I seem to remember reading somewhere > that that formulation was being changed, and indeed the example here - > > http://github.com/aslakhellesoy/cucumber/tree/master/examples/calculator/features/addition.feature > , > > looks like this - > > In order to... > As a... > I want to... > > However I can't find specific documentation that spells that out. The > discussion about migrating from stories here - > > http://github.com/aslakhellesoy/cucumber/wikis/migration-from-rspec-stories > > doesn't say anything about it and I've also written features > successfully using the original formulation. > > So I'm just curious about what the significance of the preamble is. Is > it purely an aid to help the writer think correctly about what they > are supposed to be describing? Does it make any real difference how it > is formulated or whether it's even present? > > Mark. > The preamble or narrative doest not effect the actual running of the feature but like you said, it acts as an aid to answer upfront the most important question about this feature - why am I implementing it? Or in other words, what is the business value that this feature will fulfill? Along with the business value being listed having the role in the narrative is also very helpful as it places the all of the scenarios in the right context. A more qualified person may want to answer your question, but my short explanation of the change of the default narrative layout is to state the business value at the start instead of the end. However, you shouldn't feel constrained to use that layout all the time though. Whatever communicates the business value best and most succinctly to the customer and you for a given feature is what you should use. HTH, Ben From mark.thomson at ieee.org Sat Oct 25 22:58:52 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Sat, 25 Oct 2008 21:58:52 -0500 Subject: [rspec-users] cucumber feature description In-Reply-To: <4903A996.2040903@benmabey.com> References: <49039CF7.2040307@ieee.org> <4903A996.2040903@benmabey.com> Message-ID: <4903DCEC.9020402@ieee.org> Thanks much. Mark. Ben Mabey wrote: > > The preamble or narrative doest not effect the actual running of the > feature but like you said, it acts as an aid to answer upfront the > most important question about this feature - why am I implementing > it? Or in other words, what is the business value that this feature > will fulfill? Along with the business value being listed having the > role in the narrative is also very helpful as it places the all of the > scenarios in the right context. > > A more qualified person may want to answer your question, but my short > explanation of the change of the default narrative layout is to state > the business value at the start instead of the end. However, you > shouldn't feel constrained to use that layout all the time though. > Whatever communicates the business value best and most succinctly to > the customer and you for a given feature is what you should use. > > HTH, > Ben > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > From pergesu at gmail.com Sat Oct 25 23:03:29 2008 From: pergesu at gmail.com (Pat Maddox) Date: Sat, 25 Oct 2008 20:03:29 -0700 Subject: [rspec-users] cucumber feature description In-Reply-To: <4903A996.2040903@benmabey.com> References: <49039CF7.2040307@ieee.org> <4903A996.2040903@benmabey.com> Message-ID: <810a540e0810252003t53cc6504ocb932148d374a649@mail.gmail.com> > A more qualified person may want to answer your question I think you are plenty qualified :) > but my short > explanation of the change of the default narrative layout is to state the > business value at the start instead of the end. Exactly what I was gonna say. > However, you shouldn't feel > constrained to use that layout all the time though. Whatever communicates > the business value best and most succinctly to the customer and you for a > given feature is what you should use. Right on. And I'd say that the preamble is so valuable that trying to give it a rigid syntactic structure could only detract value, not add it. Pat From ben at benmabey.com Sat Oct 25 19:03:17 2008 From: ben at benmabey.com (Ben Mabey) Date: Sat, 25 Oct 2008 17:03:17 -0600 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> Message-ID: <4903A5B5.9030700@benmabey.com> Pat Maddox wrote: >> If I say we're going to >> skip controller specs because they don't add enough value, how do I >> know that won't be interpreted as "controller specs are too hard, >> don't write specs when it's hard"? >> > > I have a three-headed defense of rarely writing controller specs > anymore: > > * Controllers are already exercised by cucumber > * Most of the logic is provided by the framework. > * Controllers tend to be procedural instead of OO > > The first one should be obvious. As for the second, since I'm not > actually writing most of the code, I'm not that worried about it > breaking. > > Procedural code is no fun to test. You have to use a lot of mocks, and > your example looks more or less the same as the production code. Blech. > Rails controllers don't encapsulate state or iteration, the only > encapsulation-worthy behavior usually is a simple if statement. > Controllers also typically aren't very cohesive, you're never going to > call more than one method on them. Put simply, controllers, as used in > Rails, are a collection of transaction scripts grouped together by the > resource on which they operate. > > Now, when I don't write cucumber features, I absolutely do write > controller specs. But I'll have those hit the db, with integrate_views > turned on, acting essentially as an integration test. The thing is, > there isn't a lot of value in writing both features and controller > specs, unless your controllers have some pretty complex logic (which > they shouldn't when using Rails!) > > So I guess that were I to be teaching someone this stuff, I would > explain the benefits of testing, and evaluate how controller specs add > value. Specifically, they don't add regression value over features, and > they provide marginal design value, particularly if you follow typical > Rails controller patterns. I would explain that I don't see much > benefit to the controller specs, and that they're kinda tough to test > because they're not very OO. And I'd use that as an opportunity to > notice smells - when you're writing specs and it's difficult, and you > control all the code, then your code could probably use some design > improvements. > > But yeah, I like working outside-in :) > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > I agree with most of this. For a purely RESTful controller I like to use a plugin, like make_resourceful, that will take care of all the boilerplate code that becomes very tedious to spec out and write. Since the plugins are tested I can just rely that coverage alongside my scenarios going through the full stack. However, once I need to go out of the ordinary RESTful controller I usually always still write specs for those actions using mocks. My two reasons for doing this is a) allow for interface discovery with mocks and b) to prevent logic from seeping into the controllers. Writing code examples for controllers in a purely interaction-based way can be laborious and it becomes extremely painful if you put actual business logic in them. I think that pain is a good thing because it reminds less experienced people on your team (and more experienced people too sometimes :) ) that controllers shouldn't get too big and that they should be pushing the responsibility into other objects (be that AR or regular ruby objects.) So while I agree completely that controller specs don't offer regression value over scenarios I do place more value on the design aspect I think they provide. In the past I have been able to detect feature envy and a number of other code smells within my controllers via my controller examples that I don't think I would of noticed and/or been motivated enough to refactor them into the right level. Again, I can totally understand your point of view and even agree with it. I think if a team is experienced and disciplined enough then writing controller specs could be skipped... just keep a look out for "broken windows" or else the whole controller neighborhood will start seeping tiny facets of business logic. :) Oh, and to an earlier point in this thread.. I can't remember the last time I wrote a view spec. Any semi-interesting logic that for some reason needs to be in the view I will place in a helper and then spec that out. +1 on working outside-in. :) -Ben From ashley.moran at patchspace.co.uk Sun Oct 26 06:11:56 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 26 Oct 2008 10:11:56 +0000 Subject: [rspec-users] cucumber feature description In-Reply-To: <4903A996.2040903@benmabey.com> References: <49039CF7.2040307@ieee.org> <4903A996.2040903@benmabey.com> Message-ID: <21951C7B-8215-48FB-B911-1B145B87482E@patchspace.co.uk> On Oct 26, 2008, at 12:19 am, Ben Mabey wrote: > A more qualified person may want to answer your question, but my > short explanation of the change of the default narrative layout is > to state the business value at the start instead of the end. I do this, and updated my TextMate Cucumber fea to this: Feature: ${1:title} So that ${2:value} As a ${3:role} I want ${4:feature} $0 for this very reason. Putting the business value first, and not writing anything else until you've found it, means you don't get to cheat and dump "it would be nice" features into the flow, then gloss over the fact they're completely useless. Found I wrote one of these myself last week, when I wrote the "I want" bit on a card 5 mins before we went home. Took half an hour this week to realise it does nothing useful (or at least, needs doing in a completely different way). But the fact I'd written it down somehow ennobled it. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Sun Oct 26 06:39:12 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 26 Oct 2008 10:39:12 +0000 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <4903A5B5.9030700@benmabey.com> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> Message-ID: <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> On Oct 26, 2008, at 12:03 am, Ben Mabey wrote: > I agree with most of this. For a purely RESTful controller I like > to use a plugin, like make_resourceful, that will take care of all > the boilerplate code that becomes very tedious to spec out and > write. Since the plugins are tested I can just rely that coverage > alongside my scenarios going through the full stack. However, once > I need to go out of the ordinary RESTful controller I usually always > still write specs for those actions using mocks. My two reasons for > doing this is a) allow for interface discovery with mocks and b) to > prevent logic from seeping into the controllers. Writing code > examples for controllers in a purely interaction-based way can be > laborious and it becomes extremely painful if you put actual > business logic in them. I think that pain is a good thing because > it reminds less experienced people on your team (and more > experienced people too sometimes :) ) that controllers shouldn't get > too big and that they should be pushing the responsibility into > other objects (be that AR or regular ruby objects.) > So while I agree completely that controller specs don't offer > regression value over scenarios I do place more value on the design > aspect I think they provide. In the past I have been able to detect > feature envy and a number of other code smells within my controllers > via my controller examples that I don't think I would of noticed and/ > or been motivated enough to refactor them into the right level. > Again, I can totally understand your point of view and even agree > with it. I think if a team is experienced and disciplined enough > then writing controller specs could be skipped... just keep a look > out for "broken windows" or else the whole controller neighborhood > will start seeping tiny facets of business logic. :) Hmm, after hearing both sides of the argument, I'm inclined to keep writing controller specs, but to gloss over them in their basic CRUD form. They add so little value initially, they are a terrible pedagogical example. Models are much more fun anyway :) Pat's breakdown, > * Controllers are already exercised by cucumber > * Most of the logic is provided by the framework. > * Controllers tend to be procedural instead of OO is useful. The last two make me think that the controller code you write should really look like: class Items < Application # ... def show Show.new(self, content_type, params).render end # ... class Show def initalize(controller, content_type, params) @controller = controller @content_type = content_type @id = id end def render @item = Item.get(params[:id]) raise NotFound unless @item controller.display @item end end end Forgive the unrunnable botched code example :) Has issues with assigning instance variables to the controller, and not sure what you'd do about the content type (but you could handle it in a much more OO way. In fact, if the controller strategy was changed, you could have the show method just return a class: def show Show end or even do it by convention (look for Items::Show). This way, you get an isolated bit of code you can spec, without worrying about all the magic that gets bundled in. Hmmm, anyway, should get back to writing real code... but I'm going to keep this at the back of my mind. So anyway, controller specs it is, just de-emphasised when I'm teaching BDD. Thanks people. > Oh, and to an earlier point in this thread.. I can't remember the > last time I wrote a view spec. Any semi-interesting logic that for > some reason needs to be in the view I will place in a helper and > then spec that out. +1 I found a long time ago they don't add enough value to justify the effort in maintaining them. Most of the things you write view specs for aren't likely to break due to human error, but are often need changing due to inconsequential HTML changes. Cheers Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From dchelimsky at gmail.com Sun Oct 26 08:16:41 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 26 Oct 2008 07:16:41 -0500 Subject: [rspec-users] cucumber feature description In-Reply-To: <21951C7B-8215-48FB-B911-1B145B87482E@patchspace.co.uk> References: <49039CF7.2040307@ieee.org> <4903A996.2040903@benmabey.com> <21951C7B-8215-48FB-B911-1B145B87482E@patchspace.co.uk> Message-ID: <57c63afe0810260516i3d27fd6g60abfaa994830aee@mail.gmail.com> On Sun, Oct 26, 2008 at 5:11 AM, Ashley Moran wrote: > > On Oct 26, 2008, at 12:19 am, Ben Mabey wrote: > >> A more qualified person may want to answer your question, but my short >> explanation of the change of the default narrative layout is to state the >> business value at the start instead of the end. > > > I do this, and updated my TextMate Cucumber fea to this: > > Feature: ${1:title} > So that ${2:value} > As a ${3:role} > I want ${4:feature} > > $0 > > for this very reason. > > Putting the business value first, and not writing anything else until you've > found it, means you don't get to cheat and dump "it would be nice" features > into the flow, then gloss over the fact they're completely useless. Found I > wrote one of these myself last week, when I wrote the "I want" bit on a card > 5 mins before we went home. Took half an hour this week to realise it does > nothing useful (or at least, needs doing in a completely different way). > But the fact I'd written it down somehow ennobled it. Recommended reading: http://lizkeogh.com/2008/09/10/feature-injection-and-handling-technical-stories/ Cheers, David > > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Sun Oct 26 08:49:58 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 26 Oct 2008 07:49:58 -0500 Subject: [rspec-users] Correct way to spec partials In-Reply-To: <6e9d2bb40810231807p48485868td431255bb387ac7f@mail.gmail.com> References: <6e9d2bb40810231807p48485868td431255bb387ac7f@mail.gmail.com> Message-ID: <57c63afe0810260549i2d6f49c0o6e195fe65c1d2a9b@mail.gmail.com> On Thu, Oct 23, 2008 at 8:07 PM, Oleksandr Rudyk wrote: > Hi everybody, > 1) Does anybody have full working example of how to test partial templates? > 2) What the correct place to test partials: controller or view spec? If > controller correct place, > should I use integrate_views? There are basically three options (from most granular to most coarse): 1. view examples rendering the partial directly 2. view examples rendering a template that includes the partial 3. controller examples with integrate_views In practice, I don't think I ever go for #3, and the choice between #1 and #2 is largely context-dependent. In the end you want to (or rather, I want you to ;) ) be equally comfortable with all three approaches, understand the pros and cons of each, and make a decision on a case by case basis. > 3) Is it true that expect_render is deprecated and I have to > use should_receive(:render) Yes! > 4) How to test that partial's locals hash is correct? Do you mean that the partial gets the right hash? If so, that's something you would expect from the including template: describe "people/edit" do it "should render the _form partial" do assigns[:groups] = mock('groups') template.should_receive(:render).with(:partial => "form", :locals => { :groups => assigns[:groups] } render "people/edit" end end HTH, David > Thx > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sfeley at gmail.com Sun Oct 26 10:56:44 2008 From: sfeley at gmail.com (Stephen Eley) Date: Sun, 26 Oct 2008 10:56:44 -0400 Subject: [rspec-users] cucumber feature description In-Reply-To: <4903A996.2040903@benmabey.com> References: <49039CF7.2040307@ieee.org> <4903A996.2040903@benmabey.com> Message-ID: <1fb4df0810260756r3dd26c6bje14972cd8d793c46@mail.gmail.com> On Sat, Oct 25, 2008 at 7:19 PM, Ben Mabey wrote: > > A more qualified person may want to answer your question, but my short > explanation of the change of the default narrative layout is to state the > business value at the start instead of the end. However, you shouldn't feel > constrained to use that layout all the time though. I prefer (and still use) the old way for grammatical reasons. Putting the dependent clause of a sentence ahead of the independent clause that it's dependent is awkward and distracts from the reading. If enough of this we do, talk like Yoda, we all will. Wish that, I do not. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From sfeley at gmail.com Sun Oct 26 10:59:21 2008 From: sfeley at gmail.com (Stephen Eley) Date: Sun, 26 Oct 2008 10:59:21 -0400 Subject: [rspec-users] cucumber feature description In-Reply-To: <1fb4df0810260756r3dd26c6bje14972cd8d793c46@mail.gmail.com> References: <49039CF7.2040307@ieee.org> <4903A996.2040903@benmabey.com> <1fb4df0810260756r3dd26c6bje14972cd8d793c46@mail.gmail.com> Message-ID: <1fb4df0810260759i52df2f70g32bf659ceedd080f@mail.gmail.com> On Sun, Oct 26, 2008 at 10:56 AM, Stephen Eley wrote: > > I prefer (and still use) the old way for grammatical reasons. Putting > the dependent clause of a sentence ahead of the independent clause > that it's dependent is awkward and distracts from the reading. Argh. That should have been "...that it's dependent UPON." I believe there's an old Internet law that states that any post bitching about grammar is guaranteed to contain at least one grammatical error, but I can't be bothered to look it up. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From ashley.moran at patchspace.co.uk Sun Oct 26 11:20:20 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 26 Oct 2008 15:20:20 +0000 Subject: [rspec-users] cucumber feature description In-Reply-To: <1fb4df0810260756r3dd26c6bje14972cd8d793c46@mail.gmail.com> References: <49039CF7.2040307@ieee.org> <4903A996.2040903@benmabey.com> <1fb4df0810260756r3dd26c6bje14972cd8d793c46@mail.gmail.com> Message-ID: <5AD9E7E2-212A-4D08-AA7C-6CE1BD2F6E43@patchspace.co.uk> On Oct 26, 2008, at 2:56 pm, Stephen Eley wrote: > I prefer (and still use) the old way for grammatical reasons. Putting > the dependent clause of a sentence ahead of the independent clause > that it's dependent is awkward and distracts from the reading. To me, the benefit of the unusual order (forcing you and/or your users to think about the value before all else) outweighs the downside. And actually, I've never had anyone comment that this order is confusing, so it can't be that bad. > If enough of this we do, talk like Yoda, we all will. Wish that, I > do not. But Yoda kicked ass! I want my stories to have Jedi powers in them! And light sabres! More light sabres in RSpec 1.2!!! -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From ashley.moran at patchspace.co.uk Sun Oct 26 11:24:31 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 26 Oct 2008 15:24:31 +0000 Subject: [rspec-users] cucumber feature description In-Reply-To: <1fb4df0810260759i52df2f70g32bf659ceedd080f@mail.gmail.com> References: <49039CF7.2040307@ieee.org> <4903A996.2040903@benmabey.com> <1fb4df0810260756r3dd26c6bje14972cd8d793c46@mail.gmail.com> <1fb4df0810260759i52df2f70g32bf659ceedd080f@mail.gmail.com> Message-ID: On Oct 26, 2008, at 2:59 pm, Stephen Eley wrote: > I believe there's an old Internet law that states that any post > bitching about grammar is guaranteed to contain at least one > grammatical error, but I can't be bothered to look it up. Read too much Slashdot, you do ;) -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From aslak.hellesoy at gmail.com Sun Oct 26 11:52:26 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Sun, 26 Oct 2008 16:52:26 +0100 Subject: [rspec-users] cucumber feature description In-Reply-To: <1fb4df0810260756r3dd26c6bje14972cd8d793c46@mail.gmail.com> References: <49039CF7.2040307@ieee.org> <4903A996.2040903@benmabey.com> <1fb4df0810260756r3dd26c6bje14972cd8d793c46@mail.gmail.com> Message-ID: <8d961d900810260852u1cc4f3edle1d61bc39f3d84ed@mail.gmail.com> On Sun, Oct 26, 2008 at 3:56 PM, Stephen Eley wrote: > On Sat, Oct 25, 2008 at 7:19 PM, Ben Mabey wrote: >> >> A more qualified person may want to answer your question, but my short >> explanation of the change of the default narrative layout is to state the >> business value at the start instead of the end. However, you shouldn't feel >> constrained to use that layout all the time though. > > I prefer (and still use) the old way for grammatical reasons. Putting > the dependent clause of a sentence ahead of the independent clause > that it's dependent is awkward and distracts from the reading. > > If enough of this we do, talk like Yoda, we all will. Wish that, I do not. > The role and a feature is secondary to the business value (and the role using the feature is more important than the feature itself). That's why we prefer promoting it to the beginning. Without a clear vision of what the business value we might be developing crap. Think of the template as three elements in order: BUSINESS VALUE ROLE FEATURE The exact wording you use is not important. The order in which these elements appear is. There is nothing about this order that suggests that it can only be described with Yoda language. I do agree that the concrete template we're currently using is a little awkward though. How can we improve it? Aslak > > > -- > Have Fun, > Steve Eley (sfeley at gmail.com) > ESCAPE POD - The Science Fiction Podcast Magazine > http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt at mattwynne.net Sun Oct 26 17:09:39 2008 From: matt at mattwynne.net (Matt Wynne) Date: Sun, 26 Oct 2008 21:09:39 +0000 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> Message-ID: <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> On 26 Oct 2008, at 10:39, Ashley Moran wrote: > > On Oct 26, 2008, at 12:03 am, Ben Mabey wrote: > >> I agree with most of this. For a purely RESTful controller I like >> to use a plugin, like make_resourceful, that will take care of all >> the boilerplate code that becomes very tedious to spec out and >> write. Since the plugins are tested I can just rely that coverage >> alongside my scenarios going through the full stack. However, once >> I need to go out of the ordinary RESTful controller I usually >> always still write specs for those actions using mocks. My two >> reasons for doing this is a) allow for interface discovery with >> mocks and b) to prevent logic from seeping into the controllers. >> Writing code examples for controllers in a purely interaction-based >> way can be laborious and it becomes extremely painful if you put >> actual business logic in them. I think that pain is a good thing >> because it reminds less experienced people on your team (and more >> experienced people too sometimes :) ) that controllers shouldn't >> get too big and that they should be pushing the responsibility into >> other objects (be that AR or regular ruby objects.) >> So while I agree completely that controller specs don't offer >> regression value over scenarios I do place more value on the design >> aspect I think they provide. In the past I have been able to >> detect feature envy and a number of other code smells within my >> controllers via my controller examples that I don't think I would >> of noticed and/or been motivated enough to refactor them into the >> right level. Again, I can totally understand your point of view >> and even agree with it. I think if a team is experienced and >> disciplined enough then writing controller specs could be >> skipped... just keep a look out for "broken windows" or else the >> whole controller neighborhood will start seeping tiny facets of >> business logic. :) > > Hmm, after hearing both sides of the argument, I'm inclined to keep > writing controller specs, but to gloss over them in their basic CRUD > form. They add so little value initially, they are a terrible > pedagogical example. Models are much more fun anyway :) I don't know. I've got inheritance in my controllers, for example I have a MediaController which is subclassed by ImagesController and VideosController. The specs allowed me to factor out this base class. I think controllers are OK for doing BDD: describe "the show action" describe "when the video is for an artist" describe "when the video cannot be found" describe "when the video exists in the database" describe "when the video is for a concert" etc. TBH, I have only just begun to glimpse the idea that cucumber might mean I don't need to get 100% coverage from unit-level specs... so I may just need more time to get my head around the idea. I guess it also depends on the rest of your team: it sounds as though David can trust the rest of his team to write well designed code - it's just him! Personally I feel I need to set the rest of my team a good example while they get through the 'shu' stage. Pat - are you going solo too? cheers, Matt From lists at ruby-forum.com Sun Oct 26 17:45:34 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Sun, 26 Oct 2008 22:45:34 +0100 Subject: [rspec-users] daylight savings time difference with rspec? Message-ID: <049bbcca16d05998ff6aa1a72a9cea15@ruby-forum.com> Hi all, I wanted to check this with you. I have an rspec example that checks the correct expiration date set on an object. The expiration is set in the model with expires_on = Time.now + next_duration[phase] where next_duration can either be in units of seconds or n.days (should be the same thing). n can be 3, 7, 25, or 30 days. in my example I check an interval because the two events are not simultaneous between when the model calls Time.now and when the rspec example calls it: rhs = expires_on < (Time.now + (n +200)) lhs = expires_on > (Time.now + (n -200)) (rhs && lhs).should be_true I find that if n takes the expires_on across the daylight savings time change then the model and rspec are off by 1 hour. Why is there a difference? Are Rails and RSpec referencing different time objects? Thanks for your help, Harry -- Posted via http://www.ruby-forum.com/. From ashley.moran at patchspace.co.uk Sun Oct 26 18:09:38 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Sun, 26 Oct 2008 22:09:38 +0000 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> Message-ID: <750B509F-6EC2-4122-A1FA-FC1D2EF18D30@patchspace.co.uk> On Oct 26, 2008, at 9:09 pm, Matt Wynne wrote: > I don't know. I've got inheritance in my controllers, for example I > have a MediaController which is subclassed by ImagesController and > VideosController. The specs allowed me to factor out this base class. > > I think controllers are OK for doing BDD: > > describe "the show action" > describe "when the video is for an artist" > describe "when the video cannot be found" > describe "when the video exists in the database" > describe "when the video is for a concert" > > etc. Hmm, what's the code like behind that? I try to avoid inheritance, or at least rarely feel the need for it. There are many ways to implement those specs, and one of them involves a lot of ifs and cases. (A valid if-statement would probably be for "when the video cannot be found" and "when the video exists in the database".) > TBH, I have only just begun to glimpse the idea that cucumber might > mean I don't need to get 100% coverage from unit-level specs... so I > may just need more time to get my head around the idea. Me too, especially when multiple content types and authentication schemes come into play... not got that far in my current projects though. > I guess it also depends on the rest of your team: it sounds as > though David can trust the rest of his team to write well designed > code - it's just him! Personally I feel I need to set the rest of my > team a good example while they get through the 'shu' stage. Pat - > are you going solo too? I'm in an unusual situation in this sense. One of my Merb projects is purely personal, right now. So for that I just want to make my app work, and the code not to cause me grief. The other is a two day a week BDD coaching/pair programming development with an otherwise solo developer. So I have to make the specs damn near perfect, because it's all the RSpec he's seen. Due to Merb still being a bit of an unknown, that's making me lean towards neurotic perfectionism in my own code, at the moment. And I know just as soon as I've made them all perfect, David will redefine perfection again :) Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From mark.thomson at ieee.org Sun Oct 26 18:30:53 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Sun, 26 Oct 2008 17:30:53 -0500 Subject: [rspec-users] Testing item links in Cucumber Message-ID: <4904EF9D.2030300@ieee.org> I have an index template that contains a tabulated list of database items, each of which has an associated "display" link that enables the item to be displayed via a "show" action. In Cucumber I know how to test that the show template is rendered when one of those links is clicked using webrat's "click_link" method and response.should render_template. What I'm not sure about is whether it's possible to specify that a particular link gets clicked, since there are multiple links on the page with the same text. I'd like to be able to test that the particular database record that gets used in the show template corresponds to the one whose display link was clicked. Any thoughts on this? Is a story-level test the right place to be checking this, or should it be handled in an object level test? Mark. From srveit at gmail.com Sun Oct 26 18:33:36 2008 From: srveit at gmail.com (Stephen Veit) Date: Sun, 26 Oct 2008 17:33:36 -0500 Subject: [rspec-users] Specs for ActionMailer views Message-ID: Folks, Has anyone written specs for ActionMailer views? What type should I use. I can't use :view since it expects a controller. Should I make my own Spec::Rails::Example::ViewExampleGroup class? TIA. -- Stephen Veit -------------- next part -------------- An HTML attachment was scrubbed... URL: From vertebrate at gmail.com Sun Oct 26 17:11:00 2008 From: vertebrate at gmail.com (Steve) Date: Sun, 26 Oct 2008 16:11:00 -0500 Subject: [rspec-users] Vim tree plugin? Message-ID: Does anyone know if there's a vim plugin out there that will show a tree of your describe/it blocks at a glance. Preferably with click ability to go right to that location? Thanks, Steve From aslak.hellesoy at gmail.com Sun Oct 26 19:43:13 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 27 Oct 2008 00:43:13 +0100 Subject: [rspec-users] Testing item links in Webrat (was: Cucumber) Message-ID: <8d961d900810261643s9d47893va7da3b91e98a04b1@mail.gmail.com> On Sun, Oct 26, 2008 at 11:30 PM, Mark Thomson wrote: > I have an index template that contains a tabulated list of database items, > each of which has an associated "display" link that enables the item to be > displayed via a "show" action. In Cucumber I know how to test that the show > template is rendered when one of those links is clicked using webrat's > "click_link" method and response.should render_template. > This is a Webrat question - not a Cucumber question. > What I'm not sure about is whether it's possible to specify that a > particular link gets clicked, since there are multiple links on the page > with the same text. I'd like to be able to test that the particular database Use the #clicks_link_within method in Webrat. Aslak > record that gets used in the show template corresponds to the one whose > display link was clicked. > > Any thoughts on this? Is a story-level test the right place to be checking > this, or should it be handled in an object level test? > > Mark. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mark.thomson at ieee.org Sun Oct 26 20:01:42 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Sun, 26 Oct 2008 19:01:42 -0500 Subject: [rspec-users] Testing item links in Webrat (was: Cucumber) In-Reply-To: <8d961d900810261643s9d47893va7da3b91e98a04b1@mail.gmail.com> References: <8d961d900810261643s9d47893va7da3b91e98a04b1@mail.gmail.com> Message-ID: <490504E6.5010401@ieee.org> aslak hellesoy wrote: > On Sun, Oct 26, 2008 at 11:30 PM, Mark Thomson wrote: > >> I have an index template that contains a tabulated list of database items, >> each of which has an associated "display" link that enables the item to be >> displayed via a "show" action. In Cucumber I know how to test that the show >> template is rendered when one of those links is clicked using webrat's >> "click_link" method and response.should render_template. >> >> > > This is a Webrat question - not a Cucumber question. > Only if you know the answer :-) > >> What I'm not sure about is whether it's possible to specify that a >> particular link gets clicked, since there are multiple links on the page >> with the same text. I'd like to be able to test that the particular database >> > > Use the #clicks_link_within method in Webrat. > > Aslak > Thanks Aslak. You've made me realize I have been looking at an old version of the documentation, here: http://www.brynary.com/uploads/webrat/rdoc/index.html. So I didn't realize there was a click_links_within method. Google has just led me here: http://webrat.rubyforge.org/. Mark. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Sun Oct 26 20:26:21 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 26 Oct 2008 19:26:21 -0500 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <750B509F-6EC2-4122-A1FA-FC1D2EF18D30@patchspace.co.uk> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <750B509F-6EC2-4122-A1FA-FC1D2EF18D30@patchspace.co.uk> Message-ID: Sent from my iPhone On Oct 26, 2008, at 5:09 PM, Ashley Moran wrote: > > On Oct 26, 2008, at 9:09 pm, Matt Wynne wrote: > >> I don't know. I've got inheritance in my controllers, for example I >> have a MediaController which is subclassed by ImagesController and >> VideosController. The specs allowed me to factor out this base class. >> >> I think controllers are OK for doing BDD: >> >> describe "the show action" >> describe "when the video is for an artist" >> describe "when the video cannot be found" >> describe "when the video exists in the database" >> describe "when the video is for a concert" >> >> etc. > > Hmm, what's the code like behind that? I try to avoid inheritance, > or at least rarely feel the need for it. There are many ways to > implement those specs, and one of them involves a lot of ifs and > cases. (A valid if-statement would probably be for "when the video > cannot be found" and "when the video exists in the database".) > > >> TBH, I have only just begun to glimpse the idea that cucumber might >> mean I don't need to get 100% coverage from unit-level specs... so >> I may just need more time to get my head around the idea. > > Me too, especially when multiple content types and authentication > schemes come into play... not got that far in my current projects > though. > > >> I guess it also depends on the rest of your team: it sounds as >> though David can trust the rest of his team to write well designed >> code - it's just him! Personally I feel I need to set the rest of >> my team a good example while they get through the 'shu' stage. Pat >> - are you going solo too? > > > I'm in an unusual situation in this sense. One of my Merb projects > is purely personal, right now. So for that I just want to make my > app work, and the code not to cause me grief. The other is a two > day a week BDD coaching/pair programming development with an > otherwise solo developer. So I have to make the specs damn near > perfect, because it's all the RSpec he's seen. Due to Merb still > being a bit of an unknown, that's making me lean towards neurotic > perfectionism in my own code, at the moment. > > And I know just as soon as I've made them all perfect, David will > redefine perfection again Are you calling me neurotic? From dchelimsky at gmail.com Sun Oct 26 22:55:49 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 26 Oct 2008 21:55:49 -0500 Subject: [rspec-users] Specs for ActionMailer views In-Reply-To: References: Message-ID: <57c63afe0810261955t622a2b60rcbf7e4bf05fe3ef0@mail.gmail.com> On Sun, Oct 26, 2008 at 5:33 PM, Stephen Veit wrote: > Folks, > > Has anyone written specs for ActionMailer views? What type should I use. I > can't use :view since it expects a controller. Should I make my own > Spec::Rails::Example::ViewExampleGroup class? TIA. I just use the ViewExampleGroup, which uses its own controller that renders the view template. The view template isn't really expecting a controller. It does not care what is rendering it, as long as the various instance variables are assigned. HTH, David > -- > Stephen Veit From joshknowles at gmail.com Sun Oct 26 23:08:13 2008 From: joshknowles at gmail.com (Josh Knowles) Date: Sun, 26 Oct 2008 23:08:13 -0400 Subject: [rspec-users] Testing item links in Webrat (was: Cucumber) In-Reply-To: <490504E6.5010401@ieee.org> References: <8d961d900810261643s9d47893va7da3b91e98a04b1@mail.gmail.com> <490504E6.5010401@ieee.org> Message-ID: On 10/26/08, Mark Thomson wrote: > Google has just led me here: http://webrat.rubyforge.org/. Please make sure you view http://github.com/brynary/webrat/tree/master for the latest code as things change much faster they they get pushed up to RubyForge. -- Josh Knowles phone: 509-979-1593 email: joshknowles at gmail.com web: http://joshknowles.com From dchelimsky at gmail.com Sun Oct 26 23:12:38 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Sun, 26 Oct 2008 22:12:38 -0500 Subject: [rspec-users] Autospec running over and over, without changes? In-Reply-To: <8577893F-E319-4EB6-AA39-8B9F2D6F8FD5@gmail.com> References: <8577893F-E319-4EB6-AA39-8B9F2D6F8FD5@gmail.com> Message-ID: <57c63afe0810262012k653f93fete768c70f2c2be399@mail.gmail.com> On Thu, Oct 23, 2008 at 4:31 PM, Scott Burton wrote: > Hi all; > > I have several Rails projects where RSpec is working correctly, and one in > which it is not. Running autospec continuously reloads all files, running my > tests over and over again, without making any changes. Each time it reloads, > it runs a smaller subset of specs until it settles at around 24. > > Using Rspec 1.1.9, Rspec-Rails 1.1.9, ZenTest 3.11.0 > > This happened to me a while back, was fixed in ZenTest. I can't figure out > why this only affects one project. > > Any ideas what's going on here? Thanks, Do you have a .autotest file in that project? > > Scott > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mark.thomson at ieee.org Sun Oct 26 23:18:38 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Sun, 26 Oct 2008 22:18:38 -0500 Subject: [rspec-users] Testing item links in Webrat (was: Cucumber) In-Reply-To: References: <8d961d900810261643s9d47893va7da3b91e98a04b1@mail.gmail.com> <490504E6.5010401@ieee.org> Message-ID: <4905330E.9060801@ieee.org> Josh Knowles wrote: > On 10/26/08, Mark Thomson wrote: > > >> Google has just led me here: http://webrat.rubyforge.org/. >> > > Please make sure you view http://github.com/brynary/webrat/tree/master > for the latest code as things change much faster they they get pushed > up to RubyForge. > Thanks, although note that that also leads back to the old documentation. From ashley.moran at patchspace.co.uk Mon Oct 27 03:28:38 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Mon, 27 Oct 2008 07:28:38 +0000 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <750B509F-6EC2-4122-A1FA-FC1D2EF18D30@patchspace.co.uk> Message-ID: On Oct 27, 2008, at 12:26 am, David Chelimsky wrote: >> Due to Merb still being a bit of an unknown, that's making me lean >> towards neurotic perfectionism in my own code, at the moment. >> >> And I know just as soon as I've made them all perfect, David will >> redefine perfection again > > Are you calling me neurotic? Ha, that was unfortunate ordering of sentences on my part! Nah, but you do have an annoying habit of finding a better way of doing something just as I've got my head round the first :) Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From matt at mattwynne.net Mon Oct 27 04:09:41 2008 From: matt at mattwynne.net (Matt Wynne) Date: Mon, 27 Oct 2008 08:09:41 +0000 Subject: [rspec-users] Testing item links in Webrat (was: Cucumber) In-Reply-To: <490504E6.5010401@ieee.org> References: <8d961d900810261643s9d47893va7da3b91e98a04b1@mail.gmail.com> <490504E6.5010401@ieee.org> Message-ID: <216A5194-7867-47B0-8114-3444C3C0F8BE@mattwynne.net> On 27 Oct 2008, at 00:01, Mark Thomson wrote: > aslak hellesoy wrote: >> >>> What I'm not sure about is whether it's possible to specify that a >>> particular link gets clicked, since there are multiple links on >>> the page >>> with the same text. I'd like to be able to test that the >>> particular database >> Use the #clicks_link_within method in Webrat. > Thanks Aslak. You've made me realize I have been looking at an old > version of the documentation, here: http://www.brynary.com/uploads/webrat/rdoc/index.html > . So I didn't realize there was a click_links_within method. Google > has just led me here: http://webrat.rubyforge.org/. The webrat code is very simple and readable IMO, even for a ruby newbie like me. When I'm wondering how to do something, I usually just open the source. I think there's also a #within call which takes a block, so you might be able to do something like. within :div_for_object_123 do clicks_link 'Follow Me' end This is based on a conversation I heard over the other side of the desk, so take it with a pinch of salt ;) cheers, Matt From philodespotos at gmail.com Mon Oct 27 10:14:59 2008 From: philodespotos at gmail.com (Kyle Hargraves) Date: Mon, 27 Oct 2008 09:14:59 -0500 Subject: [rspec-users] Vim tree plugin? In-Reply-To: References: Message-ID: <60f3810c0810270714m4bcc1de1ubeeb50a5b687310a@mail.gmail.com> On Sun, Oct 26, 2008 at 4:11 PM, Steve wrote: > Does anyone know if there's a vim plugin out there that will show a tree of > your describe/it blocks at a glance. Preferably with click ability to go > right to that location? It'd be awesome to have a ctags-esque feature for viewing a list of example groups, but I've not seen such a thing. However, if you use syntax-based folding for ruby files (:set foldmethod=syntax), then collapsing all folds (zM) will show you your top-level example groups, unfolding one will show the examples within it, etc. The only drawback is that syntax-based folding gets a bit slow on particularly large or deeply nested files. HTH k From lists at ruby-forum.com Mon Oct 27 10:54:20 2008 From: lists at ruby-forum.com (Juanma Cervera) Date: Mon, 27 Oct 2008 15:54:20 +0100 Subject: [rspec-users] Gems installation Message-ID: Hello. I have a problem trying to use cucumber with webrat. I thought I could use the gems versions of rspec, rspec-rails, cucumber and webrat, in fact I think that I could manage to do it two weeks ago, but now that I updated the versions of the rspec, rspec-rails and cucumber, I am getting a errors like this undefined method `visits' for # (NoMethodError) for all the webrat methods. Am I right.? Can I use webrat via the gem.? Or do I have to install webrat in vendor/plugins directory.? Thanks -- Posted via http://www.ruby-forum.com/. From mark.thomson at ieee.org Mon Oct 27 11:28:16 2008 From: mark.thomson at ieee.org (Mark Thomson) Date: Mon, 27 Oct 2008 10:28:16 -0500 Subject: [rspec-users] Gems installation In-Reply-To: References: Message-ID: <4905DE10.2040801@ieee.org> The webrat gem works for me. Do you have "require 'webrat'" in your features/steps/env.rb file? Mark. Juanma Cervera wrote: > Hello. > > I have a problem trying to use cucumber with webrat. > I thought I could use the gems versions of rspec, rspec-rails, cucumber > and webrat, in fact I think that I could manage to do it two weeks ago, > but now that I updated the versions of the rspec, rspec-rails and > cucumber, I am getting a errors like this > > undefined method `visits' for > # (NoMethodError) > > for all the webrat methods. > > Am I right.? Can I use webrat via the gem.? Or do I have to install > webrat in vendor/plugins directory.? > > Thanks > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Mon Oct 27 13:20:31 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 27 Oct 2008 10:20:31 -0700 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> Message-ID: <810a540e0810271020l61f1f386yd670af6bfd550b16@mail.gmail.com> On Mon, Oct 27, 2008 at 9:35 AM, Pat Maddox wrote: > Matt Wynne writes: > >> Pat - are you going solo too? > > Nope, I'm trying to teach RSpec/BDD to an organization that currently > doesn't use it and has 0% test coverage. It's interesting, to say the > least. They're good devs, but even so, the effects of not writing tests > first (or even at all) are painfully evident when trying to get the > codebase under test, and especially to change stuff. Really puts your > "working effectively with legacy code" chops to work :) One major point which I failed to make is that a heavily determining factor for me is confidence. How much confidence does a new test inspire? Clearly, a full-stack acceptance test ought to inspire a good deal of confidence. A mocked-out unit test considerably less so. As I've said before, I see three major benefits to unit tests: * Drive the design of objects * Provide regression tests * Serve as examples of how to use the code Mock based controller specs don't provide as much regression value as acceptance tests, unless you've got a bunch of weird little pathways that you want to unit test. But most Rails apps these days aren't like that - we have REST + "skinny controller / fat model" to thank for that. Ben, I think it was you who mentioned that you like using mocks in controller specs because it helps with interface discovery. While I agree that mocks can be a great tool for interface discovery, I'm finding that to be decreasingly important in controllers. They're just so damn simple, for the most part. Remember, mocks are just one of the tools we use to improve design. Refactoring is another one. I've found that when writing controllers, mocks provide little upfront design value, and the bulk of design value I get comes from refactoring. Now, I will add that I've written a crapload of controller specs over the last few years, and have developed a personal style that minimizes logic in the controllers. So I don't generally spend a lot of brain cycles on controller design. They become patterns...think Cypher from the Matrix: "all I see is blonde, brunette, redhead..." When it comes to controllers specs, mocks provide the most value by isolating from the model and db - the specs run faster, and you don't have to worry about model validations. But if you minimize controller logic, you can write acceptance tests that give you confidence that your controllers work, and then controller specs become unnecessary overhead. Pat From aidy.lewis at googlemail.com Mon Oct 27 14:33:33 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Mon, 27 Oct 2008 18:33:33 +0000 Subject: [rspec-users] Cucumber step FIT-like tables Message-ID: <7ac2300c0810271133m1f45d143gcf1eb40045e1c019@mail.gmail.com> Hi, I am having a problem with my Cucumber step FIT-like tables. This is my scenario Scenario: Filter by new files added Given a database update that creates an ExpiryDate that is within 30 days And a logged in OLC user When clicks 'After Sales' And selects 'New files added within 30 days' in the filter by drop down Then verify the AE numbers of: | text | | ABHA338K | | ABEB702B | | ABBQ403P | | ABBQ404J | My step implementation is: Then /verify the AE numbers of:/ do |link_table| link_table.hashes.each do |hash| browser.link(:url, Regexp.new(hash['text'])).exist? end end But I am getting this Then verify the AE numbers of: expected 1 block argument(s), got 0 (Cucumber::ArityMismatchError) Cheers Aidy From aslak.hellesoy at gmail.com Mon Oct 27 15:15:04 2008 From: aslak.hellesoy at gmail.com (=?UTF-8?Q?Aslak_Helles=C3=B8y?=) Date: Mon, 27 Oct 2008 20:15:04 +0100 Subject: [rspec-users] Cucumber step FIT-like tables In-Reply-To: <7ac2300c0810271133m1f45d143gcf1eb40045e1c019@mail.gmail.com> References: <7ac2300c0810271133m1f45d143gcf1eb40045e1c019@mail.gmail.com> Message-ID: <71553286-AE61-4702-AA12-7BD9358DA292@gmail.com> What version/revision? Sent from my iPhone On 27. okt.. 2008, at 19.33, "aidy lewis" wrote: > Hi, > > I am having a problem with my Cucumber step FIT-like tables. > > This is my scenario > > Scenario: Filter by new files added > Given a database update that creates an ExpiryDate that is within > 30 days > And a logged in OLC user > When clicks 'After Sales' > And selects 'New files added within 30 days' in the filter by > drop down > Then verify the AE numbers of: > | text | > | ABHA338K | > | ABEB702B | > | ABBQ403P | > | ABBQ404J | > > My step implementation is: > > Then /verify the AE numbers of:/ do |link_table| > link_table.hashes.each do |hash| > browser.link(:url, Regexp.new(hash['text'])).exist? > end > end > > But I am getting this > > Then verify the AE numbers of: > expected 1 block argument(s), got 0 (Cucumber::ArityMismatchError) > > > > Cheers > > Aidy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From jonathan at parkerhill.com Mon Oct 27 20:44:08 2008 From: jonathan at parkerhill.com (Jonathan Linowes) Date: Mon, 27 Oct 2008 20:44:08 -0400 Subject: [rspec-users] Dreading Controller Specs In-Reply-To: References: <48FDA4C4.7040505@mail.pigdestroyer.co.uk> <598008DC-7D2D-4D86-9DEE-A00BC2DF28B8@madeofstone.net> <4C854A62-BC82-4161-8809-C1F4F1E12B3C@mattwynne.net> <1fb4df0810211413ye98101dl90d562c44ad4a25e@mail.gmail.com> <34C486C4-EC2B-4707-A221-DAC90931A854@mattwynne.net> Message-ID: <568336C7-EC07-4BAA-A1B4-460FA404A759@parkerhill.com> On Oct 22, 2008, at 4:32 PM, Pat Maddox wrote: > I think any app with a rich domain model benefits from a service layer > that uses that model. When building Rails apps, stuff is relatively > simple and the controllers *are* the service layer. That's how I > think > of it, anyway. Most of the time that's sufficient, but sometimes it > gets complex enough that you want to split out some of the logic. Reflecting on this thread, I'm realizing I put a lot of these kind of things into application.rb. Maybe I should think about how to make them into objects in a service layer, but presently they're doing fine where they are: split out from the controller, and independently testable. hmm... From aidy.lewis at googlemail.com Tue Oct 28 06:43:15 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Tue, 28 Oct 2008 10:43:15 +0000 Subject: [rspec-users] Cucumber step FIT-like tables In-Reply-To: <71553286-AE61-4702-AA12-7BD9358DA292@gmail.com> References: <7ac2300c0810271133m1f45d143gcf1eb40045e1c019@mail.gmail.com> <71553286-AE61-4702-AA12-7BD9358DA292@gmail.com> Message-ID: <7ac2300c0810280343h2a2b2d10ta6578c4ef9fff00c@mail.gmail.com> Hi Alsak, 2008/10/27 Aslak Helles?y : > What version/revision? I am on 0.1.7; I guess I need to upgrade. If this is the case, will I need to use the Trunk or is there a gem? Thanks Aidy From cameron.booth at gmail.com Tue Oct 28 09:09:23 2008 From: cameron.booth at gmail.com (Cameron Booth) Date: Tue, 28 Oct 2008 08:09:23 -0500 Subject: [rspec-users] Accessing the model class from within an rspec-rails spec Message-ID: Hi everybody, New to the list, so apologies if this has been answered elsewhere, but I didn't find it. I'm trying to build up a plugin of useful rspec macros for rails development, eg. things like: it_should_return_success it_should_redirect_to { some_url } I'm basing my ideas off of some stuff technoweenie has done, as well as a few others. One thing I'd love to do is be able to figure out the model class in a rails model spec, so I can do something like: describe User do it_should_validate_presence_of :name end I can get it working if I pass in User as an argument: describe User do it_should_validate_presence_of User, :name end but that feels redundant. Is there a way to access the class itself that I'm missing? On the controller spec side, I see there is controller_class_name, but that needs to be set with the controller_name method. I could go for something like that if required, but somehow it seems like it would be overkill. Any advice would be greatly appreciated, thanks!! Cameron -------------- next part -------------- An HTML attachment was scrubbed... URL: From cameron.booth at gmail.com Tue Oct 28 09:40:45 2008 From: cameron.booth at gmail.com (Cameron Booth) Date: Tue, 28 Oct 2008 08:40:45 -0500 Subject: [rspec-users] Accessing the model class from within an rspec-rails spec In-Reply-To: References: Message-ID: Hi again, I think I may have partly found my own answer. Looking at this gist http://gist.github.com/14050 by Andy Freeman, it seems to do much of what I'm looking for right now (thanks, awesome!!). But playing around with it a bit, calling self.described_type which I thought would return the class, it's not, it seems to be looking only for a module? def described_type description_parts.find {|part| part.is_a?(Module)} end Is there something I'm missing? Cameron On Tue, Oct 28, 2008 at 8:09 AM, Cameron Booth wrote: > Hi everybody, > > New to the list, so apologies if this has been answered elsewhere, but I > didn't find it. I'm trying to build up a plugin of useful rspec macros for > rails development, eg. things like: > > it_should_return_success > it_should_redirect_to { some_url } > > I'm basing my ideas off of some stuff technoweenie has done, as well as a > few others. > > One thing I'd love to do is be able to figure out the model class in a > rails model spec, so I can do something like: > > describe User do > it_should_validate_presence_of :name > end > > I can get it working if I pass in User as an argument: > > describe User do > it_should_validate_presence_of User, :name > end > > but that feels redundant. Is there a way to access the class itself that > I'm missing? On the controller spec side, I see there is > controller_class_name, but that needs to be set with the controller_name > method. I could go for something like that if required, but somehow it seems > like it would be overkill. > > Any advice would be greatly appreciated, thanks!! > > Cameron -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Tue Oct 28 05:14:14 2008 From: matt at mattwynne.net (Matt Wynne) Date: Tue, 28 Oct 2008 09:14:14 +0000 Subject: [rspec-users] Gems installation In-Reply-To: <4905DE10.2040801@ieee.org> References: <4905DE10.2040801@ieee.org> Message-ID: <49E1A895-C583-454B-9286-AA09AA9C563B@mattwynne.net> Last time I looked, webrat is only patched in when you're running with RAILS_ENV == "test". Are you definitely doing that? On 27 Oct 2008, at 15:28, Mark Thomson wrote: > The webrat gem works for me. Do you have "require 'webrat'" in your > features/steps/env.rb file? > > Mark. > > > > Juanma Cervera wrote: >> >> Hello. >> >> I have a problem trying to use cucumber with webrat. >> I thought I could use the gems versions of rspec, rspec-rails, >> cucumber >> and webrat, in fact I think that I could manage to do it two weeks >> ago, >> but now that I updated the versions of the rspec, rspec-rails and >> cucumber, I am getting a errors like this >> >> undefined method `visits' for >> # (NoMethodError) >> >> for all the webrat methods. >> >> Am I right.? Can I use webrat via the gem.? Or do I have to install >> webrat in vendor/plugins directory.? >> >> Thanks >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lenny at aps.org Tue Oct 28 13:13:21 2008 From: lenny at aps.org (Lenny Marks) Date: Tue, 28 Oct 2008 13:13:21 -0400 Subject: [rspec-users] -n command line option broken? Message-ID: <8F213DAE-AAEA-48B3-8429-BCB92C8E6570@aps.org> It seems that '-n' command line option for rspec stopped working as of rspec 1.1.3. I think this may be related to why I can't get NetBeans to run focussed specs anymore. Does this work for others? I'm using jruby but I don't think that's the issue. http://ruby.netbeans.org/issues/show_bug.cgi?id=148462 -lenny From lists at ruby-forum.com Tue Oct 28 04:28:00 2008 From: lists at ruby-forum.com (Juanma Cervera) Date: Tue, 28 Oct 2008 09:28:00 +0100 Subject: [rspec-users] Gems installation In-Reply-To: <4905DE10.2040801@ieee.org> References: <4905DE10.2040801@ieee.org> Message-ID: Thanks Mark That was the problem Mark Thomson wrote: > The webrat gem works for me. Do you have "require 'webrat'" in your > features/steps/env.rb file? > > Mark. -- Posted via http://www.ruby-forum.com/. From lenny at aps.org Tue Oct 28 15:31:51 2008 From: lenny at aps.org (Lenny Marks) Date: Tue, 28 Oct 2008 15:31:51 -0400 Subject: [rspec-users] -l command line option broken? Message-ID: <39567504-710D-4328-9F2F-98C969FA8002@aps.org> Ooops. I meant the -l option not -n. It seems that '-l' command line option for rspec stopped working as of rspec 1.1.3. I think this may be related to why I can't get NetBeans to run focussed specs anymore. Does this work for others? I'm using jruby but I don't think that's the issue. http://ruby.netbeans.org/issues/show_bug.cgi?id=148462 -lenny From pergesu at gmail.com Tue Oct 28 13:08:12 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 28 Oct 2008 10:08:12 -0700 Subject: [rspec-users] Should acceptance tests be run against a production environment? Message-ID: When you do end-to-end acceptance testing with Selenium, I think it should be run against a production environment. Not THE production environment, mind you, but simply a new Rails app running with RAILS_ENV=production. Also, transactional fixtures should be turned off. This is so that the app runs as closely as possible to how it does from a regular user's perspective. Models and pages get cached, transactions commit and rollback as they're defined, etc. What do you think? Am I off base here? Pat From mark at mwilden.com Tue Oct 28 16:54:34 2008 From: mark at mwilden.com (Mark Wilden) Date: Tue, 28 Oct 2008 13:54:34 -0700 Subject: [rspec-users] -l command line option broken? In-Reply-To: <39567504-710D-4328-9F2F-98C969FA8002@aps.org> References: <39567504-710D-4328-9F2F-98C969FA8002@aps.org> Message-ID: <3c30da400810281354n9d51d15k63817596b62d9d77@mail.gmail.com> On Tue, Oct 28, 2008 at 12:31 PM, Lenny Marks wrote: > Ooops. I meant the -l option not -n. > > It seems that '-l' command line option for rspec stopped working as of > rspec 1.1.3. It's been working for me. I wrote a Vim script that runs the current spec (in whatever window it might be) with DRb, so it takes about a second. It's made a big difference in my TDD/BDD work cycle. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From lenny at aps.org Tue Oct 28 17:24:28 2008 From: lenny at aps.org (Lenny Marks) Date: Tue, 28 Oct 2008 17:24:28 -0400 Subject: [rspec-users] -l command line option broken? Message-ID: <5B92F099-C979-42DC-AB5F-F20427FE2209@aps.org> > On Tue, Oct 28, 2008 at 12:31 PM, Lenny Marks > wrote: > > > Ooops. I meant the -l option not -n. > > > > It seems that '-l' command line option for rspec stopped working > as of > > rspec 1.1.3. > > > It's been working for me. I wrote a Vim script that runs the current > spec > (in whatever window it might be) with DRb, so it takes about a > second. It's > made a big difference in my TDD/BDD work cycle. > > ///ark Sorry for not replying to the thread but I'm not getting any mail from rspec-users right now for whatever reason. It looks like it is an issue specific to jruby. With rspec-1.1.11 and jruby-1.4 #linenumber_spec.rb describe "line number" do it "should be example one" do true.should be_true end it "should be another example" do true.should be_true end end > jruby-1.1.4/bin/jruby $GEM_HOME/bin/spec -l 2 $HOME/tmp/ linenumber_spec.rb Finished in 0.013457 seconds 0 examples, 0 failures > ruby $GEM_HOME/bin/spec -l 2 $HOME/tmp/linenumber_spec.rb . Finished in 0.006864 seconds 1 example, 0 failures -lenny From lenny at aps.org Tue Oct 28 17:46:38 2008 From: lenny at aps.org (Lenny Marks) Date: Tue, 28 Oct 2008 17:46:38 -0400 Subject: [rspec-users] -l command line option broken? Message-ID: <58DC8C47-1597-4F4D-8A60-58701C67167E@aps.org> > Sorry for not replying to the thread but I'm not getting any mail from > rspec-users right now for whatever reason. > > It looks like it is an issue specific to jruby. > > With rspec-1.1.11 and jruby-1.4 > > #linenumber_spec.rb > describe "line number" do > it "should be example one" do > true.should be_true > end > it "should be another example" do > true.should be_true > end > end I'm not familiar enough with the rspec code to get to the bottom of this, but I did enough drilling to find its related to the new backtrace based strategy for Spec::Runner::SpecParser#spec_name_for(file, line_number). Putting a print statement inside Spec::Example::ExampleGroupMethods#registration_backtrace I get the following which shows that the target spec file isn't even in the backtrace from jruby. def registration_backtrace backtrace = eval("caller", @registration_binding_block) puts "backtrace: #{backtrace.join("\n")}" backtrace end > ruby $GEM_HOME/bin/spec -l 2 $HOME/tmp/linenumber_spec.rb backtrace: /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/ example/example_group_methods.rb:27:in `initialize' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/extensions/ class.rb:9:in `new' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/extensions/ class.rb:9:in `subclass' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/example/ example_group_methods.rb:66:in `create_nested_example_group' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/example/ example_group_methods.rb:53:in `describe' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/example/ example_group_factory.rb:53:in `create_example_group' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/extensions/ main.rb:27:in `describe' /home/jis/compsvc/lenny/tmp/linenumber_spec.rb:1 /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/runner/ example_group_runner.rb:14:in `load' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/runner/ example_group_runner.rb:14:in `load_files' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/runner/ example_group_runner.rb:13:in `each' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/runner/ example_group_runner.rb:13:in `load_files' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/runner/ options.rb:98:in `run_examples' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/runner/ command_line.rb:10:in `run' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/bin/spec:4 /Users/Shared/RubyGems/1.8/bin/spec:19:in `load' /Users/Shared/RubyGems/1.8/bin/spec:19 > jruby-1.1.4/bin/jruby $GEM_HOME/bin/spec -l 2 $HOME/tmp/ linenumber_spec.rb backtrace: /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/ extensions/class.rb:9:in `eval' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/example/ example_group_methods.rb:203:in `registration_backtrace' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/runner/ spec_parser.rb:35:in `consider_example_groups_for_best_match' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/runner/ spec_parser.rb:15:in `spec_name_for' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/runner/ spec_parser.rb:14:in `each' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/runner/ spec_parser.rb:14:in `spec_name_for' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/runner/ options.rb:302:in `set_spec_from_line_number' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/runner/ options.rb:114:in `run_examples' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/lib/spec/runner/ command_line.rb:10:in `run' /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/bin/spec:4 /Users/Shared/RubyGems/1.8/gems/rspec-1.1.11/bin/spec:19:in `load' /Users/Shared/RubyGems/1.8/bin/spec:19 From mark at mwilden.com Tue Oct 28 16:57:00 2008 From: mark at mwilden.com (Mark Wilden) Date: Tue, 28 Oct 2008 13:57:00 -0700 Subject: [rspec-users] -l command line option broken? In-Reply-To: <3c30da400810281354n9d51d15k63817596b62d9d77@mail.gmail.com> References: <39567504-710D-4328-9F2F-98C969FA8002@aps.org> <3c30da400810281354n9d51d15k63817596b62d9d77@mail.gmail.com> Message-ID: <3c30da400810281357m74f225ffpfe6ca10e58edb60d@mail.gmail.com> On Tue, Oct 28, 2008 at 1:54 PM, Mark Wilden wrote: > On Tue, Oct 28, 2008 at 12:31 PM, Lenny Marks wrote: > >> Ooops. I meant the -l option not -n. >> >> It seems that '-l' command line option for rspec stopped working as of >> rspec 1.1.3. > > > It's been working for me. I wrote a Vim script that runs the current spec > (in whatever window it might be) with DRb, so it takes about a second. It's > made a big difference in my TDD/BDD work cycle. > Come to think of it, I had to change the command it runs from 'script/spec' to 'spec' with the latest release of RSpec. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From cflipse at gmail.com Tue Oct 28 13:52:47 2008 From: cflipse at gmail.com (Chris Flipse) Date: Tue, 28 Oct 2008 13:52:47 -0400 Subject: [rspec-users] Cucumber step FIT-like tables In-Reply-To: <7ac2300c0810271133m1f45d143gcf1eb40045e1c019@mail.gmail.com> References: <7ac2300c0810271133m1f45d143gcf1eb40045e1c019@mail.gmail.com> Message-ID: On Mon, Oct 27, 2008 at 2:33 PM, aidy lewis wrote: > Hi, > > I am having a problem with my Cucumber step FIT-like tables. > > This is my scenario > > Scenario: Filter by new files added > Given a database update that creates an ExpiryDate that is within 30 > days > And a logged in OLC user > When clicks 'After Sales' > And selects 'New files added within 30 days' in the filter by drop down > Then verify the AE numbers of: > | text | > | ABHA338K | > | ABEB702B | > | ABBQ403P | > | ABBQ404J | > > My step implementation is: > > Then /verify the AE numbers of:/ do |link_table| > link_table.hashes.each do |hash| > browser.link(:url, Regexp.new(hash['text'])).exist? > end > end > > But I am getting this > > Then verify the AE numbers of: > expected 1 block argument(s), got 0 (Cucumber::ArityMismatchError) > > The problem isn't with your table, it's with your step definition: You're telling cucumber to expect an argument, without telling it where to find that argument. Then /verify the AE numbers of: (\w+)/ do |link_table| # .... end and you'll need to adjust the scenario to provide a number: Scenario: Filter by new files added Given a database update that creates an ExpiryDate that is within 30 days And a logged in OLC user When clicks 'After Sales' And selects 'New files added within 30 days' in the filter by drop down Then verify the AE numbers of: ABHA338K # then your table goes here. -- // anything worth taking seriously is worth making fun of // http://blog.devcaffeine.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Wed Oct 29 00:46:08 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 28 Oct 2008 23:46:08 -0500 Subject: [rspec-users] Accessing the model class from within an rspec-rails spec In-Reply-To: References: Message-ID: <57c63afe0810282146r372f67e9pb75b2bf471948674@mail.gmail.com> On Tue, Oct 28, 2008 at 8:09 AM, Cameron Booth wrote: > Hi everybody, > > New to the list, so apologies if this has been answered elsewhere, but I > didn't find it. I'm trying to build up a plugin of useful rspec macros for > rails development, eg. things like: > > it_should_return_success > it_should_redirect_to { some_url } > > I'm basing my ideas off of some stuff technoweenie has done, as well as a > few others. > > One thing I'd love to do is be able to figure out the model class in a rails > model spec, so I can do something like: > > describe User do > it_should_validate_presence_of :name > end > > I can get it working if I pass in User as an argument: > > describe User do > it_should_validate_presence_of User, :name > end > > but that feels redundant. Is there a way to access the class itself that I'm > missing? On the controller spec side, I see there is controller_class_name, > but that needs to be set with the controller_name method. I could go for > something like that if required, but somehow it seems like it would be > overkill. > > Any advice would be greatly appreciated, thanks!! You're looking for example_group.described_type, which you can get to like this: describe Foo do described_type # =>Foo it "should be Foo" do self.class.described_type # => Foo end end Cheers, David > > Cameron > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Wed Oct 29 01:40:08 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 29 Oct 2008 01:40:08 -0400 Subject: [rspec-users] Accessing the model class from within an rspec-rails spec In-Reply-To: References: Message-ID: <3961A8F4-311D-4237-B82D-36EFF0D56FAE@railsnewbie.com> On Oct 28, 2008, at 9:09 AM, Cameron Booth wrote: > Hi everybody, > > New to the list, so apologies if this has been answered elsewhere, > but I didn't find it. I'm trying to build up a plugin of useful > rspec macros for rails development, eg. things like: > > it_should_return_success > it_should_redirect_to { some_url } > > I'm basing my ideas off of some stuff technoweenie has done, as well > as a few others. > > One thing I'd love to do is be able to figure out the model class in > a rails model spec, so I can do something like: > > describe User do > it_should_validate_presence_of :name > end > > I can get it working if I pass in User as an argument: > > describe User do > it_should_validate_presence_of User, :name > end > > but that feels redundant. Is there a way to access the class itself > that I'm missing? On the controller spec side, I see there is > controller_class_name, but that needs to be set with the > controller_name method. I could go for something like that if > required, but somehow it seems like it would be overkill. > > Any advice would be greatly appreciated, thanks!! Why not something like this: before(:each) { @user = User.new } it { @user.validate_presence_of(:name) } Scott From sfeley at gmail.com Wed Oct 29 01:15:43 2008 From: sfeley at gmail.com (Stephen Eley) Date: Wed, 29 Oct 2008 01:15:43 -0400 Subject: [rspec-users] Should acceptance tests be run against a production environment? In-Reply-To: References: Message-ID: <1fb4df0810282215u1c8552dag5f96fd86abdf6802@mail.gmail.com> On Tue, Oct 28, 2008 at 1:08 PM, Pat Maddox wrote: > When you do end-to-end acceptance testing with Selenium, I think it > should be run against a production environment. Not THE production > environment, mind you, but simply a new Rails app running with > RAILS_ENV=production. I believe that's what the angels call a "staging environment." And yes. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From pergesu at gmail.com Wed Oct 29 01:11:39 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 28 Oct 2008 22:11:39 -0700 Subject: [rspec-users] Accessing the model class from within an rspec-rails spec In-Reply-To: (Cameron Booth's message of "Tue\, 28 Oct 2008 08\:09\:23 -0500") References: Message-ID: "Cameron Booth" writes: > Is there a way to access the class itself that I'm missing? described_type Pat From dchelimsky at gmail.com Tue Oct 28 15:57:00 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 28 Oct 2008 14:57:00 -0500 Subject: [rspec-users] -l command line option broken? In-Reply-To: <39567504-710D-4328-9F2F-98C969FA8002@aps.org> References: <39567504-710D-4328-9F2F-98C969FA8002@aps.org> Message-ID: <57c63afe0810281257g45fa661ct80fd67522a58400@mail.gmail.com> On Tue, Oct 28, 2008 at 2:31 PM, Lenny Marks wrote: > Ooops. I meant the -l option not -n. > > It seems that '-l' command line option for rspec stopped working as of rspec > 1.1.3. I think this may be related to why I can't get NetBeans to run > focussed specs anymore. Does this work for others? I'm using jruby but I > don't think that's the issue. > > http://ruby.netbeans.org/issues/show_bug.cgi?id=148462 I think 1.1.3 was the release that introduced nested example groups, so it would make sense that the -l option fell apart. Please check http://rspec.lighthouseapp.com and see if there is already a bug report and add one if not. Thx > > -lenny > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Tue Oct 28 23:52:45 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Tue, 28 Oct 2008 22:52:45 -0500 Subject: [rspec-users] Should acceptance tests be run against a production environment? In-Reply-To: References: Message-ID: <57c63afe0810282052v3ff2efb4y5b182ada7b0938d8@mail.gmail.com> On Tue, Oct 28, 2008 at 12:08 PM, Pat Maddox wrote: > When you do end-to-end acceptance testing with Selenium, I think it > should be run against a production environment. Not THE production > environment, mind you, but simply a new Rails app running with > RAILS_ENV=production. Also, transactional fixtures should be turned > off. This is so that the app runs as closely as possible to how it does > from a regular user's perspective. Models and pages get cached, > transactions commit and rollback as they're defined, etc. What do you > think? Am I off base here? I haven't been doing this (generally running against the test env), but I think this sounds right. FWIW, David > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Wed Oct 29 05:27:57 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 29 Oct 2008 10:27:57 +0100 Subject: [rspec-users] Should acceptance tests be run against a production environment? In-Reply-To: References: Message-ID: <8d961d900810290227xddde92fk6f54399c5a672ef@mail.gmail.com> On Tue, Oct 28, 2008 at 6:08 PM, Pat Maddox wrote: > When you do end-to-end acceptance testing with Selenium, I think it > should be run against a production environment. Not THE production > environment, mind you, but simply a new Rails app running with > RAILS_ENV=production. Also, transactional fixtures should be turned > off. This is so that the app runs as closely as possible to how it does > from a regular user's perspective. Models and pages get cached, > transactions commit and rollback as they're defined, etc. What do you > think? Am I off base here? > I recommend running against a production-LIKE environment. In Rails you can create a production_test environment that you make as close to your production environment as possible, for example by running against a production_test database that contains a dump of your production data from last night. Aslak > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From zach.dennis at gmail.com Tue Oct 28 21:27:31 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 28 Oct 2008 21:27:31 -0400 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <810a540e0810271020l61f1f386yd670af6bfd550b16@mail.gmail.com> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <810a540e0810271020l61f1f386yd670af6bfd550b16@mail.gmail.com> Message-ID: <85d99afe0810281827w67d6d47evffaf527be7d0ebf9@mail.gmail.com> Controllers are such a funny thing. Right now they are necessary evil. Once you start feeling pain with controllers you start changing your thinking. Somehow everyone who starts learning Rails ends up with bloated controllers even if they've read all of the posts and articles on "skinny controllers/fat models". IME, only then do people start rethinking the path they've taken. Now they start to roll up their sleeves and find out how they can really make skinny controllers and fat models. So they go write skinny controllers (in terms of what goes inside each action) and really bloated models. And the cycle repeats itself. Now they write skinny controllers (again in terms of what goes inside each action) and relatively chunky models. The key here is that they now don't shove everything into "one" model. They start using more than one if necessary. And sometimes it happens to be an AR object and other times just a PORO. Lastly, sometime in all of this they get bitten by the dormant monster that are controller filters and controller mixins. *Sigh*, now controller examples really suck to maintain and write. It seems like 1 out every 3 Rails developers will move the unnecessary logic that makes up these filters and mixins into their own objects, and they let the controller just use those objects, rather than having the logic end up embedded into the controller itself. This is what I do. At the end of this cycle folks start writing cookie cutter controller actions since their controllers really are simple and skinny. The controller actions all look like they've been generated from the same template. And so do our controller specs. Now we can write textmate snippets, generators, etc. to do the tedious work for us, and we can stop doing it from hand each time. And at this point this is a tell-tale sign that an abstraction is needed. Ultimately, more than an abstraction probably. I think we need a shift in how we think about mapping incoming requests to real objects doing real work is in order. I know that there are plugins like make_resourceful which try to eliminate some of pain that comes with redundancy, but this fills a void in the current controller implementation in Rails right now. We need bigger shifts in thinking to occur IMO. Anyways back on topic... Mock-based examples will never provide anywhere near the value as a regression test as an integration test (ie: cucumber features/acceptance tests). That's ok. They're not intended to. Integration tests will never provide anywhere near the value as design and discovery agents as object level examples. That's ok. They're not intended to. I agree with Ben Mabey that about receiving value from having controller examples. It helps the design of the controller stay simple and clean over time. To me this is important, and I value it more than the few minutes it takes me to write some controller examples. I disagree with everyone who doesn't write view specs. :) For me, the risk of not having them is too high compared to the few minutes it takes to spec a view. Granted, there is overlap between features and view specs, but I consider that par for the course. -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From aidy.lewis at googlemail.com Wed Oct 29 11:39:55 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Wed, 29 Oct 2008 15:39:55 +0000 Subject: [rspec-users] [Cucumber]: require features from mutliple folders Message-ID: <7ac2300c0810290839v3778c69anf9de3a7ad1e44ed3@mail.gmail.com> Hi, I have different projects with features related to those projects in different folders /project_1 /project_2 /steps The steps cover both projects How do I get Cucumber to require all features within both the projects folders and include the common steps? Thanks Aidy From cameron.booth at gmail.com Wed Oct 29 11:27:02 2008 From: cameron.booth at gmail.com (Cameron Booth) Date: Wed, 29 Oct 2008 10:27:02 -0500 Subject: [rspec-users] Including spec/rails/mocks into other classes Message-ID: Hi all, So my potentially crazy but I think good idea right now is to take the factory_girl gem and adapt it to generate stubbed models instead of actual ActiveRecord objects that get saved to the DB. My main reasoning there is that I like the syntax they've set up and some of the tools under the hood to deal with associations, etc, but I want to be disconnected from the database. However, for mocking my ActiveRecord objects right now (in a rails project) I'm using mock_model from rspec-rails a lot, and I would love to use that in this code too. But I'm hitting a few walls including the methods into a separate class. So far I've got this: class Factory include Spec::Mocks include Spec::Mocks::Methods include Spec::Rails::Mocks def create_stubbed(attrs = {}) model = mock_model(build_class) end .... I'm getting a method missing on the method "stub" however, so I feel like somehow I'm not including the right stuff, or maybe I should be extending some things, not quite sure. (And yes, that's the method "stub", not "stub!") Any advice would be awesome, thanks! Cameron -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Tue Oct 28 21:39:58 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Tue, 28 Oct 2008 21:39:58 -0400 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <85d99afe0810281827w67d6d47evffaf527be7d0ebf9@mail.gmail.com> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <810a540e0810271020l61f1f386yd670af6bfd550b16@mail.gmail.com> <85d99afe0810281827w67d6d47evffaf527be7d0ebf9@mail.gmail.com> Message-ID: <85d99afe0810281839i774081b8w3556e06b75188d16@mail.gmail.com> I forgot to add that until there is a new way to handle the role that controllers currently are responsible for, I would probably teach someone how to write good controllers and controller examples. I would also allow them to experience the pain that comes with trying to write bloated controller actions and filters so they can see the warning signs that come with the controller specs. This facilitates reflection and discussion, and allows them to grow while I'm there. More generally, as a teacher we have a lot of experience and reference points that we draw on. It can be easy to overlook this and to just have everyone do what we do, but then they never get the "why" part of it because that's still up in our heads. Zach On Tue, Oct 28, 2008 at 9:27 PM, Zach Dennis wrote: > Controllers are such a funny thing. Right now they are necessary evil. Once > you start feeling pain with controllers you start changing your thinking. > Somehow everyone who starts learning Rails ends up with bloated controllers > even if they've read all of the posts and articles on "skinny > controllers/fat models". > > IME, only then do people start rethinking the path they've taken. Now they > start to roll up their sleeves and find out how they can really make skinny > controllers and fat models. > > So they go write skinny controllers (in terms of what goes inside each > action) and really bloated models. And the cycle repeats itself. Now they > write skinny controllers (again in terms of what goes inside each action) > and relatively chunky models. The key here is that they now don't shove > everything into "one" model. They start using more than one if necessary. > And sometimes it happens to be an AR object and other times just a PORO. > > Lastly, sometime in all of this they get bitten by the dormant monster that > are controller filters and controller mixins. *Sigh*, now controller > examples really suck to maintain and write. > > It seems like 1 out every 3 Rails developers will move the unnecessary > logic that makes up these filters and mixins into their own objects, and > they let the controller just use those objects, rather than having the logic > end up embedded into the controller itself. This is what I do. > > At the end of this cycle folks start writing cookie cutter controller > actions since their controllers really are simple and skinny. The controller > actions all look like they've been generated from the same template. And so > do our controller specs. Now we can write textmate snippets, generators, > etc. to do the tedious work for us, and we can stop doing it from hand each > time. > > And at this point this is a tell-tale sign that an abstraction is needed. > Ultimately, more than an abstraction probably. I think we need a shift in > how we think about mapping incoming requests to real objects doing real work > is in order. I know that there are plugins like make_resourceful which try > to eliminate some of pain that comes with redundancy, but this fills a void > in the current controller implementation in Rails right now. We need bigger > shifts in thinking to occur IMO. Anyways back on topic... > > Mock-based examples will never provide anywhere near the value as a > regression test as an integration test (ie: cucumber features/acceptance > tests). That's ok. They're not intended to. > > Integration tests will never provide anywhere near the value as design and > discovery agents as object level examples. That's ok. They're not intended > to. > > I agree with Ben Mabey that about receiving value from having controller > examples. It helps the design of the controller stay simple and clean over > time. To me this is important, and I value it more than the few minutes it > takes me to write some controller examples. > > I disagree with everyone who doesn't write view specs. :) For me, the risk > of not having them is too high compared to the few minutes it takes to spec > a view. Granted, there is overlap between features and view specs, but I > consider that par for the course. > > -- > Zach Dennis > http://www.continuousthinking.com > http://www.mutuallyhuman.com > -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From hayafirst at gmail.com Wed Oct 29 00:33:13 2008 From: hayafirst at gmail.com (Yi Wen) Date: Tue, 28 Oct 2008 23:33:13 -0500 Subject: [rspec-users] Should acceptance tests be run against a production environment? In-Reply-To: References: Message-ID: I agree. I have seen way too many times selenium tests are OK but bugs appear in production. Not only should we run selenium tests against production environment, but also they should be run on a production like environment, such as, same OS, same setting (behind Apache, or whatever HTTP servers, etc.) On Tue, Oct 28, 2008 at 12:08 PM, Pat Maddox wrote: > When you do end-to-end acceptance testing with Selenium, I think it > should be run against a production environment. Not THE production > environment, mind you, but simply a new Rails app running with > RAILS_ENV=production. Also, transactional fixtures should be turned > off. This is so that the app runs as closely as possible to how it does > from a regular user's perspective. Models and pages get cached, > transactions commit and rollback as they're defined, etc. What do you > think? Am I off base here? > > Pat > _______________________________________________ > 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 Tue Oct 28 10:52:38 2008 From: lists at ruby-forum.com (=?utf-8?Q?R=c3=a9mi_Gagnon?=) Date: Tue, 28 Oct 2008 15:52:38 +0100 Subject: [rspec-users] spec'ing the :conditions argument of a find Message-ID: <8c1f77e6c2101d37f60d4256f919927a@ruby-forum.com> Let's see, I want to spec the :conditions args to make sure the right args is passed to the query. Product.find(:all, :conditions => ["inte_no = ? and vaat_id_type_statut_pcpa = ?", inte_no, 7], :limit => 2, :order => "trns_dt_appl_prod desc") Product.should_receive(:find).with(:conditions => 'vaat_id_type_statut_pcpa == 7) I'm pretty sure this is not the right synthax. Any suggestions? R?mi -- Posted via http://www.ruby-forum.com/. From mark at mwilden.com Wed Oct 29 10:20:09 2008 From: mark at mwilden.com (Mark Wilden) Date: Wed, 29 Oct 2008 07:20:09 -0700 Subject: [rspec-users] Should acceptance tests be run against a production environment? In-Reply-To: <8d961d900810290227xddde92fk6f54399c5a672ef@mail.gmail.com> References: <8d961d900810290227xddde92fk6f54399c5a672ef@mail.gmail.com> Message-ID: <3c30da400810290720i6f76a4e4oc963fb5aab9ed283@mail.gmail.com> One thing that bothers me about a 'staging' or 'production_test' environment is simply the value of Rails.env. That should really == 'production', it seems to me, but that's not always practical. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at deadorange.com Wed Oct 29 12:01:14 2008 From: nick at deadorange.com (Nick Hoffman) Date: Wed, 29 Oct 2008 12:01:14 -0400 Subject: [rspec-users] Accessing the model class from within an rspec-rails spec In-Reply-To: References: Message-ID: <8CC41C07-D224-4E73-B7E7-ACB4E57488CF@deadorange.com> On 2008-10-28, at 09:09, Cameron Booth wrote: > describe User do > it_should_validate_presence_of :name > end > > I can get it working if I pass in User as an argument: > > describe User do > it_should_validate_presence_of User, :name > end Hi Cameron. I haven't played with RSpec's internals at all, but considering that #it_should_validate_presence_of is nested within describe User do I would imagine that there's a way to grab "User". Have a look at the structure of the Example, ExampleGroup, etc classes. It'll be stored in one of those, somewhere. -Nick From cameron.booth at gmail.com Wed Oct 29 11:00:37 2008 From: cameron.booth at gmail.com (Cameron Booth) Date: Wed, 29 Oct 2008 10:00:37 -0500 Subject: [rspec-users] Accessing the model class from within an rspec-rails spec Message-ID: Hi everybody, David and Pat, thanks for the tip on using "described_type" to access the model class. I actually figured that one out like 10 minutes after sending the email. 2 learnings there, first, sometimes explaining the problem helps solve the problem, and second, maybe I should sit on those emails for 10 minutes before sending them ;-) Scott, to answer your question, basically I'd love to find something less verbose. I'm really liking rspec, but am finding my specs are getting longer and longer, and I'm basically in the process of investigating what options are out there in terms of shortening the commonly done stuff in specs (specifically in the context of Rails). Technoweenie has done some stuff on this, as has awfreeman on github. I'm in the process of diving deeper into those concepts to maybe pull together a plugin or something, will let this group know. Cheers! Cameron > Message: 6 > Date: Wed, 29 Oct 2008 01:40:08 -0400 > From: Scott Taylor > Subject: Re: [rspec-users] Accessing the model class from within an > rspec-rails spec > To: rspec-users > Message-ID: <3961A8F4-311D-4237-B82D-36EFF0D56FAE at railsnewbie.com> > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes > > > On Oct 28, 2008, at 9:09 AM, Cameron Booth wrote: > > > Hi everybody, > > > > New to the list, so apologies if this has been answered elsewhere, > > but I didn't find it. I'm trying to build up a plugin of useful > > rspec macros for rails development, eg. things like: > > > > it_should_return_success > > it_should_redirect_to { some_url } > > > > I'm basing my ideas off of some stuff technoweenie has done, as well > > as a few others. > > > > One thing I'd love to do is be able to figure out the model class in > > a rails model spec, so I can do something like: > > > > describe User do > > it_should_validate_presence_of :name > > end > > > > I can get it working if I pass in User as an argument: > > > > describe User do > > it_should_validate_presence_of User, :name > > end > > > > but that feels redundant. Is there a way to access the class itself > > that I'm missing? On the controller spec side, I see there is > > controller_class_name, but that needs to be set with the > > controller_name method. I could go for something like that if > > required, but somehow it seems like it would be overkill. > > > > Any advice would be greatly appreciated, thanks!! > > Why not something like this: > > before(:each) { @user = User.new } > > it { @user.validate_presence_of(:name) } > > Scott > > > > ------------------------------ > > Message: 7 > Date: Wed, 29 Oct 2008 01:15:43 -0400 > From: "Stephen Eley" > Subject: Re: [rspec-users] Should acceptance tests be run against a > production environment? > To: rspec-users > Message-ID: > <1fb4df0810282215u1c8552dag5f96fd86abdf6802 at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > > On Tue, Oct 28, 2008 at 1:08 PM, Pat Maddox wrote: > > When you do end-to-end acceptance testing with Selenium, I think it > > should be run against a production environment. Not THE production > > environment, mind you, but simply a new Rails app running with > > RAILS_ENV=production. > > I believe that's what the angels call a "staging environment." > > And yes. > > -- > Have Fun, > Steve Eley (sfeley at gmail.com) > ESCAPE POD - The Science Fiction Podcast Magazine > http://www.escapepod.org > > > ------------------------------ > > Message: 8 > Date: Tue, 28 Oct 2008 22:11:39 -0700 > From: Pat Maddox > Subject: Re: [rspec-users] Accessing the model class from within an > rspec-rails spec > To: rspec-users > Message-ID: > Content-Type: text/plain; charset=us-ascii > > "Cameron Booth" writes: > > > Is there a way to access the class itself that I'm missing? > > described_type > > Pat > > > ------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > End of rspec-users Digest, Vol 28, Issue 76 > ******************************************* > -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Wed Oct 29 17:05:52 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Wed, 29 Oct 2008 17:05:52 -0400 Subject: [rspec-users] Accessing the model class from within an rspec-rails spec In-Reply-To: <8CC41C07-D224-4E73-B7E7-ACB4E57488CF@deadorange.com> References: <8CC41C07-D224-4E73-B7E7-ACB4E57488CF@deadorange.com> Message-ID: <85d99afe0810291405ke54a964ua363b5e2465291fd@mail.gmail.com> On Wed, Oct 29, 2008 at 12:01 PM, Nick Hoffman wrote: > On 2008-10-28, at 09:09, Cameron Booth wrote: > >> describe User do >> it_should_validate_presence_of :name >> end >> >> I can get it working if I pass in User as an argument: >> >> describe User do >> it_should_validate_presence_of User, :name >> end >> > > Hi Cameron. I haven't played with RSpec's internals at all, but considering > that > #it_should_validate_presence_of > is nested within > describe User do > I would imagine that there's a way to grab "User". Have a look at the > structure of the Example, ExampleGroup, etc classes. It'll be stored in one > of those, somewhere. described_type is what you want. This represents the object being described, -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From lenny at aps.org Wed Oct 29 14:48:23 2008 From: lenny at aps.org (Lenny Marks) Date: Wed, 29 Oct 2008 14:48:23 -0400 Subject: [rspec-users] -l command line option broken? In-Reply-To: <58DC8C47-1597-4F4D-8A60-58701C67167E@aps.org> References: <58DC8C47-1597-4F4D-8A60-58701C67167E@aps.org> Message-ID: > On Oct 28, 2008, at 5:46 PM, Lenny Marks wrote: > >>> >> I'm not familiar enough with the rspec code to get to the bottom >> of this, but I did enough drilling to find its related to the new >> backtrace based strategy for Spec::Runner::SpecParser#spec_name_for >> (file, line_number). Putting a print statement inside >> Spec::Example::ExampleGroupMethods#registration_backtrace I get >> the following which shows that the target spec file isn't even in >> the backtrace from jruby. >> >> ... > > > I submitted a JRuby issue about this but it sounds like it might be > more of an rspec problem. See the issue comments. > The link would probably help. http://jira.codehaus.org/browse/JRUBY-3092 Sorry again for not replying directly to the messages on this thread (been pasting from the archives) but I'm still not getting mail from rspec-users. Is there something going on with that? If nobody else is experiencing problems I'll assume its on my side. Anyway, I just saw David's reply to check in lighthouse and I did find an open ticket. I commented on it to link to all of this. http://rspec.lighthouseapp.com/projects/5645/tickets/528-focused- specs-not-working-when-using-jruby Thanks, -lenny From lenny at aps.org Wed Oct 29 14:01:05 2008 From: lenny at aps.org (Lenny Marks) Date: Wed, 29 Oct 2008 14:01:05 -0400 Subject: [rspec-users] -l command line option broken? In-Reply-To: <58DC8C47-1597-4F4D-8A60-58701C67167E@aps.org> References: <58DC8C47-1597-4F4D-8A60-58701C67167E@aps.org> Message-ID: On Oct 28, 2008, at 5:46 PM, Lenny Marks wrote: >> > I'm not familiar enough with the rspec code to get to the bottom of > this, but I did enough drilling to find its related to the new > backtrace based strategy for Spec::Runner::SpecParser#spec_name_for > (file, line_number). Putting a print statement inside > Spec::Example::ExampleGroupMethods#registration_backtrace I get the > following which shows that the target spec file isn't even in the > backtrace from jruby. > > ... I submitted a JRuby issue about this but it sounds like it might be more of an rspec problem. See the issue comments. Thanks, -lenny From mailing_lists at railsnewbie.com Wed Oct 29 15:27:26 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Wed, 29 Oct 2008 15:27:26 -0400 Subject: [rspec-users] Including spec/rails/mocks into other classes In-Reply-To: References: Message-ID: <51FE460C-C3A2-4EF6-9F43-13485BE7A253@railsnewbie.com> On Oct 29, 2008, at 11:27 AM, Cameron Booth wrote: > Hi all, > > So my potentially crazy but I think good idea right now is to take > the factory_girl gem and adapt it to generate stubbed models instead > of actual ActiveRecord objects that get saved to the DB. My main > reasoning there is that I like the syntax they've set up and some of > the tools under the hood to deal with associations, etc, but I want > to be disconnected from the database. > > However, for mocking my ActiveRecord objects right now (in a rails > project) I'm using mock_model from rspec-rails a lot, and I would > love to use that in this code too. But I'm hitting a few walls > including the methods into a separate class. So far I've got this: > > class Factory > > include Spec::Mocks > include Spec::Mocks::Methods > include Spec::Rails::Mocks > > def create_stubbed(attrs = {}) > model = mock_model(build_class) > end > .... > > I'm getting a method missing on the method "stub" however, so I feel > like somehow I'm not including the right stuff, or maybe I should be > extending some things, not quite sure. (And yes, that's the method > "stub", not "stub!") > > Any advice would be awesome, thanks! Are you requiring "spec/mocks" or "spec/mocks/mock" (I forget which one it is, at the moment). Try doing it through irb, requiring the appropriate spec/mocks*.rb file, and including the module. Scott From pergesu at gmail.com Wed Oct 29 17:26:02 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 29 Oct 2008 14:26:02 -0700 Subject: [rspec-users] Accessing the model class from within an rspec-rails spec In-Reply-To: <8CC41C07-D224-4E73-B7E7-ACB4E57488CF@deadorange.com> (Nick Hoffman's message of "Wed\, 29 Oct 2008 12\:01\:14 -0400") References: <8CC41C07-D224-4E73-B7E7-ACB4E57488CF@deadorange.com> Message-ID: Nick Hoffman writes: > On 2008-10-28, at 09:09, Cameron Booth wrote: >> describe User do >> it_should_validate_presence_of :name >> end >> >> I can get it working if I pass in User as an argument: >> >> describe User do >> it_should_validate_presence_of User, :name >> end > > Hi Cameron. I haven't played with RSpec's internals at all, but > considering that > #it_should_validate_presence_of > is nested within > describe User do > I would imagine that there's a way to grab "User". Have a look at the > structure of the Example, ExampleGroup, etc classes. It'll be stored > in one of those, somewhere. For some reason my emails are getting bounced or delayed or something, so I'll try again in case my first one didn't go through... You're looking for described_type Pat From ashley.moran at patchspace.co.uk Tue Oct 28 03:32:11 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 28 Oct 2008 07:32:11 +0000 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <810a540e0810271020l61f1f386yd670af6bfd550b16@mail.gmail.com> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <810a540e0810271020l61f1f386yd670af6bfd550b16@mail.gmail.com> Message-ID: <1318A016-D9AE-4B93-B4D4-1434F9E45295@patchspace.co.uk> On Oct 27, 2008, at 5:20 pm, Pat Maddox wrote: > When it comes to controllers specs, mocks provide the most value by > isolating from the model and db - the specs run faster, and you don't > have to worry about model validations. But if you minimize controller > logic, you can write acceptance tests that give you confidence that > your controllers work, and then controller specs become unnecessary > overhead. What's the consensus here then, controller specs yay or nay? 1 nay from Pat 1 act of fence sitting from me... Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From dchelimsky at gmail.com Wed Oct 29 17:32:53 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 29 Oct 2008 16:32:53 -0500 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <1318A016-D9AE-4B93-B4D4-1434F9E45295@patchspace.co.uk> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <810a540e0810271020l61f1f386yd670af6bfd550b16@mail.gmail.com> <1318A016-D9AE-4B93-B4D4-1434F9E45295@patchspace.co.uk> Message-ID: <57c63afe0810291432u6f52c0bqfbf2130cd289d05d@mail.gmail.com> On Tue, Oct 28, 2008 at 2:32 AM, Ashley Moran wrote: > > On Oct 27, 2008, at 5:20 pm, Pat Maddox wrote: > >> When it comes to controllers specs, mocks provide the most value by >> isolating from the model and db - the specs run faster, and you don't >> have to worry about model validations. But if you minimize controller >> logic, you can write acceptance tests that give you confidence that >> your controllers work, and then controller specs become unnecessary >> overhead. > > > What's the consensus here then, controller specs yay or nay? > > 1 nay from Pat > > 1 act of fence sitting from me... I think the nay from Pat was conditional, as it should be. I think the answer is: if you have to ask, then you should use them :) Otherwise, don't use them when you feel confident that you don't need them. FWIW, David > > Ashley > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From phylae at gmail.com Wed Oct 29 16:04:22 2008 From: phylae at gmail.com (DyingToLearn) Date: Wed, 29 Oct 2008 13:04:22 -0700 (PDT) Subject: [rspec-users] Should acceptance tests be run against a production environment? In-Reply-To: <8d961d900810290227xddde92fk6f54399c5a672ef@mail.gmail.com> References: <8d961d900810290227xddde92fk6f54399c5a672ef@mail.gmail.com> Message-ID: <3f4a1724-32ca-4a8c-a062-8bd3b4ebe059@q26g2000prq.googlegroups.com> aslak hellesoy wrote: > I recommend running against a production-LIKE environment. In Rails > you can create a production_test environment that you make as close to > your production environment as possible, for example by running > against a production_test database that contains a dump of your > production data from last night. I'm assuming that this is running on your development machine, right? What about the idea of running it on machines that are as close to production as possible? So if my production machine is a SliceHost VPS with 256MB RAM, Nginx, and 3 Mongrels, then I should be running these tests on a second SliceHost VPS with 256MB RAM, Nginx, and 3 Mongrels. Is that just overkill? From aslak.hellesoy at gmail.com Wed Oct 29 18:02:05 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Wed, 29 Oct 2008 23:02:05 +0100 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <57c63afe0810291432u6f52c0bqfbf2130cd289d05d@mail.gmail.com> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <810a540e0810271020l61f1f386yd670af6bfd550b16@mail.gmail.com> <1318A016-D9AE-4B93-B4D4-1434F9E45295@patchspace.co.uk> <57c63afe0810291432u6f52c0bqfbf2130cd289d05d@mail.gmail.com> Message-ID: <8d961d900810291502y3c3df5f1w34a2339ee82df459@mail.gmail.com> On Wed, Oct 29, 2008 at 10:32 PM, David Chelimsky wrote: > On Tue, Oct 28, 2008 at 2:32 AM, Ashley Moran > wrote: >> >> On Oct 27, 2008, at 5:20 pm, Pat Maddox wrote: >> >>> When it comes to controllers specs, mocks provide the most value by >>> isolating from the model and db - the specs run faster, and you don't >>> have to worry about model validations. But if you minimize controller >>> logic, you can write acceptance tests that give you confidence that >>> your controllers work, and then controller specs become unnecessary >>> overhead. >> >> >> What's the consensus here then, controller specs yay or nay? >> >> 1 nay from Pat >> >> 1 act of fence sitting from me... > > I think the nay from Pat was conditional, as it should be. > > I think the answer is: if you have to ask, then you should use them :) > Otherwise, don't use them when you feel confident that you don't need > them. > When working outside in, the granularity increases the further in you get. On the very outside it's cumbersome to test for edge cases. Start on the outside with Cucumber and whenever you come across an edge case, make a judgement on where the right abstraction level is to test it. That may be controller, view, model or somewhere else. Don't write specs just cuz Aslak > FWIW, > David > >> >> Ashley >> >> -- >> http://www.patchspace.co.uk/ >> http://aviewfromafar.net/ >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ben at benmabey.com Wed Oct 29 14:45:30 2008 From: ben at benmabey.com (Ben Mabey) Date: Wed, 29 Oct 2008 12:45:30 -0600 Subject: [rspec-users] Including spec/rails/mocks into other classes In-Reply-To: References: Message-ID: <4908AF4A.2090106@benmabey.com> Cameron Booth wrote: > Hi all, > > So my potentially crazy but I think good idea right now is to take the > factory_girl gem and adapt it to generate stubbed models instead of > actual ActiveRecord objects that get saved to the DB. My main > reasoning there is that I like the syntax they've set up and some of > the tools under the hood to deal with associations, etc, but I want to > be disconnected from the database. > > However, for mocking my ActiveRecord objects right now (in a rails > project) I'm using mock_model from rspec-rails a lot, and I would love > to use that in this code too. But I'm hitting a few walls including > the methods into a separate class. So far I've got this: > > class Factory > > include Spec::Mocks > include Spec::Mocks::Methods > include Spec::Rails::Mocks > > def create_stubbed(attrs = {}) > model = mock_model(build_class) > end > .... > > I'm getting a method missing on the method "stub" however, so I feel > like somehow I'm not including the right stuff, or maybe I should be > extending some things, not quite sure. (And yes, that's the method > "stub", not "stub!") > > Any advice would be awesome, thanks! > > Cameron > ------------------------------------------------------------------------ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users Cameron, I would suggest looking into nulldb: http://agilewebdevelopment.com/plugins/nulldb With it I am able to maintain my same model factory interface without ever hitting the DB. Using the adapter is nice because you can turn it on or off when you please so you can really hit the DB in the cases that you need to. HTH, Ben From ashley.moran at patchspace.co.uk Wed Oct 29 03:58:20 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Wed, 29 Oct 2008 07:58:20 +0000 Subject: [rspec-users] Should acceptance tests be run against a production environment? In-Reply-To: References: Message-ID: <80C7773B-F653-4803-B6ED-5F125FFD769B@patchspace.co.uk> On Oct 28, 2008, at 5:08 pm, Pat Maddox wrote: > When you do end-to-end acceptance testing with Selenium, I think it > should be run against a production environment. Not THE production > environment, mind you, but simply a new Rails app running with > RAILS_ENV=production. Also, transactional fixtures should be turned > off. This is so that the app runs as closely as possible to how it > does > from a regular user's perspective. Models and pages get cached, > transactions commit and rollback as they're defined, etc. What do you > think? Am I off base here? Hi Pat This makes sense to me. I actually tend to run feature files against the development environment though (well, features, which is a cp of development). The code reloading saves me from having to stop and start the server. Transactions and page caching are the big ones to me - model caching should *reduce* bugs, surely. A run against a production makes sense though, especially before committing. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From hans at degraaff.org Mon Oct 27 16:37:17 2008 From: hans at degraaff.org (Hans de Graaff) Date: Mon, 27 Oct 2008 21:37:17 +0100 Subject: [rspec-users] Gems installation In-Reply-To: References: Message-ID: <1225139837.13865.0.camel@ip6-localhost> On Mon, 2008-10-27 at 15:54 +0100, Juanma Cervera wrote: > I have a problem trying to use cucumber with webrat. > I thought I could use the gems versions of rspec, rspec-rails, cucumber > and webrat, in fact I think that I could manage to do it two weeks ago, > but now that I updated the versions of the rspec, rspec-rails and > cucumber, I am getting a errors like this > > undefined method `visits' for > # (NoMethodError) I just ran into this myself. I added a "require 'webrat'" to env.rb to fix it. Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From sfeley at gmail.com Wed Oct 29 18:24:53 2008 From: sfeley at gmail.com (Stephen Eley) Date: Wed, 29 Oct 2008 18:24:53 -0400 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <57c63afe0810291432u6f52c0bqfbf2130cd289d05d@mail.gmail.com> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <810a540e0810271020l61f1f386yd670af6bfd550b16@mail.gmail.com> <1318A016-D9AE-4B93-B4D4-1434F9E45295@patchspace.co.uk> <57c63afe0810291432u6f52c0bqfbf2130cd289d05d@mail.gmail.com> Message-ID: <1fb4df0810291524q12eb55cbl8d564d01ba8be6a6@mail.gmail.com> On Wed, Oct 29, 2008 at 5:32 PM, David Chelimsky wrote: > > I think the answer is: if you have to ask, then you should use them :) > Otherwise, don't use them when you feel confident that you don't need > them. Or use them, but don't knock yourself out trying to keep them perfect with total isolation and all data interactions mocked. I'm writing controller specs now hitting the real models instead of mocks, setting expectations on method calls only in specific examples to test them. I'm finding I'm much more productive on specs now and my blood pressure is lower. Controller specs are a good thing. Controllers are the heart of your application. The heart may be a simple muscle, but your doctor will still tell you it ought to be tested. It's not hard to test either, unless you insist on building a delicate network of veins and arteries outside your body to simulate the ones inside it. I don't believe the heart needs to be removed to prove it's working. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From pergesu at gmail.com Wed Oct 29 00:39:54 2008 From: pergesu at gmail.com (Pat Maddox) Date: Tue, 28 Oct 2008 21:39:54 -0700 Subject: [rspec-users] Dreading Controller Specs In-Reply-To: <568336C7-EC07-4BAA-A1B4-460FA404A759@parkerhill.com> (Jonathan Linowes's message of "Mon\, 27 Oct 2008 20\:44\:08 -0400") References: <48FDA4C4.7040505@mail.pigdestroyer.co.uk> <598008DC-7D2D-4D86-9DEE-A00BC2DF28B8@madeofstone.net> <4C854A62-BC82-4161-8809-C1F4F1E12B3C@mattwynne.net> <1fb4df0810211413ye98101dl90d562c44ad4a25e@mail.gmail.com> <34C486C4-EC2B-4707-A221-DAC90931A854@mattwynne.net> <568336C7-EC07-4BAA-A1B4-460FA404A759@parkerhill.com> Message-ID: Jonathan Linowes writes: > On Oct 22, 2008, at 4:32 PM, Pat Maddox wrote: > >> I think any app with a rich domain model benefits from a service layer >> that uses that model. When building Rails apps, stuff is relatively >> simple and the controllers *are* the service layer. That's how I >> think >> of it, anyway. Most of the time that's sufficient, but sometimes it >> gets complex enough that you want to split out some of the logic. > > Reflecting on this thread, I'm realizing I put a lot of these kind of > things into application.rb. Maybe I should think about how to make > them into objects in a service layer, but presently they're doing > fine where they are: split out from the controller, and independently > testable. hmm... Okay, but I just want to restate that you usually don't need that extra layer. Like I said, I've done that maybe four or five times over the past three years. Basically, if it seems to fit okay in the controller, there's no need to create a service layer. It's really only when the controller stuff gets awkward to test. Pat From pergesu at gmail.com Wed Oct 29 18:49:57 2008 From: pergesu at gmail.com (Pat Maddox) Date: Wed, 29 Oct 2008 15:49:57 -0700 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <57c63afe0810291432u6f52c0bqfbf2130cd289d05d@mail.gmail.com> (David Chelimsky's message of "Wed\, 29 Oct 2008 16\:32\:53 -0500") References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <810a540e0810271020l61f1f386yd670af6bfd550b16@mail.gmail.com> <1318A016-D9AE-4B93-B4D4-1434F9E45295@patchspace.co.uk> <57c63afe0810291432u6f52c0bqfbf2130cd289d05d@mail.gmail.com> Message-ID: "David Chelimsky" writes: >> What's the consensus here then, controller specs yay or nay? >> >> 1 nay from Pat > > I think the nay from Pat was conditional, as it should be. > > I think the answer is: if you have to ask, then you should use them :) > Otherwise, don't use them when you feel confident that you don't need > them. yup From MikeG1 at larkfarm.com Wed Oct 29 07:23:46 2008 From: MikeG1 at larkfarm.com (Mike Gunderloy) Date: Wed, 29 Oct 2008 06:23:46 -0500 Subject: [rspec-users] Accessing the model class from within an rspec-rails spec In-Reply-To: References: Message-ID: <59FFDBA5-ADC1-4A8B-8D21-4F819B9C175D@larkfarm.com> Part of the testing harness on one of our projects: module Spec::Example::ExampleGroupMethods def model self.described_type.to_s.underscore end def should_require(*attrs) raise "should require needs at least one attribute" if attrs.empty? model = model() attrs.each do |attribute| it "should require :#{attribute}" do m = Factory.build(model.to_sym) m.send("#{attribute}=", nil) m.should have(1).error_on(attribute) end end end ... end Using FactoryGirl for spinning up instances, but of course easily tweaked for other mocking. Mike On Oct 28, 2008, at 8:09 AM, Cameron Booth wrote: > Hi everybody, > > New to the list, so apologies if this has been answered elsewhere, > but I didn't find it. I'm trying to build up a plugin of useful > rspec macros for rails development, eg. things like: > > it_should_return_success > it_should_redirect_to { some_url } > > I'm basing my ideas off of some stuff technoweenie has done, as well > as a few others. > > One thing I'd love to do is be able to figure out the model class in > a rails model spec, so I can do something like: > > describe User do > it_should_validate_presence_of :name > end From ashley.moran at patchspace.co.uk Tue Oct 28 14:03:52 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Tue, 28 Oct 2008 18:03:52 +0000 Subject: [rspec-users] RDoc down Message-ID: Hi I get a 404 here following the expectations page[1] to the RDoc[2]. Don't know who maintains this - is it a known problem? Ashley [1] http://rspec.info/documentation/expectations.html [2] http://rspec.info/rdoc/index.html -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From josephwilk at joesniff.co.uk Wed Oct 29 05:45:20 2008 From: josephwilk at joesniff.co.uk (Joseph Wilk) Date: Wed, 29 Oct 2008 09:45:20 +0000 Subject: [rspec-users] Should acceptance tests be run against a production environment? In-Reply-To: References: Message-ID: <490830B0.4040502@joesniff.co.uk> Pat Maddox wrote: > When you do end-to-end acceptance testing with Selenium, I think it > should be run against a production environment. Not THE production > environment, mind you, but simply a new Rails app running with > RAILS_ENV=production. Also, transactional fixtures should be turned > off. This is so that the app runs as closely as possible to how it does > from a regular user's perspective. Models and pages get cached, > transactions commit and rollback as they're defined, etc. What do you > think? Am I off base here? > That is exactly what I do Pat. I want to get as close to testing the real users experience as possible. In the end those real user experiences are my greatest concern. When you move away from testing a production rails instances you leave yourself open to 'Users are complaining about X not working. Well it worked in testing' :) It however does mean you have to be very careful to isolate your acceptance tests from each other due to caching/session/cookie/database commits. -- Joseph Wilk http://www.joesniff.co.uk From cameron at zazengo.com Tue Oct 28 08:21:25 2008 From: cameron at zazengo.com (Cameron Booth) Date: Tue, 28 Oct 2008 07:21:25 -0500 Subject: [rspec-users] Accessing the model class from within an rspec-rails spec Message-ID: Hi everybody, New to the list, so apologies if this has been answered elsewhere, but I didn't find it. I'm trying to build up a plugin of useful rspec macros for rails development, eg. things like: it_should_return_success it_should_redirect_to { some_url } I'm basing my ideas off of some stuff technoweenie has done, as well as a few others. One thing I'd love to do is be able to figure out the model class in a rails model spec, so I can do something like: describe User do it_should_validate_presence_of :name end I can get it working if I pass in User as an argument: describe User do it_should_validate_presence_of User, :name end but that feels redundant. Is there a way to access the class itself that I'm missing? On the controller spec side, I see there is controller_class_name, but that needs to be set with the controller_name method. I could go for something like that if required, but somehow it seems like it would be overkill. Any advice would be greatly appreciated, thanks!! Cameron From aslak.hellesoy at gmail.com Mon Oct 27 11:55:10 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Mon, 27 Oct 2008 16:55:10 +0100 Subject: [rspec-users] Gems installation In-Reply-To: References: Message-ID: <8d961d900810270855j558c7efdq30cede188b62ab8d@mail.gmail.com> On Mon, Oct 27, 2008 at 3:54 PM, Juanma Cervera wrote: > Hello. > > I have a problem trying to use cucumber with webrat. > I thought I could use the gems versions of rspec, rspec-rails, cucumber > and webrat, in fact I think that I could manage to do it two weeks ago, > but now that I updated the versions of the rspec, rspec-rails and > cucumber, I am getting a errors like this > > undefined method `visits' for > # (NoMethodError) > > for all the webrat methods. > > Am I right.? Can I use webrat via the gem.? Or do I have to install > webrat in vendor/plugins directory.? > Do you require 'webrat' anywhere? > Thanks > -- > 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 Oct 29 23:43:33 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 29 Oct 2008 22:43:33 -0500 Subject: [rspec-users] Accessing the model class from within an rspec-rails spec In-Reply-To: References: Message-ID: <57c63afe0810292043y270f0b6ele50fcb070d93aa98@mail.gmail.com> On Tue, Oct 28, 2008 at 8:40 AM, Cameron Booth wrote: > Hi again, > > I think I may have partly found my own answer. > > Looking at this gist http://gist.github.com/14050 by Andy Freeman, it seems > to do much of what I'm looking for right now (thanks, awesome!!). > > But playing around with it a bit, calling self.described_type which I > thought would return the class, it's not, it seems to be looking only for a > module? > > def described_type > description_parts.find {|part| part.is_a?(Module)} > end > > Is there something I'm missing? Some example groups describe modules, some classes. RSpec supports both, and Module does it: $ irb >> module Foo; end => nil >> Foo.is_a?(Module) => true >> class Bar; end => nil >> Bar.is_a?(Module) => true whereas Class does not. HTH, David Cheers, David > > Cameron > > > > On Tue, Oct 28, 2008 at 8:09 AM, Cameron Booth > wrote: >> >> Hi everybody, >> >> New to the list, so apologies if this has been answered elsewhere, but I >> didn't find it. I'm trying to build up a plugin of useful rspec macros for >> rails development, eg. things like: >> >> it_should_return_success >> it_should_redirect_to { some_url } >> >> I'm basing my ideas off of some stuff technoweenie has done, as well as a >> few others. >> >> One thing I'd love to do is be able to figure out the model class in a >> rails model spec, so I can do something like: >> >> describe User do >> it_should_validate_presence_of :name >> end >> >> I can get it working if I pass in User as an argument: >> >> describe User do >> it_should_validate_presence_of User, :name >> end >> >> but that feels redundant. Is there a way to access the class itself that >> I'm missing? On the controller spec side, I see there is >> controller_class_name, but that needs to be set with the controller_name >> method. I could go for something like that if required, but somehow it seems >> like it would be overkill. >> >> Any advice would be greatly appreciated, thanks!! >> >> Cameron > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From dchelimsky at gmail.com Wed Oct 29 23:44:55 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Wed, 29 Oct 2008 22:44:55 -0500 Subject: [rspec-users] RDoc down In-Reply-To: References: Message-ID: <57c63afe0810292044g18d3b018gdf5b68d4d273b2f5@mail.gmail.com> On Tue, Oct 28, 2008 at 1:03 PM, Ashley Moran wrote: > Hi > > I get a 404 here following the expectations page[1] to the RDoc[2]. Don't > know who maintains this - is it a known problem? It is now :) If you go to http://rspec.info, you'll see links to the rdoc where it has moved. I'll remove the obsolete links. Cheers, David > > Ashley > > [1] http://rspec.info/documentation/expectations.html > [2] http://rspec.info/rdoc/index.html > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sfeley at gmail.com Thu Oct 30 00:05:57 2008 From: sfeley at gmail.com (Stephen Eley) Date: Thu, 30 Oct 2008 00:05:57 -0400 Subject: [rspec-users] Should acceptance tests be run against a production environment? In-Reply-To: <3f4a1724-32ca-4a8c-a062-8bd3b4ebe059@q26g2000prq.googlegroups.com> References: <8d961d900810290227xddde92fk6f54399c5a672ef@mail.gmail.com> <3f4a1724-32ca-4a8c-a062-8bd3b4ebe059@q26g2000prq.googlegroups.com> Message-ID: <1fb4df0810292105p370535d9p725a729346dfb928@mail.gmail.com> On Wed, Oct 29, 2008 at 4:04 PM, DyingToLearn wrote: > > What about the idea of running it on machines that are as close to > production as possible? So if my production machine is a SliceHost VPS > with 256MB RAM, Nginx, and 3 Mongrels, then I should be running these > tests on a second SliceHost VPS with 256MB RAM, Nginx, and 3 Mongrels. > > Is that just overkill? It depends on what your risks and worries are. If you have code that has dependencies on a certain server configuration, database, etc., or if you're pushing resource boundaries in any way, then yeah, you should test it against those constraints as best you can before sending it to the wild. If what you wrote is just a very vanilla Rails app with no abstractions altered and you're not anticipating a traffic slam, it probably doesn't matter if you match all resources precisely. You should at least match basic software (don't put your staging environment on Thin with Ruby 1.9 if your production is Phusion Passenger with Ruby Enterprise) but having the same number of boxes with the same RAM is not important unless there's a reason. That said, I doubt that there are many people who would call a Slicehost VPS with 256 MB RAM overkill regardless. >8-> If you're on the low end like that, what the hell, spend another twenty bucks and then clone your production slice. You could even delete the staging slice between test iterations. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From zach.dennis at gmail.com Thu Oct 30 00:21:31 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 30 Oct 2008 00:21:31 -0400 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <8d961d900810291502y3c3df5f1w34a2339ee82df459@mail.gmail.com> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <810a540e0810271020l61f1f386yd670af6bfd550b16@mail.gmail.com> <1318A016-D9AE-4B93-B4D4-1434F9E45295@patchspace.co.uk> <57c63afe0810291432u6f52c0bqfbf2130cd289d05d@mail.gmail.com> <8d961d900810291502y3c3df5f1w34a2339ee82df459@mail.gmail.com> Message-ID: <85d99afe0810292121l3f0d17adjf78a476d3af9b63f@mail.gmail.com> On Wed, Oct 29, 2008 at 6:02 PM, aslak hellesoy wrote: > On Wed, Oct 29, 2008 at 10:32 PM, David Chelimsky > wrote: > > On Tue, Oct 28, 2008 at 2:32 AM, Ashley Moran > > wrote: > >> > >> On Oct 27, 2008, at 5:20 pm, Pat Maddox wrote: > >> > >>> When it comes to controllers specs, mocks provide the most value by > >>> isolating from the model and db - the specs run faster, and you don't > >>> have to worry about model validations. But if you minimize controller > >>> logic, you can write acceptance tests that give you confidence that > >>> your controllers work, and then controller specs become unnecessary > >>> overhead. > >> > >> > >> What's the consensus here then, controller specs yay or nay? > >> > >> 1 nay from Pat > >> > >> 1 act of fence sitting from me... > > > > I think the nay from Pat was conditional, as it should be. > > > > I think the answer is: if you have to ask, then you should use them :) > > Otherwise, don't use them when you feel confident that you don't need > > them. > > > > When working outside in, the granularity increases the further in you > get. On the very outside it's cumbersome to test for edge cases. > > Start on the outside with Cucumber and whenever you come across an > edge case, make a judgement on where the right abstraction level is to > test it. That may be controller, view, model or somewhere else. > > Don't write specs just cuz > Very well put Aslak, -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at ruby-forum.com Thu Oct 30 01:02:00 2008 From: lists at ruby-forum.com (Sebastian W.) Date: Thu, 30 Oct 2008 06:02:00 +0100 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? Message-ID: Hello RSpec folks, I've only been introduced to the world of mock objects since Wednesday of last week, so go easy on me if I come off as ignorant. :P So, I'm a big fan of testing, especially since it has really helped to do refactoring in the past. But, I'm running into an issue that I'm hoping could be cleared up. Let's say that I have some code like the following: mock_engine = mock("Engine") mock_engine.should_receive(:ignite) car = Car.new(mock_engine) car.start Internally, the car class calls "ignite" on the engine that was passed to the constructor. We run the spec, everything is green. So far, so good. Now, here's what I don't understand: suppose I refactor the Engine class and rename the "ignite" method to "turn_on". If I re-run the example from above, the test is still green - but it shouldn't be, since the "ignite" method doesn't exist on the Engine class anymore. So I'm wondering...what am I doing wrong? I feel like my tests should help catch these sorts of things when I do a refactoring - my hunch is that I'm missing a step here. All comments are welcomed and appreciated! :) -- Posted via http://www.ruby-forum.com/. From mailing_lists at railsnewbie.com Thu Oct 30 01:26:01 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 30 Oct 2008 01:26:01 -0400 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: References: Message-ID: On Oct 30, 2008, at 1:02 AM, Sebastian W. wrote: > Hello RSpec folks, > I've only been introduced to the world of mock objects since Wednesday > of last week, so go easy on me if I come off as ignorant. :P > > So, I'm a big fan of testing, especially since it has really helped to > do refactoring in the past. But, I'm running into an issue that I'm > hoping could be cleared up. Let's say that I have some code like the > following: > > mock_engine = mock("Engine") > mock_engine.should_receive(:ignite) > car = Car.new(mock_engine) > car.start > > Internally, the car class calls "ignite" on the engine that was passed > to the constructor. We run the spec, everything is green. So far, so > good. > > Now, here's what I don't understand: suppose I refactor the Engine > class > and rename the "ignite" method to "turn_on". If I re-run the example > from above, the test is still green - but it shouldn't be, since the > "ignite" method doesn't exist on the Engine class anymore. > > So I'm wondering...what am I doing wrong? I feel like my tests should > help catch these sorts of things when I do a refactoring - my hunch is > that I'm missing a step here. The step your missing is that using mocks is different then classical, black box testing. When you use a mock object, you're making a tradeoff. One of the things you gain is isolation. For instance, if you were testing a webservice or a database, you may not care about it being around *for this test*. Another thing you're gaining is pure speed (of the running test case) - you simply won't have to go through the full stack. On the other hand, that's also what your loosing - meaning that if that API changes, your screwed. This is why anyone who knows anything about testing will recommend several different layers of tests - some very close to the metal which will use mocks (which can be repeatedly run quickly), and others which are closer on the integration side of the spectrum. Scott From alex.rudyk at gmail.com Thu Oct 30 01:37:50 2008 From: alex.rudyk at gmail.com (Alex Rudyk) Date: Wed, 29 Oct 2008 22:37:50 -0700 Subject: [rspec-users] Render_template return true when only part of template name match. Bug? Message-ID: <08C3D7D2-8398-4511-BDFC-FB9C158BB70B@gmail.com> I have this code response.should render_template(:my_messages) It returns true also if :messages template rendered. I am confused, is this a bug or expected behavior? Alex From dchelimsky at gmail.com Thu Oct 30 01:40:49 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 30 Oct 2008 00:40:49 -0500 Subject: [rspec-users] Render_template return true when only part of template name match. Bug? In-Reply-To: <08C3D7D2-8398-4511-BDFC-FB9C158BB70B@gmail.com> References: <08C3D7D2-8398-4511-BDFC-FB9C158BB70B@gmail.com> Message-ID: <57c63afe0810292240r4fd6e4f4k2b0d4c3686df0167@mail.gmail.com> On Thu, Oct 30, 2008 at 12:37 AM, Alex Rudyk wrote: > I have this code > > response.should render_template(:my_messages) > > It returns true also if :messages template rendered. I am confused, is this > a bug or expected behavior? Docs say use strings: http://rspec.rubyforge.org/rspec-rails/1.1.11/classes/Spec/Rails/Matchers.html#M000078 Not sure why symbols are working at all :) > > Alex > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Thu Oct 30 02:01:19 2008 From: lists at ruby-forum.com (Sebastian W.) Date: Thu, 30 Oct 2008 07:01:19 +0100 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: References: Message-ID: Hi Scott, Cool - I see what you're saying here. The only thing that I'm a bit confused still is that it seems like, at least if your system is starting to get larger, you'd really *want* your fast unit test to help you catch API changes like this to help you make updates faster. Having to run a suite of more expensive integration tests just to catch API changes seems a little funny. But I guess I'm also hoping that there's some way for the mocks to help with that sort of thing - it's my understanding that some other frameworks out there help you with that sort of stuff. One example mentioned to me was JMock -- granted, that's Java, but still - if it's possible in Java, Ruby should be able to do it too. :P -- Posted via http://www.ruby-forum.com/. From mailing_lists at railsnewbie.com Thu Oct 30 02:14:19 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 30 Oct 2008 02:14:19 -0400 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: References: Message-ID: On Oct 30, 2008, at 2:01 AM, Sebastian W. wrote: > Hi Scott, > Cool - I see what you're saying here. The only thing that I'm a bit > confused still is that it seems like, at least if your system is > starting to get larger, you'd really *want* your fast unit test to > help > you catch API changes like this to help you make updates faster. > > Having to run a suite of more expensive integration tests just to > catch > API changes seems a little funny. But I guess I'm also hoping that > there's some way for the mocks to help with that sort of thing - > it's my > understanding that some other frameworks out there help you with that > sort of stuff. One example mentioned to me was JMock -- granted, > that's > Java, but still - if it's possible in Java, Ruby should be able to > do it > too. :P Most certainly. David, et. all: Why don't we have a partial mock which will raise an error (or at least a warning) when stubbing an object who's class doesn't respond_to? the method given? I feel like this sort of simple dependency has been brought up 1000 times on the list before, but never been explicitly stated. WDYT? Scott > > -- > 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 Oct 30 02:17:51 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 30 Oct 2008 01:17:51 -0500 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: References: Message-ID: <57c63afe0810292317j769e2bc7ve9810973258742e7@mail.gmail.com> On Thu, Oct 30, 2008 at 1:14 AM, Scott Taylor wrote: > > On Oct 30, 2008, at 2:01 AM, Sebastian W. wrote: > >> Hi Scott, >> Cool - I see what you're saying here. The only thing that I'm a bit >> confused still is that it seems like, at least if your system is >> starting to get larger, you'd really *want* your fast unit test to help >> you catch API changes like this to help you make updates faster. >> >> Having to run a suite of more expensive integration tests just to catch >> API changes seems a little funny. But I guess I'm also hoping that >> there's some way for the mocks to help with that sort of thing - it's my >> understanding that some other frameworks out there help you with that >> sort of stuff. One example mentioned to me was JMock -- granted, that's >> Java, but still - if it's possible in Java, Ruby should be able to do it >> too. :P > > Most certainly. > > David, et. all: > > Why don't we have a partial mock which will raise an error (or at least a > warning) when stubbing an object who's class doesn't respond_to? the method > given? I feel like this sort of simple dependency has been brought up 1000 > times on the list before, but never been explicitly stated. > > WDYT? This has come up before. The problem is that we're dealing with a dynamic language and the class definition may or may not include the definition of that method at the point that the mock framework would do such an evaluation, especially if thing are getting mocked that might otherwise be loading modules and extending behaviour. I'd rather have it be a known problem, but a consistent problem, then a partially solved problem that will inevitably cause more pain that it does today :) Cheers, David > > Scott > >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Thu Oct 30 02:21:10 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 30 Oct 2008 02:21:10 -0400 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: References: Message-ID: On Oct 30, 2008, at 2:14 AM, Scott Taylor wrote: > > On Oct 30, 2008, at 2:01 AM, Sebastian W. wrote: > >> Hi Scott, >> Cool - I see what you're saying here. The only thing that I'm a bit >> confused still is that it seems like, at least if your system is >> starting to get larger, you'd really *want* your fast unit test to >> help >> you catch API changes like this to help you make updates faster. >> >> Having to run a suite of more expensive integration tests just to >> catch >> API changes seems a little funny. But I guess I'm also hoping that >> there's some way for the mocks to help with that sort of thing - >> it's my >> understanding that some other frameworks out there help you with that >> sort of stuff. One example mentioned to me was JMock -- granted, >> that's >> Java, but still - if it's possible in Java, Ruby should be able to >> do it >> too. :P > > Most certainly. > > David, et. all: > > Why don't we have a partial mock which will raise an error (or at > least a warning) when stubbing an object who's class doesn't > respond_to? the method given? I feel like this sort of simple > dependency has been brought up 1000 times on the list before, but > never been explicitly stated. Also, I'd be game for implementing this, and think it would be a good default behavior for the #mock method when passed a class name, but not a literal string. Scott > > > WDYT? > > Scott > >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From lists at ruby-forum.com Thu Oct 30 02:22:52 2008 From: lists at ruby-forum.com (Sebastian W.) Date: Thu, 30 Oct 2008 07:22:52 +0100 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: References: Message-ID: <612ba0f9e70b108dc68d4dbc8856a583@ruby-forum.com> > Why don't we have a partial mock which will raise an error (or at > least a warning) when stubbing an object who's class doesn't > respond_to? the method given? I feel like this sort of simple > dependency has been brought up 1000 times on the list before, but > never been explicitly stated. > > WDYT? > > Scott Hey cool! I doubt you'd want me poking around in your codebase, but if there's somewhere you can point me to help, I'd love to take a look. But I doubt I'd be of much help. :D Can't hurt to look though. Thanks so much for your responses Scott! -- Posted via http://www.ruby-forum.com/. From mailing_lists at railsnewbie.com Thu Oct 30 02:27:24 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 30 Oct 2008 02:27:24 -0400 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: <57c63afe0810292317j769e2bc7ve9810973258742e7@mail.gmail.com> References: <57c63afe0810292317j769e2bc7ve9810973258742e7@mail.gmail.com> Message-ID: On Oct 30, 2008, at 2:17 AM, David Chelimsky wrote: > On Thu, Oct 30, 2008 at 1:14 AM, Scott Taylor > wrote: >> >> On Oct 30, 2008, at 2:01 AM, Sebastian W. wrote: >> >>> Hi Scott, >>> Cool - I see what you're saying here. The only thing that I'm a bit >>> confused still is that it seems like, at least if your system is >>> starting to get larger, you'd really *want* your fast unit test to >>> help >>> you catch API changes like this to help you make updates faster. >>> >>> Having to run a suite of more expensive integration tests just to >>> catch >>> API changes seems a little funny. But I guess I'm also hoping that >>> there's some way for the mocks to help with that sort of thing - >>> it's my >>> understanding that some other frameworks out there help you with >>> that >>> sort of stuff. One example mentioned to me was JMock -- granted, >>> that's >>> Java, but still - if it's possible in Java, Ruby should be able to >>> do it >>> too. :P >> >> Most certainly. >> >> David, et. all: >> >> Why don't we have a partial mock which will raise an error (or at >> least a >> warning) when stubbing an object who's class doesn't respond_to? >> the method >> given? I feel like this sort of simple dependency has been brought >> up 1000 >> times on the list before, but never been explicitly stated. >> >> WDYT? > > This has come up before. > > The problem is that we're dealing with a dynamic language and the > class definition may or may not include the definition of that method > at the point that the mock framework would do such an evaluation, > especially if thing are getting mocked that might otherwise be loading > modules and extending behaviour. > > I'd rather have it be a known problem, but a consistent problem, then > a partially solved problem that will inevitably cause more pain that > it does today :) Yeah, that's a good point. I wonder if possibly passing some sort of flag to the stub, which is off by default (or on) might solve this problem. Scott From mailing_lists at railsnewbie.com Thu Oct 30 02:30:07 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 30 Oct 2008 02:30:07 -0400 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: <57c63afe0810292317j769e2bc7ve9810973258742e7@mail.gmail.com> References: <57c63afe0810292317j769e2bc7ve9810973258742e7@mail.gmail.com> Message-ID: <59463643-A080-4C60-83E8-C54B49CCAAE5@railsnewbie.com> On Oct 30, 2008, at 2:17 AM, David Chelimsky wrote: > On Thu, Oct 30, 2008 at 1:14 AM, Scott Taylor > wrote: >> >> On Oct 30, 2008, at 2:01 AM, Sebastian W. wrote: >> >>> Hi Scott, >>> Cool - I see what you're saying here. The only thing that I'm a bit >>> confused still is that it seems like, at least if your system is >>> starting to get larger, you'd really *want* your fast unit test to >>> help >>> you catch API changes like this to help you make updates faster. >>> >>> Having to run a suite of more expensive integration tests just to >>> catch >>> API changes seems a little funny. But I guess I'm also hoping that >>> there's some way for the mocks to help with that sort of thing - >>> it's my >>> understanding that some other frameworks out there help you with >>> that >>> sort of stuff. One example mentioned to me was JMock -- granted, >>> that's >>> Java, but still - if it's possible in Java, Ruby should be able to >>> do it >>> too. :P >> >> Most certainly. >> >> David, et. all: >> >> Why don't we have a partial mock which will raise an error (or at >> least a >> warning) when stubbing an object who's class doesn't respond_to? >> the method >> given? I feel like this sort of simple dependency has been brought >> up 1000 >> times on the list before, but never been explicitly stated. >> >> WDYT? > > This has come up before. > > The problem is that we're dealing with a dynamic language and the > class definition may or may not include the definition of that method > at the point that the mock framework would do such an evaluation, > especially if thing are getting mocked that might otherwise be loading > modules and extending behaviour. > > I'd rather have it be a known problem, but a consistent problem, then > a partially solved problem that will inevitably cause more pain that > it does today :) Actually, I take back my previous comment. Where would you stub a method on an object where the method *isn't* even loaded by further (or previous) stubbing? In Rails, at least, it's those damn class-macro type things which do all the method loading, but those are never stubbed out (they can't be, since the code needs to be loaded first). Any concrete examples come to mind? Scott > > > Cheers, > David > >> >> Scott >> >>> >>> -- >>> Posted via http://www.ruby-forum.com/. >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users From leondu at gmail.com Thu Oct 30 02:47:54 2008 From: leondu at gmail.com (Leon Du) Date: Thu, 30 Oct 2008 14:47:54 +0800 Subject: [rspec-users] mocking does not work Message-ID: The spec -------------------------------------------------------------------------------------------------------------------------------------------------------- it "should expose a newly created logo as @logo" do Logo.should_receive(:new).with({'these' => 'params'}).and_return(mock_logo(:save => true)) Logo.should_receive(:company=).with(mock_model(Company)) post :create, :logo => {:these => 'params'} assigns(:logo).should equal(mock_logo) end The code: -------------------------------------------------------------------------------------------------------------------------------------------------------- def create @logo = Logo.new(params[:logo]) @logo.company = current_user.company puts current_user.full_name if @logo.save flash[:notice] = 'You logo was successfully uploaded.' redirect_to logo_setting_path else render :action => logo_setting_path end end And the error: -------------------------------------------------------------------------------------------------------------------------------------------------------- Spec::Mocks::MockExpectationError in 'LogosController responding to POST create with valid params should expose a newly created logo as @logo' Mock 'Logo_1001' received unexpected message :company= with (#) Question: How could I mock a company= methond on Logo? -------------- next part -------------- An HTML attachment was scrubbed... URL: From pergesu at gmail.com Mon Oct 27 12:35:36 2008 From: pergesu at gmail.com (Pat Maddox) Date: Mon, 27 Oct 2008 09:35:36 -0700 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> (Matt Wynne's message of "Sun\, 26 Oct 2008 21\:09\:39 +0000") References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> Message-ID: Matt Wynne writes: > Pat - are you going solo too? Nope, I'm trying to teach RSpec/BDD to an organization that currently doesn't use it and has 0% test coverage. It's interesting, to say the least. They're good devs, but even so, the effects of not writing tests first (or even at all) are painfully evident when trying to get the codebase under test, and especially to change stuff. Really puts your "working effectively with legacy code" chops to work :) Pat From hans at degraaff.org Thu Oct 30 03:02:45 2008 From: hans at degraaff.org (Hans de Graaff) Date: Thu, 30 Oct 2008 08:02:45 +0100 Subject: [rspec-users] mocking does not work In-Reply-To: References: Message-ID: <1225350165.14202.8.camel@ip6-localhost> On Thu, 2008-10-30 at 14:47 +0800, Leon Du wrote: > The spec > -------------------------------------------------------------------------------------------------------------------------------------------------------- > it "should expose a newly created logo as @logo" do > Logo.should_receive(:new).with({'these' => > 'params'}).and_return(mock_logo(:save => true)) > Logo.should_receive(:company=).with(mock_model(Company)) > post :create, :logo => {:these => 'params'} > assigns(:logo).should equal(mock_logo) > end The instance of Logo should receive the company= method, not the class, so: @logo = mock_logo Logo.should_receive(:new).and_return(@logo) @logo.should_receive(:company=) I would probably use stub! instead here and move this code into a before block, and just keep the post and assigns lines in the it block. Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From leondu at gmail.com Thu Oct 30 05:24:26 2008 From: leondu at gmail.com (Leon Du) Date: Thu, 30 Oct 2008 17:24:26 +0800 Subject: [rspec-users] mocking does not work In-Reply-To: <1225350165.14202.8.camel@ip6-localhost> References: <1225350165.14202.8.camel@ip6-localhost> Message-ID: Thanks for your reply, I did move the code to before before(:each) do Logo.stub!(:new).and_return(mock_logo(:save => true, :company= => nil)) end 2008/10/30 Hans de Graaff > On Thu, 2008-10-30 at 14:47 +0800, Leon Du wrote: > > The spec > > > -------------------------------------------------------------------------------------------------------------------------------------------------------- > > it "should expose a newly created logo as @logo" do > > Logo.should_receive(:new).with({'these' => > > 'params'}).and_return(mock_logo(:save => true)) > > Logo.should_receive(:company=).with(mock_model(Company)) > > post :create, :logo => {:these => 'params'} > > assigns(:logo).should equal(mock_logo) > > end > > The instance of Logo should receive the company= method, not the class, > so: > > @logo = mock_logo > Logo.should_receive(:new).and_return(@logo) > @logo.should_receive(:company=) > > I would probably use stub! instead here and move this code into a before > block, and just keep the post and assigns lines in the it block. > > Hans > > _______________________________________________ > 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 aslak.hellesoy at gmail.com Thu Oct 30 05:36:50 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 30 Oct 2008 10:36:50 +0100 Subject: [rspec-users] [Cucumber]: require features from mutliple folders In-Reply-To: <7ac2300c0810290839v3778c69anf9de3a7ad1e44ed3@mail.gmail.com> References: <7ac2300c0810290839v3778c69anf9de3a7ad1e44ed3@mail.gmail.com> Message-ID: <8d961d900810300236v4d80ce21me72acc1c07c87b08@mail.gmail.com> On Wed, Oct 29, 2008 at 4:39 PM, aidy lewis wrote: > Hi, > > I have different projects with features related to those projects in > different folders > > /project_1 > /project_2 > /steps > > The steps cover both projects > > How do I get Cucumber to require all features within both the projects > folders and include the common steps? > Use the --require option. cucumber --help for details. Aslak > Thanks > > Aidy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From aslak.hellesoy at gmail.com Thu Oct 30 05:39:29 2008 From: aslak.hellesoy at gmail.com (aslak hellesoy) Date: Thu, 30 Oct 2008 10:39:29 +0100 Subject: [rspec-users] Cucumber step FIT-like tables In-Reply-To: <7ac2300c0810280343h2a2b2d10ta6578c4ef9fff00c@mail.gmail.com> References: <7ac2300c0810271133m1f45d143gcf1eb40045e1c019@mail.gmail.com> <71553286-AE61-4702-AA12-7BD9358DA292@gmail.com> <7ac2300c0810280343h2a2b2d10ta6578c4ef9fff00c@mail.gmail.com> Message-ID: <8d961d900810300239h4df2650fi8ca1d53763420805@mail.gmail.com> On Tue, Oct 28, 2008 at 11:43 AM, aidy lewis wrote: > Hi Alsak, > > 2008/10/27 Aslak Helles?y : >> What version/revision? > > I am on 0.1.7; I guess I need to upgrade. If this is the case, will I > need to use the Trunk or is there a gem? > Changelog: http://github.com/aslakhellesoy/cucumber/tree/master/History.txt Installation instructions: http://github.com/aslakhellesoy/cucumber/wikis Aslak > Thanks > > Aidy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From matt at mattwynne.net Thu Oct 30 06:20:46 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 30 Oct 2008 10:20:46 +0000 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <14006926-840A-4671-BBC9-38E2445ED089@mattwynne.net> <57c63afe0810250633m3a1ec7ddo7e7d42015220656f@mail.gmail.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> Message-ID: <010F2227-9AA8-406A-8097-81D83D7E96E4@mattwynne.net> On 27 Oct 2008, at 16:35, Pat Maddox wrote: > Matt Wynne writes: > >> Pat - are you going solo too? > > Nope, I'm trying to teach RSpec/BDD to an organization that currently > doesn't use it and has 0% test coverage. It's interesting, to say the > least. They're good devs, but even so, the effects of not writing > tests > first (or even at all) are painfully evident when trying to get the > codebase under test, and especially to change stuff. Really puts your > "working effectively with legacy code" chops to work :) :D This reminds me of an argument I was going to make for consistently writing specs as you go, even for apparently very simple controllers. As the controller gets more and more complex, it's hard to know when you've crossed the line into something that needs specs, and when you realise it, it's usually too late. That's why I'm happy in the TDD habit. From matt at mattwynne.net Thu Oct 30 06:26:11 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 30 Oct 2008 10:26:11 +0000 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: <57c63afe0810292317j769e2bc7ve9810973258742e7@mail.gmail.com> References: <57c63afe0810292317j769e2bc7ve9810973258742e7@mail.gmail.com> Message-ID: <4881479B-0648-4704-A5E5-538E5449498C@mattwynne.net> > I'd rather have it be a known problem, but a consistent problem, then > a partially solved problem that will inevitably cause more pain that > it does today :) +1 This is one of the down-sides of working in a dynamic language. We have to suck it up, IMO. > Now, here's what I don't understand: suppose I refactor the Engine > class > and rename the "ignite" method to "turn_on". If I re-run the example > from above, the test is still green - but it shouldn't be, since the > "ignite" method doesn't exist on the Engine class anymore. > > So I'm wondering...what am I doing wrong? I feel like my tests should > help catch these sorts of things when I do a refactoring - my hunch is > that I'm missing a step here. I asked Steve Freeman (author of the original JMock) about this very question the other week. His reply was straightfowrard - "that's just crap testing!". In other words, as Scott said, if you're using mocks for your unit tests, you have to also use acceptance tests to prove that the whole stack integrates. Thanks goodness for cucumber. I have already found it a massive blessing when refactoring. From dchelimsky at gmail.com Thu Oct 30 09:46:49 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 30 Oct 2008 08:46:49 -0500 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <010F2227-9AA8-406A-8097-81D83D7E96E4@mattwynne.net> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <010F2227-9AA8-406A-8097-81D83D7E96E4@mattwynne.net> Message-ID: <57c63afe0810300646p456cbadcl209465adf1502de3@mail.gmail.com> On Thu, Oct 30, 2008 at 5:20 AM, Matt Wynne wrote: > On 27 Oct 2008, at 16:35, Pat Maddox wrote: > >> Matt Wynne writes: >> >>> Pat - are you going solo too? >> >> Nope, I'm trying to teach RSpec/BDD to an organization that currently >> doesn't use it and has 0% test coverage. It's interesting, to say the >> least. They're good devs, but even so, the effects of not writing tests >> first (or even at all) are painfully evident when trying to get the >> codebase under test, and especially to change stuff. Really puts your >> "working effectively with legacy code" chops to work :) > > :D > > This reminds me of an argument I was going to make for consistently writing > specs as you go, even for apparently very simple controllers. As the > controller gets more and more complex, it's hard to know when you've crossed > the line into something that needs specs, and when you realise it, it's > usually too late. I'd agree with this (in spite of my previous comments), and add to it. One of the benefits of writing examples is that they actually help to expose things that are growing complex. If it's hard to test, it's probably hard to change. Aslak made a good point earlier this thread with "don't write specs just cuz," but perhaps this fact is sufficient "cuz" to motivate. WDYT? > > That's why I'm happy in the TDD habit. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From ashley.moran at patchspace.co.uk Thu Oct 30 10:34:07 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Thu, 30 Oct 2008 14:34:07 +0000 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <57c63afe0810300646p456cbadcl209465adf1502de3@mail.gmail.com> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <010F2227-9AA8-406A-8097-81D83D7E96E4@mattwynne.net> <57c63afe0810300646p456cbadcl209465adf1502de3@mail.gmail.com> Message-ID: <5B45E6BC-96B4-4648-84EA-18B52C8B8508@patchspace.co.uk> On 30 Oct 2008, at 13:46, David Chelimsky wrote: > I'd agree with this (in spite of my previous comments), and add to it. > > One of the benefits of writing examples is that they actually help to > expose things that are growing complex. If it's hard to test, it's > probably hard to change. > > Aslak made a good point earlier this thread with "don't write specs > just cuz," but perhaps this fact is sufficient "cuz" to motivate. Hmm, I just tried to map the benefit you get from specs in three key areas: (read as eg Specs very helpful for Good Design) Specs | No specs ------------------------------------------------------------ Good Design very helpful for discourages Documentation somewhat help[1] no effect on[2] Regression Testing marginally help[3] no effect on[2] [1] but Cucumber is better? [2] given Cucumber features and simple controllers [3] they don't detect most real breakages Just my opinion of course. But makes me think that David is right to ask "Is it true we should write controller specs cuz they highlight excess complexity?" I personally think that's the only way they provide real value, given they are at the surface of the app and therefore hit directly by Cucumber. But then, the longer I do BDD, the smaller my all classes have become, and the more the value of unit specs have shifted from regression testing to design. (I'm starting to think I need more RSpec mini- integration examples, rather than doing everything on a class-by-class basis.) So maybe the conclusion above is not controller-specific at all. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From matt at mattwynne.net Thu Oct 30 10:47:23 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 30 Oct 2008 14:47:23 +0000 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <57c63afe0810300646p456cbadcl209465adf1502de3@mail.gmail.com> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <010F2227-9AA8-406A-8097-81D83D7E96E4@mattwynne.net> <57c63afe0810300646p456cbadcl209465adf1502de3@mail.gmail.com> Message-ID: <13D7E8CE-8B7C-4530-A797-41A9F911DB8F@mattwynne.net> > Aslak made a good point earlier this thread with "don't write specs > just cuz," but perhaps this fact is sufficient "cuz" to motivate. > > WDYT? There's something else here (nothing to do with testing rails controllers, but testing in general) about the psychological blockage to working up the testing infrastructure in order to test something you've never tested before. It's so easy and tempting to say 'sod it' and dive into code & fix when you can't muster the mental energy to work out how to make something testable. By sticking to the TDD mindset in quite an uncharacteristically dogmatic way, unless I'm doing a throwaway spike, I find I usually get just enough discipline to get me through that blockage, and out into the bright sunshine of the TDD superhighway. From dchelimsky at gmail.com Thu Oct 30 10:52:49 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 30 Oct 2008 09:52:49 -0500 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <13D7E8CE-8B7C-4530-A797-41A9F911DB8F@mattwynne.net> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <010F2227-9AA8-406A-8097-81D83D7E96E4@mattwynne.net> <57c63afe0810300646p456cbadcl209465adf1502de3@mail.gmail.com> <13D7E8CE-8B7C-4530-A797-41A9F911DB8F@mattwynne.net> Message-ID: <57c63afe0810300752x4d1c65ch19d024001d326145@mail.gmail.com> On Thu, Oct 30, 2008 at 9:47 AM, Matt Wynne wrote: >> Aslak made a good point earlier this thread with "don't write specs >> just cuz," but perhaps this fact is sufficient "cuz" to motivate. >> >> WDYT? > > There's something else here (nothing to do with testing rails controllers, > but testing in general) about the psychological blockage to working up the > testing infrastructure in order to test something you've never tested > before. It's so easy and tempting to say 'sod it' and dive into code & fix > when you can't muster the mental energy to work out how to make something > testable. By sticking to the TDD mindset in quite an uncharacteristically > dogmatic way, unless I'm doing a throwaway spike, I find I usually get just > enough discipline to get me through that blockage, and out into the bright > sunshine of the TDD superhighway. Gotta trademark that puppy. :) From zach.dennis at gmail.com Thu Oct 30 10:54:28 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 30 Oct 2008 10:54:28 -0400 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <57c63afe0810300646p456cbadcl209465adf1502de3@mail.gmail.com> References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <010F2227-9AA8-406A-8097-81D83D7E96E4@mattwynne.net> <57c63afe0810300646p456cbadcl209465adf1502de3@mail.gmail.com> Message-ID: <85d99afe0810300754n1c3d60d0pa41c3599fc8de275@mail.gmail.com> On Thu, Oct 30, 2008 at 9:46 AM, David Chelimsky wrote: > On Thu, Oct 30, 2008 at 5:20 AM, Matt Wynne wrote: > > On 27 Oct 2008, at 16:35, Pat Maddox wrote: > > > >> Matt Wynne writes: > >> > >>> Pat - are you going solo too? > >> > >> Nope, I'm trying to teach RSpec/BDD to an organization that currently > >> doesn't use it and has 0% test coverage. It's interesting, to say the > >> least. They're good devs, but even so, the effects of not writing tests > >> first (or even at all) are painfully evident when trying to get the > >> codebase under test, and especially to change stuff. Really puts your > >> "working effectively with legacy code" chops to work :) > > > > :D > > > > This reminds me of an argument I was going to make for consistently > writing > > specs as you go, even for apparently very simple controllers. As the > > controller gets more and more complex, it's hard to know when you've > crossed > > the line into something that needs specs, and when you realise it, it's > > usually too late. > > I'd agree with this (in spite of my previous comments), and add to it. > > One of the benefits of writing examples is that they actually help to > expose things that are growing complex. If it's hard to test, it's > probably hard to change. > > Aslak made a good point earlier this thread with "don't write specs > just cuz," but perhaps this fact is sufficient "cuz" to motivate. > > WDYT? > I think having this motivation and/or reasoning makes it no longer a "just cuz" argument. There is a clear reason Matt is writing the spec. It seems to be in alignment with Ben Mabey's argument earlier. There is design value from these specs, it just isn't prevalent in at the time of creation. Instead the value is received as the application evolves and grows because you're able to maintain a clean and simple design -- partially from the early warning signs that the examples give you. -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From zach.dennis at gmail.com Thu Oct 30 10:56:26 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 30 Oct 2008 10:56:26 -0400 Subject: [rspec-users] Mailing list playing catch up with anyone else? Message-ID: <85d99afe0810300756l4001071eo8906c1dc9cc80e2b@mail.gmail.com> Last night it seemed like the mailing list was playing catchup, as I got a flood of emails from the past few days. Has anyone else seen this? -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dchelimsky at gmail.com Thu Oct 30 10:58:43 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 30 Oct 2008 09:58:43 -0500 Subject: [rspec-users] Mailing list playing catch up with anyone else? In-Reply-To: <85d99afe0810300756l4001071eo8906c1dc9cc80e2b@mail.gmail.com> References: <85d99afe0810300756l4001071eo8906c1dc9cc80e2b@mail.gmail.com> Message-ID: <57c63afe0810300758x69f7550cs3af255f370abb7be@mail.gmail.com> On Thu, Oct 30, 2008 at 9:56 AM, Zach Dennis wrote: > Last night it seemed like the mailing list was playing catchup, as I got a > flood of emails from the past few days. Has anyone else seen this? Yep. Right in the middle of trying to wrap up a chapter in the rspec book! Ended up staying up until 3 (because I became a sucker for distraction) but the chapter got done! w00t! (I'm learning from the political season to turn any question into a question about my particular talking points) Cheers, David From nick at deadorange.com Thu Oct 30 11:06:31 2008 From: nick at deadorange.com (Nick Hoffman) Date: Thu, 30 Oct 2008 11:06:31 -0400 Subject: [rspec-users] spec'ing the :conditions argument of a find In-Reply-To: <8c1f77e6c2101d37f60d4256f919927a@ruby-forum.com> References: <8c1f77e6c2101d37f60d4256f919927a@ruby-forum.com> Message-ID: <97ADCF1D-2590-4715-BBC3-754322ABFEE1@deadorange.com> On 2008-10-28, at 10:52, R?mi Gagnon wrote: > Let's see, I want to spec the :conditions args to make sure the right > args is passed to the query. > > Product.find(:all, > :conditions => ["inte_no = ? and vaat_id_type_statut_pcpa = ?", > inte_no, 7], > :limit => 2, > :order => "trns_dt_appl_prod desc") > > > Product.should_receive(:find).with(:conditions => > 'vaat_id_type_statut_pcpa == 7) > > I'm pretty sure this is not the right synthax. > > Any suggestions? > > R?mi Hi R?mi. You have two options here: 1) Pass each argument to #with that #find receives; 2) Use #any_args to not specify some arguments that #find receives. I'd do something like this: find_conditions = [] find_conditions << "inte_no = ? and vaat_id_type_statut_pcpa = ?" find_conditions << inte_no find_conditions << 7 Product.should_receive(:find).with(:all, :conditions => find_conditions, :limit => 2, :order => 'trns_dt_appl_prod desc' ) From nick at deadorange.com Thu Oct 30 11:10:04 2008 From: nick at deadorange.com (Nick Hoffman) Date: Thu, 30 Oct 2008 11:10:04 -0400 Subject: [rspec-users] Mailing list playing catch up with anyone else? In-Reply-To: <85d99afe0810300756l4001071eo8906c1dc9cc80e2b@mail.gmail.com> References: <85d99afe0810300756l4001071eo8906c1dc9cc80e2b@mail.gmail.com> Message-ID: <9B36BC97-A54C-4975-B192-47E4C39F2604@deadorange.com> On 2008-10-30, at 10:56, Zach Dennis wrote: > Last night it seemed like the mailing list was playing catchup, as I > got a flood of emails from the past few days. Has anyone else seen > this? Yup! When I checked my email this morning, I found 61 new messages from the rspec-users ML. From pergesu at gmail.com Thu Oct 30 11:33:24 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 30 Oct 2008 08:33:24 -0700 Subject: [rspec-users] spec'ing the :conditions argument of a find In-Reply-To: <8c1f77e6c2101d37f60d4256f919927a@ruby-forum.com> (=?utf-8?Q?=22R=C3=A9mi?= Gagnon"'s message of "Tue\, 28 Oct 2008 15\:52\:38 +0100") References: <8c1f77e6c2101d37f60d4256f919927a@ruby-forum.com> Message-ID: R?mi Gagnon writes: > Let's see, I want to spec the :conditions args to make sure the right > args is passed to the query. > > Product.find(:all, > :conditions => ["inte_no = ? and vaat_id_type_statut_pcpa = ?", > inte_no, 7], > :limit => 2, > :order => "trns_dt_appl_prod desc") > > > Product.should_receive(:find).with(:conditions => > 'vaat_id_type_statut_pcpa == 7) > > I'm pretty sure this is not the right synthax. > > Any suggestions? > > R?mi ewww......brittle, ugly, and not encapsulated. Why don't you create a method to wrap this find? Product.find_thingy(1, 2). Then mocking becomes trivial and clean: Product.should_receive(:find_thingy).with(1,2) Pat From lists at ruby-forum.com Thu Oct 30 11:41:43 2008 From: lists at ruby-forum.com (=?utf-8?Q?R=c3=a9mi_Gagnon?=) Date: Thu, 30 Oct 2008 16:41:43 +0100 Subject: [rspec-users] spec'ing the :conditions argument of a find In-Reply-To: References: <8c1f77e6c2101d37f60d4256f919927a@ruby-forum.com> Message-ID: <6bf50a9f989ada06af0e8b0427d685e4@ruby-forum.com> I do agree, That's what we're gonna do. it was just an example. But what if we want to test find_thingy(in model spec) to make sure the :conditions is set properly? R Pat Maddox wrote: > R?mi Gagnon writes: > >> Product.should_receive(:find).with(:conditions => >> 'vaat_id_type_statut_pcpa == 7) >> >> I'm pretty sure this is not the right synthax. >> >> Any suggestions? >> >> R?mi > > ewww......brittle, ugly, and not encapsulated. Why don't you create a > method to wrap this find? Product.find_thingy(1, 2). Then mocking > becomes trivial and clean: > Product.should_receive(:find_thingy).with(1,2) > > Pat -- Posted via http://www.ruby-forum.com/. From zach.dennis at gmail.com Thu Oct 30 11:58:36 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 30 Oct 2008 11:58:36 -0400 Subject: [rspec-users] spec'ing the :conditions argument of a find In-Reply-To: <6bf50a9f989ada06af0e8b0427d685e4@ruby-forum.com> References: <8c1f77e6c2101d37f60d4256f919927a@ruby-forum.com> <6bf50a9f989ada06af0e8b0427d685e4@ruby-forum.com> Message-ID: <85d99afe0810300858w52a570a1y3a8c62e68e9737d8@mail.gmail.com> On Thu, Oct 30, 2008 at 11:41 AM, R?mi Gagnon wrote: > I do agree, That's what we're gonna do. it was just an example. > But what if we want to test find_thingy(in model spec) to make sure the > :conditions is set properly? You are probably more interested in the fact that find_thingy works rather then it sets a bunch of conditions. Perhaps something like the below would work for you: it "can find things by blank and blank" do thing1 = Thing.create! :nte_no => 1, vaat_id_type_statut_pcpa => 2 thing2 = Thing.create! :nte_no => 2, vaat_id_type_statut_pcpa => 3 Thing.find_by_thingy(1,2).should == thing1 Thing.find_by_thingy(2,3).should == thing2 end If you have a way of generating "things" that are valid, then I'd use that mechanism and pass in the attributes you are specifically going to be testing against (so they stand out in the example that that's what matters in the example). I know the above example breaks the one assertion per test guideline people strive to adhere to, but I think it is ok. If there are more examples that should be used to make sure find_thingy works then I'd break out a separate describe block and have multiple 'it' examples, -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at mattwynne.net Thu Oct 30 12:41:33 2008 From: matt at mattwynne.net (Matt Wynne) Date: Thu, 30 Oct 2008 16:41:33 +0000 Subject: [rspec-users] spec'ing the :conditions argument of a find In-Reply-To: <85d99afe0810300858w52a570a1y3a8c62e68e9737d8@mail.gmail.com> References: <8c1f77e6c2101d37f60d4256f919927a@ruby-forum.com> <6bf50a9f989ada06af0e8b0427d685e4@ruby-forum.com> <85d99afe0810300858w52a570a1y3a8c62e68e9737d8@mail.gmail.com> Message-ID: <76130096-C3C4-4B29-992E-DC27D4E8C694@mattwynne.net> On 30 Oct 2008, at 15:58, Zach Dennis wrote: > I know the above example breaks the one assertion per test guideline > people strive to adhere to, but I think it is ok. If there are more > examples that should be used to make sure find_thingy works then I'd > break out a separate describe block and have multiple 'it' examples, It also goes to the database, which will make it a slow unit test. I personally do pretty much the same thing myself mostly when working with ActiveRecord, but it doesn't mean I'm comfortable with it. (And it also doesn't mean our unit test suite is anything other than shamefully slow) I did experiment with a QueryApapter for this purpose which has worked out quite well for us. You end up with code like this in the Controller: products = Product.find(:all, Product::QueryAdapter.new(params).adapt) You then have a QueryAdapter class to test which is solely responsible for mapping web query params into database query params - so that's where you put the logic to build your conditions, your limit etc, and return them as a hash from QueryAdapter#adapt. The family of QueryAdapters then become the one place where I'm coupled to ActiveRecord's find method arguments, which is nice, rather than having it sprinkled all over the controller code. HTH, Matt From zach.dennis at gmail.com Thu Oct 30 13:00:56 2008 From: zach.dennis at gmail.com (Zach Dennis) Date: Thu, 30 Oct 2008 13:00:56 -0400 Subject: [rspec-users] spec'ing the :conditions argument of a find In-Reply-To: <76130096-C3C4-4B29-992E-DC27D4E8C694@mattwynne.net> References: <8c1f77e6c2101d37f60d4256f919927a@ruby-forum.com> <6bf50a9f989ada06af0e8b0427d685e4@ruby-forum.com> <85d99afe0810300858w52a570a1y3a8c62e68e9737d8@mail.gmail.com> <76130096-C3C4-4B29-992E-DC27D4E8C694@mattwynne.net> Message-ID: <85d99afe0810301000i11f3d91ewd50f63a540c69dae@mail.gmail.com> On Thu, Oct 30, 2008 at 12:41 PM, Matt Wynne wrote: > On 30 Oct 2008, at 15:58, Zach Dennis wrote: > >> I know the above example breaks the one assertion per test guideline >> people strive to adhere to, but I think it is ok. If there are more >> examples that should be used to make sure find_thingy works then I'd break >> out a separate describe block and have multiple 'it' examples, >> > > It also goes to the database, which will make it a slow unit test. I > personally do pretty much the same thing myself mostly when working with > ActiveRecord, but it doesn't mean I'm comfortable with it. (And it also > doesn't mean our unit test suite is anything other than shamefully slow) It will make it a *slower* unit test. I am yet to be convinced that when working with ActiveRecord, it is worthwhile to not hit the database when you trying to verify that custom queries are working correctly. I have yet to see model examples which were so slow I didn't want to run them. I get more confidence and value out of knowing custom queries work at the model example level, rather than waiting for an acceptance test to trigger their failure. I do get value out of not hitting the database for things that I don't need to hit it for, but custom finds aren't one of those things IMO. It's also easier to track down the failure and fix it at the model example level, rather than having to truck through acceptance test backtraces, log files, etc to find that you had a typo in your custom finder. For the record, my definition of custom apples to handcrafted SQL as well as handcrafted conditions, scopes, joins, etc that are used when creating find methods which encapsulate this logic (such as find_thingy 1, 2) -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From aidy.lewis at googlemail.com Thu Oct 30 13:02:44 2008 From: aidy.lewis at googlemail.com (aidy lewis) Date: Thu, 30 Oct 2008 17:02:44 +0000 Subject: [rspec-users] After a step fails, if successive steps have been executed and passed, cucumber reports them as skipped Message-ID: <7ac2300c0810301002x6118208fs91f81817e7c71a38@mail.gmail.com> Hi, I have a Given step that fails: For that Scenario the remaining Given's, When, and Then's are reported as being skipped, even though theses steps have been executed. Why I am not submitting this to Lighthouse, is that I believe, this may be intentional design. However, would it not be more indicative to have these steps "pass" for example, if the successive steps have executed and passed? Aidy From dchelimsky at gmail.com Thu Oct 30 13:07:17 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 30 Oct 2008 12:07:17 -0500 Subject: [rspec-users] After a step fails, if successive steps have been executed and passed, cucumber reports them as skipped In-Reply-To: <7ac2300c0810301002x6118208fs91f81817e7c71a38@mail.gmail.com> References: <7ac2300c0810301002x6118208fs91f81817e7c71a38@mail.gmail.com> Message-ID: <57c63afe0810301007p76fb221cpc21bc6bbcc1155cc@mail.gmail.com> On Thu, Oct 30, 2008 at 12:02 PM, aidy lewis wrote: > Hi, > > I have a Given step that fails: For that Scenario the remaining > Given's, When, and Then's are reported as being skipped, even though > theses steps have been executed. > > Why I am not submitting this to Lighthouse, is that I believe, this > may be intentional design. > > However, would it not be more indicative to have these steps "pass" > for example, if the successive steps have executed and passed? This is absolutely by design. If a step passes or fails after another has failed, you have no way of knowing if it would still pass or fail once the other one is passing. Cucumber reports the first problem in a scenario so you can fix that one and move on. Cheers, David > > Aidy > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From sfeley at gmail.com Thu Oct 30 15:18:09 2008 From: sfeley at gmail.com (Stephen Eley) Date: Thu, 30 Oct 2008 14:18:09 -0500 Subject: [rspec-users] After a step fails, if successive steps have been executed and passed, cucumber reports them as skipped In-Reply-To: <57c63afe0810301007p76fb221cpc21bc6bbcc1155cc@mail.gmail.com> References: <7ac2300c0810301002x6118208fs91f81817e7c71a38@mail.gmail.com> <57c63afe0810301007p76fb221cpc21bc6bbcc1155cc@mail.gmail.com> Message-ID: <1fb4df0810301218r1640e790l1fbd279143087d6e@mail.gmail.com> On Thu, Oct 30, 2008 at 12:07 PM, David Chelimsky wrote: > > This is absolutely by design. If a step passes or fails after another > has failed, you have no way of knowing if it would still pass or fail > once the other one is passing. Cucumber reports the first problem in a > scenario so you can fix that one and move on. I'm curious: what's the logic behind it not just stopping there? -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org From pergesu at gmail.com Thu Oct 30 15:31:40 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 30 Oct 2008 12:31:40 -0700 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <57c63afe0810300646p456cbadcl209465adf1502de3@mail.gmail.com> (David Chelimsky's message of "Thu\, 30 Oct 2008 08\:46\:49 -0500") References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <010F2227-9AA8-406A-8097-81D83D7E96E4@mattwynne.net> <57c63afe0810300646p456cbadcl209465adf1502de3@mail.gmail.com> Message-ID: "David Chelimsky" writes: > On Thu, Oct 30, 2008 at 5:20 AM, Matt Wynne wrote: >> On 27 Oct 2008, at 16:35, Pat Maddox wrote: >> >>> Matt Wynne writes: >>> >>>> Pat - are you going solo too? >>> >>> Nope, I'm trying to teach RSpec/BDD to an organization that currently >>> doesn't use it and has 0% test coverage. It's interesting, to say the >>> least. They're good devs, but even so, the effects of not writing tests >>> first (or even at all) are painfully evident when trying to get the >>> codebase under test, and especially to change stuff. Really puts your >>> "working effectively with legacy code" chops to work :) >> >> :D >> >> This reminds me of an argument I was going to make for consistently writing >> specs as you go, even for apparently very simple controllers. As the >> controller gets more and more complex, it's hard to know when you've crossed >> the line into something that needs specs, and when you realise it, it's >> usually too late. > > I'd agree with this (in spite of my previous comments), and add to it. > > One of the benefits of writing examples is that they actually help to > expose things that are growing complex. If it's hard to test, it's > probably hard to change. > > Aslak made a good point earlier this thread with "don't write specs > just cuz," but perhaps this fact is sufficient "cuz" to motivate. > > WDYT? eh I dunno. I mean, I completely agree that hard-to-write tests often expose bad code. But there isn't any gray area when it comes to designing Rails controllers, in my opinion. I see an action that's more than five lines long and I know it's wrong. I don't need to write examples to tell me that. That said, when teaching someone I suppose it would make sense to use examples to illustrate that, at least until they develop an aesthetic appreciation as finely tuned as my own :P Pat From dchelimsky at gmail.com Thu Oct 30 15:32:26 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 30 Oct 2008 14:32:26 -0500 Subject: [rspec-users] After a step fails, if successive steps have been executed and passed, cucumber reports them as skipped In-Reply-To: <1fb4df0810301218r1640e790l1fbd279143087d6e@mail.gmail.com> References: <7ac2300c0810301002x6118208fs91f81817e7c71a38@mail.gmail.com> <57c63afe0810301007p76fb221cpc21bc6bbcc1155cc@mail.gmail.com> <1fb4df0810301218r1640e790l1fbd279143087d6e@mail.gmail.com> Message-ID: <57c63afe0810301232l44e80487y13019c676cb6ba0e@mail.gmail.com> On Thu, Oct 30, 2008 at 2:18 PM, Stephen Eley wrote: > On Thu, Oct 30, 2008 at 12:07 PM, David Chelimsky wrote: >> >> This is absolutely by design. If a step passes or fails after another >> has failed, you have no way of knowing if it would still pass or fail >> once the other one is passing. Cucumber reports the first problem in a >> scenario so you can fix that one and move on. > > I'm curious: what's the logic behind it not just stopping there? Pending steps (post failure) are still reported as pending, so it gives you a sense of where you are in process. Make sense? > > > -- > Have Fun, > Steve Eley (sfeley at gmail.com) > ESCAPE POD - The Science Fiction Podcast Magazine > http://www.escapepod.org > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From pergesu at gmail.com Thu Oct 30 16:05:53 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 30 Oct 2008 13:05:53 -0700 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: <59463643-A080-4C60-83E8-C54B49CCAAE5@railsnewbie.com> (Scott Taylor's message of "Thu\, 30 Oct 2008 02\:30\:07 -0400") References: <57c63afe0810292317j769e2bc7ve9810973258742e7@mail.gmail.com> <59463643-A080-4C60-83E8-C54B49CCAAE5@railsnewbie.com> Message-ID: Scott Taylor writes: > Actually, I take back my previous comment. Where would you stub a > method on an object where the method *isn't* even loaded by further > (or previous) stubbing? > > Any concrete examples come to mind? How about if you haven't implemented that object yet? Pat From pergesu at gmail.com Thu Oct 30 16:11:11 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 30 Oct 2008 13:11:11 -0700 Subject: [rspec-users] spec'ing the :conditions argument of a find In-Reply-To: <76130096-C3C4-4B29-992E-DC27D4E8C694@mattwynne.net> (Matt Wynne's message of "Thu\, 30 Oct 2008 16\:41\:33 +0000") References: <8c1f77e6c2101d37f60d4256f919927a@ruby-forum.com> <6bf50a9f989ada06af0e8b0427d685e4@ruby-forum.com> <85d99afe0810300858w52a570a1y3a8c62e68e9737d8@mail.gmail.com> <76130096-C3C4-4B29-992E-DC27D4E8C694@mattwynne.net> Message-ID: Matt Wynne writes: > On 30 Oct 2008, at 15:58, Zach Dennis wrote: >> I know the above example breaks the one assertion per test guideline >> people strive to adhere to, but I think it is ok. If there are more >> examples that should be used to make sure find_thingy works then I'd >> break out a separate describe block and have multiple 'it' examples, > > It also goes to the database, which will make it a slow unit test. I > personally do pretty much the same thing myself mostly when working > with ActiveRecord, but it doesn't mean I'm comfortable with it. (And > it also doesn't mean our unit test suite is anything other than > shamefully slow) > > I did experiment with a QueryApapter for this purpose which has worked > out quite well for us. You end up with code like this in the > Controller: Scott is working on a SQL parser which would let you write tests that "hit" the db but keep everything in memory and fast. Might be worth checking out for you. Pat From dchelimsky at gmail.com Thu Oct 30 16:18:07 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Thu, 30 Oct 2008 15:18:07 -0500 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: References: <57c63afe0810292317j769e2bc7ve9810973258742e7@mail.gmail.com> <59463643-A080-4C60-83E8-C54B49CCAAE5@railsnewbie.com> Message-ID: <57c63afe0810301318m678d1e1au53c7091826955ad@mail.gmail.com> On Thu, Oct 30, 2008 at 3:05 PM, Pat Maddox wrote: > Scott Taylor writes: > >> Actually, I take back my previous comment. Where would you stub a >> method on an object where the method *isn't* even loaded by further >> (or previous) stubbing? >> >> Any concrete examples come to mind? > > How about if you haven't implemented that object yet? +1000 > > Pat > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From mailing_lists at railsnewbie.com Thu Oct 30 16:24:46 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 30 Oct 2008 16:24:46 -0400 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: References: <57c63afe0810292317j769e2bc7ve9810973258742e7@mail.gmail.com> <59463643-A080-4C60-83E8-C54B49CCAAE5@railsnewbie.com> Message-ID: On Oct 30, 2008, at 4:05 PM, Pat Maddox wrote: > Scott Taylor writes: > >> Actually, I take back my previous comment. Where would you stub a >> method on an object where the method *isn't* even loaded by further >> (or previous) stubbing? >> >> Any concrete examples come to mind? > > How about if you haven't implemented that object yet? It would only work if given a concrete class name (i.e. mock(Foo) as opposed to mock('foo')) No idea why you couldn't pass a flag for regression testing: mock(Foo, :check_methods => true) Scott From mailing_lists at railsnewbie.com Thu Oct 30 16:26:07 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 30 Oct 2008 16:26:07 -0400 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: References: <57c63afe0810292317j769e2bc7ve9810973258742e7@mail.gmail.com> <59463643-A080-4C60-83E8-C54B49CCAAE5@railsnewbie.com> Message-ID: On Oct 30, 2008, at 4:05 PM, Pat Maddox wrote: > Scott Taylor writes: > >> Actually, I take back my previous comment. Where would you stub a >> method on an object where the method *isn't* even loaded by further >> (or previous) stubbing? >> >> Any concrete examples come to mind? > > How about if you haven't implemented that object yet? Of course, this also depends on what context. Often in Rails I find myself using mocks when I have no need to - the dependent object is already built, and I'm using a mock just so that I don't hit the database at all. Scott From lenny at aps.org Thu Oct 30 16:35:35 2008 From: lenny at aps.org (Lenny Marks) Date: Thu, 30 Oct 2008 16:35:35 -0400 Subject: [rspec-users] stub followed by should_receive behavior changed Message-ID: I'm in the process of trying to get updated to rspec-1.1.11(from 1.1.1). I have a couple of places where I was trying to verify that a particular collaboration was made inside a transaction. My general strategy was to start off using something like Transaction.stub! (:execute).and_yield in a before block. Then in the specs to verify execution within a transaction I would override the stub with Transaction.should_receive(:execute), no and_yield, and check the collaborations did not occur. Unfortunately this doesn't work anymore and I'm not sure if that was intentional or not. The following example passes in 1.1.1 but not in 1.1.11. Also open to better approaches. Thanks, -lenny class Klass def transaction raise "error from implementation" yield end end describe "when using a stub with and_yield" do before do @klass = Klass.new @klass.stub!(:transaction).and_yield end it "should yield without explicit expectation" do Proc.new do @klass.transaction { raise "error from yield" } end.should raise_error("error from yield") end it "should not yield with explicit expectation without and_yield" do @klass.should_receive(:transaction) @klass.transaction { raise "error from yield" } end end From pergesu at gmail.com Thu Oct 30 17:29:27 2008 From: pergesu at gmail.com (Pat Maddox) Date: Thu, 30 Oct 2008 14:29:27 -0700 Subject: [rspec-users] stub followed by should_receive behavior changed In-Reply-To: References: Message-ID: <810a540e0810301429l50b7f91awafb8074c131b1e12@mail.gmail.com> You're right, the behavior did change. Now when you have a should_receive that shadows a previous stub, it returns or yields the original value. I don't know a way to turn off the yielding in the should_receive, I'll look at putting something in. In the mean time, if you stub the method again with no yield value, and then expect it, it ought to work Pat On 10/30/08, Lenny Marks wrote: > I'm in the process of trying to get updated to rspec-1.1.11(from > 1.1.1). I have a couple of places where I was trying to verify that a > particular collaboration was made inside a transaction. My general > strategy was to start off using something like Transaction.stub! > (:execute).and_yield in a before block. Then in the specs to verify > execution within a transaction I would override the stub with > Transaction.should_receive(:execute), no and_yield, and check the > collaborations did not occur. Unfortunately this doesn't work anymore > and I'm not sure if that was intentional or not. The following > example passes in 1.1.1 but not in 1.1.11. Also open to better > approaches. > > Thanks, > -lenny > > class Klass > def transaction > raise "error from implementation" > yield > end > end > > describe "when using a stub with and_yield" do > > before do > @klass = Klass.new > @klass.stub!(:transaction).and_yield > end > > it "should yield without explicit expectation" do > Proc.new do > @klass.transaction { raise "error from yield" } > end.should raise_error("error from yield") > end > > it "should not yield with explicit expectation without and_yield" do > > @klass.should_receive(:transaction) > > @klass.transaction { raise "error from yield" } > > > end > end > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > From lists at ruby-forum.com Thu Oct 30 19:52:27 2008 From: lists at ruby-forum.com (Sebastian W.) Date: Fri, 31 Oct 2008 00:52:27 +0100 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: References: <57c63afe0810292317j769e2bc7ve9810973258742e7@mail.gmail.com> <59463643-A080-4C60-83E8-C54B49CCAAE5@railsnewbie.com> Message-ID: <86e194aaa9d58c706b04879785e2cf51@ruby-forum.com> > No idea why you couldn't pass a flag for regression testing: > > mock(Foo, :check_methods => true) > > Scott It seems to me this way, too - though I'm obviously biased. :) It's true that a lot of the dynamic stuff could be problematic - what if the flag was only for checking methods directly implemented on that class? Though I guess that'd lead down a potential dark path where you'd then also want the "mock" method to potentially check all mixins and validate, etc. etc. On the other hand, maybe it could serve as a gentle remonstrance to folks to not overdo it with the "i am an 3l337 ninj4 haxx0r" metaprogramming? Just a thought. -- Posted via http://www.ruby-forum.com/. From lists at ruby-forum.com Thu Oct 30 20:21:43 2008 From: lists at ruby-forum.com (Evan Dorn) Date: Fri, 31 Oct 2008 01:21:43 +0100 Subject: [rspec-users] Help: Attempts to run specs quitting midstream Message-ID: <33f88a58f1ded34c375b1cf1be54b818@ruby-forum.com> I am having a very frustrating problem running specs on my current project. When I run tests en masse with "rake spec" or with autotest, it frequently quits without completing all the tests. It also sometimes runs the tests in multiple batches, giving more than one result line for a single batch of tests. For example, on my current project (which has in total 524 examples), it currently runs a batch of 31 examples (with 0 failures), outputs a result line, then runs a batch of 131 examples (with 3 failures), outputs a result line, then reports "rake aborted" with "command failed". If I put --reverse in spec.opts, it quits in a different place after a different number of specs. If I run with --trace, it reports that the final complaint is in spectask.rb line 177. This is a line that looks for error results when it executes the command with system(). As far as I can tell, there is no way for me to know which spec file was actually executing when it quit. Very frustrating. System information: OS X 10.5.5 Ruby 1.8.6 rspec 1.1.11 Below is an shell transcript. If this had run successfully, there would be 524 examples run, instead of 31 and then 131. The particular numbers change as I edit my files. Thanks for any help, I'm tearing my hair out here. -Evan ------------------- [17:16:12] unithrive$ rake spec --trace (in /Users/evan/Development/Ruby/unithrive) ** Invoke spec (first_time) ** Invoke db:test:prepare (first_time) ** Invoke environment (first_time) ** Execute environment ** Invoke db:abort_if_pending_migrations (first_time) ** Invoke environment ** Execute db:abort_if_pending_migrations ** Execute db:test:prepare ** Invoke db:test:clone (first_time) ** Invoke db:schema:dump (first_time) ** Invoke environment ** Execute db:schema:dump ** Invoke db:test:purge (first_time) ** Invoke environment ** Execute db:test:purge ** Execute db:test:clone ** Invoke db:schema:load (first_time) ** Invoke environment ** Execute db:schema:load ** Execute spec ...........................................................................................................................F.FF.... 1) 'LoanRequestsController responding to GET /loan_requests/new step 1 should assign step 1' FAILED expected: 1, got: nil (using ==) ./spec/controllers/loan_requests_controller_spec.rb:130: 2) NoMethodError in 'LoanRequestsController responding to GET /loan_requests/new step 1 should create a new loan_request' You have a nil object when you didn't expect it! The error occurred while evaluating nil.step /Users/evan/Development/Ruby/unithrive/app/controllers/loan_requests_controller.rb:29:in `new' /Users/evan/Development/Ruby/unithrive/app/controllers/loan_requests_controller.rb:28:in `new' ./spec/controllers/loan_requests_controller_spec.rb:140: 3) Spec::Mocks::MockExpectationError in 'LoanRequestsController responding to GET /loan_requests/new step 1 should assign the new loan_request for the view' Mock 'LoanRequest_1032' received unexpected message :step with (no args) /Users/evan/Development/Ruby/unithrive/app/controllers/loan_requests_controller.rb:29:in `new' /Users/evan/Development/Ruby/unithrive/app/controllers/loan_requests_controller.rb:28:in `new' ./spec/controllers/loan_requests_controller_spec.rb:145: Finished in 6.80498 seconds 131 examples, 3 failures ............................... Finished in 1.785438 seconds 31 examples, 0 failures rake aborted! Command /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"/Users/evan/Development/Ruby/unithrive/vendor/plugins/rspec/lib" "/Users/evan/Development/Ruby/unithrive/vendor/plugins/rspec/bin/spec" "spec/controllers/activities_controller_spec.rb" "spec/controllers/admin/forums_controller_spec.rb" "spec/controllers/admin/people_controller_spec.rb" "spec/controllers/admin/preferences_controller_spec.rb" "spec/controllers/advanced_searches_controller_spec.rb" "spec/controllers/advanced_searches_routing_spec.rb" "spec/controllers/comments_controller_spec.rb" "spec/controllers/connections_controller_spec.rb" "spec/controllers/forums_controller_spec.rb" "spec/controllers/home_controller_spec.rb" "spec/controllers/loan_requests_controller_spec.rb" "spec/controllers/loan_requests_routing_spec.rb" "spec/controllers/messages_controller_spec.rb" "spec/controllers/password_reminders_controller_spec.rb" "spec/controllers/people_controller_spec.rb" "spec/controllers/photos_controller_spec.rb" "spec/controllers/posts_controller_spec.rb" "spec/controllers/searches_controller_spec.rb" "spec/controllers/sessions_controller_spec.rb" "spec/controllers/topics_controller_spec.rb" "spec/helpers/activities_helper_spec.rb" "spec/helpers/advanced_searches_helper_spec.rb" "spec/helpers/comments_helper_spec.rb" "spec/helpers/communications_helper_spec.rb" "spec/helpers/connections_helper_spec.rb" "spec/helpers/forums_helper_spec.rb" "spec/helpers/loan_requests_helper_spec.rb" "spec/helpers/posts_helper_spec.rb" "spec/helpers/preferences_helper_spec.rb" "spec/helpers/searches_helper_spec.rb" "spec/helpers/topics_helper_spec.rb" "spec/models/activity_spec.rb" "spec/models/advanced_search_spec.rb" "spec/models/blog_post_spec.rb" "spec/models/blog_spec.rb" "spec/models/comment_spec.rb" "spec/models/connection_spec.rb" "spec/models/conversation_spec.rb" "spec/models/email_verification_spec.rb" "spec/models/feed_spec.rb" "spec/models/forum_post_spec.rb" "spec/models/forum_spec.rb" "spec/models/loan_request_spec.rb" "spec/models/message_spec.rb" "spec/models/person_mailer_spec.rb" "spec/models/person_spec.rb" "spec/models/photo_spec.rb" "spec/models/preference_spec.rb" "spec/models/topic_spec.rb" "spec/views/advanced_searches/edit.html.erb_spec.rb" "spec/views/advanced_searches/index.html.erb_spec.rb" "spec/views/advanced_searches/new.html.erb_spec.rb" "spec/views/advanced_searches/show.html.erb_spec.rb" "spec/views/layouts/application.html.erb_spec.rb" "spec/views/loan_requests/edit.html.erb_spec.rb" "spec/views/loan_requests/index.html.erb_spec.rb" "spec/views/loan_requests/new.html.erb_spec.rb" "spec/views/loan_requests/show.html.erb_spec.rb" "spec/views/people/show.html.erb_spec.rb" --options "/Users/evan/Development/Ruby/unithrive/spec/spec.opts" failed /Users/evan/Development/Ruby/unithrive/vendor/plugins/rspec/lib/spec/rake/spectask.rb:177:in `define' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1003:in `verbose' /Users/evan/Development/Ruby/unithrive/vendor/plugins/rspec/lib/spec/rake/spectask.rb:153:in `define' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in `invoke_task' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run' /Library/Ruby/Gems/1.8/gems/rake-0.8.1/bin/rake:31 /usr/bin/rake:19:in `load' /usr/bin/rake:19 -- Posted via http://www.ruby-forum.com/. From mailing_lists at railsnewbie.com Thu Oct 30 21:23:31 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 30 Oct 2008 21:23:31 -0400 Subject: [rspec-users] Help: Attempts to run specs quitting midstream In-Reply-To: <33f88a58f1ded34c375b1cf1be54b818@ruby-forum.com> References: <33f88a58f1ded34c375b1cf1be54b818@ruby-forum.com> Message-ID: <34EB771B-DED1-4031-A242-F2FC81AE761E@railsnewbie.com> On Oct 30, 2008, at 8:21 PM, Evan Dorn wrote: > I am having a very frustrating problem running specs on my current > project. When I run tests en masse with "rake spec" or with autotest, > it frequently quits without completing all the tests. It also > sometimes runs the tests in multiple batches, giving more than one > result line for a single batch of tests. > > For example, on my current project (which has in total 524 > examples), it > currently runs a batch of 31 examples (with 0 failures), outputs a > result line, then runs a batch of 131 examples (with 3 failures), > outputs a result line, then reports "rake aborted" with "command > command here> failed". > > If I put --reverse in spec.opts, it quits in a different place after a > different number of specs. > > If I run with --trace, it reports that the final complaint is in > spectask.rb line 177. This is a line that looks for error results > when > it executes the command with system(). > > As far as I can tell, there is no way for me to know which spec file > was > actually executing when it quit. Very frustrating. > > System information: > OS X 10.5.5 > Ruby 1.8.6 > rspec 1.1.11 > > > Below is an shell transcript. If this had run successfully, there > would be 524 examples run, instead of 31 and then 131. The > particular > numbers change as I edit my files. > > Thanks for any help, I'm tearing my hair out here. I'd file this bug report at lighthouse: http://rspec.lighthouseapp.com/dashboard Scott From mailing_lists at railsnewbie.com Thu Oct 30 21:24:14 2008 From: mailing_lists at railsnewbie.com (Scott Taylor) Date: Thu, 30 Oct 2008 21:24:14 -0400 Subject: [rspec-users] Mocks and Refactoring - doing it wrong? In-Reply-To: <86e194aaa9d58c706b04879785e2cf51@ruby-forum.com> References: <57c63afe0810292317j769e2bc7ve9810973258742e7@mail.gmail.com> <59463643-A080-4C60-83E8-C54B49CCAAE5@railsnewbie.com> <86e194aaa9d58c706b04879785e2cf51@ruby-forum.com> Message-ID: <6D3B0233-51F7-4083-B95A-44FDF12F1EEF@railsnewbie.com> On Oct 30, 2008, at 7:52 PM, Sebastian W. wrote: >> No idea why you couldn't pass a flag for regression testing: >> >> mock(Foo, :check_methods => true) >> >> Scott > > It seems to me this way, too - though I'm obviously biased. :) > > It's true that a lot of the dynamic stuff could be problematic - > what if > the flag was only for checking methods directly implemented on that > class? Though I guess that'd lead down a potential dark path where > you'd > then also want the "mock" method to potentially check all mixins and > validate, etc. etc. > > On the other hand, maybe it could serve as a gentle remonstrance to > folks to not overdo it with the "i am an 3l337 ninj4 haxx0r" > metaprogramming? Just a thought. +1 Tests *are* supposed to influence the way we write production code. Scott From matt at mattwynne.net Fri Oct 31 03:49:25 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 31 Oct 2008 07:49:25 +0000 Subject: [rspec-users] spec'ing the :conditions argument of a find In-Reply-To: References: <8c1f77e6c2101d37f60d4256f919927a@ruby-forum.com> <6bf50a9f989ada06af0e8b0427d685e4@ruby-forum.com> <85d99afe0810300858w52a570a1y3a8c62e68e9737d8@mail.gmail.com> <76130096-C3C4-4B29-992E-DC27D4E8C694@mattwynne.net> Message-ID: <8E053474-34E5-4753-866D-DF549A06EFE3@mattwynne.net> On 30 Oct 2008, at 20:11, Pat Maddox wrote: > Matt Wynne writes: > >> On 30 Oct 2008, at 15:58, Zach Dennis wrote: >>> I know the above example breaks the one assertion per test guideline >>> people strive to adhere to, but I think it is ok. If there are more >>> examples that should be used to make sure find_thingy works then I'd >>> break out a separate describe block and have multiple 'it' examples, >> >> It also goes to the database, which will make it a slow unit test. I >> personally do pretty much the same thing myself mostly when working >> with ActiveRecord, but it doesn't mean I'm comfortable with it. (And >> it also doesn't mean our unit test suite is anything other than >> shamefully slow) >> >> I did experiment with a QueryApapter for this purpose which has >> worked >> out quite well for us. You end up with code like this in the >> Controller: > > Scott is working on a SQL parser which would let you write tests that > "hit" the db but keep everything in memory and fast. Might be worth > checking out for you. Sounds interesting. I'd still like to see us have a proper ORM for ruby that lets us play with POROs 90% of the time, and just have a separate suite of tests for the database-object mappings that we run when necessary. cheers, Matt From ashley.moran at patchspace.co.uk Fri Oct 31 04:24:03 2008 From: ashley.moran at patchspace.co.uk (Ashley Moran) Date: Fri, 31 Oct 2008 08:24:03 +0000 Subject: [rspec-users] spec'ing the :conditions argument of a find In-Reply-To: <8E053474-34E5-4753-866D-DF549A06EFE3@mattwynne.net> References: <8c1f77e6c2101d37f60d4256f919927a@ruby-forum.com> <6bf50a9f989ada06af0e8b0427d685e4@ruby-forum.com> <85d99afe0810300858w52a570a1y3a8c62e68e9737d8@mail.gmail.com> <76130096-C3C4-4B29-992E-DC27D4E8C694@mattwynne.net> <8E053474-34E5-4753-866D-DF549A06EFE3@mattwynne.net> Message-ID: On Oct 31, 2008, at 7:49 am, Matt Wynne wrote: >>> It also goes to the database, which will make it a slow unit test. I >>> personally do pretty much the same thing myself mostly when working >>> with ActiveRecord, but it doesn't mean I'm comfortable with it. (And >>> it also doesn't mean our unit test suite is anything other than >>> shamefully slow) > > > > Sounds interesting. I'd still like to see us have a proper ORM for > ruby that lets us play with POROs 90% of the time, and just have a > separate suite of tests for the database-object mappings that we run > when necessary. I'm using DataMapper in a (non-web) project I have on now, and for part of the spec suite where I am concerned with persistence as a black-box, I create an in-memory SQLite database: # story_spec.rb describe "Class", Story do # ... describe ".unposted" do include InMemoryDatabase before(:each) do setup_in_memory_database @twitter_client = mock(TwitterAgent::Client, :post_story => true) @story_1 = Story.create(:title => "Story title 1", :published_at => DateTime.new(2008, 9, 28)) @story_2 = Story.create(:title => "Story title 2", :published_at => DateTime.new(2008, 9, 29)) @story_3 = Story.create(:title => "Story title 3", :published_at => DateTime.new(2008, 9, 27)) end it "should find all stories (in ascending published date) when none have been posted" do Story.unposted.should == [ @story_3, @story_1, @story_2 ] end it "should find only unpublished stories (in ascending published date)" do @story_1.post_to_twitter!(@twitter_client) Story.unposted.should == [ @story_3, @story_2 ] end end end # spec_helper.rb module InMemoryDatabase def setup_in_memory_database DataMapper.setup(:default, "sqlite3::memory:") Database::Migrator.new.reset_database! end end Aside from being unable to use DB-lever constraints, that gives me enough confidence in the persistence. Other specs that don't need persistence simply omit the "setup_in_memory_database" call. It's important not to lose sight of the fact that, even though ActiveRecord mixes business logic and persistence, *they are still separate concerns*. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/ From matt at mattwynne.net Fri Oct 31 05:36:28 2008 From: matt at mattwynne.net (Matt Wynne) Date: Fri, 31 Oct 2008 09:36:28 +0000 Subject: [rspec-users] described_type Message-ID: <2F793D35-C491-46B8-8BF2-3EB8FEF1A17F@mattwynne.net> I heard somebody mention described_type the other day, so I thought I'd give it a spin. It doesn't seem to behave as I'm expecting though. I have a method which generates examples to verify AR associations: def it_should_have_many(klass, association, opts = {}) it "should relate to #{association}" do klass.reflect_on_association(association).should_not be_nil end it "should have many #{association}" do klass.reflect_on_association(association).macro.should == :has_many end if opts[:as] it "should relate to #{association} as :subject" do klass.reflect_on_association(association).options[:as].should == opts[:as] end end end So at the moment, I have to call it like this: it_should_have_many Post, :attachments, :as => :comments Which is a bit ugly. I figured I could use described_type instead of klass in the example-generating method, but it doesn't work: undefined local variable or method `described_type' for #< Spec ::Rails ::Example ::ModelExampleGroup::Subclass_1::Subclass_1::Subclass_1:0x21518bc> What dumb thing am I doing wrong? cheers, Matt From pergesu at gmail.com Fri Oct 31 06:50:30 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 31 Oct 2008 03:50:30 -0700 Subject: [rspec-users] described_type In-Reply-To: <2F793D35-C491-46B8-8BF2-3EB8FEF1A17F@mattwynne.net> (Matt Wynne's message of "Fri\, 31 Oct 2008 09\:36\:28 +0000") References: <2F793D35-C491-46B8-8BF2-3EB8FEF1A17F@mattwynne.net> Message-ID: Matt Wynne writes: > I figured I could use described_type instead of > klass in the example-generating method, but it doesn't work: > > undefined local variable or method `described_type' for #< > Spec ::Rails ::Example > ::ModelExampleGroup::Subclass_1::Subclass_1::Subclass_1:0x21518bc> > > What dumb thing am I doing wrong? self.class.described_type Pat From lists at ruby-forum.com Fri Oct 31 13:26:17 2008 From: lists at ruby-forum.com (Harry Bishop) Date: Fri, 31 Oct 2008 18:26:17 +0100 Subject: [rspec-users] testing a render layout statement in a controller In-Reply-To: <19EC77D3-45A5-4541-AC47-106577D30CF3@gmail.com> References: <48F6E433.9020405@gmail.com> <19EC77D3-45A5-4541-AC47-106577D30CF3@gmail.com> Message-ID: Bart Zonneveld wrote: > On 16-okt-2008, at 8:50, Dave Gamphani Phiri wrote: > >> Here, I was trying to test if the out put displays with a layouts/menu >> template. >> Can somebody help on how you test the render(:layout => "layouts/ >> menu") statement in a controller or this is supposed to be tested in >> the view? > > Try this: > > render(:layout => "layouts/menu") and return > > cheers, > bartz Thanks Bartz, I used your input to try a controller line of format.html { render :action => "show" } and rspec of response.should render_template( :(controller name) => "/show") I tried it with and without the "and return" and both worked. Harry -- Posted via http://www.ruby-forum.com/. From nick at deadorange.com Fri Oct 31 16:54:42 2008 From: nick at deadorange.com (Nick Hoffman) Date: Fri, 31 Oct 2008 16:54:42 -0400 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <010F2227-9AA8-406A-8097-81D83D7E96E4@mattwynne.net> <57c63afe0810300646p456cbadcl209465adf1502de3@mail.gmail.com> Message-ID: <364B2A62-F8E2-4159-924E-878B29E2AC3C@deadorange.com> On 2008-10-30, at 15:31, Pat Maddox wrote: > eh I dunno. I mean, I completely agree that hard-to-write tests often > expose bad code. But there isn't any gray area when it comes to > designing Rails controllers, in my opinion. I see an action that's > more > than five lines long and I know it's wrong. I don't need to write > examples to tell me that. Hi Pat. Would you mind suggesting how I can make this 22-line action a bit shorter? =) http://refactormycode.com/codes/575-dry-up-a-controller-action Thanks! Nick From matt at matt-darby.com Fri Oct 31 17:34:59 2008 From: matt at matt-darby.com (Matt Darby) Date: Fri, 31 Oct 2008 17:34:59 -0400 Subject: [rspec-users] Fwd: spec_server not working... References: <1ED09426-C779-49AE-86D1-E1DD102D6C84@matt-darby.com> Message-ID: <4AE03859-BEC1-4ACF-AF91-AE189D8386CB@matt-darby.com> I can't seem to get spec_server to work correctly (I've never used it before, so maybe I'm missing something?) I start up spec_server as prescribed: mdarby at macbook:~/Documents/apps/CCW: rake spec:server:start (in /Users/mdarby/Documents/Apps/CCW) Starting up spec server. Loading Rails environment Ready spec_server launched. (PID: 31387) Then I try to run a spec and it times out after about thirty seconds: mdarby at macbook:~/Documents/apps/CCW: ./script/spec --drb spec/models/ job_spec.rb No server is running ^C/usr/local/lib/ruby/1.8/drb/drb.rb:566:in `read': Interrupt from /usr/local/lib/ruby/1.8/drb/drb.rb:566:in `load' from /usr/local/lib/ruby/1.8/drb/drb.rb:632:in `recv_reply' from /usr/local/lib/ruby/1.8/drb/drb.rb:923:in `recv_reply' from /usr/local/lib/ruby/1.8/drb/drb.rb:1202:in `send_message' from /usr/local/lib/ruby/1.8/drb/drb.rb:1093:in `method_missing' from /usr/local/lib/ruby/1.8/drb/drb.rb:1177:in `open' from /usr/local/lib/ruby/1.8/drb/drb.rb:1092:in `method_missing' from /usr/local/lib/ruby/1.8/drb/drb.rb:1110:in `with_friend' from /usr/local/lib/ruby/1.8/drb/drb.rb:1091:in `method_missing' from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/ runner/drb_command_line.rb:13:in `run' from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/ runner/option_parser.rb:184:in `parse_drb' from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/ runner/option_parser.rb:124:in `order!' from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/ runner.rb:202:in `options' from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/ runner/command_line.rb:8:in `run' from ./script/spec:5 Gems installed: rspec (1.1.11) rspec-rails (1.1.11) Any thoughts? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark at mwilden.com Fri Oct 31 17:47:25 2008 From: mark at mwilden.com (Mark Wilden) Date: Fri, 31 Oct 2008 14:47:25 -0700 Subject: [rspec-users] Fwd: spec_server not working... In-Reply-To: <4AE03859-BEC1-4ACF-AF91-AE189D8386CB@matt-darby.com> References: <1ED09426-C779-49AE-86D1-E1DD102D6C84@matt-darby.com> <4AE03859-BEC1-4ACF-AF91-AE189D8386CB@matt-darby.com> Message-ID: <3c30da400810311447s6e29368j88e1938c646c3c8@mail.gmail.com> On Fri, Oct 31, 2008 at 2:34 PM, Matt Darby wrote: > I can't seem to get spec_server to work correctly (I've never used it > before, so maybe I'm missing something?) > Try running 'spec' (presuming it's in your path). I had problems running 'script/spec' with version 1.1.9. I don't know if that will help, but it's worth a shot. For my money, spec_server is the most useful part of Rails programming that very few people use (TextMate is the opposite). ///ark > > I start up spec_server as prescribed: > mdarby at macbook:~/Documents/apps/CCW: rake spec:server:start > (in /Users/mdarby/Documents/Apps/CCW) > Starting up spec server. > Loading Rails environment > Ready > spec_server launched. (PID: 31387) > > > Then I try to run a spec and it times out after about thirty seconds: > mdarby at macbook:~/Documents/apps/CCW: ./script/spec --drb > spec/models/job_spec.rb > No server is running > > ^C/usr/local/lib/ruby/1.8/drb/drb.rb:566:in `read': Interrupt > from /usr/local/lib/ruby/1.8/drb/drb.rb:566:in `load' > from /usr/local/lib/ruby/1.8/drb/drb.rb:632:in `recv_reply' > from /usr/local/lib/ruby/1.8/drb/drb.rb:923:in `recv_reply' > from /usr/local/lib/ruby/1.8/drb/drb.rb:1202:in `send_message' > from /usr/local/lib/ruby/1.8/drb/drb.rb:1093:in `method_missing' > from /usr/local/lib/ruby/1.8/drb/drb.rb:1177:in `open' > from /usr/local/lib/ruby/1.8/drb/drb.rb:1092:in `method_missing' > from /usr/local/lib/ruby/1.8/drb/drb.rb:1110:in `with_friend' > from /usr/local/lib/ruby/1.8/drb/drb.rb:1091:in `method_missing' > from > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/drb_command_line.rb:13:in > `run' > from > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/option_parser.rb:184:in > `parse_drb' > from > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/option_parser.rb:124:in > `order!' > from > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner.rb:202:in > `options' > from > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/command_line.rb:8:in > `run' > from ./script/spec:5 > > Gems installed: > rspec (1.1.11) > rspec-rails (1.1.11) > > Any thoughts? > > Thanks! > > > _______________________________________________ > 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 matt at matt-darby.com Fri Oct 31 17:52:36 2008 From: matt at matt-darby.com (Matt Darby) Date: Fri, 31 Oct 2008 17:52:36 -0400 Subject: [rspec-users] Fwd: spec_server not working... In-Reply-To: <3c30da400810311447s6e29368j88e1938c646c3c8@mail.gmail.com> References: <1ED09426-C779-49AE-86D1-E1DD102D6C84@matt-darby.com> <4AE03859-BEC1-4ACF-AF91-AE189D8386CB@matt-darby.com> <3c30da400810311447s6e29368j88e1938c646c3c8@mail.gmail.com> Message-ID: <512EA428-C323-4861-B9F8-EF24BF5482CA@matt-darby.com> Same thing unfortunately. It also happens when I add --drb to spec/ spec.opts and run autotest/autospec as well. On Oct 31, 2008, at 5:47 PM, Mark Wilden wrote: > On Fri, Oct 31, 2008 at 2:34 PM, Matt Darby > wrote: > I can't seem to get spec_server to work correctly (I've never used > it before, so maybe I'm missing something?) > > Try running 'spec' (presuming it's in your path). I had problems > running 'script/spec' with version 1.1.9. I don't know if that will > help, but it's worth a shot. > > For my money, spec_server is the most useful part of Rails > programming that very few people use (TextMate is the opposite). > > ///ark > > > I start up spec_server as prescribed: > mdarby at macbook:~/Documents/apps/CCW: rake spec:server:start > (in /Users/mdarby/Documents/Apps/CCW) > Starting up spec server. > Loading Rails environment > Ready > spec_server launched. (PID: 31387) > > > Then I try to run a spec and it times out after about thirty seconds: > mdarby at macbook:~/Documents/apps/CCW: ./script/spec --drb spec/models/ > job_spec.rb > No server is running > > ^C/usr/local/lib/ruby/1.8/drb/drb.rb:566:in `read': Interrupt > from /usr/local/lib/ruby/1.8/drb/drb.rb:566:in `load' > from /usr/local/lib/ruby/1.8/drb/drb.rb:632:in `recv_reply' > from /usr/local/lib/ruby/1.8/drb/drb.rb:923:in `recv_reply' > from /usr/local/lib/ruby/1.8/drb/drb.rb:1202:in `send_message' > from /usr/local/lib/ruby/1.8/drb/drb.rb:1093:in > `method_missing' > from /usr/local/lib/ruby/1.8/drb/drb.rb:1177:in `open' > from /usr/local/lib/ruby/1.8/drb/drb.rb:1092:in > `method_missing' > from /usr/local/lib/ruby/1.8/drb/drb.rb:1110:in `with_friend' > from /usr/local/lib/ruby/1.8/drb/drb.rb:1091:in > `method_missing' > from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/ > runner/drb_command_line.rb:13:in `run' > from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/ > runner/option_parser.rb:184:in `parse_drb' > from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/ > runner/option_parser.rb:124:in `order!' > from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/ > runner.rb:202:in `options' > from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/ > runner/command_line.rb:8:in `run' > from ./script/spec:5 > > Gems installed: > rspec (1.1.11) > rspec-rails (1.1.11) > > Any thoughts? > > Thanks! > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at deadorange.com Fri Oct 31 18:04:17 2008 From: nick at deadorange.com (Nick Hoffman) Date: Fri, 31 Oct 2008 18:04:17 -0400 Subject: [rspec-users] Fwd: spec_server not working... In-Reply-To: <512EA428-C323-4861-B9F8-EF24BF5482CA@matt-darby.com> References: <1ED09426-C779-49AE-86D1-E1DD102D6C84@matt-darby.com> <4AE03859-BEC1-4ACF-AF91-AE189D8386CB@matt-darby.com> <3c30da400810311447s6e29368j88e1938c646c3c8@mail.gmail.com> <512EA428-C323-4861-B9F8-EF24BF5482CA@matt-darby.com> Message-ID: <7775AC65-C99E-4E9C-B793-7E4A6905F92F@deadorange.com> On 2008-10-31, at 17:52, Matt Darby wrote: > Same thing unfortunately. It also happens when I add --drb to spec/ > spec.opts and run autotest/autospec as well. G'day Matt. This probably won't be of much help, but I've never been able to run my specs against spec_server. I always get this error: /opt/local/lib/ruby/1.8/drb/drb.rb:852:in `initialize': getaddrinfo: nodename nor servname provided, or not known (SocketError) Cheers, Nick From mark at mwilden.com Fri Oct 31 18:24:59 2008 From: mark at mwilden.com (Mark Wilden) Date: Fri, 31 Oct 2008 15:24:59 -0700 Subject: [rspec-users] Fwd: spec_server not working... In-Reply-To: <512EA428-C323-4861-B9F8-EF24BF5482CA@matt-darby.com> References: <1ED09426-C779-49AE-86D1-E1DD102D6C84@matt-darby.com> <4AE03859-BEC1-4ACF-AF91-AE189D8386CB@matt-darby.com> <3c30da400810311447s6e29368j88e1938c646c3c8@mail.gmail.com> <512EA428-C323-4861-B9F8-EF24BF5482CA@matt-darby.com> Message-ID: <3c30da400810311524t1a1e4e01ua094f353b7bfb9c1@mail.gmail.com> On Fri, Oct 31, 2008 at 2:52 PM, Matt Darby wrote: > Same thing unfortunately. It also happens when I add --drb to > spec/spec.opts and run autotest/autospec as well. > FWIW, I've never gotten autotest to work with --drb, either. ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick at deadorange.com Fri Oct 31 18:26:07 2008 From: nick at deadorange.com (Nick Hoffman) Date: Fri, 31 Oct 2008 18:26:07 -0400 Subject: [rspec-users] Stubbing #javascript_include_tag in a helper spec Message-ID: <21F13AE4-CA67-40C7-90C1-1A689E42F722@deadorange.com> When writing specs for a helper method, how do you set an expectation for #javascript_include_tag ? describe NeighbourhoodsHelper do describe '#initialise_map' do it 'should include the "foo" JS file' do # expectation here helper.foobar end end end I've tried replacing "# expectation here" with the following, but none of them result in the desired behaviour: ActionView ::Helpers::AssetTagHelper.should_receive :javascript_include_tag @controller.should_receive :javascript_include_tag @controller.instance_eval { @template }.should_receive :javascript_include_tag Thanks! Nick From dchelimsky at gmail.com Fri Oct 31 18:50:37 2008 From: dchelimsky at gmail.com (David Chelimsky) Date: Fri, 31 Oct 2008 17:50:37 -0500 Subject: [rspec-users] Stubbing #javascript_include_tag in a helper spec In-Reply-To: <21F13AE4-CA67-40C7-90C1-1A689E42F722@deadorange.com> References: <21F13AE4-CA67-40C7-90C1-1A689E42F722@deadorange.com> Message-ID: <57c63afe0810311550g41cc318aj2e13e95b3f1980d@mail.gmail.com> On Fri, Oct 31, 2008 at 5:26 PM, Nick Hoffman wrote: > When writing specs for a helper method, how do you set an expectation for > #javascript_include_tag ? > > describe NeighbourhoodsHelper do > describe '#initialise_map' do > it 'should include the "foo" JS file' do > # expectation here > helper.foobar > end > end > end > > I've tried replacing "# expectation here" with the following, but none of > them result in the desired behaviour: > > ActionView::Helpers::AssetTagHelper.should_receive :javascript_include_tag > @controller.should_receive :javascript_include_tag > @controller.instance_eval { @template }.should_receive > :javascript_include_tag Assuming that you intend to have a helper method that calls out to javascript_include_tag, then: helper.should_receive :javascript_include_tag Let us know if that works for you. > Thanks! > Nick From nick at deadorange.com Fri Oct 31 19:13:19 2008 From: nick at deadorange.com (Nick Hoffman) Date: Fri, 31 Oct 2008 19:13:19 -0400 Subject: [rspec-users] Stubbing #javascript_include_tag in a helper spec In-Reply-To: <57c63afe0810311550g41cc318aj2e13e95b3f1980d@mail.gmail.com> References: <21F13AE4-CA67-40C7-90C1-1A689E42F722@deadorange.com> <57c63afe0810311550g41cc318aj2e13e95b3f1980d@mail.gmail.com> Message-ID: <0842EB58-A953-42B4-834B-B81B0C4B8754@deadorange.com> On 2008-10-31, at 18:50, David Chelimsky wrote: > Assuming that you intend to have a helper method that calls out to > javascript_include_tag, then: > > helper.should_receive :javascript_include_tag > > Let us know if that works for you. Hah, so easy. Why didn't I think of that? =P Thanks, mate! From matt at matt-darby.com Fri Oct 31 19:24:24 2008 From: matt at matt-darby.com (Matt Darby) Date: Fri, 31 Oct 2008 16:24:24 -0700 (PDT) Subject: [rspec-users] Fwd: spec_server not working... In-Reply-To: <3c30da400810311524t1a1e4e01ua094f353b7bfb9c1@mail.gmail.com> References: <1ED09426-C779-49AE-86D1-E1DD102D6C84@matt-darby.com> <4AE03859-BEC1-4ACF-AF91-AE189D8386CB@matt-darby.com> <3c30da400810311447s6e29368j88e1938c646c3c8@mail.gmail.com> <512EA428-C323-4861-B9F8-EF24BF5482CA@matt-darby.com> <3c30da400810311524t1a1e4e01ua094f353b7bfb9c1@mail.gmail.com> Message-ID: Hrm... So... anyone? It seems like this should be kind of straight forward :( On Oct 31, 6:24?pm, "Mark Wilden" wrote: > On Fri, Oct 31, 2008 at 2:52 PM, Matt Darby wrote: > > Same thing unfortunately. It also happens when I add --drb to > > spec/spec.opts and run autotest/autospec as well. > > FWIW, I've never gotten autotest to work with --drb, either. > > ///ark > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users From pergesu at gmail.com Fri Oct 31 20:17:47 2008 From: pergesu at gmail.com (Pat Maddox) Date: Fri, 31 Oct 2008 17:17:47 -0700 Subject: [rspec-users] Working outside-in with Cucumber and RSpec In-Reply-To: <364B2A62-F8E2-4159-924E-878B29E2AC3C@deadorange.com> (Nick Hoffman's message of "Fri\, 31 Oct 2008 16\:54\:42 -0400") References: <39734431-4E2D-438E-8207-F6BB14E70B4C@experthuman.com> <7A1029C6-59BA-4E83-AEC4-278CD79EFF47@mattwynne.net> <57c63afe0810251019n546f99f2l76766b7cb62684ad@mail.gmail.com> <2A0D0DA3-0585-49B0-9917-66DA991F6E49@patchspace.co.uk> <4903A5B5.9030700@benmabey.com> <03E104AA-E5CC-4D6E-92FF-C6C43109841F@patchspace.co.uk> <1BC43D24-C41A-46B5-9297-AC81AD593377@mattwynne.net> <010F2227-9AA8-406A-8097-81D83D7E96E4@mattwynne.net> <57c63afe0810300646p456cbadcl209465adf1502de3@mail.gmail.com> <364B2A62-F8E2-4159-924E-878B29E2AC3C@deadorange.com> Message-ID: Nick Hoffman writes: > On 2008-10-30, at 15:31, Pat Maddox wrote: >> eh I dunno. I mean, I completely agree that hard-to-write tests often >> expose bad code. But there isn't any gray area when it comes to >> designing Rails controllers, in my opinion. I see an action that's >> more >> than five lines long and I know it's wrong. I don't need to write >> examples to tell me that. > > Hi Pat. Would you mind suggesting how I can make this 22-line action a > bit shorter? =) > http://refactormycode.com/codes/575-dry-up-a-controller-action I should have known I'd get called out on this :) I pushed around some stuff that I think should be in the model. The other thing that I thought, but didn't change (I don't really know what you're doing with this action) is these render_to_string calls. Maybe you have a good reason for it, but I would just do regular "render :partial..." calls in the view. Pat